diff --git a/dzgui/managers/connection.py b/dzgui/managers/connection.py index ee72e17..a4e0fd1 100644 --- a/dzgui/managers/connection.py +++ b/dzgui/managers/connection.py @@ -47,6 +47,12 @@ if TYPE_CHECKING: logger = logging.getLogger(APP_NAME) +@dataclass(slots=True, frozen=True) +class SteamProcess: + name: str + is_running: bool + + @dataclass(slots=True, frozen=True) class Prerequisites: name: str @@ -59,9 +65,10 @@ class Prerequisites: available_space: float passworded: bool dayz_running: bool - steam_running: bool + steam_proc: SteamProcess mods: list[str] foreground_cmd: str | None + game_mode: bool class ConnectionManager: @@ -118,7 +125,8 @@ class ConnectionManager: local_version = "0.0.0" binary_missing = True - remote_mods: list[str, str, str] = [] + prefs = self.controller.get_prefs() + remote_mods: list[list[str]] = [] if res.is_modded(): try: remote_mods = self._query_modlist(record) @@ -129,9 +137,14 @@ class ConnectionManager: return hashes = get_remote_signatures(self.remote_mod_ids) - version_file = self.controller.get_prefs().paths.version + version_file = prefs.paths.version self.missing_mods = get_needs_update(version_file, hashes) + # TODO: walk through missing mods and update remote_mods store + for mod in remote_mods: + if any(mod[1] in tuple for tuple in self.missing_mods): + mod[2] = "Needs updating" + if local_version is not None: pefile_path = PeFile.get_pefile_path(steam_path, info.game_id) total, used, free = shutil.disk_usage(pefile_path) @@ -141,9 +154,15 @@ class ConnectionManager: free_mib = format_mib(required_size) dayz_running = is_dayz_running() - steam_running = is_steam_running() - self.foreground_cmd = self.controller.get_prefs().foreground_cmd + client_name = self.controller.get_steam_client_name() + client = self.controller.query_config(Preferences.CLIENT) + running = is_steam_running(client) + steam_proc = SteamProcess(client_name, running) + # /home/USER/.var/app/com.valvesoftware.Steam + + self.foreground_cmd = prefs.foreground_cmd + game_mode = prefs.is_game_mode prereqs = Prerequisites( name=info.server_name, @@ -156,9 +175,10 @@ class ConnectionManager: available_space=free_mib, passworded=info.password_protected, dayz_running=dayz_running, - steam_running=steam_running, + steam_proc=steam_proc, mods=remote_mods, foreground_cmd=self.foreground_cmd, # TODO: change to bool + game_mode=game_mode, ) func = StoredFunc(self.controller.open_connection_assistant, prereqs) @@ -261,7 +281,7 @@ class ConnectionManager: rebuild_symlinks(self.controller.get_prefs().paths.config) # TODO: update version file - # TODO: update tree checkmarks + # TODO: update tree checkmarks when finished func = StoredFunc( self.controller.update_status, "All mods updated.", mark_finished=True ) diff --git a/dzgui/strings/server_mods.py b/dzgui/strings/server_mods.py index c1a3106..c652fac 100644 --- a/dzgui/strings/server_mods.py +++ b/dzgui/strings/server_mods.py @@ -1,4 +1,4 @@ mod = "Mod" mod_id = "ID" -installed = "Installed" +up_to_date = "Up to date" modlist = "Modlist" diff --git a/dzgui/views/pages/options.py b/dzgui/views/pages/options.py index 3bd54c0..65d6292 100644 --- a/dzgui/views/pages/options.py +++ b/dzgui/views/pages/options.py @@ -49,6 +49,7 @@ class Options(Gtk.Box): ) self.controller = controller + self.controller.register_widget("options", self) emitter = controller.get_emitter() emitter.connect("api_change_failed", self._on_api_change_failed) @@ -207,6 +208,11 @@ class Options(Gtk.Box): self.scrollable.add(grid) self.add(self.scrollable) + def get_client_name(self) -> str: + model = self.client_combo.get_model() + ind = self.client_combo.get_active() + return model[ind][0] + def block_text_entry(self) -> None: for entry in self.steam_entry, self.bm_entry: entry.set_position(-1) diff --git a/dzgui/views/pages/preconnect.py b/dzgui/views/pages/preconnect.py index fb6db0e..250d265 100644 --- a/dzgui/views/pages/preconnect.py +++ b/dzgui/views/pages/preconnect.py @@ -145,20 +145,6 @@ class PreConnectionAssistant(Gtk.ScrolledWindow): ) self.progress_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=15) self.progress_box.add(self.mod_count) - # self.cancel = Gtk.Button( - # label=preconnect.cancel, - # halign=Gtk.Align.START, - # hexpand=True, - # margin_bottom=5, - # margin_top=5, - # ) - # self.progress_box.add(self.cancel) - # self.cancel.connect("clicked", self._on_cancel_clicked) - # self.cancel.set_visible(False) - - # TODO: live count of remaining downloads - # "Steam is downloading: {mod_name}" - # mention whether manual or auto mod is active self.scrolled = Gtk.ScrolledWindow() self.scrolled.add(self.tree) @@ -175,7 +161,6 @@ class PreConnectionAssistant(Gtk.ScrolledWindow): self.tree_frame = HeadingFrame(self.tree_box, preconnect.mods) # TODO: abstract into components - # TODO: strings self.warning_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.warning_tree = MaskedTree(WARNING) @@ -226,9 +211,6 @@ class PreConnectionAssistant(Gtk.ScrolledWindow): if event.keyval == Gdk.KEY_Escape: self.back.emit("clicked") - # def _on_cancel_clicked(self, button: Gtk.Button) -> None: - # print("user canceled") - def _on_ok_clicked(self, button: Gtk.Button) -> None: # TODO: cancel mod downloads # sets some kind of global event listener @@ -248,6 +230,9 @@ class PreConnectionAssistant(Gtk.ScrolledWindow): warnings: list[str] = [] errors: list[str] = [] + # TODO: check availability of currently selected steam cmd + + """Errors""" if prereqs.binary_missing: errors.append( f"Remote server is running the build '{prereqs.build}', but it is not installed." @@ -262,6 +247,17 @@ class PreConnectionAssistant(Gtk.ScrolledWindow): errors.append( f"Need to update {required_pretty} MiB of mods, but installation path only has {available_pretty} MiB." ) + if len(prereqs.mods) > 0 and prereqs.game_mode: + errors.append("Use Desktop Mode to download mods on Steam Deck") + + print(prereqs.steam_proc) + if prereqs.steam_proc.is_running is False: + client = prereqs.steam_proc.name + errors.append( + f"'{client}' is set as the default Steam client, but it either not installed or not running." + ) + + """Warnings""" if prereqs.passworded: warnings.append( "Protected: you will be prompted for a password when connecting to this server." @@ -270,10 +266,6 @@ class PreConnectionAssistant(Gtk.ScrolledWindow): warnings.append( "It looks like DayZ is already running in the background. Exit DayZ before connecting." ) - if prereqs.steam_running is False: - warnings.append( - "It looks like Steam is not running. Launch Steam before connecting." - ) self.add_warnings(warnings) self.add_errors(errors) @@ -319,8 +311,6 @@ class PreConnectionAssistant(Gtk.ScrolledWindow): def update_mod(self, text: str, mark_finished: bool = False) -> None: self.mod_count.set_label(text) - # if mark_finished: - # self.cancel.set_visible(False) def add_errors(self, errors: list[str]) -> None: self.error_tree.extend(errors) diff --git a/dzgui/views/trees/tree_server_mods.py b/dzgui/views/trees/tree_server_mods.py index edeba08..e815c85 100644 --- a/dzgui/views/trees/tree_server_mods.py +++ b/dzgui/views/trees/tree_server_mods.py @@ -32,7 +32,7 @@ class ServerModTreeView(ContextMixin, TreeView): # type: ignore columns = [ server_mods.mod, server_mods.mod_id, - server_mods.installed, + server_mods.up_to_date, ] for i, column_title in enumerate(columns): renderer = Gtk.CellRendererText(ellipsize=Pango.EllipsizeMode.END)