From 07ee86e50f5c05ca76c2c7e6d6097b2ceafad7c6 Mon Sep 17 00:00:00 2001 From: preble Date: Fri, 8 Oct 2010 00:21:29 -0400 Subject: [PATCH] Improved handling of non-existent worlds. --- IJInventoryWindowController.m | 19 ++++++++++++++++++- IJMinecraftLevel.h | 2 ++ IJMinecraftLevel.m | 7 +++++-- ItemPicker.xib | 22 +++++++++++----------- 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/IJInventoryWindowController.m b/IJInventoryWindowController.m index d5035ce..19b6601 100644 --- a/IJInventoryWindowController.m +++ b/IJInventoryWindowController.m @@ -43,6 +43,24 @@ [quickItem removeAllObjects]; [inventoryItem removeAllObjects]; + // Reload data here because we have just invalidated all of the items used in the outline view. + [outlineView reloadData]; + + + [self willChangeValueForKey:@"worldTime"]; + [level release]; + level = nil; + [inventory release]; + inventory = nil; + [self didChangeValueForKey:@"worldTime"]; + + + if (![IJMinecraftLevel worldExistsAtIndex:worldIndex]) + { + NSBeginCriticalAlertSheet(@"No world exists in that slot.", @"Dismiss", nil, nil, self.window, nil, nil, nil, nil, @"Please create a new single player world in this slot using Minecraft and try again."); + return; + } + sessionLockValue = [IJMinecraftLevel writeToSessionLockAtIndex:worldIndex]; if (![IJMinecraftLevel checkSessionLockAtIndex:worldIndex value:sessionLockValue]) { @@ -64,7 +82,6 @@ [self willChangeValueForKey:@"worldTime"]; - [level release]; level = [[IJMinecraftLevel nbtContainerWithData:fileData] retain]; inventory = [[level inventory] retain]; diff --git a/IJMinecraftLevel.h b/IJMinecraftLevel.h index 9ff66a4..509a3f3 100644 --- a/IJMinecraftLevel.h +++ b/IJMinecraftLevel.h @@ -20,6 +20,8 @@ + (NSString *)pathForLevelDatAtIndex:(int)worldIndex; + (NSString *)pathForSessionLockAtIndex:(int)worldIndex; ++ (BOOL)worldExistsAtIndex:(int)worldIndex; + + (int64_t)writeToSessionLockAtIndex:(int)worldIndex; + (BOOL)checkSessionLockAtIndex:(int)worldIndex value:(int64_t)checkValue; diff --git a/IJMinecraftLevel.m b/IJMinecraftLevel.m index d2a310a..bf308fa 100644 --- a/IJMinecraftLevel.m +++ b/IJMinecraftLevel.m @@ -96,7 +96,10 @@ return [[[self class] pathForWorldAtIndex:worldIndex] stringByAppendingPathComponent:@"session.lock"]; } - ++ (BOOL)worldExistsAtIndex:(int)worldIndex +{ + return [[NSFileManager defaultManager] fileExistsAtPath:[[self class] pathForLevelDatAtIndex:worldIndex]]; +} + (NSData *)dataWithInt64:(int64_t)v { @@ -138,7 +141,7 @@ if (!data) { NSLog(@"Failed to read session lock at %@", path); - return; + return NO; } int64_t milliseconds = [IJMinecraftLevel int64FromData:data]; diff --git a/ItemPicker.xib b/ItemPicker.xib index fa21856..b75cac4 100644 --- a/ItemPicker.xib +++ b/ItemPicker.xib @@ -12,7 +12,7 @@ YES - + YES @@ -39,7 +39,7 @@ NSApplication - 27 + 283 2 {{577, 347}, {249, 286}} -1535637504 @@ -175,7 +175,7 @@ 3 MC4zMzMzMzI5ODU2AA - + 6 System headerTextColor @@ -203,7 +203,7 @@ YES - + name 191 10 @@ -219,9 +219,9 @@ headerColor - + - + 337772096 2048 Text Cell @@ -474,7 +474,7 @@ YES - + @@ -494,17 +494,17 @@ 26 - + YES - + 27 - - + +