1 #import "ITMacResourceFile.h"
3 @implementation ITMacResourceFile
5 + (HFSUniStr255)dataForkName {
6 HFSUniStr255 dataForkName;
7 FSGetDataForkName(&dataForkName);
11 + (HFSUniStr255)resourceForkName {
12 HFSUniStr255 resourceForkName;
13 FSGetResourceForkName(&resourceForkName);
14 return resourceForkName;
17 - (id)initWithContentsOfFile:(NSString *)path {
18 return [self initWithContentsOfFile:path fork:[ITMacResourceFile dataForkName]];
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);
33 - (ITMacResource *)resourceOfType:(ITMacResourceType)type withID:(short)idNum {
34 return [[ITMacResource subclassForType:type] resourceWithHandle:GetResource((ResType)type, idNum)];
37 - (ITMacResource *)resourceOfType:(ITMacResourceType)type withName:(NSString *)name {
39 StringPtr _ptr = (StringPtr)CFStringGetPascalStringPtr((CFStringRef)name, kCFStringEncodingMacRomanLatin1);
41 if (CFStringGetPascalString((CFStringRef)name, _buffer, 256, kCFStringEncodingMacRomanLatin1)) {
47 return [[ITMacResource subclassForType:type] resourceWithHandle:GetNamedResource((ResType)type,_ptr)];
51 if (_referenceNumber) {
52 CloseResFile(_referenceNumber);