RE: Open Resource File with Cocoa Path
RE: Open Resource File with Cocoa Path
- Subject: RE: Open Resource File with Cocoa Path
- From: "Josh Ferguson" <email@hidden>
- Date: Wed, 10 Apr 2002 16:56:57 -0500
- Thread-topic: Open Resource File with Cocoa Path
This is the method that I've used to open a resource file. Keep in mind that this is a flattened (Data only) resource file, so it may not do exactly what you want, but it shouldn't be difficult to modify it for your needs. I haven't found an easier way of doing this yet, so if you come across one, I'd be interested in hearing it...
Josh Ferguson
- (IBAction)OpenResource:(id)sender
{
long error;
//Get path for resource file
NSBundle* mainb = [NSBundle mainBundle];
NSString* path = [mainb pathForResource:@"myResource" ofType:@"rsrc"];
if(path)
{
FSRef ref;
if (FSPathMakeRef([path fileSystemRepresentation],&ref,FALSE)==noErr)
{
HFSUniStr255 forkName;
short refnum=0;
FSGetDataForkName(&forkName);
error = FSOpenResourceFile(&ref,forkName.length,forkName.unicode, fsRdPerm,&refnum);
if (error==noErr)
{
//Do stuff with your resource file
CloseResFile(refnum);
}
else
{
Str255 tStr;
NumToString(error,tStr);
DebugStr(tStr);
}
}
}
else
{
DebugStr("\pNoResource!");
}
}
-----Original Message-----
From: Donald Brown [
mailto:email@hidden]
Sent: Wednesday, April 10, 2002 1:54 PM
To: Cocoa dev
Subject: Open Resource File with Cocoa Path
I need to be able to import data from a legacy file, and it includes some
data in a resource. Anyone have any code to open a resource file?
As near as I can tell, I have to parse the path myself, calling
FSMakeFSRefUnicode on each portion to build up an FSRef, which I pass to
FSpOpenResFile. It can't be that screwy, can it?
Donald
--
Donald Brown
email@hidden
http://www.eamontales.com
We have met the enemy and he is us - Pogo
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.