1
0
Fork 0
mirror of synced 2024-06-17 01:54:46 +12:00

More uninstall options,

This commit is contained in:
Dummerle 2021-04-06 11:00:13 +02:00
parent d18089d293
commit 8a74c4131e
2 changed files with 51 additions and 4 deletions

View file

@ -0,0 +1,44 @@
from PyQt5.QtWidgets import QDialog, QLabel, QVBoxLayout, QCheckBox, QFormLayout, QHBoxLayout, QPushButton
from qtawesome import icon
from custom_legendary.models.game import Game
class UninstallDialog(QDialog):
def __init__(self, game: Game):
super(UninstallDialog, self).__init__()
self.setWindowTitle("Uninstall Game")
self.info = 0
self.layout = QVBoxLayout()
self.info_text = QLabel(self.tr("Do you really want to uninstall {}").format(game.app_title))
self.layout.addWidget(self.info_text)
self.keep_files = QCheckBox(self.tr("Keep Files"))
self.form = QFormLayout()
self.form.setContentsMargins(0, 10, 0, 10)
self.form.addRow(QLabel(self.tr("Do you want to keep files?")), self.keep_files)
self.layout.addLayout(self.form)
self.button_layout = QHBoxLayout()
self.ok_button = QPushButton(icon("ei.remove-circle", color="red"), self.tr("Uninstall"))
self.ok_button.clicked.connect(self.ok)
self.cancel_button = QPushButton(self.tr("Cancel"))
self.cancel_button.clicked.connect(self.cancel)
self.button_layout.addStretch(1)
self.button_layout.addWidget(self.ok_button)
self.button_layout.addWidget(self.cancel_button)
self.layout.addLayout(self.button_layout)
self.setLayout(self.layout)
def get_information(self):
self.exec_()
return self.info
def ok(self):
self.info = {"keep_files": self.keep_files.isChecked()}
self.close()
def cancel(self):
self.info = 0
self.close()

View file

@ -47,7 +47,9 @@ def launch_game(core, app_name: str, offline: bool = False, skip_version_check:
return process, params
def uninstall(app_name: str, core):
def uninstall(app_name: str, core, options=None):
if not options:
options = {"keep_files": False}
igame = core.get_installed_game(app_name)
try:
# Remove DLC first so directory is empty when game uninstall runs
@ -55,12 +57,13 @@ def uninstall(app_name: str, core):
for dlc in dlcs:
if (idlc := core.get_installed_game(dlc.app_name)) is not None:
logger.info(f'Uninstalling DLC "{dlc.app_name}"...')
core.uninstall_game(idlc, delete_files=True)
core.uninstall_game(idlc, delete_files=not options["keep_files"])
logger.info(f'Removing "{igame.title}" from "{igame.install_path}"...')
core.uninstall_game(igame, delete_files=True, delete_root_directory=True)
core.uninstall_game(igame, delete_files=not options["keep_files"], delete_root_directory=True)
logger.info('Game has been uninstalled.')
shutil.rmtree(igame.install_path)
if not options["keep_files"]:
shutil.rmtree(igame.install_path)
except Exception as e:
logger.warning(f'Removing game failed: {e!r}, please remove {igame.install_path} manually.')