From 0eca30cb96841835f098098cecc499e6d0cb9ec9 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Sun, 4 Feb 2018 12:10:13 +0100 Subject: [PATCH] Convert the Sys_Find*() functions from the old DOS interface to WinAPI. This brings at least two big advantages: * No more 8.3 filename fuckups. Until know base0.pak and base0.pak_bak was the same file for Quake II because only the first 3 characters of the file extension were taken into account. * Search pathes can contain any Unicode character. --- src/backends/unix/system.c | 11 ++++---- src/backends/windows/system.c | 47 +++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/backends/unix/system.c b/src/backends/unix/system.c index 053062ff..3d1a140a 100644 --- a/src/backends/unix/system.c +++ b/src/backends/unix/system.c @@ -47,12 +47,6 @@ // Pointer to game library static void *game_library; -// File searching -static char findbase[MAX_OSPATH]; -static char findpath[MAX_OSPATH]; -static char findpattern[MAX_OSPATH]; -static DIR *fdir; - // Evil hack to determine if stdin is available qboolean stdin_active = true; @@ -243,6 +237,11 @@ Sys_Nanosleep(int nanosec) can't remove them since Sys_FindFirst() and Sys_FindNext() are defined in shared.h and may be used in custom game DLLs. */ +static char findbase[MAX_OSPATH]; +static char findpath[MAX_OSPATH]; +static char findpattern[MAX_OSPATH]; +static DIR *fdir; + char * Sys_FindFirst(char *path, unsigned musthave, unsigned canhave) { diff --git a/src/backends/windows/system.c b/src/backends/windows/system.c index 6986ad95..7bc1dbcb 100644 --- a/src/backends/windows/system.c +++ b/src/backends/windows/system.c @@ -48,11 +48,6 @@ static HINSTANCE game_library; static char console_text[256]; static size_t console_textlen; -// File searching -char findbase[MAX_OSPATH]; -char findpath[MAX_OSPATH]; -int findhandle; - // TODO qboolean is_portable; unsigned int sys_frame_time; @@ -301,7 +296,8 @@ Sys_Milliseconds(void) return (int)(Sys_Microseconds()/1000ll); } -void Sys_Nanosleep(int nanosec) +void +Sys_Nanosleep(int nanosec) { HANDLE timer; LARGE_INTEGER li; @@ -323,58 +319,67 @@ void Sys_Nanosleep(int nanosec) can't remove them since Sys_FindFirst() and Sys_FindNext() are defined in shared.h and may be used in custom game DLLs. */ -// TODO: Still uses broken DOS functions. -// Have a look at FindFirstFile(), FindNextFile() and FindClose(). +// File searching +static char findbase[MAX_OSPATH]; +static char findpath[MAX_OSPATH]; +static HANDLE findhandle; char * Sys_FindFirst(char *path, unsigned musthave, unsigned canthave) { - struct _finddata_t findinfo; - if (findhandle) { Sys_Error("Sys_BeginFind without close"); } - findhandle = 0; - COM_FilePath(path, findbase); - findhandle = _findfirst(path, &findinfo); - if (findhandle == -1) + WCHAR wpath[MAX_QPATH] = {0}; + MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, MAX_QPATH); + + WIN32_FIND_DATAW findinfo; + findhandle = FindFirstFileW(wpath, &findinfo); + + if (findhandle == INVALID_HANDLE_VALUE) { return NULL; } - Com_sprintf(findpath, sizeof(findpath), "%s/%s", findbase, findinfo.name); + CHAR cFileName[MAX_QPATH]; + WideCharToMultiByte(CP_UTF8, 0, findinfo.cFileName, -1, cFileName, MAX_QPATH, NULL, NULL); + + Com_sprintf(findpath, sizeof(findpath), "%s/%s", findbase, cFileName); return findpath; } char * Sys_FindNext(unsigned musthave, unsigned canthave) { - struct _finddata_t findinfo; + WIN32_FIND_DATAW findinfo; - if (findhandle == -1) + if (findhandle == INVALID_HANDLE_VALUE) { return NULL; } - if (_findnext(findhandle, &findinfo) == -1) + if (!FindNextFileW(findhandle, &findinfo)) { return NULL; } - Com_sprintf(findpath, sizeof(findpath), "%s/%s", findbase, findinfo.name); + CHAR cFileName[MAX_QPATH]; + WideCharToMultiByte(CP_UTF8, 0, findinfo.cFileName, -1, cFileName, MAX_QPATH, NULL, NULL); + + Com_sprintf(findpath, sizeof(findpath), "%s/%s", findbase, cFileName); return findpath; } void Sys_FindClose(void) { - if (findhandle != -1) + if (findhandle != INVALID_HANDLE_VALUE) { - _findclose(findhandle); + FindClose(findhandle); } findhandle = 0;