diff --git a/runtime-ext/source/dvd.c b/runtime-ext/source/dvd.c index 9ae916b..4a411be 100644 --- a/runtime-ext/source/dvd.c +++ b/runtime-ext/source/dvd.c @@ -242,7 +242,7 @@ static bool rte_dvd_resolve_my_stuff_path_to_entry_num(const char *path, s32 *en bool cached_file_exists = false; for (int i = 0; i < my_stuff_replacement->folder_contents_count; i++) { - if (strcmp(my_stuff_replacement->folder_contents[i], filename) == 0) + if (strcicmp(my_stuff_replacement->folder_contents[i], filename) == 0) { cached_file_exists = true; break; @@ -292,7 +292,7 @@ static bool rte_dvd_resolve_path_to_entry_num(const char *filename, s32 *entry_n { case RRC_RIIVO_FILE_REPLACEMENT: { - RTE_DBG("Checking file replacement: '%s' == '%s'\n", replacement->disc, "strm"); + RTE_DBG("Checking file replacement: '%s' == '%s'\n", replacement->disc, filename); // Trim leading slashes from either path. const char *disc_path = replacement->disc; @@ -306,7 +306,7 @@ static bool rte_dvd_resolve_path_to_entry_num(const char *filename, s32 *entry_n ffilename++; } - if (strcmp(disc_path, ffilename) == 0) + if (strcicmp(disc_path, ffilename) == 0) { // We already checked that the external file exists when we registered the replacement. RTE_DBG("Found a file replacement! %d (%s)\n", i, disc_path); @@ -391,13 +391,7 @@ static bool rte_dvd_resolve_path_to_entry_num(const char *filename, s32 *entry_n bool cached_file_exists = false; for (int i = 0; i < replacement->folder_contents_count; i++) { - // We need to enforce case insensitivity here because FAT is case-insensitive, - // and the folder_contents are populated based on FAT reads. - - to_lowercase((char *)replacement->folder_contents[i]); - to_lowercase(new_path_filename); - - if (strcmp(replacement->folder_contents[i], new_path_filename) == 0) + if (strcicmp(replacement->folder_contents[i], new_path_filename) == 0) { RTE_DBG("Found a cached match for the filename in the folder contents!\n"); cached_file_exists = true; diff --git a/runtime-ext/source/util.c b/runtime-ext/source/util.c index 95a8725..fa9eddb 100644 --- a/runtime-ext/source/util.c +++ b/runtime-ext/source/util.c @@ -19,6 +19,8 @@ #include #include +#include +#include u32 align_down(u32 num, u32 align_as) { @@ -32,8 +34,27 @@ u32 align_up(u32 num, u32 align_as) void to_lowercase(char *str) { - for (int i = 0; str[i]; i++) { + for (int i = 0; str[i]; i++) + { // Cast to unsigned char to avoid undefined behaviour with non-ASCII chars str[i] = tolower((unsigned char)str[i]); } +} + +int strcicmp(const char *a, const char *b) +{ + const unsigned char *p1 = (const unsigned char *)a; + const unsigned char *p2 = (const unsigned char *)b; + int result; + + if (p1 == p2) + return 0; + + while ((result = tolower(*p1) - tolower(*p2++)) == 0) + { + if (*p1++ == '\0') + break; + } + + return result; } \ No newline at end of file diff --git a/runtime-ext/source/util.h b/runtime-ext/source/util.h index b1a27ec..2c1cdf8 100644 --- a/runtime-ext/source/util.h +++ b/runtime-ext/source/util.h @@ -51,4 +51,6 @@ u32 align_up(u32 num, u32 align_as); void to_lowercase(char *str); +int strcicmp(const char *a, const char *b); + #endif