From e4569f1c576ce544e68995ce30ec12d3d6b09394 Mon Sep 17 00:00:00 2001 From: Fierelier Date: Fri, 21 Jul 2017 14:23:23 +0200 Subject: [PATCH] Basic error correction - Added basic error correction. - Program now asks before setting up the game for mod-use --- UniversalModloader.py | 79 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 70 insertions(+), 9 deletions(-) diff --git a/UniversalModloader.py b/UniversalModloader.py index b3774fd..a07dc7d 100644 --- a/UniversalModloader.py +++ b/UniversalModloader.py @@ -36,22 +36,75 @@ def openFileWithStandardApp(path): else: subprocess.call(['xdg-open', path]) +def exceptionCleanup(): + success = True + logtext = "" + logtext = logtext + "Attempting cleanup.\n" + logtext = logtext + "Making folders visible...\n" + try: + ctypes.windll.kernel32.SetFileAttributesW(appPath,128) + ctypes.windll.kernel32.SetFileAttributesW(originalAppPath,128) + except Exception as e: + success = False + logtext = logtext + str(e) + "\n" + + logtext = logtext + "Unloading mods...\n" + try: + unloadMods() + except Exception as e: + success = False + logtext = logtext + str(e) + "\n" + + logtext = logtext + "Cleaning up temporary files...\n" + try: + cleanUp() + except Exception as e: + success = False + logtext = logtext + str(e) + "\n" + + if success == False: + logtext = logtext + "\nCleanup not fully successful. Please review the errors, and go to X for a guide on how to reset your game manually. Sorry for the inconvenience, I tried :(" + + return logtext + + def exceptionHandler(exc_type, exc_value, tb): import traceback while True: clear() - print("An error has occurred:") + print("An exception has occurred:") traceback.print_exception(exc_type, exc_value, tb) + cleanupLog = exceptionCleanup() + print("\n" +cleanupLog) choice = input("\nWould you like to log this exception? (y/n)\n") if choice.lower() == "y": + success = False + fileCreated = False errorFilePath = os.path.join(scriptPath,"error.log") - errorFile = open(errorFilePath,"w") - traceback.print_exception(exc_type, exc_value, tb, None, errorFile) - errorFile.close() - openFileWithStandardApp(errorFilePath) - sys.exit(-1) - elif choice.lower() == "n": - sys.exit(-1) + try: + errorFile = open(errorFilePath,"w") + fileCreated = True + + try: + traceback.print_exception(exc_type, exc_value, tb, None, errorFile) + errorFile.write("\n" +cleanupLog) + success = True + except: + input("Writing to errorlog-file failed. Press ENTER to continue.") + except: + input("Creating errorlog-file failed. Press ENTER to continue.") + + if fileCreated: errorFile.close() + if success: + try: + openFileWithStandardApp(errorFilePath) + except: + input("Opening errorlog-file failed. You can find it at '" +errorFilePath+ "'. Press ENTER to continue.") + elif choice.lower() != "n": + continue + + sys.exit(-1) + sys.excepthook = exceptionHandler #Modloader @@ -160,7 +213,15 @@ def cleanUp(): def checkUp(): if areModsLoaded() == False: if os.path.isdir(modPath) == False: - os.makedirs(modPath) + while True: + clear() + print("You selected the following path: '" +appPath+ "'") + choice = input("Do you wish to set up that folder for mod-use? (y/n)\n") + if choice == "y": + os.makedirs(modPath) + return + + if choice == "n": sys.exit(-1) def mainMenu(): clear()