From 1268c388b0a621fbe8ddbc38fd1889c9a040e814 Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Sat, 9 May 2026 22:46:41 +0900 Subject: [PATCH] feat: version update logic --- dzgui/api/mods.py | 27 +++++++++++++++++++++++++++ dzgui/api/steam.py | 2 +- dzgui/managers/connection.py | 20 ++++++++++++++------ dzgui/managers/mods.py | 2 +- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/dzgui/api/mods.py b/dzgui/api/mods.py index 4ff646b..19929a7 100644 --- a/dzgui/api/mods.py +++ b/dzgui/api/mods.py @@ -173,3 +173,30 @@ def get_mod_dir_size(path: Path) -> int: elif i.is_dir(): size += get_mod_dir_size(i) return size + + +def version_file_to_dict(file: Path) -> dict[str, str]: + versions = file.read_text().splitlines() + d: dict[str, str] = {} + for version in versions: + line = version.split(",") + mod = line[0] + stamp = line[1] + d[mod] = stamp + return d + + +def update_signatures( + mods: list[tuple[str, str, int, int]], version_file: Path +) -> None: + d = version_file_to_dict(version_file) + for _title, mod, stamp, size in mods: + d[mod] = str(stamp) + versions: list[str] = [] + for k, v in d.items(): + row = ",".join([k, v]) + versions.append(row) + + with open(version_file, "w") as f: + for version in versions: + f.write(f"{version}\n") diff --git a/dzgui/api/steam.py b/dzgui/api/steam.py index 1cb6e5a..c906587 100644 --- a/dzgui/api/steam.py +++ b/dzgui/api/steam.py @@ -25,7 +25,7 @@ def get_local_signatures(version_file: Path) -> dict[str, int]: for line in lines: line = line.split(",") _id = line[0] - _hash = line[1] + _hash = int(line[1]) hashes[_id] = _hash return hashes diff --git a/dzgui/managers/connection.py b/dzgui/managers/connection.py index 2da6244..296bb79 100644 --- a/dzgui/managers/connection.py +++ b/dzgui/managers/connection.py @@ -18,7 +18,12 @@ from dzgui.api.steam import ( get_needs_update, ) -from dzgui.api.mods import get_mod_dir_size, get_local_mod_ids, get_local_mod_path +from dzgui.api.mods import ( + get_mod_dir_size, + get_local_mod_ids, + get_local_mod_path, + update_signatures, +) from dzgui.const.constants import ( APP_NAME, APPID_DAYZ, @@ -236,7 +241,7 @@ class ConnectionManager: dialog = ExceptionDialog(self.controller, server_timeout) dialog.run() - def connect_steam(self) -> None: + def _connect_steam(self) -> None: print(self.record.ip) print(self.record.gameport) print(self.appid) @@ -250,8 +255,9 @@ class ConnectionManager: # TODO: add to history file and list store @call_on_thread("Waiting for Steam to update mods") - def update_mods(self, raise_window: bool) -> None: + def _update_mods(self, raise_window: bool) -> None: # NOTE: fast enqueue all mods in auto mode + prefs = self.controller.get_prefs() for title, mod, stamp, size in self.missing_mods: # TODO: boolean cancel button on threadman dialog sets event inside threadman # TODO: check for early cancel event via sigint @@ -277,8 +283,10 @@ class ConnectionManager: time.sleep(1) # TODO: update version file + update_signatures(self.missing_mods, prefs.paths.version) + # TODO: get config path or just push steam path directly - rebuild_symlinks(self.controller.get_prefs().paths.config) + rebuild_symlinks(prefs.paths.config) # TODO: update tree checkmarks when finished # TODO: make this internal to preconnect page func = StoredFunc(self.controller.update_status) @@ -286,6 +294,6 @@ class ConnectionManager: def update_and_connect(self, raise_window: bool) -> None: if len(self.missing_mods) > 0: - self.update_mods(raise_window) + self._update_mods(raise_window) else: - self.connect_steam() + self._connect_steam() diff --git a/dzgui/managers/mods.py b/dzgui/managers/mods.py index f43e669..c73f489 100644 --- a/dzgui/managers/mods.py +++ b/dzgui/managers/mods.py @@ -92,7 +92,7 @@ class ModManager: if model is None: return None tree_iter = model.get_iter(tree_path) - mod = model.get_value(tree_iter, 2)[0] + mod = model.get_value(tree_iter, 2) return mod, tree_iter def delete_single_mod(self, tree_path: Gtk.TreePath) -> Gtk.TreeIter | None: