mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 04:42:29 +00:00
Changes to loaded files now get reported to the user
Database is written on lock Signed-off-by: michael starke <michael.starke@hicknhack-software.com>
This commit is contained in:
@@ -1408,7 +1408,7 @@
|
|||||||
isa = PBXProject;
|
isa = PBXProject;
|
||||||
attributes = {
|
attributes = {
|
||||||
CLASSPREFIX = MP;
|
CLASSPREFIX = MP;
|
||||||
LastUpgradeCheck = 0700;
|
LastUpgradeCheck = 0720;
|
||||||
ORGANIZATIONNAME = "HicknHack Software GmbH";
|
ORGANIZATIONNAME = "HicknHack Software GmbH";
|
||||||
TargetAttributes = {
|
TargetAttributes = {
|
||||||
4C77E36115B84A240093A587 = {
|
4C77E36115B84A240093A587 = {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "0700"
|
LastUpgradeVersion = "0720"
|
||||||
version = "1.3">
|
version = "1.3">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
|
|||||||
@@ -167,8 +167,8 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
|
|||||||
}
|
}
|
||||||
return NO; // No password or key. No save possible
|
return NO; // No password or key. No save possible
|
||||||
}
|
}
|
||||||
NSString *fileType = [self fileTypeFromLastRunSavePanel];
|
NSString *fileType = self.fileTypeFromLastRunSavePanel;
|
||||||
KPKVersion version = [[self class] versionForFileType:fileType];
|
KPKVersion version = [self.class versionForFileType:fileType];
|
||||||
if(version == KPKUnknownVersion) {
|
if(version == KPKUnknownVersion) {
|
||||||
if(outError != NULL) {
|
if(outError != NULL) {
|
||||||
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: NSLocalizedString(@"UNKNOWN_FILE_VERSION", "") };
|
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: NSLocalizedString(@"UNKNOWN_FILE_VERSION", "") };
|
||||||
@@ -179,7 +179,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
|
|||||||
NSData *treeData = [self.tree encryptWithPassword:self.compositeKey forVersion:version error:outError];
|
NSData *treeData = [self.tree encryptWithPassword:self.compositeKey forVersion:version error:outError];
|
||||||
BOOL sucess = [treeData writeToURL:url options:0 error:outError];
|
BOOL sucess = [treeData writeToURL:url options:0 error:outError];
|
||||||
if(!sucess) {
|
if(!sucess) {
|
||||||
NSLog(@"%@", [*outError localizedDescription]);
|
NSLog(@"%@", (*outError).localizedDescription);
|
||||||
}
|
}
|
||||||
return sucess;
|
return sucess;
|
||||||
}
|
}
|
||||||
@@ -248,18 +248,24 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
|
|||||||
|
|
||||||
- (NSString *)fileTypeFromLastRunSavePanel {
|
- (NSString *)fileTypeFromLastRunSavePanel {
|
||||||
if(self.savePanelViewController) {
|
if(self.savePanelViewController) {
|
||||||
return [[self class] fileTypeForVersion:self.savePanelViewController.selectedVersion];
|
return [self.class fileTypeForVersion:self.savePanelViewController.selectedVersion];
|
||||||
}
|
}
|
||||||
return [self fileType];
|
return self.fileType;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)presentedItemDidChange {
|
- (void)presentedItemDidChange {
|
||||||
[super presentedItemDidChange];
|
[super presentedItemDidChange];
|
||||||
|
|
||||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
/* If we are locked we have the data written back to file - just revert */
|
||||||
NSDate *creationDate = nil;
|
if(self.encrypted) {
|
||||||
NSDictionary *attributes = [fileManager attributesOfItemAtPath:self.fileURL.path error:nil];
|
[self revertDocumentToSaved:nil];
|
||||||
creationDate = attributes[NSFileModificationDate];
|
return;
|
||||||
|
}
|
||||||
|
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:self.fileURL.path error:nil];
|
||||||
|
NSDate *modificationDate = attributes[NSFileModificationDate];
|
||||||
|
if(NSOrderedSame == [self.fileModificationDate compare:modificationDate]) {
|
||||||
|
return; // Just metadata has changed
|
||||||
|
}
|
||||||
/* Dispatch the alert to the main queue */
|
/* Dispatch the alert to the main queue */
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
NSAlert *alert = [[NSAlert alloc] init];
|
NSAlert *alert = [[NSAlert alloc] init];
|
||||||
@@ -269,7 +275,9 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
|
|||||||
[alert addButtonWithTitle:NSLocalizedString(@"IGNORE", @"Ignore the changes to an open file!")];
|
[alert addButtonWithTitle:NSLocalizedString(@"IGNORE", @"Ignore the changes to an open file!")];
|
||||||
[alert addButtonWithTitle:NSLocalizedString(@"REOPEN", @"Reopen the file!")];
|
[alert addButtonWithTitle:NSLocalizedString(@"REOPEN", @"Reopen the file!")];
|
||||||
[alert beginSheetModalForWindow:self.windowForSheet completionHandler:^(NSModalResponse returnCode) {
|
[alert beginSheetModalForWindow:self.windowForSheet completionHandler:^(NSModalResponse returnCode) {
|
||||||
[self revertDocumentToSaved:nil];
|
if(returnCode == NSAlertSecondButtonReturn) {
|
||||||
|
[self revertDocumentToSaved:nil];
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -289,13 +297,10 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
|
|||||||
#pragma mark Lock/Unlock/Decrypt
|
#pragma mark Lock/Unlock/Decrypt
|
||||||
|
|
||||||
- (void)lockDatabase:(id)sender {
|
- (void)lockDatabase:(id)sender {
|
||||||
if(self.undoManager.canUndo) {
|
|
||||||
/* ask the user? */
|
|
||||||
[self.undoManager removeAllActions];
|
|
||||||
}
|
|
||||||
[self exitSearch:self];
|
[self exitSearch:self];
|
||||||
NSError *error;
|
NSError *error;
|
||||||
/* Locking needs to be lossless hence just use the XML format */
|
/* FIXME: User feedback is ignored */
|
||||||
|
[self saveDocument:sender];
|
||||||
self.encryptedData = [self.tree encryptWithPassword:self.compositeKey forVersion:KPKXmlVersion error:&error];
|
self.encryptedData = [self.tree encryptWithPassword:self.compositeKey forVersion:KPKXmlVersion error:&error];
|
||||||
self.tree = nil;
|
self.tree = nil;
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidLockDatabaseNotification object:self];
|
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidLockDatabaseNotification object:self];
|
||||||
|
|||||||
Reference in New Issue
Block a user