strife: Convert to new glob API.
This removes the need to do system-specific stuff to read the contents of a directory - this is all now hidden away in i_glob.c.
This commit is contained in:
parent
1bbbdea98a
commit
1c8880feb8
2 changed files with 55 additions and 75 deletions
|
|
@ -66,9 +66,7 @@ set(STRIFE_SOURCES
|
||||||
st_lib.c st_lib.h
|
st_lib.c st_lib.h
|
||||||
st_stuff.c st_stuff.h
|
st_stuff.c st_stuff.h
|
||||||
wi_stuff.c wi_stuff.h)
|
wi_stuff.c wi_stuff.h)
|
||||||
if(MSVC)
|
|
||||||
list(APPEND STRIFE_SOURCES "../../win32/win_opendir.c" "../../win32/win_opendir.h")
|
|
||||||
endif()
|
|
||||||
add_library(strife STATIC ${STRIFE_SOURCES})
|
add_library(strife STATIC ${STRIFE_SOURCES})
|
||||||
|
|
||||||
target_include_directories(strife PRIVATE "../" "../../win32/" "${CMAKE_CURRENT_BINARY_DIR}/../../")
|
target_include_directories(strife PRIVATE "../" "../../win32/" "${CMAKE_CURRENT_BINARY_DIR}/../../")
|
||||||
|
|
|
||||||
|
|
@ -19,22 +19,12 @@
|
||||||
// Strife Hub Saving Code
|
// Strife Hub Saving Code
|
||||||
//
|
//
|
||||||
|
|
||||||
// For GNU C and POSIX targets, dirent.h should be available. Otherwise, for
|
|
||||||
// Visual C++, we need to include the win_opendir module.
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
#include <win_opendir.h>
|
|
||||||
#elif defined(__GNUC__) || defined(POSIX)
|
|
||||||
#include <dirent.h>
|
|
||||||
#elif defined(__WATCOMC__)
|
|
||||||
#include <direct.h>
|
|
||||||
#else
|
|
||||||
#error Need an include for dirent.h!
|
|
||||||
#endif
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "z_zone.h"
|
#include "z_zone.h"
|
||||||
|
#include "i_glob.h"
|
||||||
#include "i_system.h"
|
#include "i_system.h"
|
||||||
#include "d_player.h"
|
#include "d_player.h"
|
||||||
#include "deh_str.h"
|
#include "deh_str.h"
|
||||||
|
|
@ -61,32 +51,27 @@ char character_name[CHARACTER_NAME_LEN]; // Name of "character" for saveslot
|
||||||
//
|
//
|
||||||
void ClearTmp(void)
|
void ClearTmp(void)
|
||||||
{
|
{
|
||||||
DIR *sp2dir = NULL;
|
glob_t *glob;
|
||||||
struct dirent *f = NULL;
|
|
||||||
|
|
||||||
if(savepathtemp == NULL)
|
if(savepathtemp == NULL)
|
||||||
I_Error("you fucked up savedir man!");
|
I_Error("you fucked up savedir man!");
|
||||||
|
|
||||||
if(!(sp2dir = opendir(savepathtemp)))
|
glob = I_StartGlob(savepathtemp, "*");
|
||||||
|
if (glob == NULL)
|
||||||
I_Error("ClearTmp: Couldn't open dir %s", savepathtemp);
|
I_Error("ClearTmp: Couldn't open dir %s", savepathtemp);
|
||||||
|
|
||||||
while((f = readdir(sp2dir)))
|
for (;;)
|
||||||
{
|
{
|
||||||
char *filepath = NULL;
|
const char *path = I_NextGlob(glob);
|
||||||
|
|
||||||
// haleyjd: skip "." and ".." without assuming they're the
|
if (path == NULL)
|
||||||
// first two entries like the original code did.
|
{
|
||||||
if(!strcmp(f->d_name, ".") || !strcmp(f->d_name, ".."))
|
break;
|
||||||
continue;
|
}
|
||||||
|
remove(path);
|
||||||
// haleyjd: use M_SafeFilePath, not sprintf
|
|
||||||
filepath = M_SafeFilePath(savepathtemp, f->d_name);
|
|
||||||
remove(filepath);
|
|
||||||
|
|
||||||
Z_Free(filepath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(sp2dir);
|
I_EndGlob(glob);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
@ -96,30 +81,28 @@ void ClearTmp(void)
|
||||||
//
|
//
|
||||||
void ClearSlot(void)
|
void ClearSlot(void)
|
||||||
{
|
{
|
||||||
DIR *spdir = NULL;
|
glob_t *glob;
|
||||||
struct dirent *f = NULL;
|
|
||||||
|
|
||||||
if(savepath == NULL)
|
if(savepath == NULL)
|
||||||
I_Error("userdir is fucked up man!");
|
I_Error("userdir is fucked up man!");
|
||||||
|
|
||||||
if(!(spdir = opendir(savepath)))
|
glob = I_StartGlob(savepath, "*");
|
||||||
|
if (glob == NULL)
|
||||||
I_Error("ClearSlot: Couldn't open dir %s", savepath);
|
I_Error("ClearSlot: Couldn't open dir %s", savepath);
|
||||||
|
|
||||||
while((f = readdir(spdir)))
|
for (;;)
|
||||||
{
|
{
|
||||||
char *filepath = NULL;
|
const char *filepath = I_NextGlob(glob);
|
||||||
|
|
||||||
|
if (filepath == NULL)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if(!strcmp(f->d_name, ".") || !strcmp(f->d_name, ".."))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// haleyjd: use M_SafeFilePath, not sprintf
|
|
||||||
filepath = M_SafeFilePath(savepath, f->d_name);
|
|
||||||
remove(filepath);
|
remove(filepath);
|
||||||
|
|
||||||
Z_Free(filepath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(spdir);
|
I_EndGlob(glob);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
@ -129,37 +112,36 @@ void ClearSlot(void)
|
||||||
//
|
//
|
||||||
void FromCurr(void)
|
void FromCurr(void)
|
||||||
{
|
{
|
||||||
DIR *sp2dir = NULL;
|
glob_t *glob;
|
||||||
struct dirent *f = NULL;
|
|
||||||
|
|
||||||
if(!(sp2dir = opendir(savepathtemp)))
|
glob = I_StartGlob(savepathtemp, "*");
|
||||||
|
|
||||||
|
if (glob == NULL)
|
||||||
I_Error("FromCurr: Couldn't open dir %s", savepathtemp);
|
I_Error("FromCurr: Couldn't open dir %s", savepathtemp);
|
||||||
|
|
||||||
while((f = readdir(sp2dir)))
|
for (;;)
|
||||||
{
|
{
|
||||||
byte *filebuffer = NULL;
|
byte *filebuffer;
|
||||||
int filelen = 0;
|
int filelen;
|
||||||
char *srcfilename = NULL;
|
const char *srcfilename;
|
||||||
char *dstfilename = NULL;
|
char *dstfilename;
|
||||||
|
|
||||||
// haleyjd: skip "." and ".." without assuming they're the
|
srcfilename = I_NextGlob(glob);
|
||||||
// first two entries like the original code did.
|
if (srcfilename == NULL)
|
||||||
if(!strcmp(f->d_name, ".") || !strcmp(f->d_name, ".."))
|
{
|
||||||
continue;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// haleyjd: use M_SafeFilePath, NOT sprintf.
|
dstfilename = M_SafeFilePath(savepath, M_BaseName(srcfilename));
|
||||||
srcfilename = M_SafeFilePath(savepathtemp, f->d_name);
|
|
||||||
dstfilename = M_SafeFilePath(savepath, f->d_name);
|
|
||||||
|
|
||||||
filelen = M_ReadFile(srcfilename, &filebuffer);
|
filelen = M_ReadFile(srcfilename, &filebuffer);
|
||||||
M_WriteFile(dstfilename, filebuffer, filelen);
|
M_WriteFile(dstfilename, filebuffer, filelen);
|
||||||
|
|
||||||
Z_Free(filebuffer);
|
Z_Free(filebuffer);
|
||||||
Z_Free(srcfilename);
|
|
||||||
Z_Free(dstfilename);
|
Z_Free(dstfilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(sp2dir);
|
I_EndGlob(glob);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
@ -169,39 +151,39 @@ void FromCurr(void)
|
||||||
//
|
//
|
||||||
void ToCurr(void)
|
void ToCurr(void)
|
||||||
{
|
{
|
||||||
DIR *spdir = NULL;
|
glob_t *glob;
|
||||||
struct dirent *f = NULL;
|
|
||||||
|
|
||||||
ClearTmp();
|
ClearTmp();
|
||||||
|
|
||||||
// BUG: Rogue copypasta'd this error message, which is why we don't know
|
// BUG: Rogue copypasta'd this error message, which is why we don't know
|
||||||
// the real original name of this function.
|
// the real original name of this function.
|
||||||
if(!(spdir = opendir(savepath)))
|
glob = I_StartGlob(savepath, "*");
|
||||||
|
if (glob == NULL)
|
||||||
I_Error("ClearSlot: Couldn't open dir %s", savepath);
|
I_Error("ClearSlot: Couldn't open dir %s", savepath);
|
||||||
|
|
||||||
while((f = readdir(spdir)))
|
for (;;)
|
||||||
{
|
{
|
||||||
byte *filebuffer = NULL;
|
byte *filebuffer;
|
||||||
int filelen = 0;
|
int filelen;
|
||||||
char *srcfilename = NULL;
|
const char *srcfilename;
|
||||||
char *dstfilename = NULL;
|
char *dstfilename;
|
||||||
|
|
||||||
if(!strcmp(f->d_name, ".") || !strcmp(f->d_name, ".."))
|
srcfilename = I_NextGlob(glob);
|
||||||
continue;
|
if (srcfilename == NULL)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// haleyjd: use M_SafeFilePath, NOT sprintf.
|
dstfilename = M_SafeFilePath(savepathtemp, M_BaseName(srcfilename));
|
||||||
srcfilename = M_SafeFilePath(savepath, f->d_name);
|
|
||||||
dstfilename = M_SafeFilePath(savepathtemp, f->d_name);
|
|
||||||
|
|
||||||
filelen = M_ReadFile(srcfilename, &filebuffer);
|
filelen = M_ReadFile(srcfilename, &filebuffer);
|
||||||
M_WriteFile(dstfilename, filebuffer, filelen);
|
M_WriteFile(dstfilename, filebuffer, filelen);
|
||||||
|
|
||||||
Z_Free(filebuffer);
|
Z_Free(filebuffer);
|
||||||
Z_Free(srcfilename);
|
|
||||||
Z_Free(dstfilename);
|
Z_Free(dstfilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(spdir);
|
I_EndGlob(glob);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue