From 9b15142ec2e31d48fe2169dc0c75b61f111815d1 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Wed, 20 Apr 2011 17:35:51 +0200 Subject: [PATCH] q3map2: use "My Games" directory if exists on Win32 --- radiant/mainframe.cpp | 20 +++++++++ radiant/qe3.cpp | 8 +--- tools/quake3/q3map2/path_init.c | 72 +++++++++++++++++++++++---------- 3 files changed, 73 insertions(+), 27 deletions(-) diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index c8a739b6..85aaaee7 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -196,6 +196,26 @@ void HomePaths_Realise() Q_mkdir(g_qeglobals.m_userEnginePath.c_str()); } else +#elif defined(WIN32) + if(!string_empty(prefix)) + { + StringOutputStream path(256); + TCHAR mydocsdir[MAX_PATH + 1]; + if(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, mydocsdir)) + { + path << DirectoryCleaned(mydocsdir) << "My Games/" << prefix << "/"; + // win32: only add it if it already exists + if(file_is_directory(path.c_str())) + g_qeglobals.m_userEnginePath = path.c_str(); + else + g_qeglobals.m_userEnginePath = EnginePath_get(); + } + else + { + g_qeglobals.m_userEnginePath = EnginePath_get(); + } + } + else #endif { g_qeglobals.m_userEnginePath = EnginePath_get(); diff --git a/radiant/qe3.cpp b/radiant/qe3.cpp index 67ffebec..1b3d060e 100644 --- a/radiant/qe3.cpp +++ b/radiant/qe3.cpp @@ -78,22 +78,19 @@ void QE_InitVFS() const char* gamename = gamename_get(); const char* basegame = basegame_get(); -#if defined(POSIX) const char* userRoot = g_qeglobals.m_userEnginePath.c_str(); -#endif const char* globalRoot = EnginePath_get(); // if we have a mod dir if(!string_equal(gamename, basegame)) { -#if defined(POSIX) // ~/./ + if(userRoot) { StringOutputStream userGamePath(256); userGamePath << userRoot << gamename << '/'; GlobalFileSystem().initDirectory(userGamePath.c_str()); } -#endif // / { @@ -103,14 +100,13 @@ void QE_InitVFS() } } -#if defined(POSIX) // ~/./ + if(userRoot) { StringOutputStream userBasePath(256); userBasePath << userRoot << basegame << '/'; GlobalFileSystem().initDirectory(userBasePath.c_str()); } -#endif // / { diff --git a/tools/quake3/q3map2/path_init.c b/tools/quake3/q3map2/path_init.c index 83383e22..8e9bd4d5 100644 --- a/tools/quake3/q3map2/path_init.c +++ b/tools/quake3/q3map2/path_init.c @@ -65,7 +65,18 @@ gets the user's home dir (for ~/.q3a) char *LokiGetHomeDir( void ) { #ifndef Q_UNIX - return NULL; + #ifndef WIN32 + return NULL; + #else + static char buf[MAX_OS_PATH]; + TCHAR mydocsdir[MAX_PATH + 1]; + if(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, mydocsdir)) + { + snprintf(buf, "%s/My Games", mydocsdir); + return buf; + } + return NULL; + #endif #else char *home; uid_t id; @@ -107,6 +118,14 @@ void LokiInitPaths( char *argv0 ) #ifndef Q_UNIX /* this is kinda crap, but hey */ strcpy( installPath, "../" ); + + /* get home dir */ + home = LokiGetHomeDir(); + if( home == NULL ) + home = "."; + + /* set home path */ + homePath = home; #else char temp[ MAX_OS_PATH ]; char last0[ 2 ]; @@ -272,28 +291,39 @@ adds a base path to the beginning of the list, prefixed by ~/ void AddHomeBasePath( char *path ) { - #ifdef Q_UNIX - int i; - char temp[ MAX_OS_PATH ]; - - - /* dummy check */ - if( path == NULL || path[ 0 ] == '\0' ) + int i; + char temp[ MAX_OS_PATH ]; + + if(!homePath) + return; + + /* dummy check */ + if( path == NULL || path[ 0 ] == '\0' ) + return; + + /* concatenate home dir and path */ + sprintf( temp, "%s/%s", homePath, path ); + +#ifdef WIN32 + { + /* on Win32, we ONLY add it if the directory already exists */ + GDir *dir; + dir = g_dir_open (temp, 0, NULL); + if(!dir) return; + g_dir_close(dir); + } +#endif - /* make a hole */ - for( i = (MAX_BASE_PATHS - 2); i >= 0; i-- ) - basePaths[ i + 1 ] = basePaths[ i ]; - - /* concatenate home dir and path */ - sprintf( temp, "%s/%s", homePath, path ); - - /* add it to the list */ - basePaths[ 0 ] = safe_malloc( strlen( temp ) + 1 ); - strcpy( basePaths[ 0 ], temp ); - CleanPath( basePaths[ 0 ] ); - numBasePaths++; - #endif + /* make a hole */ + for( i = (MAX_BASE_PATHS - 2); i >= 0; i-- ) + basePaths[ i + 1 ] = basePaths[ i ]; + + /* add it to the list */ + basePaths[ 0 ] = safe_malloc( strlen( temp ) + 1 ); + strcpy( basePaths[ 0 ], temp ); + CleanPath( basePaths[ 0 ] ); + numBasePaths++; } -- 2.39.2