Mac OS X 10.9 no longer uses the -psn_XXX command line arg for Finder launches. SDL-1.2
authorRyan C. Gordon <icculus@icculus.org>
Fri, 15 Nov 2013 22:33:55 -0500
branchSDL-1.2
changeset 7991cfec3f86fba7
parent 7734 bbfb41c13a87
child 8040 22a7f096bb9d
Mac OS X 10.9 no longer uses the -psn_XXX command line arg for Finder launches.
src/main/macosx/SDLMain.m
     1.1 --- a/src/main/macosx/SDLMain.m	Fri Sep 06 23:35:30 2013 -0700
     1.2 +++ b/src/main/macosx/SDLMain.m	Fri Nov 15 22:33:55 2013 -0500
     1.3 @@ -351,12 +351,42 @@
     1.4  #endif
     1.5  
     1.6  
     1.7 +static int IsRootCwd()
     1.8 +{
     1.9 +    char buf[MAXPATHLEN];
    1.10 +    char *cwd = getcwd(buf, sizeof (buf));
    1.11 +    return (cwd && (strcmp(cwd, "/") == 0));
    1.12 +}
    1.13 +
    1.14 +static int IsTenPointNineOrLater()
    1.15 +{
    1.16 +    /* Gestalt() is deprecated in 10.8, but I don't care. Stop using SDL 1.2. */
    1.17 +    SInt32 major, minor;
    1.18 +    Gestalt(gestaltSystemVersionMajor, &major);
    1.19 +    Gestalt(gestaltSystemVersionMinor, &minor);
    1.20 +    return ( ((major << 16) | minor) >= ((10 << 16) | 9) );
    1.21 +}
    1.22 +
    1.23 +static int IsFinderLaunch(const int argc, char **argv)
    1.24 +{
    1.25 +    const int bIsNewerOS = IsTenPointNineOrLater();
    1.26 +    /* -psn_XXX is passed if we are launched from Finder in 10.8 and earlier */
    1.27 +    if ( (!bIsNewerOS) && (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) {
    1.28 +        return 1;
    1.29 +    } else if ((bIsNewerOS) && (argc == 1) && IsRootCwd()) {
    1.30 +        /* we might still be launched from the Finder; on 10.9+, you might not
    1.31 +        get the -psn command line anymore. Check version, if there's no
    1.32 +        command line, and if our current working directory is "/". */
    1.33 +        return 1;
    1.34 +    }
    1.35 +    return 0;  /* not a Finder launch. */
    1.36 +}
    1.37 +
    1.38  /* Main entry point to executable - should *not* be SDL_main! */
    1.39  int main (int argc, char **argv)
    1.40  {
    1.41      /* Copy the arguments into a global variable */
    1.42 -    /* This is passed if we are launched by double-clicking */
    1.43 -    if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
    1.44 +    if (IsFinderLaunch(argc, argv)) {
    1.45          gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
    1.46          gArgv[0] = argv[0];
    1.47          gArgv[1] = NULL;