Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions runtime-ext/source/dvd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 22 additions & 1 deletion runtime-ext/source/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include <types.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

u32 align_down(u32 num, u32 align_as)
{
Expand All @@ -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;
}
2 changes: 2 additions & 0 deletions runtime-ext/source/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading