Created
November 9, 2012 19:08
-
-
Save pjrobertson/4047584 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSDictionary *)infoRecord { | |
NSString *path = [self validSingleFilePath]; | |
if (!path) | |
return nil; | |
NSDictionary *dict; | |
if (dict = [self objectForCache:@"QSItemInfoRecord"]) | |
return dict; | |
/* Try to get information for this file */ | |
LSItemInfoRecord record; | |
OSStatus status = LSCopyItemInfoForURL((CFURLRef)[NSURL fileURLWithPath:path], kLSRequestAllInfo, &record); | |
if (status) { | |
NSLog(@"LSCopyItemInfoForURL error: %ld", (long)status); | |
return nil; | |
} | |
NSString *uti = QSUTIForExtensionOrType((NSString *)record.extension, record.filetype); | |
NSString *extension = [(NSString *)record.extension copy]; | |
/* local or network volume? does it support Trash? */ | |
struct statfs sfsb; | |
statfs([path UTF8String], &sfsb); | |
NSString *device = [NSString stringWithCString:sfsb.f_mntfromname encoding:NSUTF8StringEncoding]; | |
BOOL isLocal = [device hasPrefix:@"/dev/"]; | |
/* Now build a dictionary with that record */ | |
NSMutableDictionary *tempDict = [NSMutableDictionary dictionaryWithObjectsAndKeys: | |
[NSNumber numberWithUnsignedInt:record.flags], @"flags", | |
[NSValue valueWithOSType:record.filetype], @"filetype", | |
[NSValue valueWithOSType:record.creator], @"creator", | |
[NSNumber numberWithBool:record.flags & kLSItemInfoIsApplication, @"isApplication". | |
[NSNumber numberWithBool:isLocal], @"localVolume", | |
nil]; | |
if (uti) { | |
[tempDict setObject:uti forKey:@"uti"]; | |
} | |
if (extension) { | |
[tempDict setObject:extension forKey:@"extension"]; | |
} | |
dict = [NSDictionary dictionaryWithDictionary:tempDict]; | |
/* Release the file's extension if one was returned */ | |
if (record.extension) | |
CFRelease(record.extension); | |
[self setObject:dict forCache:@"QSItemInfoRecord"]; | |
return dict; | |
} | |
- (BOOL)isApplication { | |
NSDictionary *infoRecord = [self objectForCache:@"QSItemInfoRecord"]; | |
if(!infoRecord) { | |
BOOL isApp = [NFileManager … get is application; | |
[[self setObject:[NSDictionary dictionaryWithObjectAndKey:[NSNumber numberWithBool:isApp],@"isApplication,nil] forCache:@"QSItemInfoRecord"]; | |
} | |
return [[[self objectForCache:@"QSItemInfoRecord"] objectForKey:@"isApplication] boolValue]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment