blorp
- Changed mod-location - Added status messages - Simplified exception handler (needs testing) - Folder claiming actually works now
This commit is contained in:
parent
45318f36c1
commit
0bc37d2f72
@ -38,34 +38,33 @@ def openFileWithStandardApp(path):
|
|||||||
|
|
||||||
def exceptionCleanup():
|
def exceptionCleanup():
|
||||||
success = True
|
success = True
|
||||||
logtext = ""
|
print("Attempting cleanup.")
|
||||||
logtext = logtext + "Attempting cleanup.\n"
|
print("\nMaking folders visible...")
|
||||||
logtext = logtext + "Making folders visible...\n"
|
|
||||||
try:
|
try:
|
||||||
ctypes.windll.kernel32.SetFileAttributesW(appPath,128)
|
ctypes.windll.kernel32.SetFileAttributesW(appPath,128)
|
||||||
ctypes.windll.kernel32.SetFileAttributesW(originalAppPath,128)
|
ctypes.windll.kernel32.SetFileAttributesW(originalAppPath,128)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
success = False
|
success = False
|
||||||
logtext = logtext + str(e) + "\n"
|
print(str(e))
|
||||||
|
|
||||||
logtext = logtext + "Unloading mods...\n"
|
print("\nUnloading mods...")
|
||||||
try:
|
try:
|
||||||
unloadMods()
|
unloadMods()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
success = False
|
success = False
|
||||||
logtext = logtext + str(e) + "\n"
|
print(str(e))
|
||||||
|
|
||||||
logtext = logtext + "Cleaning up temporary files...\n"
|
print("\nCleaning up temporary files...")
|
||||||
try:
|
try:
|
||||||
cleanUp()
|
cleanUp()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
success = False
|
success = False
|
||||||
logtext = logtext + str(e) + "\n"
|
print(str(e))
|
||||||
|
|
||||||
if success == False:
|
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):
|
def logError(logFilePath,textList):
|
||||||
logFile = False
|
logFile = False
|
||||||
@ -86,44 +85,11 @@ def logError(logFilePath,textList):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def exceptionHandler(exc_type, exc_value, tb):
|
def exceptionHandler(exc_type, exc_value, tb):
|
||||||
import traceback
|
|
||||||
clear()
|
clear()
|
||||||
|
|
||||||
print("An error occurred, trying to revert everything...")
|
print("An error occurred, trying to revert everything...")
|
||||||
|
exceptionCleanup()
|
||||||
cleanupSuccess,cleanupLog = exceptionCleanup()
|
input()
|
||||||
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)
|
|
||||||
|
|
||||||
sys.excepthook = exceptionHandler
|
sys.excepthook = exceptionHandler
|
||||||
|
|
||||||
@ -135,6 +101,7 @@ def cloneMods(modDir):
|
|||||||
if dir[0] == "[" and dir[-1:] == "]":
|
if dir[0] == "[" and dir[-1:] == "]":
|
||||||
cloneMods(os.path.join(root,dir))
|
cloneMods(os.path.join(root,dir))
|
||||||
else:
|
else:
|
||||||
|
print("Applying Mod: " +dir)
|
||||||
if os.path.isfile(os.path.join(root,dir,"uml_installscript.py")) == True:
|
if os.path.isfile(os.path.join(root,dir,"uml_installscript.py")) == True:
|
||||||
file = open(os.path.join(root,dir,"uml_installscript.py"))
|
file = open(os.path.join(root,dir,"uml_installscript.py"))
|
||||||
exec(file.read(),globals(),locals())
|
exec(file.read(),globals(),locals())
|
||||||
@ -148,15 +115,20 @@ def loadMods(output = False):
|
|||||||
if output: print("Unloading mods failed!")
|
if output: print("Unloading mods failed!")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
print("Claiming app folder...")
|
||||||
claimFolder(appPath)
|
claimFolder(appPath)
|
||||||
|
print("Claiming mod folder...")
|
||||||
|
claimFolder(modPath)
|
||||||
|
print("Cloning app folder...")
|
||||||
cloneFolder(appPath,tmpAppPath,False)
|
cloneFolder(appPath,tmpAppPath,False)
|
||||||
|
print("Cloning mods...")
|
||||||
cloneMods(modPath)
|
cloneMods(modPath)
|
||||||
|
|
||||||
os.rename(appPath,originalAppPath)
|
os.rename(appPath,originalAppPath)
|
||||||
os.rename(tmpAppPath,appPath)
|
os.rename(tmpAppPath,appPath)
|
||||||
ctypes.windll.kernel32.SetFileAttributesW(originalAppPath,2)
|
ctypes.windll.kernel32.SetFileAttributesW(originalAppPath,2)
|
||||||
|
|
||||||
if output: print("Mods have been loaded!")
|
if output: print("\nMods have been loaded!")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def unloadMods(output = False):
|
def unloadMods(output = False):
|
||||||
@ -164,11 +136,12 @@ def unloadMods(output = False):
|
|||||||
if output: print("Mods are already unloaded.")
|
if output: print("Mods are already unloaded.")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
print("Removing cloned app folder...")
|
||||||
shutil.rmtree(appPath)
|
shutil.rmtree(appPath)
|
||||||
os.rename(originalAppPath,appPath)
|
os.rename(originalAppPath,appPath)
|
||||||
ctypes.windll.kernel32.SetFileAttributesW(appPath,128)
|
ctypes.windll.kernel32.SetFileAttributesW(appPath,128)
|
||||||
|
|
||||||
if output: print("Unloading mods successful.")
|
if output: print("\nUnloading mods successful.")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def openModsFolder():
|
def openModsFolder():
|
||||||
@ -183,7 +156,7 @@ def areModsLoaded():
|
|||||||
|
|
||||||
return False
|
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):
|
for root,dirs,files in os.walk(src):
|
||||||
newRoot = root.replace(src,dst)
|
newRoot = root.replace(src,dst)
|
||||||
if ignoreMods == True:
|
if ignoreMods == True:
|
||||||
@ -206,6 +179,12 @@ def cloneFolder(src,dst,rpl,ignoreMods = True, isMod = False):
|
|||||||
|
|
||||||
def claimFolder(path):
|
def claimFolder(path):
|
||||||
os.chmod(path, stat.S_IRWXU| stat.S_IRWXG| stat.S_IRWXO)
|
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):
|
def walklevel(some_dir, level=1):
|
||||||
some_dir = some_dir.rstrip(os.path.sep)
|
some_dir = some_dir.rstrip(os.path.sep)
|
||||||
@ -231,17 +210,17 @@ def cleanUp():
|
|||||||
shutil.rmtree(tmpAppPath)
|
shutil.rmtree(tmpAppPath)
|
||||||
|
|
||||||
def checkUp():
|
def checkUp():
|
||||||
if areModsLoaded() == False:
|
if os.path.isdir(modPath) == False:
|
||||||
if os.path.isdir(modPath) == False:
|
while True:
|
||||||
while True:
|
clear()
|
||||||
clear()
|
print("You selected the following path: '" +appPath+ "'")
|
||||||
print("You selected the following path: '" +appPath+ "'")
|
choice = input("Do you wish to set up that folder for mod-use? (y/n)\n")
|
||||||
choice = input("Do you wish to set up that folder for mod-use? (y/n)\n")
|
if choice == "y":
|
||||||
if choice == "y":
|
os.makedirs(modPath)
|
||||||
os.makedirs(modPath)
|
ctypes.windll.kernel32.SetFileAttributesW(modPath,2)
|
||||||
return
|
return
|
||||||
|
|
||||||
if choice == "n": sys.exit(-1)
|
if choice == "n": sys.exit(-1)
|
||||||
|
|
||||||
def mainMenu():
|
def mainMenu():
|
||||||
clear()
|
clear()
|
||||||
@ -300,8 +279,8 @@ def setupVariables():
|
|||||||
appName = appPath.replace(os.path.dirname(appPath)+ "\\","")
|
appName = appPath.replace(os.path.dirname(appPath)+ "\\","")
|
||||||
originalAppPath = appPath + " - umlOriginal"
|
originalAppPath = appPath + " - umlOriginal"
|
||||||
tmpAppPath = appPath + " - umlTemp"
|
tmpAppPath = appPath + " - umlTemp"
|
||||||
modPath = os.path.join(appPath,"umlMods")
|
modPath = os.path.join(appPath + " - umlMods")
|
||||||
originalModPath = os.path.join(originalAppPath,"umlMods")
|
originalModPath = modPath
|
||||||
|
|
||||||
#Init
|
#Init
|
||||||
setupVariables()
|
setupVariables()
|
||||||
@ -309,5 +288,6 @@ title("Fier's Universal Modloader: " +appName)
|
|||||||
|
|
||||||
cleanUp()
|
cleanUp()
|
||||||
checkUp()
|
checkUp()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
mainMenu()
|
mainMenu()
|
Loading…
Reference in New Issue
Block a user