findfile aggressive optimisation: If srb2home and srb2path are the current working directory, don't search in them

srb2path will report "." while this optimisation is in play, but this can be disabled if necessary by modifying the small #if (1) in IdentifyVersion
This commit is contained in:
toaster 2025-08-25 21:00:44 +01:00
parent 48261ae4b5
commit 2b2b20718f
2 changed files with 33 additions and 21 deletions

View file

@ -1395,19 +1395,25 @@ static void IdentifyVersion(void)
srb2waddir = I_LocateWad();
#endif
char tempsrb2path[256] = ".";
getcwd(tempsrb2path, 256);
// get the current directory (possible problem on NT with "." as current dir)
if (srb2waddir)
if (!srb2waddir)
{
strlcpy(srb2path,srb2waddir,sizeof (srb2path));
}
else
{
if (getcwd(srb2path, 256) != NULL)
srb2waddir = srb2path;
if (tempsrb2path[0])
srb2waddir = tempsrb2path;
else
srb2waddir = ".";
}
#if (1) // reduce the amount of findfile by only using full cwd in this func
if (strcmp(tempsrb2path, srb2waddir))
#endif
{
strlcpy(srb2path, srb2waddir, sizeof (srb2path));
}
// Load the IWAD
if (! AddIWAD())
{

View file

@ -1764,23 +1764,29 @@ filestatus_t findfile(char *filename, const char *priorityfolder, const UINT8 *w
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, priorityfolder, wantedmd5sum, completepath, 10);
// first, check SRB2's "home" directory (if non-'.')
if (strcmp(srb2home, "."))
{
homecheck = filesearch(filename, srb2home, priorityfolder, 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 (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, priorityfolder, wantedmd5sum, completepath, 10);
// next, check SRB2's "path" directory (also if non-'.')
if (strcmp(srb2path, "."))
{
homecheck = filesearch(filename, srb2path, priorityfolder, 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 (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, ".", priorityfolder, wantedmd5sum, completepath, 10);