From 7e22c6d81c509dbac1c036fb128bccf5750bb9cb Mon Sep 17 00:00:00 2001 From: terminx Date: Wed, 27 Mar 2013 01:39:18 +0000 Subject: [PATCH] Read GOG.com and Steam Duke3D install paths from the registry instead of hard-coding the default paths. git-svn-id: https://svn.eduke32.com/eduke32@3615 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/Makefile.msvc | 2 +- polymer/eduke32/build/Makefile.shared | 2 +- polymer/eduke32/build/src/cache1d.c | 25 ++++++++++++++++++++----- polymer/eduke32/source/common.c | 20 ++++++++++++++++++-- 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/polymer/eduke32/Makefile.msvc b/polymer/eduke32/Makefile.msvc index ae501860e..d1a93af5c 100644 --- a/polymer/eduke32/Makefile.msvc +++ b/polymer/eduke32/Makefile.msvc @@ -58,7 +58,7 @@ CFLAGS= /MT /J /nologo $(flags_cl) \ /W2 $(ENGINEOPTS) \ /I$(VORBISSDK)\include /DRENDERTYPEWIN=1 -LIBS=user32.lib gdi32.lib shell32.lib winmm.lib ws2_32.lib comctl32.lib \ +LIBS=user32.lib gdi32.lib shell32.lib winmm.lib ws2_32.lib comctl32.lib shlwapi.lib \ vorbisfile_static.lib vorbis_static.lib ogg_static.lib dsound.lib advapi32.lib LIBS=/NODEFAULTLIB:glu32.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcrtd.lib /NODEFAULTLIB:libcmt.lib \ diff --git a/polymer/eduke32/build/Makefile.shared b/polymer/eduke32/build/Makefile.shared index 6940da6a0..3d6eb7322 100644 --- a/polymer/eduke32/build/Makefile.shared +++ b/polymer/eduke32/build/Makefile.shared @@ -106,7 +106,7 @@ ifeq ($(PLATFORM),WINDOWS) SDL_FRAMEWORK=1 BUILDCOMMONFLAGS+= -DHAVE_INTTYPES EXESUFFIX=.exe - BUILDLIBS+= -Wl,--enable-auto-import -mwindows -lmingwex -lcomctl32 -lwinmm $(L_SSP) -lwsock32 -lws2_32 + BUILDLIBS+= -Wl,--enable-auto-import -mwindows -lmingwex -lcomctl32 -lwinmm $(L_SSP) -lwsock32 -lws2_32 -lshlwapi #-lshfolder #BUILDLIBDIRS+= -L$(ENETROOT) #STDCPPLIB:=-lstdc++ diff --git a/polymer/eduke32/build/src/cache1d.c b/polymer/eduke32/build/src/cache1d.c index ca6293171..afea60870 100644 --- a/polymer/eduke32/build/src/cache1d.c +++ b/polymer/eduke32/build/src/cache1d.c @@ -318,27 +318,41 @@ int32_t addsearchpath(const char *p) struct Bstat st; char *s; searchpath_t *srch; + char *path = Bstrdup(p); - if (Bstat(p, &st) < 0) + if (path[Bstrlen(path)-1] == '\\') + path[Bstrlen(path)-1] = 0; // hack for stat() returning ENOENT on paths ending in \ + + if (Bstat(path, &st) < 0) { + Bfree(path); if (errno == ENOENT) return -2; return -1; } - if (!(st.st_mode & BS_IFDIR)) return -1; + if (!(st.st_mode & BS_IFDIR)) + { + Bfree(path); + return -1; + } srch = (searchpath_t *)Bmalloc(sizeof(searchpath_t)); - if (!srch) return -1; + if (!srch) + { + Bfree(path); + return -1; + } srch->next = searchpathhead; - srch->pathlen = Bstrlen(p)+1; + srch->pathlen = Bstrlen(path)+1; srch->path = (char *)Bmalloc(srch->pathlen + 1); if (!srch->path) { + Bfree(path); Bfree(srch); return -1; } - Bstrcpy(srch->path, p); + Bstrcpy(srch->path, path); for (s=srch->path; *s; s++) { /* do nothing */ @@ -355,6 +369,7 @@ int32_t addsearchpath(const char *p) initprintf("Using %s for game data\n", srch->path); + Bfree(path); return 0; } diff --git a/polymer/eduke32/source/common.c b/polymer/eduke32/source/common.c index 55e5d5e2f..c879502f2 100644 --- a/polymer/eduke32/source/common.c +++ b/polymer/eduke32/source/common.c @@ -12,6 +12,7 @@ #ifdef _WIN32 # include "winbits.h" +#include #endif #include "common.h" @@ -227,8 +228,23 @@ void G_AddSearchPaths(void) addsearchpath("/Library/Application Support/JFDuke3D"); addsearchpath("/Library/Application Support/EDuke32"); #elif defined (_WIN32) - addsearchpath_ProgramFiles("GOG.com/Duke Nukem 3D"); - addsearchpath_ProgramFiles("Steam/SteamApps/common/Duke Nukem 3D/gameroot"); + // detect Steam and GOG versions of Duke3D + char buf[BMAX_PATH]; + int32_t siz = BMAX_PATH, ret; + + ret = SHGetValueA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Steam App 225140", "InstallLocation", NULL, buf, (LPDWORD)&siz); + + if (ret == ERROR_SUCCESS) + Bstrcat(buf, "/gameroot"); + else + { + siz = BMAX_PATH; + ret = SHGetValueA(HKEY_LOCAL_MACHINE, "SOFTWARE\\GOG.com\\GOGDUKE3D", "PATH", NULL, buf, (LPDWORD)&siz); + } + + if (ret == ERROR_SUCCESS) + addsearchpath(buf); + #endif }