OS X: Am I in an app bundle?

How do I detect I am in an app bundle?

Why this is relevant:

I am trying to locate my game assets directory in a cross platform manner. This is usually $EXE_DIR/assets. OS X is throwing a curveball, because the app bundle puts it in a different location.

If I am not in an app bundle, I take the return of SDL_GetBasePath() and append ?assets?.

If I am in the bundle, I need to append a different string, depending on the SDL_FILESYSTEM_BASE_DIR_TYPE plist. Both ?resource? and ?parent? settings are okay for my needs.

So then, how do I detect that I am in the app bundle? The string I append has to change, and this needs to happen at runtime or I sacrifice robustness.

SDL_GetBasePath() can?t be used to construct a path to assets without this test.

What I am getting:
OS X inside of a bundle with SDL_FILESYSTEM_BASE_DIR=?bundle":
"/Applications/Some Game.app/? <- Need to append “Contents/Resources/assets/”

“/Users/mlabbe/dev/game/? <- need to append ?assets/”

Michael Labb?

OS X inside of a bundle with SDL_FILESYSTEM_BASE_DIR=?bundle":
"/Applications/Some Game.app/?  <- Need to append

“Contents/Resources/assets/”

"/Users/mlabbe/dev/game/?  <- need to append ?assets/"

I’m probably misunderstanding the problem, but you should get
"myapp.app/Contents/Resources/" by default without the hint, making it
so you just have to append “assets/” in either case.

–ryan.

Upon re-reading, that would definitely solve my problem as written. Unfortunately, I oversimplified the explanation for the email. In practice, I actually have no ?assets? subdirectory under ?Contents/Resources?.

Given that it is pretty trivial for me to update my bundle creation script to do so, that?s what I?ll do. It beats ducking into a .m file and doing a quick test for the existence of the plist.

Michael Labb?On Feb 6, 2014, at 12:47 PM, Ryan C. Gordon wrote:

OS X inside of a bundle with SDL_FILESYSTEM_BASE_DIR=?bundle":
"/Applications/Some Game.app/? <- Need to append
"Contents/Resources/assets/"

“/Users/mlabbe/dev/game/? <- need to append ?assets/”

I’m probably misunderstanding the problem, but you should get “myapp.app/Contents/Resources/” by default without the hint, making it so you just have to append “assets/” in either case.

–ryan.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org