mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-03-23 19:31:05 +00:00
Merge branch 'better-wad-search' into 'next'
Clean up the WAD searching code a little. See merge request STJr/SRB2!1678
This commit is contained in:
commit
21808e883b
1 changed files with 55 additions and 93 deletions
|
@ -143,21 +143,32 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T);
|
|||
#define UNIXBACKTRACE
|
||||
#endif
|
||||
|
||||
// Locations for searching the srb2.pk3
|
||||
// Locations to directly check for srb2.pk3 in
|
||||
const char *wadDefaultPaths[] = {
|
||||
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
|
||||
#define DEFAULTWADLOCATION1 "/usr/local/share/games/SRB2"
|
||||
#define DEFAULTWADLOCATION2 "/usr/local/games/SRB2"
|
||||
#define DEFAULTWADLOCATION3 "/usr/share/games/SRB2"
|
||||
#define DEFAULTWADLOCATION4 "/usr/games/SRB2"
|
||||
#define DEFAULTSEARCHPATH1 "/usr/local/games"
|
||||
#define DEFAULTSEARCHPATH2 "/usr/games"
|
||||
#define DEFAULTSEARCHPATH3 "/usr/local"
|
||||
"/usr/local/share/games/SRB2",
|
||||
"/usr/local/games/SRB2",
|
||||
"/usr/share/games/SRB2",
|
||||
"/usr/games/SRB2",
|
||||
#elif defined (_WIN32)
|
||||
#define DEFAULTWADLOCATION1 "c:\\games\\srb2"
|
||||
#define DEFAULTWADLOCATION2 "\\games\\srb2"
|
||||
#define DEFAULTSEARCHPATH1 "c:\\games"
|
||||
#define DEFAULTSEARCHPATH2 "\\games"
|
||||
"c:\\games\\srb2",
|
||||
"\\games\\srb2",
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
||||
// Folders to recurse through looking for srb2.pk3
|
||||
const char *wadSearchPaths[] = {
|
||||
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
|
||||
"/usr/local/games",
|
||||
"/usr/games",
|
||||
"/usr/local",
|
||||
#elif defined (_WIN32)
|
||||
"c:\\games",
|
||||
"\\games",
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
||||
/** \brief WAD file to look for
|
||||
*/
|
||||
|
@ -2808,6 +2819,20 @@ static const char *searchWad(const char *searchDir)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#define CHECKWADPATH(ret) \
|
||||
do { \
|
||||
I_OutputMsg(",%s", returnWadPath); \
|
||||
if (isWadPathOk(returnWadPath)) \
|
||||
return ret; \
|
||||
} while (0)
|
||||
|
||||
#define SEARCHWAD(str) \
|
||||
do { \
|
||||
WadPath = searchWad(str); \
|
||||
if (WadPath) \
|
||||
return WadPath; \
|
||||
} while (0)
|
||||
|
||||
/** \brief go through all possible paths and look for srb2.pk3
|
||||
|
||||
\return path to srb2.pk3 if any
|
||||
|
@ -2816,6 +2841,7 @@ static const char *locateWad(void)
|
|||
{
|
||||
const char *envstr;
|
||||
const char *WadPath;
|
||||
int i;
|
||||
|
||||
I_OutputMsg("SRB2WADDIR");
|
||||
// does SRB2WADDIR exist?
|
||||
|
@ -2823,108 +2849,44 @@ static const char *locateWad(void)
|
|||
return envstr;
|
||||
|
||||
#ifndef NOCWD
|
||||
I_OutputMsg(",.");
|
||||
// examine current dir
|
||||
strcpy(returnWadPath, ".");
|
||||
if (isWadPathOk(returnWadPath))
|
||||
return NULL;
|
||||
CHECKWADPATH(NULL);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef CMAKECONFIG
|
||||
#ifndef NDEBUG
|
||||
I_OutputMsg(","CMAKE_ASSETS_DIR);
|
||||
strcpy(returnWadPath, CMAKE_ASSETS_DIR);
|
||||
if (isWadPathOk(returnWadPath))
|
||||
{
|
||||
return returnWadPath;
|
||||
}
|
||||
CHECKWADPATH(returnWadPath);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
OSX_GetResourcesPath(returnWadPath);
|
||||
I_OutputMsg(",%s", returnWadPath);
|
||||
if (isWadPathOk(returnWadPath))
|
||||
{
|
||||
return returnWadPath;
|
||||
}
|
||||
CHECKWADPATH(returnWadPath);
|
||||
#endif
|
||||
|
||||
// examine default dirs
|
||||
#ifdef DEFAULTWADLOCATION1
|
||||
I_OutputMsg(","DEFAULTWADLOCATION1);
|
||||
strcpy(returnWadPath, DEFAULTWADLOCATION1);
|
||||
if (isWadPathOk(returnWadPath))
|
||||
return returnWadPath;
|
||||
#endif
|
||||
#ifdef DEFAULTWADLOCATION2
|
||||
I_OutputMsg(","DEFAULTWADLOCATION2);
|
||||
strcpy(returnWadPath, DEFAULTWADLOCATION2);
|
||||
if (isWadPathOk(returnWadPath))
|
||||
return returnWadPath;
|
||||
#endif
|
||||
#ifdef DEFAULTWADLOCATION3
|
||||
I_OutputMsg(","DEFAULTWADLOCATION3);
|
||||
strcpy(returnWadPath, DEFAULTWADLOCATION3);
|
||||
if (isWadPathOk(returnWadPath))
|
||||
return returnWadPath;
|
||||
#endif
|
||||
#ifdef DEFAULTWADLOCATION4
|
||||
I_OutputMsg(","DEFAULTWADLOCATION4);
|
||||
strcpy(returnWadPath, DEFAULTWADLOCATION4);
|
||||
if (isWadPathOk(returnWadPath))
|
||||
return returnWadPath;
|
||||
#endif
|
||||
#ifdef DEFAULTWADLOCATION5
|
||||
I_OutputMsg(","DEFAULTWADLOCATION5);
|
||||
strcpy(returnWadPath, DEFAULTWADLOCATION5);
|
||||
if (isWadPathOk(returnWadPath))
|
||||
return returnWadPath;
|
||||
#endif
|
||||
#ifdef DEFAULTWADLOCATION6
|
||||
I_OutputMsg(","DEFAULTWADLOCATION6);
|
||||
strcpy(returnWadPath, DEFAULTWADLOCATION6);
|
||||
if (isWadPathOk(returnWadPath))
|
||||
return returnWadPath;
|
||||
#endif
|
||||
#ifdef DEFAULTWADLOCATION7
|
||||
I_OutputMsg(","DEFAULTWADLOCATION7);
|
||||
strcpy(returnWadPath, DEFAULTWADLOCATION7);
|
||||
if (isWadPathOk(returnWadPath))
|
||||
return returnWadPath;
|
||||
#endif
|
||||
for (i = 0; wadDefaultPaths[i]; i++)
|
||||
{
|
||||
strcpy(returnWadPath, wadDefaultPaths[i]);
|
||||
CHECKWADPATH(returnWadPath);
|
||||
}
|
||||
|
||||
#ifndef NOHOME
|
||||
// find in $HOME
|
||||
I_OutputMsg(",HOME");
|
||||
if ((envstr = I_GetEnv("HOME")) != NULL)
|
||||
SEARCHWAD(envstr);
|
||||
#endif
|
||||
|
||||
// search paths
|
||||
for (i = 0; wadSearchPaths[i]; i++)
|
||||
{
|
||||
WadPath = searchWad(envstr);
|
||||
if (WadPath)
|
||||
return WadPath;
|
||||
I_OutputMsg(", in:%s", wadSearchPaths[i]);
|
||||
SEARCHWAD(wadSearchPaths[i]);
|
||||
}
|
||||
#endif
|
||||
#ifdef DEFAULTSEARCHPATH1
|
||||
// find in /usr/local
|
||||
I_OutputMsg(", in:"DEFAULTSEARCHPATH1);
|
||||
WadPath = searchWad(DEFAULTSEARCHPATH1);
|
||||
if (WadPath)
|
||||
return WadPath;
|
||||
#endif
|
||||
#ifdef DEFAULTSEARCHPATH2
|
||||
// find in /usr/games
|
||||
I_OutputMsg(", in:"DEFAULTSEARCHPATH2);
|
||||
WadPath = searchWad(DEFAULTSEARCHPATH2);
|
||||
if (WadPath)
|
||||
return WadPath;
|
||||
#endif
|
||||
#ifdef DEFAULTSEARCHPATH3
|
||||
// find in ???
|
||||
I_OutputMsg(", in:"DEFAULTSEARCHPATH3);
|
||||
WadPath = searchWad(DEFAULTSEARCHPATH3);
|
||||
if (WadPath)
|
||||
return WadPath;
|
||||
#endif
|
||||
|
||||
// if nothing was found
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue