mirror of
https://github.com/nickshanks/ResKnife.git
synced 2025-01-23 14:30:04 +00:00
106 lines
2.4 KiB
Objective-C
106 lines
2.4 KiB
Objective-C
//
|
|
// NuTemplatePSTRElement.m
|
|
// ResKnife (PB2)
|
|
//
|
|
// Created by Uli Kusterer on Tue Aug 05 2003.
|
|
// Copyright (c) 2003 M. Uli Kusterer. All rights reserved.
|
|
//
|
|
|
|
#import "NuTemplatePSTRElement.h"
|
|
|
|
|
|
@implementation NuTemplatePSTRElement
|
|
|
|
-(id) initForType: (NSString*)t withLabel: (NSString*)l
|
|
{
|
|
if( self = [super initForType:t withLabel:l] )
|
|
stringValue = [[NSString alloc] init];
|
|
|
|
return self;
|
|
}
|
|
|
|
-(void) dealloc
|
|
{
|
|
[stringValue release];
|
|
|
|
[super dealloc];
|
|
}
|
|
|
|
-(id) copyWithZone: (NSZone*)zone
|
|
{
|
|
NuTemplatePSTRElement* el = [super copyWithZone: zone];
|
|
|
|
if( el )
|
|
[el setStringValue: stringValue];
|
|
|
|
return el;
|
|
}
|
|
|
|
|
|
-(void) readDataFrom: (NuTemplateStream*)stream containingArray: (NSMutableArray*)containing
|
|
{
|
|
char buf[256] = { 0 };
|
|
|
|
if( [type isEqualToString: @"PSTR"] ) // Packed, variable-length string.
|
|
{
|
|
[stream readAmount:1 toBuffer: buf];
|
|
[stream readAmount:buf[0] toBuffer: (buf +1)];
|
|
}
|
|
else if( [type isEqualToString: @"P100"] ) // Constant-size string. Resourcerer-style P100, not ResEdit-style P0FF.
|
|
[stream readAmount:256 toBuffer: buf];
|
|
else if( [type isEqualToString: @"P020"] ) // Constant-size string. Resourcerer-style P020, not ResEdit-style P01F.
|
|
[stream readAmount:32 toBuffer: buf];
|
|
else if( [type isEqualToString: @"P040"] ) // Constant-size string. Resourcerer-style P040, not ResEdit-style P03F.
|
|
[stream readAmount:64 toBuffer: buf];
|
|
|
|
[self setStringValue: [NSString stringWithCString:(buf +1) length:buf[0]]];
|
|
|
|
NSLog(@"PSTR: %@", stringValue);
|
|
}
|
|
|
|
|
|
// Before writeDataTo: is called, this is called to calculate the final resource size:
|
|
-(unsigned int) sizeOnDisk
|
|
{
|
|
if( [type isEqualToString: @"PSTR"] )
|
|
return [stringValue length] +1;
|
|
else if( [type isEqualToString: @"P100"] ) // Str255
|
|
return 256;
|
|
else if( [type isEqualToString: @"P020"] ) // Str31
|
|
return 32;
|
|
else if( [type isEqualToString: @"P040"] ) // Str63
|
|
return 64;
|
|
else
|
|
return 1;
|
|
}
|
|
|
|
-(void) writeDataTo: (NuTemplateStream*)stream
|
|
{
|
|
unsigned char buf[257] = { 0 }; // 256 + terminating zero-byte (which isn't written, but generated by getCString)
|
|
|
|
[stringValue getCString:(buf +1) maxLength:255];
|
|
buf[0] = [stringValue length];
|
|
if( [type isEqualToString: @"PSTR"] )
|
|
[stream writeAmount:([stringValue length] +1) fromBuffer:buf];
|
|
else
|
|
[stream writeAmount:[self sizeOnDisk] fromBuffer:buf];
|
|
}
|
|
|
|
|
|
-(void) setStringValue: (NSString*)d
|
|
{
|
|
[d retain];
|
|
[stringValue release];
|
|
stringValue = d;
|
|
}
|
|
|
|
|
|
-(NSString*) stringValue
|
|
{
|
|
return stringValue;
|
|
}
|
|
|
|
|
|
|
|
@end
|