From 94551946699279b8d56a720f1b2e2ba151f3bdc2 Mon Sep 17 00:00:00 2001 From: Fierelier Date: Fri, 11 Oct 2019 08:52:03 +0200 Subject: [PATCH] tweaks may now be converted for an already installed system --- .gitattributes | 1 - .gitignore | 5 ++- apply-locally.bat | 19 +++++++++ bin/opus-nt/applyTweakLocally.bat | 12 ++++++ convert-to-local.py | 68 +++++++++++++++++++++++++++++++ 5 files changed, 103 insertions(+), 2 deletions(-) delete mode 100644 .gitattributes create mode 100644 apply-locally.bat create mode 100644 bin/opus-nt/applyTweakLocally.bat create mode 100644 convert-to-local.py diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index f16ea7f..0000000 --- a/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -*.reg text \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9396778..593220c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ +desktop.ini *.iso iso/* tmp/* bin/* --bin/opus-nt \ No newline at end of file +tweaks - converted/* +tweaksReversal - converted/* +!bin/opus-nt \ No newline at end of file diff --git a/apply-locally.bat b/apply-locally.bat new file mode 100644 index 0000000..df011a6 --- /dev/null +++ b/apply-locally.bat @@ -0,0 +1,19 @@ +@echo off +setlocal EnableDelayedExpansion +cd /d %~dp0 +set execName=%~n0 +set tweakPath=%cd%\tweaks - converted +for /d %%i in ("bin\*") do set path=%cd%\%%i;!path! + +echo. +echo WARNING! +echo this will apply opus-nt's tweaks to your currently running system. +pause + +for /d %%t in ("%tweakpath%\*") do ( + call "applyTweakLocally.bat" "%%t" +) + +echo. +echo done. restart your system to see all the changes. +pause \ No newline at end of file diff --git a/bin/opus-nt/applyTweakLocally.bat b/bin/opus-nt/applyTweakLocally.bat new file mode 100644 index 0000000..5f9076f --- /dev/null +++ b/bin/opus-nt/applyTweakLocally.bat @@ -0,0 +1,12 @@ +echo. +echo -- applying tweak: %~n1 -- + +if exist %1\"reg" for /R %1\"reg" %%r in (*.reg) do ( + echo importing "%%~nr%%~xr"... + reg import "%%r" +) + +if exist %1\"wim" ( + echo applying system files... + xcopy %1\"wim" "%SystemDrive%\" /e /y +) \ No newline at end of file diff --git a/convert-to-local.py b/convert-to-local.py new file mode 100644 index 0000000..f42751d --- /dev/null +++ b/convert-to-local.py @@ -0,0 +1,68 @@ +import os +import shutil +sp = os.path.dirname(os.path.realpath(__file__)) +p = os.path.join + +regRep = "HKEY_LOCAL_MACHINE\\OPUS-NT_TMP" + +def walklevel(some_dir, level=0): + some_dir = some_dir.rstrip(os.path.sep) + assert os.path.isdir(some_dir) + num_sep = some_dir.count(os.path.sep) + for root, dirs, files in os.walk(some_dir): + yield root, dirs, files + num_sep_this = root.count(os.path.sep) + if num_sep + level <= num_sep_this: + del dirs[:] + +def convertFolder(dirIn): + # loop: tweaks + for tweakRoot,tweaks,_ in walklevel(dirIn): + for tweak in tweaks: + fullTweak = p(tweakRoot,tweak) + + # loop: tweak types + for tweakTypeRoot,tweakTypes,_ in walklevel(fullTweak): + for tweakType in tweakTypes: + fullTweakType = p(tweakTypeRoot,tweakType) + + # reg files + if tweakType.lower() == "reg": + for regTypeRoot,regTypes,_ in walklevel(fullTweakType): + for regType in regTypes: + fullRegType = p(regTypeRoot,regType) + + for regRoot,_,regFiles in walklevel(fullRegType): + for regFile in regFiles: + fullReg = p(regRoot,regFile) + fullRegOut = fullReg.replace(dirIn,dirIn + " - converted") + fullRegOutDir = os.path.dirname(fullRegOut) + + if not os.path.isdir(fullRegOutDir): os.makedirs(fullRegOutDir) + regFh = open(fullReg,"r") + regText = regFh.read() + regFh.close() + + replaceWith = regRep + if regType.lower() == "software": replaceWith = "HKEY_LOCAL_MACHINE\\SOFTWARE" + if regType.lower() == "system": replaceWith = "HKEY_LOCAL_MACHINE\\SYSTEM" + if regType.lower() == "ntuser": + regFhOut = open(fullRegOut+ ".defaultUser" + ".reg","w",encoding="utf-8") + regFhOut.write(regText.replace(regRep,"HKEY_USERS\\.DEFAULT")) + regFhOut.close() + replaceWith = "HKEY_CURRENT_USER" + + regTextOld = regText + regText = regText.replace(regRep,replaceWith) + if regText == regTextOld: + print("warning, " +tweak+ "/" +regType+ "/" +regFile+ ": not modified") + + regFhOut = open(fullRegOut,"w",encoding="utf-8") + regFhOut.write(regText) + regFhOut.close() + + if tweakType.lower() == "wim": + shutil.copytree(fullTweakType,fullTweakType.replace(dirIn,dirIn + " - converted")) + +convertFolder(p(sp,"tweaks")) +convertFolder(p(sp,"tweaksReversal")) \ No newline at end of file