]> de.git.xonotic.org Git - xonotic/netradiant.git/commitdiff
detect being inside a Nexuiz install from Radiant C code, no longer from a shell...
authordivverent <divverent@61c419a2-8eb2-4b30-bcec-8cead039b335>
Thu, 5 Mar 2009 11:27:30 +0000 (11:27 +0000)
committerdivverent <divverent@61c419a2-8eb2-4b30-bcec-8cead039b335>
Thu, 5 Mar 2009 11:27:30 +0000 (11:27 +0000)
git-svn-id: svn://svn.icculus.org/netradiant/trunk@210 61c419a2-8eb2-4b30-bcec-8cead039b335

radiant/environment.cpp
setup/data/osx/NetRadiant.app/Contents/MacOS/netradiant.sh

index 45266919f7688470e1fdcd2cb8f33684a1ea2713..99c6971a07aac05f34d8756eaab316d9d39b61c9 100644 (file)
@@ -26,9 +26,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include "stream/stringstream.h"
 #include "debugging/debugging.h"
 #include "os/path.h"
 #include "stream/stringstream.h"
 #include "debugging/debugging.h"
 #include "os/path.h"
+#include "os/file.h"
 #include "cmdlib.h"
 
 #include "cmdlib.h"
 
-
 int g_argc;
 char** g_argv;
 
 int g_argc;
 char** g_argv;
 
@@ -55,6 +55,84 @@ void args_init(int argc, char* argv[])
   g_argv = argv;
 }
 
   g_argv = argv;
 }
 
+char *gamedetect_argv_buffer[1024];
+void gamedetect_found_game(char *game, char *path)
+{
+  int argc;
+  static char buf[128];
+
+  if(g_argv == gamedetect_argv_buffer)
+    return;
+
+  globalOutputStream() << "Detected game " << game << " in " << path << "\n";
+
+  sprintf(buf, "-%s-EnginePath", game);
+  argc = 0;
+  gamedetect_argv_buffer[argc++] = "-global-gamefile";
+  gamedetect_argv_buffer[argc++] = game;
+  gamedetect_argv_buffer[argc++] = buf;
+  gamedetect_argv_buffer[argc++] = path;
+  if((size_t) (argc + g_argc) >= sizeof(gamedetect_argv_buffer) / sizeof(*gamedetect_argv_buffer) - 1)
+    g_argc = sizeof(gamedetect_argv_buffer) / sizeof(*gamedetect_argv_buffer) - g_argc - 1;
+  memcpy(gamedetect_argv_buffer + 4, g_argv, sizeof(*gamedetect_argv_buffer) * g_argc);
+  g_argc += argc;
+  g_argv = gamedetect_argv_buffer;
+}
+
+void gamedetect()
+{
+  // if we're inside a Nexuiz install
+  // default to nexuiz.game (unless the user used an option to inhibit this)
+  bool nogamedetect = false;
+  int i;
+  for(i = 1; i < g_argc - 1; ++i)
+    if(g_argv[i][0] == '-')
+       {
+      if(!strcmp(g_argv[i], "-gamedetect"))
+           nogamedetect = !strcmp(g_argv[i+1], "false");
+         ++i;
+       }
+  if(!nogamedetect)
+  {
+       static char buf[1024 + 64];
+       strncpy(buf, environment_get_app_path(), sizeof(buf));
+       buf[sizeof(buf) - 1 - 64] = 0;
+       if(!strlen(buf))
+         return;
+
+       char *p = buf + strlen(buf) - 1; // point directly on the slash of get_app_path
+       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");
+#elif defined(__APPLE__)
+           strcpy(p, "/Nexuiz.app/Contents/Info.plist");
+#else
+           strcpy(p, "/nexuiz-linux-glx.sh");
+#endif
+               if(file_exists(buf))
+               {
+                 p[1] = 0;
+                 gamedetect_found_game("nexuiz.game", buf);
+                 return;
+               }
+      }
+
+         // we found nothing
+         // go backwards
+         --p;
+         while(p != buf && *p != '/')
+           --p;
+       }
+  }
+}
+
 namespace
 {
   CopiedString home_path;
 namespace
 {
   CopiedString home_path;
@@ -145,6 +223,7 @@ void environment_init(int argc, char* argv[])
     app_path = getexename(real);
     ASSERT_MESSAGE(!string_empty(app_path.c_str()), "failed to deduce app path");
   }
     app_path = getexename(real);
     ASSERT_MESSAGE(!string_empty(app_path.c_str()), "failed to deduce app path");
   }
+  gamedetect();
 }
 
 #elif defined(WIN32)
 }
 
 #elif defined(WIN32)
@@ -190,6 +269,7 @@ void environment_init(int argc, char* argv[])
     app << PathCleaned(filename);
     app_path = app.c_str();
   }
     app << PathCleaned(filename);
     app_path = app.c_str();
   }
+  gamedetect();
 }
 
 #else
 }
 
 #else
index 14c4b52dfdc1a42d26862970f00b974d2102e393..3df16e39c43d65fb0ffe0d66aa0010b13588928a 100755 (executable)
@@ -9,31 +9,6 @@ export PANGO_RC_FILE="$MY_DIRECTORY/Contents/MacOS/install/pangorc"
 export GDK_PIXBUF_MODULE_FILE="$MY_DIRECTORY/Contents/MacOS/install/gdk-pixbuf.loaders"
 
 cd "$MY_DIRECTORY/Contents/MacOS/install"
 export GDK_PIXBUF_MODULE_FILE="$MY_DIRECTORY/Contents/MacOS/install/gdk-pixbuf.loaders"
 
 cd "$MY_DIRECTORY/Contents/MacOS/install"
-
-# autodetect nexuiz installs
-NEX_DIRECTORY="/${MY_DIRECTORY%/*}"
-while :; do
-       if [ -z "$NEX_DIRECTORY" ]; then
-               break
-       fi
-       if [ -f "$NEX_DIRECTORY/data/common-spog.pk3" ]; then
-               if [ -d "$NEX_DIRECTORY/Nexuiz.app" ]; then
-                       break
-               fi
-       fi
-       NEX_DIRECTORY=${NEX_DIRECTORY%/*}
-done
-case "$NEX_DIRECTORY" in
-       //*)
-               NEX_DIRECTORY=${NEX_DIRECTORY#/}
-               set -- -global-gamefile nexuiz.game -nexuiz.game-EnginePath "$NEX_DIRECTORY/"
-               # -global-gamePrompt false?
-               ;;
-       *)
-               set --
-               ;;
-esac
-
 if [ -x /usr/bin/open-x11 ]; then
        /usr/bin/open-x11 ./radiant.ppc "$@" &
 else
 if [ -x /usr/bin/open-x11 ]; then
        /usr/bin/open-x11 ./radiant.ppc "$@" &
 else