From 426e771313dd69508414b7ef9a71a16fd52cb2e5 Mon Sep 17 00:00:00 2001 From: Toast Date: Mon, 2 Jun 2025 00:10:28 +0200 Subject: [PATCH 1/3] Add vdf dependency --- flake.nix | 4 ++++ pyproject.toml | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 64ebfc9..bbdb95c 100644 --- a/flake.nix +++ b/flake.nix @@ -15,12 +15,16 @@ ruff ( python3.withPackages (ps: with ps;[ + # Dev dependencies python-lsp-server pylsp-mypy mypy setuptools-scm + + #App dependencies pyside6 tomlkit + vdf ] ) ) diff --git a/pyproject.toml b/pyproject.toml index a7857ca..b0cc6ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,6 +17,7 @@ classifiers = [ dependencies = [ "pyside6", "tomlkit", + "vdf", ] requires-python = ">=3.6" @@ -47,7 +48,8 @@ mypy_path = "$MYPY_CONFIG_FILE_DIR/src" module = [ "PySide6.QtGui", "PySide6.QtCore", - "PySide6.QtQml" + "PySide6.QtQml", + "vdf" ] ignore_missing_imports = true -- 2.51.2 From 67edfdf74305dff00ab9132efe1b64daa4cd4c5b Mon Sep 17 00:00:00 2001 From: Toast Date: Mon, 2 Jun 2025 01:21:55 +0200 Subject: [PATCH 2/3] Add GameFinder class --- src/leek/utils.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/leek/utils.py diff --git a/src/leek/utils.py b/src/leek/utils.py new file mode 100644 index 0000000..c1d0bac --- /dev/null +++ b/src/leek/utils.py @@ -0,0 +1,32 @@ +import vdf +from pathlib import Path + + +class GameFinder: + __game_path: Path | None = None + + @staticmethod + def find() -> Path: + if GameFinder.__game_path is not None: + return GameFinder.__game_path + + # .local/share/Steam/config/libraryfolders.vdf + steam_path: Path = Path.home() / ".local/share/Steam" + libraries_vdf_path: Path = steam_path / "config/libraryfolders.vdf" + + with libraries_vdf_path.open() as vdf_file: + data: dict = vdf.parse(vdf_file) + for index in data["libraryfolders"]: + library: dict = data["libraryfolders"][index] + + project_diva_id: str = "1761390" + if project_diva_id in library["apps"]: + libray_path: Path = Path(library["path"]) + GameFinder.__game_path = ( + libray_path + / "steamapps/common/Hatsune Miku Project DIVA Mega Mix Plus" + ) + return GameFinder.__game_path + + # Could not find the game :( + raise FileNotFoundError -- 2.51.2 From f2cc48f705e0d99f3a6dba35cc6e2896b4e6c391 Mon Sep 17 00:00:00 2001 From: Toast Date: Mon, 2 Jun 2025 01:24:52 +0200 Subject: [PATCH 3/3] QModListModel: get game path with GameFinder --- src/leek/mod_list.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/leek/mod_list.py b/src/leek/mod_list.py index 5357bba..ee12488 100644 --- a/src/leek/mod_list.py +++ b/src/leek/mod_list.py @@ -3,16 +3,11 @@ from PySide6.QtCore import QAbstractListModel, QModelIndex from leek.mod import InvalidModError from leek.qmod import QMod from pathlib import Path +from leek.utils import GameFinder QML_IMPORT_NAME = "Leek" QML_IMPORT_MAJOR_VERSION = 1 -# TODO: Don't harcode the mods path -GAME_PATH = Path( - "/home/toast/.local/share/Steam/steamapps/common/Hatsune Miku Project DIVA Mega Mix Plus/" -) -MOD_PATH = Path(GAME_PATH, "mods") - # Qt follows C++ naming conventions # ruff: noqa: N802 @@ -22,7 +17,9 @@ class QModListModel(QAbstractListModel): super().__init__(parent=parent) mods: list[QMod] = [] - for dir in MOD_PATH.iterdir(): + mod_path: Path = GameFinder.find() / "mods" + + for dir in mod_path.iterdir(): if dir.name == ".stfolder": continue try: -- 2.51.2