-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathITMacResource.m
89 lines (72 loc) · 1.62 KB
/
ITMacResource.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#import "ITMacResource.h"
@implementation ITMacResource
+ (Class)subclassForType:(ITMacResourceType)type {
NSEnumerator *subclassEnumerator = [[self subclasses] objectEnumerator];
Class subclass;
while ((subclass = [subclassEnumerator nextObject])) {
if ([subclass supportsResourceType:type]) {
return subclass;
}
}
return self;
}
+ (NSArray *)supportedResourceTypes {
return [NSArray array];
}
+ (BOOL)supportsResourceType:(ITMacResourceType)type {
return [[self supportedResourceTypes] containsObject:[NSString stringWithFourCharCode:type]];
}
+ (id)resourceWithHandle:(Handle)handle {
return [[[self alloc] initWithHandle:handle] autorelease];
}
- (id)initWithHandle:(Handle)handle {
if (self = [super init]) {
_handle = handle;
}
return self;
}
- (Handle)handle {
return _handle;
}
- (NSData *)data {
NSData *_data;
HLock(_handle);
_data = [NSData dataWithBytes:(*_handle) length:GetHandleSize(_handle)];
HUnlock(_handle);
return _data;
}
- (ITMacResourceType)type {
short _id;
ResType _type;
Str255 _name;
GetResInfo(_handle, &_id, &_type, _name);
return (ITMacResourceType)_type;
}
- (short)id {
short _id;
ResType _type;
Str255 _name;
GetResInfo(_handle, &_id, &_type, _name);
return _id;
}
- (NSString *)name {
short _id;
ResType _type;
Str255 _name;
GetResInfo(_handle, &_id, &_type, _name);
return [(NSString*)CFStringCreateWithPascalString(NULL,
_name, kCFStringEncodingMacRomanLatin1) autorelease];
}
- (Class)nativeRepresentationClass {
return nil;
}
- (id)nativeRepresentation {
return nil;
}
- (void)dealloc {
if (_handle) {
ReleaseResource(_handle);
}
[super dealloc];
}
@end