diff --git a/polymer/eduke32/build/include/cache1d.h b/polymer/eduke32/build/include/cache1d.h index ad9bba8fd..8d3571023 100644 --- a/polymer/eduke32/build/include/cache1d.h +++ b/polymer/eduke32/build/include/cache1d.h @@ -23,6 +23,7 @@ void agecache(void); extern int32_t pathsearchmode; // 0 = gamefs mode (default), 1 = localfs mode (editor's mode) int32_t addsearchpath(const char *p); +int32_t removesearchpath(const char *p); int32_t findfrompath(const char *fn, char **where); int32_t openfrompath(const char *fn, int32_t flags, int32_t mode); BFILE *fopenfrompath(const char *fn, const char *mode); diff --git a/polymer/eduke32/build/src/cache1d.c b/polymer/eduke32/build/src/cache1d.c index ad254cb52..86088c3c8 100644 --- a/polymer/eduke32/build/src/cache1d.c +++ b/polymer/eduke32/build/src/cache1d.c @@ -353,11 +353,9 @@ int32_t addsearchpath(const char *p) } Bstrcpy(srch->path, path); - for (s=srch->path; *s; s++) - { - /* do nothing */ - } + for (s=srch->path; *s; s++); s--; + if (spath || toupperlookup[*s] != '/') Bstrcat(srch->path, "/"); @@ -373,6 +371,58 @@ int32_t addsearchpath(const char *p) return 0; } +int32_t removesearchpath(const char *p) +{ + searchpath_t *srch; + char *s; + char *path = (char *)Bmalloc(Bstrlen(p) + 2); + + Bstrcpy(path, p); + + if (path[Bstrlen(path)-1] == '\\') + path[Bstrlen(path)-1] = 0; + + for (s=path; *s; s++); + s--; + + if (snext) + { + if (!Bstrncmp(path, srch->path, srch->pathlen)) + { +// initprintf("Removing %s from path stack\n", path); + + if (srch == searchpathhead) + searchpathhead = srch->next; + else + { + searchpath_t *sp; + + for (sp = searchpathhead; sp; sp = sp->next) + { + if (sp->next == srch) + { +// initprintf("matched %s\n", srch->path); + sp->next = srch->next; + break; + } + } + } + + Bfree(srch->path); + Bfree(srch); + break; + } + } + + Bfree(path); + return 0; +} + int32_t findfrompath(const char *fn, char **where) { searchpath_t *sp; diff --git a/polymer/eduke32/source/common.c b/polymer/eduke32/source/common.c index bc2477345..165d716e1 100644 --- a/polymer/eduke32/source/common.c +++ b/polymer/eduke32/source/common.c @@ -218,17 +218,28 @@ void G_ExtPreInit(void) } #ifdef _WIN32 -const char * G_GetSteamPath(void) +const char * G_GetInstallPath(int32_t insttype) { - static char spath[BMAX_PATH]; - static int32_t success = -1; + static char spath[NUMINSTPATHS][BMAX_PATH]; + static int32_t success[NUMINSTPATHS] = { -1, -1 }; int32_t siz = BMAX_PATH; - if (success == -1) - success = SHGetValueA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Steam App 225140", "InstallLocation", NULL, spath, (LPDWORD)&siz); + // this still needs to be fixed for win64 builds + if (success[insttype] == -1) + { + switch (insttype) + { + case INSTPATH_STEAM: + success[insttype] = SHGetValueA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Steam App 225140", "InstallLocation", NULL, spath[insttype], (LPDWORD)&siz); + break; + case INSTPATH_GOG: + success[insttype] = SHGetValueA(HKEY_LOCAL_MACHINE, "SOFTWARE\\GOG.com\\GOGDUKE3D", "PATH", NULL, spath[insttype], (LPDWORD)&siz); + break; + } + } - if (success == ERROR_SUCCESS) - return spath; + if (success[insttype] == ERROR_SUCCESS) + return spath[insttype]; return NULL; } @@ -247,21 +258,18 @@ void G_AddSearchPaths(void) #elif defined (_WIN32) // detect Steam and GOG versions of Duke3D char buf[BMAX_PATH]; - int32_t siz = BMAX_PATH, ret; - if (G_GetSteamPath()) + if (G_GetInstallPath(INSTPATH_STEAM)) { - Bsprintf(buf, "%s/gameroot/classic", G_GetSteamPath()); + Bsprintf(buf, "%s/gameroot", G_GetInstallPath(INSTPATH_STEAM)); addsearchpath(buf); - Bsprintf(buf, "%s/gameroot/addons", G_GetSteamPath()); + Bsprintf(buf, "%s/gameroot/addons", G_GetInstallPath(INSTPATH_STEAM)); addsearchpath(buf); } - ret = SHGetValueA(HKEY_LOCAL_MACHINE, "SOFTWARE\\GOG.com\\GOGDUKE3D", "PATH", NULL, buf, (LPDWORD)&siz); - - if (ret == ERROR_SUCCESS) - addsearchpath(buf); + if (G_GetInstallPath(INSTPATH_GOG)) + addsearchpath(G_GetInstallPath(INSTPATH_GOG)); #endif } diff --git a/polymer/eduke32/source/common_game.h b/polymer/eduke32/source/common_game.h index 83ef732ec..c99b1eeee 100644 --- a/polymer/eduke32/source/common_game.h +++ b/polymer/eduke32/source/common_game.h @@ -27,6 +27,12 @@ enum Games_t { GAMECOUNT }; +enum instpath_t { + INSTPATH_STEAM, + INSTPATH_GOG, + NUMINSTPATHS +}; + extern const char *defaultgamegrp[GAMECOUNT]; extern const char *defaultdeffilename[GAMECOUNT]; extern const char *defaultconfilename; @@ -55,4 +61,6 @@ extern void G_ExtPreInit(void); extern void G_AddSearchPaths(void); +extern const char * G_GetInstallPath(int32_t insttype); + #endif diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 8ecf445d8..24ad0215b 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -10452,6 +10452,20 @@ int32_t app_main(int32_t argc, const char **argv) } } +#ifdef _WIN32 + if (G_GetInstallPath(INSTPATH_STEAM)) + { + Bsprintf(buf, "%s/gameroot", G_GetInstallPath(INSTPATH_STEAM)); + removesearchpath(buf); + + Bsprintf(buf, "%s/gameroot/addons", G_GetInstallPath(INSTPATH_STEAM)); + removesearchpath(buf); + } + + if (G_GetInstallPath(INSTPATH_GOG)) + removesearchpath(G_GetInstallPath(INSTPATH_GOG)); +#endif + if (g_modDir[0] != '/') G_LoadGroupsInDir(g_modDir);