offline-minecraft-launcher/offline-minecraft-launcher.py
2022-05-18 02:30:32 +02:00

103 lines
2.4 KiB
Python

#!/usr/bin/env python3
import sys
mainScript = ""
oldexcepthook = sys.excepthook
def newexcepthook(type,value,traceback):
try:
with open(p(omlPath,"error-mainScript.py"),"w",encoding="utf-8") as ms:
ms.write(mainScript)
except:
pass
oldexcepthook(type,value,traceback)
input("Press ENTER to quit.")
sys.excepthook = newexcepthook
import os
p = os.path.join
pUp = os.path.dirname
s = False
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
s = os.path.realpath(sys.executable)
else:
s = os.path.realpath(__file__)
sp = pUp(s)
import configparser
import subprocess
import json
import hashlib
import platform
import copy
import shutil
omlPath = p(sp,"oml")
def runCode(str, lcs = False, description = "loose-code"):
if lcs == False: lcs = {}
code = compile(str,description,"exec")
exec(code,globals(),lcs)
return lcs
def runScript(sf, lcs = False):
if lcs == False: lcs = {}
code = False
with open(sf,"r",encoding="utf-8") as script:
code = script.read()
runCode(code,lcs,sf)
return lcs
def readGenericListFile(path):
rtn = []
with open(path,"r",encoding="utf-8") as listf:
for line in listf:
line = line.split("#",1)[0]
line = line.strip(" \t\r\n")
if line == "": continue
rtn.append(line)
return rtn
def readFile(file,decode = "utf-8"):
fileh = False
fileh = open(file,"rb")
data = fileh.read()
fileh.close()
if decode == False: return data
return data.decode(decode)
def readJsonFile(file):
fileh = open(file,"r")
data = fileh.read()
fileh.close()
return json.loads(data)
def main():
print("Running modules...")
for root,dirs,files in os.walk(p(omlPath,"modules")):
for file in files:
sfile = file.rsplit(".",1)
if len(sfile) < 2: continue
if sfile[1] != "modlist": continue
ffile = p(root,file)
lfile = ffile.replace(p(omlPath,"modules") + os.path.sep,"",1)
print("> " +lfile)
for mod in readGenericListFile(ffile):
print(">> " +mod+ " ...")
runScript(p(omlPath,"modules",mod))
break
print("")
print(colored(colorama.Fore.GREEN,"Creating main-script from stages..."))
global mainScript
mainScript = ""
for stage in readGenericListFile(p(omlPath,"stages","stages.txt")):
mainScript += "# --- STAGE: " +stage + "\r\n"
with open(p(omlPath,"stages",stage),"r",encoding="utf-8") as sf:
mainScript += sf.read()
mainScript += "\r\n\r\n"
print(colored(colorama.Fore.MAGENTA,"\nRunning main-script..."))
runCode(mainScript,False,"main-script")
main()