]> git.saurik.com Git - winterboard.git/commitdiff
Remove code duplication that had already drifted.
authorJay Freeman (saurik) <saurik@saurik.com>
Wed, 14 Mar 2012 08:55:27 +0000 (08:55 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Wed, 14 Mar 2012 08:55:27 +0000 (08:55 +0000)
Settings.mm

index 2029981d245322ce6028f111a3b4812f0b4efb5e..6ba7b41261dd53e5cc8a657c764377f92661196a 100644 (file)
@@ -445,25 +445,29 @@ static NSString *_plist;
     UnHideIconViaDisplayId = reinterpret_cast<BOOL (*)(NSString *)>(dlsym(libhide, "UnHideIconViaDisplayId"));
 }
 
-- (id) initForContentSize:(CGSize)size {
-    if ((self = [super initForContentSize:size]) != nil) {
-        _plist = [[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.WinterBoard.plist", NSHomeDirectory()] retain];
-        _settings = [NSMutableDictionary dictionaryWithContentsOfFile:_plist];
-
-        bool set;
-        if (_settings != nil)
-            set = true;
-        else {
-            set = false;
-            _settings = [NSMutableDictionary dictionary];
-        }
+- (void) _wb$loadSettings {
+    _plist = [[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.WinterBoard.plist", NSHomeDirectory()] retain];
+    _settings = [NSMutableDictionary dictionaryWithContentsOfFile:_plist];
+
+    bool set;
+    if (_settings != nil)
+        set = true;
+    else {
+        set = false;
+        _settings = [NSMutableDictionary dictionary];
+    }
 
-        _settings = [_settings retain];
+    _settings = [_settings retain];
 
-        if ([_settings objectForKey:@"SummerBoard"] == nil)
-            [_settings setObject:[NSNumber numberWithBool:set] forKey:@"SummerBoard"];
+    if ([_settings objectForKey:@"SummerBoard"] == nil)
+        [_settings setObject:[NSNumber numberWithBool:set] forKey:@"SummerBoard"];
 
-        [_settings setObject:[NSNumber numberWithBool:IsIconHiddenDisplayId(WinterBoardDisplayID)] forKey:@"IconHidden"];
+    [_settings setObject:[NSNumber numberWithBool:IsIconHiddenDisplayId(WinterBoardDisplayID)] forKey:@"IconHidden"];
+}
+
+- (id) initForContentSize:(CGSize)size {
+    if ((self = [super initForContentSize:size]) != nil) {
+        [self _wb$loadSettings];
     } return self;
 }
 
@@ -510,10 +514,9 @@ static NSString *_plist;
 - (void) cancelChanges {
     [_settings release];
     [_plist release];
-    _plist = [[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.WinterBoard.plist", NSHomeDirectory()] retain];
-    _settings = [([NSMutableDictionary dictionaryWithContentsOfFile:_plist] ?: [NSMutableDictionary dictionary]) retain];
 
-    [_settings setObject:[NSNumber numberWithBool:IsIconHiddenDisplayId(WinterBoardDisplayID)] forKey:@"IconHidden"];
+    [self _wb$loadSettings];
+
     [self reloadSpecifiers];
     if (![[PSViewController class] instancesRespondToSelector:@selector(showLeftButton:withStyle:rightButton:withStyle:)]) {
         [[self navigationItem] setLeftBarButtonItem:nil];