]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
lovely untested OSX code for detecting gamedir inside .app
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 8 May 2011 21:02:54 +0000 (21:02 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 8 May 2011 21:02:54 +0000 (21:02 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11135 d7cf8633-e32d-0410-b094-e92efae38249

fs.c

diff --git a/fs.c b/fs.c
index b678a268f6456c71e6c99ce34ebc93ad1f6f3cda..da708289997ea93e878fb9f24090a9b705ef5d90 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -1927,8 +1927,7 @@ void FS_Init (void)
 #ifdef DP_FS_BASEDIR
                strlcpy(fs_basedir, DP_FS_BASEDIR, sizeof(fs_basedir));
 #elif defined(MACOSX)
-               // FIXME: is there a better way to find the directory outside the .app?
-               // FIXME: check if game data is inside .app bundle
+               // FIXME: is there a better way to find the directory outside the .app, without using Objective-C?
                if (strstr(com_argv[0], ".app/"))
                {
                        char *split;
@@ -1936,9 +1935,23 @@ void FS_Init (void)
                        split = strstr(fs_basedir, ".app/");
                        if (split)
                        {
-                               while (split > fs_basedir && *split != '/')
-                                       split--;
-                               *split = 0;
+                               struct stat statresult;
+                               // truncate to just after the .app/
+                               split[5] = 0;
+                               // see if gamedir exists in Resources
+                               if (stat(va("%s/Contents/Resources/%s", fs_basedir, gamedirname1)), &statresult) == 0)
+                               {
+                                       // found gamedir inside Resources, use it
+                                       strlcat(fs_basedir, "Contents/Resources/", sizeof(fs_basedir));
+                               }
+                               else
+                               {
+                                       // no gamedir found in Resources, gamedir is probably
+                                       // outside the .app, remove .app part of path
+                                       while (split > fs_basedir && *split != '/')
+                                               split--;
+                                       *split = 0;
+                               }
                        }
                }
 #endif