Adding frameworks and resources to .app

visage
Unregistered
 
Post: #1
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
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #2
I suggest you read a bit about CFBundle (or NSBundle if you use ObjC).
Quote this message in a reply
visage
Unregistered
 
Post: #3
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
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
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.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #5
This page 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.
Code:
- (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:
Code:
- (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);
    }
}

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
visage
Unregistered
 
Post: #6
Awesome! You guys have been a ton of help. Its now working!

Thanks again guys!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #7
There's a CFBundleCopyResourcesDirectoryURL that's probably better than manually appending Contents/Resources...
Quote this message in a reply
Member
Posts: 185
Joined: 2005.02
Post: #8
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".
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Member
Posts: 185
Joined: 2005.02
Post: #10
Ok, thanks, that works. And its so much simpler!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Adding friends to iOS games rubilee 0 2,330 Oct 18, 2011 05:02 AM
Last Post: rubilee
  SDL frameworks are giant. ravuya 8 4,590 Oct 9, 2006 08:40 PM
Last Post: ravuya
  physfs or howto make frameworks ? seoushi 2 2,750 Sep 16, 2006 05:58 PM
Last Post: seoushi
  LGPL and Frameworks? chuck 1 2,447 Sep 10, 2006 06:09 PM
Last Post: OneSadCookie
  Adding frameworks to a framework vbuser1338 4 4,162 May 25, 2006 04:02 AM
Last Post: vbuser1338