Accessing the Datafork in Carbon

Posts: 45
Joined: 2002.04
Post: #1
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);

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);

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

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

/* Drunk...... fix later.... */
Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #2
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?
Quote this message in a reply
Post: #3
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: 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 Map

Hope this helps.
Quote this message in a reply
Posts: 116
Joined: 2002.04
Post: #4
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.

Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  SQLite3 question: accessing by column instead of index? Toontingy 3 6,738 Apr 8, 2010 06:19 PM
Last Post: OneSadCookie
  Noob: Accessing Structures from Cocoa Classes MikeC 15 9,083 Oct 19, 2007 02:42 PM
Last Post: MikeC
  Accessing an inherited class's variables Tobs_ 22 13,970 Feb 28, 2007 05:26 PM
Last Post: mac_girl
  Accessing Pixel Information Nick 11 6,045 Jun 1, 2005 09:33 PM
Last Post: Andrew