tweaks may now be converted for an already installed system

This commit is contained in:
Fierelier 2019-10-11 08:52:03 +02:00
parent 63c90a163e
commit 9455194669
5 changed files with 103 additions and 2 deletions

1
.gitattributes vendored
View File

@ -1 +0,0 @@
*.reg text

5
.gitignore vendored
View File

@ -1,5 +1,8 @@
desktop.ini
*.iso
iso/*
tmp/*
bin/*
-bin/opus-nt
tweaks - converted/*
tweaksReversal - converted/*
!bin/opus-nt

19
apply-locally.bat Normal file
View File

@ -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

View File

@ -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
)

68
convert-to-local.py Normal file
View File

@ -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"))