Fixed multi-monitorness except with Pivot, which is only half fixed.
[ITKit.git] / ITMacResourceFile.m
1 //
2 //  ITMacResourceFile.m
3 //  ITKit
4 //
5 //  Created by Joseph Spiros on Thu Dec 25 2003.
6 //  Copyright (c) 2003 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "ITMacResourceFile.h"
10
11
12 @implementation ITMacResourceFile
13
14 - (id)initWithContentsOfFile:(NSString *)path {
15     HFSUniStr255 dataForkName;
16     FSGetDataForkName(&dataForkName);
17     return [self initWithContentsOfFile:path fork:dataForkName];
18 }
19
20 - (id)initWithContentsOfFile:(NSString *)path fork:(HFSUniStr255)namedFork {
21     if (self = [super init]) {
22         if (FSPathMakeRef([path fileSystemRepresentation],&_fileReference,NULL) == noErr) {
23             FSOpenResourceFile(&_fileReference, namedFork.length, namedFork.unicode, fsRdPerm, &_referenceNumber);
24         } else {
25             // Raise Exception!
26         }
27     }
28     return self;
29 }
30
31 - (ITMacResource *)resourceOfType:(ITMacResourceType)type withID:(NSNumber *)idNum {
32     return [[ITMacResource _classForType:type] _resourceWithHandle:GetResource((ResType)type,[idNum shortValue])];
33 }
34
35 - (ITMacResource *)resourceOfType:(ITMacResourceType)type withName:(NSString *)name {
36     Str255 _buffer;
37     StringPtr _ptr = CFStringGetPascalStringPtr((CFStringRef)name, kCFStringEncodingMacRomanLatin1);
38     if (_ptr == NULL) {
39         if (CFStringGetPascalString((CFStringRef)name, _buffer, 256, kCFStringEncodingMacRomanLatin1)) {
40             _ptr = _buffer;
41         } else {
42             // Raise exception!
43         }
44     }
45     return [[ITMacResource _classForType:type] _resourceWithHandle:GetNamedResource((ResType)type,_ptr)];
46 }
47
48 - (void)dealloc {
49     CloseResFile(_referenceNumber);
50     [super dealloc];
51 }
52
53 @end