From 4f534c5ce308216f323c83415da41c55fe5b0499 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 25 Aug 2025 16:10:24 +0200 Subject: [PATCH 1/4] remove d_main include from filesrch --- src/filesrch.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/filesrch.c b/src/filesrch.c index c5b1cd8b6..c76c9b7a9 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -12,7 +12,6 @@ /// FS_MD5SUMBAD; /// FS_FOUND -#include "d_main.h" #include #ifdef __GNUC__ #include From 6e123b0732d8f0565de1728c24227f42a02752ee Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 26 Aug 2025 08:34:57 +0100 Subject: [PATCH 2/4] fix filesearch portability --- src/filesrch.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/filesrch.c b/src/filesrch.c index c76c9b7a9..9592c63c2 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -381,7 +381,9 @@ filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *want filestatus_t retval = FS_NOTFOUND; DIR **dirhandle; struct dirent *dent; +#ifndef _WIN32 struct stat fsstat; +#endif int found = 0; char *searchname; int depthleft = maxsearchdepth; @@ -485,12 +487,16 @@ filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *want // Linux and FreeBSD has a special field for file type on dirent, so use that to speed up lookups. // FIXME: should we also follow symlinks? if ((dent->d_type == DT_DIR && depthleft) || (dent->d_type == DT_LNK && depthleft)) -#else +#elif defined (_WIN32) // if we wanna follow symlinks we can check with FILE_ATTRIBUTE_REPARSE_POINT DWORD fileattr = GetFileAttributes(searchpath); if (fileattr == INVALID_FILE_ATTRIBUTES) ; // was the file (re)moved? can't stat it else if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) && depthleft) +#else + if (stat(searchpath,&fsstat) < 0) // do we want to follow symlinks? if not: change it to lstat + ; // was the file (re)moved? can't stat it + else if (S_ISDIR(fsstat.st_mode) && depthleft) #endif { searchpathindex[--depthleft] = strlen(searchpath) + 1; @@ -704,7 +710,9 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) { DIR *dirhandle; struct dirent *dent; +#ifndef _WIN32 struct stat fsstat; +#endif size_t pos = 0, folderpos = 0, numfolders = 0; char *tempname = NULL; @@ -747,7 +755,7 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) strcpy(&menupath[menupathindex[menudepthleft]],dent->d_name); -#if defined(__linux__) || defined(__FreeBSD__) +#ifndef _WIN32 if (stat(menupath, &fsstat) < 0) #else // if we wanna follow symlinks we can check with FILE_ATTRIBUTE_REPARSE_POINT @@ -757,7 +765,7 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) ; // was the file (re)moved? can't stat it else // is a file or directory { -#if defined(__linux__) || defined(__FreeBSD__) +#ifndef _WIN32 if (!S_ISDIR(fsstat.st_mode)) // file #else if (!(fileattr & FILE_ATTRIBUTE_DIRECTORY)) @@ -829,7 +837,7 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) strcpy(&menupath[menupathindex[menudepthleft]],dent->d_name); -#if defined(__linux__) || defined(__FreeBSD__) +#ifndef _WIN32 if (stat(menupath, &fsstat) < 0) #else // if we wanna follow symlinks we can check with FILE_ATTRIBUTE_REPARSE_POINT @@ -844,7 +852,7 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) UINT8 ext = EXT_FOLDER; UINT8 folder; -#if defined(__linux__) || defined(__FreeBSD__) +#ifndef _WIN32 if (!S_ISDIR(fsstat.st_mode)) // file #else if (!(fileattr & FILE_ATTRIBUTE_DIRECTORY)) From 6f891dd2351a881aba15a1180c61231a348cce1f Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 26 Aug 2025 08:36:00 +0100 Subject: [PATCH 3/4] use GetFileAttributes for pathisdirectory on Windows should slightly speedup gamestartup with autoloaded files --- src/filesrch.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/filesrch.c b/src/filesrch.c index 9592c63c2..74ff1ef53 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -341,6 +341,7 @@ char *refreshdirname = NULL; // direrror is set if there was an error. INT32 pathisdirectory(const char *path) { +#ifndef _WIN32 struct stat fsstat; if (stat(path, &fsstat) < 0) @@ -348,7 +349,21 @@ INT32 pathisdirectory(const char *path) return -1; } else if (S_ISDIR(fsstat.st_mode)) + { return 1; + } + +#else + DWORD fileattr = GetFileAttributes(path); + if (fileattr == INVALID_FILE_ATTRIBUTES) + { + return -1; + } + else if (fileattr & FILE_ATTRIBUTE_DIRECTORY) + { + return 1; + } +#endif return 0; } From 74c9c09fcdd2a27c029916a61cba39af57b2d093 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 26 Aug 2025 12:04:00 +0200 Subject: [PATCH 4/4] remove skipexclude variable with the folderchange check this becomes erronous --- src/d_netfil.c | 12 ++++++------ src/dedicated/i_system.c | 4 ++-- src/filesrch.c | 7 +++---- src/filesrch.h | 3 +-- src/sdl/i_system.cpp | 2 +- src/sdl/i_ttf.c | 2 +- 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/d_netfil.c b/src/d_netfil.c index 8a37a2dac..356fb6854 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -1179,7 +1179,7 @@ filestatus_t findfile(char *filename, const UINT8 *wantedmd5sum, boolean complet if (cv_addons_option.value == 3 && *cv_addons_folder.string != '\0') { // first, check any custom directory if specified - homecheck = filesearch(filename, cv_addons_folder.string, wantedmd5sum, completepath, 10, false); + homecheck = filesearch(filename, cv_addons_folder.string, wantedmd5sum, completepath, 10); if (homecheck == FS_FOUND) // we found the file, so return that we have :) return FS_FOUND; @@ -1189,7 +1189,7 @@ filestatus_t findfile(char *filename, const UINT8 *wantedmd5sum, boolean complet } // next, check "DOWNLOAD" directory - homecheck = filesearch(filename, "DOWNLOAD", wantedmd5sum, completepath, 10, false); + homecheck = filesearch(filename, "DOWNLOAD", wantedmd5sum, completepath, 10); if (homecheck == FS_FOUND) // we found the file, so return that we have :) return FS_FOUND; @@ -1198,7 +1198,7 @@ filestatus_t findfile(char *filename, const UINT8 *wantedmd5sum, boolean complet // if not found at all, just move on without doing anything // next, check "addons" directory - homecheck = filesearch(filename, "addons", wantedmd5sum, completepath, 10, false); + homecheck = filesearch(filename, "addons", wantedmd5sum, completepath, 10); if (homecheck == FS_FOUND) // we found the file, so return that we have :) return FS_FOUND; @@ -1208,7 +1208,7 @@ filestatus_t findfile(char *filename, const UINT8 *wantedmd5sum, boolean complet } // next, check SRB2's "home" directory - homecheck = filesearch(filename, srb2home, wantedmd5sum, completepath, 10, true); + homecheck = filesearch(filename, srb2home, wantedmd5sum, completepath, 10); if (homecheck == FS_FOUND) // we found the file, so return that we have :) return FS_FOUND; @@ -1217,7 +1217,7 @@ filestatus_t findfile(char *filename, const UINT8 *wantedmd5sum, boolean complet // if not found at all, just move on without doing anything // next, check SRB2's "path" directory - homecheck = filesearch(filename, srb2path, wantedmd5sum, completepath, 10, true); + homecheck = filesearch(filename, srb2path, wantedmd5sum, completepath, 10); if (homecheck == FS_FOUND) // we found the file, so return that we have :) return FS_FOUND; @@ -1226,7 +1226,7 @@ filestatus_t findfile(char *filename, const UINT8 *wantedmd5sum, boolean complet // if not found at all, just move on without doing anything // finally check "." directory - homecheck = filesearch(filename, ".", wantedmd5sum, completepath, 10, true); + homecheck = filesearch(filename, ".", wantedmd5sum, completepath, 10); if (homecheck != FS_NOTFOUND) // if not found this time, fall back on the below return statement return homecheck; // otherwise return the result we got diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index 9c3a9f2d2..1fe81e165 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -1899,7 +1899,7 @@ static const char *searchWad(const char *searchDir) filestatus_t fstemp; strcpy(tempsw, WADKEYWORD1); - fstemp = filesearch(tempsw, searchDir, NULL, true, 20, true); + fstemp = filesearch(tempsw, searchDir, NULL, true, 20); if (fstemp == FS_FOUND) { pathonly(tempsw); @@ -1907,7 +1907,7 @@ static const char *searchWad(const char *searchDir) } strcpy(tempsw, WADKEYWORD2); - fstemp = filesearch(tempsw, searchDir, NULL, true, 20, true); + fstemp = filesearch(tempsw, searchDir, NULL, true, 20); if (fstemp == FS_FOUND) { pathonly(tempsw); diff --git a/src/filesrch.c b/src/filesrch.c index 74ff1ef53..55b04aadc 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -391,7 +391,7 @@ static const char *exclude_paths[] = { }; #endif -filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *wantedmd5sum, boolean completepath, int maxsearchdepth, boolean skipexclude) +filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *wantedmd5sum, boolean completepath, int maxsearchdepth) { filestatus_t retval = FS_NOTFOUND; DIR **dirhandle; @@ -404,7 +404,7 @@ filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *want int depthleft = maxsearchdepth; char searchpath[1024]; size_t *searchpathindex; - boolean folderchanged = true; + boolean folderchanged = true; // tells us if we changed folders during traversal dirhandle = (DIR**)malloc(maxsearchdepth * sizeof(DIR*)); searchpathindex = (size_t *)malloc(maxsearchdepth * sizeof(size_t)); @@ -453,7 +453,7 @@ filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *want } // skip some folders that wont have addons in them - if (skipexclude && folderchanged) + if (folderchanged) { boolean skipfolder = false; @@ -500,7 +500,6 @@ filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *want } // Linux and FreeBSD has a special field for file type on dirent, so use that to speed up lookups. - // FIXME: should we also follow symlinks? if ((dent->d_type == DT_DIR && depthleft) || (dent->d_type == DT_LNK && depthleft)) #elif defined (_WIN32) // if we wanna follow symlinks we can check with FILE_ATTRIBUTE_REPARSE_POINT diff --git a/src/filesrch.h b/src/filesrch.h index d2cba7272..697020c54 100644 --- a/src/filesrch.h +++ b/src/filesrch.h @@ -24,14 +24,13 @@ extern consvar_t cv_addons_option, cv_addons_folder, cv_addons_md5, cv_addons_sh \param wantedmd5sum want to check with MD5 \param completepath want to return the complete path of the file? \param maxsearchdepth the max depth to search for the file - \param skipexclude when true this skips certain named folders \return filestatus_t */ -filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *wantedmd5sum, boolean completepath, int maxsearchdepth, boolean skipexclude); +filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *wantedmd5sum, boolean completepath, int maxsearchdepth); #define menudepth 20 diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 2dc371015..e2c7801f2 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -2486,7 +2486,7 @@ static const char *searchWad(const char *searchDir) filestatus_t fstemp; strcpy(tempsw, WADKEYWORD1); - fstemp = filesearch(tempsw, searchDir, NULL, true, 20, true); + fstemp = filesearch(tempsw, searchDir, NULL, true, 20); if (fstemp == FS_FOUND) { pathonly(tempsw); diff --git a/src/sdl/i_ttf.c b/src/sdl/i_ttf.c index ebfc50d4a..f2cd497ee 100644 --- a/src/sdl/i_ttf.c +++ b/src/sdl/i_ttf.c @@ -58,7 +58,7 @@ static char *searchFont(const char *fontsearchDir) filestatus_t fstemp; strcpy(tempsw, FONTFILE); - fstemp = filesearch(tempsw, fontsearchDir, NULL, true, 20, true); + fstemp = filesearch(tempsw, fontsearchDir, NULL, true, 20); if (fstemp == FS_FOUND) { return tempsw;