mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-12-04 01:51:11 +00:00
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:
parent
e9615608a8
commit
0eca30cb96
2 changed files with 31 additions and 27 deletions
|
@ -47,12 +47,6 @@
|
||||||
// Pointer to game library
|
// Pointer to game library
|
||||||
static void *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
|
// Evil hack to determine if stdin is available
|
||||||
qboolean stdin_active = true;
|
qboolean stdin_active = true;
|
||||||
|
|
||||||
|
@ -243,6 +237,11 @@ Sys_Nanosleep(int nanosec)
|
||||||
can't remove them since Sys_FindFirst() and Sys_FindNext()
|
can't remove them since Sys_FindFirst() and Sys_FindNext()
|
||||||
are defined in shared.h and may be used in custom game DLLs. */
|
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 *
|
char *
|
||||||
Sys_FindFirst(char *path, unsigned musthave, unsigned canhave)
|
Sys_FindFirst(char *path, unsigned musthave, unsigned canhave)
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,11 +48,6 @@ static HINSTANCE game_library;
|
||||||
static char console_text[256];
|
static char console_text[256];
|
||||||
static size_t console_textlen;
|
static size_t console_textlen;
|
||||||
|
|
||||||
// File searching
|
|
||||||
char findbase[MAX_OSPATH];
|
|
||||||
char findpath[MAX_OSPATH];
|
|
||||||
int findhandle;
|
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
qboolean is_portable;
|
qboolean is_portable;
|
||||||
unsigned int sys_frame_time;
|
unsigned int sys_frame_time;
|
||||||
|
@ -301,7 +296,8 @@ Sys_Milliseconds(void)
|
||||||
return (int)(Sys_Microseconds()/1000ll);
|
return (int)(Sys_Microseconds()/1000ll);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sys_Nanosleep(int nanosec)
|
void
|
||||||
|
Sys_Nanosleep(int nanosec)
|
||||||
{
|
{
|
||||||
HANDLE timer;
|
HANDLE timer;
|
||||||
LARGE_INTEGER li;
|
LARGE_INTEGER li;
|
||||||
|
@ -323,58 +319,67 @@ void Sys_Nanosleep(int nanosec)
|
||||||
can't remove them since Sys_FindFirst() and Sys_FindNext()
|
can't remove them since Sys_FindFirst() and Sys_FindNext()
|
||||||
are defined in shared.h and may be used in custom game DLLs. */
|
are defined in shared.h and may be used in custom game DLLs. */
|
||||||
|
|
||||||
// TODO: Still uses broken DOS functions.
|
// File searching
|
||||||
// Have a look at FindFirstFile(), FindNextFile() and FindClose().
|
static char findbase[MAX_OSPATH];
|
||||||
|
static char findpath[MAX_OSPATH];
|
||||||
|
static HANDLE findhandle;
|
||||||
|
|
||||||
char *
|
char *
|
||||||
Sys_FindFirst(char *path, unsigned musthave, unsigned canthave)
|
Sys_FindFirst(char *path, unsigned musthave, unsigned canthave)
|
||||||
{
|
{
|
||||||
struct _finddata_t findinfo;
|
|
||||||
|
|
||||||
if (findhandle)
|
if (findhandle)
|
||||||
{
|
{
|
||||||
Sys_Error("Sys_BeginFind without close");
|
Sys_Error("Sys_BeginFind without close");
|
||||||
}
|
}
|
||||||
|
|
||||||
findhandle = 0;
|
|
||||||
|
|
||||||
COM_FilePath(path, findbase);
|
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;
|
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;
|
return findpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
Sys_FindNext(unsigned musthave, unsigned canthave)
|
Sys_FindNext(unsigned musthave, unsigned canthave)
|
||||||
{
|
{
|
||||||
struct _finddata_t findinfo;
|
WIN32_FIND_DATAW findinfo;
|
||||||
|
|
||||||
if (findhandle == -1)
|
if (findhandle == INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_findnext(findhandle, &findinfo) == -1)
|
if (!FindNextFileW(findhandle, &findinfo))
|
||||||
{
|
{
|
||||||
return NULL;
|
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;
|
return findpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Sys_FindClose(void)
|
Sys_FindClose(void)
|
||||||
{
|
{
|
||||||
if (findhandle != -1)
|
if (findhandle != INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
_findclose(findhandle);
|
FindClose(findhandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
findhandle = 0;
|
findhandle = 0;
|
||||||
|
|
Loading…
Reference in a new issue