Fixing project references due to the previous upgrade from .xcode to .xcodeproj.
[ITMac.git] / ITMacResourceFile.m
1 #import "ITMacResourceFile.h"
2
3 @implementation ITMacResourceFile
4
5 + (HFSUniStr255)dataForkName {
6         HFSUniStr255 dataForkName;
7         FSGetDataForkName(&dataForkName);
8         return dataForkName;
9 }
10
11 + (HFSUniStr255)resourceForkName {
12         HFSUniStr255 resourceForkName;
13         FSGetResourceForkName(&resourceForkName);
14         return resourceForkName;
15 }
16
17 - (id)initWithContentsOfFile:(NSString *)path {
18         return [self initWithContentsOfFile:path fork:[ITMacResourceFile dataForkName]];
19 }
20
21 - (id)initWithContentsOfFile:(NSString *)path fork:(HFSUniStr255)namedFork {
22         if (self = [super init]) {
23                 if (FSPathMakeRef([path fileSystemRepresentation], &_fileReference, NULL) == noErr) {
24                         FSOpenResourceFile(&_fileReference, namedFork.length, namedFork.unicode, fsRdPerm, &_referenceNumber);
25                 } else {
26                         [super release];
27                         self = nil;
28                 }
29         }
30         return self;
31 }
32
33 - (ITMacResource *)resourceOfType:(ITMacResourceType)type withID:(short)idNum {
34         return [[ITMacResource subclassForType:type] resourceWithHandle:GetResource((ResType)type, idNum)];
35 }
36
37 - (ITMacResource *)resourceOfType:(ITMacResourceType)type withName:(NSString *)name {
38         Str255 _buffer;
39         StringPtr _ptr = (StringPtr)CFStringGetPascalStringPtr((CFStringRef)name, kCFStringEncodingMacRomanLatin1);
40         if (_ptr == NULL) {
41                 if (CFStringGetPascalString((CFStringRef)name, _buffer, 256, kCFStringEncodingMacRomanLatin1)) {
42                         _ptr = _buffer;
43                 } else {
44                         return nil;
45                 }
46         }
47         return [[ITMacResource subclassForType:type] resourceWithHandle:GetNamedResource((ResType)type,_ptr)];
48 }
49
50 - (void)dealloc {
51         if (_referenceNumber) {
52                 CloseResFile(_referenceNumber);
53         }
54         [super dealloc];
55 }
56
57 @end