Merge Library and Status into a unified Games tab
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
"""Dialog showing downloaded versions of a game with management actions."""
|
||||
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
from loguru import logger
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtGui import QFont
|
||||
from PySide6.QtWidgets import (
|
||||
@@ -18,10 +18,9 @@ from PySide6.QtWidgets import (
|
||||
QVBoxLayout,
|
||||
QWidget,
|
||||
)
|
||||
from loguru import logger
|
||||
|
||||
from src.config import MetadataStore
|
||||
from src.models import DownloadedInstaller, language_folder_name, sanitize_folder_name
|
||||
from src.models import DownloadedInstaller, language_folder_name
|
||||
|
||||
COL_FILE = 0
|
||||
COL_VERSION = 1
|
||||
@@ -38,13 +37,6 @@ def _fmt_size(size: int) -> str:
|
||||
return f"{size:.1f} GB"
|
||||
|
||||
|
||||
def _installer_path(base_path: Path, game_name: str, installer: DownloadedInstaller) -> Path:
|
||||
"""Reconstruct the path where an installer file lives."""
|
||||
lang_path = base_path / game_name / installer.version / language_folder_name(installer.language) / installer.filename
|
||||
direct_path = base_path / game_name / installer.version / installer.filename
|
||||
return lang_path if lang_path.exists() else direct_path
|
||||
|
||||
|
||||
class GameVersionsDialog(QDialog):
|
||||
"""Shows all downloaded versions/files for a game and lets user manage them."""
|
||||
|
||||
@@ -60,7 +52,6 @@ class GameVersionsDialog(QDialog):
|
||||
self.game_title = game_title
|
||||
self.metadata = metadata
|
||||
self.base_path = metadata.base_path
|
||||
self.game_folder = self.base_path / sanitize_folder_name(game_title)
|
||||
|
||||
self.setWindowTitle(f"Downloaded versions — {game_title}")
|
||||
self.setMinimumSize(700, 450)
|
||||
@@ -171,8 +162,7 @@ class GameVersionsDialog(QDialog):
|
||||
file_node.setData(COL_FILE, Qt.ItemDataRole.UserRole, ("installer", inst))
|
||||
|
||||
# Grey out if file no longer on disk
|
||||
path = _installer_path(self.base_path, sanitize_folder_name(self.game_title), inst)
|
||||
if not path.exists():
|
||||
if not self.metadata.find_installer_file(record, inst):
|
||||
for col in range(5):
|
||||
file_node.setForeground(col, self.palette().color(self.foregroundRole()).darker(150))
|
||||
file_node.setToolTip(COL_FILE, "File not found on disk")
|
||||
@@ -192,8 +182,7 @@ class GameVersionsDialog(QDialog):
|
||||
node.setText(3, _fmt_size(bonus.size))
|
||||
node.setData(0, Qt.ItemDataRole.UserRole, bonus)
|
||||
|
||||
bonus_path = self.base_path / sanitize_folder_name(self.game_title) / "Bonus" / bonus.filename
|
||||
if not bonus_path.exists():
|
||||
if not self.metadata.find_bonus_file(record, bonus):
|
||||
for col in range(4):
|
||||
node.setForeground(col, self.palette().color(self.foregroundRole()).darker(150))
|
||||
node.setToolTip(0, "File not found on disk")
|
||||
@@ -226,8 +215,8 @@ class GameVersionsDialog(QDialog):
|
||||
deleted = 0
|
||||
for item in selected:
|
||||
inst: DownloadedInstaller = item.data(COL_FILE, Qt.ItemDataRole.UserRole)[1]
|
||||
path = _installer_path(self.base_path, sanitize_folder_name(self.game_title), inst)
|
||||
if path.exists():
|
||||
path = self.metadata.find_installer_file(record, inst)
|
||||
if path:
|
||||
path.unlink()
|
||||
logger.info(f"Deleted {path}")
|
||||
deleted += 1
|
||||
@@ -266,19 +255,20 @@ class GameVersionsDialog(QDialog):
|
||||
|
||||
version = preselected_version or versions[-1]
|
||||
|
||||
version_dirs = [d / version for d in self.metadata.candidate_dirs(record) if (d / version).exists()]
|
||||
|
||||
reply = QMessageBox.question(
|
||||
self,
|
||||
"Delete version folder",
|
||||
f"Delete entire version folder '{version}' for '{self.game_title}'?\n\n"
|
||||
f"Path: {self.base_path / sanitize_folder_name(self.game_title) / version}\n\n"
|
||||
f"Path: {version_dirs[0] if version_dirs else '(not found on disk)'}\n\n"
|
||||
"This will remove all files in that folder from disk.",
|
||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
||||
)
|
||||
if reply != QMessageBox.StandardButton.Yes:
|
||||
return
|
||||
|
||||
version_dir = self.base_path / sanitize_folder_name(self.game_title) / version
|
||||
if version_dir.exists():
|
||||
for version_dir in version_dirs:
|
||||
shutil.rmtree(version_dir)
|
||||
logger.info(f"Deleted version folder {version_dir}")
|
||||
|
||||
@@ -313,8 +303,8 @@ class GameVersionsDialog(QDialog):
|
||||
deleted = 0
|
||||
for item in selected:
|
||||
bonus = item.data(0, Qt.ItemDataRole.UserRole)
|
||||
path = self.base_path / sanitize_folder_name(self.game_title) / "Bonus" / bonus.filename
|
||||
if path.exists():
|
||||
path = self.metadata.find_bonus_file(record, bonus)
|
||||
if path:
|
||||
path.unlink()
|
||||
logger.info(f"Deleted bonus {path}")
|
||||
deleted += 1
|
||||
|
||||
Reference in New Issue
Block a user