Basic error correction

- Added basic error correction.
- Program now asks before setting up the game for mod-use
This commit is contained in:
Fierelier 2017-07-21 14:23:23 +02:00
parent 532db5bd15
commit e4569f1c57

View File

@ -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")
try:
errorFile = open(errorFilePath,"w")
fileCreated = True
try:
traceback.print_exception(exc_type, exc_value, tb, None, errorFile)
errorFile.close()
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)
elif choice.lower() == "n":
sys.exit(-1)
sys.excepthook = exceptionHandler
#Modloader
@ -160,7 +213,15 @@ def cleanUp():
def checkUp():
if areModsLoaded() == False:
if os.path.isdir(modPath) == False:
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()