2022-01-13 11:46:46 +13:00
|
|
|
import os
|
|
|
|
import platform
|
|
|
|
from logging import getLogger
|
|
|
|
from typing import List
|
|
|
|
|
2022-01-14 06:58:07 +13:00
|
|
|
from PyQt5.QtCore import QRunnable, QObject, pyqtSignal, QThreadPool
|
2022-01-19 07:46:16 +13:00
|
|
|
from PyQt5.QtWidgets import QGroupBox, QMessageBox
|
2022-10-27 08:36:16 +13:00
|
|
|
from legendary.lfs import eos
|
2022-11-04 09:34:50 +13:00
|
|
|
|
2022-07-27 02:41:23 +12:00
|
|
|
from rare.models.install import InstallOptionsModel
|
2022-11-04 09:34:50 +13:00
|
|
|
from rare.shared import LegendaryCoreSingleton, GlobalSignalsSingleton
|
2022-11-04 09:39:48 +13:00
|
|
|
from rare.ui.components.tabs.games.integrations.eos_widget import Ui_EosWidget
|
2022-01-13 11:46:46 +13:00
|
|
|
|
|
|
|
logger = getLogger("EOS")
|
|
|
|
|
|
|
|
|
|
|
|
def get_wine_prefixes() -> List[str]:
|
2022-10-21 06:55:52 +13:00
|
|
|
prefixes = list()
|
2022-01-20 08:10:10 +13:00
|
|
|
if os.path.exists(p := os.path.expanduser("~/.wine")):
|
2022-10-21 06:55:52 +13:00
|
|
|
prefixes.append(p)
|
|
|
|
|
|
|
|
for name, section in LegendaryCoreSingleton().lgd.config.items():
|
|
|
|
pfx = section.get("WINEPREFIX") or section.get("wine_prefix")
|
|
|
|
if pfx and pfx not in prefixes:
|
|
|
|
prefixes.append(pfx)
|
|
|
|
|
2022-01-13 11:46:46 +13:00
|
|
|
return prefixes
|
|
|
|
|
|
|
|
|
2022-01-14 06:58:07 +13:00
|
|
|
class CheckForUpdateWorker(QRunnable):
|
2022-07-11 08:00:35 +12:00
|
|
|
class CheckForUpdateSignals(QObject):
|
|
|
|
update_available = pyqtSignal(bool)
|
|
|
|
|
2022-01-14 06:58:07 +13:00
|
|
|
def __init__(self):
|
|
|
|
super(CheckForUpdateWorker, self).__init__()
|
2022-07-11 08:00:35 +12:00
|
|
|
self.signals = self.CheckForUpdateSignals()
|
2022-01-14 06:58:07 +13:00
|
|
|
self.setAutoDelete(True)
|
2022-02-26 06:43:27 +13:00
|
|
|
self.core = LegendaryCoreSingleton()
|
2022-01-14 06:58:07 +13:00
|
|
|
|
|
|
|
def run(self) -> None:
|
2022-02-26 06:43:27 +13:00
|
|
|
self.core.check_for_overlay_updates()
|
|
|
|
self.signals.update_available.emit(self.core.overlay_update_available)
|
2022-01-13 11:46:46 +13:00
|
|
|
|
|
|
|
|
2022-11-04 09:34:50 +13:00
|
|
|
class EOSGroup(QGroupBox, Ui_EosWidget):
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
super(EOSGroup, self).__init__(parent=parent)
|
2022-01-13 11:46:46 +13:00
|
|
|
self.setupUi(self)
|
2023-01-26 04:08:43 +13:00
|
|
|
# lk: set object names for CSS properties
|
|
|
|
self.install_button.setObjectName("InstallButton")
|
|
|
|
self.uninstall_button.setObjectName("UninstallButton")
|
|
|
|
|
2022-02-26 06:43:27 +13:00
|
|
|
self.core = LegendaryCoreSingleton()
|
|
|
|
self.signals = GlobalSignalsSingleton()
|
2022-01-13 11:46:46 +13:00
|
|
|
|
|
|
|
self.prefix_enabled = False
|
|
|
|
|
|
|
|
self.enabled_cb.stateChanged.connect(self.change_enable)
|
|
|
|
self.uninstall_button.clicked.connect(self.uninstall_overlay)
|
|
|
|
|
|
|
|
self.update_button.setVisible(False)
|
|
|
|
self.overlay = self.core.lgd.get_overlay_install_info()
|
|
|
|
|
2022-12-29 06:55:15 +13:00
|
|
|
self.signals.application.overlay_installed.connect(self.overlay_installation_finished)
|
|
|
|
self.signals.application.prefix_updated.connect(self.update_prefixes)
|
2022-01-13 11:46:46 +13:00
|
|
|
|
|
|
|
self.update_check_button.clicked.connect(self.check_for_update)
|
|
|
|
self.install_button.clicked.connect(self.install_overlay)
|
2022-01-14 06:58:07 +13:00
|
|
|
self.update_button.clicked.connect(lambda: self.install_overlay(True))
|
2022-01-13 11:46:46 +13:00
|
|
|
|
|
|
|
if self.overlay: # installed
|
2022-11-04 09:34:50 +13:00
|
|
|
self.installed_version_lbl.setText(f"<b>{self.overlay.version}</b>")
|
|
|
|
self.installed_path_lbl.setText(f"<b>{self.overlay.install_path}</b>")
|
|
|
|
self.overlay_stack.setCurrentIndex(0)
|
2022-01-13 11:46:46 +13:00
|
|
|
else:
|
2022-11-04 09:34:50 +13:00
|
|
|
self.overlay_stack.setCurrentIndex(1)
|
|
|
|
self.enable_frame.setDisabled(True)
|
2022-01-13 11:46:46 +13:00
|
|
|
|
|
|
|
if platform.system() == "Windows":
|
|
|
|
self.current_prefix = None
|
|
|
|
self.select_pfx_combo.setVisible(False)
|
|
|
|
else:
|
2022-01-20 08:10:10 +13:00
|
|
|
self.current_prefix = os.path.expanduser("~/.wine") \
|
|
|
|
if os.path.exists(os.path.expanduser("~/.wine")) \
|
|
|
|
else None
|
|
|
|
pfxs = get_wine_prefixes()
|
|
|
|
for pfx in pfxs:
|
2022-01-13 11:46:46 +13:00
|
|
|
self.select_pfx_combo.addItem(pfx.replace(os.path.expanduser("~/"), "~/"))
|
2022-01-20 08:10:10 +13:00
|
|
|
if not pfxs:
|
2022-11-04 09:34:50 +13:00
|
|
|
self.enable_frame.setDisabled(True)
|
2022-01-20 08:10:10 +13:00
|
|
|
else:
|
|
|
|
self.select_pfx_combo.setCurrentIndex(0)
|
2022-01-13 11:46:46 +13:00
|
|
|
|
2022-01-20 08:10:10 +13:00
|
|
|
self.select_pfx_combo.currentIndexChanged.connect(self.update_select_combo)
|
|
|
|
if pfxs:
|
|
|
|
self.update_select_combo(None)
|
2022-01-13 11:46:46 +13:00
|
|
|
|
|
|
|
self.enabled_info_label.setText("")
|
|
|
|
|
2022-01-19 07:46:16 +13:00
|
|
|
self.threadpool = QThreadPool.globalInstance()
|
|
|
|
|
2022-01-20 08:10:10 +13:00
|
|
|
def update_prefixes(self):
|
|
|
|
logger.debug("Updated prefixes")
|
|
|
|
pfxs = get_wine_prefixes() # returns /home/whatever
|
|
|
|
self.select_pfx_combo.clear()
|
|
|
|
|
|
|
|
for pfx in pfxs:
|
|
|
|
self.select_pfx_combo.addItem(pfx.replace(os.path.expanduser("~/"), "~/"))
|
|
|
|
|
|
|
|
if self.current_prefix in pfxs:
|
|
|
|
self.select_pfx_combo.setCurrentIndex(
|
|
|
|
self.select_pfx_combo.findText(self.current_prefix.replace(os.path.expanduser("~/"), "~/")))
|
|
|
|
|
2022-01-13 11:46:46 +13:00
|
|
|
def check_for_update(self):
|
2022-01-14 06:58:07 +13:00
|
|
|
def worker_finished(update_available):
|
|
|
|
self.update_button.setVisible(update_available)
|
|
|
|
self.update_check_button.setDisabled(False)
|
2022-01-19 07:46:16 +13:00
|
|
|
if not update_available:
|
|
|
|
self.update_check_button.setText(self.tr("No update available"))
|
2022-01-14 06:58:07 +13:00
|
|
|
|
|
|
|
self.update_check_button.setDisabled(True)
|
|
|
|
worker = CheckForUpdateWorker()
|
|
|
|
worker.signals.update_available.connect(worker_finished)
|
|
|
|
QThreadPool.globalInstance().start(worker)
|
2022-01-13 11:46:46 +13:00
|
|
|
|
|
|
|
def overlay_installation_finished(self):
|
|
|
|
self.overlay = self.core.lgd.get_overlay_install_info()
|
|
|
|
|
|
|
|
if not self.overlay:
|
|
|
|
logger.error("Something went wrong, when installing overlay")
|
|
|
|
QMessageBox.warning(self, "Error", self.tr("Something went wrong, when installing overlay"))
|
|
|
|
return
|
|
|
|
|
2022-11-04 09:34:50 +13:00
|
|
|
self.overlay_stack.setCurrentIndex(0)
|
|
|
|
self.installed_version_lbl.setText(f"<b>{self.overlay.version}</b>")
|
|
|
|
self.installed_path_lbl.setText(f"<b>{self.overlay.install_path}</b>")
|
2022-01-13 11:46:46 +13:00
|
|
|
|
2022-01-14 06:58:07 +13:00
|
|
|
self.update_button.setVisible(False)
|
|
|
|
|
2022-11-04 09:34:50 +13:00
|
|
|
self.enable_frame.setEnabled(True)
|
2022-01-13 11:46:46 +13:00
|
|
|
|
|
|
|
def update_select_combo(self, i: None):
|
|
|
|
if i is None:
|
|
|
|
i = self.select_pfx_combo.currentIndex()
|
2022-01-20 08:10:10 +13:00
|
|
|
prefix = os.path.expanduser(self.select_pfx_combo.itemText(i))
|
|
|
|
if platform.system() != "Windows" and not os.path.exists(prefix):
|
|
|
|
return
|
2022-01-13 11:46:46 +13:00
|
|
|
self.current_prefix = prefix
|
|
|
|
reg_paths = eos.query_registry_entries(self.current_prefix)
|
|
|
|
|
|
|
|
overlay_enabled = False
|
|
|
|
if reg_paths['overlay_path'] and self.core.is_overlay_install(reg_paths['overlay_path']):
|
|
|
|
overlay_enabled = True
|
|
|
|
self.enabled_cb.setChecked(overlay_enabled)
|
|
|
|
|
|
|
|
def change_enable(self):
|
|
|
|
enabled = self.enabled_cb.isChecked()
|
|
|
|
if not enabled:
|
2022-09-19 11:00:17 +12:00
|
|
|
try:
|
|
|
|
eos.remove_registry_entries(self.current_prefix)
|
|
|
|
except PermissionError:
|
|
|
|
logger.error("Can't disable eos overlay")
|
|
|
|
QMessageBox.warning(self, "Error", self.tr(
|
|
|
|
"Failed to disable Overlay. Probably it is installed by Epic Games Launcher"))
|
|
|
|
return
|
2022-01-13 11:46:46 +13:00
|
|
|
logger.info("Disabled Epic Overlay")
|
|
|
|
self.enabled_info_label.setText(self.tr("Disabled"))
|
|
|
|
else:
|
|
|
|
if not self.overlay:
|
|
|
|
available_installs = self.core.search_overlay_installs(self.current_prefix)
|
|
|
|
if not available_installs:
|
|
|
|
logger.error('No EOS overlay installs found!')
|
|
|
|
return
|
|
|
|
path = available_installs[0]
|
|
|
|
else:
|
|
|
|
path = self.overlay.install_path
|
|
|
|
|
|
|
|
if not self.core.is_overlay_install(path):
|
|
|
|
logger.error(f'Not a valid Overlay installation: {path}')
|
|
|
|
self.select_pfx_combo.removeItem(self.select_pfx_combo.currentIndex())
|
|
|
|
return
|
|
|
|
|
|
|
|
path = os.path.normpath(path)
|
|
|
|
reg_paths = eos.query_registry_entries(self.current_prefix)
|
|
|
|
if old_path := reg_paths["overlay_path"]:
|
|
|
|
if os.path.normpath(old_path) == path:
|
|
|
|
logger.info(f'Overlay already enabled, nothing to do.')
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
logger.info(f'Updating overlay registry entries from "{old_path}" to "{path}"')
|
2022-09-19 11:00:17 +12:00
|
|
|
try:
|
|
|
|
eos.remove_registry_entries(self.current_prefix)
|
|
|
|
except PermissionError:
|
|
|
|
logger.error("Can't disable eos overlay")
|
|
|
|
QMessageBox.warning(self, "Error", self.tr(
|
|
|
|
"Failed to disable Overlay. Probably it is installed by Epic Games Launcher"))
|
|
|
|
return
|
|
|
|
try:
|
|
|
|
eos.add_registry_entries(path, self.current_prefix)
|
|
|
|
except PermissionError:
|
|
|
|
logger.error("Failed to disable eos overlay")
|
|
|
|
QMessageBox.warning(self, "Error", self.tr(
|
|
|
|
"Failed to enable EOS overlay. Maybe it is already installed by Epic Games Launcher"))
|
|
|
|
return
|
2022-01-13 11:46:46 +13:00
|
|
|
self.enabled_info_label.setText(self.tr("Enabled"))
|
|
|
|
logger.info(f'Enabled overlay at: {path}')
|
|
|
|
|
|
|
|
def update_checkbox(self):
|
|
|
|
reg_paths = eos.query_registry_entries(self.current_prefix)
|
|
|
|
enabled = False
|
|
|
|
if reg_paths['overlay_path'] and self.core.is_overlay_install(reg_paths['overlay_path']):
|
|
|
|
enabled = True
|
|
|
|
self.enabled_cb.setChecked(enabled)
|
|
|
|
|
2022-01-14 06:58:07 +13:00
|
|
|
def install_overlay(self, update=False):
|
2023-01-21 13:15:06 +13:00
|
|
|
base_path = os.path.join(
|
|
|
|
self.core.lgd.config.get("Legendary", "install_dir", fallback=os.path.expanduser("~/legendary")),".overlay"
|
|
|
|
)
|
2022-01-14 06:58:07 +13:00
|
|
|
if update:
|
|
|
|
if not self.overlay:
|
2022-11-04 09:34:50 +13:00
|
|
|
self.overlay_stack.setCurrentIndex(1)
|
|
|
|
self.enable_frame.setDisabled(True)
|
2022-01-14 06:58:07 +13:00
|
|
|
QMessageBox.warning(self, "Warning", self.tr("Overlay is not installed. Could not update"))
|
|
|
|
return
|
|
|
|
base_path = self.overlay.install_path
|
|
|
|
|
2023-01-21 13:15:06 +13:00
|
|
|
options = InstallOptionsModel(
|
|
|
|
app_name=eos.EOSOverlayApp.app_name, base_path=base_path, platform="Windows", overlay=True
|
|
|
|
)
|
2022-01-13 11:46:46 +13:00
|
|
|
|
2022-12-29 06:55:15 +13:00
|
|
|
self.signals.game.install.emit(options)
|
2022-01-13 11:46:46 +13:00
|
|
|
|
|
|
|
def uninstall_overlay(self):
|
|
|
|
if not self.core.is_overlay_installed():
|
|
|
|
logger.error('No legendary-managed overlay installation found.')
|
2022-11-04 09:34:50 +13:00
|
|
|
self.overlay_stack.setCurrentIndex(1)
|
2022-01-13 11:46:46 +13:00
|
|
|
return
|
|
|
|
|
|
|
|
if QMessageBox.No == QMessageBox.question(
|
|
|
|
self, "Uninstall Overlay", self.tr("Do you want to uninstall overlay?"),
|
|
|
|
QMessageBox.Yes | QMessageBox.No, QMessageBox.No
|
|
|
|
):
|
|
|
|
return
|
|
|
|
if platform.system() == "Windows":
|
|
|
|
eos.remove_registry_entries(None)
|
|
|
|
else:
|
|
|
|
for prefix in [self.select_pfx_combo.itemText(i) for i in range(self.select_pfx_combo.count())]:
|
2022-01-19 07:46:16 +13:00
|
|
|
logger.info(f"Removing registry entries from {prefix}")
|
2022-01-13 11:46:46 +13:00
|
|
|
try:
|
|
|
|
eos.remove_registry_entries(os.path.expanduser(prefix))
|
2022-01-19 07:46:16 +13:00
|
|
|
except Exception as e:
|
|
|
|
logger.warning(f"{prefix}: {e}")
|
2022-01-13 11:46:46 +13:00
|
|
|
|
|
|
|
self.core.remove_overlay_install()
|
2022-11-04 09:34:50 +13:00
|
|
|
self.overlay_stack.setCurrentIndex(1)
|
2022-01-13 11:46:46 +13:00
|
|
|
|
2022-11-04 09:34:50 +13:00
|
|
|
self.enable_frame.setDisabled(True)
|