What's the fastest way to get icons for file/folders?
What's the fastest way to get icons for file/folders?
- Subject: What's the fastest way to get icons for file/folders?
- From: "Alan Smith" <email@hidden>
- Date: Fri, 18 Aug 2006 08:11:50 -0400
Hi everyone,
I ran my code through Shark and found that NSWorkspace's iconForFile
is too slow for me to keep in my code. So I looked around and found
some stuff on GetIconRefFromFile(). After writting some code I had a
nice NSImage category that got the icon at the path I specified. But
there are some paths (like: /Projects/App Controller, which is the
path to a directory) that it can't release the IconRef to. So, I've
pretty much given up on that and was wondering what my alternatives
were.
Thanks in advance, Alan
P.S. Below is the NSImage category.
- (NSImage*)initWithIconAtPath:(NSString*)path
{
if ([[NSFileManager defaultManager] fileExistsAtPath: path])
{
FSRef fsref;
FSSpec spec;
OSStatus status;
OSErr err;
status = FSPathMakeRef([path fileSystemRepresentation], &fsref, NULL);
if (status == noErr)
status = FSGetCatalogInfo(&fsref, kFSCatInfoNone, NULL,
NULL, &spec, NULL);
IconRef ref;
err = GetIconRefFromFile (&spec, &ref, (SInt16*) NULL);
if (err == noErr)
{
IconFamilyHandle fam;
NSData *imageData;
err = IconRefToIconFamily(ref, kSelectorAllAvailableData, &fam);
NSAssert(err == noErr, @"can't get icon family from icon ref");
err = ReleaseIconRef(ref);
NSAssert1(err == noErr, @"can't release icon ref %@", path);
imageData = [NSData dataWithBytes: *fam length:
fam[0]->resourceSize];
NSAssert(imageData != nil, @"can't make NSData from icon data");
return [self initWithData: imageData];
}
}
return nil;
}
--
// Quotes from yours truly -------------------------
"You don't forget, you just don't remember."
"Maturity resides in the mind."
"Silence is the Universe's greatest gift."
"Don't waste your life doing things others have already done."
_______________________________________________
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