From 829a043d626a15012c76ac6328ef07ea453f671a Mon Sep 17 00:00:00 2001 From: preble Date: Sat, 16 Oct 2010 16:11:18 -0400 Subject: [PATCH] Fixed bug in overzealous error testing: check for backup file before trying to delete it. --- Classes/IJInventoryWindowController.m | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Classes/IJInventoryWindowController.m b/Classes/IJInventoryWindowController.m index 2714eec..2d22499 100644 --- a/Classes/IJInventoryWindowController.m +++ b/Classes/IJInventoryWindowController.m @@ -213,14 +213,19 @@ BOOL success = NO; NSError *error = nil; - success = [[NSFileManager defaultManager] removeItemAtPath:backupPath error:&error]; - if (!success) + // Remove a previously-created .insidejobbackup, if it exists: + if ([[NSFileManager defaultManager] fileExistsAtPath:backupPath]) { - NSLog(@"%s:%d %@", __PRETTY_FUNCTION__, __LINE__, [error localizedDescription]); - NSBeginCriticalAlertSheet(@"An error occurred while saving.", @"Dismiss", nil, nil, self.window, nil, nil, nil, nil, @"Inside Job was unable to remove the prior backup of this level file:\n%@", [error localizedDescription]); - return; + success = [[NSFileManager defaultManager] removeItemAtPath:backupPath error:&error]; + if (!success) + { + NSLog(@"%s:%d %@", __PRETTY_FUNCTION__, __LINE__, [error localizedDescription]); + NSBeginCriticalAlertSheet(@"An error occurred while saving.", @"Dismiss", nil, nil, self.window, nil, nil, nil, nil, @"Inside Job was unable to remove the prior backup of this level file:\n%@", [error localizedDescription]); + return; + } } + // Create the backup: success = [[NSFileManager defaultManager] copyItemAtPath:levelPath toPath:backupPath error:&error]; if (!success) { @@ -229,6 +234,7 @@ return; } + // Write the new level.dat out: success = [[level writeData] writeToURL:[NSURL fileURLWithPath:levelPath] options:0 error:&error]; if (!success) {