Path problems on OS X

I’m having problems reading files on OS X - this is always a pain, in my experience…

When I build a self-contained .app and try loading files, the default location seems to be / (the root of the volume). After a bit of googling, I came up with this workaround that you can put in the setup() of your testApp.cpp file to get the correct path to the folder containing your .app (it works on 10.5, may be different on 10.4) - you’ll need to include string.h for it to work:

  
  
// get the path the correct apple way  
CFURLRef mainRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());  
CFStringRef macPath = CFURLCopyFileSystemPath(mainRef, nkCFURLPOSIXPathStyle);  
  
const char *pathPtr = CFStringGetCStringPtr(macPath,   
												CFStringGetSystemEncoding());  
  
string str (pathPtr);  
	  
size_t found;  
found=str.find_last_of("/\\");  
mainPath = str.substr(0,found+1);  // now this contains the main   
                   // path string, terminated by a '/'  
  
  

cheers
pixelpusher