]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/environment.cpp
option: -sRGBcolor (unused yet)
[xonotic/netradiant.git] / radiant / environment.cpp
index 99c6971a07aac05f34d8756eaab316d9d39b61c9..040335794d339fd627ce91c0924e804243883823 100644 (file)
@@ -79,6 +79,28 @@ void gamedetect_found_game(char *game, char *path)
   g_argv = gamedetect_argv_buffer;
 }
 
+bool gamedetect_check_game(char *gamefile, const char *checkfile1, const char *checkfile2, char *buf /* must have 64 bytes free after bufpos */, int bufpos)
+{
+       buf[bufpos] = '/';
+
+       strcpy(buf + bufpos + 1, checkfile1);
+       globalOutputStream() << "Checking for a game file in " << buf << "\n";
+       if(!file_exists(buf))
+               return false;
+
+       if(checkfile2)
+       {
+               strcpy(buf + bufpos + 1, checkfile2);
+               globalOutputStream() << "Checking for a game file in " << buf << "\n";
+               if(!file_exists(buf))
+                       return false;
+       }
+
+       buf[bufpos + 1] = 0;
+       gamedetect_found_game(gamefile, buf);
+       return true;
+}
+
 void gamedetect()
 {
   // if we're inside a Nexuiz install
@@ -104,30 +126,29 @@ void gamedetect()
        while(p != buf)
        {
          // TODO add more games to this
+
          // try to detect Nexuiz installs
-         strcpy(p, "/data/common-spog.pk3");
-         globalOutputStream() << "Checking for a game file in " << buf << "\n";
-         if(file_exists(buf))
-         {
 #if defined(WIN32)
-           strcpy(p, "/nexuiz.exe");
+         if(gamedetect_check_game("nexuiz.game", "data/common-spog.pk3", "nexuiz.exe", buf, p - buf))
 #elif defined(__APPLE__)
-           strcpy(p, "/Nexuiz.app/Contents/Info.plist");
+         if(gamedetect_check_game("nexuiz.game", "data/common-spog.pk3", "Nexuiz.app/Contents/Info.plist", buf, p - buf))
 #else
-           strcpy(p, "/nexuiz-linux-glx.sh");
+         if(gamedetect_check_game("nexuiz.game", "data/common-spog.pk3", "nexuiz-linux-glx.sh", buf, p - buf))
 #endif
-               if(file_exists(buf))
-               {
-                 p[1] = 0;
-                 gamedetect_found_game("nexuiz.game", buf);
-                 return;
-               }
-      }
+           return;
+
+         // try to detect Q2World installs
+         if(gamedetect_check_game("q2w.game", "default/quake2world.version", NULL, buf, p - buf))
+           return;
+
+         // try to detect Warsow installs
+         if(gamedetect_check_game("warsow.game", "basewsw/dedicated_autoexec.cfg", NULL, buf, p - buf))
+           return;
 
          // we found nothing
          // go backwards
          --p;
-         while(p != buf && *p != '/')
+         while(p != buf && *p != '/' && *p != '\\')
            --p;
        }
   }
@@ -149,6 +170,17 @@ const char* environment_get_app_path()
   return app_path.c_str();
 }
 
+bool portable_app_setup()
+{
+       StringOutputStream confdir(256);
+       confdir << app_path.c_str() << "settings/";
+       if(file_exists(confdir.c_str()))
+       {
+               home_path = confdir.c_str();
+               return true;
+       }
+       return false;
+}
 
 #if defined(POSIX)
 
@@ -212,17 +244,19 @@ void environment_init(int argc, char* argv[])
 
   args_init(argc, argv);
 
+  {
+    char real[PATH_MAX];
+    app_path = getexename(real);
+    ASSERT_MESSAGE(!string_empty(app_path.c_str()), "failed to deduce app path");
+  }
+
+  if(!portable_app_setup())
   {
     StringOutputStream home(256);
     home << DirectoryCleaned(g_get_home_dir()) << ".netradiant/";
     Q_mkdir(home.c_str());
     home_path = home.c_str();
   }
-  {
-    char real[PATH_MAX];
-    app_path = getexename(real);
-    ASSERT_MESSAGE(!string_empty(app_path.c_str()), "failed to deduce app path");
-  }
   gamedetect();
 }
 
@@ -234,24 +268,6 @@ void environment_init(int argc, char* argv[])
 {
   args_init(argc, argv);
 
-  {
-    char *appdata = getenv("APPDATA");
-
-    StringOutputStream home(256);
-    if(!appdata || string_empty(appdata))
-    {
-      ERROR_MESSAGE("Application Data folder not available.\n"
-        "Radiant will use C:\\ for user preferences.\n");
-      home << "C:";
-    }
-    else
-    {
-      home << PathCleaned(appdata);
-    }
-    home << "/NetRadiantSettings/";
-    Q_mkdir(home.c_str());
-    home_path = home.c_str();
-  }
   {
     // get path to the editor
     char filename[MAX_PATH+1];
@@ -269,6 +285,25 @@ void environment_init(int argc, char* argv[])
     app << PathCleaned(filename);
     app_path = app.c_str();
   }
+
+  if(!portable_app_setup())
+  {
+    char *appdata = getenv("APPDATA");
+    StringOutputStream home(256);
+    if(!appdata || string_empty(appdata))
+    {
+      ERROR_MESSAGE("Application Data folder not available.\n"
+        "Radiant will use C:\\ for user preferences.\n");
+      home << "C:";
+    }
+    else
+    {
+      home << PathCleaned(appdata);
+    }
+    home << "/NetRadiantSettings/";
+    Q_mkdir(home.c_str());
+    home_path = home.c_str();
+  }
   gamedetect();
 }