aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPFavoritesController.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2012-06-22 01:46:50 +0000
committerrowanbeentje <rowan@beent.je>2012-06-22 01:46:50 +0000
commitbc51d59ca9a5ec8a741eef8142d3224a02461a5a (patch)
tree2e6b22048f3d7fbc86c0908c2095809ae2952ec1 /Source/SPFavoritesController.m
parent756f01cc734ba7603f7e24bce8102bb360e6f56d (diff)
downloadsequelpro-bc51d59ca9a5ec8a741eef8142d3224a02461a5a.tar.gz
sequelpro-bc51d59ca9a5ec8a741eef8142d3224a02461a5a.tar.bz2
sequelpro-bc51d59ca9a5ec8a741eef8142d3224a02461a5a.zip
- Address favourites saving on quit, which appears to sometimes die during preference serialisation, causing Issue #1332. Reworking the order of commands ensure this is performed more safely.
- Move upgrade routine to only be called on version upgrades, tweak order of calls
Diffstat (limited to 'Source/SPFavoritesController.m')
-rw-r--r--Source/SPFavoritesController.m52
1 files changed, 26 insertions, 26 deletions
diff --git a/Source/SPFavoritesController.m b/Source/SPFavoritesController.m
index 0a069b3a..da8be7c6 100644
--- a/Source/SPFavoritesController.m
+++ b/Source/SPFavoritesController.m
@@ -356,7 +356,21 @@ static SPFavoritesController *sharedFavoritesController = nil;
NSError *error = nil;
NSString *errorString = nil;
-
+
+ // Before starting the file actions, attempt to create a dictionary
+ // from the current favourites tree and convert it to a dictionary representation
+ // to create the plist data. This is done before file changes as it can sometimes
+ // be terminated during shutdown.
+ NSDictionary *dictionary = [NSDictionary dictionaryWithObject:data forKey:SPFavoritesRootKey];
+ NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:dictionary
+ format:NSPropertyListXMLFormat_v1_0
+ errorDescription:&errorString];
+ if (errorString) {
+ NSLog(@"Error converting favorites data to plist format: %@", errorString);
+ [errorString release];
+ }
+
+
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *dataPath = [fileManager applicationSupportDirectoryForSubDirectory:SPDataSupportFolder error:&error];
@@ -389,33 +403,19 @@ static SPFavoritesController *sharedFavoritesController = nil;
return;
}
}
-
- NSDictionary *dictionary = [NSDictionary dictionaryWithObject:data forKey:SPFavoritesRootKey];
-
- // Convert the current favorites tree to a dictionary representation to create the plist data
- NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:dictionary
- format:NSPropertyListXMLFormat_v1_0
- errorDescription:&errorString];
-
- if (plistData) {
- [plistData writeToFile:favoritesFile options:NSAtomicWrite error:&error];
+
+ // Write the converted data to the favourites file
+ [plistData writeToFile:favoritesFile options:NSAtomicWrite error:&error];
+
+ if (error) {
+ NSLog(@"Error writing favorites data. Restoring backup if available: %@", [error localizedDescription]);
- if (error) {
- NSLog(@"Error writing favorites data. Restoring backup if available: %@", [error localizedDescription]);
-
- // Restore the original data file
- [fileManager moveItemAtPath:favoritesBackupFile toPath:favoritesFile error:NULL];
- }
- else {
- // Remove the original backup
- [fileManager removeItemAtPath:favoritesBackupFile error:NULL];
- }
+ // Restore the original data file
+ [fileManager moveItemAtPath:favoritesBackupFile toPath:favoritesFile error:NULL];
}
- else if (errorString) {
- NSLog(@"Error converting favorites data to plist format: %@", errorString);
-
- [errorString release];
-
+ else {
+
+ // Remove the original backup
[fileManager removeItemAtPath:favoritesBackupFile error:NULL];
}