From b3a9598718974f27e71139e19db714d570fd043f Mon Sep 17 00:00:00 2001 From: Fierelier Date: Wed, 8 Jun 2022 15:25:12 +0200 Subject: [PATCH] Allow application to online systems --- api/opusnt.py | 61 ++++++++++++++++--- .../disable file open warnings/modscript.py | 2 +- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/api/opusnt.py b/api/opusnt.py index 6715c4a..ca3f6f0 100644 --- a/api/opusnt.py +++ b/api/opusnt.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 - +dummyMode = False if __name__ == "__main__": print("this is supposed to be imported") exit() @@ -8,7 +8,28 @@ print("opus-nt api says hello world") import os import subprocess import winreg -p = os.path.join +def p(*args): + args = list(args) + index = 0 + length = len(args) + while index < length: + arg = args[index] + arg = arg.replace("/",os.path.sep) + arg = arg.replace("\\",os.path.sep) + if index != 0: arg = arg.lstrip(os.path.sep) + arg = arg.rstrip(os.path.sep) + while os.path.sep + os.path.sep in arg: + arg = arg.replace(os.path.sep + os.path.sep,os.path.sep) + + if arg == "": + del args[index] + length -= 1 + continue + + args[index] = arg + index += 1 + + return os.path.sep.join(args) target = { "type": False, # "wim", "offline" - whether to target a wim file or an offline installed windows @@ -21,9 +42,16 @@ tmpPath = "tmp" regTmpPath = "HKEY_LOCAL_MACHINE\\opus-nt_" def runReg(cmd,check = True): + if target["type"] == "online": + cmd[1] = applyRegmap(cmd[1]) + if cmd[0] == "unload": + if not cmd[1].startswith(regTmpPath): return cmd = ["reg"] + cmd try: - subprocess.run(cmd,stdout=subprocess.DEVNULL,check=True) + if dummyMode: + print(cmd) + else: + subprocess.run(cmd,stdout=subprocess.DEVNULL,check=True) except Exception as e: if check == True: raise e @@ -44,6 +72,7 @@ def getModlist(path): return modList def addFiles(path): + if dummyMode: return if target["type"] == "offline": for root,dirs,files in os.walk(path): for file in dirs: @@ -75,7 +104,7 @@ def addFiles(path): ],check=True,stdout=subprocess.DEVNULL) def readyFile(path): - if target["type"] == "offline": return + if target["type"] in ["offline","online"]: return if target["type"] == "wim": subprocess.run([ @@ -86,6 +115,7 @@ def readyFile(path): ],check=True,stdout=subprocess.DEVNULL) def renameFile(path,newpath): + if dummyMode: return if target["type"] == "offline": os.rename(filePath(path),filePath(newpath)) @@ -97,6 +127,7 @@ def renameFile(path,newpath): ],check=True,stdout=subprocess.DEVNULL) def removeFile(path): + if dummyMode: return if target["type"] == "offline": os.remove(filePath(path)) @@ -129,10 +160,17 @@ def fileExists(path): return True def filePath(path): - if target["type"] == "offline": return p(target["path"],path) + if target["type"] in ["offline","online"]: return p(target["path"],path) if target["type"] == "wim": return p(tmpPath,path) -def mountReg(path,regFile): +def mountReg(path,regFile,regList,reg): + if target["type"] == "online": + try: + runReg(["load",path,regFile]) + except Exception: + if reg.startswith("user-"): + del regList[reg] + return runReg(["load",path,regFile]) def unmountReg(path): @@ -140,6 +178,7 @@ def unmountReg(path): def getVersion(hkey,SOFTWARE): versionData = {} + if target["type"] == "online": SOFTWARE = "software" key = winreg.OpenKey(hkey,SOFTWARE + "\\Microsoft\\Windows NT\\CurrentVersion") isTen = False @@ -168,7 +207,6 @@ def getVersion(hkey,SOFTWARE): else: # this sucks versionData["architecture"] = "ia64" - global target target["version"] = versionData def getMaxIndex(): @@ -190,7 +228,14 @@ def getMaxIndex(): return def regQueryKeys(rp): + if target["type"] == "online": rp = applyRegmap(rp) output = subprocess.check_output(["reg","query",rp,"/f","*","/k"]).decode("utf-8","ignore") output = output.split("\r\n") output = output[1:-2] - return output \ No newline at end of file + return output + +def applyRegmap(rp): + for path in target["regmap"]: + if rp.startswith(path): + return rp.replace(path,target["regmap"][path],1) + return rp \ No newline at end of file diff --git a/mods/[all]/disable file open warnings/modscript.py b/mods/[all]/disable file open warnings/modscript.py index 67e391a..35e90ae 100644 --- a/mods/[all]/disable file open warnings/modscript.py +++ b/mods/[all]/disable file open warnings/modscript.py @@ -1 +1 @@ -opusnt.runReg(["add",opusnt.regTmpPath + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Attachments","/v","SaveZoneInformation","/t","REG_DWORD","/d","1","/f"]) +opusnt.runReg(["add",opusnt.regTmpPath + "software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Attachments","/v","SaveZoneInformation","/t","REG_DWORD","/d","1","/f"])