Re: Philosophy of FSRef - way
Re: Philosophy of FSRef - way
- Subject: Re: Philosophy of FSRef - way
- From: Shawn Erickson <email@hidden>
- Date: Fri, 11 Feb 2005 09:33:31 -0800
On Feb 11, 2005, at 8:48 AM, Jim Hagen wrote:
At 16:41 Uhr +0200 10.02.2005, Ruslan Zasukhin wrote:
1) It looks very weird that I cannot create Fsref for non-existing object,
Like we was able do this with FSSpec. What a great idea is behind of this?
Clearly this entire line of questioning is one for the Carbon list, but it would seem from a quick glance at the functions and documentation it looks like you're expected to use FSSpec until you _need_ to drop down to the FSRef level. This makes sense when you look at the FSRef structure and realize that it doesn't store the full file path name.
FSRef should generally always be used in preference to FSSpec when possible. An concrete example of usage in a Unicode friendly way (notice I never once used FSSpec nor should I).
OSErr err;
HFSUniStr255 aliasName;
CFStringRef str = CFSTR("Some Name");
aliasName.length = CFStringGetLength(str);
CFStringGetCharacters(str, CFRangeMake(0, aliasName.length), aliasName.unicode);
FSRef prefFolderRef, aliasRef;
err = FSFindFolder(kUserDomain, kPreferencesFolderType, kCreateFolder, &prefFolderRef);
err = FSMakeFSRefUnicode(&prefFolderRef, aliasName.length, aliasName.unicode, kTextEncodingUnknown, &aliasRef);
if(err == noErr)
{
err = FSDeleteObject(&aliasRef);
}
if ((err == noErr) || (err == fnfErr)) {
err = FSCreateFileUnicode(&prefFolderRef,
aliasName.length, aliasName.unicode,
kFSCatInfoNone, NULL,
&aliasRef, NULL);
HFSUniStr255 dataForkName;
FSGetDataForkName(&dataForkName);
SInt16 refNum;
err = FSOpenFork(&aliasRef, dataForkName.length, dataForkName.unicode, fsCurPerm, &refNum);
if(refNum > -1)
{
FSRef appRef;
err = FSPathMakeRef([[[NSBundle mainBundle] bundlePath] UTF8String], &appRef, NULL);
AliasHandle alias;
err = FSNewAlias(NULL, &appRef, &alias);
long count = GetHandleSize((Handle)alias);
err = FSWrite(refNum, &count, *alias);
FSClose(refNum);
}
} _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden