mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 17:32:17 +00:00
Implemented path through which a file can be created.
MPDatabaseController and MPDatabaseDocument, needed new initializers to properly support creating a new document.
This commit is contained in:
@@ -31,7 +31,8 @@ APPKIT_EXTERN NSString *const MPDatabaseControllerDatabaseKey;
|
|||||||
+ (MPDatabaseController *)defaultController;
|
+ (MPDatabaseController *)defaultController;
|
||||||
+ (BOOL)hasOpenDatabase;
|
+ (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 *)openDatabase:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key;
|
||||||
|
- (MPDatabaseDocument *)newDatabaseAtURL:(NSURL *)url databaseVersion:(MPDatabaseVersion)version password:(NSString *)password keyfile:(NSURL *)key;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -53,6 +53,11 @@ NSString *const MPDatabaseControllerDatabaseKey = @"com.macpass.MPDatabaseContro
|
|||||||
return self.database;
|
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 {
|
- (MPDatabaseDocument *)openDatabase:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key {
|
||||||
self.database = [MPDatabaseDocument documentWithFile:file password:password keyfile:key];
|
self.database = [MPDatabaseDocument documentWithFile:file password:password keyfile:key];
|
||||||
return self.database;
|
return self.database;
|
||||||
|
|||||||
@@ -26,8 +26,10 @@ APPKIT_EXTERN NSString *const MPDatabaseDocumentDocumentKey;
|
|||||||
|
|
||||||
+ (id)documentWithFile:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key;
|
+ (id)documentWithFile:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key;
|
||||||
+ (id)documentWithNewDatabase:(MPDatabaseVersion)version;
|
+ (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)initWithFile:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key;
|
||||||
- (id)initWithNewDatabase:(MPDatabaseVersion)version;
|
- (id)initWithNewDatabase:(MPDatabaseVersion)version;
|
||||||
|
- (id)initNewDocumentAtURL:(NSURL *)url databaseVersion:(MPDatabaseVersion)dbversion password:(NSString *)password keyfile:(NSURL *)key;
|
||||||
/*
|
/*
|
||||||
Saves the current database to the filesystem
|
Saves the current database to the filesystem
|
||||||
Tries to use the stored password and file path
|
Tries to use the stored password and file path
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ NSString *const MPDidLoadDatabaseNotification = @"DidLoadDataBaseNotification";
|
|||||||
@property (retain) NSURL *file;
|
@property (retain) NSURL *file;
|
||||||
@property (nonatomic, readonly) KdbPassword *passwordHash;
|
@property (nonatomic, readonly) KdbPassword *passwordHash;
|
||||||
@property (assign) MPDatabaseVersion version;
|
@property (assign) MPDatabaseVersion version;
|
||||||
|
@property (readonly)BOOL isNewFile;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@@ -32,11 +33,42 @@ NSString *const MPDidLoadDatabaseNotification = @"DidLoadDataBaseNotification";
|
|||||||
return [[[MPDatabaseDocument alloc] initWithNewDatabase:version] autorelease];
|
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 {
|
- (id)init {
|
||||||
// create empty document
|
// create empty document
|
||||||
return [self initWithFile:nil password:nil keyfile:nil];
|
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
|
Initalizer for creating
|
||||||
*/
|
*/
|
||||||
@@ -109,7 +141,7 @@ NSString *const MPDidLoadDatabaseNotification = @"DidLoadDataBaseNotification";
|
|||||||
|
|
||||||
- (BOOL)save {
|
- (BOOL)save {
|
||||||
NSError *fileError;
|
NSError *fileError;
|
||||||
if( [self.file checkResourceIsReachableAndReturnError:&fileError] ) {
|
if(self.isNewFile || [self.file checkResourceIsReachableAndReturnError:&fileError] ) {
|
||||||
@try {
|
@try {
|
||||||
[KdbWriterFactory persist:self.tree file:[self.file path] withPassword:self.passwordHash];
|
[KdbWriterFactory persist:self.tree file:[self.file path] withPassword:self.passwordHash];
|
||||||
}
|
}
|
||||||
@@ -119,6 +151,11 @@ NSString *const MPDidLoadDatabaseNotification = @"DidLoadDataBaseNotification";
|
|||||||
}
|
}
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSLog(@"File Error: %@", fileError);
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)saveAsFile:(NSURL *)file withPassword:(NSString *)password keyfile:(NSURL *)key {
|
- (BOOL)saveAsFile:(NSURL *)file withPassword:(NSString *)password keyfile:(NSURL *)key {
|
||||||
|
|||||||
Reference in New Issue
Block a user