This patch makes Dragon Hunt use the user's home to store saved games and settings Patch created for Zenwalk linux by George Vlahavas (vlahavas~AT~gmail~DOT~com, gapan@zenwalk forums) --- Dragon_Hunt-3.56-old/code/g.py 2007-05-06 10:17:19.000000000 +0300 +++ Dragon_Hunt-3.56/code/g.py 2008-10-31 21:42:53.885320899 +0200 @@ -27,6 +27,8 @@ #import ImageTk #needed for die_roll import pygame +import os +import shutil from random import random #needed for save/load game @@ -137,11 +139,15 @@ #uses pickle, first line is a version number. def savegame(save_file): #If there is no save directory, make one. - if path.isdir(g.mod_directory + "/saves") == 0: - if path.exists(g.mod_directory + "/saves") == 1: - remove(g.mod_directory + "/saves") - mkdir(g.mod_directory + "/saves") - save_loc = g.mod_directory + "/saves/" + save_file + if path.isdir(os.getenv('HOME')+"/.Dragon_Hunt") == 0: + if path.exists(os.getenv('HOME')+"/.Dragon_Hunt") == 1: + remove(os.getenv('HOME')+"/.Dragon_Hunt") + mkdir(os.getenv('HOME')+"/.Dragon_Hunt") + if path.isdir(os.getenv('HOME')+"/.Dragon_Hunt/saves") == 0: + if path.exists(os.getenv('HOME')+"/.Dragon_Hunt/saves") == 1: + remove(os.getenv('HOME')+"/.Dragon_Hunt/saves") + mkdir(os.getenv('HOME')+"/.Dragon_Hunt/saves") + save_loc = os.getenv('HOME')+"/.Dragon_Hunt/saves/" + save_file savefile=open(save_loc, 'w') #savefile version; update whenever the data saved changes. pickle.dump("dh3.3", savefile) @@ -187,7 +193,7 @@ savefile.close() def loadgame(save_file): - save_loc = g.mod_directory + "/saves/" + save_file + save_loc = os.getenv('HOME')+"/.Dragon_Hunt/saves/" + save_file savefile=open(save_loc, 'r') version = pickle.load(savefile) if version != "dh3.3": @@ -229,7 +235,7 @@ savefile.close() def loadgame_31(save_file): - save_loc = g.mod_directory + "/saves/" + save_file + save_loc = os.getenv('HOME')+"/.Dragon_Hunt/saves/" + save_file savefile=open(save_loc, 'r') version = pickle.load(savefile) if version != "dh3.2": @@ -372,7 +378,14 @@ fullscreen = 0 #try to open settings.txt. If it doesn't exist, # just use the default settings. - try: file = open("../settings.txt", 'r') + if path.isdir(os.getenv('HOME')+"/.Dragon_Hunt") == 0: + if path.exists(os.getenv('HOME')+"/.Dragon_Hunt") == 1: + remove(os.getenv('HOME')+"/.Dragon_Hunt") + mkdir(os.getenv('HOME')+"/.Dragon_Hunt") + #copy over the standard settings file if it doesn't exist and use that + if path.exists(os.getenv('HOME')+"/.Dragon_Hunt/settings.txt") == 0: + shutil.copy2("/usr/share/Dragon_Hunt/settings.txt", os.getenv('HOME')+"/.Dragon_Hunt/settings.txt") + try: file = open(os.getenv('HOME')+"/.Dragon_Hunt/settings.txt", 'r') except IOError: return 0 line = file.readline() while (line != ''): diff -Naur Dragon_Hunt-3.56-old/code/loadgame.py Dragon_Hunt-3.56/code/loadgame.py --- Dragon_Hunt-3.56-old/code/loadgame.py 2007-05-05 07:43:50.000000000 +0300 +++ Dragon_Hunt-3.56/code/loadgame.py 2008-10-31 21:43:04.056305907 +0200 @@ -21,6 +21,8 @@ import pygame import g +import os + from os import listdir, path, mkdir, remove #was a game loaded? Used to determine whether to use newgame script. @@ -92,7 +94,7 @@ tmp_titles.append("") # return else: - save_loc = g.mod_directory + "/saves/" + saves_array[saves_pos] + save_loc = os.getenv('HOME')+"/.Dragon_Hunt/saves/" + saves_array[saves_pos] savefile=open(save_loc, 'r') version_unused = g.pickle.load(savefile) tmp_stats["name"] = str(g.pickle.load(savefile)) @@ -359,14 +361,18 @@ pixels_per_line = 20 #If there is no save directory, make one. - if path.isdir(g.mod_directory + "/saves") == 0: - if path.exists(g.mod_directory + "/saves") == 1: - remove(g.mod_directory + "/saves") - mkdir(g.mod_directory + "/saves") + if path.isdir(os.getenv('HOME')+"/.Dragon_Hunt") == 0: + if path.exists(os.getenv('HOME')+"/.Dragon_Hunt") == 1: + remove(os.getenv('HOME')+"/.Dragon_Hunt") + mkdir(os.getenv('HOME')+"/.Dragon_Hunt") + if path.isdir(os.getenv('HOME')+"/.Dragon_Hunt/saves") == 0: + if path.exists(os.getenv('HOME')+"/.Dragon_Hunt/saves") == 1: + remove(os.getenv('HOME')+"/.Dragon_Hunt/saves") + mkdir(os.getenv('HOME')+"/.Dragon_Hunt/saves") #show the files contained in the saves directory. global saves_array saves_array = [] - tmp_saves_array = listdir(g.mod_directory + "/saves") + tmp_saves_array = listdir(os.getenv('HOME')+"/.Dragon_Hunt/saves") for save_name in tmp_saves_array: if save_name [:1] != "." and save_name != "CVS": saves_array.append(save_name) diff -Naur Dragon_Hunt-3.56-old/code/options.py Dragon_Hunt-3.56/code/options.py --- Dragon_Hunt-3.56-old/code/options.py 2007-05-06 09:04:14.000000000 +0300 +++ Dragon_Hunt-3.56/code/options.py 2008-10-31 21:42:58.942864763 +0200 @@ -20,7 +20,10 @@ import pygame import g -from os import path +import os +import shutil + +from os import path, getenv #-1=none, 0=fullscreen, 1=difficulty, 2=custom key, 3=use joy, 4=custom joy #5=save, 6=reset, 7=cancel @@ -276,14 +279,16 @@ #save the settings to disk options_file_text = [] - if path.exists(g.mod_directory + "/../../settings.txt") == 1: - optionfile = open(g.mod_directory + "/../../settings.txt") - options_file_text = optionfile.readlines() - else: - "Could not open settings.txt. Not saving settings." - cancel_settings() - refresh_window() - return + #create the settings dir in user's home if it doesn't exist + if path.isdir(os.getenv('HOME')+"/.Dragon_Hunt") == 0: + if path.exists(os.getenv('HOME')+"/.Dragon_Hunt") == 1: + remove(os.getenv('HOME')+"/.Dragon_Hunt") + mkdir(os.getenv('HOME')+"/.Dragon_Hunt") + #copy over the standard settings file if it doesn't exist and use that + if path.exists(os.getenv('HOME')+"/.Dragon_Hunt/settings.txt") == 0: + shutil.copy2( "/usr/share/Dragon_Hunt/settings.txt", os.getenv('HOME')+"/.Dragon_Hunt/settings.txt") + optionfile = open(os.getenv('HOME')+"/.Dragon_Hunt/settings.txt") + options_file_text = optionfile.readlines() for linenum in range(len(options_file_text)): command = options_file_text[linenum].split("=")[0].strip().lower() @@ -309,7 +314,7 @@ options_file_text[linenum]=command+"="+str(g.joy_axis1)+"\n" optionfile.close() - optionfile = open(g.mod_directory + "/../../settings.txt", "w") + optionfile = open(os.getenv('HOME')+"/.Dragon_Hunt/settings.txt", "w") optionfile.writelines(options_file_text)