diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index bc14c36f..fb0bb6a4 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -87,6 +87,7 @@ 4C305F36179A0BD70082334F /* KPKIcon.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C305F35179A0BD70082334F /* KPKIcon.m */; }; 4C305F3C179A19F90082334F /* KPKIconLoading.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C305F3B179A19F90082334F /* KPKIconLoading.m */; }; 4C305F3E179A1A760082334F /* image.png in Resources */ = {isa = PBXBuildFile; fileRef = 4C305F3D179A1A760082334F /* image.png */; }; + 4C32B0E71A1D4436007E12F1 /* KPKFormat+MPUTIDetection.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C32B0E61A1D4436007E12F1 /* KPKFormat+MPUTIDetection.m */; }; 4C3666411787327E00B249F1 /* MPDocument+Attachments.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C3666401787327E00B249F1 /* MPDocument+Attachments.m */; }; 4C366643178748F500B249F1 /* 99_HarddiskTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4C366642178748F500B249F1 /* 99_HarddiskTemplate.pdf */; }; 4C37A6731769393300AD0A40 /* HNHTableHeaderCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C37A6721769393300AD0A40 /* HNHTableHeaderCell.m */; }; @@ -525,6 +526,8 @@ 4C305F35179A0BD70082334F /* KPKIcon.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KPKIcon.m; sourceTree = ""; }; 4C305F3B179A19F90082334F /* KPKIconLoading.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KPKIconLoading.m; sourceTree = ""; }; 4C305F3D179A1A760082334F /* image.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = image.png; path = Images/image.png; sourceTree = ""; }; + 4C32B0E51A1D4436007E12F1 /* KPKFormat+MPUTIDetection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "KPKFormat+MPUTIDetection.h"; sourceTree = ""; }; + 4C32B0E61A1D4436007E12F1 /* KPKFormat+MPUTIDetection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "KPKFormat+MPUTIDetection.m"; sourceTree = ""; }; 4C3666401787327E00B249F1 /* MPDocument+Attachments.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MPDocument+Attachments.m"; sourceTree = ""; }; 4C366642178748F500B249F1 /* 99_HarddiskTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = 99_HarddiskTemplate.pdf; path = Icons/99_HarddiskTemplate.pdf; sourceTree = ""; }; 4C37A6711769393300AD0A40 /* HNHTableHeaderCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HNHTableHeaderCell.h; sourceTree = ""; }; @@ -1115,6 +1118,8 @@ 4CEED1C517D7BD0E007180F1 /* NSError+Messages.m */, 4C77C83F18E240E000D1C42B /* DDHotKey+MacPassAdditions.h */, 4C77C84018E240E000D1C42B /* DDHotKey+MacPassAdditions.m */, + 4C32B0E51A1D4436007E12F1 /* KPKFormat+MPUTIDetection.h */, + 4C32B0E61A1D4436007E12F1 /* KPKFormat+MPUTIDetection.m */, ); name = Categories; sourceTree = ""; @@ -2515,6 +2520,7 @@ 4C5CD35717D15DBD000B7F38 /* NSDate+Packed.m in Sources */, 4C5CD35817D15DBD000B7F38 /* NSMutableData+Base64.m in Sources */, 4C5CD35917D15DBD000B7F38 /* NSString+Empty.m in Sources */, + 4C32B0E71A1D4436007E12F1 /* KPKFormat+MPUTIDetection.m in Sources */, 4C5CD35A17D15DBD000B7F38 /* NSString+Hexdata.m in Sources */, 4C5CD36117D15DCA000B7F38 /* KPKArc4RandomStream.m in Sources */, 4C5CD36217D15DCA000B7F38 /* KPKRandomStream.m in Sources */, diff --git a/MacPass/KPKFormat+MPUTIDetection.h b/MacPass/KPKFormat+MPUTIDetection.h new file mode 100644 index 00000000..fd48e7ce --- /dev/null +++ b/MacPass/KPKFormat+MPUTIDetection.h @@ -0,0 +1,17 @@ +// +// KPKFormat+MPUTIDetection.h +// MacPass +// +// Created by Michael Starke on 19/11/14. +// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved. +// + +#import "KPKFormat.h" + +@interface KPKFormat (MPUTIDetection) + +- (NSString *)typeForData:(NSData *)data; + +- (NSString *)typeForContentOfURL:(NSURL *)url; + +@end diff --git a/MacPass/KPKFormat+MPUTIDetection.m b/MacPass/KPKFormat+MPUTIDetection.m new file mode 100644 index 00000000..c88c9405 --- /dev/null +++ b/MacPass/KPKFormat+MPUTIDetection.m @@ -0,0 +1,37 @@ +// +// KPKFormat+MPUTIDetection.m +// MacPass +// +// Created by Michael Starke on 19/11/14. +// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved. +// + +#import "KPKFormat+MPUTIDetection.h" + +#import "MPConstants.h" + +@implementation KPKFormat (MPUTIDetection) + +- (NSDictionary *)_typeToUTIdictionary { + static NSDictionary *typeToUTI; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + typeToUTI = @{ + @(KPKLegacyVersion) : MPLegacyDocumentUTI, + @(KPKXmlVersion) : MPXMLDocumentUTI + }; + }); + return typeToUTI; +} + +- (NSString *)typeForData:(NSData *)data { + KPKVersion version = [self databaseVersionForData:data]; + return [self _typeToUTIdictionary][@(version)]; +} + +- (NSString *)typeForContentOfURL:(NSURL *)url { + NSData *data = [NSData dataWithContentsOfURL:url]; + return [self typeForData:data]; +} + +@end diff --git a/MacPass/MPDocumentController.m b/MacPass/MPDocumentController.m index 845bb759..bf731cff 100644 --- a/MacPass/MPDocumentController.m +++ b/MacPass/MPDocumentController.m @@ -7,9 +7,13 @@ // #import "MPDocumentController.h" +#import "MPConstants.h" #import "HNHCommon.h" +#import "KPKFormat.h" +#import "KPKFormat+MPUTIDetection.h" + @interface MPDocumentController () @property (strong) IBOutlet NSView *accessoryView; @@ -43,8 +47,18 @@ - (IBAction)toggleAllowAllFilesButton:(id)sender { NSButton *button = (NSButton *)sender; self.allowAllFiles = HNHBoolForState(button.state); - self.openPanel.allowedFileTypes = self.allowAllFiles ? nil : @[@".kdb", @".kdbx"]; - //self.openPanel.directoryURL = self.openPanel.directoryURL; + self.openPanel.allowedFileTypes = self.allowAllFiles ? nil : @[MPLegacyDocumentUTI, MPXMLDocumentUTI]; + self.openPanel.canChooseDirectories = self.allowAllFiles; + self.openPanel.delegate = self.allowAllFiles ? self : nil; + [self.openPanel validateVisibleColumns]; +} + +- (NSString *)typeForContentsOfURL:(NSURL *)url error:(NSError *__autoreleasing *)outError { + NSString *detectedType = [[KPKFormat sharedFormat] typeForContentOfURL:url]; + if(nil != detectedType) { + return detectedType; + } + return [super typeForContentsOfURL:url error:outError]; } #pragma mark NSOpenSavePanelDelegate diff --git a/MacPass/MPWorkflowSettingsController.m b/MacPass/MPWorkflowSettingsController.m index b28c555d..f302bf6d 100644 --- a/MacPass/MPWorkflowSettingsController.m +++ b/MacPass/MPWorkflowSettingsController.m @@ -61,7 +61,7 @@ - (void)_showCustomBrowserSelection:(id)sender { NSOpenPanel *openPanel = [NSOpenPanel openPanel]; - NSURL *applicationURL = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationDirectory inDomains:NSSystemDomainMask][0]; + NSURL *applicationURL = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationDirectory inDomains:NSLocalDomainMask][0]; [openPanel setDirectoryURL:applicationURL]; [openPanel setAllowsMultipleSelection:NO]; [openPanel setCanChooseDirectories:NO];