From 1d5959549f0ca0bf9328ca90a709e7d11183cd0e Mon Sep 17 00:00:00 2001 From: Die4Ever Date: Thu, 28 Mar 2024 08:48:46 -0500 Subject: [PATCH] installer smarter GetVersion() --- installer/GUI/InstallerWindow.py | 2 +- installer/Install/__init__.py | 33 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/installer/GUI/InstallerWindow.py b/installer/GUI/InstallerWindow.py index 0afc561ae..bd0076fea 100644 --- a/installer/GUI/InstallerWindow.py +++ b/installer/GUI/InstallerWindow.py @@ -15,7 +15,7 @@ def initWindow(self): self.width = 350 self.height = 500 self.lastprogress = '' - self.root.title("Deus Ex Randomizer Installer " + GetVersion()) + self.root.title("Deus Ex Randomizer " + GetVersion() + " Installer") dxvk_default = CheckVulkan()# this takes a second or so ogl2_default = dxvk_default or not IsWindows() diff --git a/installer/Install/__init__.py b/installer/Install/__init__.py index 15a437ad5..3db6b2c6c 100644 --- a/installer/Install/__init__.py +++ b/installer/Install/__init__.py @@ -31,6 +31,7 @@ def info(*args): import certifi import ssl import subprocess + import re except Exception as e: info('ERROR: importing', e) raise @@ -56,8 +57,38 @@ def GetDryrun() -> bool: def IsWindows() -> bool: return os.name == 'nt' +version = None def GetVersion(): - return 'v2.6' # TODO: make this automatic + global version + if version: + return version + + p = GetPackagesPath('vanilla') / 'DeusEx.u' + assert p.exists() + data = p.read_bytes() + + i = data.find(b'class DXRVersion extends Info;') + data = data[i:] + i = data.find(b'////// you probably don\'t need to touch the stuff below') + data = data[:i] + + i = data.find(b'static function CurrentVersion(') + CurrentVersion = data[i:] + i = CurrentVersion.find(b'}') + CurrentVersion = CurrentVersion[:i].decode('iso_8859_1') + m = re.search(r'major=(\d+);\s+minor=(\d+);\s+patch=(\d+);\s+build=(\d+);', CurrentVersion, flags=re.MULTILINE) + version = 'v' + m.group(1) + '.' + m.group(2) + '.' + m.group(3) + '.' + m.group(4) + + i = data.find(b'static function string VersionString(') + VersionString = data[i:] + i = VersionString.find(b'}') + VersionString = VersionString[:i].decode('iso_8859_1') + + m = re.search(r'status = "(.*)";', VersionString, flags=re.MULTILINE) + if m and m.group(1): + version += ' ' + m.group(1) + + return version def CheckVulkan() -> bool: if not IsWindows():