diff options
author | rowanbeentje <rowan@beent.je> | 2012-06-22 01:46:50 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2012-06-22 01:46:50 +0000 |
commit | bc51d59ca9a5ec8a741eef8142d3224a02461a5a (patch) | |
tree | 2e6b22048f3d7fbc86c0908c2095809ae2952ec1 /Source/SPPreferencesUpgrade.m | |
parent | 756f01cc734ba7603f7e24bce8102bb360e6f56d (diff) | |
download | sequelpro-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/SPPreferencesUpgrade.m')
-rw-r--r-- | Source/SPPreferencesUpgrade.m | 78 |
1 files changed, 40 insertions, 38 deletions
diff --git a/Source/SPPreferencesUpgrade.m b/Source/SPPreferencesUpgrade.m index ac25b6b3..a7123ce6 100644 --- a/Source/SPPreferencesUpgrade.m +++ b/Source/SPPreferencesUpgrade.m @@ -298,7 +298,12 @@ void SPApplyRevisionChanges(void) [prefs setObject:newMappedValue forKey:@"DefaultEncodingTag"]; } - + + // For versions prior to 3695 (<1.0), migrate the favourites across if appropriate + if (recordedVersionNumber < 3695) { + SPMigrateConnectionFavoritesData(); + } + // Update the prefs revision [prefs setObject:[NSNumber numberWithInteger:currentVersionNumber] forKey:SPLastUsedVersion]; } @@ -312,9 +317,20 @@ void SPMigrateConnectionFavoritesData(void) NSError *error = nil; NSFileManager *fileManager = [NSFileManager defaultManager]; NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; - + + NSString *dataPath = [fileManager applicationSupportDirectoryForSubDirectory:SPDataSupportFolder error:&error]; + if (error) { + NSLog(@"Error loading favorites: %@", [error localizedDescription]); + return; + } + + NSString *favoritesFile = [dataPath stringByAppendingPathComponent:SPFavoritesDataFile]; + + // If the favourites file already exists, don't proceed + if ([fileManager fileExistsAtPath:favoritesFile]) return; + NSMutableArray *favorites = [[NSMutableArray alloc] initWithArray:[prefs objectForKey:SPOldFavoritesKey]]; - + // Change the last used favorite and default favorite's indexes to be ID based if (![prefs objectForKey:SPLastFavoriteID] && [favorites count]) { @@ -332,47 +348,33 @@ void SPMigrateConnectionFavoritesData(void) // TOOD: Favorites migration - only uncomment when we want to remove backwards compatibility //[prefs removeObjectForKey:@"LastFavoriteIndex"]; } + + NSDictionary *newFavorites = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Favorites", @"favorites label"), SPFavoritesGroupNameKey, favorites, SPFavoriteChildrenKey, nil] forKey:SPFavoritesRootKey]; - NSString *dataPath = [fileManager applicationSupportDirectoryForSubDirectory:SPDataSupportFolder error:&error]; - - if (error) { - NSLog(@"Error loading favorites: %@", [error localizedDescription]); - [favorites release]; - return; - } - - NSString *favoritesFile = [dataPath stringByAppendingPathComponent:SPFavoritesDataFile]; + error = nil; + NSString *errorString = nil; - // Only proceed if the new favorites plist doesn't already exist - if (![fileManager fileExistsAtPath:favoritesFile]) { - - NSDictionary *newFavorites = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Favorites", @"favorites label"), SPFavoritesGroupNameKey, favorites, SPFavoriteChildrenKey, nil] forKey:SPFavoritesRootKey]; - - 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]; - 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 { - // TOOD: Favorites migration - only uncomment when we want to remove backwards compatibility - //[prefs removeObjectForKey:SPOldFavoritesKey]; - } + if (error) { + NSLog(@"Error migrating favorites data: %@", [error localizedDescription]); } - else if (errorString) { - NSLog(@"Error converting migrating favorites data to plist format: %@", errorString); - - [favorites release]; - [errorString release]; - return; + else { + // TOOD: Favorites migration - only uncomment when we want to remove backwards compatibility + //[prefs removeObjectForKey:SPOldFavoritesKey]; } } + else if (errorString) { + NSLog(@"Error converting migrating favorites data to plist format: %@", errorString); + + [favorites release]; + [errorString release]; + return; + } [favorites release]; } |