-
Notifications
You must be signed in to change notification settings - Fork 0
/
ITMacResourceFile.m
57 lines (48 loc) · 1.57 KB
/
ITMacResourceFile.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
#import "ITMacResourceFile.h"
@implementation ITMacResourceFile
+ (HFSUniStr255)dataForkName {
HFSUniStr255 dataForkName;
FSGetDataForkName(&dataForkName);
return dataForkName;
}
+ (HFSUniStr255)resourceForkName {
HFSUniStr255 resourceForkName;
FSGetResourceForkName(&resourceForkName);
return resourceForkName;
}
- (id)initWithContentsOfFile:(NSString *)path {
return [self initWithContentsOfFile:path fork:[ITMacResourceFile dataForkName]];
}
- (id)initWithContentsOfFile:(NSString *)path fork:(HFSUniStr255)namedFork {
if (self = [super init]) {
if (FSPathMakeRef([path fileSystemRepresentation], &_fileReference, NULL) == noErr) {
FSOpenResourceFile(&_fileReference, namedFork.length, namedFork.unicode, fsRdPerm, &_referenceNumber);
} else {
[super release];
self = nil;
}
}
return self;
}
- (ITMacResource *)resourceOfType:(ITMacResourceType)type withID:(short)idNum {
return [[ITMacResource subclassForType:type] resourceWithHandle:GetResource((ResType)type, idNum)];
}
- (ITMacResource *)resourceOfType:(ITMacResourceType)type withName:(NSString *)name {
Str255 _buffer;
StringPtr _ptr = (StringPtr)CFStringGetPascalStringPtr((CFStringRef)name, kCFStringEncodingMacRomanLatin1);
if (_ptr == NULL) {
if (CFStringGetPascalString((CFStringRef)name, _buffer, 256, kCFStringEncodingMacRomanLatin1)) {
_ptr = _buffer;
} else {
return nil;
}
}
return [[ITMacResource subclassForType:type] resourceWithHandle:GetNamedResource((ResType)type,_ptr)];
}
- (void)dealloc {
if (_referenceNumber) {
CloseResFile(_referenceNumber);
}
[super dealloc];
}
@end