aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPPreferencesUpgrade.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2010-11-11 13:15:46 +0000
committerstuconnolly <stuart02@gmail.com>2010-11-11 13:15:46 +0000
commit0a990aea16056b35fc95fb6845ac2570700bb613 (patch)
tree8fc6e9be062115d739e389dcf7eb36d262178666 /Source/SPPreferencesUpgrade.m
parentf5a548c05eb23afd80d3c7f105233542b0cfe8aa (diff)
downloadsequelpro-0a990aea16056b35fc95fb6845ac2570700bb613.tar.gz
sequelpro-0a990aea16056b35fc95fb6845ac2570700bb613.tar.bz2
sequelpro-0a990aea16056b35fc95fb6845ac2570700bb613.zip
More work on the new favorites controller, including loading and saving as well as the method to migrate existing favorites data. Currently not yet active.
Diffstat (limited to 'Source/SPPreferencesUpgrade.m')
-rw-r--r--Source/SPPreferencesUpgrade.m48
1 files changed, 48 insertions, 0 deletions
diff --git a/Source/SPPreferencesUpgrade.m b/Source/SPPreferencesUpgrade.m
index 887289e7..081be36a 100644
--- a/Source/SPPreferencesUpgrade.m
+++ b/Source/SPPreferencesUpgrade.m
@@ -297,4 +297,52 @@ void SPApplyRevisionChanges(void)
[prefs setObject:[NSNumber numberWithInteger:currentVersionNumber] forKey:SPLastUsedVersion];
}
+/**
+ * Attempts to migrate the user's connection favorites from their preference file to the new Favaorites
+ * plist in the application's support 'Data' directory.
+ */
+void SPMigrateConnectionFavoritesData(void)
+{
+ NSError *error = nil;
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+
+ NSString *dataPath = [fileManager applicationSupportDirectoryForSubDirectory:SPDataSupportFolder error:&error];
+
+ if (error) {
+ NSLog(@"Error loading favorites: %@", [error localizedDescription]);
+ return;
+ }
+
+ NSString *favoritesFile = [dataPath stringByAppendingPathComponent:SPFavoritesDataFile];
+
+ // Only proceed if the new favorites plist doesn't already exist
+ if (![fileManager fileExistsAtPath:favoritesFile]) {
+ NSDictionary *newFavorites = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:[[NSUserDefaults standardUserDefaults] objectForKey:SPFavorites] forKey:SPFavoriteChildrenKey] forKey:SPFavoritesRootKey];
+
+ NSError *error = nil;
+ NSString *errorString = nil;
+
+ NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:newFavorites
+ format:NSPropertyListXMLFormat_v1_0
+ errorDescription:&errorString];
+ if (plistData) {
+ [plistData writeToFile:favoritesFile options:NSAtomicWrite error:&error];
+
+ if (error) {
+ NSLog(@"Error migrating favorites data: %@", [error localizedDescription]);
+ }
+ else {
+ // Only uncomment when migration is complete
+ //[[NSUserDefaults standardUserDefaults] removeObjectForKey:SPFavorites];
+ }
+ }
+ else if (errorString) {
+ NSLog(@"Error converting migrating favorites data to plist format: %@", errorString);
+
+ [errorString release];
+ return;
+ }
+ }
+}
+
@end