From 9ca8a199c01210adaef7f5c603e5100e3596261f Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Fri, 5 Feb 2010 16:51:00 +0100 Subject: [PATCH] Re-implemented the fix for utf-8 lookup error during auto-update in a more graceful way. --- cocoa/base/AppDelegate.h | 5 +++++ cocoa/base/AppDelegate.m | 26 ++++++++++++++++++++++++-- cocoa/base/xib/MainMenu.xib | 32 ++++++++++++++++---------------- cocoa/me/AppDelegate.h | 7 +------ cocoa/me/AppDelegate.m | 3 ++- cocoa/pe/AppDelegate.h | 7 +------ cocoa/pe/AppDelegate.m | 3 ++- cocoa/se/AppDelegate.h | 7 +------ cocoa/se/AppDelegate.m | 3 ++- core/app.py | 9 ++------- 10 files changed, 56 insertions(+), 46 deletions(-) diff --git a/cocoa/base/AppDelegate.h b/cocoa/base/AppDelegate.h index db18f519..dbc11206 100644 --- a/cocoa/base/AppDelegate.h +++ b/cocoa/base/AppDelegate.h @@ -11,6 +11,7 @@ http://www.hardcoded.net/licenses/hs_license #import "PyDupeGuru.h" #import "ResultWindow.h" #import "DetailsPanel.h" +#import "DirectoryPanel.h" @interface AppDelegateBase : NSObject { @@ -19,11 +20,15 @@ http://www.hardcoded.net/licenses/hs_license IBOutlet NSMenuItem *unlockMenuItem; IBOutlet ResultWindowBase *result; + DirectoryPanelBase *_directoryPanel; DetailsPanelBase *_detailsPanel; + BOOL _savedResults; } - (IBAction)unlockApp:(id)sender; - (PyDupeGuruBase *)py; - (RecentDirectories *)recentDirectories; +- (DirectoryPanelBase *)directoryPanel; // Virtual - (DetailsPanelBase *)detailsPanel; // Virtual +- (void)saveResults; @end diff --git a/cocoa/base/AppDelegate.m b/cocoa/base/AppDelegate.m index 8067c91f..e0c0672a 100644 --- a/cocoa/base/AppDelegate.m +++ b/cocoa/base/AppDelegate.m @@ -11,6 +11,7 @@ http://www.hardcoded.net/licenses/hs_license #import "RegistrationInterface.h" #import "Utils.h" #import "Consts.h" +#import @implementation AppDelegateBase - (IBAction)unlockApp:(id)sender @@ -28,8 +29,19 @@ http://www.hardcoded.net/licenses/hs_license - (PyDupeGuruBase *)py { return py; } - (RecentDirectories *)recentDirectories { return recentDirectories; } +- (DirectoryPanelBase *)directoryPanel {return nil; } // Virtual - (DetailsPanelBase *)detailsPanel { return nil; } // Virtual +- (void)saveResults +{ + if (_savedResults) { + return; + } + [py saveIgnoreList]; + [py saveResults]; + _savedResults = YES; +} + /* Delegate */ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { @@ -48,6 +60,7 @@ http://www.hardcoded.net/licenses/hs_license //Restore results [py loadIgnoreList]; [py loadResults]; + _savedResults = NO; } - (void)applicationWillBecomeActive:(NSNotification *)aNotification @@ -61,8 +74,7 @@ http://www.hardcoded.net/licenses/hs_license NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; [ud setObject: [result getColumnsOrder] forKey:@"columnsOrder"]; [ud setObject: [result getColumnsWidth] forKey:@"columnsWidth"]; - [py saveIgnoreList]; - [py saveResults]; + [self saveResults]; NSInteger sc = [ud integerForKey:@"sessionCountSinceLastIgnorePurge"]; if (sc >= 10) { @@ -81,4 +93,14 @@ http://www.hardcoded.net/licenses/hs_license { [[self directoryPanel] addDirectory:directory]; } + +/* SUUpdater delegate */ + +- (BOOL)updater:(SUUpdater *)updater shouldPostponeRelaunchForUpdate:(SUAppcastItem *)update untilInvoking:(NSInvocation *)invocation; +{ + /* If results aren't saved now, we might get a weird utf-8 lookup error when saving later. + **/ + [self saveResults]; + return NO; +} @end diff --git a/cocoa/base/xib/MainMenu.xib b/cocoa/base/xib/MainMenu.xib index bb7c8c7c..627b5be2 100644 --- a/cocoa/base/xib/MainMenu.xib +++ b/cocoa/base/xib/MainMenu.xib @@ -2,10 +2,10 @@ 1050 - 10B504 + 10C540 740 - 1038.2 - 437.00 + 1038.25 + 458.00 com.apple.InterfaceBuilder.CocoaPlugin 740 @@ -83,11 +83,9 @@ Power Marker - + 256 {{7, 14}, {67, 24}} - - YES 67239424 @@ -178,11 +176,9 @@ Filter - + 258 {{0, 14}, {81, 22}} - - YES 343014976 @@ -324,11 +320,9 @@ Action - + 256 {{0, 14}, {58, 26}} - - YES -2076049856 @@ -531,11 +525,9 @@ Delta Values - + 256 {{4, 14}, {67, 24}} - - YES 67239424 @@ -2227,6 +2219,14 @@ 1174 + + + delegate + + + + 1175 + @@ -3584,7 +3584,7 @@ - 1174 + 1175 diff --git a/cocoa/me/AppDelegate.h b/cocoa/me/AppDelegate.h index 74f1d30a..24f63067 100644 --- a/cocoa/me/AppDelegate.h +++ b/cocoa/me/AppDelegate.h @@ -9,16 +9,11 @@ http://www.hardcoded.net/licenses/hs_license #import #import "../base/AppDelegate.h" #import "ResultWindow.h" -#import "DirectoryPanel.h" #import "PyDupeGuru.h" -@interface AppDelegate : AppDelegateBase -{ - DirectoryPanel *_directoryPanel; -} +@interface AppDelegate : AppDelegateBase {} - (IBAction)openWebsite:(id)sender; - (IBAction)toggleDirectories:(id)sender; -- (DirectoryPanel *)directoryPanel; - (PyDupeGuru *)py; @end diff --git a/cocoa/me/AppDelegate.m b/cocoa/me/AppDelegate.m index 70c53e1c..569b9f8f 100644 --- a/cocoa/me/AppDelegate.m +++ b/cocoa/me/AppDelegate.m @@ -13,6 +13,7 @@ http://www.hardcoded.net/licenses/hs_license #import "../../cocoalib/ValueTransformers.h" #import "../../cocoalib/Dialogs.h" #import "DetailsPanel.h" +#import "DirectoryPanel.h" #import "Consts.h" @implementation AppDelegate @@ -73,7 +74,7 @@ http://www.hardcoded.net/licenses/hs_license return _detailsPanel; } -- (DirectoryPanel *)directoryPanel +- (DirectoryPanelBase *)directoryPanel { if (!_directoryPanel) _directoryPanel = [[DirectoryPanel alloc] initWithParentApp:self]; diff --git a/cocoa/pe/AppDelegate.h b/cocoa/pe/AppDelegate.h index b3398fca..4e48f0b6 100644 --- a/cocoa/pe/AppDelegate.h +++ b/cocoa/pe/AppDelegate.h @@ -8,16 +8,11 @@ http://www.hardcoded.net/licenses/hs_license #import #import "../base/AppDelegate.h" -#import "DirectoryPanel.h" #import "PyDupeGuru.h" -@interface AppDelegate : AppDelegateBase -{ - DirectoryPanel *_directoryPanel; -} +@interface AppDelegate : AppDelegateBase {} - (IBAction)openWebsite:(id)sender; - (IBAction)toggleDirectories:(id)sender; -- (DirectoryPanel *)directoryPanel; - (PyDupeGuru *)py; @end diff --git a/cocoa/pe/AppDelegate.m b/cocoa/pe/AppDelegate.m index 8c6ef6a5..af42f5c4 100644 --- a/cocoa/pe/AppDelegate.m +++ b/cocoa/pe/AppDelegate.m @@ -13,6 +13,7 @@ http://www.hardcoded.net/licenses/hs_license #import "ValueTransformers.h" #import "Consts.h" #import "DetailsPanel.h" +#import "DirectoryPanel.h" @implementation AppDelegate + (void)initialize @@ -57,7 +58,7 @@ http://www.hardcoded.net/licenses/hs_license [[self directoryPanel] toggleVisible:sender]; } -- (DirectoryPanel *)directoryPanel +- (DirectoryPanelBase *)directoryPanel { if (!_directoryPanel) _directoryPanel = [[DirectoryPanel alloc] initWithParentApp:self]; diff --git a/cocoa/se/AppDelegate.h b/cocoa/se/AppDelegate.h index b3398fca..4e48f0b6 100644 --- a/cocoa/se/AppDelegate.h +++ b/cocoa/se/AppDelegate.h @@ -8,16 +8,11 @@ http://www.hardcoded.net/licenses/hs_license #import #import "../base/AppDelegate.h" -#import "DirectoryPanel.h" #import "PyDupeGuru.h" -@interface AppDelegate : AppDelegateBase -{ - DirectoryPanel *_directoryPanel; -} +@interface AppDelegate : AppDelegateBase {} - (IBAction)openWebsite:(id)sender; - (IBAction)toggleDirectories:(id)sender; -- (DirectoryPanel *)directoryPanel; - (PyDupeGuru *)py; @end diff --git a/cocoa/se/AppDelegate.m b/cocoa/se/AppDelegate.m index 81126e61..97c95bce 100644 --- a/cocoa/se/AppDelegate.m +++ b/cocoa/se/AppDelegate.m @@ -12,6 +12,7 @@ http://www.hardcoded.net/licenses/hs_license #import "../../cocoalib/Utils.h" #import "../../cocoalib/ValueTransformers.h" #import "DetailsPanel.h" +#import "DirectoryPanel.h" #import "Consts.h" @implementation AppDelegate @@ -56,7 +57,7 @@ http://www.hardcoded.net/licenses/hs_license [[self directoryPanel] toggleVisible:sender]; } -- (DirectoryPanel *)directoryPanel +- (DirectoryPanelBase *)directoryPanel { if (!_directoryPanel) _directoryPanel = [[DirectoryPanel alloc] initWithParentApp:self]; diff --git a/core/app.py b/core/app.py index 5e1e3f1b..4b8c655d 100644 --- a/core/app.py +++ b/core/app.py @@ -212,13 +212,8 @@ class DupeGuru(RegistrableApplication): changed_groups.add(g) def save(self): - try: - self.directories.save_to_file(op.join(self.appdata, 'last_directories.xml')) - self.results.save_to_xml(op.join(self.appdata, 'last_results.xml')) - except LookupError: - # This is that weird issue from #39 that sometimes happens when auto-updating with - # Sparkle. Just ignore it. - pass + self.directories.save_to_file(op.join(self.appdata, 'last_directories.xml')) + self.results.save_to_xml(op.join(self.appdata, 'last_results.xml')) def save_ignore_list(self): p = op.join(self.appdata, 'ignore_list.xml')