mirror of
https://gitea.tendokyu.moe/Hay1tsme/bananatools.git
synced 2026-04-25 07:58:21 -05:00
common: improve path hooks
This commit is contained in:
parent
5f9ba0627b
commit
6c5a0affff
1015
hooklib/path.c
1015
hooklib/path.c
File diff suppressed because it is too large
Load Diff
|
|
@ -13,6 +13,10 @@ typedef HRESULT (*path_hook_t)(
|
|||
HRESULT path_hook_push(path_hook_t hook);
|
||||
void path_hook_insert_hooks(HMODULE target);
|
||||
int path_compare_w(const wchar_t *string1, const wchar_t *string2, size_t count);
|
||||
BOOL path_transform_a(char **out, const char *src);
|
||||
BOOL path_transform_w(wchar_t **out, const wchar_t *src);
|
||||
BOOL path_transform_args_a(const char* str, char delimiter, char* buf, size_t size);
|
||||
BOOL path_transform_args_w(const wchar_t* str, wchar_t delimiter, wchar_t* buf, size_t size);
|
||||
|
||||
static inline bool path_is_separator_w(wchar_t c)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ static DWORD (*next_GetLogicalDrives)();
|
|||
static UINT (*next_GetDriveTypeA)(LPCSTR lpRootPathName);
|
||||
static void vfs_fixup_path(wchar_t *path, size_t max_count);
|
||||
static HRESULT vfs_mkdir_rec(const wchar_t *path);
|
||||
static HRESULT vfs_path_hook(const wchar_t *src, wchar_t *dest, size_t *count);
|
||||
static HRESULT vfs_path_hook_nthome(
|
||||
const wchar_t *src,
|
||||
wchar_t *dest,
|
||||
|
|
@ -290,11 +289,12 @@ end:
|
|||
return hr;
|
||||
}
|
||||
|
||||
static HRESULT vfs_path_hook(const wchar_t *src, wchar_t *dest, size_t *count)
|
||||
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;
|
||||
HRESULT hr;
|
||||
|
||||
assert(src != NULL);
|
||||
|
|
@ -345,10 +345,16 @@ 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 <prefix>\, 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) {
|
||||
|
|
@ -356,7 +362,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;
|
||||
|
|
|
|||
|
|
@ -18,3 +18,4 @@ struct vfs_config {
|
|||
};
|
||||
|
||||
HRESULT vfs_hook_init(const struct vfs_config *config);
|
||||
HRESULT vfs_path_hook(const wchar_t *src, wchar_t *dest, size_t *count);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user