Merge pull request #47 from Dummerle/dlc_support
Add tab in game info to install and list dlcs. Uninstalling dlcs is not supported by Legendary
This commit is contained in:
commit
b71fe88eec
8 changed files with 183 additions and 16 deletions
|
@ -23,7 +23,6 @@ class InstallDialog(QDialog):
|
|||
default_path = self.core.lgd.config.get("Legendary", "install_dir")
|
||||
else:
|
||||
default_path = os.path.expanduser("~/legendary")
|
||||
# TODO read from config
|
||||
if not default_path:
|
||||
default_path = os.path.expanduser("~/legendary")
|
||||
if not update:
|
||||
|
@ -63,7 +62,9 @@ class InstallDialog(QDialog):
|
|||
|
||||
self.setLayout(self.layout)
|
||||
|
||||
def get_information(self):
|
||||
def get_information(self, path=None):
|
||||
if path:
|
||||
self.install_path_field.text_edit.setText(path)
|
||||
self.exec_()
|
||||
return self.infos
|
||||
|
||||
|
|
|
@ -78,7 +78,6 @@ class LaunchDialog(QDialog):
|
|||
|
||||
def launch(self):
|
||||
# self.core = core
|
||||
self.pb_size = len(self.core.get_game_list())
|
||||
self.info_text.setText(self.tr("Downloading Images"))
|
||||
self.thread = LaunchThread(self.core, self)
|
||||
self.thread.download_progess.connect(self.update_pb)
|
||||
|
@ -86,7 +85,7 @@ class LaunchDialog(QDialog):
|
|||
self.thread.start()
|
||||
|
||||
def update_pb(self, i: int):
|
||||
self.info_pb.setValue(i / self.pb_size * 100)
|
||||
self.info_pb.setValue(i)
|
||||
|
||||
def info(self, text: str):
|
||||
if text == "finish":
|
||||
|
|
|
@ -65,6 +65,8 @@ class TabWidget(QTabWidget):
|
|||
self.downloadTab.finished.connect(self.dl_finished)
|
||||
# start download
|
||||
self.games_tab.default_widget.game_list.install_game.connect(self.start_download)
|
||||
# install dlc
|
||||
self.games_tab.game_info.dlc_tab.install_dlc.connect(self.start_download)
|
||||
|
||||
# repair game
|
||||
self.games_tab.game_info.info.verify_game.connect(lambda app_name: self.downloadTab.install_game(
|
||||
|
@ -93,8 +95,8 @@ class TabWidget(QTabWidget):
|
|||
downloads = len(self.downloadTab.dl_queue) + len(self.downloadTab.update_widgets.keys())
|
||||
self.setTabText(1, "Downloads" + ((" (" + str(downloads) + ")") if downloads != 0 else ""))
|
||||
|
||||
def start_download(self, app_name):
|
||||
self.downloadTab.install_game(app_name)
|
||||
def start_download(self, options):
|
||||
self.downloadTab.install_game(options)
|
||||
downloads = len(self.downloadTab.dl_queue) + len(self.downloadTab.update_widgets.keys()) + 1
|
||||
self.setTabText(1, "Downloads" + ((" (" + str(downloads) + ")") if downloads != 0 else ""))
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ class GameTab(QWidget):
|
|||
super(GameTab, self).__init__()
|
||||
self.layout = QStackedLayout()
|
||||
self.default_widget = Games(core)
|
||||
# Signal to show info
|
||||
self.default_widget.game_list.show_game_info.connect(self.show_info)
|
||||
self.default_widget.head_bar.import_game.clicked.connect(lambda: self.layout.setCurrentIndex(2))
|
||||
self.layout.addWidget(self.default_widget)
|
||||
|
@ -33,7 +34,7 @@ class GameTab(QWidget):
|
|||
self.layout.setCurrentIndex(0)
|
||||
|
||||
def show_info(self, app_name):
|
||||
self.game_info.update_game(app_name)
|
||||
self.game_info.update_game(app_name, self.default_widget.game_list.dlcs)
|
||||
self.game_info.setCurrentIndex(1)
|
||||
self.layout.setCurrentIndex(1)
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ from PyQt5.QtGui import QPixmap, QKeyEvent
|
|||
from PyQt5.QtWidgets import QWidget, QPushButton, QVBoxLayout, QLabel, QHBoxLayout, QTabWidget, QMessageBox, \
|
||||
QProgressBar, QStackedWidget, QGroupBox, QScrollArea
|
||||
from qtawesome import icon
|
||||
|
||||
from rare.components.tabs.games.game_info.dlcs import DlcTab
|
||||
from rare.utils import legendary_utils
|
||||
|
||||
from rare.components.dialogs.uninstall_dialog import UninstallDialog
|
||||
|
@ -29,14 +31,26 @@ class InfoTabs(QTabWidget):
|
|||
|
||||
self.info = GameInfo(core)
|
||||
self.addTab(self.info, self.tr("Game Info"))
|
||||
|
||||
self.settings = GameSettings(core)
|
||||
self.addTab(self.settings, self.tr("Settings"))
|
||||
self.tabBar().setCurrentIndex(1)
|
||||
|
||||
def update_game(self, app_name):
|
||||
self.dlc_tab = DlcTab(core)
|
||||
self.addTab(self.dlc_tab, self.tr("DLCs"))
|
||||
|
||||
def update_game(self, app_name, dlcs: list):
|
||||
|
||||
self.info.update_game(app_name)
|
||||
self.settings.update_game(app_name)
|
||||
|
||||
# DLC Tab: Disable if no dlcs available
|
||||
if len(dlcs[self.core.get_game(app_name).asset_info.catalog_item_id]) == 0:
|
||||
self.setTabEnabled(3, False)
|
||||
else:
|
||||
self.setTabEnabled(3, True)
|
||||
self.dlc_tab.update_dlcs(app_name, dlcs)
|
||||
|
||||
def keyPressEvent(self, e: QKeyEvent):
|
||||
if e.key() == Qt.Key_Escape:
|
||||
self.parent().layout.setCurrentIndex(0)
|
||||
|
|
146
rare/components/tabs/games/game_info/dlcs.py
Normal file
146
rare/components/tabs/games/game_info/dlcs.py
Normal file
|
@ -0,0 +1,146 @@
|
|||
import os
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, QSettings
|
||||
from PyQt5.QtGui import QPixmap
|
||||
from PyQt5.QtWidgets import QGroupBox, QHBoxLayout, QVBoxLayout, QScrollArea, QWidget, QLabel, QPushButton, QMessageBox
|
||||
|
||||
from custom_legendary.core import LegendaryCore
|
||||
from custom_legendary.models.game import Game
|
||||
from rare.components.dialogs.install_dialog import InstallDialog
|
||||
from rare.utils.models import InstallOptions
|
||||
from rare.utils.utils import download_image
|
||||
|
||||
|
||||
class DlcTab(QScrollArea):
|
||||
install_dlc = pyqtSignal(InstallOptions)
|
||||
game: Game
|
||||
|
||||
def __init__(self, core: LegendaryCore):
|
||||
super(DlcTab, self).__init__()
|
||||
self.core = core
|
||||
self.widget = QGroupBox("DLCs")
|
||||
self.widget.setObjectName("group")
|
||||
self.setWidgetResizable(True)
|
||||
self.layout = QVBoxLayout()
|
||||
self.installed_dlcs = [i.app_name for i in self.core.get_installed_dlc_list()]
|
||||
|
||||
self.installed_dlc_widget = QGroupBox(self.tr("Installed DLCs"))
|
||||
self.installed_layout = QVBoxLayout()
|
||||
self.available_dlcs = QGroupBox(self.tr("Available DLCs"))
|
||||
self.available_dlcs_layout = QVBoxLayout()
|
||||
|
||||
self.installed = []
|
||||
self.available = []
|
||||
|
||||
def update_dlcs(self, app_name, dlcs: list[Game]):
|
||||
self.installed_dlcs = [i.app_name for i in self.core.get_installed_dlc_list()]
|
||||
self.installed_dlc_widget = QGroupBox(self.tr("Installed DLCs"))
|
||||
self.installed_layout = QVBoxLayout()
|
||||
self.available_dlcs = QGroupBox(self.tr("Available DLCs"))
|
||||
self.available_dlcs_layout = QVBoxLayout()
|
||||
self.installed = []
|
||||
self.available = []
|
||||
QVBoxLayout().addWidget(self.widget)
|
||||
|
||||
self.game = self.core.get_game(app_name)
|
||||
|
||||
for dlc in sorted(dlcs[self.game.asset_info.catalog_item_id], key=lambda x: x.app_title):
|
||||
if dlc.app_name in self.installed_dlcs:
|
||||
w = DLCWidget(dlc, True)
|
||||
self.installed_layout.addWidget(w)
|
||||
self.installed.append(dlc)
|
||||
else:
|
||||
w = DLCWidget(dlc, False)
|
||||
w.install.connect(self.install)
|
||||
self.available_dlcs_layout.addWidget(w)
|
||||
self.available.append(dlc)
|
||||
if len(self.installed) == 0:
|
||||
self.installed_layout.addWidget(QLabel(self.tr("No DLCs are installed")))
|
||||
if len(self.available) == 0:
|
||||
self.available_dlcs_layout.addWidget(QLabel(self.tr("No DLCs are available")))
|
||||
|
||||
self.widget = QGroupBox("DLCs")
|
||||
self.layout = QVBoxLayout()
|
||||
self.installed_dlc_widget.setLayout(self.installed_layout)
|
||||
self.available_dlcs.setLayout(self.available_dlcs_layout)
|
||||
self.layout.addWidget(self.installed_dlc_widget)
|
||||
self.layout.addWidget(self.available_dlcs)
|
||||
self.layout.addStretch(1)
|
||||
self.widget.setLayout(self.layout)
|
||||
self.setWidget(self.widget)
|
||||
|
||||
def install(self, app_name):
|
||||
if not self.core.is_installed(self.game.app_name):
|
||||
QMessageBox.warning(self, "Error", self.tr("Base Game is not installed. Please install {} first").format(self.game.app_title))
|
||||
return
|
||||
infos = InstallDialog(self.game.app_name, self.core, True).get_information()
|
||||
if infos != 0:
|
||||
path, max_workers, force, ignore_free_space = infos
|
||||
self.install_dlc.emit(
|
||||
InstallOptions(app_name=app_name, max_workers=max_workers, path=path, force=force,
|
||||
ignore_free_space=ignore_free_space))
|
||||
|
||||
|
||||
class DLCWidget(QGroupBox):
|
||||
install = pyqtSignal(str) # Appname
|
||||
|
||||
def __init__(self, dlc: Game, installed: bool):
|
||||
super(DLCWidget, self).__init__()
|
||||
self.main_layout = QHBoxLayout()
|
||||
self.dlc = dlc
|
||||
IMAGE_DIR = QSettings().value("img_dir", os.path.expanduser("~/.cache/rare/images"))
|
||||
if installed:
|
||||
|
||||
if os.path.exists(os.path.join(IMAGE_DIR, dlc.app_name, "FinalArt.png")):
|
||||
pixmap = QPixmap(os.path.join(IMAGE_DIR, dlc.app_name, "FinalArt.png"))
|
||||
elif os.path.exists(os.path.join(IMAGE_DIR, dlc.app_name, "DieselGameBoxTall.png")):
|
||||
pixmap = QPixmap(os.path.join(IMAGE_DIR, dlc.app_name, "DieselGameBoxTall.png"))
|
||||
elif os.path.exists(os.path.join(IMAGE_DIR, dlc.app_name, "DieselGameBoxLogo.png")):
|
||||
pixmap = QPixmap(os.path.join(IMAGE_DIR, dlc.app_name, "DieselGameBoxLogo.png"))
|
||||
else:
|
||||
print(f"No Image found: {dlc.app_title}")
|
||||
pixmap = None
|
||||
if not pixmap or pixmap.isNull():
|
||||
print(dlc.app_title + " has corrupt Image")
|
||||
download_image(dlc, force=True)
|
||||
pixmap = QPixmap(f"{IMAGE_DIR}/{dlc.app_name}/UninstalledArt.png")
|
||||
else:
|
||||
if os.path.exists(f"{IMAGE_DIR}/{dlc.app_name}/UninstalledArt.png"):
|
||||
pixmap = QPixmap(f"{IMAGE_DIR}/{dlc.app_name}/DieselGameBoxTall.png")
|
||||
|
||||
else:
|
||||
pixmap = None
|
||||
|
||||
if not pixmap or pixmap.isNull():
|
||||
print(dlc.app_title + " has corrupt Image")
|
||||
download_image(dlc, force=True)
|
||||
pixmap = QPixmap(f"{IMAGE_DIR}/{dlc.app_name}/UninstalledArt.png")
|
||||
|
||||
image = QLabel()
|
||||
image.setPixmap(pixmap)
|
||||
self.main_layout.addWidget(image)
|
||||
|
||||
self.layout = QVBoxLayout()
|
||||
|
||||
self.layout.addWidget(QLabel(dlc.app_title))
|
||||
self.layout.addWidget(QLabel("Version: " + str(dlc.app_version)))
|
||||
|
||||
self.layout.addWidget(QLabel("App Name: " + dlc.app_name))
|
||||
if not installed:
|
||||
self.install_button = QPushButton(self.tr("Install"))
|
||||
self.layout.addWidget(self.install_button)
|
||||
|
||||
self.install_button.clicked.connect(lambda: self.install.emit(dlc.app_name))
|
||||
else:
|
||||
self.layout.addWidget(QLabel(self.tr("Installed. Uninstalling DLCs is not supported")))
|
||||
|
||||
self.main_layout.addLayout(self.layout)
|
||||
|
||||
self.setLayout(self.main_layout)
|
||||
|
||||
self.layout.addStretch(1)
|
||||
|
||||
def install_game(self):
|
||||
self.install_button.setDisabled(True)
|
||||
self.install_button.setText(self.tr("Installing"))
|
||||
self.install.emit(self.dlc.app_name)
|
|
@ -116,9 +116,10 @@ class GameList(QStackedWidget):
|
|||
uninstalled_games = []
|
||||
installed = [i.app_name for i in self.core.get_installed_list()]
|
||||
# get Uninstalled games
|
||||
for igame in sorted(self.core.get_game_list(), key=lambda x: x.app_title):
|
||||
if not igame.app_name in installed:
|
||||
uninstalled_games.append(igame)
|
||||
games, self.dlcs = self.core.get_game_and_dlc_list()
|
||||
for game in sorted(games, key=lambda x: x.app_title):
|
||||
if not game.app_name in installed:
|
||||
uninstalled_games.append(game)
|
||||
|
||||
# add uninstalled games
|
||||
for igame in uninstalled_games:
|
||||
|
@ -129,7 +130,6 @@ class GameList(QStackedWidget):
|
|||
logger.info(igame.app_title + " has a corrupt image.")
|
||||
download_image(igame, force=True)
|
||||
pixmap = QPixmap(f"{IMAGE_DIR}/{igame.app_name}/UninstalledArt.png")
|
||||
|
||||
else:
|
||||
logger.warning(f"No Image found: {igame.app_title}")
|
||||
download_image(igame, force=True)
|
||||
|
|
|
@ -23,18 +23,22 @@ def download_images(signal: pyqtSignal, core: LegendaryCore):
|
|||
logger.info("Create Image dir")
|
||||
|
||||
# Download Images
|
||||
for i, game in enumerate(sorted(core.get_game_list(), key=lambda x: x.app_title)):
|
||||
|
||||
games, dlcs = core.get_game_and_dlc_list()
|
||||
dlc_list = []
|
||||
for i in dlcs.values():
|
||||
dlc_list.append(i[0])
|
||||
game_list = games + dlc_list
|
||||
for i, game in enumerate(game_list):
|
||||
try:
|
||||
download_image(game)
|
||||
except json.decoder.JSONDecodeError:
|
||||
shutil.rmtree(f"{IMAGE_DIR}/{game.app_name}")
|
||||
download_image(game)
|
||||
signal.emit(i)
|
||||
signal.emit(i/len(game_list)*100)
|
||||
|
||||
|
||||
def download_image(game, force=False):
|
||||
if force:
|
||||
if force and os.path.exists(f"{IMAGE_DIR}/{game.app_name}"):
|
||||
shutil.rmtree(f"{IMAGE_DIR}/{game.app_name}")
|
||||
if not os.path.isdir(f"{IMAGE_DIR}/" + game.app_name):
|
||||
os.mkdir(f"{IMAGE_DIR}/" + game.app_name)
|
||||
|
|
Loading…
Reference in a new issue