Skip to content

Commit

Permalink
installer dry run mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Die4Ever committed Jun 24, 2023
1 parent bce9537 commit 8c23b16
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 26 deletions.
27 changes: 13 additions & 14 deletions installer/Install/Install.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def InstallVanilla(system:Path, settings:dict, speedupfix:bool):
else:
configs_dest = system
DXRandoini = configs_dest / (exename+'.ini')
DXRandoini.parent.mkdir(parents=True, exist_ok=True)
Mkdir(DXRandoini.parent, parents=True, exist_ok=True)

changes = {}
if DXRandoini.exists():
Expand All @@ -101,11 +101,11 @@ def InstallVanilla(system:Path, settings:dict, speedupfix:bool):
if changes:
b = defini_dest.read_bytes()
b = Config.ModifyConfig(b, changes, additions={})
defini_dest.write_bytes(b)
WriteBytes(defini_dest, b)

b = DXRandoini.read_bytes()
b = Config.ModifyConfig(b, changes, additions={})
DXRandoini.write_bytes(b)
WriteBytes(DXRandoini, b)

dxrroot = gameroot / 'DXRando'
(dxrroot / 'Maps').mkdir(exist_ok=True, parents=True)
Expand All @@ -123,7 +123,7 @@ def InstallVanilla(system:Path, settings:dict, speedupfix:bool):
def InstallLDDP(system:Path, settings:dict):
callback = settings.get('downloadcallback')
tempdir = Path(tempfile.gettempdir()) / 'dxrando'
tempdir.mkdir(exist_ok=True)
Mkdir(tempdir, exist_ok=True)
name = 'Lay_D_Denton_Project_1.1.zip'
temp = tempdir / name
if temp.exists():
Expand Down Expand Up @@ -151,8 +151,7 @@ def InstallLDDP(system:Path, settings:dict):
dest = mapsdir / name
else:
continue
with open(dest, 'wb') as out:
out.write(data)
WriteBytes(dest, data)
print(Path(f.filename).name, f.file_size)

print('done Installing LDDP to', system, '\n')
Expand All @@ -168,15 +167,15 @@ def InstallGMDX(system:Path, settings:dict, exename:str):
if confpath.exists():
b = confpath.read_bytes()
b = Config.ModifyConfig(b, changes, additions)
confpath.write_bytes(b)
WriteBytes(confpath, b)

confpath = game / exename / 'System' / 'gmdx.ini'
if confpath.exists():
b = confpath.read_bytes()
b = Config.ModifyConfig(b, changes, additions)
confpath.write_bytes(b)
WriteBytes(confpath, b)

CopyPackageFiles('GMDX', system.parent, ['GMDXRandomizer.u'])
CopyPackageFiles('GMDX', game, ['GMDXRandomizer.u'])


def InstallRevision(system:Path, settings:dict):
Expand All @@ -200,7 +199,7 @@ def CreateModConfigs(system:Path, settings:dict, modname:str, exename:str, in_pl
newexepath = system / (newexename+'.exe')
modpath = system.parent / (modname+'Randomizer')
mapspath = modpath / 'Maps'
mapspath.mkdir(exist_ok=True, parents=True)
Mkdir(mapspath, exist_ok=True, parents=True)
if not IsWindows():
in_place = True
if not in_place:
Expand Down Expand Up @@ -228,7 +227,7 @@ def ChangeModConfigs(system:Path, settings:dict, modname:str, exename:str, newex
if in_place:
newexename = exename
outconf = system / (newexename + 'Default.ini')
outconf.write_bytes(b)
WriteBytes(outconf, b)

confpath = system / (exename + '.ini')
if confpath.exists():
Expand All @@ -237,7 +236,7 @@ def ChangeModConfigs(system:Path, settings:dict, modname:str, exename:str, newex
outconf = system / (newexename + '.ini')
if in_place:
outconf = confpath
outconf.write_bytes(b)
WriteBytes(outconf, b)

# User inis
if in_place:
Expand All @@ -248,7 +247,7 @@ def ChangeModConfigs(system:Path, settings:dict, modname:str, exename:str, newex
outconf = system / (newexename + 'DefUser.ini')
if in_place:
outconf = confpath
outconf.write_bytes(b)
WriteBytes(outconf, b)

confpath = system / (exename + 'User.ini')
if confpath.exists():
Expand All @@ -257,4 +256,4 @@ def ChangeModConfigs(system:Path, settings:dict, modname:str, exename:str, newex
outconf = system / (newexename + 'User.ini')
if in_place:
outconf = confpath
outconf.write_bytes(b)
WriteBytes(outconf, b)
8 changes: 4 additions & 4 deletions installer/Install/MapVariants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path
import tempfile
from zipfile import ZipFile
from Install import MD5, DownloadFile
from Install import MD5, DownloadFile, Mkdir, WriteBytes

def InstallMirrors(mapsdir: Path, callback: callable, flavor:str):
print('\nInstallMirrors(', mapsdir, flavor, ')')
Expand All @@ -21,7 +21,7 @@ def InstallMirrors(mapsdir: Path, callback: callable, flavor:str):
print('unknown existing maps MD5:', totalmd5)

tempdir = Path(tempfile.gettempdir()) / 'dxrando'
tempdir.mkdir(exist_ok=True)
Mkdir(tempdir, exist_ok=True)
name = 'dx.mirrored.maps.zip'
if flavor == 'VMD':
name = 'dx.vmd.mirrored.maps.zip'
Expand All @@ -44,8 +44,8 @@ def InstallMirrors(mapsdir: Path, callback: callable, flavor:str):
continue
name = Path(f.filename).name
data = zip.read(f.filename)
with open(mapsdir / name, 'wb') as out:
out.write(data)
out = mapsdir / name
WriteBytes(out, data)
print(Path(f.filename).name, f.file_size)

print('done extracting to', mapsdir)
Expand Down
40 changes: 32 additions & 8 deletions installer/Install/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
import certifi
import ssl

dryrun = False
def SetDryrun(val):
global dryrun
dryrun = val

def GetDryrun() -> bool:
global dryrun
return dryrun

def IsWindows() -> bool:
return os.name == 'nt'

Expand Down Expand Up @@ -98,9 +107,9 @@ def CopyPackageFiles(modname:str, gameroot:Path, packages:list):

packages_path = GetPackagesPath(modname)

dxrandoroot.mkdir(exist_ok=True)
Mkdir(dxrandoroot, exist_ok=True)
dxrandosystem = dxrandoroot / 'System'
dxrandosystem.mkdir(exist_ok=True)
Mkdir(dxrandosystem, exist_ok=True)

# need to split our package files and organize them into different folders since these always have the same names
#packages.append('DXRandoCore.u')
Expand All @@ -123,24 +132,24 @@ def EngineDllFix(p:Path) -> bool:
print('skipping Engine.dll speedup fix, unrecognized md5 sum:', hex)
return False
dllbak = p / 'Engine.dll.bak'
dllbak.write_bytes(bytes)
WriteBytes(dllbak, bytes)
bytes = bytearray(bytes)
for i in range(0x12ADCC, 0x12ADCF + 1):
bytes[i] = 0
dll.write_bytes(bytes)
WriteBytes(dll, bytes)
return True


def ModifyConfig(defconfig:Path, config:Path, outdefconfig:Path, outconfig:Path, changes:dict):
print('ModifyConfig', defconfig, config, outdefconfig, outconfig)
bytes = defconfig.read_bytes()
bytes = Config.ModifyConfig(bytes, changes)
outdefconfig.write_bytes(bytes)
WriteBytes(outdefconfig, bytes)

if config.exists():
bytes = defconfig.read_bytes()
bytes = Config.ModifyConfig(bytes, changes)
outconfig.write_bytes(bytes)
WriteBytes(outconfig, bytes)


def CopyD3D10Renderer(system:Path):
Expand All @@ -152,22 +161,37 @@ def CopyD3D10Renderer(system:Path):

drvdir_source = thirdparty / 'd3d10drv'
drvdir_dest = system / 'd3d10drv'
drvdir_dest.mkdir(exist_ok=True)
Mkdir(drvdir_dest, exist_ok=True)
for f in drvdir_source.glob('*'):
CopyTo(f, drvdir_dest / f.name, True)


def Mkdir(dir:Path, parents=False, exist_ok=False):
if GetDryrun():
print("dryrun would've created folder", dir)
else:
dir.mkdir(parents=parents, exist_ok=exist_ok)

def WriteBytes(out:Path, data:bytes):
if GetDryrun():
print("dryrun would've written to", out)
else:
out.write_bytes(data)


def CopyTo(source:Path, dest:Path, silent:bool=False):
if not silent:
print('Copying', source, 'to', dest)
bytes = source.read_bytes()
dest.write_bytes(bytes)
WriteBytes(dest, bytes)


def MD5(bytes:bytes) -> str:
return hashlib.md5(bytes).hexdigest()


def DownloadFile(url, dest, callback):
# still do this on dryrun because it writes to temp?
sslcontext = ssl.create_default_context(cafile=certifi.where())
old_func = ssl._create_default_https_context
ssl._create_default_https_context = lambda : sslcontext # HACK
Expand Down
5 changes: 5 additions & 0 deletions installer/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import sys

import GUI.InstallerWindow
from Install import SetDryrun

parser = argparse.ArgumentParser(description='Deus Ex Randomizer')
parser.add_argument('--version', action="store_true", help='Output version')
parser.add_argument('--dryrun', action="store_true", help="Dry run, don't actually change anything")
#parser.add_argument('--verbose', action="store_true", help="Output way more to the console")
args = parser.parse_args()

Expand All @@ -16,4 +18,7 @@ def GetVersion():
print('Python version:', sys.version_info, file=sys.stderr)
sys.exit(0)

if args.dryrun:
SetDryrun(True)

GUI.InstallerWindow.main()

0 comments on commit 8c23b16

Please sign in to comment.