Accessing the Datafork in Carbon

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

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?

/* Drunk...... fix later.... */
Quote this message in a reply
Luminary
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
Pazolli
Unregistered
 
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:

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.
Quote this message in a reply
Member
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.

Wade
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 4,569 Apr 8, 2010 06:19 PM
Last Post: OneSadCookie
  Noob: Accessing Structures from Cocoa Classes MikeC 15 7,387 Oct 19, 2007 02:42 PM
Last Post: MikeC
  Accessing an inherited class's variables Tobs_ 22 9,978 Feb 28, 2007 05:26 PM
Last Post: mac_girl
  Accessing Pixel Information Nick 11 4,613 Jun 1, 2005 09:33 PM
Last Post: Andrew