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.
This commit is contained in:
Yamagi Burmeister 2018-02-04 12:10:13 +01:00
parent e9615608a8
commit 0eca30cb96
2 changed files with 31 additions and 27 deletions

View file

@ -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)
{

View file

@ -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;