From 878970ff22d78e68a628605b7fa8cd0b6916ef5a Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Sat, 4 Apr 2020 17:34:07 -0400 Subject: [PATCH] JSON support for Mac app. --- .../project.pbxproj | 4 ++-- platform-darwin/Source/Mac/MPMacAppDelegate.m | 23 +++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/platform-darwin/MasterPassword-macOS.xcodeproj/project.pbxproj b/platform-darwin/MasterPassword-macOS.xcodeproj/project.pbxproj index 478de0dc..a3f3e20c 100644 --- a/platform-darwin/MasterPassword-macOS.xcodeproj/project.pbxproj +++ b/platform-darwin/MasterPassword-macOS.xcodeproj/project.pbxproj @@ -3378,7 +3378,7 @@ ); OTHER_CFLAGS = ( "-DMPW_SODIUM=1", - "-DMPW_CPERCIVA=0", + "-DMPW_JSON=1", ); PRODUCT_BUNDLE_IDENTIFIER = com.lyndir.lhunath.MasterPassword.Mac; PRODUCT_NAME = MasterPassword; @@ -3418,7 +3418,7 @@ ); OTHER_CFLAGS = ( "-DMPW_SODIUM=1", - "-DMPW_CPERCIVA=0", + "-DMPW_JSON=1", ); PRODUCT_BUNDLE_IDENTIFIER = com.lyndir.lhunath.MasterPassword.Mac; PRODUCT_NAME = MasterPassword; diff --git a/platform-darwin/Source/Mac/MPMacAppDelegate.m b/platform-darwin/Source/Mac/MPMacAppDelegate.m index d15c9a14..32888c10 100644 --- a/platform-darwin/Source/Mac/MPMacAppDelegate.m +++ b/platform-darwin/Source/Mac/MPMacAppDelegate.m @@ -20,6 +20,7 @@ #import "MPAppDelegate_Key.h" #import "MPAppDelegate_Store.h" #import "MPSecrets.h" +#import "mpw-marshal.h" #import #import @@ -318,7 +319,15 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven openPanel.message = @"Locate the Master Password export file to import."; openPanel.prompt = @"Import"; openPanel.directoryURL = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask].firstObject; - openPanel.allowedFileTypes = @[ @"mpsites" ]; + NSMutableArray *allExtensions = [NSMutableArray array]; + for (MPMarshalFormat format = MPMarshalFormatLast; format >= MPMarshalFormatFirst; --format) { + size_t count = 0; + const char **extensions = mpw_format_extensions( format, &count ); + for (int c = 0; c < count; ++c) + [allExtensions addObject:@(extensions[c])]; + free( extensions ); + } + openPanel.allowedFileTypes = allExtensions; [NSApp activateIgnoringOtherApps:YES]; if ([openPanel runModal] == NSFileHandlingPanelCancelButton) return; @@ -535,9 +544,15 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven savePanel.message ); savePanel.prompt = @"Export"; savePanel.directoryURL = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask].firstObject; - savePanel.nameFieldStringValue = strf( @"%@ (%@).mpsites", mainActiveUser.name, - [exportDateFormatter stringFromDate:[NSDate date]] ); - savePanel.allowedFileTypes = @[ @"mpsites" ]; + savePanel.nameFieldStringValue = strf( @"%@ (%@).%@", mainActiveUser.name, [exportDateFormatter stringFromDate:[NSDate date]], + @(mpw_format_extension( MPMarshalFormatDefault ) ) ); + NSMutableArray *allExtensions = [NSMutableArray array]; + size_t count = 0; + const char **extensions = mpw_format_extensions( MPMarshalFormatDefault, &count ); + for (int c = 0; c < count; ++c) + [allExtensions addObject:@(extensions[c])]; + free( extensions ); + savePanel.allowedFileTypes = allExtensions; [NSApp activateIgnoringOtherApps:YES]; if ([savePanel runModal] == NSFileHandlingPanelCancelButton) return;