0

fixed crash on worlds named "World[not int]", and made world list play nice with world names

This commit is contained in:
Aaron Griffith
2011-02-23 13:07:21 -05:00
parent dd01eae9e0
commit b40d84f92b
2 changed files with 15 additions and 4 deletions

12
gmap.py
View File

@@ -183,13 +183,21 @@ def list_worlds():
print 'No world saves found in the usual place'
return
print "Detected saves:"
for num, info in sorted(worlds.iteritems()):
for name, info in sorted(worlds.iteritems()):
if isinstance(name, basestring) and name.startswith("World") and len(name) == 6:
try:
world_n = int(name[-1])
# we'll catch this one later, when it shows up as an
# integer key
continue
except ValueError:
pass
timestamp = time.strftime("%Y-%m-%d %H:%M",
time.localtime(info['LastPlayed'] / 1000))
playtime = info['Time'] / 20
playstamp = '%d:%02d' % (playtime / 3600, playtime / 60 % 60)
size = "%.2fMB" % (info['SizeOnDisk'] / 1024. / 1024.)
print "World %s: %s Playtime: %s Modified: %s" % (num, size, playstamp, timestamp)
print "World %s: %s Playtime: %s Modified: %s" % (name, size, playstamp, timestamp)
if __name__ == "__main__":

View File

@@ -406,8 +406,11 @@ def get_worlds():
info = nbt.load(world_dat)[1]
info['Data']['path'] = os.path.join(save_dir, dir)
if dir.startswith("World") and len(dir) == 6:
try:
world_n = int(dir[-1])
ret[world_n] = info['Data']
except ValueError:
pass
if 'LevelName' in info['Data'].keys():
ret[info['Data']['LevelName']] = info['Data']