I recently took a suggestion for my MacOS version of my OF game, to build the file resources into the .app, which seems to be typical MacOS software practice, and is done in magic settings in xCode.
It worked fine at first, moving the files from OF’s Data into the .app, but requiring no code changes…
… but then I made minor unrelated code changes, added a few files, and tried to build a new version…
… and for mysterious xCode reasons, while the files were still packaged inside the .app, the program in the later version went looking for the files in an external Data folder which I now wasn’t shipping, and failed.
So I added some code to find and use the Resources folder inside the .app, and now it works. I thought I’d just share what I did, in case it helps other people in future trying to do this. I found a couple of other mentions of this problem here ( ofToDataPath() ) on this forum and near solutions here: How to get the path to my app? but that last one shows how to point to the path to the program itself. To get to the Resources folder, I needed to navigate up two levels and then down into Resources, like:
#ifdef TARGET_OSX sAppPath = ofFilePath::getAbsolutePath(ofFilePath::getCurrentExeDir()); sAppPath = sAppPath.substr(0, sAppPath.find_last_of("/")); sAppPath = sAppPath.substr(0, sAppPath.find_last_of("/")); sAppPath += "/Resources/"; #endif
Which seems like it would be a good thing for there to be an OF method for, since this seems to be a mainstream place to put data files on MacOS. A MacOS dev said he thought there might be a more official/universal way to get the Resources folder.