From aa8566feda1dbb277ca727fbbdc1ecdf6da5eb33 Mon Sep 17 00:00:00 2001 From: tappi287 Date: Tue, 1 Feb 2022 21:08:00 +0100 Subject: [PATCH] refactor get_mod_version_from_dll to utils --- app/mod/__init__.py | 4 ++-- app/mod/base_mod.py | 27 +++------------------------ app/mod/mod_utils.py | 23 ++++++++++++++++++++++- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/app/mod/__init__.py b/app/mod/__init__.py index d66f30b..25611d3 100644 --- a/app/mod/__init__.py +++ b/app/mod/__init__.py @@ -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'] diff --git a/app/mod/base_mod.py b/app/mod/base_mod.py index b7c6115..981d031 100644 --- a/app/mod/base_mod.py +++ b/app/mod/base_mod.py @@ -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: @@ -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() @@ -189,26 +188,6 @@ 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(): @@ -216,7 +195,7 @@ def get_version(self): 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 diff --git a/app/mod/mod_utils.py b/app/mod/mod_utils.py index 45e77d7..89473c9 100644 --- a/app/mod/mod_utils.py +++ b/app/mod/mod_utils.py @@ -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): @@ -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