Skip to content

Commit

Permalink
Detect if .exe is in a bundle on OSX, and if so, set current director…
Browse files Browse the repository at this point in the history
…y to folder containing bundle instead of contents/macos folder
  • Loading branch information
UnknownShadow200 committed Sep 10, 2019
1 parent 7e129ba commit 1d93a62
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -1720,8 +1720,8 @@ ReturnCode Platform_SetDefaultCurrentDirectory(void) {
int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, String* args) {
int i, count;
argc--; argv++; /* skip executable path argument */
count = min(argc, GAME_MAX_CMDARGS);

count = min(argc, GAME_MAX_CMDARGS);
for (i = 0; i < count; i++) { args[i] = String_FromReadonly(argv[i]); }
return count;
}
Expand Down Expand Up @@ -1751,13 +1751,13 @@ int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, String* args)

#ifdef CC_BUILD_OSX
if (argc) {
String arg0 = String_FromReadonly(argv[0]);
String psn = String_FromConst("-psn_0_");
static const String psn = String_FromConst("-psn_0_");
String arg0 = String_FromReadonly(argv[0]);
if (String_CaselessStarts(&arg0, &psn)) { argc--; argv++; }
}
#endif
count = min(argc, GAME_MAX_CMDARGS);

count = min(argc, GAME_MAX_CMDARGS);
for (i = 0; i < count; i++) { args[i] = String_FromReadonly(argv[i]); }
return count;
}
Expand All @@ -1773,6 +1773,19 @@ ReturnCode Platform_SetDefaultCurrentDirectory(void) {
if (path[i] == '/') break;
}

#ifdef CC_BUILD_OSX
static const String bundle = String_FromConst(".app/Contents/MacOS/");
String raw = String_Init(path, len, 0);

if (String_CaselessEnds(&raw, &bundle)) {
len -= bundle.length;

for (i = len - 1; i >= 0; i--, len--) {
if (path[i] == '/') break;
}
}
#endif

path[len] = '\0';
return chdir(path) == -1 ? errno : 0;
}
Expand Down

0 comments on commit 1d93a62

Please sign in to comment.