diff --git a/CHANGELOG.md b/CHANGELOG.md
index d65c8c8c..0c694eb3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -58,6 +58,7 @@
- Validate mods via Mod page to pull in updates
- Support for Nasdara (Badlands) DLC
- Load offline mods
+- Support Snap package version of Steam
### Changed
- Conform to PEP 440 versioning for beta versions
@@ -101,6 +102,8 @@
- Steam Flatpak cannot run DZGUI as a non-Steam game
- Collisions between native Steam and Steam Flatpak clients
- Sticky toggle signal on radio buttons when reloading Options
+- Handle missing mods directory if not installed previously
+- Filters not blocked by keyboard keys when filters are disabled
### Developer-facing
- Options -> Dev page
diff --git a/docs/source/conf.py b/docs/source/conf.py
index 4c746e2a..63611680 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -15,7 +15,7 @@ author = 'aclist'
extensions = []
templates_path = ['_templates']
-exclude_patterns = []
+exclude_patterns = [] # type: ignore[var-annotated]
diff --git a/dzgui/api/mods.py b/dzgui/api/mods.py
index 1d595280..8b73c98f 100644
--- a/dzgui/api/mods.py
+++ b/dzgui/api/mods.py
@@ -35,6 +35,10 @@ def get_local_mod_path(steam_path: Path) -> Path:
def get_local_mods(workshop_path: Path) -> list[Path]:
+ # NOTE: user may not have staged mods before
+ if workshop_path.is_dir() is False:
+ logger.debug("Mod directory not yet present, returning empty list")
+ return []
mods = [file for file in workshop_path.iterdir() if file.is_dir()]
return mods
@@ -123,6 +127,7 @@ def remove_stale_signatures(
path = lookup(config, Preferences.DEFAULT)
steam_path = Path(path)
+
if ids is None:
local_ids = get_local_mod_ids(steam_path)
diff --git a/dzgui/api/steam.py b/dzgui/api/steam.py
index 23357f2b..22fefa42 100644
--- a/dzgui/api/steam.py
+++ b/dzgui/api/steam.py
@@ -12,9 +12,7 @@ from typing import Any, Generator, Union
from warnings import deprecated
from dzgui.api.acf import ACF
-from dzgui.const.endpoints import VALIDATE
-from dzgui.init.prereqs import has_any_client
-from dzgui.init.prereqs import has_flatpak_client, has_steam_client
+from dzgui.config.xdg import get_real_home
from dzgui.const.constants import (
APPID_DAYZ,
APPID_DAYZ_EXP,
@@ -27,6 +25,7 @@ from dzgui.const.constants import (
FLATPAK_STEAM_PATH,
LIBRARYFOLDERS_PATH,
REQUEST_TIMEOUT,
+ SNAP_STEAM_PATH,
UBUNTU_STEAM_PATH,
VDF_PATH,
)
@@ -35,7 +34,10 @@ from dzgui.const.endpoints import (
STEAM_PUBLISHED_FILES,
STEAM_SUB,
STEAM_UNSUB,
+ VALIDATE,
)
+from dzgui.init.prereqs import has_any_client
+from dzgui.init.prereqs import has_flatpak_client, has_steam_client
from dzgui.strings import wizard
from dzgui.strings.errors import api_validation_error, workshop_endpoint_error
from dzgui.util.bash import concat_bash_args
@@ -64,26 +66,36 @@ class VDFLoadError(Exception):
def get_steam_paths() -> list[tuple[Path, str]]:
paths = []
if has_any_client():
- HOME = Path.home()
+ HOME = get_real_home()
env = os.environ.get("XDG_DATA_HOME")
if env is not None:
- XDG_DATA_HOME = env
+ XDG_DATA_HOME = Path(env)
+ DEFAULT_PATH = XDG_DATA_HOME.joinpath("Steam")
+ default_label = wizard.desc_custom_path
else:
- XDG_DATA_HOME = DEFAULT_STEAM_PATH
+ DEFAULT_PATH = HOME.joinpath(DEFAULT_STEAM_PATH)
+ default_label = wizard.desc_default_path
- DEFAULT_PATH = HOME.joinpath(XDG_DATA_HOME)
FLATPAK_PATH = HOME.joinpath(FLATPAK_STEAM_PATH)
UBUNTU_PATH = HOME.joinpath(UBUNTU_STEAM_PATH)
DEBIAN_PATH = HOME.joinpath(DEBIAN_STEAM_PATH)
+ SNAP_PATH = HOME.joinpath(SNAP_STEAM_PATH)
human = {
- DEFAULT_PATH: wizard.desc_default_path,
+ DEFAULT_PATH: default_label,
FLATPAK_PATH: wizard.desc_flatpak_path,
UBUNTU_PATH: wizard.desc_ubuntu_path,
+ SNAP_PATH: wizard.desc_snap_path,
DEBIAN_PATH: wizard.desc_debian_path,
}
- for path in DEFAULT_PATH, FLATPAK_PATH, UBUNTU_PATH, DEBIAN_PATH:
+ for path in (
+ DEFAULT_PATH,
+ FLATPAK_PATH,
+ UBUNTU_PATH,
+ SNAP_PATH,
+ DEBIAN_PATH,
+ ):
if path is FLATPAK_PATH and has_flatpak_client() is False:
continue
if path is not FLATPAK_PATH and has_steam_client() is False:
@@ -485,11 +497,11 @@ def is_dayz_downloading(steam_path: Path, appid: int) -> bool:
def get_app_path(folders_path: Path, appid: int) -> Path:
app_path = None
-
try:
with open(folders_path / LIBRARYFOLDERS_PATH) as f:
folders = vdf.load(f)
- except Exception:
+ except Exception as e:
+ logger.debug(e)
raise VDFLoadError("Failed to parse libraryfolders")
for obj in folders["libraryfolders"]:
diff --git a/dzgui/config/freedesktop.py b/dzgui/config/freedesktop.py
index de38ee8e..4053fa01 100644
--- a/dzgui/config/freedesktop.py
+++ b/dzgui/config/freedesktop.py
@@ -3,6 +3,7 @@ import textwrap
from pathlib import Path
+from dzgui.config.xdg import get_real_home
from dzgui.util.dirs import copy_dzgui_to_xdg_data, find_icon_resource, make_parents
@@ -36,7 +37,8 @@ def write_desktop_file(exe_path: Path) -> Path:
def write_desktop_shortcut(desktop_file: Path) -> None:
# NOTE: necessarily depends on the above (UI blocks creation without XDG entry first)
- link = Path.home().joinpath("Desktop/dzgui.desktop")
+ home = get_real_home()
+ link = home.joinpath("Desktop/dzgui.desktop")
make_parents(link)
if link.exists():
link.unlink()
diff --git a/dzgui/config/xdg.py b/dzgui/config/xdg.py
index eac3dcf4..3a41659c 100644
--- a/dzgui/config/xdg.py
+++ b/dzgui/config/xdg.py
@@ -6,10 +6,8 @@ from dataclasses import dataclass
from dzgui.const.constants import (
APP_NAME_LOWER,
DEBUG_LOG,
- FLATPAK_ROOT_PATH,
SYSTEM_LOG,
)
-from dzgui.init.proc import is_sandboxed
@dataclass(slots=True, frozen=True)
@@ -50,9 +48,17 @@ def is_writeable(path_str: str) -> bool:
file.unlink()
return True
+def get_real_home() -> Path:
+ home = Path.home()
+ if resolved := os.environ.get("SNAP_REAL_HOME"): # Snap
+ home = Path(resolved)
+ elif resolved := os.environ.get("HOME"): # Flatpak
+ home = Path(resolved)
+ return home
+
def get_xdg_paths() -> dict[str, Path]:
- home = Path.home()
+ home = get_real_home()
xdg_paths = {
"XDG_CONFIG_HOME": home / ".config",
"XDG_STATE_HOME": home / ".local" / "state",
@@ -62,9 +68,6 @@ def get_xdg_paths() -> dict[str, Path]:
resolved_paths = {}
for path in xdg_paths:
real_path = os.environ.get(path)
- if real_path is not None and is_sandboxed():
- search_string = FLATPAK_ROOT_PATH + "/"
- real_path = real_path.replace(search_string, "")
if real_path is not None and is_writeable(real_path):
new_path = Path(real_path)
else:
diff --git a/dzgui/const/constants.py b/dzgui/const/constants.py
index daed17e6..6c8a6092 100644
--- a/dzgui/const/constants.py
+++ b/dzgui/const/constants.py
@@ -60,6 +60,7 @@ DEFAULT_STEAM_PATH = ".local/share/Steam"
FLATPAK_ROOT_PATH = ".var/app/com.valvesoftware.Steam"
FLATPAK_STEAM_PATH = FLATPAK_ROOT_PATH + "/data/Steam"
UBUNTU_STEAM_PATH = ".steam/steam"
+SNAP_STEAM_PATH = "snap/steam/common/" + DEFAULT_STEAM_PATH
DEBIAN_STEAM_PATH = ".steam/debian-installation"
LOG_FILTERS = ("CRITICAL", "WARNING", "INFO", "DEBUG")
diff --git a/dzgui/init/migrate.py b/dzgui/init/migrate.py
index 0ff3ce22..3b2b8ce2 100644
--- a/dzgui/init/migrate.py
+++ b/dzgui/init/migrate.py
@@ -12,13 +12,15 @@ from dzgui.const.constants import (
LEGACY_IPS_PATH,
)
from dzgui.config.convert import rc2json
+from dzgui.config.xdg import get_real_home
from dzgui.util._json import read_json, write_json
logger = logging.getLogger(APP_NAME)
def migrate_legacy_conf(config: Path) -> Any:
- old_conf = Path.home() / LEGACY_CONFIG_PATH
+ home = get_real_home()
+ old_conf = home / LEGACY_CONFIG_PATH
j = rc2json(old_conf)
return json.loads(j)
@@ -44,7 +46,8 @@ def convert_cols_file(res: Path) -> Any | None:
def migrate_cols_file(res: Path) -> None:
# NOTE: filename "dzg.columns.json" is API 7 spec
- old_res = Path.home() / LEGACY_COLS_PATH
+ home = get_real_home()
+ old_res = home / LEGACY_COLS_PATH
if old_res.is_file():
j = convert_cols_file(old_res)
if j is not None:
@@ -52,7 +55,7 @@ def migrate_cols_file(res: Path) -> None:
def copy_state_files(state_path: Path) -> None:
- home = Path.home()
+ home = get_real_home()
legacy = home / ".local/state/dzgui"
to_copy = [
"dzg.res.json",
@@ -71,7 +74,7 @@ def copy_state_files(state_path: Path) -> None:
def copy_ipdb(ips_path: Path) -> None:
- home = Path.home()
+ home = get_real_home()
legacy = home / LEGACY_IPS_PATH
if ips_path == legacy:
return
diff --git a/dzgui/init/prereqs.py b/dzgui/init/prereqs.py
index 9266bfbe..91278048 100644
--- a/dzgui/init/prereqs.py
+++ b/dzgui/init/prereqs.py
@@ -3,13 +3,13 @@ import shutil
import subprocess
from dzgui.const.constants import APP_NAME, FLATPAK_APPID, FLATPAK_CMD, STEAM_CMD
-from dzgui.init.proc import is_sandboxed
+from dzgui.init.proc import is_flatpak_sandbox
logger = logging.getLogger(APP_NAME)
def has_flatpak_client() -> bool:
- if is_sandboxed():
+ if is_flatpak_sandbox():
return True
try:
res = subprocess.run(
diff --git a/dzgui/init/proc.py b/dzgui/init/proc.py
index 0c1a2a06..dbf3bf55 100644
--- a/dzgui/init/proc.py
+++ b/dzgui/init/proc.py
@@ -27,19 +27,40 @@ def is_steam_running(cmd: str) -> bool:
raise TypeError("Not a valid Steam client selection")
-def is_sandboxed() -> bool:
+def is_snap_sandbox() -> bool:
+ return bool(os.environ.get("SNAP"))
+
+
+def is_flatpak_sandbox() -> bool:
return bool(os.environ.get("FLATPAK_ID"))
+def is_sandboxed() -> bool:
+ if is_snap_sandbox() or is_flatpak_sandbox():
+ return True
+ return False
+
+
+def get_flatpak_output() -> list[str] | None:
+ try:
+ proc = subprocess.check_output(
+ [FLATPAK_CMD, "ps", "--columns=application"], text=True
+ )
+ lines = proc.splitlines()
+ return lines
+ except Exception as e:
+ logger.debug(e)
+ return None
+
+
def is_flatpak_steam_running() -> bool:
- if is_sandboxed():
+ if is_flatpak_sandbox():
return True
if has_cmd(FLATPAK_CMD) is False:
return False
- proc = subprocess.check_output(
- [FLATPAK_CMD, "ps", "--columns=application"], text=True
- )
- lines = proc.splitlines()
+ lines = get_flatpak_output()
+ if lines is None:
+ return False
if FLATPAK_APPID in lines:
return True
return False
diff --git a/dzgui/strings/wizard.py b/dzgui/strings/wizard.py
index de837620..613b1d2a 100644
--- a/dzgui/strings/wizard.py
+++ b/dzgui/strings/wizard.py
@@ -3,7 +3,7 @@ title_intro = "Welcome"
blurb_intro = """
This wizard will help you set up some common config options before launching the application.
"""
-error_sandbox = "Setup cannot be run from inside Flatpak sandbox.\nPlease launch the application directly."
+error_sandbox = "Setup cannot be run from inside a sandboxed version of Steam (Snap/Flatpak).\nPlease launch the application directly first."
welcome = "Welcome to {0}!"
### SteamPathPage
@@ -12,15 +12,15 @@ blurb_steam_path = """
DZGUI needs to find the location to your default Steam installation.
This will be used to determine whether (and where) DayZ is installed.
"""
+desc_custom_path = "This is the expected Steam path if you set a custom XDG_DATA_HOME directory."
desc_default_path = "This is the default Steam path on most distributions."
desc_flatpak_path = (
"This is the default Steam path if you are using Flatpak Steam."
)
desc_ubuntu_path = "This is the default Steam path on Ubuntu-based systems."
+desc_snap_path = "This is the default Steam path on systems using Snap packages."
desc_debian_path = "This is the default Steam path on Debian-based systems."
-no_valid_paths = (
- "No valid Steam path or Steam command found on system. Please install Steam to continue."
-)
+no_valid_paths = "No valid Steam path or Steam command found on system. Please install Steam to continue."
button_scan = "Scan for Steam"
### ConfigMigrationPage
@@ -73,7 +73,7 @@ checkbox_steam_shortcut = (
"This creates a standalone copy of DZGUI and adds it to Steam. "
"You must restart Steam for the shortcut to appear. This will not replace or update existing shortcuts. "
"If you update DZGUI when it is launched via Steam, updates will be applied to the Steam version. "
- "Not available if you selected the Flatpak client as your Steam default."
+ "Not available if you selected the Snap client as your Steam default."
),
)
checkbox_start_menu = (
diff --git a/dzgui/util/dirs.py b/dzgui/util/dirs.py
index 5707f211..e2720a85 100644
--- a/dzgui/util/dirs.py
+++ b/dzgui/util/dirs.py
@@ -10,8 +10,9 @@ from dzgui.const.constants import APP_NAME, APP_NAME_LOWER, IMAGES_PATH
logger = logging.getLogger(APP_NAME)
-def make_parents(path: "Path") -> None:
- path.parent.mkdir(parents=True, exist_ok=True)
+def make_parents(path: "Path", descend: bool = False) -> None:
+ p = path if descend else path.parent
+ p.mkdir(parents=True, exist_ok=True)
def copy_dzgui_to_xdg_data(exe_path: Path) -> None:
diff --git a/dzgui/util/symlink.py b/dzgui/util/symlink.py
index 574ec2bd..9049f91a 100644
--- a/dzgui/util/symlink.py
+++ b/dzgui/util/symlink.py
@@ -35,6 +35,8 @@ def rebuild_symlinks(config: Path) -> None:
expunge_link(file)
workshop = get_local_mod_path(steam_path)
+ if workshop.is_dir() is False:
+ return
# NOTE: create symlinks for missing mods
for mod_id in get_local_mod_ids(steam_path):
uid = str(mod_id)
diff --git a/dzgui/views/dialogs/wizard.py b/dzgui/views/dialogs/wizard.py
index 82d84f08..a06b614f 100644
--- a/dzgui/views/dialogs/wizard.py
+++ b/dzgui/views/dialogs/wizard.py
@@ -14,8 +14,10 @@ from dzgui.const.constants import (
HERO_PATH,
FLATPAK_ROOT_PATH,
LEGACY_CONFIG_PATH,
+ SNAP_STEAM_PATH,
TMP_PATH,
)
+from dzgui.config.xdg import get_real_home
from dzgui.const.boilerplate import config_boilerplate
from dzgui.const.endpoints import STEAM_API_SETUP
from dzgui.config import freedesktop
@@ -506,7 +508,8 @@ class Assistant(Gtk.Assistant):
self.pages: dict[EnumeratedWizardPage, int] = {}
- legacy_path = Path.home().joinpath(LEGACY_CONFIG_PATH)
+ home = get_real_home()
+ legacy_path = home.joinpath(LEGACY_CONFIG_PATH)
self.has_legacy_config = legacy_path.is_file()
for page in (
self.page_intro,
@@ -699,6 +702,7 @@ class ShortcutCreationPage(OptionalPageMixin, EnumeratedWizardPage): # type: ig
self.add_start(self.checks_area)
self.show_all()
+
self.connect("map", self._on_map)
def _on_start_menu_toggled(self, button: Gtk.CheckButton) -> None:
@@ -709,6 +713,9 @@ class ShortcutCreationPage(OptionalPageMixin, EnumeratedWizardPage): # type: ig
def set_steam_path(self, path: Path) -> None:
self.steam_path = path
+ if SNAP_STEAM_PATH in str(self.steam_path):
+ self.steam_checkbox.set_active(False)
+ self.steam_checkbox.set_sensitive(False)
def is_steam_checkbox_active(self) -> bool:
return self.steam_checkbox.get_active()
diff --git a/tests/fixtures/api/steamapps/libraryfolders.vdf b/tests/fixtures/api/steamapps/libraryfolders.vdf
new file mode 100644
index 00000000..668ef502
--- /dev/null
+++ b/tests/fixtures/api/steamapps/libraryfolders.vdf
@@ -0,0 +1,12 @@
+"libraryfolders"
+{
+ "0"
+ {
+ "path" ""
+ "label" ""
+ "apps"
+ {
+ "221100" "11111"
+ }
+ }
+}
diff --git a/tests/test_default_steam_paths.py b/tests/test_default_steam_paths.py
new file mode 100644
index 00000000..a7136f25
--- /dev/null
+++ b/tests/test_default_steam_paths.py
@@ -0,0 +1,43 @@
+import pytest
+import tempfile
+
+from pathlib import Path
+from typing import TYPE_CHECKING
+
+from dzgui.api.steam import get_steam_paths
+
+if TYPE_CHECKING:
+ from _pytest.monkeypatch import MonkeyPatch
+
+
+def test_custom_xdg_path(monkeypatch: "MonkeyPatch") -> None:
+ tmp = tempfile.TemporaryDirectory(delete=False).name
+ custom_path = Path(tmp).joinpath("xdg_data_home")
+ monkeypatch.setenv("XDG_DATA_HOME", str(custom_path))
+
+ vdf_path = custom_path.joinpath("Steam/steamapps")
+ vdf_path.mkdir(parents=True, exist_ok=True)
+ vdf_path.joinpath("libraryfolders.vdf").touch()
+
+ resolved_paths = get_steam_paths()
+ expect = custom_path.joinpath("Steam")
+ assert any(expect in el for el in resolved_paths)
+
+
+def test_default_xdg_path() -> None:
+ resolved_paths = get_steam_paths()
+ expect = Path.home().joinpath(".local/share/Steam")
+ assert any(expect in el for el in resolved_paths)
+
+
+def test_ubuntu_path() -> None:
+ resolved_paths = get_steam_paths()
+ expect = Path.home().joinpath(".steam/steam")
+ assert any(expect in el for el in resolved_paths)
+
+
+@pytest.mark.flatpak
+def test_flatpak_path() -> None:
+ resolved_paths = get_steam_paths()
+ expect = Path.home().joinpath(".var/app/com.valvesoftware.Steam/data/steam")
+ assert any(expect in el for el in resolved_paths)
diff --git a/tests/test_home_in_sandbox.py b/tests/test_home_in_sandbox.py
new file mode 100644
index 00000000..4404b62a
--- /dev/null
+++ b/tests/test_home_in_sandbox.py
@@ -0,0 +1,23 @@
+import pytest
+import tempfile
+
+from pathlib import Path
+from typing import TYPE_CHECKING
+
+from dzgui.config.xdg import get_xdg_paths
+
+if TYPE_CHECKING:
+ from _pytest.monkeypatch import MonkeyPatch
+
+
+@pytest.mark.parametrize("env", ["SNAP_REAL_HOME", "HOME"])
+def test_sandbox_home_resolution(monkeypatch: "MonkeyPatch", env: str) -> None:
+ with tempfile.NamedTemporaryFile(delete=False) as f:
+ monkeypatch.setenv(env, f.name)
+ paths = get_xdg_paths()
+ assert paths["XDG_CONFIG_HOME"] == Path(f.name).joinpath(".config/dzgui")
+
+
+def test_home_fallback() -> None:
+ paths = get_xdg_paths()
+ assert paths["XDG_CONFIG_HOME"] == Path.home().joinpath(".config/dzgui")
diff --git a/tests/test_mod_directory.py b/tests/test_mod_directory.py
new file mode 100644
index 00000000..bde040e9
--- /dev/null
+++ b/tests/test_mod_directory.py
@@ -0,0 +1,30 @@
+import pytest
+import vdf
+
+from pathlib import Path
+
+from dzgui.api.mods import get_local_mod_ids
+from dzgui.util.dirs import make_parents
+from tests.fixtures import fixture_path
+
+@pytest.fixture
+def libraryfolders() -> Path:
+ return fixture_path("api/steamapps/libraryfolders.vdf")
+
+def test_missing_mod_dir(tmp_path, libraryfolders: Path) -> None:
+ """
+ Updates fixture file key with tmp path value serializes to file,
+ then tests for missing mod directory returning an empty list
+ """
+ folders = tmp_path.joinpath("steamapps/libraryfolders.vdf")
+ workshop = tmp_path.joinpath("steamapps/workshop/content")
+ make_parents(folders)
+ make_parents(workshop, descend=True)
+
+ with open(libraryfolders, "r") as f:
+ data = vdf.load(f)
+ data["libraryfolders"]["0"]["path"] = tmp_path
+ with open(folders, "w") as f:
+ vdf.dump(data, f, pretty=True)
+ ids = get_local_mod_ids(tmp_path)
+ assert len(ids) == 0