diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 99b8b648..a55cb6d6 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -118,6 +118,8 @@ 4CE8246F16E2E93400573141 /* MPOverlayWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8246E16E2E93400573141 /* MPOverlayWindowController.m */; }; 4CE8247516E2F2B900573141 /* MPOverlayView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8247416E2F2B900573141 /* MPOverlayView.m */; }; 4CFC53BF16E94729007396BE /* MPShadowBox.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CFC53BE16E94729007396BE /* MPShadowBox.m */; }; + 6E71971217203FB700E4C5FC /* MPCreationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E71971017203FB600E4C5FC /* MPCreationViewController.m */; }; + 6E71971317203FB700E4C5FC /* CreationView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6E71971117203FB600E4C5FC /* CreationView.xib */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -322,6 +324,10 @@ 4CE8247416E2F2B900573141 /* MPOverlayView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPOverlayView.m; sourceTree = ""; }; 4CFC53BD16E94729007396BE /* MPShadowBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPShadowBox.h; sourceTree = ""; }; 4CFC53BE16E94729007396BE /* MPShadowBox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPShadowBox.m; sourceTree = ""; }; + 6E71970F17203FB600E4C5FC /* MPCreationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPCreationViewController.h; sourceTree = ""; }; + 6E71971017203FB600E4C5FC /* MPCreationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPCreationViewController.m; sourceTree = ""; }; + 6E71971117203FB600E4C5FC /* CreationView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CreationView.xib; sourceTree = ""; }; + 6E719715172058BA00E4C5FC /* MPDatabaseVersion.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPDatabaseVersion.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -342,6 +348,7 @@ 4C06398C15B980480004DE27 /* Views */ = { isa = PBXGroup; children = ( + 6E71971117203FB600E4C5FC /* CreationView.xib */, 4C25D58616CF0FAA00F6806C /* EntryView.xib */, 4CA0B2EF15BCADC800654E32 /* GeneralSettings.xib */, 4C77E37B15B84A240093A587 /* MainMenu.xib */, @@ -417,6 +424,7 @@ 4C37A83F15B8B474005EF8EE /* MPOutlineDataSource.m */, 4CBA981615BA0DB600721965 /* MPDatabaseDocument.h */, 4CBA981715BA0DB600721965 /* MPDatabaseDocument.m */, + 6E719715172058BA00E4C5FC /* MPDatabaseVersion.h */, ); name = Model; sourceTree = ""; @@ -645,6 +653,8 @@ 4C40AC5B170782730073D1C3 /* MPAbstractSettingsViewController.m */, 4C5A11FB1708DE8700223D8A /* MPPasswordCreatorViewController.h */, 4C5A11FC1708DE8700223D8A /* MPPasswordCreatorViewController.m */, + 6E71970F17203FB600E4C5FC /* MPCreationViewController.h */, + 6E71971017203FB600E4C5FC /* MPCreationViewController.m */, ); name = "View Controller"; sourceTree = ""; @@ -845,6 +855,7 @@ 4CE39AC116ECE359000FE29D /* IconSelection.xib in Resources */, 4C5A11FF1708DE8800223D8A /* PasswordCreatorView.xib in Resources */, 4C1DDCDD1711ECEB00C98DA3 /* PasswordCreatorWindow.xib in Resources */, + 6E71971317203FB700E4C5FC /* CreationView.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -950,6 +961,7 @@ 4C46B88B1706D16E0046109A /* NSData+MPRandomBytes.m in Sources */, 4C40AC5C170782730073D1C3 /* MPAbstractSettingsViewController.m in Sources */, 4C5A11FE1708DE8700223D8A /* MPPasswordCreatorViewController.m in Sources */, + 6E71971217203FB700E4C5FC /* MPCreationViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/MacPass/CreationView.xib b/MacPass/CreationView.xib new file mode 100644 index 00000000..3dd39f02 --- /dev/null +++ b/MacPass/CreationView.xib @@ -0,0 +1,1248 @@ + + + + 1070 + 12C60 + 2549 + 1187.34 + 625.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 2549 + + + IBNSLayoutConstraint + NSButton + NSButtonCell + NSCustomObject + NSCustomView + NSPathCell + NSPathControl + NSSecureTextField + NSSecureTextFieldCell + NSTextField + NSTextFieldCell + + + com.apple.InterfaceBuilder.CocoaPlugin + + + PluginDependencyRecalculationVersion + + + + + MPCreationViewController + + + FirstResponder + + + NSApplication + + + + 268 + + + + 268 + {{17, 20}, {449, 42}} + + + _NS:9 + {250, 750} + YES + + 67108864 + 272891904 + A KeePass database can be encrypted with a password and/or a keyfile. If both methods are used to encrypt the database, both will be required to decrypt the database. + + LucidaGrande + 11 + 16 + + _NS:9 + + + 6 + System + controlColor + + 3 + MC42NjY2NjY2NjY3AA + + + + 6 + System + controlTextColor + + 3 + MAA + + + + NO + YES + + + + 268 + {{146, 179}, {191, 22}} + + + + _NS:9 + YES + + 342884416 + 272630848 + + + LucidaGrande + 13 + 1044 + + _NS:9 + + YES + + 6 + System + textBackgroundColor + + 3 + MQA + + + + 6 + System + textColor + + + + NSAllRomanInputSourcesLocaleIdentifier + + + NO + + + + 268 + {{37, 181}, {104, 17}} + + + + _NS:1535 + YES + + 68157504 + 272630784 + Verify Password + + _NS:1535 + + + + + NO + + + + 268 + {{172, 241}, {139, 17}} + + + + _NS:1535 + YES + + 68157504 + 272630784 + Create New Database + + _NS:1535 + + + + + NO + + + + 268 + {{180, 106}, {82, 32}} + + + + _NS:9 + YES + + 67108864 + 134217728 + Cancel + + _NS:9 + + -2038284288 + 129 + + Gw + 200 + 25 + + NO + + + + 268 + + Apple URL pasteboard type + NSFilenamesPboardType + + {{143, 150}, {197, 22}} + + + + _NS:9 + YES + + 337641473 + 131072 + + LucidaGrande + 11 + 3100 + + _NS:9 + + + 2 + + + NO + + + + 268 + {{146, 211}, {191, 22}} + + + + _NS:9 + YES + + 342884416 + 272630848 + + + _NS:9 + + YES + + + + NSAllRomanInputSourcesLocaleIdentifier + + + NO + + + + 268 + {{77, 213}, {64, 17}} + + + + _NS:1535 + YES + + 68157504 + 272630784 + Password + + _NS:1535 + + + + + NO + + + + 268 + {{95, 155}, {46, 17}} + + + + _NS:1535 + YES + + 68157504 + 272630784 + Keyfile + + _NS:1535 + + + + + NO + + + + 268 + {{262, 106}, {81, 32}} + + + + _NS:9 + {250, 250} + YES + + 67108864 + 134217728 + Create + + _NS:9 + + -2038284288 + 129 + + DQ + 200 + 25 + + NO + + + {483, 380} + + + + NSView + + + + + + + view + + + + 2 + + + + passwordTextField + + + + 199 + + + + keyPathControl + + + + 200 + + + + _new: + + + + 201 + + + + validatePasswordTextField + + + + 202 + + + + errorInfoTextField + + + + 203 + + + + + + 0 + + + + + + -2 + + + File's Owner + + + -1 + + + First Responder + + + -3 + + + Application + + + 1 + + + + + 5 + 0 + + 6 + 1 + + 12 + + 1000 + + 9 + 40 + 3 + + + + 6 + 0 + + 6 + 1 + + 0.0 + + 1000 + + 9 + 40 + 2 + + + + 3 + 0 + + 4 + 1 + + 20 + + 1000 + + 6 + 24 + 3 + + + + 11 + 0 + + 11 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 11 + 0 + + 11 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 6 + 0 + + 6 + 1 + + 0.0 + + 1000 + + 9 + 40 + 2 + + + + 5 + 0 + + 5 + 1 + + 0.0 + + 1000 + + 9 + 40 + 2 + + + + 3 + 0 + + 4 + 1 + + 8 + + 1000 + + 9 + 40 + 3 + + + + 5 + 0 + + 6 + 1 + + 8 + + 1000 + + 6 + 24 + 3 + + + + 9 + 0 + + 9 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 10 + 0 + + 10 + 1 + + 0.0 + + 1000 + + 9 + 40 + 2 + + + + 9 + 0 + + 9 + 1 + + 0.0 + + 1000 + + 9 + 40 + 2 + + + + 3 + 0 + + 4 + 1 + + 10 + + 1000 + + 9 + 40 + 3 + + + + 5 + 0 + + 6 + 1 + + 8 + + 1000 + + 9 + 40 + 3 + + + + 6 + 0 + + 6 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 5 + 0 + + 5 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 5 + 0 + + 6 + 1 + + 8 + + 1000 + + 6 + 24 + 3 + + + + 3 + 0 + + 4 + 1 + + 8 + + 1000 + + 9 + 40 + 3 + + + + 4 + 0 + + 4 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 6 + 0 + + 6 + 1 + + 20 + + 1000 + + 9 + 40 + 3 + + + + 5 + 0 + + 5 + 1 + + 20 + + 1000 + + 9 + 40 + 3 + + + + 9 + 0 + + 9 + 1 + + 0.0 + + 1000 + + 9 + 40 + 2 + + + + 11 + 0 + + 11 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 11 + 0 + + 11 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + + + + + + + + + + + + + 3 + + + + + + + + 4 + + + + + + + + 5 + + + + + + + + 6 + + + + + + 7 + 0 + + 0 + 1 + + 191 + + 1000 + + 3 + 9 + 1 + + + + + + 7 + + + + + + + + 8 + + + + + + + + 10 + + + + + + + + 11 + + + + + 15 + + + + + 16 + + + + + 18 + + + + + 19 + + + + + 20 + + + + + 21 + + + + + 61 + + + + + 62 + + + + + + + + 63 + + + + + + + + 64 + + + + + 66 + + + + + 71 + + + + + 78 + + + + + 84 + + + + + 86 + + + + + 94 + + + + + 96 + + + + + 97 + + + + + + + + 98 + + + + + 133 + + + + + 91 + + + + + 103 + + + + + 89 + + + + + 85 + + + + + 67 + + + + + 75 + + + + + 53 + + + + + 162 + + + + + 167 + + + + + 168 + + + + + 170 + + + + + 181 + + + + + 134 + + + + + 132 + + + + + 193 + + + + + 194 + + + + + 191 + + + + + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + + + + + + + + + + + + + + + + + + + + + + + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + + + 203 + + + + + MPCreationViewController + MPViewController + + _new: + id + + + _new: + + _new: + id + + + + NSTextField + NSPathControl + NSSecureTextField + NSSecureTextField + + + + errorInfoTextField + NSTextField + + + keyPathControl + NSPathControl + + + passwordTextField + NSSecureTextField + + + validatePasswordTextField + NSSecureTextField + + + + IBProjectSource + ./Classes/MPCreationViewController.h + + + + MPViewController + NSViewController + + IBProjectSource + ./Classes/MPViewController.h + + + + NSLayoutConstraint + NSObject + + IBProjectSource + ./Classes/NSLayoutConstraint.h + + + + + 0 + IBCocoaFramework + + com.apple.InterfaceBuilder.CocoaPlugin.macosx + + + YES + 3 + YES + + diff --git a/MacPass/MPCreationViewController.h b/MacPass/MPCreationViewController.h new file mode 100644 index 00000000..3593f424 --- /dev/null +++ b/MacPass/MPCreationViewController.h @@ -0,0 +1,15 @@ +// +// MPCreationViewController.h +// MacPass +// +// Created by Nathaniel Madura on 18/04/13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#import "MPViewController.h" + +@interface MPCreationViewController : MPViewController + +@property (retain) NSURL *fileURL; + +@end diff --git a/MacPass/MPCreationViewController.m b/MacPass/MPCreationViewController.m new file mode 100644 index 00000000..419d7b3d --- /dev/null +++ b/MacPass/MPCreationViewController.m @@ -0,0 +1,76 @@ +// +// MPCreationViewController.m +// MacPass +// +// Created by Nathaniel Madura on 18/04/13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#import "MPCreationViewController.h" +#import "MPKeyfilePathControlDelegate.h" +#import "MPDatabaseController.h" +#import "MPDatabaseDocument.h" + +@interface MPCreationViewController () + +@property (assign) IBOutlet NSSecureTextField *passwordTextField; +@property (assign) IBOutlet NSSecureTextField *validatePasswordTextField; +@property (assign) IBOutlet NSPathControl *keyPathControl; +@property (retain) MPKeyfilePathControlDelegate *pathControlDelegate; +@property (assign) IBOutlet NSTextField *errorInfoTextField; + +- (IBAction)_new:(id)sender; +- (void)_showError; +- (void)_reset; + +@end + +@implementation MPCreationViewController + +- (id)init { + return [[MPCreationViewController alloc] initWithNibName:@"CreationView" bundle:nil]; +} + +- (void)dealloc { + [_fileURL release]; + [_pathControlDelegate release]; + [super dealloc]; +} + +- (void)didLoadView { + [self.keyPathControl setDelegate:self.pathControlDelegate]; + [self _reset]; +} + +- (NSResponder *)reconmendedFirstResponder { + return self.passwordTextField; +} + +- (IBAction)_new:(id)sender { + NSString *password = self.passwordTextField.stringValue; + NSURL *keyfile = [self.keyPathControl URL]; + if ([password compare:self.validatePasswordTextField.stringValue] != NSOrderedSame) + { + [self.errorInfoTextField setStringValue:@"Passwords do not match"]; + [self.errorInfoTextField setHidden:NO]; + } + [self _reset]; + + [[MPDatabaseController defaultController] newDatabaseAtURL:self.fileURL + databaseVersion:MPDatabaseVersion4 + password:password + keyfile:keyfile]; +} + +- (void)_reset { + [self.passwordTextField setStringValue:@""]; + [self.validatePasswordTextField setStringValue:@""]; + [self.keyPathControl setURL:nil]; + [self.errorInfoTextField setHidden:YES]; +} + +- (void)_showError { + [self.errorInfoTextField setHidden:NO]; +} + +@end diff --git a/MacPass/MPDatabaseController.h b/MacPass/MPDatabaseController.h index 21bf3e83..a33f344c 100644 --- a/MacPass/MPDatabaseController.h +++ b/MacPass/MPDatabaseController.h @@ -7,6 +7,7 @@ // #import +#import "MPDatabaseVersion.h" /* Notification is posted, when a database is loaded @@ -30,7 +31,8 @@ APPKIT_EXTERN NSString *const MPDatabaseControllerDatabaseKey; + (MPDatabaseController *)defaultController; + (BOOL)hasOpenDatabase; -//- (MPDatabaseDocument *)createDatabase:(MPDatabaseVersion )version password:(NSString *)password keyfile:(NSURL *)key; +- (MPDatabaseDocument *)createDatabase:(MPDatabaseVersion)version password:(NSString *)password keyfile:(NSURL *)key; - (MPDatabaseDocument *)openDatabase:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key; +- (MPDatabaseDocument *)newDatabaseAtURL:(NSURL *)url databaseVersion:(MPDatabaseVersion)version password:(NSString *)password keyfile:(NSURL *)key; @end diff --git a/MacPass/MPDatabaseController.m b/MacPass/MPDatabaseController.m index d9018bd2..10d38c9d 100644 --- a/MacPass/MPDatabaseController.m +++ b/MacPass/MPDatabaseController.m @@ -53,6 +53,11 @@ NSString *const MPDatabaseControllerDatabaseKey = @"com.macpass.MPDatabaseContro return self.database; } +- (MPDatabaseDocument *)newDatabaseAtURL:(NSURL *)url databaseVersion:(MPDatabaseVersion)version password:(NSString *)password keyfile:(NSURL *)key { + self.database = [MPDatabaseDocument newDocumentAtURL:url databaseVersion:version password:password keyfile:key]; + return self.database; +} + - (MPDatabaseDocument *)openDatabase:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key { self.database = [MPDatabaseDocument documentWithFile:file password:password keyfile:key]; return self.database; diff --git a/MacPass/MPDatabaseDocument.h b/MacPass/MPDatabaseDocument.h index 42ea97e8..4e070dae 100644 --- a/MacPass/MPDatabaseDocument.h +++ b/MacPass/MPDatabaseDocument.h @@ -7,15 +7,11 @@ // #import +#import "MPDatabaseVersion.h" APPKIT_EXTERN NSString *const MPDidLoadDatabaseNotification; APPKIT_EXTERN NSString *const MPDatabaseDocumentDocumentKey; -typedef enum { - MPDatabaseVersion3, - MPDatabaseVersion4 -} MPDatabaseVersion; - @class KdbPassword; @class KdbGroup; @class KdbEntry; @@ -30,8 +26,10 @@ typedef enum { + (id)documentWithFile:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key; + (id)documentWithNewDatabase:(MPDatabaseVersion)version; ++ (id)newDocumentAtURL:(NSURL *)url databaseVersion:(MPDatabaseVersion)dbversion password:(NSString *)password keyfile:(NSURL *)key; - (id)initWithFile:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key; - (id)initWithNewDatabase:(MPDatabaseVersion)version; +- (id)initNewDocumentAtURL:(NSURL *)url databaseVersion:(MPDatabaseVersion)dbversion password:(NSString *)password keyfile:(NSURL *)key; /* Saves the current database to the filesystem Tries to use the stored password and file path diff --git a/MacPass/MPDatabaseDocument.m b/MacPass/MPDatabaseDocument.m index 462cdfd9..7a7615ed 100644 --- a/MacPass/MPDatabaseDocument.m +++ b/MacPass/MPDatabaseDocument.m @@ -19,6 +19,7 @@ NSString *const MPDidLoadDatabaseNotification = @"DidLoadDataBaseNotification"; @property (retain) NSURL *file; @property (nonatomic, readonly) KdbPassword *passwordHash; @property (assign) MPDatabaseVersion version; +@property (readonly)BOOL isNewFile; @end @@ -32,11 +33,42 @@ NSString *const MPDidLoadDatabaseNotification = @"DidLoadDataBaseNotification"; return [[[MPDatabaseDocument alloc] initWithNewDatabase:version] autorelease]; } ++ (id)newDocumentAtURL:(NSURL *)url databaseVersion:(MPDatabaseVersion)dbversion password:(NSString *)password keyfile:(NSURL *)key +{ + return [[[MPDatabaseDocument alloc] initNewDocumentAtURL:url databaseVersion:dbversion password:password keyfile:key] autorelease]; +} + - (id)init { // create empty document return [self initWithFile:nil password:nil keyfile:nil]; } + +- (id)initNewDocumentAtURL:(NSURL *)url databaseVersion:(MPDatabaseVersion)dbversion password:(NSString *)password keyfile:(NSURL *)key +{ + self = [super init]; + if(self) { + self.file = url; + self.key = key; + self.password = password; + _isNewFile = YES; + switch(dbversion) { + case MPDatabaseVersion3: + self.tree = [[[Kdb3Tree alloc] init] autorelease]; + break; + case MPDatabaseVersion4: + self.tree = [[[Kdb4Tree alloc] init] autorelease]; + break; + default: + [self release]; + return nil; + } + KdbGroup *newGroup = [self.tree createGroup:self.tree.root]; + newGroup.name = @"Default"; + } + return self; +} + /* Initalizer for creating */ @@ -109,7 +141,7 @@ NSString *const MPDidLoadDatabaseNotification = @"DidLoadDataBaseNotification"; - (BOOL)save { NSError *fileError; - if( [self.file checkResourceIsReachableAndReturnError:&fileError] ) { + if(self.isNewFile || [self.file checkResourceIsReachableAndReturnError:&fileError] ) { @try { [KdbWriterFactory persist:self.tree file:[self.file path] withPassword:self.passwordHash]; } @@ -119,6 +151,11 @@ NSString *const MPDidLoadDatabaseNotification = @"DidLoadDataBaseNotification"; } return YES; } + else + { + NSLog(@"File Error: %@", fileError); + return NO; + } } - (BOOL)saveAsFile:(NSURL *)file withPassword:(NSString *)password keyfile:(NSURL *)key { diff --git a/MacPass/MPDatabaseVersion.h b/MacPass/MPDatabaseVersion.h new file mode 100644 index 00000000..d4d087b5 --- /dev/null +++ b/MacPass/MPDatabaseVersion.h @@ -0,0 +1,17 @@ +// +// MPDatabaseVersion.h +// MacPass +// +// Created by Nathaniel Madura on 18/04/13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#ifndef MacPass_MPDatabaseVersion_h +#define MacPass_MPDatabaseVersion_h + +typedef enum { + MPDatabaseVersion3, + MPDatabaseVersion4 +} MPDatabaseVersion; + +#endif diff --git a/MacPass/MPMainWindowController.h b/MacPass/MPMainWindowController.h index 83531b75..0c3a7e4c 100644 --- a/MacPass/MPMainWindowController.h +++ b/MacPass/MPMainWindowController.h @@ -13,6 +13,7 @@ @class MPInspectorTabViewController; @class MPPasswordInputController; @class MPOutlineViewController; +@class MPCreationViewController; @interface MPMainWindowController : NSWindowController @@ -20,6 +21,7 @@ @property (readonly, retain) MPEntryViewController *entryViewController; @property (readonly, retain) MPOutlineViewController *outlineViewController; @property (readonly, retain) MPInspectorTabViewController *inspectorTabViewController; +@property (readonly, retain) MPCreationViewController *creationViewController; - (void)showEntries; diff --git a/MacPass/MPMainWindowController.m b/MacPass/MPMainWindowController.m index 4658e769..0b6bc547 100644 --- a/MacPass/MPMainWindowController.m +++ b/MacPass/MPMainWindowController.m @@ -16,6 +16,7 @@ #import "MPMainWindowSplitViewDelegate.h" #import "MPInspectorTabViewController.h" #import "MPAppDelegate.h" +#import "MPCreationViewController.h" @interface MPMainWindowController () @@ -32,6 +33,7 @@ @property (retain) MPEntryViewController *entryViewController; @property (retain) MPOutlineViewController *outlineViewController; @property (retain) MPInspectorTabViewController *inspectorTabViewController; +@property (retain) MPCreationViewController *creationViewController; @property (retain) MPToolbarDelegate *toolbarDelegate; @property (retain) MPMainWindowSplitViewDelegate *splitViewDelegate; @@ -54,6 +56,7 @@ _outlineViewController = [[MPOutlineViewController alloc] init]; _inspectorTabViewController = [[MPInspectorTabViewController alloc] init]; _splitViewDelegate = [[MPMainWindowSplitViewDelegate alloc] init]; + _creationViewController = [[MPCreationViewController alloc] init]; [[NSBundle mainBundle] loadNibNamed:@"WelcomeView" owner:self topLevelObjects:NULL]; [self.welcomeView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; @@ -76,6 +79,7 @@ [_entryViewController release]; [_outlineViewController release]; [_inspectorTabViewController release]; + [_creationViewController release]; [_toolbarDelegate release]; [_splitViewDelegate release]; @@ -248,6 +252,31 @@ - (void)showEditForm:(id)sender { } +- (void)newDocument:(id)sender { + if (!self.creationViewController) { + self.creationViewController = [[[MPCreationViewController alloc] init] autorelease]; + } + + NSSavePanel *savePanel = [NSSavePanel savePanel]; + [savePanel setAllowedFileTypes:@[@"kdbx", @"kdb"]]; + [savePanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) { + if (result == NSFileHandlingPanelOKButton) { + NSURL *file = [savePanel URL]; + NSLog(@"Will create file at: %@", file); + self.creationViewController.fileURL = file; + [self _setContentViewController:self.creationViewController]; + } + }]; +} + +- (void)saveDocument:(id)sender +{ + NSLog(@"Attempting to save document"); + if ([[MPDatabaseController defaultController].database save]) + NSLog(@"Save successful"); + else + NSLog(@"Save failed"); +} #pragma mark Helper