2021-02-20 00:57:55 +13:00
|
|
|
import os
|
|
|
|
from getpass import getuser
|
2021-03-15 06:11:55 +13:00
|
|
|
from logging import getLogger
|
2021-02-20 00:57:55 +13:00
|
|
|
|
2021-02-18 22:22:15 +13:00
|
|
|
from PyQt5.QtCore import pyqtSignal
|
2021-02-20 00:57:55 +13:00
|
|
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QLabel, QButtonGroup, QRadioButton
|
2021-03-19 00:45:59 +13:00
|
|
|
|
2021-03-17 03:12:37 +13:00
|
|
|
from custom_legendary.core import LegendaryCore
|
2021-02-18 22:22:15 +13:00
|
|
|
|
2021-03-15 06:11:55 +13:00
|
|
|
logger = getLogger("Import")
|
2021-03-15 06:20:05 +13:00
|
|
|
|
|
|
|
|
2021-02-18 22:22:15 +13:00
|
|
|
class ImportWidget(QWidget):
|
2021-03-15 06:37:26 +13:00
|
|
|
success = pyqtSignal()
|
2021-02-18 22:22:15 +13:00
|
|
|
|
|
|
|
def __init__(self, core: LegendaryCore):
|
|
|
|
super(ImportWidget, self).__init__()
|
|
|
|
self.layout = QVBoxLayout()
|
|
|
|
self.core = core
|
|
|
|
|
|
|
|
self.back = QPushButton("Back")
|
2021-02-20 00:57:55 +13:00
|
|
|
self.layout.addWidget(self.back)
|
|
|
|
self.title = QLabel("<h3>Import existing Login session</h3>")
|
|
|
|
self.title.setWordWrap(True)
|
|
|
|
self.layout.addWidget(self.title)
|
2021-03-15 06:11:55 +13:00
|
|
|
self.infoText = QLabel(
|
|
|
|
"Found Installations here. \nPlease select prefix, where Epic Games Launcher is installed\nNote: You will get logged out there")
|
|
|
|
self.infoText.setWordWrap(True)
|
|
|
|
self.layout.addWidget(self.infoText)
|
|
|
|
self.import_button = QPushButton(self.tr("Import"))
|
|
|
|
self.data_path = ""
|
2021-03-15 06:30:56 +13:00
|
|
|
if os.name == "nt":
|
|
|
|
|
|
|
|
if not self.core.egl.appdata_path and os.path.exists(
|
|
|
|
os.path.expandvars("%LOCALAPPDATA%/EpicGamesLauncher/Saved/Config/Windows")):
|
|
|
|
self.core.egl.appdata_path = os.path.expandvars("%LOCALAPPDATA%/EpicGamesLauncher/Saved/Config/Windows")
|
|
|
|
|
|
|
|
if not self.core.egl.appdata_path:
|
|
|
|
self.text = QLabel(self.tr("Could not find EGL program data"))
|
|
|
|
|
2021-03-15 06:11:55 +13:00
|
|
|
else:
|
2021-03-15 06:30:56 +13:00
|
|
|
self.text = QLabel(self.tr("Found EGL program Data. Do you want to import them?"))
|
|
|
|
|
|
|
|
self.layout.addWidget(self.text)
|
|
|
|
|
|
|
|
# Linux
|
2021-02-20 00:57:55 +13:00
|
|
|
else:
|
2021-03-15 06:11:55 +13:00
|
|
|
self.radio_buttons = []
|
|
|
|
prefixes = self.get_wine_prefixes()
|
|
|
|
if len(prefixes) == 0:
|
|
|
|
self.infoText.setText(self.tr("Could not find any Epic Games login data"))
|
|
|
|
self.import_button.setDisabled(True)
|
|
|
|
else:
|
|
|
|
self.btn_group = QButtonGroup()
|
|
|
|
for i in prefixes:
|
|
|
|
radio_button = QRadioButton(i)
|
|
|
|
self.radio_buttons.append(radio_button)
|
|
|
|
self.btn_group.addButton(radio_button)
|
|
|
|
self.layout.addWidget(radio_button)
|
|
|
|
radio_button.toggled.connect(self.toggle_radiobutton)
|
2021-02-20 00:57:55 +13:00
|
|
|
|
2021-03-15 06:11:55 +13:00
|
|
|
self.login_text = QLabel("")
|
|
|
|
self.layout.addWidget(self.login_text)
|
|
|
|
self.layout.addWidget(self.import_button)
|
|
|
|
self.import_button.clicked.connect(self.import_login_data)
|
2021-02-20 00:57:55 +13:00
|
|
|
|
|
|
|
self.setLayout(self.layout)
|
|
|
|
|
2021-03-15 06:11:55 +13:00
|
|
|
def toggle_radiobutton(self):
|
|
|
|
if self.sender().isChecked():
|
|
|
|
self.data_path = self.sender().text()
|
2021-02-20 00:57:55 +13:00
|
|
|
|
2021-03-15 06:11:55 +13:00
|
|
|
def get_wine_prefixes(self):
|
|
|
|
possible_prefixes = [
|
|
|
|
os.path.expanduser("~/.wine"),
|
|
|
|
os.path.expanduser("~/Games/epic-games-store")
|
|
|
|
]
|
|
|
|
prefixes = []
|
|
|
|
for i in possible_prefixes:
|
|
|
|
if os.path.exists(os.path.join(i, "drive_c/users", getuser(),
|
|
|
|
"Local Settings/Application Data/EpicGamesLauncher/Saved/Config/Windows")):
|
|
|
|
prefixes.append(i)
|
|
|
|
return prefixes
|
2021-02-20 00:57:55 +13:00
|
|
|
|
2021-03-15 06:11:55 +13:00
|
|
|
def import_login_data(self):
|
|
|
|
self.import_button.setText(self.tr("Loading..."))
|
|
|
|
self.import_button.setDisabled(True)
|
|
|
|
if os.name != "nt":
|
2021-03-15 06:20:05 +13:00
|
|
|
self.core.egl.appdata_path = os.path.join(self.data_path,
|
|
|
|
f"drive_c/users/{getuser()}/Local Settings/Application Data/EpicGamesLauncher/Saved/Config/Windows")
|
2021-04-07 20:44:16 +12:00
|
|
|
try:
|
|
|
|
if self.core.auth_import():
|
|
|
|
logger.info(f"Logged in as {self.core.lgd.userdata['displayName']}")
|
|
|
|
self.success.emit()
|
|
|
|
else:
|
|
|
|
logger.warning("Failed to import existing session")
|
|
|
|
except Exception as e:
|
|
|
|
logger.warning(e)
|
2021-03-15 06:30:56 +13:00
|
|
|
|
2021-03-15 06:11:55 +13:00
|
|
|
logger.warning("Error: No valid session found")
|
|
|
|
self.login_text.setText(self.tr("Error: No valid session found"))
|
|
|
|
self.import_button.setText(self.tr("Import"))
|
2021-03-15 06:20:05 +13:00
|
|
|
self.import_button.setDisabled(False)
|