]> git.xonotic.org Git - xonotic/netradiant.git/commitdiff
q3map2: use "My Games" directory if exists on Win32
authorRudolf Polzer <divverent@alientrap.org>
Wed, 20 Apr 2011 15:35:51 +0000 (17:35 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Wed, 20 Apr 2011 15:44:27 +0000 (17:44 +0200)
radiant/mainframe.cpp
radiant/qe3.cpp
tools/quake3/q3map2/path_init.c

index c8a739b6f6939952f32845849e74b8c5b6252d5e..85aaaee75b0c1487ac85b53d0d3d02827b080ffb 100644 (file)
@@ -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();
index 67ffebeccb3d38e5a88405cbe307b1821f30959a..1b3d060eddf7450334606c01f9312e9b6433d750 100644 (file)
@@ -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)
     // ~/.<gameprefix>/<fs_game>
+    if(userRoot)
     {
       StringOutputStream userGamePath(256);
       userGamePath << userRoot << gamename << '/';
       GlobalFileSystem().initDirectory(userGamePath.c_str());
     }
-#endif
 
     // <fs_basepath>/<fs_game>
     {
@@ -103,14 +100,13 @@ void QE_InitVFS()
     }
   }
 
-#if defined(POSIX)
   // ~/.<gameprefix>/<fs_main>
+  if(userRoot)
   {
     StringOutputStream userBasePath(256);
     userBasePath << userRoot << basegame << '/';
     GlobalFileSystem().initDirectory(userBasePath.c_str());
   }
-#endif
 
   // <fs_basepath>/<fs_main>
   {
index 83383e2287ba3cdae523ab375748b7cb2387b046..8e9bd4d5559301b8f8a146d9e1f1ae5d2e4b1783 100644 (file)
@@ -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++;
 }