1
0
Fork 0
mirror of synced 2024-06-02 10:44:40 +12:00

EOSGroup: Add the option to select which overlay installation to enable

This commit is contained in:
loathingKernel 2023-09-10 19:11:03 +03:00
parent 3c43da1594
commit 89486f882e
3 changed files with 107 additions and 84 deletions

View file

@ -4,8 +4,17 @@ from logging import getLogger
from typing import Optional from typing import Optional
from PyQt5.QtCore import QRunnable, QObject, pyqtSignal, QThreadPool, Qt, pyqtSlot, QSize from PyQt5.QtCore import QRunnable, QObject, pyqtSignal, QThreadPool, Qt, pyqtSlot, QSize
from PyQt5.QtWidgets import QGroupBox, QMessageBox, QFrame, QHBoxLayout, QSizePolicy, QLabel, QPushButton, QFormLayout from PyQt5.QtWidgets import (
from legendary.lfs import eos QGroupBox,
QMessageBox,
QFrame,
QHBoxLayout,
QSizePolicy,
QLabel,
QPushButton,
QFormLayout,
QComboBox,
)
from rare.lgndr.core import LegendaryCore from rare.lgndr.core import LegendaryCore
from rare.models.game import RareEosOverlay from rare.models.game import RareEosOverlay
@ -42,55 +51,101 @@ class EosPrefixWidget(QFrame):
self.indicator = QLabel(parent=self) self.indicator = QLabel(parent=self)
self.indicator.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Preferred) self.indicator.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Preferred)
self.label = ElideLabel( self.prefix_label = ElideLabel(prefix if prefix is not None else overlay.app_title, parent=self)
prefix if prefix is not None else "Epic Online Services Overlay", self.overlay_label = ElideLabel(parent=self)
parent=self self.overlay_label.setDisabled(True)
)
self.path_select = QComboBox(self)
self.path_select.setMaximumWidth(150)
self.path_select.setMinimumWidth(150)
self.button = QPushButton(parent=self) self.button = QPushButton(parent=self)
self.button.setMinimumWidth(150) self.button.setMinimumWidth(150)
self.button.clicked.connect(self.action)
layout = QHBoxLayout(self) layout = QHBoxLayout(self)
layout.setContentsMargins(-1, 0, 0, 0) layout.setContentsMargins(-1, 0, 0, 0)
layout.addWidget(self.indicator) layout.addWidget(self.indicator)
layout.addWidget(self.label, stretch=1) layout.addWidget(self.prefix_label, stretch=2)
layout.addWidget(self.overlay_label, stretch=3)
layout.addWidget(self.path_select)
layout.addWidget(self.button) layout.addWidget(self.button)
self.overlay = overlay self.overlay = overlay
self.prefix = prefix self.prefix = prefix
self.path_select.currentIndexChanged.connect(self.path_changed)
self.button.clicked.connect(self.action)
self.overlay.signals.game.installed.connect(self.update_state) self.overlay.signals.game.installed.connect(self.update_state)
self.overlay.signals.game.uninstalled.connect(self.update_state) self.overlay.signals.game.uninstalled.connect(self.update_state)
self.update_state() self.update_state()
@pyqtSlot(int)
def path_changed(self, index: int) -> None:
path = self.path_select.itemData(index, Qt.UserRole)
active_path = os.path.normpath(p) if (p := self.overlay.active_path(self.prefix)) else ""
if self.overlay.is_enabled(self.prefix) and (path == active_path):
self.button.setText(self.tr("Disable overlay"))
else:
self.button.setText(self.tr("Enable overlay"))
@pyqtSlot() @pyqtSlot()
def update_state(self): def update_state(self) -> None:
if not self.overlay.is_installed: active_path = os.path.normpath(p) if (p := self.overlay.active_path(self.prefix)) else ""
self.overlay_label.setText(f"<i>{active_path}<\i>")
self.path_select.clear()
if not self.overlay.is_installed and not self.overlay.available_paths(self.prefix):
self.setDisabled(True) self.setDisabled(True)
self.button.setText(self.tr("Unavailable"))
self.indicator.setPixmap(icon("fa.circle-o", color="grey").pixmap(20, 20)) self.indicator.setPixmap(icon("fa.circle-o", color="grey").pixmap(20, 20))
self.overlay_label.setText(self.overlay.active_path(self.prefix))
self.button.setText(self.tr("Unavailable"))
return return
self.setDisabled(False) self.setDisabled(False)
if self.overlay.is_enabled(self.prefix): if self.overlay.is_enabled(self.prefix):
self.button.setText(self.tr("Disable overlay")) self.indicator.setPixmap(icon("fa.check-circle-o", color="green").pixmap(QSize(20, 20)))
self.indicator.setPixmap(
icon("fa.check-circle-o", color="green").pixmap(QSize(20, 20))
)
else: else:
self.button.setText(self.tr("Enable overlay")) self.indicator.setPixmap(icon("fa.times-circle-o", color="red").pixmap(QSize(20, 20)))
self.indicator.setPixmap(
icon("fa.times-circle-o", color="red").pixmap(QSize(20, 20)) install_path = os.path.normpath(p) if (p := self.overlay.install_path) else ""
)
self.path_select.addItem("Auto-detect", "")
self.path_select.setItemData(0, "Auto-detect", Qt.ToolTipRole)
for path in self.overlay.available_paths(self.prefix):
path = os.path.normpath(path)
self.path_select.addItem("Legendary-managed" if path == install_path else "EGL-managed", path)
self.path_select.setItemData(self.path_select.findData(path), path, Qt.ToolTipRole)
self.path_select.setCurrentIndex(self.path_select.findData(active_path))
@pyqtSlot() @pyqtSlot()
def action(self): def action(self) -> None:
if self.overlay.is_enabled(self.prefix): path = self.path_select.currentData(Qt.UserRole)
self.overlay.disable(prefix=self.prefix) active_path = os.path.normpath(p) if (p := self.overlay.active_path(self.prefix)) else ""
install_path = os.path.normpath(p) if (p := self.overlay.install_path) else ""
if self.overlay.is_enabled(self.prefix) and (path == active_path):
if not self.overlay.disable(prefix=self.prefix):
QMessageBox.warning(
self, "Warning",
self.tr("Failed to completely disable the active EOS Overlay.{}").format(
self.tr(" Since the previous overlay was managed by EGL you can safely ignore this is.")
if active_path != install_path else ""
),
)
else: else:
self.overlay.enable(prefix=self.prefix) self.overlay.disable(prefix=self.prefix)
if not self.overlay.enable(prefix=self.prefix, path=path):
QMessageBox.warning(
self,
"Warning",
self.tr("Failed to completely enable EOS overlay.{}").format(
self.tr(" Since the previous overlay was managed by EGL you can safely ignore this is.")
if active_path != install_path
else ""
),
)
self.update_state() self.update_state()
@ -129,7 +184,7 @@ class EosGroup(QGroupBox):
if self.overlay.is_installed: # installed if self.overlay.is_installed: # installed
self.installed_version_label.setText(f"<b>{self.overlay.version}</b>") self.installed_version_label.setText(f"<b>{self.overlay.version}</b>")
self.installed_path_label.setText(self.overlay.install_path) self.installed_path_label.setText(os.path.normpath(self.overlay.install_path))
self.ui.overlay_stack.setCurrentWidget(self.ui.info_page) self.ui.overlay_stack.setCurrentWidget(self.ui.info_page)
else: else:
self.ui.overlay_stack.setCurrentWidget(self.ui.install_page) self.ui.overlay_stack.setCurrentWidget(self.ui.install_page)
@ -185,65 +240,13 @@ class EosGroup(QGroupBox):
def uninstall_finished(self): def uninstall_finished(self):
self.ui.overlay_stack.setCurrentWidget(self.ui.install_page) self.ui.overlay_stack.setCurrentWidget(self.ui.install_page)
def change_enable(self):
enabled = self.ui.enabled_cb.isChecked()
if not enabled:
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
logger.info("Disabled Epic Overlay")
self.ui.enabled_info_label.setText(self.tr("Disabled"))
else:
if not self.overlay.is_installed:
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.ui.select_pfx_combo.removeItem(self.ui.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}"')
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
self.ui.enabled_info_label.setText(self.tr("Enabled"))
logger.info(f'Enabled overlay at: {path}')
@pyqtSlot() @pyqtSlot()
def install_overlay(self): def install_overlay(self):
self.overlay.install() self.overlay.install()
def uninstall_overlay(self): def uninstall_overlay(self):
if not self.overlay.is_installed: if not self.overlay.is_installed:
logger.error('No Rare-managed overlay installation found.') logger.error("No Legendary-managed overlay installation found.")
self.ui.overlay_stack.setCurrentWidget(self.ui.install_page) self.ui.overlay_stack.setCurrentWidget(self.ui.install_page)
return return
self.overlay.uninstall() self.overlay.uninstall()

View file

@ -583,13 +583,23 @@ class RareEosOverlay(RareGameBase):
reg_paths = eos.query_registry_entries(prefix) reg_paths = eos.query_registry_entries(prefix)
return reg_paths["overlay_path"] and self.core.is_overlay_install(reg_paths["overlay_path"]) return reg_paths["overlay_path"] and self.core.is_overlay_install(reg_paths["overlay_path"])
def active_path(self, prefix: Optional[str] = None) -> str:
path = eos.query_registry_entries(prefix)["overlay_path"]
return path if path and self.core.is_overlay_install(path) else ""
def available_paths(self, prefix: Optional[str] = None) -> List[str]:
return self.core.search_overlay_installs(prefix)
def enable( def enable(
self, prefix: Optional[str] = None, app_name: Optional[str] = None, path: Optional[str] = None self, prefix: Optional[str] = None, path: Optional[str] = None
) -> bool: ) -> bool:
if not self.is_installed or self.is_enabled(prefix): if self.is_enabled(prefix):
return False return False
if not path: if not path:
path = self.igame.install_path if self.is_installed:
path = self.igame.install_path
else:
path = self.available_paths(prefix)[-1]
reg_paths = eos.query_registry_entries(prefix) reg_paths = eos.query_registry_entries(prefix)
if old_path := reg_paths["overlay_path"]: if old_path := reg_paths["overlay_path"]:
if os.path.normpath(old_path) == path: if os.path.normpath(old_path) == path:
@ -598,15 +608,25 @@ class RareEosOverlay(RareGameBase):
else: else:
logger.info(f'Updating overlay registry entries from "{old_path}" to "{path}"') logger.info(f'Updating overlay registry entries from "{old_path}" to "{path}"')
eos.remove_registry_entries(prefix) eos.remove_registry_entries(prefix)
eos.add_registry_entries(path, prefix) try:
eos.add_registry_entries(path, prefix)
except PermissionError as e:
logger.error("Exception while writing registry to enable the overlay .")
logger.error(e)
return False
logger.info(f"Enabled overlay at: {path} for prefix: {prefix}") logger.info(f"Enabled overlay at: {path} for prefix: {prefix}")
return True return True
def disable(self, prefix: Optional[str] = None, app_name: Optional[str] = None) -> bool: def disable(self, prefix: Optional[str] = None) -> bool:
if not self.is_enabled(prefix): if not self.is_enabled(prefix):
return False return False
logger.info(f"Disabling overlay (removing registry keys) for prefix: {prefix}") logger.info(f"Disabling overlay (removing registry keys) for prefix: {prefix}")
eos.remove_registry_entries(prefix) try:
eos.remove_registry_entries(prefix)
except PermissionError as e:
logger.error("Exception while writing registry to disable the overlay.")
logger.error(e)
return False
return True return True
def install(self) -> bool: def install(self) -> bool:

View file

@ -40,7 +40,7 @@ def uninstall_game(
remove_registry_entries(prefix) remove_registry_entries(prefix)
logger.debug("Removed registry entries for prefix %s", prefix) logger.debug("Removed registry entries for prefix %s", prefix)
else: else:
remove_registry_entries(None) remove_registry_entries()
return True, "" return True, ""