File savesfix.patch of Package ardentryst
Fix crashes when renaming or removing saves.
* Opening the in-game menu with [Q] and renaming the player name with [R]
crashed the game. Appearently, the code had been edited to put saves in the
user's home dir, but the rename function was forgotten and accessed the wrong
place. (play_level.py)
* Deleting a save crashed if it was the only save left. The game didn't know
where to put the cursor in the now empty list of saves. Fixed by returning
to the main menu in this case. (ardentryst.py)
* Both of these fails were caught by the game's own error handling code, which
unfortunately threw another exception, because it, too, was trying to write
its bug report to the wrong dir. (ardentryst.py)
Bug-Debian: https://bugs.debian.org/733469
Signed-off-by: Jens Rottmann
--- ardentryst/ardentryst.py
+++ savesfix/ardentryst.py
@@ -682,8 +682,8 @@ def handleException(e):
if str(e) not in ["Don't cheat!"]:
traceback.print_exc()
traceback.print_exc(file = open(os.path.join(SAVEDIRECTORY, "log.txt"), "a"))
- open("bugreport.txt", "w").write(open(os.path.join(SAVEDIRECTORY, "log.txt"), "r").read())
-
+ open(os.path.join(SAVEDIRECTORY, "bugreport.txt"), "w").write(open(os.path.join(SAVEDIRECTORY, "log.txt"), "r").read())
+
screen.fill((0, 0, 0))
if "game" in PLAYLOCALS:
@@ -1464,6 +1464,8 @@ def Game_SlotMenu(gameobj = None):
cursor = min(cursor, len(gamelist)-1)
cursloaded = False
incompat = False
+ if len(gamelist) == 0:
+ return False
elif k == K_ESCAPE:
password = ""
if passwordstage:
--- ardentryst/play_level.py
+++ savesfix/play_level.py
@@ -1585,17 +1585,18 @@ def Ingame_Menu(data):
elif k == K_BACKSPACE and renaming:
renameto = renameto[:-1]
elif k == K_RETURN and renaming:
- sfiles = os.listdir("Saves")
+ from helpers import SAVEDIRECTORY
+ sfiles = os.listdir(os.path.join(SAVEDIRECTORY, "Saves"))
if renameto+".asf" in sfiles:
interface_sound("error", SOUNDBOX)
elif len(renameto) == 0:
interface_sound("error", SOUNDBOX)
else:
interface_sound("menu-small-select", SOUNDBOX)
- tempgobj = pickle.load(open(os.path.join("Saves", game.savefilename),"r"))
- os.rename(os.path.join("Saves", game.savefilename), os.path.join("Saves", renameto+".asf"))
+ tempgobj = pickle.load(open(os.path.join(SAVEDIRECTORY, "Saves", game.savefilename),"rb"))
+ os.rename(os.path.join(SAVEDIRECTORY, "Saves", game.savefilename), os.path.join(SAVEDIRECTORY, "Saves", renameto+".asf"))
tempgobj.savefilename = renameto + ".asf"
- pickle.dump(tempgobj, open(os.path.join("Saves", renameto+".asf"), "w"))
+ pickle.dump(tempgobj, open(os.path.join(SAVEDIRECTORY, "Saves", renameto+".asf"), "wb"))
game.savefilename = renameto + ".asf"
renaming = False
renameto = ""
--