2021-02-10 23:48:25 +13:00
|
|
|
import os
|
2021-06-21 07:55:31 +12:00
|
|
|
import platform
|
2021-03-09 08:36:42 +13:00
|
|
|
from logging import getLogger
|
2021-02-10 23:48:25 +13:00
|
|
|
|
2022-12-25 01:14:41 +13:00
|
|
|
from PyQt5.QtCore import QStandardPaths
|
2021-09-07 07:10:18 +12:00
|
|
|
from legendary.core import LegendaryCore
|
2022-07-02 03:42:41 +12:00
|
|
|
|
2022-08-03 11:33:50 +12:00
|
|
|
from rare.lgndr.cli import LegendaryCLI
|
2022-12-25 01:14:41 +13:00
|
|
|
from rare.lgndr.glue.arguments import LgndrUninstallGameArgs
|
2022-10-27 14:00:48 +13:00
|
|
|
from rare.lgndr.glue.monkeys import LgndrIndirectStatus
|
2022-02-06 02:48:50 +13:00
|
|
|
from rare.utils import config_helper
|
2021-02-10 23:48:25 +13:00
|
|
|
|
2021-03-09 08:36:42 +13:00
|
|
|
logger = getLogger("Legendary Utils")
|
|
|
|
|
2021-02-10 23:48:25 +13:00
|
|
|
|
2022-07-24 10:06:35 +12:00
|
|
|
def uninstall_game(core: LegendaryCore, app_name: str, keep_files=False, keep_config=False):
|
2021-03-09 08:36:42 +13:00
|
|
|
igame = core.get_installed_game(app_name)
|
2021-05-01 21:17:18 +12:00
|
|
|
|
|
|
|
# remove shortcuts link
|
2022-04-01 08:29:31 +13:00
|
|
|
desktop = QStandardPaths.writableLocation(QStandardPaths.DesktopLocation)
|
|
|
|
applications = QStandardPaths.writableLocation(QStandardPaths.ApplicationsLocation)
|
2021-06-21 07:55:31 +12:00
|
|
|
if platform.system() == "Linux":
|
2022-04-01 08:29:31 +13:00
|
|
|
desktop_shortcut = os.path.join(desktop, f"{igame.title}.desktop")
|
|
|
|
if os.path.exists(desktop_shortcut):
|
|
|
|
os.remove(desktop_shortcut)
|
|
|
|
|
|
|
|
applications_shortcut = os.path.join(applications, f"{igame.title}.desktop")
|
|
|
|
if os.path.exists(applications_shortcut):
|
|
|
|
os.remove(applications_shortcut)
|
2021-05-01 21:17:18 +12:00
|
|
|
|
2021-06-21 07:55:31 +12:00
|
|
|
elif platform.system() == "Windows":
|
2022-04-01 08:29:31 +13:00
|
|
|
game_title = igame.title.split(":")[0]
|
|
|
|
desktop_shortcut = os.path.join(desktop, f"{game_title}.lnk")
|
|
|
|
if os.path.exists(desktop_shortcut):
|
|
|
|
os.remove(desktop_shortcut)
|
|
|
|
|
|
|
|
start_menu_shortcut = os.path.join(applications, "..", f"{game_title}.lnk")
|
|
|
|
if os.path.exists(start_menu_shortcut):
|
|
|
|
os.remove(start_menu_shortcut)
|
2021-05-12 21:45:10 +12:00
|
|
|
|
2022-07-24 10:06:35 +12:00
|
|
|
status = LgndrIndirectStatus()
|
2022-08-01 23:31:07 +12:00
|
|
|
LegendaryCLI(core).uninstall_game(
|
2022-07-16 06:16:12 +12:00
|
|
|
LgndrUninstallGameArgs(
|
|
|
|
app_name=app_name,
|
|
|
|
keep_files=keep_files,
|
2022-07-24 10:06:35 +12:00
|
|
|
indirect_status=status,
|
2022-07-16 06:16:12 +12:00
|
|
|
yes=True,
|
2021-12-24 22:09:50 +13:00
|
|
|
)
|
2022-07-16 06:16:12 +12:00
|
|
|
)
|
2022-07-24 10:06:35 +12:00
|
|
|
if not keep_config:
|
2022-07-02 03:42:41 +12:00
|
|
|
logger.info("Removing sections in config file")
|
|
|
|
config_helper.remove_section(app_name)
|
|
|
|
config_helper.remove_section(f"{app_name}.env")
|
2021-03-10 04:52:51 +13:00
|
|
|
|
2022-07-02 03:42:41 +12:00
|
|
|
config_helper.save_config()
|
2021-08-31 01:14:40 +12:00
|
|
|
|
2022-07-24 10:06:35 +12:00
|
|
|
return status.success, status.message
|