]> git.sesse.net Git - vlc/commitdiff
macosx: fix broken first time settings setup
authorDavid Fuhrmann <dfuhrmann@videolan.org>
Thu, 19 Jun 2014 18:14:16 +0000 (20:14 +0200)
committerDavid Fuhrmann <dfuhrmann@videolan.org>
Thu, 19 Jun 2014 18:16:55 +0000 (20:16 +0200)
Handling with *.plist on the file system should really
be avoided, as its not safe at all. Thus the current
default version is set the right way now.

close #11625

modules/gui/macosx/intf.m

index 8f46abb7f86b4c380602280d258e35cb247348c3..6c127192dfdc5d5aaa8b99de0e2659178d00e2c5 100644 (file)
@@ -1679,6 +1679,14 @@ static VLCMain *_o_sharedMainInstance = nil;
 static NSString * kVLCPreferencesVersion = @"VLCPreferencesVersion";
 static const int kCurrentPreferencesVersion = 3;
 
++ (void)initialize
+{
+    NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCurrentPreferencesVersion]
+                                                            forKey:kVLCPreferencesVersion];
+
+    [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
+}
+
 - (void)resetAndReinitializeUserDefaults
 {
     // note that [NSUserDefaults resetStandardUserDefaults] will NOT correctly reset to the defaults
@@ -1695,6 +1703,13 @@ static const int kCurrentPreferencesVersion = 3;
 {
     NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
     int version = [defaults integerForKey:kVLCPreferencesVersion];
+
+    /*
+     * Store version explicitely in file, for ease of debugging.
+     * Otherwise, the value will be just defined at app startup,
+     * as initialized above.
+     */
+    [defaults setInteger:version forKey:kVLCPreferencesVersion];
     if (version >= kCurrentPreferencesVersion)
         return;
 
@@ -1717,13 +1732,6 @@ static const int kCurrentPreferencesVersion = 3;
         if (!libraries || [libraries count] == 0) return;
         NSString * preferences = [[libraries objectAtIndex:0] stringByAppendingPathComponent:@"Preferences"];
 
-        /* File not found, don't attempt anything */
-        if (![[NSFileManager defaultManager] fileExistsAtPath:[preferences stringByAppendingPathComponent:@"org.videolan.vlc"]] &&
-           ![[NSFileManager defaultManager] fileExistsAtPath:[preferences stringByAppendingPathComponent:@"org.videolan.vlc.plist"]]) {
-            [defaults setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
-            return;
-        }
-
         int res = NSRunInformationalAlertPanel(_NS("Remove old preferences?"),
                     _NS("We just found an older version of VLC's preferences files."),
                     _NS("Move To Trash and Relaunch VLC"), _NS("Ignore"), nil, nil);