[vlc-devel] commit: macosx: Check for older preferences and ask to delete them. ( Pierre d'Herbemont )

git version control git at videolan.org
Tue Sep 16 15:28:02 CEST 2008


vlc | branch: 0.9-bugfix | Pierre d'Herbemont <pdherbemont at videolan.org> | Tue Sep 16 00:40:58 2008 +0200| [53b7c1b78cbd36626955b9a70809c38b1418a066] | committer: Felix Paul Kühne 

macosx: Check for older preferences and ask to delete them.

Signed-off-by: Felix Paul Kühne <fkuehne at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=53b7c1b78cbd36626955b9a70809c38b1418a066
---

 modules/gui/macosx/intf.m |   50 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m
index 256f6a2..4a46762 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -212,6 +212,11 @@ static int InteractCallback( vlc_object_t *p_this, const char *psz_variable,
 }
 
 #pragma mark -
+#pragma mark Private
+
+ at interface VLCMain ()
+- (void)_removeOldPreferences;
+ at end
 
 /*****************************************************************************
  * VLCMain implementation
@@ -460,6 +465,8 @@ static VLCMain *_o_sharedMainInstance = nil;
 
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
 {
+    [self _removeOldPreferences];
+
 #ifdef UPDATE_CHECK
     /* Check for update silently on startup */
     if( !nib_update_loaded )
@@ -2209,6 +2216,49 @@ end:
 }
 
 #pragma mark -
+#pragma mark Remove old prefs
+
+- (void)_removeOldPreferences
+{
+    static NSString * kVLCPreferencesVersion = @"VLCPreferencesVersion";
+    static const int kCurrentPreferencesVersion = 1;
+    int version = [[NSUserDefaults standardUserDefaults] integerForKey:kVLCPreferencesVersion];
+    if( version >= kCurrentPreferencesVersion ) return;
+
+    NSArray *libraries = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, 
+        NSUserDomainMask, YES);
+    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:@"VLC"]] &&
+       ![[NSFileManager defaultManager] fileExistsAtPath:[preferences stringByAppendingPathComponent:@"org.videolan.vlc.plist"]] )
+    {
+        [[NSUserDefaults standardUserDefaults] 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);
+    if( res != NSOKButton ) return;
+
+    NSArray * ourPreferences = [NSArray arrayWithObjects:@"org.videolan.vlc.plist", @"VLC"];
+
+    /* Move the file to trash so that user can find them later */
+    [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:preferences destination:nil files:ourPreferences tag:0];
+
+    /* really reset the defaults from now on */
+    [NSUserDefaults resetStandardUserDefaults];
+
+    [[NSUserDefaults standardUserDefaults] setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
+
+    /* Relaunch now */
+    [[NSWorkspace sharedWorkspace] launchApplication:[[NSBundle mainBundle] bundlePath]];
+    exit(0);
+}
+
+#pragma mark -
 #pragma mark Errors, warnings and messages
 
 - (IBAction)viewErrorsAndWarnings:(id)sender




More information about the vlc-devel mailing list