Index: ardentryst.py =================================================================== --- ardentryst.py +++ ardentryst.py 2009-07-21 09:31:19.000000000 -0400 @@ -49,6 +49,13 @@ VERSION = "20090405 (1.7-Warp Speed Stable) 10:22 AM AEST" DVERSION = VERSION[VERSION.index("(")+1:VERSION.index(")")].replace("-", ":") +homedir = os.path.expanduser('~') +ardentryst_dir = ".ardentryst" + +if not os.path.exists(os.path.join(homedir,ardentryst_dir)): + os.mkdir(os.path.join(homedir,ardentryst_dir)) + + # This is the importing of my own modules. from pygame.locals import * from data import * @@ -59,9 +66,9 @@ from wordwrap import * from controls import * from helpers import * - + # I log the start of a new run-through. Reset log.txt too. -open("log.txt", "w") +open(os.path.join(homedir,ardentryst_dir, "log.txt" ), 'w') logfile("*** BEGIN ARDENTRYST LOGFILE ***") logfile(time.ctime()) logfile("Python " + sys.version.replace("\n", " ")) @@ -1196,7 +1203,7 @@ inslotmenu = True dark = pygame.Surface((640,480)) dark.set_alpha(180) - savedir = os.path.join(os.getcwd(), "Saves") + savedir = os.path.join(homedir,ardentryst_dir,"Saves") if not os.path.isdir(savedir): try: os.mkdir(savedir) @@ -1204,7 +1211,7 @@ raise Exception("Do not have a file called Saves in your Ardentryst directory.") gamelist = [x for x in os.listdir(savedir) if x.endswith(".asf")] - gamelist.sort(lambda x, y: cPickle.load(open(os.path.join(os.getcwd(), "Saves", x),"r")).startdate < cPickle.load(open(os.path.join(os.getcwd(), "Saves", y),"r")).startdate) + gamelist.sort(lambda x, y: cPickle.load(open(os.path.join(homedir,ardentryst_dir, "Saves", x),"r")).startdate < cPickle.load(open(os.path.join(homedir,ardentryst_dir, "Saves", y),"r")).startdate) cursor = 0 csurf = Data.images["Menupiece.png"][0] @@ -1229,7 +1236,7 @@ return title = "Resume Quest" try: - gameobj = cPickle.load(open(os.path.join(os.getcwd(), "Saves", gamelist[0]),"r")) + gameobj = cPickle.load(open(os.path.join(homedir,ardentryst_dir, "Saves", gamelist[0]),"r")) except: raise Exception("Corruption. Delete all saves you don't need in Saves directory") @@ -1371,8 +1378,8 @@ elif k == K_DELETE: if gamelist[cursor]: interface_sound("menu-select") - os.remove(os.path.join("Saves", gamelist[cursor])) - gamelist = [x for x in os.listdir(os.path.join(os.getcwd(), "Saves")) if x.endswith(".asf")] + os.remove(os.path.join(homedir,ardentryst_dir,"Saves", gamelist[cursor])) + gamelist = [x for x in os.listdir(os.path.join(homedir,ardentryst_dir, "Saves")) if x.endswith(".asf")] cursor = min(cursor, len(gamelist)-1) elif k == K_ESCAPE: password = "" @@ -1488,7 +1495,7 @@ lasttick = wait_tick(lasttick) if not newgame and not cursloaded: - gameobj = cPickle.load(open(os.path.join(os.getcwd(), "Saves", gamelist[cursor]),"r")) + gameobj = cPickle.load(open(os.path.join(homedir,ardentryst_dir, "Saves", gamelist[cursor]),"r")) cursloaded = True pygame.key.set_repeat() @@ -2310,7 +2317,7 @@ saved = False if not pointer or must: - cPickle.dump(game, open(os.path.join(os.getcwd(), "Saves", game.savefilename), "w")) + cPickle.dump(game, open(os.path.join(homedir,ardentryst_dir, "Saves", game.savefilename), "w")) saved = True fade_to_black(screen, 1) if saved: @@ -2459,7 +2466,7 @@ for l in mapdata[w+1][1:]: Game.scores[w].append(0) Game.timegems[w].append(0) - cPickle.dump(Game, open(os.path.join(os.getcwd(), "Saves", Game.savefilename), "w")) + cPickle.dump(Game, open(os.path.join(homedir,ardentryst_dir, "Saves", Game.savefilename), "w")) else: player = Game.playerobject @@ -3734,7 +3741,7 @@ # Load options from file try: - optionsfile = open("options.dat", "r") + optionsfile = open(os.path.join(homedir,ardentryst_dir, "options.dat"), "r") graphic_o = cPickle.load(optionsfile) audio_o = cPickle.load(optionsfile) @@ -4376,7 +4383,7 @@ # restart display mode to windowed or fullscreen/4:3 or 16:10 depending on new options # Save options to file - optionsfile = open("options.dat", "w") + optionsfile = open(os.path.join(homedir,ardentryst_dir,"options.dat"), "w") cPickle.dump(g_options, optionsfile) cPickle.dump(a_options, optionsfile) cPickle.dump(p_options, optionsfile) @@ -4499,7 +4506,7 @@ selected = "" activeitem = dict.fromkeys(menu_items, True) p_options["MustOP"] = 0 - optionsfile = open("options.dat", "w") + optionsfile = open(os.path.join(homedir,ardentryst_dir,"options.dat"), "w") cPickle.dump(g_options, optionsfile) cPickle.dump(a_options, optionsfile) cPickle.dump(p_options, optionsfile) @@ -4641,7 +4648,7 @@ print "An error has occurred. " if str(e) not in ["Don't cheat!"]: traceback.print_exc() - traceback.print_exc(file=open("log.txt", "a")) + traceback.print_exc(file=open(os.path.join(homedir,ardentryst_dir, "log.txt" ), "a")) try: screen.fill((0,0,0)) @@ -4661,7 +4668,7 @@ screen.blit(surfs[x], (320-r[2]/2, 240+x*20)) - traceback.print_exc(file=open("log.txt", "a")) + traceback.print_exc(file=open(os.path.join(homedir,ardentryst_dir, "log.txt" ), "a")) myflip() ge() @@ -4678,7 +4685,7 @@ if e.type == KEYDOWN: if e.key == K_e: try: - bugreport = open("log.txt", "r").readlines() + bugreport = open(os.path.join(homedir,ardentryst_dir, "log.txt" ), "r").readlines() if bugreport[-1].strip() in ["KeyboardInterrupt", "Exception: Don't cheat!"]: surfs[2] = Fonts[13].render("There is no reason to report this", 1, (255, 0, 0)) else: @@ -4691,7 +4698,7 @@ bugreport.append("\n########################### Playvars: ########################### \n\n") for x in PLAYLOCALS: bugreport.append(x+": "+str(PLAYLOCALS[x])[:100]+"\n") - open("log.txt", "w").writelines(bugreport) + open(os.path.join(homedir,ardentryst_dir, "log.txt" ), "w").writelines(bugreport) msg = email.message_from_string("".join(bugreport)) msg['Subject'] = mysubj msg['From'] = "Ardentryst_Report@hotmail.com" Index: helpers.py =================================================================== --- helpers.py +++ helpers.py 2009-07-21 00:12:30.000000000 -0400 @@ -69,22 +69,24 @@ PROFILING = True def logfile(text): + ardentryst_dir = ".ardentryst" + homedir = os.path.expanduser('~') global LOGGING if not LOGGING: return if type(text) != str: print "Warning, logfile call incorrect:", str(text) return try: - src = open("log.txt", "r").readlines() + src = open(os.path.join(homedir,ardentryst_dir, "log.txt" ), 'r').readlines() except: - open("log.txt", "w") + open(os.path.join(homedir,ardentryst_dir, "log.txt" ), 'w') src = [] if len(src) and "|" in src[-1]: if src[-1][src[-1].index("|")+1:].strip() == text.strip(): return src.append(time.ctime() + "| " + text+"\n") - fileobj = open("log.txt", "w") + fileobj = open(os.path.join(homedir,ardentryst_dir, "log.txt" ), 'w') fileobj.writelines(src) def WS_PIC(pic): Index: play_level.py =================================================================== --- play_level.py +++ play_level.py 2009-07-21 09:22:06.000000000 -0400 @@ -26,6 +26,10 @@ from fade import * from helpers import * from mapping import bgfortheme, pbgfortheme, pfgfortheme, fallingobjstylefortheme, framesfalling, footstep_types +# +homedir = os.path.expanduser('~') +ardentryst_dir = ".ardentryst" + # Global values and hard-coded data here PLAYDEMO = False @@ -1583,17 +1587,17 @@ elif k == K_BACKSPACE and renaming: renameto = renameto[:-1] elif k == K_RETURN and renaming: - sfiles = os.listdir("Saves") + sfiles = os.listdir(os.path.join(homedir,ardentryst_dir,"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 = cPickle.load(open(os.path.join("Saves", game.savefilename),"r")) - os.rename(os.path.join("Saves", game.savefilename), os.path.join("Saves", renameto+".asf")) + tempgobj = cPickle.load(open(os.path.join(homedir,ardentryst_dir,"Saves", game.savefilename),"r")) + os.rename(os.path.join(homedir,ardentryst_dir,"Saves", game.savefilename), os.path.join(homedir,ardentryst_dir,"Saves", renameto+".asf")) tempgobj.savefilename = renameto + ".asf" - cPickle.dump(tempgobj, open(os.path.join("Saves", renameto+".asf"), "w")) + cPickle.dump(tempgobj, open(os.path.join(homedir,ardentryst_dir,"Saves", renameto+".asf"), "w")) game.savefilename = renameto + ".asf" renaming = False renameto = ""