PDA

View Full Version : Adding frameworks and resources to .app


visage
2006.05.05, 05:11 PM
Hey all! I know this is probably a fairly common question, but I googled extensively and I couldn't find anything (tough when I don't honestly really know what I am looking for...)

Here is my issue. I have a .app (which I just learned how to put a .icns on!) that I am trying to make portable to other macosx boxes. Now, it extensively uses .frameworks and has a lot of resource files that I would like to add.

Looking at a game like Battle of Wesnoth, it seems like they just add their frameworks to a Framework folder in Content and their resource (sound, image) files to Resources in Content

I tried to do the same with my resources, and my application said that it could not find any of the resources it tried to load. So my first question is, how do I get the .app to recognize where the resources are? It works if the resource folders are external to the .app, but not when they are placed in the Resources folder.

Next, the frameworks. I want those that are assumed not to me on osx10.4 to be added to the .app. Is all I have to do just add a Frameworks folder?

Also, how can I get xcode to automate this for me? I figure if I put my resources in the XCode resources folder, it should work (and, I think it does...), but what about the frameworks?

Sorry if this is a bit wish-wash. I am having trouble finding the words I want to say...
Thanks!

-visage

DoG
2006.05.05, 06:28 PM
I suggest you read a bit about CFBundle (or NSBundle if you use ObjC).

visage
2006.05.05, 06:55 PM
I greatly appreciate the help, but after looking through apple's developer info on CSBundle, I still have no idea what I should be looking for (though, I do know NSBundle is non-applicable for my situation).

Am I looking into editing my SDLMain.m file to set the Resource location? What should I be looking for? Constants used in editing the .plist file?

Thanks!
-visage

OneSadCookie
2006.05.05, 10:48 PM
If you're using SDL, the default SDLMain.m sets the current working directory to the one containing the application bundle. You probably want to set it to your Resources folder instead.

Skorche
2006.05.06, 12:35 AM
This page (http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFBundles/Concepts/BundleAnatomy.html#//apple_ref/doc/uid/20001119-SW1) might help you some.

Also, it used to be really easy to change the SDLMain.m file to drop you in the Resources folder. Now they are using CFUrlRef. I need to look into this for myself. I'll tell you what I find.

Edit: Okay figured it out.
- (void) setupWorkingDirectory:(BOOL)shouldChdir
{
if (shouldChdir)
{
char parentdir[MAXPATHLEN];
CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
if (CFURLGetFileSystemRepresentation(url2, true, parentdir, MAXPATHLEN)) {
assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */
}
CFRelease(url);
CFRelease(url2);
}
}

Should become:
- (void) setupWorkingDirectory:(BOOL)shouldChdir
{
if (shouldChdir)
{
char parentdir[MAXPATHLEN];

CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
CFStringRef path = CFStringCreateWithCString(0, "Contents/Resources", 0);
CFURLRef url2 = CFURLCreateWithFileSystemPathRelativeToBase(0, path, kCFURLPOSIXPathStyle, true, url);

if (CFURLGetFileSystemRepresentation(url2, true, parentdir, MAXPATHLEN)) {
assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */
}

CFRelease(url);
CFRelease(url2);
}
}

visage
2006.05.06, 01:29 PM
Awesome! You guys have been a ton of help. Its now working!

Thanks again guys!

OneSadCookie
2006.05.06, 09:17 PM
There's a CFBundleCopyResourcesDirectoryURL that's probably better than manually appending Contents/Resources...

ferum
2006.08.10, 10:47 PM
Ok, OSC, how would I set the directory to CFBundleCopyResourcesDirectoryURL?
Using the above code to manually append Contents/Resources gives me a error about "signedness".

OneSadCookie
2006.08.10, 10:56 PM
http://tips.onesadcookie.net/tips/published/Where%27s+my+File%3F

ferum
2006.08.11, 09:18 AM
Ok, thanks, that works. And its so much simpler!