From 5533bc572d18ff0aea7a1002f80b260f1826f223 Mon Sep 17 00:00:00 2001 From: michael starke Date: Wed, 31 Aug 2016 16:02:08 +0200 Subject: [PATCH] added errore recovery and fixed issue in project file due to missing file --- MacPass.xcodeproj/project.pbxproj | 19 ++++-------- MacPass/MPErrorRecoveryAttempter.h | 16 +++++++++++ MacPass/MPErrorRecoveryAttempter.m | 46 ++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 MacPass/MPErrorRecoveryAttempter.h create mode 100644 MacPass/MPErrorRecoveryAttempter.m diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 6d8d3a8f..cadb5d27 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -143,6 +143,7 @@ 4C76155C1764C04C0015A1A6 /* GeneralSettings.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C76155E1764C04C0015A1A6 /* GeneralSettings.xib */; }; 4C7615681764C0C40015A1A6 /* PasswordInputView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C76156A1764C0C40015A1A6 /* PasswordInputView.xib */; }; 4C76156D1764C0E20015A1A6 /* InspectorView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C76156F1764C0E20015A1A6 /* InspectorView.xib */; }; + 4C7679BF1D76D6D8001F33D6 /* MPErrorRecoveryAttempter.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C7679BE1D76D6D8001F33D6 /* MPErrorRecoveryAttempter.m */; }; 4C7714AA176C998F00549F2A /* 43_TrashTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4C7714A9176C998F00549F2A /* 43_TrashTemplate.pdf */; }; 4C77547516E55FE800970E02 /* MPInspectorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C77547416E55FE800970E02 /* MPInspectorViewController.m */; }; 4C77C84118E240E000D1C42B /* DDHotKey+MacPassAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C77C84018E240E000D1C42B /* DDHotKey+MacPassAdditions.m */; }; @@ -498,6 +499,8 @@ 4C7615781764C4A50015A1A6 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = de; path = de.lproj/Credits.rtf; sourceTree = ""; }; 4C7615791764C4A50015A1A6 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/InfoPlist.strings; sourceTree = ""; }; 4C7679BC1D75E690001F33D6 /* MPModelChangeObserving.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPModelChangeObserving.h; sourceTree = ""; }; + 4C7679BD1D76D6D8001F33D6 /* MPErrorRecoveryAttempter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPErrorRecoveryAttempter.h; sourceTree = ""; }; + 4C7679BE1D76D6D8001F33D6 /* MPErrorRecoveryAttempter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPErrorRecoveryAttempter.m; sourceTree = ""; }; 4C7714A9176C998F00549F2A /* 43_TrashTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = 43_TrashTemplate.pdf; sourceTree = ""; }; 4C77547316E55FE800970E02 /* MPInspectorViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPInspectorViewController.h; sourceTree = ""; }; 4C77547416E55FE800970E02 /* MPInspectorViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPInspectorViewController.m; sourceTree = ""; }; @@ -598,8 +601,6 @@ 4CCA7EEC1797866F00B0B55E /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/GeneralSettings.strings; sourceTree = ""; }; 4CCA7EEE1797867200B0B55E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/GeneralSettings.strings; sourceTree = ""; }; 4CCA8E9A18D91ED9001A6754 /* Quartz.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quartz.framework; path = System/Library/Frameworks/Quartz.framework; sourceTree = SDKROOT; }; - 4CCCD83C1C8DFF20002B77B6 /* MPEntryProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntryProxy.h; sourceTree = ""; }; - 4CCCD83D1C8DFF20002B77B6 /* MPEntryProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPEntryProxy.m; sourceTree = ""; }; 4CCCE7FF1D75CA48006AA951 /* MPArrayController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPArrayController.h; sourceTree = ""; }; 4CCCE8001D75CA48006AA951 /* MPArrayController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPArrayController.m; sourceTree = ""; }; 4CCEDE28179F203B008402BE /* MPOutlineView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPOutlineView.h; sourceTree = ""; }; @@ -876,6 +877,8 @@ 4CCEDE2D179F213B008402BE /* MPNotifications.m */, 4C663D3F1D6D91A900CB6237 /* MPNumberFormatter.h */, 4C663D401D6D91A900CB6237 /* MPNumberFormatter.m */, + 4C7679BD1D76D6D8001F33D6 /* MPErrorRecoveryAttempter.h */, + 4C7679BE1D76D6D8001F33D6 /* MPErrorRecoveryAttempter.m */, ); name = Common; sourceTree = ""; @@ -966,7 +969,6 @@ 4C6B7C7C18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.m */, 4C0AF62D195C1F2B009E658D /* MPEntrySearchContext.h */, 4C0AF62E195C1F2B009E658D /* MPEntrySearchContext.m */, - 4CB44EEE1C972BFD00EE2D60 /* Proxies */, ); name = Model; sourceTree = ""; @@ -1299,15 +1301,6 @@ name = Protocolls; sourceTree = ""; }; - 4CB44EEE1C972BFD00EE2D60 /* Proxies */ = { - isa = PBXGroup; - children = ( - 4CCCD83C1C8DFF20002B77B6 /* MPEntryProxy.h */, - 4CCCD83D1C8DFF20002B77B6 /* MPEntryProxy.m */, - ); - name = Proxies; - sourceTree = ""; - }; 4CCFA12C1BF0CC7A0078E0A1 /* Databases */ = { isa = PBXGroup; children = ( @@ -1727,7 +1720,6 @@ 4C89B71019B4B4A300DC0A6A /* MPTreeDelegate.m in Sources */, 4C88C66918D9F8D600F43852 /* MPTemporaryFileStorageCenter.m in Sources */, 4C7B63741C0CB51F00D7038C /* TTTDateTransformers.m in Sources */, - 4CCCD83E1C8DFF20002B77B6 /* MPEntryProxy.m in Sources */, 4CF5BE6D1BF33E3000048505 /* NSApplication+MPAdditions.m in Sources */, 4CE30ACC1A312B7F0063FCC6 /* MPReferenceBuilderViewController.m in Sources */, 4C6F228C19A4AA700012310C /* MPAutotypeDelay.m in Sources */, @@ -1735,6 +1727,7 @@ 4C978E0D19AE54AB003067DF /* MPFlagsHelper.m in Sources */, 4C6F228919A4A7F90012310C /* MPAutotypeClear.m in Sources */, 4C0B038C18E36DA400B9F9C9 /* MPFixAutotypeWindowController.m in Sources */, + 4C7679BF1D76D6D8001F33D6 /* MPErrorRecoveryAttempter.m in Sources */, 4CA0F3ED1A3074B50067C0E5 /* MPWindowTitleComboBoxDelegate.m in Sources */, 4CF78064176E75AD0032EE71 /* MPIntegrationSettingsController.m in Sources */, 4C25703F1BF11C2300D39416 /* MPPluginSettingsController.m in Sources */, diff --git a/MacPass/MPErrorRecoveryAttempter.h b/MacPass/MPErrorRecoveryAttempter.h new file mode 100644 index 00000000..7da153ee --- /dev/null +++ b/MacPass/MPErrorRecoveryAttempter.h @@ -0,0 +1,16 @@ +// +// MPDocumentSaveRecoveryAttempter.h +// MacPass +// +// Created by Michael Starke on 31/08/16. +// Copyright © 2016 HicknHack Software GmbH. All rights reserved. +// + +#import +@class MPDocument; + +@interface MPErrorRecoveryAttempter : NSObject + +@property (strong, nullable) MPDocument *document; + +@end diff --git a/MacPass/MPErrorRecoveryAttempter.m b/MacPass/MPErrorRecoveryAttempter.m new file mode 100644 index 00000000..315986b7 --- /dev/null +++ b/MacPass/MPErrorRecoveryAttempter.m @@ -0,0 +1,46 @@ +// +// MPDocumentSaveRecoveryAttempter.m +// MacPass +// +// Created by Michael Starke on 31/08/16. +// Copyright © 2016 HicknHack Software GmbH. All rights reserved. +// + +#import "MPErrorRecoveryAttempter.h" +#import "NSError+Messages.h" +#import "MPDocument.h" +#import "MPDocumentWindowController.h" + +@implementation MPErrorRecoveryAttempter + +/* Given that an error alert has been presented document-modally to the user, and the user has chosen one of the error's recovery options, attempt recovery from the error, and send the selected message to the specified delegate. The option index is an index into the error's array of localized recovery options. The method selected by didRecoverSelector must have the same signature as: + + - (void)didPresentErrorWithRecovery:(BOOL)didRecover contextInfo:(void *)contextInfo; + + The value passed for didRecover must be YES if error recovery was completely successful, NO otherwise. + */ +- (void)attemptRecoveryFromError:(NSError *)error optionIndex:(NSUInteger)recoveryOptionIndex delegate:(nullable id)delegate didRecoverSelector:(nullable SEL)didRecoverSelector contextInfo:(nullable void *)contextInfo { + NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[delegate methodSignatureForSelector:didRecoverSelector]]; + + if(error.code == MPErrorNoPasswordOrKeyFile) { + if([delegate isKindOfClass:[MPDocument class]]) { + MPDocument *document = delegate; + [document.windowControllers.firstObject editPasswordWithCompetionHandler:^(NSInteger result) { + BOOL didRecover = result == NSModalResponseOK; + invocation.target = delegate; + invocation.selector = didRecoverSelector; + [invocation setArgument:&didRecover atIndex:2]; + [invocation setArgument:&contextInfo atIndex:3]; + [invocation invoke]; + }]; + } + } + +} + +/* Given that an error alert has been presented applicaton-modally to the user, and the user has chosen one of the error's recovery options, attempt recovery from the error, and return YES if error recovery was completely successful, NO otherwise. The recovery option index is an index into the error's array of localized recovery options. + */ +- (BOOL)attemptRecoveryFromError:(NSError *)error optionIndex:(NSUInteger)recoveryOptionIndex { + return NO; +} +@end