iDevGames Forums
Accessing the Datafork in Carbon - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Accessing the Datafork in Carbon (/thread-7761.html)



Accessing the Datafork in Carbon - Muffinking - May 14, 2002 06:39 PM

Since I porting my code over to carbon I really need to know how to do this..

As far as I know (from looking at apples site) all my function calls pretaining to file manipulation are useable in carbon..

yet it doesn't seem to work.. When I make an FSSpec to the file I want it returns an error that the file cannot be found or doesn't exist. Here is my code for opening my world Map:

void loadWorldNode(short theNode)
{
OSErr err;
FSSpec worldDatSpec;
long byteCount;
long startByte;
short fileRefNum;
// unsigned char namesting[] = {'W', 'o', 'r', 'l', 'd', ' ', 'M', 'a', 'p'};

//err = PBMakeFSSpecSync (paramBlock);

//The World Data Folder should be in the same folder
err = FSMakeFSSpec(0, 0, "\p:Senario Files:World Map", &worldDatSpec);

if(err)
{
switch(err)
{
case fnfErr: RedAlert("\pPut World Map in Senario folder."); break;

default: RedAlert("\pPut World Map in Senario folder."); break;
}

}

//Open the Data Fork of our File
err = FSpOpenDF(&worldDatSpec, fsRdWrPerm, &fileRefNum);

//Calculate where in the file to load from
startByte = sizeof(numGrid);
startByte *= theNode;

//Set the start position to where we need.
SetFPos (fileRefNum, fsFromStart, startByte);

//Read it all in at once
byteCount = sizeof(numGrid);
err = FSRead(fileRefNum, &byteCount, &numGrid);

//Close
err = FSClose(fileRefNum);
if(err != noErr) { RedAlert("\pError Closing File."); }
}

any Ideas on how to make it "see" my file?


Accessing the Datafork in Carbon - OneSadCookie - May 14, 2002 08:23 PM

Quote:Originally posted by Muffinking
//The World Data Folder should be in the same folder
err = FSMakeFSSpec(0, 0, "\p:Senario Files:World Map", &worldDatSpec);

IIRC, this doesn't work on MacOSX. Could that be the problem?


Accessing the Datafork in Carbon - Pazolli - May 14, 2002 10:48 PM

As I recall colon-based file paths were still valid on Mac OS X. So, I believe you (like so many programmers were when we started out with Mac OS X) have not realized that the relative path ":Scenario Files:World Map" refers to:

YourApp.app/Contents/MacOS/Scenario Files/World Map

Hence putting a directory "Scenario Files" with a file "World Map" in the same directory as "YourApp" will never be properly accessed by the FSSpec referenceing ":Scenario Files:World Map", instead you'll have to manually or using PB place it inside the MacOS directory of the application package for your application to "see" the "World Map" file. That said, you could use a rather ugly relative path to get into the correct position, for example, the following (if I recall correctly)

::Resources:World Map

Will get you to

YourApp.app/Contents/Resources/World Map

Hope this helps.


Accessing the Datafork in Carbon - wadesworld - May 15, 2002 10:06 AM

If the app is bundled, it's important to remember that the working directory probably isn't set to where it traditionally has been (the location of the app).

So, use CFBundle services to find the location of the app, and change your directory from there.

To find out what the app thinks is the current working directory, call HGetVol and look at the path returned.

Wade