Skip to content

Commit

Permalink
installer output to log.txt file
Browse files Browse the repository at this point in the history
  • Loading branch information
Die4Ever committed Jun 25, 2023
1 parent 1579130 commit df5e681
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
dist
build
installer/3rdParty
installer/log.txt

# Visual Studio 2015 user specific files
.vs/
Expand Down
12 changes: 6 additions & 6 deletions installer/GUI/InstallerWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ def initWindow(self):
self.SetShowHiddenFiles()
p = fd.askopenfilename(title="Find plain DeusEx.exe", filetypes=filetypes, initialdir=initdir)
if not p:
print('no file selected')
info('no file selected')
sys.exit(0)

p = Path(p)
print(p)
info(p)
assert p.name.lower() == 'deusex.exe'
assert p.parent.name.lower() == 'system'
self.exe = p

flavors = Install.DetectFlavors(self.exe)
print(flavors)
info(flavors)

self.font = font.Font(size=14)
self.linkfont = font.Font(size=12, underline=True)
Expand Down Expand Up @@ -130,15 +130,15 @@ def Install(self):
except Exception as e:
self.root.title('DXRando Installer Error!')
self.root.update()
print('\n\nError!')
print(str(e) + '\n\n' + traceback.format_exc())
info('\n\nError!')
info(str(e) + '\n\n' + traceback.format_exc())
messagebox.showinfo('Error!', str(e) + '\n\n' + traceback.format_exc(5))
exit(1)

def _Install(self):
self.root.title('DXRando Installing...')
self.root.update()
print(self.speedupfixval.get())
info(self.speedupfixval.get())
self.installButton["state"]='disabled'

flavors = {}
Expand Down
5 changes: 3 additions & 2 deletions installer/GUI/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib import Path
import traceback
from idlelib.tooltip import Hovertip
from Install import info

class GUIBase:
def __init__(self):
Expand All @@ -32,7 +33,7 @@ def resize(self,event):
self.width = event.width
self.height = event.height
except Exception as e:
print('ERROR: in resize:', e)
info('ERROR: in resize:', e)

def newInput(self, cls, label:str, tooltip:str, row:int, *args, **kargs):
label = Label(self.win,text=label,width=22,height=2,font=self.font, anchor='e', justify='left')
Expand Down Expand Up @@ -112,7 +113,7 @@ def left(self,event):
def errordialog(title, msg, e=None):
if e:
msg += '\n' + str(e) + '\n\n' + traceback.format_exc()
print(title, '\n', msg)
info(title, '\n', msg)
messagebox.showerror(title, msg)


Expand Down
5 changes: 3 additions & 2 deletions installer/Install/Config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path
import re
import Install

# use regex, because configparser doesn't support multiple entries with the same key, like Paths
get_sections = re.compile(
Expand Down Expand Up @@ -51,10 +52,10 @@ def _ModifyConfig(text:str, changes:dict, additions:dict) -> str:
for k in leftovers.keys():
outtext += '\r\n\r\n[' + k + ']\r\n'
if k in changes:
print(changes[k])
Install.debug(changes[k])
outtext += _AddConfigVals('', changes[k])
if k in additions:
print(additions[k])
Install.debug(additions[k])
outtext += _AddConfigVals('', additions[k])
return outtext

Expand Down
13 changes: 6 additions & 7 deletions installer/Install/Install.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def UnattendedInstall(installpath:str, downloadmirrors):

assert p.exists(), str(p)

callback = lambda a,b,c, status='Downloading' : print(status, a,b,c)
callback = lambda a,b,c, status='Downloading' : debug(status, a,b,c)
flavors = DetectFlavors(p)
settings = {}
for f in flavors:
Expand All @@ -43,7 +43,7 @@ def Install(exe:Path, flavors:dict, speedupfix:bool) -> dict:
system:Path = exe.parent
assert system.name.lower() == 'system'

print('Installing flavors:', flavors, speedupfix, exe)
info('Installing flavors:', flavors, speedupfix, exe)

for(f, settings) in flavors.items():
ret={}
Expand All @@ -67,8 +67,7 @@ def Install(exe:Path, flavors:dict, speedupfix:bool) -> dict:
if speedupfix:
EngineDllFix(system)

if GetVerbose():
print("Install returning", flavors)
debug("Install returning", flavors)

return flavors

Expand Down Expand Up @@ -182,9 +181,9 @@ def InstallLDDP(system:Path, settings:dict):
else:
continue
WriteBytes(dest, data)
print(Path(f.filename).name, f.file_size)
debug(Path(f.filename).name, f.file_size)

print('done Installing LDDP to', system, '\n')
info('done Installing LDDP to', system, '\n')
temp.unlink()


Expand Down Expand Up @@ -253,7 +252,7 @@ def CreateModConfigs(system:Path, settings:dict, modname:str, exename:str, in_pl

def ChangeModConfigs(system:Path, settings:dict, modname:str, exename:str, newexename:str, changes:dict, additions:dict, in_place:bool=False):
# inis
print('ChangeModConfigs', system, modname, exename, newexename, in_place)
info('ChangeModConfigs', system, modname, exename, newexename, in_place)
confpath = system / (exename + 'Default.ini')
b = confpath.read_bytes()
b = Config.ModifyConfig(b, changes, additions)
Expand Down
20 changes: 10 additions & 10 deletions installer/Install/MapVariants.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
from pathlib import Path
import tempfile
from zipfile import ZipFile
from Install import MD5, DownloadFile, Mkdir, WriteBytes
from Install import MD5, DownloadFile, Mkdir, WriteBytes, debug, info

def InstallMirrors(mapsdir: Path, callback: callable, flavor:str):
print('\nInstallMirrors(', mapsdir, flavor, ')')
info('\nInstallMirrors(', mapsdir, flavor, ')')
callback(0, 1, 1, 'Checking Maps')
totalmd5 = Md5Maps(mapsdir)
callback(1, 1, 1, 'Checking Maps')

if totalmd5 == 'd41d8cd98f00b204e9800998ecf8427e': # no map files found
print('no mirrored maps found')
info('no mirrored maps found')
elif totalmd5 == '265d1d8bef836074c28303c9326f5d35': # mirrored maps v0.7
print('overwriting mirrored maps v0.7')
info('overwriting mirrored maps v0.7')
elif totalmd5 == '8d06331fdc7fcc6904c316bbb94a4598': # v0.8
print('overwriting mirrored maps v0.8')
info('overwriting mirrored maps v0.8')
elif totalmd5 == '5551a03906a0f5470e2f9bd8724d59a6':
print('overwriting mirrored maps v0.9')
info('overwriting mirrored maps v0.9')
elif totalmd5 == '4a2b4cb284de0799ce0f111cfd8170fc': # v0.9.1
print('already have mirrored maps v0.9.1')
info('already have mirrored maps v0.9.1')
return
else:
print('unknown existing maps MD5:', totalmd5)
info('unknown existing maps MD5:', totalmd5)

tempdir = Path(tempfile.gettempdir()) / 'dxrando'
Mkdir(tempdir, exist_ok=True)
Expand Down Expand Up @@ -49,9 +49,9 @@ def InstallMirrors(mapsdir: Path, callback: callable, flavor:str):
data = zip.read(f.filename)
out = mapsdir / name
WriteBytes(out, data)
print(Path(f.filename).name, f.file_size)
debug(Path(f.filename).name, f.file_size)

print('done extracting to', mapsdir)
info('done extracting to', mapsdir)
temp.unlink()

def Md5Maps(mapsdir: Path) -> str:
Expand Down
58 changes: 36 additions & 22 deletions installer/Install/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@ def GetDryrun() -> bool:
def IsWindows() -> bool:
return os.name == 'nt'

try:
outfile = open('log.txt', 'w')
except Exception as e:
print('ERROR writing to log.txt file', e)
outfile = None

def debug(*args):
global outfile
if GetDryrun():
print(*args)
if outfile:
print(*args, file=outfile)

def info(*args):
global outfile
print(*args)
if outfile:
print(*args, file=outfile)


def GetConfChanges(modname):
changes = {
Expand Down Expand Up @@ -104,8 +123,7 @@ def _DetectFlavors(system:Path):

if (game / 'VMDSim').is_dir():
flavors = ['Vanilla? Madder.']# VMD seems like it can only exist by itself
if GetVerbose():
print("_DetectFlavors", flavors)
debug("_DetectFlavors", flavors)
return flavors

if (system / 'DeusEx.u').exists():
Expand All @@ -115,9 +133,9 @@ def _DetectFlavors(system:Path):
if md5_name == 'vanilla':
is_vanilla = True
elif md5_name:
print("found DeusEx.u", md5_name, vanilla_md5)
info("found DeusEx.u", md5_name, vanilla_md5)
else:
print('unknown MD5 for DeusEx.u', vanilla_md5)
info('unknown MD5 for DeusEx.u', vanilla_md5)

if (game / 'GMDXv9').is_dir():
flavors.append('GMDX v9')
Expand All @@ -127,13 +145,12 @@ def _DetectFlavors(system:Path):
flavors.append('GMDX v10')
if (system / 'HX.u').exists():
if not is_vanilla:
print('WARNING: DeusEx.u file is not vanilla! This can cause issues with HX')
info('WARNING: DeusEx.u file is not vanilla! This can cause issues with HX')
flavors.append('HX')
if (game / 'Revision').is_dir():
flavors.append('Revision')

if GetVerbose():
print("_DetectFlavors", flavors)
debug("_DetectFlavors", flavors)
return flavors


Expand Down Expand Up @@ -165,10 +182,10 @@ def EngineDllFix(p:Path) -> bool:
bytes = dll.read_bytes()
hex = MD5(bytes)
if hex == '1f23c5a7e63c79457bd4c24cd14641b0':
print('Engine.dll speedup fix already applied')
info('Engine.dll speedup fix already applied')
return True
if hex != '0af95a7328719b1d4eb26374aad8ae9a':
print('skipping Engine.dll speedup fix, unrecognized md5 sum:', hex)
info('skipping Engine.dll speedup fix, unrecognized md5 sum:', hex)
return False
dllbak = p / 'Engine.dll.bak'
WriteBytes(dllbak, bytes)
Expand All @@ -180,7 +197,7 @@ def EngineDllFix(p:Path) -> bool:


def ModifyConfig(defconfig:Path, config:Path, outdefconfig:Path, outconfig:Path, changes:dict):
print('ModifyConfig', defconfig, config, outdefconfig, outconfig)
info('ModifyConfig', defconfig, config, outdefconfig, outconfig)
bytes = defconfig.read_bytes()
bytes = Config.ModifyConfig(bytes, changes)
WriteBytes(outdefconfig, bytes)
Expand All @@ -193,7 +210,7 @@ def ModifyConfig(defconfig:Path, config:Path, outdefconfig:Path, outconfig:Path,

def CopyD3D10Renderer(system:Path):
thirdparty = GetSourcePath() / '3rdParty'
print('CopyD3D10Renderer from', thirdparty, ' to ', system)
info('CopyD3D10Renderer from', thirdparty, ' to ', system)

CopyTo(thirdparty/'d3d10drv.dll', system/'d3d10drv.dll', True)
CopyTo(thirdparty/'D3D10Drv.int', system/'D3D10Drv.int', True)
Expand All @@ -207,32 +224,29 @@ def CopyD3D10Renderer(system:Path):

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

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


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


def MD5(bytes:bytes) -> str:
ret = hashlib.md5(bytes).hexdigest()
if GetVerbose():
print("MD5 of", len(bytes), " bytes is", ret)
debug("MD5 of", len(bytes), " bytes is", ret)
return ret


Expand All @@ -242,8 +256,8 @@ def DownloadFile(url, dest, callback):
old_func = ssl._create_default_https_context
ssl._create_default_https_context = lambda : sslcontext # HACK

print('\n\ndownloading', url, 'to', dest)
info('\n\ndownloading', url, 'to', dest)
urllib.request.urlretrieve(url, dest, callback) # "legacy interface"
print('done downloading ', url, 'to', dest)
info('done downloading ', url, 'to', dest)

ssl._create_default_https_context = old_func
14 changes: 7 additions & 7 deletions installer/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import traceback

import GUI.InstallerWindow
from Install import SetDryrun, SetVerbose
from Install import SetDryrun, SetVerbose, info
from Install.Install import UnattendedInstall

parser = argparse.ArgumentParser(description='Deus Ex Randomizer')
Expand All @@ -19,8 +19,8 @@ def GetVersion():
return 'v0.3'

if args.version:
print('DXRando Installer version:', GetVersion(), file=sys.stderr)
print('Python version:', sys.version_info, file=sys.stderr)
info('DXRando Installer version:', GetVersion())
info('Python version:', sys.version_info)
sys.exit(0)

if args.verbose:
Expand All @@ -34,9 +34,9 @@ def GetVersion():
UnattendedInstall(args.path, args.downloadmirrors)
sys.exit(0)
except Exception as e:
print('\n\nError!')
print(e, '\n')
print(traceback.format_exc())
print('falling back to manual install')
info('\n\nError!')
info(e, '\n')
info(traceback.format_exc())
info('falling back to manual install')

GUI.InstallerWindow.main()

0 comments on commit df5e681

Please sign in to comment.