Categories
- Added categories and sub-categories - Added exception handler - Game-folders are now claimed before they're used
This commit is contained in:
parent
6082478c63
commit
077377efb6
@ -1,8 +1,21 @@
|
|||||||
|
#Preload Exception handler
|
||||||
|
import sys
|
||||||
|
def preloadExceptionHandler(exc_type, exc_value, tb):
|
||||||
|
import traceback
|
||||||
|
print("An error has occurred while initializing:")
|
||||||
|
traceback.print_exception(exc_type, exc_value, tb)
|
||||||
|
input("\nPress ENTER to exit.")
|
||||||
|
sys.exit(-1)
|
||||||
|
sys.excepthook = preloadExceptionHandler
|
||||||
|
|
||||||
|
#Imports and variables
|
||||||
import ctypes
|
import ctypes
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
import time
|
||||||
|
import stat
|
||||||
|
scriptPath = os.path.dirname(os.path.realpath(__file__))
|
||||||
appPath = sys.argv[1]
|
appPath = sys.argv[1]
|
||||||
appName = appPath.replace(os.path.dirname(appPath)+ "\\","")
|
appName = appPath.replace(os.path.dirname(appPath)+ "\\","")
|
||||||
originalAppPath = appPath + " - umlOriginal"
|
originalAppPath = appPath + " - umlOriginal"
|
||||||
@ -10,20 +23,59 @@ tmpAppPath = appPath + " - umlTemp"
|
|||||||
modPath = os.path.join(appPath,"umlMods")
|
modPath = os.path.join(appPath,"umlMods")
|
||||||
originalModPath = os.path.join(originalAppPath,"umlMods")
|
originalModPath = os.path.join(originalAppPath,"umlMods")
|
||||||
|
|
||||||
|
#Exception Handler
|
||||||
|
def openFileWithStandardApp(path):
|
||||||
|
# Windows
|
||||||
|
if os.name == "nt":
|
||||||
|
os.startfile(path)
|
||||||
|
# Macintosh
|
||||||
|
elif sys.platform == "darwin":
|
||||||
|
subprocess.call(['open', path])
|
||||||
|
# Generic Unix (X11)
|
||||||
|
else:
|
||||||
|
subprocess.call(['xdg-open', path])
|
||||||
|
|
||||||
|
def exceptionHandler(exc_type, exc_value, tb):
|
||||||
|
import traceback
|
||||||
|
while True:
|
||||||
|
clear()
|
||||||
|
print("An error has occurred:")
|
||||||
|
traceback.print_exception(exc_type, exc_value, tb)
|
||||||
|
choice = input("\nWould you like to log this exception? (y/n)\n")
|
||||||
|
if choice.lower() == "y":
|
||||||
|
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)
|
||||||
|
sys.excepthook = exceptionHandler
|
||||||
|
|
||||||
|
#Modloader
|
||||||
|
def cloneMods(modDir):
|
||||||
|
for root,dirs,files in walklevel(modDir,0):
|
||||||
|
for dir in dirs:
|
||||||
|
if dir[0] == "-": continue
|
||||||
|
if dir[0] == "[" and dir[-1:] == "]":
|
||||||
|
cloneMods(os.path.join(root,dir))
|
||||||
|
else:
|
||||||
|
cloneFolder(os.path.join(root,dir),tmpAppPath,True,False)
|
||||||
|
|
||||||
def loadMods(output = False):
|
def loadMods(output = False):
|
||||||
if areModsLoaded():
|
if areModsLoaded():
|
||||||
if unloadMods() == False:
|
if unloadMods() == False:
|
||||||
if output: print("Unloading mods failed!")
|
if output: print("Unloading mods failed!")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
claimFolder(appPath)
|
||||||
cloneFolder(appPath,tmpAppPath,False)
|
cloneFolder(appPath,tmpAppPath,False)
|
||||||
for root,dirs,files in walklevel(modPath,0):
|
cloneMods(modPath)
|
||||||
for dir in dirs:
|
|
||||||
cloneFolder(os.path.join(root,dir),tmpAppPath,True,False)
|
|
||||||
|
|
||||||
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("Mods have been loaded!")
|
||||||
return True
|
return True
|
||||||
@ -35,7 +87,7 @@ def unloadMods(output = False):
|
|||||||
|
|
||||||
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("Unloading mods successful.")
|
||||||
return True
|
return True
|
||||||
@ -71,6 +123,9 @@ def cloneFolder(src,dst,rpl,ignoreMods = True):
|
|||||||
else:
|
else:
|
||||||
os.link(fullFile,newFile)
|
os.link(fullFile,newFile)
|
||||||
|
|
||||||
|
def claimFolder(path):
|
||||||
|
os.chmod(path, 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)
|
||||||
assert os.path.isdir(some_dir)
|
assert os.path.isdir(some_dir)
|
||||||
@ -101,7 +156,6 @@ def checkUp():
|
|||||||
|
|
||||||
def mainMenu():
|
def mainMenu():
|
||||||
clear()
|
clear()
|
||||||
|
|
||||||
if areModsLoaded() == False:
|
if areModsLoaded() == False:
|
||||||
print("Welcome to Fier's Universal Modloader.")
|
print("Welcome to Fier's Universal Modloader.")
|
||||||
print("Mods are not loaded.")
|
print("Mods are not loaded.")
|
||||||
@ -129,6 +183,7 @@ def mainMenu():
|
|||||||
if choice == "2": unloadMods(True); input("Press ENTER to continue.")
|
if choice == "2": unloadMods(True); input("Press ENTER to continue.")
|
||||||
if choice == "3": openModsFolder()
|
if choice == "3": openModsFolder()
|
||||||
|
|
||||||
|
#Init
|
||||||
title("Fier's Universal Modloader: " +appName)
|
title("Fier's Universal Modloader: " +appName)
|
||||||
cleanUp()
|
cleanUp()
|
||||||
checkUp()
|
checkUp()
|
||||||
|
Loading…
Reference in New Issue
Block a user