aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPBundleEditorController.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-12-20 09:48:22 +0000
committerBibiko <bibiko@eva.mpg.de>2010-12-20 09:48:22 +0000
commitd442e29e22e7cdb8a36f2bf3d2ad7cfc8910a0e9 (patch)
tree70f7b83f6f5ed4a76feb41ad0b0db38963da79d9 /Source/SPBundleEditorController.m
parentb3b8f0ff04486a982175f70ba72a623a5fff9ad7 (diff)
downloadsequelpro-d442e29e22e7cdb8a36f2bf3d2ad7cfc8910a0e9.tar.gz
sequelpro-d442e29e22e7cdb8a36f2bf3d2ad7cfc8910a0e9.tar.bz2
sequelpro-d442e29e22e7cdb8a36f2bf3d2ad7cfc8910a0e9.zip
• preparations for managing default Bundles which will ship with SP
• improved Bundle Editor to store only modified Bundles
Diffstat (limited to 'Source/SPBundleEditorController.m')
-rw-r--r--Source/SPBundleEditorController.m32
1 files changed, 32 insertions, 0 deletions
diff --git a/Source/SPBundleEditorController.m b/Source/SPBundleEditorController.m
index 32f5b581..82c93047 100644
--- a/Source/SPBundleEditorController.m
+++ b/Source/SPBundleEditorController.m
@@ -871,6 +871,7 @@
NSFileManager *fm = [NSFileManager defaultManager];
BOOL isDir = NO;
+ BOOL isNewBundle = NO;
// If passed aPath is nil construct the path from bundle's bundleName.
// aPath is mainly used for dragging a bundle from table view.
@@ -888,6 +889,7 @@
if(![fm createDirectoryAtPath:aPath withIntermediateDirectories:YES attributes:nil error:nil])
return NO;
isDir = YES;
+ isNewBundle = YES;
}
// If aPath exists but it's not a folder bail out
@@ -908,6 +910,28 @@
kBundleNameKey,
nil]];
+
+ if(!isNewBundle) {
+ NSError *readError = nil;
+ NSString *convError = nil;
+ NSPropertyListFormat format;
+ NSDictionary *cmdData = nil;
+ NSData *pData = [NSData dataWithContentsOfFile:cmdFilePath options:NSUncachedRead error:&readError];
+ cmdData = [[NSPropertyListSerialization propertyListFromData:pData
+ mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain];
+ if(!cmdData || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
+ NSLog(@"“%@” file couldn't be read.", cmdFilePath);
+ NSBeep();
+ return NO;
+ } else {
+ // Check for changes and return if no changes are found
+ if([[saveDict description] isEqualToString:[cmdData description]])
+ return YES;
+ if([cmdData objectForKey:SPBundleFileIsDefaultBundleKey])
+ [saveDict setObject:[NSNumber numberWithBool:YES] forKey:SPBundleFileDefaultBundleWasModifiedKey];
+ }
+ }
+
// Remove a given old command.plist file
[fm removeItemAtPath:cmdFilePath error:nil];
[saveDict writeToFile:cmdFilePath atomically:YES];
@@ -960,6 +984,14 @@
deletionSuccessfully = NO;
break;
}
+ if([obj objectForKey:SPBundleFileIsDefaultBundleKey]) {
+ NSMutableArray *deletedBundles = [NSMutableArray array];
+ [deletedBundles setArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"deletedDefaultBundles"]];
+ if(![deletedBundles containsObject:[obj objectForKey:SPBundleFileUUIDKey]]) {
+ [deletedBundles addObject:[obj objectForKey:SPBundleFileUUIDKey]];
+ [[NSUserDefaults standardUserDefaults] setObject:deletedBundles forKey:@"deletedDefaultBundles"];
+ }
+ }
[commandsOutlineView reloadData];
}
}