mirror of
https://github.com/aclist/dztui.git
synced 2026-08-28 10:47:15 +02:00
Merge branch 'dzgui7' into fix/update-symlinks
This commit is contained in:
commit
65c159505f
@ -10,7 +10,6 @@ from shlex import shlex
|
||||
from pathlib import Path
|
||||
|
||||
from dzgui.init.prereqs import has_steam_client
|
||||
from dzgui.api.mods import _hash
|
||||
from dzgui.const.constants import (
|
||||
APPID_DAYZ,
|
||||
APP_NAME,
|
||||
@ -58,6 +57,9 @@ def get_steam_paths() -> list[tuple[Path, str]]:
|
||||
|
||||
|
||||
def concat_mods(mods: list[str]) -> str:
|
||||
# TODO: circular import workaround
|
||||
from dzgui.api.mods import _hash
|
||||
|
||||
hashes = []
|
||||
for mod in mods:
|
||||
md5sum = _hash(mod)
|
||||
@ -170,8 +172,10 @@ def launch_offline(
|
||||
"-skipintro",
|
||||
f"-name={name}",
|
||||
f"-mod={symlinks}",
|
||||
f"-mission={mission}",
|
||||
]
|
||||
if len(mission) > 0:
|
||||
arg = f"-mission={mission}"
|
||||
params.append(arg)
|
||||
proc = subprocess.run([*client_args, *params])
|
||||
return proc.returncode
|
||||
|
||||
|
||||
@ -3,6 +3,8 @@ import shlex
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from dzgui.const.boilerplate import config_boilerplate
|
||||
|
||||
|
||||
"""
|
||||
Convert legacy dztuirc to config.json
|
||||
@ -89,4 +91,8 @@ def rc2json(file: Path) -> str:
|
||||
keys["ip_list"] = ips
|
||||
keys["use_miles"] = False
|
||||
keys["start_tab"] = 0
|
||||
# NOTE: workaround for DZGUI 6 logic (see #375)
|
||||
for key in config_boilerplate.keys():
|
||||
if key not in keys:
|
||||
keys[key] = config_boilerplate[key]
|
||||
return json.dumps(keys, indent=2)
|
||||
|
||||
@ -4,7 +4,8 @@ UDP_PORT = 27016
|
||||
VM_FILE = "/proc/sys/vm/max_map_count"
|
||||
MIN_COUNT = 1048576
|
||||
|
||||
RATE_LIMIT_THRESHOLD = 3
|
||||
API_RATE_LIMIT = 1
|
||||
CLIENT_RATE_LIMIT = 3
|
||||
REQUEST_TIMEOUT = 10
|
||||
|
||||
APPNAME_DAYZ = "DayZ"
|
||||
|
||||
@ -172,3 +172,7 @@ class Emitter(GObject.GObject):
|
||||
@GObject.Signal(flags=GObject.SignalFlags.RUN_LAST, arg_types=())
|
||||
def invalid_custom_mods(self) -> None:
|
||||
pass
|
||||
|
||||
@GObject.Signal(flags=GObject.SignalFlags.RUN_LAST, arg_types=())
|
||||
def all_mods_synched(self) -> None:
|
||||
pass
|
||||
|
||||
@ -23,7 +23,7 @@ from dzgui.managers.contextmenu import ContextMenuManager
|
||||
from dzgui.managers.notes import NoteManager
|
||||
from dzgui.model.servers import ServerModelManager
|
||||
from dzgui.util.diag import write_diagnostic
|
||||
from dzgui.util.format import format_player_count
|
||||
from dzgui.util.format import format_exception, format_player_count
|
||||
from dzgui.util.open_links import open_user_workshop, open_workshop_page
|
||||
from dzgui.views.dialogs.filepicker import FilePicker
|
||||
from dzgui.views.dialogs.generic import ExceptionDialog
|
||||
@ -203,7 +203,9 @@ class Controller(GObject.GObject):
|
||||
try:
|
||||
# TODO: where to put config file check
|
||||
self.mediator.grid.notebook.settings.populate_settings()
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
msg = format_exception(e)
|
||||
logger.critical(msg)
|
||||
return
|
||||
case ButtonType.MODS:
|
||||
self.load_mods()
|
||||
|
||||
@ -25,17 +25,17 @@ from dzgui.api.mods import (
|
||||
update_signatures,
|
||||
)
|
||||
from dzgui.const.constants import (
|
||||
API_RATE_LIMIT,
|
||||
APP_NAME,
|
||||
APPID_DAYZ,
|
||||
APPID_DAYZ_EXP,
|
||||
APPNAME_DAYZ,
|
||||
APPNAME_DAYZ_EXP_HUMAN,
|
||||
RATE_LIMIT_THRESHOLD,
|
||||
)
|
||||
from dzgui.const.enum import NotebookPage, Preferences
|
||||
from dzgui.init.proc import is_dayz_running, is_steam_running
|
||||
from dzgui.managers.threading import call_on_thread, StoredFunc, ThreadingManager
|
||||
from dzgui.strings.dialogs import waiting_for_launch, waiting_for_mods
|
||||
from dzgui.strings.dialogs import waiting_for_launch, waiting_for_mods, waiting_for_directories
|
||||
from dzgui.strings.server_mods import checkmark, resync
|
||||
from dzgui.util.format import format_mib
|
||||
from dzgui.util.strings import dialog, server_timeout
|
||||
@ -276,7 +276,6 @@ class ConnectionManager:
|
||||
self.thread_man.set_cleanup_func(func)
|
||||
return
|
||||
|
||||
self.thread_man.show_cancel(False)
|
||||
self.thread_man.update_dialog(waiting_for_launch)
|
||||
while True:
|
||||
# FIXME: cancel should not be visible here per setting above
|
||||
@ -303,8 +302,9 @@ class ConnectionManager:
|
||||
if self.controller.is_cancel_pending():
|
||||
return
|
||||
subscribe(key, int(mod))
|
||||
time.sleep(RATE_LIMIT_THRESHOLD)
|
||||
time.sleep(API_RATE_LIMIT)
|
||||
|
||||
self.thread_man.update_dialog(waiting_for_directories)
|
||||
for title, mod, stamp, size in self.missing_mods:
|
||||
mod_path = self.workshop / mod
|
||||
|
||||
@ -322,8 +322,12 @@ class ConnectionManager:
|
||||
time.sleep(1)
|
||||
|
||||
update_signatures(self.missing_mods, prefs.paths.version)
|
||||
# TODO: just push steam path directly
|
||||
rebuild_symlinks(prefs.paths.config)
|
||||
|
||||
# NOTE: update table status in main loop
|
||||
self.thread_man.update_emitter("all_mods_synched")
|
||||
|
||||
# TODO: just push steam path directly
|
||||
self._connect_steam(menu_only)
|
||||
|
||||
@call_on_thread(waiting_for_mods, show_cancel=True)
|
||||
|
||||
@ -12,10 +12,10 @@ from dzgui.api.mods import (
|
||||
remove_stale_signatures,
|
||||
)
|
||||
from dzgui.const.constants import (
|
||||
API_RATE_LIMIT,
|
||||
APP_NAME,
|
||||
APPID_DAYZ,
|
||||
APPID_DAYZ_EXP,
|
||||
RATE_LIMIT_THRESHOLD,
|
||||
)
|
||||
from dzgui.const.enum import Preferences
|
||||
from dzgui.managers.threading import call_on_thread, StoredFunc, ThreadingManager
|
||||
@ -116,6 +116,7 @@ class ModManager:
|
||||
for mod, _iter in mods:
|
||||
self.unsub_atomic_mod(mod)
|
||||
self.thread_man.increment_dialog()
|
||||
time.sleep(API_RATE_LIMIT)
|
||||
|
||||
iters = [_iter for mod, _iter in mods]
|
||||
func = StoredFunc(self._on_mods_unsubbed, iters)
|
||||
@ -143,7 +144,7 @@ class ModManager:
|
||||
symlink.unlink()
|
||||
except PeFile.AppNotInstalledError:
|
||||
pass
|
||||
time.sleep(RATE_LIMIT_THRESHOLD)
|
||||
time.sleep(API_RATE_LIMIT)
|
||||
|
||||
def _on_mods_unsubbed(self, iters: list[Gtk.TreeIter]) -> None:
|
||||
if self.store is None:
|
||||
|
||||
@ -81,6 +81,11 @@ class ThreadingManager:
|
||||
def set_job_count(self, jobs: int) -> None:
|
||||
self.jobs = jobs
|
||||
|
||||
def update_emitter(self, signal: str) -> None:
|
||||
if self.controller:
|
||||
emitter = self.controller.get_emitter()
|
||||
GLib.idle_add(lambda: emitter.emit(signal))
|
||||
|
||||
def update_dialog(self, msg: str) -> None:
|
||||
GLib.idle_add(lambda: self.wait_dialog.update_text(msg))
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
waiting_for_launch = "Waiting for DayZ to launch"
|
||||
waiting_for_mods = "Waiting for Steam to update mods"
|
||||
waiting_for_mods = "Queueing up mods (step 1/2)"
|
||||
waiting_for_directories = "Steam is staging mods (step 2/2)"
|
||||
|
||||
fetching_update = "Fetching update"
|
||||
failed_to_update = "Failed to update DZGUI executable"
|
||||
|
||||
@ -10,6 +10,7 @@ warnings = "Warnings"
|
||||
errors = "Errors"
|
||||
mods = "Mods"
|
||||
total_mods = "Total mods: "
|
||||
up_to_date = "All mods are up to date."
|
||||
all_updated = "All mods updated."
|
||||
"If you recently installed {build} or moved it to a different drive, "
|
||||
"restart Steam to allow these changes to synchronize, then try again."
|
||||
|
||||
@ -392,7 +392,7 @@ class Options(Gtk.Box):
|
||||
if prefs.paths.config.is_file() is False:
|
||||
dialog = ExceptionDialog(self.controller, strings.config_not_found)
|
||||
dialog.run()
|
||||
raise Exception
|
||||
raise OSError(f"Config file '{prefs.paths.config}' not found")
|
||||
|
||||
config = query.get_config(prefs.paths.config)
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@ from gi.repository import Gdk, Gtk # noqa E402
|
||||
if TYPE_CHECKING:
|
||||
from dzgui.managers.connection import Prerequisites
|
||||
from dzgui.controllers.mc import Controller
|
||||
from dzgui.controllers.emitter import Emitter
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -191,9 +192,14 @@ class PreConnectionAssistant(Gtk.Box):
|
||||
self.add(self.scrolled_box)
|
||||
self.add(self.button_box)
|
||||
|
||||
emitter = self.controller.get_emitter()
|
||||
emitter.connect("all_mods_synched", self._on_mods_synched)
|
||||
self.connect("key-press-event", self._on_keypress)
|
||||
self.connect("map", self._on_map)
|
||||
|
||||
def _on_mods_synched(self, emitter: "Emitter") -> None:
|
||||
self.tree.mark_mods_synched()
|
||||
|
||||
def _on_map(self, widget: Self) -> None:
|
||||
widgets = (
|
||||
self.tree_frame,
|
||||
@ -297,16 +303,16 @@ class PreConnectionAssistant(Gtk.Box):
|
||||
self._hide_mod_area()
|
||||
else:
|
||||
self._show_mod_area()
|
||||
msg = "All mods are up to date."
|
||||
msg = preconnect.up_to_date
|
||||
self.mod_count.set_text(msg)
|
||||
|
||||
if prereqs.required_space == 0:
|
||||
self.ok.set_label(preconnect.connect)
|
||||
|
||||
if prereqs.required_space != 0:
|
||||
pretty = number(prereqs.required_space)
|
||||
suffix = f" Need to download {pretty} MiB of mod updates."
|
||||
prefix = preconnect.total_mods
|
||||
self.mod_count.set_text(f"{prefix}{str(total_mods)}.{suffix}")
|
||||
else:
|
||||
self.ok.set_label(preconnect.connect)
|
||||
|
||||
if prereqs.is_last_server:
|
||||
self.connect_last.show()
|
||||
|
||||
@ -48,6 +48,10 @@ class ServerModTreeView(ContextMixin, TreeView): # type: ignore
|
||||
case _:
|
||||
pass
|
||||
|
||||
def mark_mods_synched(self) -> None:
|
||||
for row in self.mod_store:
|
||||
row[2] = server_mods.checkmark
|
||||
|
||||
# TODO: could be problematic if user downloads mods out of band
|
||||
def _on_row_activated(
|
||||
self,
|
||||
|
||||
@ -107,6 +107,7 @@ config-settings-package = { pygobject-stubs = { config = "Gtk3,Gdk3,Soup2" } }
|
||||
[tool.pytest.ini_options]
|
||||
markers = [
|
||||
"config: config file keys/values",
|
||||
"mods: tests mod metadata/link creation",
|
||||
"pefile: validate PE files",
|
||||
"post_install: requires a completed installation",
|
||||
"slow: long-running tests",
|
||||
|
||||
3
tests/fixtures/cpp/test.py
vendored
3
tests/fixtures/cpp/test.py
vendored
@ -1,3 +0,0 @@
|
||||
from dzgui.api.mods import tokenize
|
||||
|
||||
print(tokenize("meta4.cpp"))
|
||||
42
tests/fixtures/dztuirc_3
vendored
Normal file
42
tests/fixtures/dztuirc_3
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
#Path to DayZ installation
|
||||
steam_path="/tmp"
|
||||
|
||||
#Battlemetrics API key
|
||||
api_key=""
|
||||
|
||||
#Favorited server IP:PORT array
|
||||
ip_list=(
|
||||
)
|
||||
|
||||
#Favorite server to fast-connect to (limit one)
|
||||
fav_server=""
|
||||
|
||||
#Favorite server label (human readable)
|
||||
fav_label=""
|
||||
|
||||
#Custom player name (optional, required by some servers)
|
||||
name=""
|
||||
|
||||
#Set to 1 to perform dry-run and print launch options
|
||||
debug="1"
|
||||
|
||||
#Toggle stable/testing branch
|
||||
branch="testing"
|
||||
|
||||
#Steam API key
|
||||
steam_api=""
|
||||
|
||||
#Auto-install mods
|
||||
auto_install="2"
|
||||
|
||||
#Automod staging directory
|
||||
staging_dir="/tmp"
|
||||
|
||||
#Path to default Steam client
|
||||
default_steam_path="/tmp"
|
||||
|
||||
#Preferred Steam launch command (for Flatpak support)
|
||||
preferred_client="steam"
|
||||
|
||||
#DZGUI source path
|
||||
src_path=""
|
||||
@ -1,6 +1,7 @@
|
||||
import json
|
||||
import pytest
|
||||
|
||||
from dzgui.const.boilerplate import config_boilerplate
|
||||
from dzgui.config.query import get_config
|
||||
from dzgui.config.xdg import get_xdg_paths, parse_filepaths
|
||||
from dzgui.config import convert
|
||||
@ -11,7 +12,11 @@ pytestmark = pytest.mark.config
|
||||
|
||||
@pytest.fixture
|
||||
def legacy_config():
|
||||
return fixture_path("dztuirc_one")
|
||||
return fixture_path("dztuirc_1")
|
||||
|
||||
@pytest.fixture
|
||||
def unset_values():
|
||||
return fixture_path("dztuirc_3")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -60,8 +65,8 @@ def test_contains_invalid_values(keys, config):
|
||||
@pytest.mark.parametrize(
|
||||
"fixture, expect",
|
||||
[
|
||||
("dztuirc_one", (False, True, True)),
|
||||
("dztuirc_two", (False, False, False)),
|
||||
("dztuirc_1", (False, True, True)),
|
||||
("dztuirc_2", (False, False, False)),
|
||||
],
|
||||
)
|
||||
def test_bool_conversion(fixture, expect):
|
||||
@ -86,5 +91,12 @@ def test_key_conversion(legacy_config):
|
||||
for key in keys:
|
||||
assert key not in j
|
||||
|
||||
def test_missing_values(unset_values):
|
||||
j = convert.rc2json(unset_values)
|
||||
j = json.loads(j)
|
||||
assert j.keys() == config_boilerplate.keys()
|
||||
|
||||
|
||||
|
||||
|
||||
# TODO: test that when a config file is created from scratch, it contains all values
|
||||
|
||||
@ -1,17 +1,13 @@
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
|
||||
from dzgui.api.mods import tokenize
|
||||
from tests.fixtures import fixture_path
|
||||
|
||||
@pytest.mark.mods
|
||||
@pytest.mark.parametrize("fixture", [
|
||||
fixture_path("cpp/meta1.cpp"),
|
||||
fixture_path("cpp/meta2.cpp"),
|
||||
fixture_path("cpp/meta3.cpp"),
|
||||
fixture_path("cpp/meta4.cpp"),
|
||||
fixture_path("cpp/meta5.cpp"),
|
||||
fixture_path("cpp/meta6.cpp"),
|
||||
]
|
||||
)
|
||||
def test_modmeta(fixture: str) -> None:
|
||||
meta = tokenize(fixture)
|
||||
@pytest.mark.parametrize("i", range(1, 7))
|
||||
def test_modmeta(i: int) -> None:
|
||||
fixture = fixture_path(f"cpp/mod{i}")
|
||||
path = Path(fixture)
|
||||
meta = tokenize(path)
|
||||
assert meta["name"] == "ModName"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user