[vlc-commits] macosx: improve the handling of broken prefs and make sure that the user is unable to re-break them without using the command-line or a text editor

Felix Paul Kühne git at videolan.org
Fri May 11 13:06:33 CEST 2012


vlc/vlc-2.0 | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Fri May 11 13:05:03 2012 +0200| [672577b7fda2be059a330de1578ac15b8d9c7f17] | committer: Felix Paul Kühne

macosx: improve the handling of broken prefs and make sure that the user is unable to re-break them without using the command-line or a text editor
(cherry picked from commit 4fac18958067cc3506413ae1d690910a1994506b)

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=672577b7fda2be059a330de1578ac15b8d9c7f17
---

 modules/gui/macosx/CoreInteraction.h |    2 +
 modules/gui/macosx/CoreInteraction.m |   37 ++++++++++++++++++++++++++++++++++
 modules/gui/macosx/intf.m            |   32 +---------------------------
 modules/gui/macosx/prefs.m           |    2 +
 modules/gui/macosx/simple_prefs.m    |    2 +
 5 files changed, 45 insertions(+), 30 deletions(-)

diff --git a/modules/gui/macosx/CoreInteraction.h b/modules/gui/macosx/CoreInteraction.h
index 5c80635..abe0d86 100644
--- a/modules/gui/macosx/CoreInteraction.h
+++ b/modules/gui/macosx/CoreInteraction.h
@@ -75,4 +75,6 @@
 - (void)setAspectRatioLocked:(BOOL)b_value;
 - (BOOL)aspectRatioIsLocked;
 - (void)toggleFullscreen;
+
+- (BOOL)fixPreferences;
 @end
diff --git a/modules/gui/macosx/CoreInteraction.m b/modules/gui/macosx/CoreInteraction.m
index cc3a075..475c389 100644
--- a/modules/gui/macosx/CoreInteraction.m
+++ b/modules/gui/macosx/CoreInteraction.m
@@ -638,4 +638,41 @@ static VLCCoreInteraction *_o_sharedInstance = nil;
     }
 }
 
+#pragma mark -
+#pragma mark uncommon stuff
+
+- (BOOL)fixPreferences
+{
+    NSMutableString * o_workString;
+    NSRange returnedRange;
+    NSRange fullRange;
+    BOOL b_needsRestart = NO;
+
+    #define fixpref( pref ) \
+    o_workString = [[NSMutableString alloc] initWithFormat:@"%s", config_GetPsz( VLCIntf, pref )]; \
+    if ([o_workString length] > 0) \
+    { \
+        returnedRange = [o_workString rangeOfString:@"macosx" options: NSCaseInsensitiveSearch]; \
+        if (returnedRange.location != NSNotFound) \
+        { \
+            if ([o_workString isEqualToString:@"macosx"]) \
+                [o_workString setString:@""]; \
+            fullRange = NSMakeRange( 0, [o_workString length] ); \
+            [o_workString replaceOccurrencesOfString:@":macosx" withString:@"" options: NSCaseInsensitiveSearch range: fullRange]; \
+            fullRange = NSMakeRange( 0, [o_workString length] ); \
+            [o_workString replaceOccurrencesOfString:@"macosx:" withString:@"" options: NSCaseInsensitiveSearch range: fullRange]; \
+            \
+            config_PutPsz( VLCIntf, pref, [o_workString UTF8String] ); \
+            b_needsRestart = YES; \
+        } \
+    } \
+    [o_workString release]
+
+    fixpref( "control" );
+    fixpref( "extraintf" );
+    #undef fixpref
+
+    return b_needsRestart;
+}
+
 @end
diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m
index 13723db..74d0121 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -1895,38 +1895,10 @@ unsigned int CocoaKeyToVLC( unichar i_key )
 
     if( version == 1 )
     {
-        NSMutableString * o_workString;
-        NSRange returnedRange;
-        NSRange fullRange;
-        BOOL b_needsRestart = NO;
-
-        #define fixpref( pref ) \
-        o_workString = [[NSMutableString alloc] initWithFormat:@"%s", config_GetPsz( VLCIntf, pref )]; \
-        if ([o_workString length] > 0) \
-        { \
-            returnedRange = [o_workString rangeOfString:@"macosx" options: NSCaseInsensitiveSearch]; \
-            if (returnedRange.location != NSNotFound) \
-            { \
-                fullRange = NSMakeRange( 0, [o_workString length] ); \
-                [o_workString replaceOccurrencesOfString:@":macosx" withString:@"" options: NSCaseInsensitiveSearch range: fullRange]; \
-                fullRange = NSMakeRange( 0, [o_workString length] ); \
-                [o_workString replaceOccurrencesOfString:@"macosx:" withString:@"" options: NSCaseInsensitiveSearch range: fullRange]; \
-                fullRange = NSMakeRange( 0, [o_workString length] ); \
-                [o_workString replaceOccurrencesOfString:@"macosx" withString:@"" options: NSCaseInsensitiveSearch range: fullRange]; \
-                config_PutPsz( VLCIntf, pref, [o_workString UTF8String] ); \
-                b_needsRestart = YES; \
-            } \
-        } \
-        [o_workString release]
-
-        fixpref( "control" );
-        fixpref( "extraintf" );
-        #undef fixpref
-
         [[NSUserDefaults standardUserDefaults] setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
         [[NSUserDefaults standardUserDefaults] synchronize];
 
-        if (!b_needsRestart)
+        if (![[VLCCoreInteraction sharedInstance] fixPreferences])
             return;
         else
             config_SaveConfigFile( VLCIntf ); // we need to do manually, since we won't quit libvlc cleanly
@@ -1955,7 +1927,7 @@ unsigned int CocoaKeyToVLC( unichar i_key )
             return;
         }
 
-        NSArray * ourPreferences = [NSArray arrayWithObjects:@"org.videolan.vlc.plist", @"VLC", nil];
+        NSArray * ourPreferences = [NSArray arrayWithObjects:@"org.videolan.vlc.plist", @"VLC", @"org.videolan.vlc", nil];
 
         /* Move the file to trash so that user can find them later */
         [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:preferences destination:nil files:ourPreferences tag:0];
diff --git a/modules/gui/macosx/prefs.m b/modules/gui/macosx/prefs.m
index 6b85d24..811f4e4 100644
--- a/modules/gui/macosx/prefs.m
+++ b/modules/gui/macosx/prefs.m
@@ -57,6 +57,7 @@
 #import "prefs.h"
 #import "simple_prefs.h"
 #import "prefs_widgets.h"
+#import "CoreInteraction.h"
 #import <vlc_keys.h>
 #import <vlc_modules.h>
 
@@ -212,6 +213,7 @@ static VLCPrefs *_o_sharedMainInstance = nil;
 {
     /* TODO: call savePrefs on Root item */
     [_rootTreeItem applyChanges];
+    [[VLCCoreInteraction sharedInstance] fixPreferences];
     config_SaveConfigFile( p_intf );
     [o_prefs_window orderOut:self];
 }
diff --git a/modules/gui/macosx/simple_prefs.m b/modules/gui/macosx/simple_prefs.m
index ed3ba1e..d419492 100644
--- a/modules/gui/macosx/simple_prefs.m
+++ b/modules/gui/macosx/simple_prefs.m
@@ -1009,6 +1009,8 @@ static inline void save_module_list( intf_thread_t * p_intf, id object, const ch
         b_hotkeyChanged = NO;
     }
 
+    [[VLCCoreInteraction sharedInstance] fixPreferences];
+
     /* okay, let's save our changes to vlcrc */
     config_SaveConfigFile( p_intf );
 



More information about the vlc-commits mailing list