hooklib/path.c: add slash-insensitive path comparison API

This commit is contained in:
Shiz 2019-12-18 21:30:35 +01:00
parent 28e9594b98
commit a31557c5cd
3 changed files with 31 additions and 1 deletions

View File

@ -388,6 +388,35 @@ end:
return ok; return ok;
} }
int path_compare_w(const wchar_t *string1, const wchar_t *string2, size_t count)
{
size_t i;
wchar_t c1, c2;
assert(string1 != NULL);
assert(string2 != NULL);
for (i = 0; i < count && string1[i] && string2[i]; i++) {
c1 = towlower(string1[i]);
if (c1 == '/') {
c1 = '\\';
}
c2 = towlower(string2[i]);
if (c2 == '/') {
c2 = '\\';
}
if (c1 != c2) {
break;
}
}
return i == count ? 0 : string2[i] - string1[i];
}
/* Dumping ground for kernel32 file system ops whose path parameters we have to /* Dumping ground for kernel32 file system ops whose path parameters we have to
hook into and translate. This list will grow over time as we go back and hook into and translate. This list will grow over time as we go back and
fix up older games that don't pay attention to the mount point registry. */ fix up older games that don't pay attention to the mount point registry. */

View File

@ -10,3 +10,4 @@ typedef HRESULT (*path_hook_t)(
size_t *count); size_t *count);
HRESULT path_hook_push(path_hook_t hook); HRESULT path_hook_push(path_hook_t hook);
int path_compare_w(const wchar_t *string1, const wchar_t *string2, size_t count);

View File

@ -273,7 +273,7 @@ static HRESULT vfs_path_hook_nthome(
/* Case-insensitive check to see if src starts with vfs_nthome */ /* Case-insensitive check to see if src starts with vfs_nthome */
if (_wcsnicmp(src, vfs_nthome, vfs_nthome_len) != 0) { if (path_compare_w(src, vfs_nthome, vfs_nthome_len) != 0) {
return S_FALSE; return S_FALSE;
} }