mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 14:02:28 +00:00
Started transition to document based application
This commit is contained in:
@@ -109,7 +109,6 @@ NSString *const MPDidLoadDatabaseNotification = @"DidLoadDataBaseNotification";
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
self.tree = nil;
|
||||
|
||||
25
MacPass/MPDocument.h
Normal file
25
MacPass/MPDocument.h
Normal file
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// MPDocument.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 08.05.13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "MPDatabaseVersion.h"
|
||||
|
||||
@class KdbGroup;
|
||||
|
||||
@interface MPDocument : NSDocument
|
||||
|
||||
@property (assign, readonly) KdbGroup *root;
|
||||
@property (retain, readonly) NSURL *file;
|
||||
@property (nonatomic,retain) NSString *password;
|
||||
@property (nonatomic, retain) NSURL *key;
|
||||
@property (assign, readonly) MPDatabaseVersion version;
|
||||
|
||||
- (id)initWithVersion:(MPDatabaseVersion)version;
|
||||
- (BOOL)decryptWithPassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL;
|
||||
|
||||
@end
|
||||
119
MacPass/MPDocument.m
Normal file
119
MacPass/MPDocument.m
Normal file
@@ -0,0 +1,119 @@
|
||||
//
|
||||
// MPDocument.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 08.05.13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPDocument.h"
|
||||
#import "KdbLib.h"
|
||||
#import "Kdb3Node.h"
|
||||
#import "Kdb4Node.h"
|
||||
#import "KdbPassword.h"
|
||||
#import "MPDatabaseVersion.h"
|
||||
|
||||
@interface MPDocument ()
|
||||
|
||||
@property (retain) KdbTree *tree;
|
||||
@property (retain) NSURL *file;
|
||||
@property (nonatomic, readonly) KdbPassword *passwordHash;
|
||||
@property (assign) MPDatabaseVersion version;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation MPDocument
|
||||
|
||||
- (id)init
|
||||
{
|
||||
return [self initWithVersion:MPDatabaseVersion4];
|
||||
}
|
||||
|
||||
- (id)initWithVersion:(MPDatabaseVersion)version {
|
||||
self = [super init];
|
||||
if(self) {
|
||||
switch(version) {
|
||||
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;
|
||||
}
|
||||
|
||||
- (void) makeWindowControllers {
|
||||
}
|
||||
|
||||
- (NSString *)windowNibName
|
||||
{
|
||||
// Override returning the nib file name of the document
|
||||
// If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
|
||||
return @"MainWindow";
|
||||
//return @"MPDocument";
|
||||
}
|
||||
|
||||
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
|
||||
{
|
||||
[super windowControllerDidLoadNib:aController];
|
||||
// Add any code here that needs to be executed once the windowController has loaded the document's window.
|
||||
}
|
||||
|
||||
- (BOOL)writeToURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError {
|
||||
self.file = url;
|
||||
|
||||
@try {
|
||||
[KdbWriterFactory persist:self.tree file:[self.file path] withPassword:self.passwordHash];
|
||||
}
|
||||
@catch (NSException *exception) {
|
||||
NSLog(@"%@", [exception description]);
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
|
||||
}
|
||||
|
||||
- (BOOL)readFromURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError {
|
||||
self.file = url;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)decryptWithPassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL {
|
||||
self.key = keyFileURL;
|
||||
self.password = password;
|
||||
@try {
|
||||
self.tree = [KdbReaderFactory load:[self.file path] withPassword:self.passwordHash];
|
||||
}
|
||||
@catch (NSException *exception) {
|
||||
NSLog(@"%@", [exception description]);
|
||||
return NO;
|
||||
}
|
||||
|
||||
if([self.tree isKindOfClass:[Kdb4Tree class]]) {
|
||||
self.version = MPDatabaseVersion4;
|
||||
}
|
||||
else if( [self.tree isKindOfClass:[Kdb3Tree class]]) {
|
||||
self.version = MPDatabaseVersion3;
|
||||
}
|
||||
}
|
||||
|
||||
- (KdbPassword *)passwordHash {
|
||||
// TODO: Use defaults to determine Encoding?
|
||||
return [[[KdbPassword alloc] initWithPassword:self.password passwordEncoding:NSUTF8StringEncoding keyFile:[self.key path]] autorelease];
|
||||
}
|
||||
|
||||
+ (BOOL)autosavesInPlace
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -4,6 +4,29 @@
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleDocumentTypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>CFBundleTypeExtensions</key>
|
||||
<array>
|
||||
<string>kdbx</string>
|
||||
</array>
|
||||
<key>CFBundleTypeName</key>
|
||||
<string>KeePass2 Database </string>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>Editor</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>CFBundleTypeExtensions</key>
|
||||
<array>
|
||||
<string>kdb</string>
|
||||
</array>
|
||||
<key>CFBundleTypeName</key>
|
||||
<string>KeePass Database</string>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>Editor</string>
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
@@ -21,7 +44,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>63A</string>
|
||||
<string>63C</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
|
||||
Reference in New Issue
Block a user