]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
detect Q2W too
authordivverent <divverent@61c419a2-8eb2-4b30-bcec-8cead039b335>
Wed, 11 Mar 2009 19:17:43 +0000 (19:17 +0000)
committerdivverent <divverent@61c419a2-8eb2-4b30-bcec-8cead039b335>
Wed, 11 Mar 2009 19:17:43 +0000 (19:17 +0000)
git-svn-id: svn://svn.icculus.org/netradiant/trunk@218 61c419a2-8eb2-4b30-bcec-8cead039b335

radiant/environment.cpp

index 0656f8db8c447e1e07af85b04c5bb45d13df52a2..16aba7f7098089e52ee18c0d64928fae96d7523a 100644 (file)
@@ -79,6 +79,25 @@ 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;
+
+       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,25 +123,20 @@ 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;
 
          // we found nothing
          // go backwards