speedup addon search
by adding a blacklist of folders logs, luafiles, replay etc shouldnt ever contain addons so those can be skipped entirely this massively speeds up searching for addons on windows also will make findfile try to search in the designated addon folders first so it doesent look in the home or kart folders before it this is probably not the best way to do things but idk what im even doing, im not a coder just some chao who likes to sleep all day
This commit is contained in:
1 parent
4fc780298f
commit
bbb4749815
6 files changed
+110
-36
No files matched your search
+44
-22
@@ -1173,28 +1173,32 @@ filestatus_t findfile(char *filename, const UINT8 *wantedmd5sum, boolean complet
|
||||
filestatus_t homecheck; // store result of last file search
|
||||
boolean badmd5 = false; // store whether md5 was bad from either of the first two searches (if nothing was found in the third)
|
||||
|
||||
// first, check SRB2's "home" directory
|
||||
homecheck = filesearch(filename, srb2home, wantedmd5sum, completepath, 10);
|
||||
|
||||
if (homecheck == FS_FOUND) // we found the file, so return that we have :)
|
||||
return FS_FOUND;
|
||||
else if (homecheck == FS_MD5SUMBAD) // file has a bad md5; move on and look for a file with the right md5
|
||||
badmd5 = true;
|
||||
// if not found at all, just move on without doing anything
|
||||
|
||||
// next, check SRB2's "path" directory
|
||||
homecheck = filesearch(filename, srb2path, wantedmd5sum, completepath, 10);
|
||||
|
||||
if (homecheck == FS_FOUND) // we found the file, so return that we have :)
|
||||
return FS_FOUND;
|
||||
else if (homecheck == FS_MD5SUMBAD) // file has a bad md5; move on and look for a file with the right md5
|
||||
badmd5 = true;
|
||||
// if not found at all, just move on without doing anything
|
||||
|
||||
if (cv_addons_option.value == 3 && *cv_addons_folder.string != '\0')
|
||||
// skip for startup, our mainwads wont be in there
|
||||
if (loaded_config)
|
||||
{
|
||||
// next, check any custom directory if specified
|
||||
homecheck = filesearch(filename, cv_addons_folder.string, wantedmd5sum, completepath, 10);
|
||||
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);
|
||||
|
||||
if (homecheck == FS_FOUND) // we found the file, so return that we have :)
|
||||
return FS_FOUND;
|
||||
else if (homecheck == FS_MD5SUMBAD) // file has a bad md5; move on and look for a file with the right md5
|
||||
badmd5 = true;
|
||||
// if not found at all, just move on without doing anything
|
||||
}
|
||||
|
||||
// next, check "DOWNLOAD" directory
|
||||
homecheck = filesearch(filename, "DOWNLOAD", wantedmd5sum, completepath, 10, false);
|
||||
|
||||
if (homecheck == FS_FOUND) // we found the file, so return that we have :)
|
||||
return FS_FOUND;
|
||||
else if (homecheck == FS_MD5SUMBAD) // file has a bad md5; move on and look for a file with the right md5
|
||||
badmd5 = true;
|
||||
// if not found at all, just move on without doing anything
|
||||
|
||||
// next, check "addons" directory
|
||||
homecheck = filesearch(filename, "addons", wantedmd5sum, completepath, 10, false);
|
||||
|
||||
if (homecheck == FS_FOUND) // we found the file, so return that we have :)
|
||||
return FS_FOUND;
|
||||
@@ -1203,8 +1207,26 @@ 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 "home" directory
|
||||
homecheck = filesearch(filename, srb2home, wantedmd5sum, completepath, 10, true);
|
||||
|
||||
if (homecheck == FS_FOUND) // we found the file, so return that we have :)
|
||||
return FS_FOUND;
|
||||
else if (homecheck == FS_MD5SUMBAD) // file has a bad md5; move on and look for a file with the right md5
|
||||
badmd5 = true;
|
||||
// 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);
|
||||
|
||||
if (homecheck == FS_FOUND) // we found the file, so return that we have :)
|
||||
return FS_FOUND;
|
||||
else if (homecheck == FS_MD5SUMBAD) // file has a bad md5; move on and look for a file with the right md5
|
||||
badmd5 = true;
|
||||
// if not found at all, just move on without doing anything
|
||||
|
||||
// finally check "." directory
|
||||
homecheck = filesearch(filename, ".", wantedmd5sum, completepath, 10);
|
||||
homecheck = filesearch(filename, ".", wantedmd5sum, completepath, 10, true);
|
||||
|
||||
if (homecheck != FS_NOTFOUND) // if not found this time, fall back on the below return statement
|
||||
return homecheck; // otherwise return the result we got
|
||||
|
||||
@@ -1862,7 +1862,7 @@ static const char *searchWad(const char *searchDir)
|
||||
filestatus_t fstemp;
|
||||
|
||||
strcpy(tempsw, WADKEYWORD1);
|
||||
fstemp = filesearch(tempsw,searchDir,NULL,true,20);
|
||||
fstemp = filesearch(tempsw, searchDir, NULL, true, 20, true);
|
||||
if (fstemp == FS_FOUND)
|
||||
{
|
||||
pathonly(tempsw);
|
||||
@@ -1870,7 +1870,7 @@ static const char *searchWad(const char *searchDir)
|
||||
}
|
||||
|
||||
strcpy(tempsw, WADKEYWORD2);
|
||||
fstemp = filesearch(tempsw, searchDir, NULL, true, 20);
|
||||
fstemp = filesearch(tempsw, searchDir, NULL, true, 20, true);
|
||||
if (fstemp == FS_FOUND)
|
||||
{
|
||||
pathonly(tempsw);
|
||||
|
||||
+60
-8
@@ -12,6 +12,7 @@
|
||||
/// FS_MD5SUMBAD;
|
||||
/// FS_FOUND
|
||||
|
||||
#include "d_main.h"
|
||||
#include <stdio.h>
|
||||
#ifdef __GNUC__
|
||||
#include <dirent.h>
|
||||
@@ -353,34 +354,58 @@ INT32 pathisdirectory(const char *path)
|
||||
return 0;
|
||||
}
|
||||
|
||||
filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *wantedmd5sum, boolean completepath, int maxsearchdepth)
|
||||
// skip those folders, they will not have any addons
|
||||
#ifdef _WIN32
|
||||
static const char *exclude_paths[] = {
|
||||
"\\logs\\",
|
||||
"\\luafiles\\",
|
||||
"\\replay\\",
|
||||
"\\mdls\\",
|
||||
"\\gifs\\",
|
||||
"\\screenshots\\",
|
||||
NULL
|
||||
};
|
||||
#else
|
||||
static const char *exclude_paths[] = {
|
||||
"/logs/",
|
||||
"/luafiles/",
|
||||
"/replay/",
|
||||
"/mdls/",
|
||||
"/gifs/",
|
||||
"/screenshots/",
|
||||
NULL
|
||||
};
|
||||
#endif
|
||||
|
||||
filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *wantedmd5sum, boolean completepath, int maxsearchdepth, boolean skipexclude)
|
||||
{
|
||||
filestatus_t retval = FS_NOTFOUND;
|
||||
DIR **dirhandle;
|
||||
struct dirent *dent;
|
||||
struct stat fsstat;
|
||||
int found = 0;
|
||||
char *searchname = strdup(filename);
|
||||
char *searchname;
|
||||
int depthleft = maxsearchdepth;
|
||||
char searchpath[1024];
|
||||
size_t *searchpathindex;
|
||||
|
||||
dirhandle = (DIR**) malloc(maxsearchdepth * sizeof(DIR*));
|
||||
searchpathindex = (size_t *) malloc(maxsearchdepth * sizeof(size_t));
|
||||
dirhandle = (DIR**)malloc(maxsearchdepth * sizeof(DIR*));
|
||||
searchpathindex = (size_t *)malloc(maxsearchdepth * sizeof(size_t));
|
||||
|
||||
strcpy(searchpath,startpath);
|
||||
strcpy(searchpath, startpath);
|
||||
searchpathindex[--depthleft] = strlen(searchpath) + 1;
|
||||
|
||||
dirhandle[depthleft] = opendir(searchpath);
|
||||
|
||||
if (dirhandle[depthleft] == NULL)
|
||||
{
|
||||
free(searchname);
|
||||
free(dirhandle);
|
||||
free(searchpathindex);
|
||||
return FS_NOTFOUND;
|
||||
}
|
||||
|
||||
searchname = strdup(filename);
|
||||
|
||||
if (searchpath[searchpathindex[depthleft]-2] != PATHSEP[0])
|
||||
{
|
||||
searchpath[searchpathindex[depthleft]-1] = PATHSEP[0];
|
||||
@@ -409,6 +434,33 @@ filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *want
|
||||
continue;
|
||||
}
|
||||
|
||||
// skip some folders that wont have addons in them
|
||||
if (skipexclude)
|
||||
{
|
||||
boolean skipfolder = false;
|
||||
|
||||
for (const char **path = exclude_paths; *path != NULL; path++)
|
||||
{
|
||||
if (**path == '\0')
|
||||
continue;
|
||||
#ifdef _WIN32
|
||||
if (strstr(searchpath, *path)) // windows doesent care if lower or uppercase
|
||||
#else
|
||||
if (strcasestr(searchpath, *path))
|
||||
#endif
|
||||
{
|
||||
skipfolder = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (skipfolder)
|
||||
{
|
||||
closedir(dirhandle[depthleft++]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// okay, now we actually want searchpath to incorporate d_name
|
||||
strcpy(&searchpath[searchpathindex[depthleft]], dent->d_name);
|
||||
|
||||
@@ -423,7 +475,7 @@ filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *want
|
||||
|
||||
// Symlinks aren't always directory symlinks. Dunno if this would resolve recursive
|
||||
// symlinks, but i think stat already does that
|
||||
if (dent->d_type == DT_LNK && stat(searchpath,&fsstat) == 0 && !S_ISDIR(fsstat.st_mode))
|
||||
if (dent->d_type == DT_LNK && stat(searchpath, &fsstat) == 0 && !S_ISDIR(fsstat.st_mode))
|
||||
{
|
||||
dent->d_type = DT_UNKNOWN;
|
||||
}
|
||||
@@ -432,7 +484,7 @@ filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *want
|
||||
// FIXME: should we also follow symlinks?
|
||||
if ((dent->d_type == DT_DIR && depthleft) || (dent->d_type == DT_LNK && depthleft))
|
||||
#else
|
||||
if (stat(searchpath,&fsstat) < 0) // do we want to follow symlinks? if not: change it to lstat
|
||||
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
|
||||
|
||||
+2
-2
@@ -24,14 +24,14 @@ 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);
|
||||
filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *wantedmd5sum, boolean completepath, int maxsearchdepth, boolean skipexclude);
|
||||
|
||||
#define menudepth 20
|
||||
|
||||
|
||||
@@ -2458,7 +2458,7 @@ static const char *searchWad(const char *searchDir)
|
||||
filestatus_t fstemp;
|
||||
|
||||
strcpy(tempsw, WADKEYWORD1);
|
||||
fstemp = filesearch(tempsw,searchDir,NULL,true,20);
|
||||
fstemp = filesearch(tempsw, searchDir, NULL, true, 20, true);
|
||||
if (fstemp == FS_FOUND)
|
||||
{
|
||||
pathonly(tempsw);
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ static char *searchFont(const char *fontsearchDir)
|
||||
filestatus_t fstemp;
|
||||
|
||||
strcpy(tempsw, FONTFILE);
|
||||
fstemp = filesearch(tempsw, fontsearchDir, NULL, true, 20);
|
||||
fstemp = filesearch(tempsw, fontsearchDir, NULL, true, 20, true);
|
||||
if (fstemp == FS_FOUND)
|
||||
{
|
||||
return tempsw;
|
||||
|
||||
Reference in new issue
Block a user