Re: ObjC++ (& Scary Carbon Stuff)
Re: ObjC++ (& Scary Carbon Stuff)
- Subject: Re: ObjC++ (& Scary Carbon Stuff)
- From: Thomas Lachand-Robert <email@hidden>
- Date: Wed, 5 Dec 2001 22:01:22 +0100
Le mercredi 5 dicembre 2001, ` 09:22 , Chris Thomas a icrit :
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.
Eeeeeh... Sorry but I'm still scared... particularly because you seem
unsure about your own code, because of (*(FileInfo
*)&catalogInfo.finderInfo) and 'evilHasComeToGetUs' does not make things
better.
C. Cox has suggested in Cocoa:
NSString *expandedPath = [fullPath stringByExpandingTildeInPath];
NSDictionary *fattrs = [ [ NSFileManager defaultManager ]
fileAttributesAtPath: expandedPath traverseLink: YES ];
macType = [ fattrs fileHFSTypeCode ];
macCreator = [ fattrs fileHFSCreatorCode ];
so I will let everyone here make his own mind about the difference between
Cocoa and Carbon based on this small example <LARGE GRIN>.
Thomas Lachand-Robert
********************** email@hidden
<< Et le chemin est long du projet ` la chose. >> Molihre, Tartuffe.