-
Notifications
You must be signed in to change notification settings - Fork 11
/
NDResourceFork+OtherSorces.m
executable file
·58 lines (47 loc) · 1.37 KB
/
NDResourceFork+OtherSorces.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* NDResourceFork+OtherSorces.m category
* NDResourceFork
*
* Created by Nathan Day on Thu Dec 05 2002.
* Copyright (c) 2002 Nathan Day. All rights reserved.
*/
#import "NDResourceFork+OtherSorces.h"
#import "NSURL+NDCarbonUtilities.h"
/*
* category implementation NDResourceFork (OtherSorces)
*/
@implementation NDResourceFork (OtherSorces)
/*
* +iconFamilyDataForURL:
*/
+ (NSData *)iconFamilyDataForURL:(NSURL *)aURL
{
NSData * theIconFamilyData = nil;
FSRef theFSRef;
IconRef theIconRef;
SInt16 theOutLabel;
IconFamilyHandle theIconFamilyHandle;
if( [aURL getFSRef:&theFSRef] )
{
if( noErr == GetIconRefFromFileInfo( &theFSRef, 0, NULL, kFSCatInfoFinderInfo, NULL, kIconServicesNormalUsageFlag, &theIconRef, &theOutLabel ) )
{
if( noErr == IconRefToIconFamily( theIconRef, kSelectorAllAvailableData, &theIconFamilyHandle ) )
{
HLock( (Handle)theIconFamilyHandle );
theIconFamilyData = [NSData dataWithBytes:*theIconFamilyHandle length:GetHandleSize( (Handle)theIconFamilyHandle )];
HUnlock( (Handle)theIconFamilyHandle );
DisposeHandle( (Handle)theIconFamilyHandle );
}
ReleaseIconRef( theIconRef );
}
}
return theIconFamilyData;
}
/*
* +iconFamilyDataForFile:
*/
+ (NSData *)iconFamilyDataForFile:(NSString *)aPath
{
return [self iconFamilyDataForURL:[NSURL fileURLWithPath:aPath]];
}
@end