Automatic game path detection #18

Merged
Toast merged 3 commits from gamePathDetection into main 2025-06-02 01:26:29 +02:00
4 changed files with 43 additions and 8 deletions

View file

@ -15,12 +15,16 @@
ruff ruff
( (
python3.withPackages (ps: with ps;[ python3.withPackages (ps: with ps;[
# Dev dependencies
python-lsp-server python-lsp-server
pylsp-mypy pylsp-mypy
mypy mypy
setuptools-scm setuptools-scm
#App dependencies
pyside6 pyside6
tomlkit tomlkit
vdf
] ]
) )
) )

View file

@ -17,6 +17,7 @@ classifiers = [
dependencies = [ dependencies = [
"pyside6", "pyside6",
"tomlkit", "tomlkit",
"vdf",
] ]
requires-python = ">=3.6" requires-python = ">=3.6"
@ -47,7 +48,8 @@ mypy_path = "$MYPY_CONFIG_FILE_DIR/src"
module = [ module = [
"PySide6.QtGui", "PySide6.QtGui",
"PySide6.QtCore", "PySide6.QtCore",
"PySide6.QtQml" "PySide6.QtQml",
"vdf"
] ]
ignore_missing_imports = true ignore_missing_imports = true

View file

@ -3,16 +3,11 @@ from PySide6.QtCore import QAbstractListModel, QModelIndex
from leek.mod import InvalidModError from leek.mod import InvalidModError
from leek.qmod import QMod from leek.qmod import QMod
from pathlib import Path from pathlib import Path
from leek.utils import GameFinder
QML_IMPORT_NAME = "Leek" QML_IMPORT_NAME = "Leek"
QML_IMPORT_MAJOR_VERSION = 1 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 # Qt follows C++ naming conventions
# ruff: noqa: N802 # ruff: noqa: N802
@ -22,7 +17,9 @@ class QModListModel(QAbstractListModel):
super().__init__(parent=parent) super().__init__(parent=parent)
mods: list[QMod] = [] 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": if dir.name == ".stfolder":
continue continue
try: try:

32
src/leek/utils.py Normal file
View file

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