Changeset 3193

Show
Ignore:
Timestamp:
08/15/05 13:38:00 (3 years ago)
Author:
morris
Message:

Load from separate defaults domain

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • WiredServer/trunk/PreferencePane/WPWired.m

    r3191 r3193  
    4747 
    4848+ (void)load { 
    49         NSBundle        *bundle
     49        NSBundle        *bundle, *zankaBundle
    5050        NSString        *path; 
    5151         
    52         path = [[[NSBundle bundleForClass:[self class]] privateFrameworksPath] 
    53                 stringByAppendingPathComponent:@"ZankaAdditions.framework"]; 
     52        bundle = [NSBundle bundleForClass:[self class]]; 
     53        path = [[bundle privateFrameworksPath] stringByAppendingPathComponent:@"ZankaAdditions.framework"]; 
     54        zankaBundle = [NSBundle bundleWithPath:path]; 
    5455         
    55         bundle = [NSBundle bundleWithPath:path]; 
    56          
    57         if(!bundle) 
     56        if(!zankaBundle) 
    5857                NSLog(@"Failed to load ZankaAdditions.framework from %@", path); 
    5958         
    60         if(![bundle load]) 
    61                 NSLog(@"Failed to load %@", bundle); 
     59        if(![zankaBundle load]) 
     60                NSLog(@"Failed to load %@", zankaBundle); 
     61         
     62        [WCSettings loadWithIdentifier:[bundle bundleIdentifier]]; 
    6263} 
    6364 
  • WiredServer/trunk/WCSettings.h

    r3011 r3193  
    2727 */ 
    2828 
    29 @interface WCSettings : NSObject { 
    30         NSMutableDictionary                             *_settings; 
    31         NSRecursiveLock                                 *_lock; 
    32 
    33  
     29@interface WCSettings : ZASettings 
    3430 
    3531#define WCPrefixPath                            @"WCPrefixPath" 
     
    5450NSString *                                                      WCExpandWiredPath(NSString *); 
    5551 
    56  
    57 + (WCSettings *)settings; 
    58 + (NSDictionary *)defaults; 
    59  
    60 + (id)objectForKey:(id)key; 
    61 + (NSString *)stringForKey:(id)key; 
    62 + (BOOL)boolForKey:(id)key; 
    63 + (int)intForKey:(id)key; 
    64 + (double)doubleForKey:(id)key; 
    65 + (void)setObject:(id)object forKey:(id)key; 
    66 + (void)setBool:(BOOL)value forKey:(id)key; 
    67 + (void)setInt:(int)value forKey:(id)key; 
    68 + (void)setDouble:(double)value forKey:(id)key; 
    69  
    7052@end 
  • WiredServer/trunk/WCSettings.m

    r3011 r3193  
    2929#import "WCSettings.h" 
    3030 
    31 @interface WCSettings(Private) 
    32  
    33 - (id)objectForKey:(id)key; 
    34 - (void)setObject:(id)object forKey:(id)key; 
    35  
    36 @end 
    37  
    38  
    3931@implementation WCSettings 
    4032 
     
    4436         
    4537        return [[WCSettings objectForKey:WCPrefixPath] stringByAppendingPathComponent:path]; 
    46 } 
    47  
    48  
    49  
    50 + (WCSettings *)settings { 
    51         static id sharedSettings; 
    52  
    53         if(!sharedSettings) 
    54                 sharedSettings = [[self alloc] init]; 
    55  
    56         return sharedSettings; 
    5738} 
    5839 
     
    8869} 
    8970 
    90  
    91  
    92 - (id)init { 
    93         NSUserDefaults  *defaults; 
    94         NSDictionary    *defaultValues; 
    95         NSString                *key; 
    96         NSEnumerator    *enumerator; 
    97         id                              object; 
    98  
    99         self = [super init]; 
    100  
    101         _settings = [[NSMutableDictionary alloc] init]; 
    102         _lock = [[NSRecursiveLock alloc] init]; 
    103  
    104         defaultValues = [[self class] defaults]; 
    105         defaults = [NSUserDefaults standardUserDefaults]; 
    106         enumerator = [defaultValues keyEnumerator]; 
    107  
    108         while((key = [enumerator nextObject])) { 
    109                 object = [defaults objectForKey:key]; 
    110  
    111                 if(!object) { 
    112                         object = [defaultValues objectForKey:key]; 
    113  
    114                         if([object isKindOfPropertyListSerializableClass]) 
    115                                 [defaults setObject:object forKey:key]; 
    116                         else 
    117                                 [defaults setObject:[NSArchiver archivedDataWithRootObject:object] forKey:key]; 
    118                 } 
    119  
    120                 if([object isKindOfClass:[NSData class]]) { 
    121                         object = [NSUnarchiver unarchiveObjectWithData:object]; 
    122  
    123                         if(object) 
    124                                 [_settings setObject:object forKey:key]; 
    125                 } 
    126                 else { 
    127                         [_settings setObject:object forKey:key]; 
    128                 } 
    129         } 
    130  
    131         return self; 
    132 } 
    133  
    134  
    135  
    136 #pragma mark - 
    137  
    138 - (id)objectForKey:(id)key { 
    139         id              object; 
    140  
    141         [_lock lock]; 
    142         object = [_settings objectForKey:key]; 
    143         [_lock unlock]; 
    144  
    145         return object; 
    146 } 
    147  
    148  
    149  
    150 - (void)setObject:(id)object forKey:(id)key { 
    151         NSUserDefaults          *defaults; 
    152  
    153         defaults = [NSUserDefaults standardUserDefaults]; 
    154  
    155         if([object isKindOfPropertyListSerializableClass]) 
    156                 [defaults setObject:object forKey:key]; 
    157         else 
    158                 [defaults setObject:[NSArchiver archivedDataWithRootObject:object] forKey:key]; 
    159  
    160         [_lock lock]; 
    161         [_settings setObject:object forKey:key]; 
    162         [_lock unlock]; 
    163  
    164         [defaults performSelectorOnce:@selector(synchronize) withObject:NULL afterDelay:0.1]; 
    165 } 
    166  
    167  
    168  
    169 #pragma mark - 
    170  
    171 + (id)objectForKey:(id)key { 
    172         return [[self settings] objectForKey:key]; 
    173 } 
    174  
    175  
    176  
    177 + (NSString *)stringForKey:(id)key { 
    178         return [[self settings] objectForKey:key]; 
    179 } 
    180  
    181  
    182  
    183 + (BOOL)boolForKey:(id)key { 
    184         return [[[self settings] objectForKey:key] boolValue]; 
    185 } 
    186  
    187  
    188  
    189 + (int)intForKey:(id)key { 
    190         return [[[self settings] objectForKey:key] intValue]; 
    191 } 
    192  
    193  
    194  
    195 + (double)doubleForKey:(id)key { 
    196         return [[[self settings] objectForKey:key] doubleValue]; 
    197 } 
    198  
    199  
    200  
    201 + (void)setObject:(id)object forKey:(id)key { 
    202         [[self settings] setObject:object forKey:key]; 
    203 } 
    204  
    205  
    206  
    207 + (void)setBool:(BOOL)value forKey:(id)key { 
    208         [[self settings] setObject:[NSNumber numberWithBool:value] forKey:key]; 
    209 } 
    210  
    211  
    212  
    213 + (void)setInt:(int)value forKey:(id)key { 
    214         [[self settings] setObject:[NSNumber numberWithInt:value] forKey:key]; 
    215 } 
    216  
    217  
    218  
    219 + (void)setDouble:(double)value forKey:(id)key { 
    220         [[self settings] setObject:[NSNumber numberWithDouble:value] forKey:key]; 
    221 } 
    222  
    22371@end