2021-02-10 23:48:25 +13:00
|
|
|
import os
|
2022-07-24 10:06:35 +12:00
|
|
|
import platform as pf
|
2023-04-17 04:38:57 +12:00
|
|
|
import shutil
|
2022-07-24 10:06:35 +12:00
|
|
|
from typing import Tuple, List, Union, Optional
|
2021-02-10 23:48:25 +13:00
|
|
|
|
2023-02-19 06:36:49 +13:00
|
|
|
from PyQt5.QtCore import Qt, QThreadPool, QSettings, QCoreApplication
|
2023-01-27 09:03:38 +13:00
|
|
|
from PyQt5.QtCore import pyqtSignal, pyqtSlot
|
2022-01-13 11:46:46 +13:00
|
|
|
from PyQt5.QtGui import QCloseEvent, QKeyEvent
|
2023-02-19 06:36:49 +13:00
|
|
|
from PyQt5.QtWidgets import QDialog, QFileDialog, QCheckBox, QLayout, QWidget, QVBoxLayout
|
2022-07-24 10:06:35 +12:00
|
|
|
from legendary.utils.selective_dl import get_sdl_appname
|
2022-07-08 05:19:52 +12:00
|
|
|
|
2023-01-21 13:15:06 +13:00
|
|
|
from rare.models.game import RareGame
|
|
|
|
from rare.models.install import InstallDownloadModel, InstallQueueItemModel, InstallOptionsModel
|
|
|
|
from rare.shared import LegendaryCoreSingleton, ArgumentsSingleton
|
2023-01-27 09:03:38 +13:00
|
|
|
from rare.shared.workers.install_info import InstallInfoWorker
|
2021-05-21 11:47:03 +12:00
|
|
|
from rare.ui.components.dialogs.install_dialog import Ui_InstallDialog
|
2022-11-01 03:54:40 +13:00
|
|
|
from rare.ui.components.dialogs.install_dialog_advanced import Ui_InstallDialogAdvanced
|
2022-08-01 09:55:21 +12:00
|
|
|
from rare.utils import config_helper
|
2023-03-05 07:56:04 +13:00
|
|
|
from rare.utils.misc import format_size
|
2022-11-01 03:54:40 +13:00
|
|
|
from rare.widgets.collapsible_widget import CollapsibleFrame
|
2023-02-19 04:29:41 +13:00
|
|
|
from rare.widgets.indicator_edit import PathEdit, IndicatorReasonsCommon
|
2022-11-01 03:54:40 +13:00
|
|
|
|
|
|
|
|
|
|
|
class InstallDialogAdvanced(CollapsibleFrame):
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
widget = QWidget()
|
2022-12-26 07:02:04 +13:00
|
|
|
title = widget.tr("Advanced options")
|
2022-11-01 03:54:40 +13:00
|
|
|
self.ui = Ui_InstallDialogAdvanced()
|
|
|
|
self.ui.setupUi(widget)
|
|
|
|
super(InstallDialogAdvanced, self).__init__(widget=widget, title=title, parent=parent)
|
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
|
|
|
|
2023-01-26 00:04:21 +13:00
|
|
|
def __init__(self, rgame: RareGame, options: InstallOptionsModel, parent=None):
|
|
|
|
super(InstallDialog, self).__init__(parent=parent)
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui = Ui_InstallDialog()
|
|
|
|
self.ui.setupUi(self)
|
2023-01-26 03:43:06 +13:00
|
|
|
self.setAttribute(Qt.WA_DeleteOnClose, True)
|
|
|
|
self.setWindowFlags(Qt.Dialog | Qt.CustomizeWindowHint | Qt.WindowTitleHint)
|
2023-01-27 02:49:19 +13:00
|
|
|
# lk: set object names for CSS properties
|
|
|
|
self.ui.install_button.setObjectName("InstallButton")
|
2021-05-21 11:47:03 +12:00
|
|
|
|
2022-02-26 06:43:27 +13:00
|
|
|
self.core = LegendaryCoreSingleton()
|
2023-01-21 13:15:06 +13:00
|
|
|
self.rgame = rgame
|
|
|
|
self.options = options
|
|
|
|
self.__download: Optional[InstallDownloadModel] = None
|
2022-11-01 03:54:40 +13:00
|
|
|
|
|
|
|
self.advanced = InstallDialogAdvanced(parent=self)
|
|
|
|
self.ui.advanced_layout.addWidget(self.advanced)
|
|
|
|
|
|
|
|
self.selectable = CollapsibleFrame(widget=None, title=self.tr("Optional downloads"), parent=self)
|
|
|
|
self.ui.selectable_layout.addWidget(self.selectable)
|
2022-01-16 04:44:22 +13: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
|
|
|
|
2023-01-21 13:15:06 +13:00
|
|
|
if options.repair_mode:
|
|
|
|
header = self.tr("Repair")
|
|
|
|
if options.repair_and_update:
|
|
|
|
header = self.tr("Repair and update")
|
|
|
|
elif options.update:
|
|
|
|
header = self.tr("Update")
|
|
|
|
else:
|
|
|
|
header = self.tr("Install")
|
|
|
|
self.ui.install_dialog_label.setText(f'<h3>{header} "{self.rgame.app_title}"</h3>')
|
2023-02-19 06:36:49 +13:00
|
|
|
self.setWindowTitle(f'{header} "{self.rgame.app_title}" - {QCoreApplication.instance().applicationName()}')
|
2021-04-05 21:53:33 +12:00
|
|
|
|
2023-01-21 13:15:06 +13:00
|
|
|
if not self.options.base_path:
|
|
|
|
self.options.base_path = self.core.lgd.config.get(
|
2022-05-27 22:23:08 +12:00
|
|
|
"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(
|
2023-01-21 13:15:06 +13:00
|
|
|
path=self.options.base_path,
|
2023-03-16 09:49:18 +13:00
|
|
|
file_mode=QFileDialog.DirectoryOnly,
|
2021-12-24 22:09:50 +13:00
|
|
|
edit_func=self.option_changed,
|
2023-04-17 04:38:57 +12:00
|
|
|
save_func=self.save_install_edit,
|
2021-12-24 22:09:50 +13:00
|
|
|
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
|
|
|
|
2023-01-21 13:15:06 +13:00
|
|
|
if self.options.update:
|
2022-10-24 07:36:44 +13:00
|
|
|
self.ui.install_dir_label.setEnabled(False)
|
|
|
|
self.install_dir_edit.setEnabled(False)
|
|
|
|
self.ui.shortcut_label.setEnabled(False)
|
|
|
|
self.ui.shortcut_check.setEnabled(False)
|
2022-09-01 01:57:50 +12:00
|
|
|
else:
|
2022-10-24 07:36:44 +13:00
|
|
|
self.ui.shortcut_check.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"]
|
2023-01-21 13:15:06 +13:00
|
|
|
if self.rgame.is_win32:
|
2021-12-04 13:11:20 +13:00
|
|
|
platforms.append("Win32")
|
2023-01-21 13:15:06 +13:00
|
|
|
if self.rgame.is_mac:
|
2021-12-04 13:11:20 +13:00
|
|
|
platforms.append("Mac")
|
2022-10-24 07:36:44 +13:00
|
|
|
self.ui.platform_combo.addItems(platforms)
|
|
|
|
self.ui.platform_combo.currentIndexChanged.connect(lambda: self.option_changed(None))
|
|
|
|
self.ui.platform_combo.currentIndexChanged.connect(lambda: self.error_box())
|
|
|
|
self.ui.platform_combo.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-10-24 07:36:44 +13:00
|
|
|
self.ui.platform_combo.itemText(i)
|
2021-12-24 22:09:50 +13:00
|
|
|
),
|
|
|
|
)
|
2022-10-24 07:36:44 +13:00
|
|
|
if (self.ui.platform_combo.currentText() == "Mac" and pf.system() != "Darwin")
|
2021-12-24 22:09:50 +13:00
|
|
|
else None
|
|
|
|
)
|
2022-07-24 10:06:35 +12:00
|
|
|
if pf.system() == "Darwin" and "Mac" in platforms:
|
2022-10-24 07:36:44 +13:00
|
|
|
self.ui.platform_combo.setCurrentIndex(platforms.index("Mac"))
|
2023-02-05 03:23:07 +13:00
|
|
|
self.ui.platform_combo.currentTextChanged.connect(self.setup_sdl_list)
|
2023-02-08 00:06:08 +13:00
|
|
|
|
2022-11-01 03:54:40 +13:00
|
|
|
self.advanced.ui.max_workers_spin.setValue(self.core.lgd.config.getint("Legendary", "max_workers", fallback=0))
|
|
|
|
self.advanced.ui.max_workers_spin.valueChanged.connect(self.option_changed)
|
2021-05-24 00:52:39 +12:00
|
|
|
|
2022-11-01 03:54:40 +13:00
|
|
|
self.advanced.ui.max_memory_spin.setValue(self.core.lgd.config.getint("Legendary", "max_memory", fallback=0))
|
|
|
|
self.advanced.ui.max_memory_spin.valueChanged.connect(self.option_changed)
|
2022-05-27 08:03:17 +12:00
|
|
|
|
2022-11-01 03:54:40 +13:00
|
|
|
self.advanced.ui.dl_optimizations_check.stateChanged.connect(self.option_changed)
|
|
|
|
self.advanced.ui.force_download_check.stateChanged.connect(self.option_changed)
|
|
|
|
self.advanced.ui.ignore_space_check.stateChanged.connect(self.option_changed)
|
|
|
|
self.advanced.ui.download_only_check.stateChanged.connect(
|
|
|
|
lambda: self.non_reload_option_changed("download_only")
|
|
|
|
)
|
|
|
|
self.ui.shortcut_check.stateChanged.connect(
|
|
|
|
lambda: self.non_reload_option_changed("shortcut")
|
|
|
|
)
|
2022-07-24 10:06:35 +12:00
|
|
|
|
2022-11-01 03:54:40 +13:00
|
|
|
self.selectable_checks: List[TagCheckBox] = []
|
2022-07-24 10:06:35 +12:00
|
|
|
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
|
|
|
|
2023-01-21 13:15:06 +13:00
|
|
|
if self.options.overlay:
|
|
|
|
self.ui.platform_label.setEnabled(False)
|
|
|
|
self.ui.platform_combo.setEnabled(False)
|
|
|
|
self.advanced.ui.ignore_space_label.setEnabled(False)
|
|
|
|
self.advanced.ui.ignore_space_check.setEnabled(False)
|
|
|
|
self.advanced.ui.download_only_label.setEnabled(False)
|
|
|
|
self.advanced.ui.download_only_check.setEnabled(False)
|
|
|
|
self.ui.shortcut_label.setEnabled(False)
|
|
|
|
self.ui.shortcut_check.setEnabled(False)
|
|
|
|
self.selectable.setEnabled(False)
|
2022-02-05 10:12:00 +13:00
|
|
|
|
2022-07-24 10:06:35 +12:00
|
|
|
if pf.system() == "Darwin":
|
2022-10-24 07:36:44 +13:00
|
|
|
self.ui.shortcut_check.setDisabled(True)
|
|
|
|
self.ui.shortcut_check.setChecked(False)
|
|
|
|
self.ui.shortcut_check.setToolTip(self.tr("Creating a shortcut is not supported on MacOS"))
|
2022-02-05 10:12:00 +13:00
|
|
|
|
2022-11-01 03:54:40 +13:00
|
|
|
self.advanced.ui.install_prereqs_label.setEnabled(False)
|
|
|
|
self.advanced.ui.install_prereqs_check.setEnabled(False)
|
|
|
|
self.advanced.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
|
|
|
|
2023-01-21 13:15:06 +13:00
|
|
|
self.advanced.ui.install_prereqs_check.setChecked(self.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):
|
2023-01-21 13:15:06 +13:00
|
|
|
if self.options.silent:
|
2021-05-26 08:37:50 +12:00
|
|
|
self.reject_close = False
|
|
|
|
self.get_download_info()
|
|
|
|
else:
|
2023-01-26 03:43:06 +13:00
|
|
|
self.setModal(True)
|
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"):
|
2022-11-01 03:54:40 +13:00
|
|
|
for cb in self.selectable_checks:
|
2022-07-24 10:06:35 +12:00
|
|
|
cb.disconnect()
|
|
|
|
cb.deleteLater()
|
2022-11-01 03:54:40 +13:00
|
|
|
self.selectable_checks.clear()
|
2022-07-24 10:06:35 +12:00
|
|
|
|
2023-01-21 13:15:06 +13:00
|
|
|
if config_tags := self.core.lgd.config.get(self.rgame.app_name, 'install_tags', fallback=None):
|
2022-07-24 10:06:35 +12:00
|
|
|
self.config_tags = config_tags.split(",")
|
2023-01-21 13:15:06 +13:00
|
|
|
config_disable_sdl = self.core.lgd.config.getboolean(self.rgame.app_name, 'disable_sdl', fallback=False)
|
|
|
|
sdl_name = get_sdl_appname(self.rgame.app_name)
|
2022-07-24 10:06:35 +12:00
|
|
|
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:
|
2022-11-01 03:54:40 +13:00
|
|
|
widget = QWidget(self.selectable)
|
|
|
|
layout = QVBoxLayout(widget)
|
|
|
|
layout.setSpacing(0)
|
2022-07-24 10:06:35 +12:00
|
|
|
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-11-01 03:54:40 +13:00
|
|
|
layout.addWidget(cb)
|
|
|
|
self.selectable_checks.append(cb)
|
|
|
|
for cb in self.selectable_checks:
|
2022-07-24 10:06:35 +12:00
|
|
|
cb.stateChanged.connect(self.option_changed)
|
2022-11-01 03:54:40 +13:00
|
|
|
self.selectable.setWidget(widget)
|
2022-07-24 10:06:35 +12:00
|
|
|
else:
|
2022-11-01 03:54:40 +13:00
|
|
|
self.selectable.setDisabled(True)
|
2022-07-24 10:06:35 +12:00
|
|
|
|
2021-05-24 00:15:36 +12:00
|
|
|
def get_options(self):
|
2023-01-21 13:15:06 +13:00
|
|
|
self.options.base_path = self.install_dir_edit.text() if not self.options.update else None
|
|
|
|
self.options.max_workers = self.advanced.ui.max_workers_spin.value()
|
|
|
|
self.options.shared_memory = self.advanced.ui.max_memory_spin.value()
|
|
|
|
self.options.order_opt = self.advanced.ui.dl_optimizations_check.isChecked()
|
|
|
|
self.options.force = self.advanced.ui.force_download_check.isChecked()
|
|
|
|
self.options.ignore_space = self.advanced.ui.ignore_space_check.isChecked()
|
|
|
|
self.options.no_install = self.advanced.ui.download_only_check.isChecked()
|
|
|
|
self.options.platform = self.ui.platform_combo.currentText()
|
|
|
|
self.options.install_prereqs = self.advanced.ui.install_prereqs_check.isChecked()
|
|
|
|
self.options.create_shortcut = self.ui.shortcut_check.isChecked()
|
2022-11-01 03:54:40 +13:00
|
|
|
if self.selectable_checks:
|
2023-01-21 13:15:06 +13:00
|
|
|
self.options.install_tag = [""]
|
2022-11-01 03:54:40 +13:00
|
|
|
for cb in self.selectable_checks:
|
2022-07-24 10:06:35 +12:00
|
|
|
if data := cb.isChecked():
|
|
|
|
# noinspection PyTypeChecker
|
2023-01-21 13:15:06 +13:00
|
|
|
self.options.install_tag.extend(data)
|
2021-05-24 00:15:36 +12:00
|
|
|
|
|
|
|
def get_download_info(self):
|
2023-01-21 13:15:06 +13:00
|
|
|
self.__download = None
|
|
|
|
info_worker = InstallInfoWorker(self.core, self.options)
|
2021-05-26 08:37:50 +12:00
|
|
|
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-10-24 07:36:44 +13:00
|
|
|
self.ui.download_size_text.setText(message)
|
|
|
|
self.ui.download_size_text.setStyleSheet("font-style: italic; font-weight: normal")
|
|
|
|
self.ui.install_size_text.setText(message)
|
|
|
|
self.ui.install_size_text.setStyleSheet("font-style: italic; font-weight: normal")
|
2022-09-01 02:01:52 +12:00
|
|
|
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
|
|
|
|
2023-02-19 01:33:42 +13:00
|
|
|
def option_changed(self, path) -> Tuple[bool, str, int]:
|
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)
|
2023-02-19 01:33:42 +13:00
|
|
|
return True, path, IndicatorReasonsCommon.VALID
|
2021-05-24 04:38:33 +12:00
|
|
|
|
2023-04-17 04:38:57 +12:00
|
|
|
def save_install_edit(self, path: str):
|
|
|
|
if not os.path.exists(path):
|
|
|
|
return
|
|
|
|
_, _, free_space = shutil.disk_usage(path)
|
|
|
|
self.ui.avail_space.setText(format_size(free_space))
|
|
|
|
|
2021-10-15 10:57:57 +13:00
|
|
|
def non_reload_option_changed(self, option: str):
|
|
|
|
if option == "download_only":
|
2023-01-21 13:15:06 +13:00
|
|
|
self.options.no_install = self.advanced.ui.download_only_check.isChecked()
|
2022-02-05 10:12:00 +13:00
|
|
|
elif option == "shortcut":
|
2022-10-24 07:36:44 +13:00
|
|
|
QSettings().setValue("create_shortcut", self.ui.shortcut_check.isChecked())
|
2023-01-21 13:15:06 +13:00
|
|
|
self.options.create_shortcut = self.ui.shortcut_check.isChecked()
|
2022-09-01 20:49:42 +12:00
|
|
|
elif option == "install_prereqs":
|
2023-01-21 13:15:06 +13:00
|
|
|
self.options.install_prereqs = self.advanced.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):
|
2023-03-14 12:28:05 +13:00
|
|
|
if self.config_tags is not None:
|
2023-01-21 13:15:06 +13:00
|
|
|
config_helper.add_option(self.rgame.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
|
2023-01-21 13:15:06 +13:00
|
|
|
config_helper.remove_option(self.rgame.app_name, 'install_tags')
|
2022-07-24 10:06:35 +12:00
|
|
|
|
2023-01-21 13:15:06 +13:00
|
|
|
self.__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
|
|
|
|
2023-01-27 09:03:38 +13:00
|
|
|
@pyqtSlot(InstallDownloadModel)
|
|
|
|
def on_worker_result(self, download: InstallDownloadModel):
|
|
|
|
self.__download = download
|
|
|
|
download_size = download.analysis.dl_size
|
|
|
|
install_size = download.analysis.install_size
|
2023-01-21 13:15:06 +13:00
|
|
|
# install_size = self.dl_item.download.analysis.disk_space_delta
|
2023-03-14 12:28:05 +13:00
|
|
|
if download_size or (not download_size and (download.game.is_dlc or download.repair)):
|
2023-03-05 07:56:04 +13:00
|
|
|
self.ui.download_size_text.setText(format_size(download_size))
|
2022-10-24 07:36:44 +13:00
|
|
|
self.ui.download_size_text.setStyleSheet("font-style: normal; font-weight: bold")
|
2022-09-01 02:01:52 +12:00
|
|
|
self.ui.install_button.setEnabled(not self.options_changed)
|
2021-05-21 11:47:03 +12:00
|
|
|
else:
|
2022-10-24 07:36:44 +13:00
|
|
|
self.ui.install_size_text.setText(self.tr("Game already installed"))
|
|
|
|
self.ui.install_size_text.setStyleSheet("font-style: italics; font-weight: normal")
|
2023-03-05 07:56:04 +13:00
|
|
|
self.ui.install_size_text.setText(format_size(install_size))
|
2022-10-24 07:36:44 +13:00
|
|
|
self.ui.install_size_text.setStyleSheet("font-style: normal; font-weight: bold")
|
2022-09-01 02:01:52 +12:00
|
|
|
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:
|
2023-01-27 09:03:38 +13:00
|
|
|
if download.igame.prereq_info and not download.igame.prereq_info.get("installed", False):
|
2022-11-01 03:54:40 +13:00
|
|
|
self.advanced.ui.install_prereqs_check.setEnabled(True)
|
|
|
|
self.advanced.ui.install_prereqs_label.setEnabled(True)
|
|
|
|
self.advanced.ui.install_prereqs_check.setChecked(True)
|
2023-01-27 09:03:38 +13:00
|
|
|
prereq_name = download.igame.prereq_info.get("name", "")
|
|
|
|
prereq_path = os.path.split(download.igame.prereq_info.get("path", ""))[-1]
|
2022-09-18 23:55:33 +12:00
|
|
|
prereq_desc = prereq_name if prereq_name else prereq_path
|
2022-11-01 03:54:40 +13:00
|
|
|
self.advanced.ui.install_prereqs_check.setText(
|
2022-09-18 23:55:33 +12:00
|
|
|
self.tr("Also install: {}").format(prereq_desc)
|
2022-05-27 22:23:08 +12:00
|
|
|
)
|
2023-01-21 13:15:06 +13:00
|
|
|
if self.options.silent:
|
2022-09-01 01:57:50 +12:00
|
|
|
self.close()
|
2021-05-26 08:37:50 +12:00
|
|
|
|
|
|
|
def on_worker_failed(self, message: str):
|
|
|
|
error_text = self.tr("Error")
|
2022-10-24 07:36:44 +13:00
|
|
|
self.ui.download_size_text.setText(error_text)
|
|
|
|
self.ui.install_size_text.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)
|
2023-01-21 13:15:06 +13:00
|
|
|
if self.options.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-10-24 07:36:44 +13:00
|
|
|
self.ui.warning_label.setVisible(bool(label))
|
|
|
|
self.ui.warning_label.setText(label)
|
|
|
|
self.ui.warning_text.setVisible(bool(message))
|
|
|
|
self.ui.warning_text.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()
|
2023-01-21 13:15:06 +13:00
|
|
|
self.result_ready.emit(InstallQueueItemModel(options=self.options, download=self.__download))
|
2022-11-01 03:54:40 +13:00
|
|
|
super(InstallDialog, self).closeEvent(a0)
|
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-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]]:
|
2022-11-01 03:54:40 +13:00
|
|
|
return self.tags if super(TagCheckBox, self).isChecked() else False
|
2023-01-21 13:15:06 +13:00
|
|
|
|
|
|
|
|
|
|
|
|