- Changed mod-location
- Added status messages
- Simplified exception handler (needs testing)
- Folder claiming actually works now
This commit is contained in:
Fierelier 2017-12-17 05:34:03 +01:00
parent 45318f36c1
commit 0bc37d2f72

View File

@ -38,34 +38,33 @@ def openFileWithStandardApp(path):
def exceptionCleanup():
success = True
logtext = ""
logtext = logtext + "Attempting cleanup.\n"
logtext = logtext + "Making folders visible...\n"
print("Attempting cleanup.")
print("\nMaking folders visible...")
try:
ctypes.windll.kernel32.SetFileAttributesW(appPath,128)
ctypes.windll.kernel32.SetFileAttributesW(originalAppPath,128)
except Exception as e:
success = False
logtext = logtext + str(e) + "\n"
print(str(e))
logtext = logtext + "Unloading mods...\n"
print("\nUnloading mods...")
try:
unloadMods()
except Exception as e:
success = False
logtext = logtext + str(e) + "\n"
print(str(e))
logtext = logtext + "Cleaning up temporary files...\n"
print("\nCleaning up temporary files...")
try:
cleanUp()
except Exception as e:
success = False
logtext = logtext + str(e) + "\n"
print(str(e))
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 :("
print("\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 success,logtext
return success
def logError(logFilePath,textList):
logFile = False
@ -86,44 +85,11 @@ def logError(logFilePath,textList):
return True
def exceptionHandler(exc_type, exc_value, tb):
import traceback
clear()
print("An error occurred, trying to revert everything...")
cleanupSuccess,cleanupLog = exceptionCleanup()
logFile = os.path.join(scriptPath,"error.log")
logSuccess = logError(logFile,[
"An exception has occurred:",
traceback.format_exc(),
"",
cleanupLog
])
if cleanupSuccess == True:
while True:
clear()
print("An error occured, game has been reset to default.")
print("C) Continue")
if logSuccess == True: print("S) Show more info")
choice = input("Choice: ")
if choice.lower() == "c": return
if logSuccess == True:
if choice.lower() == "s": openFileWithStandardApp(logFile)
else:
clear()
print("An error occured and error-correction failed. This is a major exception.\n")
if logSuccess == True:
print("You might need to reset some stuff by yourself; we printed a report into '" +logFile+ "' which will help you resolve this issue, this file will be opened for you automagically after you exit.")
input("\nPress ENTER to exit.")
openFileWithStandardApp(logFile)
sys.exit(-1)
else:
print("You might need to reset some stuff by yourself; we tried printing a report, but failed. Please check out X for help, we will open that website for you automagically after you exit.")
input("\nPress ENTER to exit.")
sys.exit(-1)
exceptionCleanup()
input()
sys.excepthook = exceptionHandler
@ -135,6 +101,7 @@ def cloneMods(modDir):
if dir[0] == "[" and dir[-1:] == "]":
cloneMods(os.path.join(root,dir))
else:
print("Applying Mod: " +dir)
if os.path.isfile(os.path.join(root,dir,"uml_installscript.py")) == True:
file = open(os.path.join(root,dir,"uml_installscript.py"))
exec(file.read(),globals(),locals())
@ -148,15 +115,20 @@ def loadMods(output = False):
if output: print("Unloading mods failed!")
return False
print("Claiming app folder...")
claimFolder(appPath)
print("Claiming mod folder...")
claimFolder(modPath)
print("Cloning app folder...")
cloneFolder(appPath,tmpAppPath,False)
print("Cloning mods...")
cloneMods(modPath)
os.rename(appPath,originalAppPath)
os.rename(tmpAppPath,appPath)
ctypes.windll.kernel32.SetFileAttributesW(originalAppPath,2)
if output: print("Mods have been loaded!")
if output: print("\nMods have been loaded!")
return True
def unloadMods(output = False):
@ -164,11 +136,12 @@ def unloadMods(output = False):
if output: print("Mods are already unloaded.")
return True
print("Removing cloned app folder...")
shutil.rmtree(appPath)
os.rename(originalAppPath,appPath)
ctypes.windll.kernel32.SetFileAttributesW(appPath,128)
if output: print("Unloading mods successful.")
if output: print("\nUnloading mods successful.")
return True
def openModsFolder():
@ -183,7 +156,7 @@ def areModsLoaded():
return False
def cloneFolder(src,dst,rpl,ignoreMods = True, isMod = False):
def cloneFolder(src,dst,rpl,ignoreMods = True, isMod = False):
for root,dirs,files in os.walk(src):
newRoot = root.replace(src,dst)
if ignoreMods == True:
@ -206,6 +179,12 @@ def cloneFolder(src,dst,rpl,ignoreMods = True, isMod = False):
def claimFolder(path):
os.chmod(path, stat.S_IRWXU| stat.S_IRWXG| stat.S_IRWXO)
for root,dirs,files in os.walk(path):
for dir in dirs:
os.chmod(os.path.join(root,dir), stat.S_IRWXU| stat.S_IRWXG| stat.S_IRWXO)
for file in files:
os.chmod(os.path.join(root,file), stat.S_IRWXU| stat.S_IRWXG| stat.S_IRWXO)
def walklevel(some_dir, level=1):
some_dir = some_dir.rstrip(os.path.sep)
@ -231,17 +210,17 @@ def cleanUp():
shutil.rmtree(tmpAppPath)
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 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)
ctypes.windll.kernel32.SetFileAttributesW(modPath,2)
return
if choice == "n": sys.exit(-1)
if choice == "n": sys.exit(-1)
def mainMenu():
clear()
@ -300,8 +279,8 @@ def setupVariables():
appName = appPath.replace(os.path.dirname(appPath)+ "\\","")
originalAppPath = appPath + " - umlOriginal"
tmpAppPath = appPath + " - umlTemp"
modPath = os.path.join(appPath,"umlMods")
originalModPath = os.path.join(originalAppPath,"umlMods")
modPath = os.path.join(appPath + " - umlMods")
originalModPath = modPath
#Init
setupVariables()
@ -309,5 +288,6 @@ title("Fier's Universal Modloader: " +appName)
cleanUp()
checkUp()
while True:
mainMenu()
mainMenu()