2021-02-10 23:48:25 +13:00
|
|
|
import os
|
2022-07-24 10:06:35 +12:00
|
|
|
import platform as pf
|
2022-05-27 22:23:08 +12:00
|
|
|
import sys
|
2022-07-24 10:06:35 +12:00
|
|
|
from typing import Tuple, List, Union, Optional
|
2021-02-10 23:48:25 +13:00
|
|
|
|
2022-09-01 01:57:50 +12:00
|
|
|
from PyQt5.QtCore import Qt, QObject, QRunnable, QThreadPool, pyqtSignal, pyqtSlot, QSettings
|
2022-01-13 11:46:46 +13:00
|
|
|
from PyQt5.QtGui import QCloseEvent, QKeyEvent
|
2022-09-01 02:01:52 +12:00
|
|
|
from PyQt5.QtWidgets import QDialog, QFileDialog, QCheckBox, QLayout
|
2022-07-24 10:06:35 +12:00
|
|
|
from legendary.models.downloading import ConditionCheckResult
|
|
|
|
from legendary.models.game import Game
|
|
|
|
from legendary.utils.selective_dl import get_sdl_appname
|
2022-07-08 05:19:52 +12:00
|
|
|
|
2022-07-11 04:32:42 +12:00
|
|
|
from rare.lgndr.api_arguments import LgndrInstallGameArgs
|
2022-07-11 22:22:17 +12:00
|
|
|
from rare.lgndr.api_exception import LgndrException
|
2022-07-24 10:06:35 +12:00
|
|
|
from rare.lgndr.api_monkeys import LgndrIndirectStatus
|
2022-08-01 09:55:21 +12:00
|
|
|
from rare.lgndr.cli import LegendaryCLI
|
2022-04-19 02:51:51 +12:00
|
|
|
from rare.lgndr.core import LegendaryCore
|
2022-08-01 09:55:21 +12:00
|
|
|
from rare.models.install import InstallDownloadModel, InstallQueueItemModel
|
2022-08-01 23:31:07 +12:00
|
|
|
from rare.shared import LegendaryCoreSingleton, ApiResultsSingleton, ArgumentsSingleton
|
2021-05-21 11:47:03 +12:00
|
|
|
from rare.ui.components.dialogs.install_dialog import Ui_InstallDialog
|
2022-08-01 09:55:21 +12:00
|
|
|
from rare.utils import config_helper
|
2021-04-23 00:34:06 +12:00
|
|
|
from rare.utils.extra_widgets import PathEdit
|
2022-07-27 02:58:17 +12:00
|
|
|
from rare.utils.misc import get_size
|
2022-08-01 09:55:21 +12:00
|
|
|
from rare.widgets.collabsible_widget import CollabsibleWidget
|
2021-02-10 23:48:25 +13:00
|
|
|
|
|
|
|
|
2022-09-01 02:01:52 +12:00
|
|
|
class InstallDialog(QDialog):
|
2021-05-26 08:37:50 +12:00
|
|
|
result_ready = pyqtSignal(InstallQueueItemModel)
|
2021-02-18 05:46:03 +13:00
|
|
|
|
2022-08-01 08:00:50 +12:00
|
|
|
def __init__(self, dl_item: InstallQueueItemModel, update=False, repair=False, silent=False, parent=None):
|
2021-05-23 05:52:58 +12:00
|
|
|
super(InstallDialog, self).__init__(parent)
|
|
|
|
self.setAttribute(Qt.WA_DeleteOnClose, True)
|
2021-05-24 07:50:31 +12:00
|
|
|
self.setWindowFlags(Qt.Dialog | Qt.CustomizeWindowHint | Qt.WindowTitleHint)
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui = Ui_InstallDialog()
|
|
|
|
self.ui.setupUi(self)
|
2021-05-21 11:47:03 +12:00
|
|
|
|
2022-02-26 06:43:27 +13:00
|
|
|
self.core = LegendaryCoreSingleton()
|
|
|
|
self.api_results = ApiResultsSingleton()
|
2021-05-24 00:15:36 +12:00
|
|
|
self.dl_item = dl_item
|
|
|
|
self.app_name = self.dl_item.options.app_name
|
2022-05-27 22:23:08 +12:00
|
|
|
self.game = (
|
|
|
|
self.core.get_game(self.app_name)
|
|
|
|
if not self.dl_item.options.overlay
|
2022-01-13 11:46:46 +13:00
|
|
|
else Game(app_name=self.app_name, app_title="Epic Overlay")
|
2022-05-27 22:23:08 +12:00
|
|
|
)
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.advanced_layout.setParent(None)
|
2022-08-01 09:55:21 +12:00
|
|
|
self.advanced_widget = CollabsibleWidget(
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.advanced_layout, self.tr("Advanced options"), parent=self
|
2022-08-01 09:55:21 +12:00
|
|
|
)
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.collapsible_layout.addWidget(self.advanced_widget)
|
2022-01-16 04:44:22 +13:00
|
|
|
|
2022-05-27 22:23:08 +12:00
|
|
|
self.game_path = self.game.metadata.get("customAttributes", {}).get("FolderName", {}).get("value", "")
|
2022-01-14 07:49:39 +13:00
|
|
|
|
2021-05-26 08:37:50 +12:00
|
|
|
self.update = update
|
2022-08-01 08:00:50 +12:00
|
|
|
self.repair = repair
|
2021-05-26 08:37:50 +12:00
|
|
|
self.silent = silent
|
2021-05-21 11:47:03 +12:00
|
|
|
|
2021-10-13 08:11:52 +13:00
|
|
|
self.options_changed = False
|
|
|
|
self.worker_running = False
|
|
|
|
self.reject_close = True
|
|
|
|
|
2021-05-23 09:07:47 +12:00
|
|
|
self.threadpool = QThreadPool(self)
|
|
|
|
self.threadpool.setMaxThreadCount(1)
|
2021-05-21 11:47:03 +12:00
|
|
|
|
2021-05-22 02:48:15 +12:00
|
|
|
header = self.tr("Update") if update else self.tr("Install")
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.install_dialog_label.setText(f'<h3>{header} "{self.game.app_title}"</h3>')
|
2021-12-24 22:09:50 +13:00
|
|
|
self.setWindowTitle(f'{self.windowTitle()} - {header} "{self.game.app_title}"')
|
2021-04-05 21:53:33 +12:00
|
|
|
|
2022-01-14 07:01:52 +13:00
|
|
|
if not self.dl_item.options.base_path:
|
2022-05-27 22:23:08 +12:00
|
|
|
self.dl_item.options.base_path = self.core.lgd.config.get(
|
|
|
|
"Legendary", "install_dir", fallback=os.path.expanduser("~/legendary")
|
|
|
|
)
|
2021-05-21 11:47:03 +12:00
|
|
|
|
2021-12-24 22:09:50 +13:00
|
|
|
self.install_dir_edit = PathEdit(
|
2022-01-14 07:01:52 +13:00
|
|
|
path=self.dl_item.options.base_path,
|
2021-12-24 22:09:50 +13:00
|
|
|
file_type=QFileDialog.DirectoryOnly,
|
|
|
|
edit_func=self.option_changed,
|
|
|
|
parent=self,
|
|
|
|
)
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.install_dir_layout.addWidget(self.install_dir_edit)
|
2021-05-21 11:47:03 +12:00
|
|
|
|
2021-05-26 08:37:50 +12:00
|
|
|
if self.update:
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.install_dir_label.setVisible(False)
|
2021-05-22 02:48:15 +12:00
|
|
|
self.install_dir_edit.setVisible(False)
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.shortcut_lbl.setVisible(False)
|
|
|
|
self.ui.shortcut_cb.setVisible(False)
|
2022-09-01 01:57:50 +12:00
|
|
|
else:
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.shortcut_cb.setChecked(QSettings().value("create_shortcut", True, bool))
|
2021-02-10 23:48:25 +13:00
|
|
|
|
2022-05-27 22:23:08 +12:00
|
|
|
self.error_box()
|
2021-06-08 01:42:49 +12:00
|
|
|
|
2021-12-04 13:11:20 +13:00
|
|
|
platforms = ["Windows"]
|
2022-02-26 06:43:27 +13:00
|
|
|
if dl_item.options.app_name in self.api_results.bit32_games:
|
2021-12-04 13:11:20 +13:00
|
|
|
platforms.append("Win32")
|
2022-02-26 06:43:27 +13:00
|
|
|
if dl_item.options.app_name in self.api_results.mac_games:
|
2021-12-04 13:11:20 +13:00
|
|
|
platforms.append("Mac")
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.platform_combo_box.addItems(platforms)
|
|
|
|
self.ui.platform_combo_box.currentIndexChanged.connect(lambda: self.option_changed(None))
|
|
|
|
self.ui.platform_combo_box.currentIndexChanged.connect(lambda: self.error_box())
|
|
|
|
self.ui.platform_combo_box.currentIndexChanged.connect(
|
2022-05-27 22:23:08 +12:00
|
|
|
lambda i: self.error_box(
|
|
|
|
self.tr("Warning"),
|
2022-07-24 10:06:35 +12:00
|
|
|
self.tr("You will not be able to run the game if you select <b>{}</b> as platform").format(
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.platform_combo_box.itemText(i)
|
2021-12-24 22:09:50 +13:00
|
|
|
),
|
|
|
|
)
|
2022-09-01 02:01:52 +12:00
|
|
|
if (self.ui.platform_combo_box.currentText() == "Mac" and pf.system() != "Darwin")
|
2021-12-24 22:09:50 +13:00
|
|
|
else None
|
|
|
|
)
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.platform_combo_box.currentTextChanged.connect(self.setup_sdl_list)
|
2021-12-06 08:11:11 +13:00
|
|
|
|
2022-07-24 10:06:35 +12:00
|
|
|
if pf.system() == "Darwin" and "Mac" in platforms:
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.platform_combo_box.setCurrentIndex(platforms.index("Mac"))
|
2021-12-04 13:11:20 +13:00
|
|
|
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.max_workers_spin.setValue(self.core.lgd.config.getint("Legendary", "max_workers", fallback=0))
|
|
|
|
self.ui.max_workers_spin.valueChanged.connect(self.option_changed)
|
2021-05-24 00:52:39 +12:00
|
|
|
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.max_memory_spin.setValue(self.core.lgd.config.getint("Legendary", "max_memory", fallback=0))
|
|
|
|
self.ui.max_memory_spin.valueChanged.connect(self.option_changed)
|
2022-05-27 08:03:17 +12:00
|
|
|
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.dl_optimizations_check.stateChanged.connect(self.option_changed)
|
|
|
|
self.ui.force_download_check.stateChanged.connect(self.option_changed)
|
|
|
|
self.ui.ignore_space_check.stateChanged.connect(self.option_changed)
|
|
|
|
self.ui.download_only_check.stateChanged.connect(lambda: self.non_reload_option_changed("download_only"))
|
|
|
|
self.ui.shortcut_cb.stateChanged.connect(lambda: self.non_reload_option_changed("shortcut"))
|
2022-07-24 10:06:35 +12:00
|
|
|
|
|
|
|
self.sdl_list_cbs: List[TagCheckBox] = []
|
|
|
|
self.config_tags: Optional[List[str]] = None
|
|
|
|
self.setup_sdl_list("Mac" if pf.system() == "Darwin" and "Mac" in platforms else "Windows")
|
2021-05-22 02:48:15 +12:00
|
|
|
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.install_button.setEnabled(False)
|
2021-02-10 23:48:25 +13:00
|
|
|
|
2022-01-13 11:46:46 +13:00
|
|
|
if self.dl_item.options.overlay:
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.platform_label.setVisible(False)
|
|
|
|
self.ui.platform_combo_box.setVisible(False)
|
|
|
|
self.ui.ignore_space_check.setVisible(False)
|
|
|
|
self.ui.ignore_space_label.setVisible(False)
|
|
|
|
self.ui.download_only_check.setVisible(False)
|
|
|
|
self.ui.download_only_label.setVisible(False)
|
|
|
|
self.ui.shortcut_cb.setVisible(False)
|
|
|
|
self.ui.shortcut_lbl.setVisible(False)
|
2022-02-05 10:12:00 +13:00
|
|
|
|
2022-07-24 10:06:35 +12:00
|
|
|
if pf.system() == "Darwin":
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.shortcut_cb.setDisabled(True)
|
|
|
|
self.ui.shortcut_cb.setChecked(False)
|
|
|
|
self.ui.shortcut_cb.setToolTip(self.tr("Creating a shortcut is not supported on MacOS"))
|
2022-02-05 10:12:00 +13:00
|
|
|
|
2022-09-01 20:49:42 +12:00
|
|
|
self.ui.install_prereqs_lbl.setVisible(False)
|
|
|
|
self.ui.install_prereqs_check.setVisible(False)
|
|
|
|
self.ui.install_prereqs_check.stateChanged.connect(lambda: self.non_reload_option_changed("install_prereqs"))
|
2022-04-13 10:56:45 +12:00
|
|
|
|
2022-02-05 10:12:00 +13:00
|
|
|
self.non_reload_option_changed("shortcut")
|
2022-01-13 11:46:46 +13:00
|
|
|
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.cancel_button.clicked.connect(self.cancel_clicked)
|
|
|
|
self.ui.verify_button.clicked.connect(self.verify_clicked)
|
|
|
|
self.ui.install_button.clicked.connect(self.install_clicked)
|
2021-05-24 04:38:33 +12:00
|
|
|
|
2022-09-01 20:49:42 +12:00
|
|
|
self.ui.install_prereqs_check.setChecked(self.dl_item.options.install_prereqs)
|
2022-08-11 10:47:55 +12:00
|
|
|
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.install_dialog_layout.setSizeConstraint(QLayout.SetFixedSize)
|
2021-08-17 06:41:33 +12:00
|
|
|
|
2021-05-26 18:37:55 +12:00
|
|
|
def execute(self):
|
2021-05-26 08:37:50 +12:00
|
|
|
if self.silent:
|
|
|
|
self.reject_close = False
|
|
|
|
self.get_download_info()
|
|
|
|
else:
|
2021-09-11 09:30:59 +12:00
|
|
|
self.verify_clicked()
|
2021-05-26 08:37:50 +12:00
|
|
|
self.show()
|
|
|
|
|
2022-07-24 10:06:35 +12:00
|
|
|
@pyqtSlot(str)
|
|
|
|
def setup_sdl_list(self, platform="Windows"):
|
|
|
|
for cb in self.sdl_list_cbs:
|
|
|
|
cb.disconnect()
|
|
|
|
cb.deleteLater()
|
|
|
|
self.sdl_list_cbs.clear()
|
|
|
|
|
|
|
|
if config_tags := self.core.lgd.config.get(self.game.app_name, 'install_tags', fallback=None):
|
|
|
|
self.config_tags = config_tags.split(",")
|
|
|
|
config_disable_sdl = self.core.lgd.config.getboolean(self.game.app_name, 'disable_sdl', fallback=False)
|
|
|
|
sdl_name = get_sdl_appname(self.game.app_name)
|
|
|
|
if not config_disable_sdl and sdl_name is not None:
|
|
|
|
# FIXME: this should be updated whenever platform changes
|
|
|
|
sdl_data = self.core.get_sdl_data(sdl_name, platform=platform)
|
|
|
|
if sdl_data:
|
|
|
|
for tag, info in sdl_data.items():
|
|
|
|
cb = TagCheckBox(info["name"], info["tags"])
|
|
|
|
if tag == "__required":
|
|
|
|
cb.setChecked(True)
|
|
|
|
cb.setDisabled(True)
|
2022-08-01 19:30:31 +12:00
|
|
|
if self.config_tags is not None:
|
|
|
|
if all(elem in self.config_tags for elem in info["tags"]):
|
|
|
|
cb.setChecked(True)
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.sdl_list_layout.addWidget(cb)
|
2022-07-24 10:06:35 +12:00
|
|
|
self.sdl_list_cbs.append(cb)
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.sdl_list_layout.setSizeConstraint(QLayout.SetFixedSize)
|
2022-07-24 10:06:35 +12:00
|
|
|
for cb in self.sdl_list_cbs:
|
|
|
|
cb.stateChanged.connect(self.option_changed)
|
|
|
|
else:
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.sdl_list_frame.setVisible(False)
|
|
|
|
self.ui.sdl_list_label.setVisible(False)
|
2022-07-24 10:06:35 +12:00
|
|
|
|
2021-05-24 00:15:36 +12:00
|
|
|
def get_options(self):
|
2022-05-27 22:23:08 +12:00
|
|
|
self.dl_item.options.base_path = self.install_dir_edit.text() if not self.update else None
|
2022-01-13 11:46:46 +13:00
|
|
|
|
2022-09-01 02:01:52 +12:00
|
|
|
self.dl_item.options.max_workers = self.ui.max_workers_spin.value()
|
|
|
|
self.dl_item.options.shared_memory = self.ui.max_memory_spin.value()
|
|
|
|
self.dl_item.options.order_opt = self.ui.dl_optimizations_check.isChecked()
|
|
|
|
self.dl_item.options.force = self.ui.force_download_check.isChecked()
|
|
|
|
self.dl_item.options.ignore_space = self.ui.ignore_space_check.isChecked()
|
|
|
|
self.dl_item.options.no_install = self.ui.download_only_check.isChecked()
|
|
|
|
self.dl_item.options.platform = self.ui.platform_combo_box.currentText()
|
2022-09-01 20:49:42 +12:00
|
|
|
self.dl_item.options.install_prereqs = self.ui.install_prereqs_check.isChecked()
|
2022-09-01 02:01:52 +12:00
|
|
|
self.dl_item.options.create_shortcut = self.ui.shortcut_cb.isChecked()
|
2022-07-24 10:06:35 +12:00
|
|
|
if self.sdl_list_cbs:
|
|
|
|
self.dl_item.options.install_tag = [""]
|
|
|
|
for cb in self.sdl_list_cbs:
|
|
|
|
if data := cb.isChecked():
|
|
|
|
# noinspection PyTypeChecker
|
|
|
|
self.dl_item.options.install_tag.extend(data)
|
2021-05-24 00:15:36 +12:00
|
|
|
|
|
|
|
def get_download_info(self):
|
2021-05-26 08:37:50 +12:00
|
|
|
self.dl_item.download = None
|
2022-01-13 11:46:46 +13:00
|
|
|
info_worker = InstallInfoWorker(self.core, self.dl_item, self.game)
|
2021-05-26 08:37:50 +12:00
|
|
|
info_worker.setAutoDelete(True)
|
|
|
|
info_worker.signals.result.connect(self.on_worker_result)
|
|
|
|
info_worker.signals.failed.connect(self.on_worker_failed)
|
|
|
|
info_worker.signals.finished.connect(self.on_worker_finished)
|
|
|
|
self.worker_running = True
|
|
|
|
self.threadpool.start(info_worker)
|
|
|
|
|
|
|
|
def verify_clicked(self):
|
2022-05-27 22:23:08 +12:00
|
|
|
self.error_box()
|
2021-05-22 02:48:15 +12:00
|
|
|
message = self.tr("Updating...")
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.download_size_info_label.setText(message)
|
|
|
|
self.ui.download_size_info_label.setStyleSheet("font-style: italic; font-weight: normal")
|
|
|
|
self.ui.install_size_info_label.setText(message)
|
|
|
|
self.ui.install_size_info_label.setStyleSheet("font-style: italic; font-weight: normal")
|
|
|
|
self.ui.cancel_button.setEnabled(False)
|
|
|
|
self.ui.verify_button.setEnabled(False)
|
|
|
|
self.ui.install_button.setEnabled(False)
|
2021-05-24 04:38:33 +12:00
|
|
|
self.options_changed = False
|
2021-05-26 08:37:50 +12:00
|
|
|
self.get_options()
|
|
|
|
self.get_download_info()
|
2021-05-21 11:47:03 +12:00
|
|
|
|
2022-01-14 07:49:39 +13:00
|
|
|
def option_changed(self, path) -> Tuple[bool, str, str]:
|
2021-05-24 04:38:33 +12:00
|
|
|
self.options_changed = True
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.install_button.setEnabled(False)
|
|
|
|
self.ui.verify_button.setEnabled(not self.worker_running)
|
2022-01-14 07:49:39 +13:00
|
|
|
return True, path, ""
|
2021-05-24 04:38:33 +12:00
|
|
|
|
2021-10-15 10:57:57 +13:00
|
|
|
def non_reload_option_changed(self, option: str):
|
|
|
|
if option == "download_only":
|
2022-09-01 02:01:52 +12:00
|
|
|
self.dl_item.options.no_install = self.ui.download_only_check.isChecked()
|
2022-02-05 10:12:00 +13:00
|
|
|
elif option == "shortcut":
|
2022-09-01 02:01:52 +12:00
|
|
|
QSettings().setValue("create_shortcut", self.ui.shortcut_cb.isChecked())
|
|
|
|
self.dl_item.options.create_shortcut = self.ui.shortcut_cb.isChecked()
|
2022-09-01 20:49:42 +12:00
|
|
|
elif option == "install_prereqs":
|
|
|
|
self.dl_item.options.install_prereqs = self.ui.install_prereqs_check.isChecked()
|
2021-10-15 10:57:57 +13:00
|
|
|
|
2021-05-26 08:37:50 +12:00
|
|
|
def cancel_clicked(self):
|
2022-07-24 10:06:35 +12:00
|
|
|
if self.config_tags:
|
2022-07-27 03:45:27 +12:00
|
|
|
config_helper.add_option(self.game.app_name, 'install_tags', ','.join(self.config_tags))
|
2022-07-24 10:06:35 +12:00
|
|
|
else:
|
|
|
|
# lk: this is purely for cleaning any install tags we might have added erroneously to the config
|
2022-07-27 03:45:27 +12:00
|
|
|
config_helper.remove_option(self.game.app_name, 'install_tags')
|
2022-07-24 10:06:35 +12:00
|
|
|
|
2021-05-24 04:38:33 +12:00
|
|
|
self.dl_item.download = None
|
2021-05-26 08:37:50 +12:00
|
|
|
self.reject_close = False
|
2021-02-18 05:46:03 +13:00
|
|
|
self.close()
|
|
|
|
|
2021-05-26 08:37:50 +12:00
|
|
|
def install_clicked(self):
|
|
|
|
self.reject_close = False
|
2021-05-21 11:47:03 +12:00
|
|
|
self.close()
|
2021-02-18 05:46:03 +13:00
|
|
|
|
2021-05-26 08:37:50 +12:00
|
|
|
def on_worker_result(self, dl_item: InstallDownloadModel):
|
|
|
|
self.dl_item.download = dl_item
|
|
|
|
download_size = self.dl_item.download.analysis.dl_size
|
|
|
|
install_size = self.dl_item.download.analysis.install_size
|
|
|
|
if download_size:
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.download_size_info_label.setText("{}".format(get_size(download_size)))
|
|
|
|
self.ui.download_size_info_label.setStyleSheet("font-style: normal; font-weight: bold")
|
|
|
|
self.ui.install_button.setEnabled(not self.options_changed)
|
2021-05-21 11:47:03 +12:00
|
|
|
else:
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.install_size_info_label.setText(self.tr("Game already installed"))
|
|
|
|
self.ui.install_size_info_label.setStyleSheet("font-style: italics; font-weight: normal")
|
|
|
|
self.ui.install_size_info_label.setText("{}".format(get_size(install_size)))
|
|
|
|
self.ui.install_size_info_label.setStyleSheet("font-style: normal; font-weight: bold")
|
|
|
|
self.ui.verify_button.setEnabled(self.options_changed)
|
|
|
|
self.ui.cancel_button.setEnabled(True)
|
2022-07-24 10:06:35 +12:00
|
|
|
if pf.system() == "Windows" or ArgumentsSingleton().debug:
|
2022-04-13 10:56:45 +12:00
|
|
|
if dl_item.igame.prereq_info and not dl_item.igame.prereq_info.get("installed", False):
|
2022-09-01 20:49:42 +12:00
|
|
|
self.ui.install_prereqs_check.setVisible(True)
|
|
|
|
self.ui.install_prereqs_lbl.setVisible(True)
|
|
|
|
self.ui.install_prereqs_check.setChecked(True)
|
|
|
|
self.ui.install_prereqs_check.setText(
|
2022-05-27 22:23:08 +12:00
|
|
|
self.tr("Also install: {}").format(dl_item.igame.prereq_info.get("name", ""))
|
|
|
|
)
|
2022-09-01 01:57:50 +12:00
|
|
|
if self.silent:
|
|
|
|
self.close()
|
2021-05-26 08:37:50 +12:00
|
|
|
|
|
|
|
def on_worker_failed(self, message: str):
|
|
|
|
error_text = self.tr("Error")
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.download_size_info_label.setText(error_text)
|
|
|
|
self.ui.install_size_info_label.setText(error_text)
|
2022-05-27 22:23:08 +12:00
|
|
|
self.error_box(error_text, message)
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.verify_button.setEnabled(self.options_changed)
|
|
|
|
self.ui.cancel_button.setEnabled(True)
|
2021-05-26 08:49:53 +12:00
|
|
|
if self.silent:
|
2022-09-01 01:57:50 +12:00
|
|
|
self.show()
|
2021-02-18 05:46:03 +13:00
|
|
|
|
2022-05-27 22:23:08 +12:00
|
|
|
def error_box(self, label: str = "", message: str = ""):
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.warn_label.setVisible(bool(label))
|
|
|
|
self.ui.warn_label.setText(label)
|
|
|
|
self.ui.warn_message.setVisible(bool(message))
|
|
|
|
self.ui.warn_message.setText(message)
|
2022-05-27 22:23:08 +12:00
|
|
|
|
2021-05-26 08:37:50 +12:00
|
|
|
def on_worker_finished(self):
|
|
|
|
self.worker_running = False
|
|
|
|
|
|
|
|
# lk: happens when close() is called, also when top right 'X' is pressed.
|
2021-05-26 08:49:53 +12:00
|
|
|
# lk: reject any events not coming from the buttons in case the WM
|
2021-05-26 08:37:50 +12:00
|
|
|
# lk: doesn't honor the window hints
|
2021-05-24 04:38:33 +12:00
|
|
|
def closeEvent(self, a0: QCloseEvent) -> None:
|
2021-05-26 08:37:50 +12:00
|
|
|
if self.reject_close:
|
|
|
|
a0.ignore()
|
|
|
|
else:
|
|
|
|
self.threadpool.clear()
|
|
|
|
self.threadpool.waitForDone()
|
|
|
|
self.result_ready.emit(self.dl_item)
|
|
|
|
a0.accept()
|
2021-05-24 04:38:33 +12:00
|
|
|
|
2022-01-13 11:46:46 +13:00
|
|
|
def keyPressEvent(self, e: QKeyEvent) -> None:
|
|
|
|
if e.key() == Qt.Key_Escape:
|
|
|
|
self.cancel_clicked()
|
|
|
|
|
2021-02-18 05:46:03 +13:00
|
|
|
|
2022-05-06 00:25:28 +12:00
|
|
|
class InstallInfoWorker(QRunnable):
|
|
|
|
class Signals(QObject):
|
|
|
|
result = pyqtSignal(InstallDownloadModel)
|
|
|
|
failed = pyqtSignal(str)
|
|
|
|
finished = pyqtSignal()
|
2021-02-18 05:46:03 +13:00
|
|
|
|
2022-01-13 11:46:46 +13:00
|
|
|
def __init__(self, core: LegendaryCore, dl_item: InstallQueueItemModel, game: Game = None):
|
2022-05-27 22:23:08 +12:00
|
|
|
sys.excepthook = sys.__excepthook__
|
2021-05-21 11:47:03 +12:00
|
|
|
super(InstallInfoWorker, self).__init__()
|
2022-05-06 00:25:28 +12:00
|
|
|
self.signals = InstallInfoWorker.Signals()
|
2021-05-21 11:47:03 +12:00
|
|
|
self.core = core
|
2021-05-24 00:15:36 +12:00
|
|
|
self.dl_item = dl_item
|
2022-01-13 11:46:46 +13:00
|
|
|
self.game = game
|
2021-05-21 11:47:03 +12:00
|
|
|
|
|
|
|
@pyqtSlot()
|
|
|
|
def run(self):
|
|
|
|
try:
|
2022-07-24 10:06:35 +12:00
|
|
|
if not self.dl_item.options.overlay:
|
2022-08-01 23:31:07 +12:00
|
|
|
cli = LegendaryCLI(self.core)
|
2022-07-24 10:06:35 +12:00
|
|
|
status = LgndrIndirectStatus()
|
|
|
|
result = cli.install_game(
|
|
|
|
LgndrInstallGameArgs(**self.dl_item.options.as_install_kwargs(), indirect_status=status)
|
2022-01-13 11:46:46 +13:00
|
|
|
)
|
2022-07-24 10:06:35 +12:00
|
|
|
if result:
|
|
|
|
download = InstallDownloadModel(*result)
|
|
|
|
else:
|
|
|
|
raise LgndrException(status.message)
|
2022-01-13 11:46:46 +13:00
|
|
|
else:
|
|
|
|
if not os.path.exists(path := self.dl_item.options.base_path):
|
|
|
|
os.makedirs(path)
|
|
|
|
|
|
|
|
dlm, analysis, igame = self.core.prepare_overlay_install(
|
2022-07-24 10:06:35 +12:00
|
|
|
path=self.dl_item.options.base_path
|
2021-12-24 22:09:50 +13:00
|
|
|
)
|
2022-01-13 11:46:46 +13:00
|
|
|
|
|
|
|
download = InstallDownloadModel(
|
2022-08-26 20:38:13 +12:00
|
|
|
dlm=dlm,
|
2022-01-13 11:46:46 +13:00
|
|
|
analysis=analysis,
|
|
|
|
igame=igame,
|
2022-06-27 04:07:16 +12:00
|
|
|
game=self.game,
|
2022-01-13 11:46:46 +13:00
|
|
|
repair=False,
|
|
|
|
repair_file="",
|
2022-05-27 22:23:08 +12:00
|
|
|
res=ConditionCheckResult(), # empty
|
2022-01-13 11:46:46 +13:00
|
|
|
)
|
|
|
|
|
|
|
|
if not download.res or not download.res.failures:
|
2021-06-08 01:42:49 +12:00
|
|
|
self.signals.result.emit(download)
|
|
|
|
else:
|
2022-05-27 22:23:08 +12:00
|
|
|
self.signals.failed.emit("\n".join(str(i) for i in download.res.failures))
|
2022-07-11 22:22:17 +12:00
|
|
|
except LgndrException as ret:
|
|
|
|
self.signals.failed.emit(ret.message)
|
2021-05-30 03:24:33 +12:00
|
|
|
except Exception as e:
|
2021-05-26 08:37:50 +12:00
|
|
|
self.signals.failed.emit(str(e))
|
|
|
|
self.signals.finished.emit()
|
2021-05-22 02:48:15 +12:00
|
|
|
|
|
|
|
|
2022-07-24 10:06:35 +12:00
|
|
|
class TagCheckBox(QCheckBox):
|
|
|
|
def __init__(self, text, tags: List[str], parent=None):
|
|
|
|
super(TagCheckBox, self).__init__(parent)
|
2021-05-22 02:48:15 +12:00
|
|
|
self.setText(text)
|
2022-07-24 10:06:35 +12:00
|
|
|
self.tags = tags
|
2021-05-22 02:48:15 +12:00
|
|
|
|
2022-07-24 10:06:35 +12:00
|
|
|
def isChecked(self) -> Union[bool, List[str]]:
|
|
|
|
if super(TagCheckBox, self).isChecked():
|
|
|
|
return self.tags
|
2021-05-22 02:48:15 +12:00
|
|
|
else:
|
|
|
|
return False
|