Re: ObjC++ (& Scary Carbon Stuff)
Re: ObjC++ (& Scary Carbon Stuff)
- Subject: Re: ObjC++ (& Scary Carbon Stuff)
- From: Chris Thomas <email@hidden>
- Date: Wed, 05 Dec 2001 12:22:53 -0800
On 12/5/01 8:32 AM, "Thomas Lachand-Robert" <email@hidden> wrote:
>
OSStatus status;
>
FSRef fsRef;
>
const char* cname;
>
FSSpec fsSpec;
>
FInfo fndrInfo;
>
>
cname = [[fullPath stringByExpandingTildeInPath] UTF8String];
>
status = FSPathMakeRef ((UInt8*) cname, &fsRef, NULL);
>
if (status == 0)
>
status = FSGetCatalogInfo (&fsRef, 0, NULL, NULL, &fsSpec, NULL);
>
if (status == 0)
>
status = FSpGetFInfo (&fsSpec, &fndrInfo);
>
if (status == 0) {
>
macType = fndrInfo.fdType;
>
macCreator = fndrInfo.fdCreator;
>
}
No wonder you're scared. Although it works, this code is inefficient in
several ways, and if you can point us to the place in the docs that you
found it, we'll fix it. Assuming that you don't want to use the Cocoa
methods introduced in 10.1 for retrieving the file type and creator (maybe
you want your code to run on 10.0, or maybe in the future you'll want to
read additional attributes that Cocoa doesn't have accessors for), you want
something more like:
// Carbon Headers
#include <Finder.h>
#include <Files.h>
#include <Debugging.h>
[...]
OSStatus status;
FSRef fileRef;
FSCatalogInfo catalogInfo;
char * cPath;
cPath = [fullPath fileSystemRepresentation];
status = FSPathMakeRef ((UInt8*) cPath, &fileRef, NULL);
require_noerr( status, evilHasComeToGetUs );
status = FSGetCatalogInfo (&fileRef, kFSCatalogFinderInfo, &catalogInfo,
NULL, NULL, NULL);
require_noerr( status, evilHasComeToGetUs );
macType = (*(FileInfo *)&catalogInfo.finderInfo).fileType;
macCreator = (*(FileInfo *)&catalogInfo.finderInfo).fileCreator;
evilHasComeToGetUs:
return status;
N.B. I have no idea whether the above code actually compiles, and the
constant for the FSCatalogBitmap parameter is likely wrong, but the general
form is accurate.
Chris