Skip to content

Commit

Permalink
refactor get_mod_version_from_dll to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
tappi287 committed Feb 1, 2022
1 parent 2950c64 commit aa8566f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions app/mod/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from .base_mod_type import BaseModType
from .mod_utils import get_mod, get_available_mods, check_mod_data_dir, update_mod_data_dirs
from .mod_utils import get_mod, get_available_mods, check_mod_data_dir, update_mod_data_dirs, get_mod_version_from_dll
from .base_mod import BaseMod
from .fsr_mod import FsrMod
from .foveated_mod import FoveatedMod
from .vrperfkit_mod import VRPerfKitMod

__all__ = ['BaseMod', 'BaseModType', 'FsrMod', 'FoveatedMod', 'VRPerfKitMod',
'get_mod', 'get_available_mods', 'check_mod_data_dir', 'update_mod_data_dirs']
'get_mod', 'get_available_mods', 'check_mod_data_dir', 'update_mod_data_dirs', 'get_mod_version_from_dll']
27 changes: 3 additions & 24 deletions app/mod/base_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
from typing import Optional

import app.cfg
from app.app_settings import AppSettings
from app.cfg import BaseModCfgType, BaseModSettings
from app.mod import BaseModType, update_mod_data_dirs
from app.mod import BaseModType, update_mod_data_dirs, get_mod_version_from_dll


class BaseMod:
Expand Down Expand Up @@ -89,7 +88,7 @@ def _read_write_cfg(self, write: bool = False):
cfg_results.append(settings_read)

if settings_read:
version = self.get_mod_version_from_dll(self.engine_dll, self.TYPE)
version = get_mod_version_from_dll(self.engine_dll, self.TYPE)
self.manifest[self.VAR_NAMES['version']] = version or 'Unknown Version'
self.manifest[self.VAR_NAMES['settings']] = self.settings.to_js()

Expand Down Expand Up @@ -189,34 +188,14 @@ def _install_mod(self, org_engine_dll: Path):
return False
return True

@staticmethod
def get_mod_version_from_dll(engine_dll: Path, mod_type: int) -> Optional[str]:
if not engine_dll.exists():
return

file_hash = app.utils.get_file_hash(engine_dll.as_posix())
version_dict = dict()

if mod_type == BaseModType.fsr:
version_dict = AppSettings.open_vr_fsr_versions
elif mod_type == BaseModType.foveated:
version_dict = AppSettings.open_vr_foveated_versions
elif mod_type == BaseModType.vrp:
version_dict = AppSettings.vrperfkit_versions

for version, hash_str in version_dict.items():
if file_hash != hash_str:
continue
return version

def get_version(self):
results = list()
for engine_dll in self._update_engine_dll_paths():
if not engine_dll:
continue

try:
results.append(self.get_mod_version_from_dll(self.engine_dll, self.TYPE))
results.append(get_mod_version_from_dll(self.engine_dll, self.TYPE))
except Exception as e:
msg = f'Error reading dll version: {e}'
self.error = msg
Expand Down
23 changes: 22 additions & 1 deletion app/mod/mod_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from pathlib import Path, WindowsPath
from typing import Dict
from typing import Dict, Optional

import app.mod
from app.app_settings import AppSettings
from app.globals import get_data_dir
from app.mod import BaseModType
from app.util.utils import get_file_hash


def get_mod(manifest, mod_type):
Expand Down Expand Up @@ -52,3 +53,23 @@ def update_mod_data_dirs() -> Dict[int, str]:

AppSettings.mod_data_dirs.update(mod_dirs)
return mod_dirs


def get_mod_version_from_dll(engine_dll: Path, mod_type: int) -> Optional[str]:
if not engine_dll.exists():
return

file_hash = get_file_hash(engine_dll.as_posix())
version_dict = dict()

if mod_type == BaseModType.fsr:
version_dict = AppSettings.open_vr_fsr_versions
elif mod_type == BaseModType.foveated:
version_dict = AppSettings.open_vr_foveated_versions
elif mod_type == BaseModType.vrp:
version_dict = AppSettings.vrperfkit_versions

for version, hash_str in version_dict.items():
if file_hash != hash_str:
continue
return version

0 comments on commit aa8566f

Please sign in to comment.