From 1d77f68c2273c8b5b1e5ddec1aaabf413e0b4dcd Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Sun, 3 Jun 2012 14:33:33 +0200 Subject: [PATCH] Implement system depended file handling Those functions were taken from ioQuake2 and refactored to match Yamagi Quake II. --- src/windows/system.c | 132 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/src/windows/system.c b/src/windows/system.c index 2157cb6b..7e945c05 100644 --- a/src/windows/system.c +++ b/src/windows/system.c @@ -57,6 +57,10 @@ unsigned int sys_frame_time; static char console_text[256]; static int console_textlen; +char findbase[MAX_OSPATH]; +char findpath[MAX_OSPATH]; +int findhandle; + int argc; char *argv[MAX_NUM_ARGVS]; @@ -506,6 +510,134 @@ Sys_Milliseconds(void) /* ======================================================================= */ +static qboolean +CompareAttributes(unsigned found, unsigned musthave, unsigned canthave) +{ + if ((found & _A_RDONLY) && (canthave & SFF_RDONLY)) + { + return false; + } + + if ((found & _A_HIDDEN) && (canthave & SFF_HIDDEN)) + { + return false; + } + + if ((found & _A_SYSTEM) && (canthave & SFF_SYSTEM)) + { + return false; + } + + if ((found & _A_SUBDIR) && (canthave & SFF_SUBDIR)) + { + return false; + } + + if ((found & _A_ARCH) && (canthave & SFF_ARCH)) + { + return false; + } + + if ((musthave & SFF_RDONLY) && !(found & _A_RDONLY)) + { + return false; + } + + if ((musthave & SFF_HIDDEN) && !(found & _A_HIDDEN)) + { + return false; + } + + if ((musthave & SFF_SYSTEM) && !(found & _A_SYSTEM)) + { + return false; + } + + if ((musthave & SFF_SUBDIR) && !(found & _A_SUBDIR)) + { + return false; + } + + if ((musthave & SFF_ARCH) && !(found & _A_ARCH)) + { + return false; + } + + return true; +} + +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) + { + return NULL; + } + + if (!CompareAttributes(findinfo.attrib, musthave, canthave)) + { + return NULL; + } + + Com_sprintf(findpath, sizeof(findpath), "%s/%s", findbase, findinfo.name); + return findpath; +} + +char * +Sys_FindNext(unsigned musthave, unsigned canthave) +{ + struct _finddata_t findinfo; + + if (findhandle == -1) + { + return NULL; + } + + if (_findnext(findhandle, &findinfo) == -1) + { + return NULL; + } + + if (!CompareAttributes(findinfo.attrib, musthave, canthave)) + { + return NULL; + } + + Com_sprintf(findpath, sizeof(findpath), "%s/%s", findbase, findinfo.name); + return findpath; +} + +void +Sys_FindClose(void) +{ + if (findhandle != -1) + { + _findclose(findhandle); + } + + findhandle = 0; +} + +void +Sys_Mkdir(char *path) +{ + _mkdir(path); +} + +/* ======================================================================= */ + /* * Windows main function. Containts the * initialization code and the main loop