Clean up autodetected game install search paths on all platforms that use them.

This should prevent Lunar Apocalypse from becoming Nuclear Winter with Megaton on Linux and Mac.

git-svn-id: https://svn.eduke32.com/eduke32@4886 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2015-01-08 15:14:47 +00:00
parent 1f3ce84585
commit e3de98e2ae
4 changed files with 57 additions and 55 deletions

View file

@ -25,8 +25,10 @@ void agecache(void);
extern int32_t pathsearchmode; // 0 = gamefs mode (default), 1 = localfs mode (editor's mode) extern int32_t pathsearchmode; // 0 = gamefs mode (default), 1 = localfs mode (editor's mode)
char *listsearchpath(int32_t initp); char *listsearchpath(int32_t initp);
int32_t addsearchpath(const char *p); #define addsearchpath(a) addsearchpath_user(a, 0)
int32_t addsearchpath_user(const char *p, int32_t user);
int32_t removesearchpath(const char *p); int32_t removesearchpath(const char *p);
void removesearchpaths_withuser(int32_t usermask);
int32_t findfrompath(const char *fn, char **where); int32_t findfrompath(const char *fn, char **where);
int32_t openfrompath(const char *fn, int32_t flags, int32_t mode); int32_t openfrompath(const char *fn, int32_t flags, int32_t mode);
BFILE *fopenfrompath(const char *fn, const char *mode); BFILE *fopenfrompath(const char *fn, const char *mode);

View file

@ -334,6 +334,7 @@ typedef struct _searchpath
struct _searchpath *next; struct _searchpath *next;
char *path; char *path;
size_t pathlen; // to save repeated calls to strlen() size_t pathlen; // to save repeated calls to strlen()
int32_t user;
} searchpath_t; } searchpath_t;
static searchpath_t *searchpathhead = NULL; static searchpath_t *searchpathhead = NULL;
static size_t maxsearchpathlen = 0; static size_t maxsearchpathlen = 0;
@ -351,7 +352,7 @@ char *listsearchpath(int32_t initp)
return sp ? sp->path : NULL; return sp ? sp->path : NULL;
} }
int32_t addsearchpath(const char *p) int32_t addsearchpath_user(const char *p, int32_t user)
{ {
struct Bstat st; struct Bstat st;
char *s; char *s;
@ -392,6 +393,8 @@ int32_t addsearchpath(const char *p)
Bcorrectfilename(srch->path,0); Bcorrectfilename(srch->path,0);
srch->user = user;
initprintf("Using %s for game data\n", srch->path); initprintf("Using %s for game data\n", srch->path);
Bfree(path); Bfree(path);
@ -450,6 +453,34 @@ int32_t removesearchpath(const char *p)
return 0; return 0;
} }
void removesearchpaths_withuser(int32_t usermask)
{
for (searchpath_t *srch = searchpathhead; srch; srch = srch->next)
{
if (srch->user & usermask)
{
if (srch == searchpathhead)
searchpathhead = srch->next;
else
{
searchpath_t *sp;
for (sp = searchpathhead; sp; sp = sp->next)
{
if (sp->next == srch)
{
sp->next = srch->next;
break;
}
}
}
Bfree(srch->path);
Bfree(srch);
}
}
}
int32_t findfrompath(const char *fn, char **where) int32_t findfrompath(const char *fn, char **where)
{ {
searchpath_t *sp; searchpath_t *sp;

View file

@ -609,23 +609,23 @@ static void G_AddSteamPaths(const char *basepath)
char buf[BMAX_PATH]; char buf[BMAX_PATH];
Bsnprintf(buf, sizeof(buf), "%s/steamapps/common/Duke Nukem 3D/gameroot", basepath); Bsnprintf(buf, sizeof(buf), "%s/steamapps/common/Duke Nukem 3D/gameroot", basepath);
addsearchpath(buf); addsearchpath_user(buf, SEARCHPATH_REMOVE);
Bsnprintf(buf, sizeof(buf), "%s/steamapps/common/Duke Nukem 3D/gameroot/addons/dc", basepath); Bsnprintf(buf, sizeof(buf), "%s/steamapps/common/Duke Nukem 3D/gameroot/addons/dc", basepath);
addsearchpath(buf); addsearchpath_user(buf, SEARCHPATH_REMOVE);
Bsnprintf(buf, sizeof(buf), "%s/steamapps/common/Duke Nukem 3D/gameroot/addons/nw", basepath); Bsnprintf(buf, sizeof(buf), "%s/steamapps/common/Duke Nukem 3D/gameroot/addons/nw", basepath);
addsearchpath(buf); addsearchpath_user(buf, SEARCHPATH_REMOVE);
Bsnprintf(buf, sizeof(buf), "%s/steamapps/common/Duke Nukem 3D/gameroot/addons/vacation", basepath); Bsnprintf(buf, sizeof(buf), "%s/steamapps/common/Duke Nukem 3D/gameroot/addons/vacation", basepath);
addsearchpath(buf); addsearchpath_user(buf, SEARCHPATH_REMOVE);
#if defined __APPLE__ #if defined __APPLE__
Bsnprintf(buf, sizeof(buf), "%s/steamapps/common/Nam/Nam.app/Contents/Resources/Nam.boxer/C.harddisk/NAM", basepath); Bsnprintf(buf, sizeof(buf), "%s/steamapps/common/Nam/Nam.app/Contents/Resources/Nam.boxer/C.harddisk/NAM", basepath);
#else #else
Bsnprintf(buf, sizeof(buf), "%s/steamapps/common/Nam/NAM", basepath); Bsnprintf(buf, sizeof(buf), "%s/steamapps/common/Nam/NAM", basepath);
#endif #endif
addsearchpath(buf); addsearchpath_user(buf, SEARCHPATH_NAM);
} }
// A bare-bones "parser" for Valve's KeyValues VDF format. // A bare-bones "parser" for Valve's KeyValues VDF format.
@ -829,7 +829,7 @@ void G_AddSearchPaths(void)
G_ParseSteamKeyValuesForPaths(buf); G_ParseSteamKeyValuesForPaths(buf);
Bsnprintf(buf, sizeof(buf), "%s/Duke Nukem 3D.app/Contents/Resources/Duke Nukem 3D.boxer/C.harddisk", applications[i]); Bsnprintf(buf, sizeof(buf), "%s/Duke Nukem 3D.app/Contents/Resources/Duke Nukem 3D.boxer/C.harddisk", applications[i]);
addsearchpath(buf); addsearchpath_user(buf, SEARCHPATH_REMOVE);
} }
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
@ -852,83 +852,47 @@ void G_AddSearchPaths(void)
if ((instpath = G_GetInstallPath(INSTPATH_STEAM_DUKE3D))) if ((instpath = G_GetInstallPath(INSTPATH_STEAM_DUKE3D)))
{ {
Bsnprintf(buf, sizeof(buf), "%s/gameroot", instpath); Bsnprintf(buf, sizeof(buf), "%s/gameroot", instpath);
addsearchpath(buf); addsearchpath_user(buf, SEARCHPATH_REMOVE);
Bsnprintf(buf, sizeof(buf), "%s/gameroot/addons/dc", instpath); Bsnprintf(buf, sizeof(buf), "%s/gameroot/addons/dc", instpath);
addsearchpath(buf); addsearchpath_user(buf, SEARCHPATH_REMOVE);
Bsnprintf(buf, sizeof(buf), "%s/gameroot/addons/nw", instpath); Bsnprintf(buf, sizeof(buf), "%s/gameroot/addons/nw", instpath);
addsearchpath(buf); addsearchpath_user(buf, SEARCHPATH_REMOVE);
Bsnprintf(buf, sizeof(buf), "%s/gameroot/addons/vacation", instpath); Bsnprintf(buf, sizeof(buf), "%s/gameroot/addons/vacation", instpath);
addsearchpath(buf); addsearchpath_user(buf, SEARCHPATH_REMOVE);
} }
if ((instpath = G_GetInstallPath(INSTPATH_GOG_DUKE3D))) if ((instpath = G_GetInstallPath(INSTPATH_GOG_DUKE3D)))
addsearchpath(instpath); addsearchpath_user(instpath, SEARCHPATH_REMOVE);
if ((instpath = G_GetInstallPath(INSTPATH_3DR_DUKE3D))) if ((instpath = G_GetInstallPath(INSTPATH_3DR_DUKE3D)))
{ {
Bsnprintf(buf, sizeof(buf), "%s/Duke Nukem 3D", instpath); Bsnprintf(buf, sizeof(buf), "%s/Duke Nukem 3D", instpath);
addsearchpath(buf); addsearchpath_user(buf, SEARCHPATH_REMOVE);
} }
if ((instpath = G_GetInstallPath(INSTPATH_3DR_ANTH))) if ((instpath = G_GetInstallPath(INSTPATH_3DR_ANTH)))
{ {
Bsnprintf(buf, sizeof(buf), "%s/Duke Nukem 3D", instpath); Bsnprintf(buf, sizeof(buf), "%s/Duke Nukem 3D", instpath);
addsearchpath(buf); addsearchpath_user(buf, SEARCHPATH_REMOVE);
} }
if ((instpath = G_GetInstallPath(INSTPATH_STEAM_NAM))) if ((instpath = G_GetInstallPath(INSTPATH_STEAM_NAM)))
{ {
Bsnprintf(buf, sizeof(buf), "%s/NAM", instpath); Bsnprintf(buf, sizeof(buf), "%s/NAM", instpath);
addsearchpath(buf); addsearchpath_user(buf, SEARCHPATH_NAM);
} }
#endif #endif
} }
void G_CleanupSearchPaths(void) void G_CleanupSearchPaths(void)
{ {
#ifdef _WIN32 removesearchpaths_withuser(SEARCHPATH_REMOVE);
char buf[BMAX_PATH];
const char* instpath;
if ((instpath = G_GetInstallPath(INSTPATH_STEAM_DUKE3D))) if (!(NAM || NAPALM))
{ removesearchpaths_withuser(SEARCHPATH_NAM);
Bsnprintf(buf, sizeof(buf), "%s/gameroot", instpath);
removesearchpath(buf);
Bsnprintf(buf, sizeof(buf), "%s/gameroot/addons/dc", instpath);
removesearchpath(buf);
Bsnprintf(buf, sizeof(buf), "%s/gameroot/addons/nw", instpath);
removesearchpath(buf);
Bsnprintf(buf, sizeof(buf), "%s/gameroot/addons/vacation", instpath);
removesearchpath(buf);
}
if ((instpath = G_GetInstallPath(INSTPATH_GOG_DUKE3D)))
removesearchpath(instpath);
if ((instpath = G_GetInstallPath(INSTPATH_3DR_DUKE3D)))
{
Bsnprintf(buf, sizeof(buf), "%s/Duke Nukem 3D", instpath);
removesearchpath(buf);
}
if ((instpath = G_GetInstallPath(INSTPATH_3DR_ANTH)))
{
Bsnprintf(buf, sizeof(buf), "%s/Duke Nukem 3D", instpath);
removesearchpath(buf);
}
if (g_gameType != GAMEFLAG_NAM && (instpath = G_GetInstallPath(INSTPATH_STEAM_NAM)))
{
Bsnprintf(buf, sizeof(buf), "%s/NAM", instpath);
removesearchpath(buf);
}
#endif
} }
////////// //////////

View file

@ -50,6 +50,11 @@ enum instpath_t {
NUMINSTPATHS NUMINSTPATHS
}; };
enum searchpathtypes_t {
SEARCHPATH_REMOVE = 1<<0,
SEARCHPATH_NAM = 1<<1,
};
typedef enum basepal_ { typedef enum basepal_ {
BASEPAL = 0, BASEPAL = 0,
WATERPAL, WATERPAL,