mirror of
https://github.com/aclist/dztui.git
synced 2026-08-29 19:27:13 +02:00
Compare commits
1 Commits
bd0fd07ae9
...
a1f851430d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1f851430d |
@ -305,6 +305,8 @@ def _get_running_app() -> int | None:
|
||||
return None
|
||||
|
||||
|
||||
# TODO: write tests
|
||||
# TODO: consider moving to proc module
|
||||
def get_running_app() -> int | None:
|
||||
PROC_NAME = "steam"
|
||||
SUBPROC_NAME = "reaper"
|
||||
@ -327,6 +329,7 @@ def get_running_app() -> int | None:
|
||||
return None
|
||||
|
||||
|
||||
# TODO: write tests
|
||||
def get_app_allows_downloads(path: Path, appid: int) -> bool:
|
||||
root_path = get_app_path(path, appid)
|
||||
acf = root_path.joinpath(f"steamapps/appmanifest_{appid}.acf")
|
||||
@ -341,15 +344,13 @@ def get_app_allows_downloads(path: Path, appid: int) -> bool:
|
||||
# NOTE: never allow
|
||||
case 2:
|
||||
return False
|
||||
# NOTE: no other known values at this time, fallback (assume permits)
|
||||
# NOTE: no other known values at this time
|
||||
case _:
|
||||
return True
|
||||
|
||||
def get_config(path: Path) -> Path:
|
||||
return path.joinpath("config/config.vdf")
|
||||
|
||||
def get_client_allows_downloads(path: Path) -> bool:
|
||||
config = get_config(path)
|
||||
config = path.joinpath("config/config.vdf")
|
||||
try:
|
||||
with open(config) as f:
|
||||
settings = vdf.load(f)
|
||||
|
||||
@ -12,11 +12,8 @@ import dzgui.api.servers as Servers
|
||||
|
||||
from dzgui.api.steam import (
|
||||
connect,
|
||||
get_app_allows_downloads,
|
||||
get_app_name,
|
||||
get_needs_update,
|
||||
get_remote_signatures,
|
||||
get_running_app,
|
||||
get_needs_update,
|
||||
load_to_menu,
|
||||
subscribe,
|
||||
)
|
||||
@ -85,7 +82,6 @@ class Prerequisites:
|
||||
mods: list[list[str]]
|
||||
game_mode: bool
|
||||
is_last_server: bool
|
||||
allows_downloads: tuple[bool, str]
|
||||
|
||||
|
||||
class ConnectionManager:
|
||||
@ -171,15 +167,6 @@ class ConnectionManager:
|
||||
|
||||
dayz_running = is_dayz_running()
|
||||
|
||||
running_app = get_running_app()
|
||||
if running_app is not None:
|
||||
allows_dl = get_app_allows_downloads(steam_path, running_app)
|
||||
running_app_name = get_app_name(running_app)
|
||||
allows_downloads = (allows_dl, running_app_name)
|
||||
else:
|
||||
allows_downloads = (True, "")
|
||||
|
||||
|
||||
client_name = self.controller.get_steam_client_name()
|
||||
client = self.controller.query_config(Preferences.CLIENT)
|
||||
running = is_steam_running(client)
|
||||
@ -205,7 +192,6 @@ class ConnectionManager:
|
||||
mods=remote_mods,
|
||||
game_mode=game_mode,
|
||||
is_last_server=is_last,
|
||||
allows_downloads=allows_downloads,
|
||||
)
|
||||
|
||||
func = StoredFunc(self.controller.open_connection_assistant, prereqs)
|
||||
@ -239,7 +225,7 @@ class ConnectionManager:
|
||||
) -> tuple[list[list[str]], list[tuple[str, str, int, int]]]:
|
||||
mods = Servers.get_rules(record)
|
||||
steam_path = self.controller.query_config(Preferences.DEFAULT)
|
||||
local = get_local_mod_ids(Path(steam_path))
|
||||
local = get_local_mod_ids(steam_path)
|
||||
|
||||
alpha_mods: list[list[str]] = [
|
||||
[
|
||||
|
||||
@ -76,7 +76,7 @@ class OfflineManager:
|
||||
window.set_sensitive(True)
|
||||
self.emitter.emit("custom_mods_loaded", store, folder)
|
||||
|
||||
@call_on_thread(dialogs.waiting_for_launch, show_cancel=True)
|
||||
@call_on_thread(dialogs.waiting_for_launch)
|
||||
def launch(
|
||||
self,
|
||||
appid: int,
|
||||
|
||||
@ -272,15 +272,6 @@ class PreConnectionAssistant(Gtk.Box):
|
||||
"It looks like DayZ is already running in the background. Exit DayZ before connecting."
|
||||
)
|
||||
|
||||
allows_dl, running_app = prereqs.allows_downloads
|
||||
if allows_dl is False:
|
||||
msg = (
|
||||
f"The game '{running_app}' is currently running in Steam, but background downloads are not enabled.\n"
|
||||
"Either stop the game first, or update your global Steam settings or the game's local settings.\n"
|
||||
"Otherwise, mods may be queued for download but never update."
|
||||
)
|
||||
warnings.append(msg)
|
||||
|
||||
self.add_warnings(warnings)
|
||||
self.add_errors(errors)
|
||||
|
||||
|
||||
13
tests/fixtures/api/client_allows_downloads.vdf
vendored
13
tests/fixtures/api/client_allows_downloads.vdf
vendored
@ -1,13 +0,0 @@
|
||||
"InstallConfigStore"
|
||||
{
|
||||
"Software"
|
||||
{
|
||||
"Valve"
|
||||
{
|
||||
"Steam"
|
||||
{
|
||||
"AllowDownloadsDuringGameplay" "1"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
"InstallConfigStore"
|
||||
{
|
||||
"Software"
|
||||
{
|
||||
"Valve"
|
||||
{
|
||||
"Steam"
|
||||
{
|
||||
"AllowDownloadsDuringGameplay" "0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
53
tests/fixtures/api/steamapps/appmanifest_111.acf
vendored
53
tests/fixtures/api/steamapps/appmanifest_111.acf
vendored
@ -1,53 +0,0 @@
|
||||
"AppState"
|
||||
{
|
||||
"appid" "111"
|
||||
"Universe" "1"
|
||||
"name" "TEST APP"
|
||||
"StateFlags" "4"
|
||||
"installdir" "TESTAPP"
|
||||
"LastUpdated" "0"
|
||||
"LastPlayed" "0"
|
||||
"SizeOnDisk" "0"
|
||||
"StagingSize" "0"
|
||||
"buildid" "0"
|
||||
"LastOwner" "0"
|
||||
"DownloadType" "2"
|
||||
"UpdateResult" "0"
|
||||
"BytesToDownload" "0"
|
||||
"BytesDownloaded" "0"
|
||||
"BytesToStage" "0"
|
||||
"BytesStaged" "0"
|
||||
"TargetBuildID" "0"
|
||||
"AutoUpdateBehavior" "0"
|
||||
"AllowOtherDownloadsWhileRunning" "1"
|
||||
"ScheduledAutoUpdate" "0"
|
||||
"FullValidateAfterNextUpdate" "1"
|
||||
"InstalledDepots"
|
||||
{
|
||||
"1110"
|
||||
{
|
||||
"manifest" "0"
|
||||
"size" "0"
|
||||
}
|
||||
}
|
||||
"SharedDepots"
|
||||
{
|
||||
"228983" "228980"
|
||||
"228985" "228980"
|
||||
"228988" "228980"
|
||||
"228990" "228980"
|
||||
"229004" "228980"
|
||||
}
|
||||
"UserConfig"
|
||||
{
|
||||
"language" "english"
|
||||
"platform_override_dest" "linux"
|
||||
"platform_override_source" "windows"
|
||||
}
|
||||
"MountedConfig"
|
||||
{
|
||||
"language" "english"
|
||||
"platform_override_dest" "linux"
|
||||
"platform_override_source" "windows"
|
||||
}
|
||||
}
|
||||
53
tests/fixtures/api/steamapps/appmanifest_222.acf
vendored
53
tests/fixtures/api/steamapps/appmanifest_222.acf
vendored
@ -1,53 +0,0 @@
|
||||
"AppState"
|
||||
{
|
||||
"appid" "222"
|
||||
"Universe" "1"
|
||||
"name" "TEST APP"
|
||||
"StateFlags" "4"
|
||||
"installdir" "TESTAPP"
|
||||
"LastUpdated" "0"
|
||||
"LastPlayed" "0"
|
||||
"SizeOnDisk" "0"
|
||||
"StagingSize" "0"
|
||||
"buildid" "0"
|
||||
"LastOwner" "0"
|
||||
"DownloadType" "2"
|
||||
"UpdateResult" "0"
|
||||
"BytesToDownload" "0"
|
||||
"BytesDownloaded" "0"
|
||||
"BytesToStage" "0"
|
||||
"BytesStaged" "0"
|
||||
"TargetBuildID" "0"
|
||||
"AutoUpdateBehavior" "0"
|
||||
"AllowOtherDownloadsWhileRunning" "2"
|
||||
"ScheduledAutoUpdate" "0"
|
||||
"FullValidateAfterNextUpdate" "1"
|
||||
"InstalledDepots"
|
||||
{
|
||||
"2220"
|
||||
{
|
||||
"manifest" "0"
|
||||
"size" "0"
|
||||
}
|
||||
}
|
||||
"SharedDepots"
|
||||
{
|
||||
"228983" "228980"
|
||||
"228985" "228980"
|
||||
"228988" "228980"
|
||||
"228990" "228980"
|
||||
"229004" "228980"
|
||||
}
|
||||
"UserConfig"
|
||||
{
|
||||
"language" "english"
|
||||
"platform_override_dest" "linux"
|
||||
"platform_override_source" "windows"
|
||||
}
|
||||
"MountedConfig"
|
||||
{
|
||||
"language" "english"
|
||||
"platform_override_dest" "linux"
|
||||
"platform_override_source" "windows"
|
||||
}
|
||||
}
|
||||
53
tests/fixtures/api/steamapps/appmanifest_333.acf
vendored
53
tests/fixtures/api/steamapps/appmanifest_333.acf
vendored
@ -1,53 +0,0 @@
|
||||
"AppState"
|
||||
{
|
||||
"appid" "333"
|
||||
"Universe" "1"
|
||||
"name" "TEST APP"
|
||||
"StateFlags" "4"
|
||||
"installdir" "TESTAPP"
|
||||
"LastUpdated" "0"
|
||||
"LastPlayed" "0"
|
||||
"SizeOnDisk" "0"
|
||||
"StagingSize" "0"
|
||||
"buildid" "0"
|
||||
"LastOwner" "0"
|
||||
"DownloadType" "2"
|
||||
"UpdateResult" "0"
|
||||
"BytesToDownload" "0"
|
||||
"BytesDownloaded" "0"
|
||||
"BytesToStage" "0"
|
||||
"BytesStaged" "0"
|
||||
"TargetBuildID" "0"
|
||||
"AutoUpdateBehavior" "0"
|
||||
"AllowOtherDownloadsWhileRunning" "0"
|
||||
"ScheduledAutoUpdate" "0"
|
||||
"FullValidateAfterNextUpdate" "1"
|
||||
"InstalledDepots"
|
||||
{
|
||||
"3330"
|
||||
{
|
||||
"manifest" "0"
|
||||
"size" "0"
|
||||
}
|
||||
}
|
||||
"SharedDepots"
|
||||
{
|
||||
"228983" "228980"
|
||||
"228985" "228980"
|
||||
"228988" "228980"
|
||||
"228990" "228980"
|
||||
"229004" "228980"
|
||||
}
|
||||
"UserConfig"
|
||||
{
|
||||
"language" "english"
|
||||
"platform_override_dest" "linux"
|
||||
"platform_override_source" "windows"
|
||||
}
|
||||
"MountedConfig"
|
||||
{
|
||||
"language" "english"
|
||||
"platform_override_dest" "linux"
|
||||
"platform_override_source" "windows"
|
||||
}
|
||||
}
|
||||
@ -1,60 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from _pytest.monkeypatch import MonkeyPatch
|
||||
from pathlib import Path
|
||||
|
||||
from dzgui.api.steam import get_app_allows_downloads
|
||||
from tests.fixtures import fixture_path
|
||||
|
||||
pytestmark = pytest.mark.apitest
|
||||
|
||||
|
||||
def mock_path(p: Path, appid: int) -> Path:
|
||||
return Path(fixture_path("api"))
|
||||
|
||||
|
||||
def mock_config_allows(p: Path) -> Path:
|
||||
return Path(fixture_path("api/client_allows_downloads.vdf"))
|
||||
|
||||
|
||||
def mock_config_disallows(p: Path) -> Path:
|
||||
return Path(fixture_path("api/client_disallows_downloads.vdf"))
|
||||
|
||||
|
||||
def mock_config_missing(p: Path) -> Path:
|
||||
return Path(fixture_path(""))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client_allows() -> Path:
|
||||
return Path(fixture_path("api/client_allows_downloads.vdf"))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def steam_path() -> Path:
|
||||
return Path(fixture_path("api"))
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def patch_api() -> None:
|
||||
mp = MonkeyPatch()
|
||||
mp.setattr("dzgui.api.steam.get_app_path", mock_path)
|
||||
yield
|
||||
mp.undo()
|
||||
|
||||
|
||||
def test_app_allows_downloads(steam_path) -> None:
|
||||
assert get_app_allows_downloads(steam_path, 111) is True
|
||||
|
||||
|
||||
def test_app_disallows_downloads(steam_path):
|
||||
assert get_app_allows_downloads(steam_path, 222) is False
|
||||
|
||||
|
||||
def test_app_delegates_downloads(monkeypatch, steam_path, client_allows):
|
||||
monkeypatch.setattr("dzgui.api.steam.get_config", mock_config_disallows)
|
||||
assert get_app_allows_downloads(steam_path, 333) is False
|
||||
monkeypatch.setattr("dzgui.api.steam.get_config", mock_config_allows)
|
||||
assert get_app_allows_downloads(steam_path, 333) is True
|
||||
monkeypatch.setattr("dzgui.api.steam.get_config", mock_config_missing)
|
||||
assert get_app_allows_downloads(steam_path, 333) is True
|
||||
Loading…
Reference in New Issue
Block a user