From: havoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Date: Sun, 8 May 2011 21:02:54 +0000 (+0000)
Subject: lovely untested OSX code for detecting gamedir inside .app
X-Git-Tag: xonotic-v0.5.0~206
X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c593855782a3910f70e73fc69583adb790567e47;p=xonotic%2Fdarkplaces.git

lovely untested OSX code for detecting gamedir inside .app

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11135 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=52e0ce1d000e4326978840aff6a4cb3c0a19df6c
---

diff --git a/fs.c b/fs.c
index b678a268..da708289 100644
--- 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