feat: get last updated timestamp

This commit is contained in:
aclist committed 2026-11-01 23:42:06 +09:00
1 parent 46117ecdda
commit e3c1ef59ee
5 files changed
+57 -4

No files matched your search

+23
View File
@@ -2,6 +2,7 @@ import logging
import re import re
from collections.abc import Iterator from collections.abc import Iterator
from datetime import date, datetime
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
from warnings import deprecated from warnings import deprecated
@@ -69,6 +70,28 @@ class ACF:
except StopIteration: except StopIteration:
return acf return acf
def search_key(self, key: str) -> str:
return self.dict["AppState"][key]
def date_to_str(self, epoch: int) -> str | None:
if epoch == 0:
return None
return datetime.fromtimestamp(epoch).isoformat(" ")
def get_date_by_key(self, key: str) -> str | None:
try:
stamp = int(self.search_key(key))
return self.date_to_str(stamp)
except Exception as e:
logger.critical(e)
return None
def get_last_updated(self) -> str | None:
return self.get_date_by_key("LastUpdated")
def get_last_played(self) -> str:
return self.get_date_by_key("LastPlayed")
def get_allows_downloads(self) -> int | None: def get_allows_downloads(self) -> int | None:
try: try:
# TODO: consider coercing strs to ints on initial import # TODO: consider coercing strs to ints on initial import
+11
View File
@@ -389,6 +389,17 @@ def get_running_app() -> int | None:
return None return None
def get_last_updated(path: Path, appid: int) -> str:
root_path = get_app_path(path, appid)
acf = root_path.joinpath(f"steamapps/appmanifest_{appid}.acf")
return ACF(acf).get_last_updated()
def get_last_played(path: Path, appid: int) -> str:
root_path = get_app_path(path, appid)
acf = root_path.joinpath(f"steamapps/appmanifest_{appid}.acf")
# TODO: make tests for this, use fixtures
return ACF(acf).get_last_played()
def get_app_allows_downloads(path: Path, appid: int) -> bool: def get_app_allows_downloads(path: Path, appid: int) -> bool:
try: try:
root_path = get_app_path(path, appid) root_path = get_app_path(path, appid)
+13 -2
View File
@@ -2,6 +2,7 @@ from pathlib import Path
from typing import Callable, TYPE_CHECKING from typing import Callable, TYPE_CHECKING
from dzgui.api import pefile as PeFile from dzgui.api import pefile as PeFile
from dzgui.api.steam import get_last_played, get_last_updated
from dzgui.config import query from dzgui.config import query
from dzgui.const.constants import ( from dzgui.const.constants import (
@@ -340,8 +341,10 @@ class Options(ScrollableMixin, Gtk.ScrolledWindow): # type: ignore
[LeftLabel(options.flatpak_label), self.flatpak_toggle], [LeftLabel(options.flatpak_label), self.flatpak_toggle],
) )
self.dayz_version_label = Gtk.Label(label=strings.null) self.dayz_version_label = Gtk.Label(label=strings.null, halign=Gtk.Align.START)
self.dayz_exp_version_label = Gtk.Label(label=strings.null) self.dayz_exp_version_label = Gtk.Label(
label=strings.null, halign=Gtk.Align.START
)
version_rows = [ version_rows = [
[LeftLabel(APPNAME_DAYZ), self.dayz_version_label], [LeftLabel(APPNAME_DAYZ), self.dayz_version_label],
@@ -467,10 +470,18 @@ class Options(ScrollableMixin, Gtk.ScrolledWindow): # type: ignore
dayz_version = PeFile.get_pretty_version(steam_path, APPID_DAYZ) dayz_version = PeFile.get_pretty_version(steam_path, APPID_DAYZ)
if dayz_version is None: if dayz_version is None:
dayz_version = strings.null dayz_version = strings.null
else:
last_updated = get_last_updated(steam_path, APPID_DAYZ)
if last_updated is not None:
dayz_version += f" (updated at {last_updated})"
dayz_exp_version = PeFile.get_pretty_version(steam_path, APPID_DAYZ_EXP) dayz_exp_version = PeFile.get_pretty_version(steam_path, APPID_DAYZ_EXP)
if dayz_exp_version is None: if dayz_exp_version is None:
dayz_exp_version = strings.null dayz_exp_version = strings.null
else:
last_updated = get_last_updated(steam_path, APPID_DAYZ_EXP)
if last_updated is not None:
dayz_exp_version += f" (updated at {last_updated})"
self.dayz_version_label.set_text(dayz_version) self.dayz_version_label.set_text(dayz_version)
self.dayz_exp_version_label.set_text(dayz_exp_version) self.dayz_exp_version_label.set_text(dayz_exp_version)
+9 -1
View File
@@ -3,7 +3,7 @@ import pytest
from _pytest.monkeypatch import MonkeyPatch from _pytest.monkeypatch import MonkeyPatch
from pathlib import Path from pathlib import Path
from dzgui.api.steam import get_app_allows_downloads from dzgui.api.steam import get_app_allows_downloads, get_last_updated
from tests.fixtures import fixture_path from tests.fixtures import fixture_path
pytestmark = pytest.mark.apitest pytestmark = pytest.mark.apitest
@@ -43,6 +43,14 @@ def patch_api() -> None:
mp.undo() mp.undo()
def test_no_last_update(steam_path) -> None:
assert get_last_updated(steam_path, 555) is None
def test_last_update(steam_path) -> None:
assert get_last_updated(steam_path, 444) == "2026-10-22 00:09:33"
def test_app_allows_downloads(steam_path) -> None: def test_app_allows_downloads(steam_path) -> None:
assert get_app_allows_downloads(steam_path, 111) is True assert get_app_allows_downloads(steam_path, 111) is True