From f57086994641f9d934bf58d60624fc968c481821 Mon Sep 17 00:00:00 2001 From: Dniel97 Date: Tue, 27 Feb 2024 16:49:27 +0100 Subject: [PATCH] fixed AMFS path redirect with no E:/ drive present --- README.md | 2 +- platform/vfs.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 50a2e73..a754a74 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Segatools -Version: `2024-02-22` +Version: `2024-02-27` Loaders and hardware emulators for SEGA games that run on the Nu and ALLS platforms. diff --git a/platform/vfs.c b/platform/vfs.c index 60e4d4f..c44bbb0 100644 --- a/platform/vfs.c +++ b/platform/vfs.c @@ -277,11 +277,12 @@ static HRESULT vfs_path_hook(const wchar_t *src, wchar_t *dest, size_t *count) const wchar_t *redir; size_t required; size_t redir_len; + size_t src_len; assert(src != NULL); assert(count != NULL); - if (src[0] == L'\0' || src[1] != L':' || !path_is_separator_w(src[2])) { + if (src[0] == L'\0' || src[1] != L':') { return S_FALSE; } @@ -304,10 +305,15 @@ static HRESULT vfs_path_hook(const wchar_t *src, wchar_t *dest, size_t *count) return S_FALSE; } + /* GetFileAttributesW would request the src "E:", so fix the src_len in + in order to redirect the drive letter successfully */ + + src_len = path_is_separator_w(src[2]) ? 3 : 2; + /* Cut off \, replace with redir path, count NUL terminator */ redir_len = wcslen(redir); - required = wcslen(src) - 3 + redir_len + 1; + required = wcslen(src) - src_len + redir_len + 1; if (dest != NULL) { if (required > *count) { @@ -315,7 +321,7 @@ static HRESULT vfs_path_hook(const wchar_t *src, wchar_t *dest, size_t *count) } wcscpy_s(dest, *count, redir); - wcscpy_s(dest + redir_len, *count - redir_len, src + 3); + wcscpy_s(dest + redir_len, *count - redir_len, src + src_len); } *count = required;