Current Directory when running in PB

slur

Geek / Hedonist
When I run my program in Project Builder the "current directory" seems to be different than when I launch my program from the Finder.

Specifically, I've got a "data" folder which is copied into the Resources folder as part of the build process. When I run the program from Project Builder, attempts to open files in the "data" folder fail with a file-not-found error. When I launch the executable from the Finder there's no problem at all.

Has anyone else happened upon this problem before? If so, have you found a solution? For now I'm just using a symlink in the build directory, which implies that the "current directory" is the "build" folder when running from PB.
 
I have te opposite problem: my apps find the data files OK when running from PB, but then fail when I run them from the finder. I'm using standard C FILE*, fopen, fseek, etc. I think that the solution will be using the NSBundle class, which should do a search for the data file requested in the apropiate places. (I haven't tried this yet)
 
IMO you should not rely on the current directory. I see two options:

1) In main() use argv[0] which refers to your executable to locate your data files.

2) Use a commonly-used location to store your data, e.g. into ~/Library/Yourapp/data/ if the data files are user-related.
 
I guess I have to agree with you about not relying on the current directory.

For an application bundle argv[0] should contain the path to "MyCool.app/MacOSX/MyCool", right? The mechanistic way to find the Resources folder would be to append "Resources" after *.app.

There's obviously a Cocoa function to find the Resources folder directly.

To give a little more background on my project, I'm using SDL, which is an open source cross-platform media library. It has functions for loading files and images, and these seem to be smart enough to look in both the same folder as the application bundle, and the bundles' Resources folder - but it only finds the Resources folder when running outside of PB. I'll double-check the source code to see exactly what it's doing and get back to you.

The data I'm locating, BTW, is game data - graphics and sounds. If there is user-data or preferences data to be stored I'll certainly use the appropriate location for each OS I deploy on (e.g., Windows, Mac, and Linux).
 
Wouldn't you know it, here's one possible answer to my question.

However, it states that the working directory will be Resources if using GLUT but the folder containing the application if using SDL. Yet, again, the SDL load-image function finds my files located in the Resources folder.

I guess I still need to have a look at the SDL source code....
 
Back
Top