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 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: 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