From 3bf7b20fbc6e66bf99cf5c73f572705af10ad5da Mon Sep 17 00:00:00 2001 From: loathingKernel <142770+loathingKernel@users.noreply.github.com> Date: Thu, 26 May 2022 23:03:17 +0300 Subject: [PATCH] InstallDialog: Add max shared memory override and download reordering options Fixes: #206 --- rare/components/dialogs/install_dialog.py | 29 +++-- rare/ui/components/dialogs/install_dialog.py | 79 ++++++++---- rare/ui/components/dialogs/install_dialog.ui | 112 ++++++++++++++---- rare/ui/components/tabs/settings/legendary.py | 4 +- rare/ui/components/tabs/settings/legendary.ui | 4 +- rare/utils/models.py | 8 +- 6 files changed, 177 insertions(+), 59 deletions(-) diff --git a/rare/components/dialogs/install_dialog.py b/rare/components/dialogs/install_dialog.py index fb99f448..89761c64 100644 --- a/rare/components/dialogs/install_dialog.py +++ b/rare/components/dialogs/install_dialog.py @@ -104,13 +104,17 @@ class InstallDialog(QDialog, Ui_InstallDialog): if platform.system() == "Darwin" and "Mac" in platforms: self.platform_combo_box.setCurrentIndex(platforms.index("Mac")) - if self.core.lgd.config.has_option("Legendary", "max_workers"): - max_workers = self.core.lgd.config.get("Legendary", "max_workers") - else: - max_workers = 0 - self.max_workers_spin.setValue(int(max_workers)) + self.max_workers_spin.setValue( + self.core.lgd.config.getint("Legendary", "max_workers", fallback=0) + ) self.max_workers_spin.valueChanged.connect(self.option_changed) + self.max_memory_spin.setValue( + self.core.lgd.config.getint("Legendary", "max_memory", fallback=0) + ) + self.max_memory_spin.valueChanged.connect(self.option_changed) + + self.dl_optimizations_check.stateChanged.connect(self.option_changed) self.force_download_check.stateChanged.connect(self.option_changed) self.ignore_space_check.stateChanged.connect(self.option_changed) self.download_only_check.stateChanged.connect( @@ -164,7 +168,6 @@ class InstallDialog(QDialog, Ui_InstallDialog): self.install_button.clicked.connect(self.install_clicked) self.resize(self.minimumSize()) - # self.setFixedSize(self.size()) def execute(self): if self.silent: @@ -180,10 +183,12 @@ class InstallDialog(QDialog, Ui_InstallDialog): ) self.dl_item.options.max_workers = self.max_workers_spin.value() + self.dl_item.options.max_shm = self.max_memory_spin.value() + self.dl_item.options.dl_optimizations = self.dl_optimizations_check.isChecked() self.dl_item.options.force = self.force_download_check.isChecked() self.dl_item.options.ignore_space_req = self.ignore_space_check.isChecked() self.dl_item.options.no_install = self.download_only_check.isChecked() - self.dl_item.options.install_platform = self.platform_combo_box.currentText() + self.dl_item.options.platform = self.platform_combo_box.currentText() self.dl_item.options.sdl_list = [""] for cb in self.sdl_list_checks: if data := cb.isChecked(): @@ -201,6 +206,8 @@ class InstallDialog(QDialog, Ui_InstallDialog): self.threadpool.start(info_worker) def verify_clicked(self): + self.warn_label.setVisible(False) + self.warn_message.setVisible(False) message = self.tr("Updating...") self.download_size_info_label.setText(message) self.download_size_info_label.setStyleSheet( @@ -268,7 +275,7 @@ class InstallDialog(QDialog, Ui_InstallDialog): self.install_preqs_check.setVisible(True) self.install_preqs_lbl.setVisible(True) self.install_preqs_check.setText( - self.tr("This will install {}").format(dl_item.igame.prereq_info.get("name", ""))) + self.tr("Also install: {}").format(dl_item.igame.prereq_info.get("name", ""))) def on_worker_failed(self, message: str): error_text = self.tr("Error") @@ -330,18 +337,18 @@ class InstallInfoWorker(QRunnable): force=self.dl_item.options.force, no_install=self.dl_item.options.no_install, status_q=self.dl_item.status_q, - # max_shm=, + max_shm=self.dl_item.options.max_shm, max_workers=self.dl_item.options.max_workers, # game_folder=, # disable_patching=, # override_manifest=, # override_old_manifest=, # override_base_url=, - platform=self.dl_item.options.install_platform, + platform=self.dl_item.options.platform, # file_prefix_filter=, # file_exclude_filter=, # file_install_tag=, - # dl_optimizations=, + dl_optimizations=self.dl_item.options.dl_optimizations, # dl_timeout=, repair=self.dl_item.options.repair, # repair_use_latest=, diff --git a/rare/ui/components/dialogs/install_dialog.py b/rare/ui/components/dialogs/install_dialog.py index 80927028..ff198bfd 100644 --- a/rare/ui/components/dialogs/install_dialog.py +++ b/rare/ui/components/dialogs/install_dialog.py @@ -14,7 +14,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets class Ui_InstallDialog(object): def setupUi(self, InstallDialog): InstallDialog.setObjectName("InstallDialog") - InstallDialog.resize(337, 372) + InstallDialog.resize(379, 434) InstallDialog.setWindowTitle("Rare") self.install_dialog_layout = QtWidgets.QFormLayout(InstallDialog) self.install_dialog_layout.setSizeConstraint(QtWidgets.QLayout.SetFixedSize) @@ -51,7 +51,7 @@ class Ui_InstallDialog(object): self.install_dialog_layout.setLayout(3, QtWidgets.QFormLayout.FieldRole, self.max_workers_layout) self.force_download_label = QtWidgets.QLabel(InstallDialog) self.force_download_label.setObjectName("force_download_label") - self.install_dialog_layout.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.force_download_label) + self.install_dialog_layout.setWidget(6, QtWidgets.QFormLayout.LabelRole, self.force_download_label) self.force_download_check = QtWidgets.QCheckBox(InstallDialog) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) @@ -60,7 +60,7 @@ class Ui_InstallDialog(object): self.force_download_check.setSizePolicy(sizePolicy) self.force_download_check.setText("") self.force_download_check.setObjectName("force_download_check") - self.install_dialog_layout.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.force_download_check) + self.install_dialog_layout.setWidget(6, QtWidgets.QFormLayout.FieldRole, self.force_download_check) self.platform_label = QtWidgets.QLabel(InstallDialog) self.platform_label.setObjectName("platform_label") self.install_dialog_layout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.platform_label) @@ -74,20 +74,20 @@ class Ui_InstallDialog(object): self.install_dialog_layout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.platform_combo_box) self.ignore_space_label = QtWidgets.QLabel(InstallDialog) self.ignore_space_label.setObjectName("ignore_space_label") - self.install_dialog_layout.setWidget(5, QtWidgets.QFormLayout.LabelRole, self.ignore_space_label) + self.install_dialog_layout.setWidget(7, QtWidgets.QFormLayout.LabelRole, self.ignore_space_label) self.download_only_label = QtWidgets.QLabel(InstallDialog) self.download_only_label.setObjectName("download_only_label") - self.install_dialog_layout.setWidget(6, QtWidgets.QFormLayout.LabelRole, self.download_only_label) + self.install_dialog_layout.setWidget(8, QtWidgets.QFormLayout.LabelRole, self.download_only_label) self.shortcut_lbl = QtWidgets.QLabel(InstallDialog) self.shortcut_lbl.setObjectName("shortcut_lbl") - self.install_dialog_layout.setWidget(7, QtWidgets.QFormLayout.LabelRole, self.shortcut_lbl) + self.install_dialog_layout.setWidget(9, QtWidgets.QFormLayout.LabelRole, self.shortcut_lbl) self.shortcut_cb = QtWidgets.QCheckBox(InstallDialog) self.shortcut_cb.setText("") self.shortcut_cb.setObjectName("shortcut_cb") - self.install_dialog_layout.setWidget(7, QtWidgets.QFormLayout.FieldRole, self.shortcut_cb) + self.install_dialog_layout.setWidget(9, QtWidgets.QFormLayout.FieldRole, self.shortcut_cb) self.sdl_list_label = QtWidgets.QLabel(InstallDialog) self.sdl_list_label.setObjectName("sdl_list_label") - self.install_dialog_layout.setWidget(9, QtWidgets.QFormLayout.LabelRole, self.sdl_list_label) + self.install_dialog_layout.setWidget(11, QtWidgets.QFormLayout.LabelRole, self.sdl_list_label) self.sdl_list_frame = QtWidgets.QFrame(InstallDialog) self.sdl_list_frame.setFrameShape(QtWidgets.QFrame.StyledPanel) self.sdl_list_frame.setFrameShadow(QtWidgets.QFrame.Raised) @@ -95,36 +95,36 @@ class Ui_InstallDialog(object): self.sdl_list_layout = QtWidgets.QVBoxLayout(self.sdl_list_frame) self.sdl_list_layout.setSpacing(0) self.sdl_list_layout.setObjectName("sdl_list_layout") - self.install_dialog_layout.setWidget(9, QtWidgets.QFormLayout.FieldRole, self.sdl_list_frame) + self.install_dialog_layout.setWidget(11, QtWidgets.QFormLayout.FieldRole, self.sdl_list_frame) self.download_size_label = QtWidgets.QLabel(InstallDialog) self.download_size_label.setObjectName("download_size_label") - self.install_dialog_layout.setWidget(11, QtWidgets.QFormLayout.LabelRole, self.download_size_label) + self.install_dialog_layout.setWidget(13, QtWidgets.QFormLayout.LabelRole, self.download_size_label) self.download_size_info_label = QtWidgets.QLabel(InstallDialog) font = QtGui.QFont() font.setItalic(True) self.download_size_info_label.setFont(font) self.download_size_info_label.setObjectName("download_size_info_label") - self.install_dialog_layout.setWidget(11, QtWidgets.QFormLayout.FieldRole, self.download_size_info_label) + self.install_dialog_layout.setWidget(13, QtWidgets.QFormLayout.FieldRole, self.download_size_info_label) self.install_size_label = QtWidgets.QLabel(InstallDialog) self.install_size_label.setObjectName("install_size_label") - self.install_dialog_layout.setWidget(12, QtWidgets.QFormLayout.LabelRole, self.install_size_label) + self.install_dialog_layout.setWidget(14, QtWidgets.QFormLayout.LabelRole, self.install_size_label) self.install_size_info_label = QtWidgets.QLabel(InstallDialog) font = QtGui.QFont() font.setItalic(True) self.install_size_info_label.setFont(font) self.install_size_info_label.setWordWrap(True) self.install_size_info_label.setObjectName("install_size_info_label") - self.install_dialog_layout.setWidget(12, QtWidgets.QFormLayout.FieldRole, self.install_size_info_label) + self.install_dialog_layout.setWidget(14, QtWidgets.QFormLayout.FieldRole, self.install_size_info_label) self.warn_message = QtWidgets.QLabel(InstallDialog) font = QtGui.QFont() font.setItalic(True) self.warn_message.setFont(font) self.warn_message.setWordWrap(True) self.warn_message.setObjectName("warn_message") - self.install_dialog_layout.setWidget(13, QtWidgets.QFormLayout.FieldRole, self.warn_message) + self.install_dialog_layout.setWidget(15, QtWidgets.QFormLayout.FieldRole, self.warn_message) self.warn_label = QtWidgets.QLabel(InstallDialog) self.warn_label.setObjectName("warn_label") - self.install_dialog_layout.setWidget(13, QtWidgets.QFormLayout.LabelRole, self.warn_label) + self.install_dialog_layout.setWidget(15, QtWidgets.QFormLayout.LabelRole, self.warn_label) self.button_layout = QtWidgets.QHBoxLayout() self.button_layout.setObjectName("button_layout") spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) @@ -138,14 +138,17 @@ class Ui_InstallDialog(object): self.install_button = QtWidgets.QPushButton(InstallDialog) self.install_button.setObjectName("install_button") self.button_layout.addWidget(self.install_button) - self.install_dialog_layout.setLayout(14, QtWidgets.QFormLayout.SpanningRole, self.button_layout) + self.install_dialog_layout.setLayout(16, QtWidgets.QFormLayout.SpanningRole, self.button_layout) self.install_preqs_lbl = QtWidgets.QLabel(InstallDialog) self.install_preqs_lbl.setObjectName("install_preqs_lbl") - self.install_dialog_layout.setWidget(8, QtWidgets.QFormLayout.LabelRole, self.install_preqs_lbl) + self.install_dialog_layout.setWidget(10, QtWidgets.QFormLayout.LabelRole, self.install_preqs_lbl) self.install_preqs_check = QtWidgets.QCheckBox(InstallDialog) + font = QtGui.QFont() + font.setItalic(True) + self.install_preqs_check.setFont(font) self.install_preqs_check.setText("") self.install_preqs_check.setObjectName("install_preqs_check") - self.install_dialog_layout.setWidget(8, QtWidgets.QFormLayout.FieldRole, self.install_preqs_check) + self.install_dialog_layout.setWidget(10, QtWidgets.QFormLayout.FieldRole, self.install_preqs_check) self.ignore_space_check = QtWidgets.QCheckBox(InstallDialog) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) @@ -156,7 +159,7 @@ class Ui_InstallDialog(object): font.setItalic(True) self.ignore_space_check.setFont(font) self.ignore_space_check.setObjectName("ignore_space_check") - self.install_dialog_layout.setWidget(5, QtWidgets.QFormLayout.FieldRole, self.ignore_space_check) + self.install_dialog_layout.setWidget(7, QtWidgets.QFormLayout.FieldRole, self.ignore_space_check) self.download_only_check = QtWidgets.QCheckBox(InstallDialog) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) @@ -167,7 +170,39 @@ class Ui_InstallDialog(object): font.setItalic(True) self.download_only_check.setFont(font) self.download_only_check.setObjectName("download_only_check") - self.install_dialog_layout.setWidget(6, QtWidgets.QFormLayout.FieldRole, self.download_only_check) + self.install_dialog_layout.setWidget(8, QtWidgets.QFormLayout.FieldRole, self.download_only_check) + self.max_memory_label = QtWidgets.QLabel(InstallDialog) + self.max_memory_label.setObjectName("max_memory_label") + self.install_dialog_layout.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.max_memory_label) + self.max_memory_layout = QtWidgets.QHBoxLayout() + self.max_memory_layout.setObjectName("max_memory_layout") + self.max_memory_spin = QtWidgets.QSpinBox(InstallDialog) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.max_memory_spin.sizePolicy().hasHeightForWidth()) + self.max_memory_spin.setSizePolicy(sizePolicy) + self.max_memory_spin.setMinimum(0) + self.max_memory_spin.setMaximum(10240) + self.max_memory_spin.setSingleStep(128) + self.max_memory_spin.setProperty("value", 1024) + self.max_memory_spin.setObjectName("max_memory_spin") + self.max_memory_layout.addWidget(self.max_memory_spin) + self.max_memory_info_label = QtWidgets.QLabel(InstallDialog) + font = QtGui.QFont() + font.setItalic(True) + self.max_memory_info_label.setFont(font) + self.max_memory_info_label.setObjectName("max_memory_info_label") + self.max_memory_layout.addWidget(self.max_memory_info_label) + self.install_dialog_layout.setLayout(4, QtWidgets.QFormLayout.FieldRole, self.max_memory_layout) + self.dl_optimizations_label = QtWidgets.QLabel(InstallDialog) + self.dl_optimizations_label.setObjectName("dl_optimizations_label") + self.install_dialog_layout.setWidget(5, QtWidgets.QFormLayout.LabelRole, self.dl_optimizations_label) + self.dl_optimizations_check = QtWidgets.QCheckBox(InstallDialog) + self.dl_optimizations_check.setText("") + self.dl_optimizations_check.setChecked(False) + self.dl_optimizations_check.setObjectName("dl_optimizations_check") + self.install_dialog_layout.setWidget(5, QtWidgets.QFormLayout.FieldRole, self.dl_optimizations_check) self.retranslateUi(InstallDialog) QtCore.QMetaObject.connectSlotsByName(InstallDialog) @@ -196,6 +231,10 @@ class Ui_InstallDialog(object): self.install_preqs_lbl.setText(_translate("InstallDialog", "Install prerequisites")) self.ignore_space_check.setText(_translate("InstallDialog", "Use with caution!")) self.download_only_check.setText(_translate("InstallDialog", "Do not try to install.")) + self.max_memory_label.setText(_translate("InstallDialog", "Max shared memory")) + self.max_memory_spin.setSuffix(_translate("InstallDialog", "MiB")) + self.max_memory_info_label.setText(_translate("InstallDialog", "Less is slower (0: Default)")) + self.dl_optimizations_label.setText(_translate("InstallDialog", "Enable reordering")) if __name__ == "__main__": diff --git a/rare/ui/components/dialogs/install_dialog.ui b/rare/ui/components/dialogs/install_dialog.ui index 5c43d499..aa33c879 100644 --- a/rare/ui/components/dialogs/install_dialog.ui +++ b/rare/ui/components/dialogs/install_dialog.ui @@ -6,8 +6,8 @@ 0 0 - 337 - 372 + 379 + 434 @@ -70,14 +70,14 @@ - + Force redownload - + @@ -107,42 +107,42 @@ - + Ignore free space - + Download only - + Create shortcut - + - + Optional packs - + QFrame::StyledPanel @@ -157,14 +157,14 @@ - + Download size - + @@ -176,14 +176,14 @@ - + Total install size - + @@ -198,7 +198,7 @@ - + @@ -213,14 +213,14 @@ - + Warnings - + @@ -258,21 +258,26 @@ - + Install prerequisites - + + + + true + + - + @@ -290,7 +295,7 @@ - + @@ -308,6 +313,71 @@ + + + + Max shared memory + + + + + + + + + + 0 + 0 + + + + MiB + + + 0 + + + 10240 + + + 128 + + + 1024 + + + + + + + + true + + + + Less is slower (0: Default) + + + + + + + + + Enable reordering + + + + + + + + + + false + + + diff --git a/rare/ui/components/tabs/settings/legendary.py b/rare/ui/components/tabs/settings/legendary.py index ca1ca9f0..96c62572 100644 --- a/rare/ui/components/tabs/settings/legendary.py +++ b/rare/ui/components/tabs/settings/legendary.py @@ -14,7 +14,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets class Ui_LegendarySettings(object): def setupUi(self, LegendarySettings): LegendarySettings.setObjectName("LegendarySettings") - LegendarySettings.resize(552, 334) + LegendarySettings.resize(595, 334) LegendarySettings.setWindowTitle("LegendarySettings") self.legendary_layout = QtWidgets.QHBoxLayout(LegendarySettings) self.legendary_layout.setObjectName("legendary_layout") @@ -159,7 +159,7 @@ class Ui_LegendarySettings(object): self.download_group.setTitle(_translate("LegendarySettings", "Download Settings")) self.max_workers_label.setText(_translate("LegendarySettings", "Max Workers")) self.max_workers_info_label.setText(_translate("LegendarySettings", "Less is slower (0: Default)")) - self.max_memory_label.setText(_translate("LegendarySettings", "Max Memory")) + self.max_memory_label.setText(_translate("LegendarySettings", "Max Shared Memory")) self.max_memory_spin.setSuffix(_translate("LegendarySettings", "MiB")) self.max_memory_info_label.setText(_translate("LegendarySettings", "Less is slower (0: Default)")) self.preferred_cdn_label.setText(_translate("LegendarySettings", "Preferred CDN")) diff --git a/rare/ui/components/tabs/settings/legendary.ui b/rare/ui/components/tabs/settings/legendary.ui index 1ab099f8..f3e27bd5 100644 --- a/rare/ui/components/tabs/settings/legendary.ui +++ b/rare/ui/components/tabs/settings/legendary.ui @@ -6,7 +6,7 @@ 0 0 - 552 + 595 334 @@ -90,7 +90,7 @@ - Max Memory + Max Shared Memory diff --git a/rare/utils/models.py b/rare/utils/models.py index 54743e4e..81352b75 100644 --- a/rare/utils/models.py +++ b/rare/utils/models.py @@ -1,5 +1,5 @@ import os -import platform +import platform as pf from dataclasses import field, dataclass from multiprocessing import Queue from typing import Union, List, Optional @@ -16,6 +16,7 @@ from legendary.models.game import Game, InstalledGame class InstallOptionsModel: app_name: str base_path: str = "" + max_shm: int = 1024 max_workers: int = os.cpu_count() * 2 repair: bool = False no_install: bool = False @@ -24,10 +25,11 @@ class InstallOptionsModel: sdl_list: list = field(default_factory=lambda: [""]) update: bool = False silent: bool = False - install_platform: str = "" + platform: str = "" + dl_optimizations: bool = False overlay: bool = False create_shortcut: bool = True - install_preqs: bool = platform.system() == "Windows" + install_preqs: bool = pf.system() == "Windows" def set_no_install(self, enabled: bool) -> None: self.no_install = enabled