• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: ObjC++ (& Scary Carbon Stuff)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: ObjC++ (& Scary Carbon Stuff)
      • From: Thomas Lachand-Robert <email@hidden>
References: 
 >Re: ObjC++ (and a word about Java, too ;-) (From: Thomas Lachand-Robert <email@hidden>)

  • Prev by Date: Re: getFocus on NSTextField
  • Next by Date: Re: ObjC++ (& Scary Carbon Stuff)
  • Previous by thread: Re: ObjC++ (and a word about Java, too ;-)
  • Next by thread: Re: ObjC++ (& Scary Carbon Stuff)
  • Index(es):
    • Date
    • Thread