2004-06-16 02:30:32 +00:00
|
|
|
/* Preferences.m - Preferences
|
|
|
|
class and support functions for the
|
|
|
|
Macintosh OS X SDL port of Stella
|
|
|
|
Mark Grebe <atarimac@cox.net>
|
|
|
|
|
|
|
|
Based on the Preferences pane of the
|
|
|
|
TextEdit application.
|
|
|
|
|
|
|
|
*/
|
2006-02-28 02:17:26 +00:00
|
|
|
/* $Id: Preferences.m,v 1.3 2006-02-28 02:17:26 markgrebe Exp $ */
|
2004-06-16 02:30:32 +00:00
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
#import "Preferences.h"
|
|
|
|
#import "SDL.h"
|
|
|
|
|
2009-10-13 00:30:45 +00:00
|
|
|
void prefsSetString(const char* key, const char* value)
|
2004-06-16 02:30:32 +00:00
|
|
|
{
|
2009-10-27 18:05:19 +00:00
|
|
|
[[Preferences sharedInstance] setString:key:value];
|
2004-06-16 02:30:32 +00:00
|
|
|
}
|
|
|
|
|
2009-10-13 00:30:45 +00:00
|
|
|
void prefsGetString(const char* key, char* value, int size)
|
2004-06-16 02:30:32 +00:00
|
|
|
{
|
2009-10-27 18:05:19 +00:00
|
|
|
[[Preferences sharedInstance] getString:key:value:size];
|
2004-06-16 02:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void prefsSave(void)
|
|
|
|
{
|
2009-10-27 18:05:19 +00:00
|
|
|
[[Preferences sharedInstance] save];
|
2004-06-16 02:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@implementation Preferences
|
|
|
|
|
|
|
|
static Preferences *sharedInstance = nil;
|
|
|
|
|
2009-10-27 18:05:19 +00:00
|
|
|
+ (Preferences *)sharedInstance
|
|
|
|
{
|
|
|
|
return sharedInstance ? sharedInstance : [[self alloc] init];
|
2004-06-16 02:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id)init
|
|
|
|
{
|
2009-10-27 18:05:19 +00:00
|
|
|
defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
sharedInstance = self;
|
|
|
|
return(self);
|
2004-06-16 02:30:32 +00:00
|
|
|
}
|
|
|
|
|
2009-10-13 00:30:45 +00:00
|
|
|
- (void)setString:(const char *)key:(const char *)value
|
2004-06-16 02:30:32 +00:00
|
|
|
{
|
2009-10-13 00:30:45 +00:00
|
|
|
NSString* theKey = [NSString stringWithCString:key encoding:NSASCIIStringEncoding];
|
2009-10-27 18:05:19 +00:00
|
|
|
NSString* theValue = [NSString stringWithCString:value encoding:NSASCIIStringEncoding];
|
2009-10-13 00:30:45 +00:00
|
|
|
|
|
|
|
[defaults setObject:theValue forKey:theKey];
|
|
|
|
[theKey release];
|
|
|
|
[theValue release];
|
2004-06-16 02:30:32 +00:00
|
|
|
}
|
|
|
|
|
2009-10-13 00:30:45 +00:00
|
|
|
- (void)getString:(const char *)key:(char *)value:(int)size
|
2004-06-16 02:30:32 +00:00
|
|
|
{
|
2009-10-13 00:30:45 +00:00
|
|
|
NSString* theKey = [NSString stringWithCString:key encoding:NSASCIIStringEncoding];
|
2009-10-27 18:05:19 +00:00
|
|
|
NSString* theValue = [defaults objectForKey:theKey];
|
|
|
|
if (theValue != nil)
|
2009-10-13 00:30:45 +00:00
|
|
|
strncpy(value, [theValue cStringUsingEncoding: NSASCIIStringEncoding], size);
|
2009-10-27 18:05:19 +00:00
|
|
|
else
|
2009-10-13 00:30:45 +00:00
|
|
|
value[0] = 0;
|
|
|
|
|
|
|
|
[theKey release];
|
|
|
|
[theValue release];
|
2004-06-16 02:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)save
|
|
|
|
{
|
2009-10-27 18:05:19 +00:00
|
|
|
[defaults synchronize];
|
2004-06-16 02:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|