From 6918e175c44b3d00b36df2ceb35b7c92802535a4 Mon Sep 17 00:00:00 2001 From: Toast Date: Sun, 25 May 2025 14:24:40 +0200 Subject: [PATCH 1/2] mod_list: use Path instad of strings --- src/leek/mod_list.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/leek/mod_list.py b/src/leek/mod_list.py index 8e5c6b6..68476f4 100644 --- a/src/leek/mod_list.py +++ b/src/leek/mod_list.py @@ -1,13 +1,14 @@ from PySide6.QtQml import QmlElement from PySide6.QtCore import QAbstractListModel, QModelIndex from leek.mod import Mod, InvalidModError -import os +from pathlib import Path QML_IMPORT_NAME = "Leek" QML_IMPORT_MAJOR_VERSION = 1 # TODO: Don't harcode the mods path -GAME_PATH = "/home/toast/.local/share/Steam/steamapps/common/Hatsune Miku Project DIVA Mega Mix Plus/" +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 @@ -17,14 +18,13 @@ class QModListModel(QAbstractListModel): super().__init__(parent=parent) mods: list[Mod] = [] - with os.scandir(GAME_PATH + "mods/") as dirs: - for dir in dirs: - try: - new_mod: Mod = Mod(dir.path + "/" ) - mods.append(new_mod) - except InvalidModError as e: - print(f"Found invalid mod at {dir.path}: {e.message}") - continue + for dir in MOD_PATH.iterdir(): + try: + new_mod: Mod = Mod(f"{dir.as_posix()}/") + mods.append(new_mod) + except InvalidModError as e: + print(f"Found invalid mod at {dir}: {e.message}") + continue self.mods = mods -- 2.51.2 From 5cfab64b0769769fb2cddc16e6a40ac6e9970a32 Mon Sep 17 00:00:00 2001 From: Toast Date: Sun, 25 May 2025 14:31:46 +0200 Subject: [PATCH 2/2] mod: use Path instead of strings --- src/leek/mod.py | 13 ++++++++----- src/leek/mod_list.py | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/leek/mod.py b/src/leek/mod.py index aca1726..8d57465 100644 --- a/src/leek/mod.py +++ b/src/leek/mod.py @@ -1,17 +1,18 @@ import tomlkit +from pathlib import Path from tomlkit import TOMLDocument class Mod: __config: TOMLDocument - __path: str + __path: Path __name: str __description: str __author: str __enabled: bool @property - def path(self) -> str: + def path(self) -> Path: return self.__path # Mod metadata @@ -44,15 +45,17 @@ class Mod: # Nothing to do return - with open(self.__path + "config.toml", "w") as config_file: + config_toml = Path(self.__path, "config.toml") + with config_toml.open("w") as config_file: self.__config["enabled"] = value tomlkit.dump(self.__config, config_file) - def __init__(self, path: str) -> None: + def __init__(self, path: Path) -> None: self.__path = path try: - with open(path + "config.toml") as config_file: + config_toml = Path(self.__path, "config.toml") + with config_toml.open() as config_file: self.__config = tomlkit.load(config_file) if "enabled" not in self.__config: diff --git a/src/leek/mod_list.py b/src/leek/mod_list.py index 68476f4..f8696a5 100644 --- a/src/leek/mod_list.py +++ b/src/leek/mod_list.py @@ -20,7 +20,7 @@ class QModListModel(QAbstractListModel): for dir in MOD_PATH.iterdir(): try: - new_mod: Mod = Mod(f"{dir.as_posix()}/") + new_mod: Mod = Mod(dir) mods.append(new_mod) except InvalidModError as e: print(f"Found invalid mod at {dir}: {e.message}") -- 2.51.2