From b8fc79dd357d8dd1cf3177d1a7faef030497a9e0 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Thu, 11 Nov 2010 15:09:14 +0000 Subject: Commenting and move SPFavoriteNode within Xcode's logical structure. --- Source/SPFavoritesController.m | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Source') diff --git a/Source/SPFavoritesController.m b/Source/SPFavoritesController.m index 85f4e587..08df59c8 100644 --- a/Source/SPFavoritesController.m +++ b/Source/SPFavoritesController.m @@ -98,6 +98,7 @@ static SPFavoritesController *sharedFavoritesController = nil; NSString *favoritesFile = [dataPath stringByAppendingPathComponent:SPFavoritesDataFile]; NSString *favoritesBackupFile = [dataPath stringByAppendingPathComponent:[@"~" stringByAppendingString:SPFavoritesDataFile]]; + // If the favorites data file already exists, attempt to move it to keep as a backup if ([fileManager fileExistsAtPath:favoritesFile]) { [fileManager moveItemAtPath:favoritesFile toPath:favoritesBackupFile error:&error]; } @@ -107,6 +108,7 @@ static SPFavoritesController *sharedFavoritesController = nil; error = nil; + // We can't move it so try and delete it if (![fileManager removeItemAtPath:favoritesFile error:&error] && error) { NSLog(@"Unable to delete existing favorites data file during save. Something is wrong, permissions perhaps: %@", [error localizedDescription]); return; @@ -123,9 +125,11 @@ static SPFavoritesController *sharedFavoritesController = nil; 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]; } } @@ -173,6 +177,7 @@ static SPFavoritesController *sharedFavoritesController = nil; NSString *favoritesFile = [dataPath stringByAppendingPathComponent:SPFavoritesDataFile]; + // If the favorites data file already exists use it, otherwise create an empty one if ([fileManager fileExistsAtPath:favoritesFile]) { favorites = [[NSDictionary alloc] initWithContentsOfFile:favoritesFile]; } -- cgit v1.2.3