2021-02-20 06:09:00 +13:00
|
|
|
from logging import getLogger
|
|
|
|
|
2021-04-08 21:09:17 +12:00
|
|
|
from PyQt5.QtCore import Qt
|
2021-02-20 06:09:00 +13:00
|
|
|
from PyQt5.QtGui import QIntValidator
|
2021-04-23 00:34:06 +12:00
|
|
|
from PyQt5.QtWidgets import QVBoxLayout, QFileDialog, QPushButton, QLineEdit, QGroupBox, QMessageBox, \
|
2021-04-08 21:09:17 +12:00
|
|
|
QScrollArea
|
2021-02-20 06:09:00 +13:00
|
|
|
|
2021-04-23 00:34:06 +12:00
|
|
|
from custom_legendary.core import LegendaryCore
|
2021-04-08 08:42:30 +12:00
|
|
|
from rare.components.tabs.settings.settings_widget import SettingsWidget
|
2021-04-08 08:39:23 +12:00
|
|
|
from rare.utils.extra_widgets import PathEdit
|
2021-04-17 20:50:25 +12:00
|
|
|
from rare.utils.utils import get_size
|
2021-02-20 06:09:00 +13:00
|
|
|
|
|
|
|
logger = getLogger("LegendarySettings")
|
2021-02-20 00:57:55 +13:00
|
|
|
|
|
|
|
|
2021-04-08 21:09:17 +12:00
|
|
|
class LegendarySettings(QScrollArea):
|
2021-02-20 06:09:00 +13:00
|
|
|
def __init__(self, core: LegendaryCore):
|
2021-02-20 00:57:55 +13:00
|
|
|
super(LegendarySettings, self).__init__()
|
2021-04-08 21:09:17 +12:00
|
|
|
self.widget = QGroupBox(self.tr("Legendary settings"))
|
|
|
|
self.setWidgetResizable(True)
|
|
|
|
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
2021-02-20 00:57:55 +13:00
|
|
|
self.layout = QVBoxLayout()
|
2021-02-20 06:09:00 +13:00
|
|
|
self.core = core
|
2021-04-08 21:09:17 +12:00
|
|
|
|
|
|
|
self.widget.setObjectName("group")
|
2021-02-20 06:09:00 +13:00
|
|
|
# Default installation directory
|
|
|
|
self.select_path = PathEdit(core.get_default_install_dir(), type_of_file=QFileDialog.DirectoryOnly,
|
|
|
|
infotext="Default")
|
|
|
|
self.select_path.text_edit.textChanged.connect(lambda t: self.save_path_button.setDisabled(False))
|
|
|
|
self.save_path_button = QPushButton("Save")
|
|
|
|
self.save_path_button.clicked.connect(self.save_path)
|
2021-03-01 08:01:15 +13:00
|
|
|
self.install_dir_widget = SettingsWidget(self.tr("Default installation directory"), self.select_path,
|
2021-02-27 07:28:54 +13:00
|
|
|
self.save_path_button)
|
2021-02-20 06:09:00 +13:00
|
|
|
self.layout.addWidget(self.install_dir_widget)
|
|
|
|
|
|
|
|
# Max Workers
|
|
|
|
self.max_worker_select = QLineEdit(self.core.lgd.config["Legendary"].get("max_workers"))
|
|
|
|
self.max_worker_select.setValidator(QIntValidator())
|
|
|
|
self.max_worker_select.setPlaceholderText("Default")
|
|
|
|
self.max_worker_select.textChanged.connect(self.max_worker_save)
|
2021-03-01 08:01:15 +13:00
|
|
|
self.max_worker_widget = SettingsWidget(self.tr("Max workers for Download (Less: slower download)(0: Default)"),
|
2021-02-20 06:09:00 +13:00
|
|
|
self.max_worker_select)
|
|
|
|
self.layout.addWidget(self.max_worker_widget)
|
|
|
|
|
2021-04-23 00:34:06 +12:00
|
|
|
# cleanup
|
2021-04-06 02:13:27 +12:00
|
|
|
self.clean_layout = QVBoxLayout()
|
2021-04-07 06:55:59 +12:00
|
|
|
self.cleanup_widget = QGroupBox(self.tr("Cleanup"))
|
2021-04-06 02:13:27 +12:00
|
|
|
self.clean_button = QPushButton(self.tr("Remove everything"))
|
|
|
|
self.clean_button.clicked.connect(lambda: self.cleanup(False))
|
|
|
|
self.clean_layout.addWidget(self.clean_button)
|
|
|
|
|
|
|
|
self.clean_button_without_manifests = QPushButton(self.tr("Clean, but keep manifests"))
|
|
|
|
self.clean_button_without_manifests.clicked.connect(lambda: self.cleanup(True))
|
|
|
|
self.clean_layout.addWidget(self.clean_button_without_manifests)
|
|
|
|
|
|
|
|
self.cleanup_widget.setLayout(self.clean_layout)
|
|
|
|
self.layout.addWidget(self.cleanup_widget)
|
|
|
|
|
2021-02-20 06:09:00 +13:00
|
|
|
self.layout.addStretch(1)
|
2021-04-08 21:09:17 +12:00
|
|
|
self.widget.setLayout(self.layout)
|
|
|
|
self.setWidget(self.widget)
|
2021-02-20 06:09:00 +13:00
|
|
|
|
|
|
|
def save_path(self):
|
|
|
|
self.core.lgd.config["Legendary"]["install_dir"] = self.select_path.text()
|
|
|
|
if self.select_path.text() == "" and "install_dir" in self.core.lgd.config["Legendary"].keys():
|
|
|
|
self.core.lgd.config["Legendary"].pop("install_dir")
|
|
|
|
else:
|
|
|
|
logger.info("Set config install_dir to " + self.select_path.text())
|
|
|
|
self.core.lgd.save_config()
|
|
|
|
|
|
|
|
def max_worker_save(self, num_workers: str):
|
|
|
|
if num_workers == "":
|
2021-04-08 04:18:50 +12:00
|
|
|
self.core.lgd.config.remove_option("Legendary", "max_workers")
|
|
|
|
self.core.lgd.save_config()
|
2021-02-20 06:09:00 +13:00
|
|
|
return
|
|
|
|
num_workers = int(num_workers)
|
|
|
|
if num_workers == 0:
|
2021-04-08 04:18:50 +12:00
|
|
|
self.core.lgd.config.remove_option("Legendary", "max_workers")
|
|
|
|
else:
|
|
|
|
self.core.lgd.config.set("Legendary", "max_workers", str(num_workers))
|
2021-02-20 06:09:00 +13:00
|
|
|
self.core.lgd.save_config()
|
2021-04-06 02:13:27 +12:00
|
|
|
|
|
|
|
def cleanup(self, keep_manifests):
|
|
|
|
before = self.core.lgd.get_dir_size()
|
|
|
|
logger.debug('Removing app metadata...')
|
|
|
|
app_names = set(g.app_name for g in self.core.get_assets(update_assets=False))
|
|
|
|
self.core.lgd.clean_metadata(app_names)
|
|
|
|
|
|
|
|
if not keep_manifests:
|
|
|
|
logger.debug('Removing manifests...')
|
|
|
|
installed = [(ig.app_name, ig.version) for ig in self.core.get_installed_list()]
|
|
|
|
installed.extend((ig.app_name, ig.version) for ig in self.core.get_installed_dlc_list())
|
|
|
|
self.core.lgd.clean_manifests(installed)
|
|
|
|
|
|
|
|
logger.debug('Removing tmp data')
|
|
|
|
self.core.lgd.clean_tmp_data()
|
|
|
|
|
|
|
|
after = self.core.lgd.get_dir_size()
|
|
|
|
logger.info(f'Cleanup complete! Removed {(before - after) / 1024 / 1024:.02f} MiB.')
|
2021-04-23 00:34:06 +12:00
|
|
|
if (before - after) > 0:
|
|
|
|
QMessageBox.information(self, "Cleanup", self.tr("Cleanup complete! Successfully removed {}").format(
|
|
|
|
get_size(before - after)))
|
2021-04-06 02:13:27 +12:00
|
|
|
else:
|
|
|
|
QMessageBox.information(self, "Cleanup", "Nothing to clean")
|