login via import
This commit is contained in:
parent
135e686962
commit
abc0d5d433
|
@ -1,7 +1,58 @@
|
|||
import os
|
||||
|
||||
from PyQt5.QtWidgets import QDialog, QVBoxLayout, QHBoxLayout, QPushButton, QLabel, QLineEdit
|
||||
from Rare.utils import legendaryUtils
|
||||
from PyQt5.QtCore import pyqtSignal
|
||||
from PyQt5.QtWidgets import QDialog, QStackedLayout, QHBoxLayout, QWidget, QVBoxLayout, QPushButton, QLineEdit, QLabel
|
||||
|
||||
from Rare.Login import ImportWidget
|
||||
|
||||
|
||||
class LoginDialog(QDialog):
|
||||
signal = pyqtSignal(bool)
|
||||
|
||||
def __init__(self):
|
||||
super(LoginDialog, self).__init__()
|
||||
self.layout = QStackedLayout()
|
||||
|
||||
self.widget = QWidget()
|
||||
self.import_widget = ImportWidget()
|
||||
self.login_widget = QWidget()
|
||||
self.import_widget.signal.connect(self.loggedin)
|
||||
self.initWidget()
|
||||
|
||||
self.layout.insertWidget(0, self.widget)
|
||||
self.layout.insertWidget(1, self.login_widget)
|
||||
self.layout.insertWidget(2, self.import_widget)
|
||||
|
||||
self.setLayout(self.layout)
|
||||
self.layout.setCurrentIndex(0)
|
||||
|
||||
def initWidget(self):
|
||||
self.widget_layout = QVBoxLayout()
|
||||
self.login_button = QPushButton("Login via Browser")
|
||||
self.import_button = QPushButton("Import from existing EGL installation")
|
||||
self.close_button = QPushButton("Exit")
|
||||
|
||||
# self.login_button.clicked.connect(self.login)
|
||||
self.import_button.clicked.connect(self.set_import_widget)
|
||||
self.close_button.clicked.connect(self.exit_login)
|
||||
|
||||
self.widget_layout.addWidget(self.login_button)
|
||||
self.widget_layout.addWidget(self.import_button)
|
||||
self.widget_layout.addWidget(self.close_button)
|
||||
self.widget.setLayout(self.widget_layout)
|
||||
|
||||
def loggedin(self, int):
|
||||
self.signal.emit(True)
|
||||
|
||||
def login(self):
|
||||
self.layout.setCurrentIndex(1)
|
||||
|
||||
def set_import_widget(self):
|
||||
self.layout.setCurrentIndex(2)
|
||||
|
||||
def exit_login(self):
|
||||
self.signal.emit(False)
|
||||
|
||||
|
||||
class InstallDialog(QDialog):
|
||||
def __init__(self, game):
|
||||
|
@ -44,38 +95,6 @@ class InstallDialog(QDialog):
|
|||
self.close()
|
||||
|
||||
|
||||
class LoginDialog(QDialog):
|
||||
def __init__(self):
|
||||
super(LoginDialog, self).__init__()
|
||||
self.open_browser_button = QPushButton("Open Browser to get sid")
|
||||
self.open_browser_button.clicked.connect(self.open_browser)
|
||||
self.sid_field = QLineEdit()
|
||||
self.sid_field.setPlaceholderText("Enter sid from the Browser")
|
||||
self.login_button = QPushButton("Login")
|
||||
self.login_button.clicked.connect(self.login)
|
||||
self.import_button = QPushButton("Or Import Login from EGL")
|
||||
self.import_button.clicked.connect(self.import_key)
|
||||
|
||||
self.layout = QVBoxLayout()
|
||||
self.layout.addWidget(self.open_browser_button)
|
||||
self.layout.addWidget(self.sid_field)
|
||||
self.layout.addWidget(self.login_button)
|
||||
self.layout.addWidget(self.import_button)
|
||||
self.setLayout(self.layout)
|
||||
|
||||
def open_browser(self):
|
||||
pass
|
||||
|
||||
def login(self):
|
||||
legendaryUtils.auth(self.sid_field.text())
|
||||
|
||||
def import_key(self):
|
||||
if legendaryUtils.auth_import():
|
||||
self.close()
|
||||
else:
|
||||
self.import_button.setText("Das hat nicht funktioniert")
|
||||
|
||||
|
||||
class GameSettingsDialog(QDialog):
|
||||
def __init__(self):
|
||||
super(GameSettingsDialog, self).__init__()
|
||||
super(GameSettingsDialog, self).__init__()
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import subprocess
|
||||
|
||||
from PyQt5.QtGui import QPixmap
|
||||
from PyQt5.QtWidgets import QWidget, QLabel, QHBoxLayout, QVBoxLayout, QPushButton, QStyle
|
||||
|
||||
|
@ -8,14 +10,14 @@ from Rare.utils import legendaryUtils
|
|||
class GameWidget(QWidget):
|
||||
def __init__(self, game):
|
||||
super(GameWidget, self).__init__()
|
||||
|
||||
self.proc: subprocess.Popen = None
|
||||
self.title = game.title
|
||||
self.app_name = game.app_name
|
||||
self.version = game.version
|
||||
self.size = game.install_size
|
||||
self.launch_params = game.launch_parameters
|
||||
#self.dev =
|
||||
|
||||
# self.dev =
|
||||
self.game_running = False
|
||||
self.layout = QHBoxLayout()
|
||||
|
||||
pixmap = QPixmap(f"../images/{game.app_name}/FinalArt.png")
|
||||
|
@ -50,10 +52,15 @@ class GameWidget(QWidget):
|
|||
self.setLayout(self.layout)
|
||||
|
||||
def launch(self):
|
||||
print(f"launch {self.title}")
|
||||
self.launch_button.setText("Running")
|
||||
self.launch_button.setDisabled(True)
|
||||
legendaryUtils.start(self.app_name) # adding launch params #TODO
|
||||
if not self.game_running:
|
||||
print(f"launch {self.title}")
|
||||
self.launch_button.setText("Kill")
|
||||
self.proc = legendaryUtils.launch_game(self.app_name)
|
||||
self.game_running = True
|
||||
else:
|
||||
self.proc.kill()
|
||||
self.launch_button.setText("Launch")
|
||||
self.game_running = False
|
||||
|
||||
def get_rating(self) -> str:
|
||||
return "gold" # TODO
|
||||
|
@ -94,4 +101,3 @@ class UninstalledGameWidget(QWidget):
|
|||
path = data.get("install_path")
|
||||
print(path)
|
||||
# TODO
|
||||
|
||||
|
|
65
Rare/Login.py
Normal file
65
Rare/Login.py
Normal file
|
@ -0,0 +1,65 @@
|
|||
import os
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal
|
||||
from PyQt5.QtWidgets import QLineEdit, QPushButton, QCheckBox, QVBoxLayout, QWidget, QLabel
|
||||
|
||||
from Rare.utils import legendaryUtils
|
||||
|
||||
|
||||
class ImportWidget(QWidget):
|
||||
signal = pyqtSignal(int)
|
||||
def __init__(self):
|
||||
super(ImportWidget, self).__init__()
|
||||
|
||||
self.layout = QVBoxLayout()
|
||||
|
||||
self.use_lutris_button = QCheckBox("Use from Lutris")
|
||||
self.insert_wine_prefix = QLineEdit()
|
||||
self.info_text = QLabel("Use login from an existing EGL installation. You will logged out there")
|
||||
|
||||
self.layout.addWidget(self.info_text)
|
||||
if os.name != "nt":
|
||||
self.insert_wine_prefix.setPlaceholderText("Or insert path of wineprefix")
|
||||
self.layout.addWidget(self.use_lutris_button)
|
||||
self.layout.addWidget(self.insert_wine_prefix)
|
||||
|
||||
self.import_button = QPushButton("Import Login from EGL")
|
||||
self.import_button.clicked.connect(self.import_key)
|
||||
self.text = QLabel()
|
||||
self.layout.addWidget(self.text)
|
||||
|
||||
self.layout.addWidget(self.import_button)
|
||||
|
||||
self.setLayout(self.layout)
|
||||
|
||||
def import_key(self):
|
||||
wine_prefix = self.insert_wine_prefix.text()
|
||||
if wine_prefix == "":
|
||||
wine_prefix = None
|
||||
|
||||
print("import")
|
||||
if self.use_lutris_button.isChecked():
|
||||
if legendaryUtils.auth_import(wine_prefix=wine_prefix,
|
||||
lutris=self.use_lutris_button.isChecked()):
|
||||
print("login successful")
|
||||
self.signal.emit(0)
|
||||
else:
|
||||
self.text.setText("Failed")
|
||||
self.import_button.setText("Das hat nicht funktioniert")
|
||||
|
||||
|
||||
class LoginWidget(QWidget):
|
||||
def __init__(self):
|
||||
super(LoginWidget, self).__init__()
|
||||
self.open_browser_button = QPushButton("Open Browser to get sid")
|
||||
self.open_browser_button.clicked.connect(self.open_browser)
|
||||
self.sid_field = QLineEdit()
|
||||
self.sid_field.setPlaceholderText("Enter sid from the Browser")
|
||||
self.login_button = QPushButton("Login")
|
||||
self.login_button.clicked.connect(self.login)
|
||||
|
||||
def login(self):
|
||||
pass
|
||||
|
||||
def open_browser(self):
|
||||
pass
|
16
Rare/Main.py
16
Rare/Main.py
|
@ -38,17 +38,10 @@ class TabWidget(QTabWidget):
|
|||
self.addTab(self.settings, "Settings")
|
||||
|
||||
|
||||
class LoginWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super(LoginWindow, self).__init__()
|
||||
self.setWindowTitle("Rare - Login")
|
||||
self.setGeometry(0, 0, 200, 150)
|
||||
self.show()
|
||||
|
||||
|
||||
def main():
|
||||
def main(start: bool = True):
|
||||
# Check if Legendary is installed
|
||||
|
||||
if not bool:
|
||||
exit(0)
|
||||
if os.path.isfile(os.path.expanduser("~") + '/.config/legendary/user.json'):
|
||||
print("Launching Rare")
|
||||
startMainProcess()
|
||||
|
@ -67,8 +60,9 @@ def startMainProcess():
|
|||
def notLoggedIn():
|
||||
app = QApplication(sys.argv)
|
||||
dia = LoginDialog()
|
||||
dia.signal.connect(main)
|
||||
dia.show()
|
||||
sys.exit(app.exec_())
|
||||
app.exec_()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
import os
|
||||
from argparse import Namespace
|
||||
from distutils.util import strtobool
|
||||
import subprocess
|
||||
|
||||
from legendary.cli import LegendaryCLI
|
||||
from legendary.core import LegendaryCore
|
||||
|
||||
core = LegendaryCore()
|
||||
cli = LegendaryCLI()
|
||||
from getpass import getuser
|
||||
|
||||
|
||||
def get_installed():
|
||||
|
@ -58,43 +56,95 @@ def get_games():
|
|||
return core.get_game_list()
|
||||
|
||||
|
||||
def start(game_name,
|
||||
offline=False,
|
||||
skip_version_check=False,
|
||||
reset_defaults=None,
|
||||
set_defaults=None,
|
||||
wine_bin=os.environ.get('LGDRY_WINE_BINARY', None),
|
||||
wine_pfx=os.environ.get('LGDRY_WINE_PREFIX', None),
|
||||
no_wine=strtobool(os.environ.get('LGDRY_NO_WINE', 'False')),
|
||||
debug=False,
|
||||
dry_run=False,
|
||||
user_name_override=None,
|
||||
language=None
|
||||
):
|
||||
cli.launch_game(Namespace(app_name=game_name,
|
||||
offline=offline,
|
||||
wrapper=os.environ.get('LGDRY_WRAPPER', None),
|
||||
skip_version_check=skip_version_check,
|
||||
reset_defaults=reset_defaults,
|
||||
set_defaults=set_defaults,
|
||||
wine_bin=wine_bin,
|
||||
wine_pfx=wine_pfx,
|
||||
no_wine=no_wine,
|
||||
debug=debug,
|
||||
dry_run=dry_run,
|
||||
user_name_override=user_name_override,
|
||||
language=language
|
||||
),
|
||||
[] # Extra
|
||||
)
|
||||
def launch_game(app_name: str, offline: bool = False, skip_version_check: bool = False, username_override=None,
|
||||
wine_bin: str = None, wine_prfix: str = None, language: str = None, wrapper=None,
|
||||
no_wine: bool = os.name == "nt", extra: [] = None):
|
||||
game = core.get_installed_game(app_name)
|
||||
if not game:
|
||||
return 1
|
||||
if game.is_dlc:
|
||||
return 1
|
||||
if not os.path.exists(game.install_path):
|
||||
return 1
|
||||
|
||||
def auth(sid:str):
|
||||
if not offline:
|
||||
print("logging in")
|
||||
if not core.login():
|
||||
return 1
|
||||
if not skip_version_check and not core.is_noupdate_game(app_name):
|
||||
# check updates
|
||||
try:
|
||||
latest = core.get_asset(app_name, update=True)
|
||||
except ValueError:
|
||||
print("Metadata doesn't exist")
|
||||
return 1
|
||||
if latest.build_version != game.version:
|
||||
print("Please update game")
|
||||
return 1
|
||||
params, cwd, env = core.get_launch_parameters(app_name=app_name, offline=offline,
|
||||
extra_args=extra, user=username_override,
|
||||
wine_bin=wine_bin, wine_pfx=wine_prfix,
|
||||
language=language, wrapper=wrapper,
|
||||
disable_wine=no_wine)
|
||||
|
||||
cli.auth(Namespace(session_id=sid))
|
||||
return subprocess.Popen(params, cwd=cwd, env=env)
|
||||
|
||||
|
||||
def auth_import():
|
||||
def auth(sid: str):
|
||||
# cli.auth(Namespace(session_id=sid))
|
||||
pass
|
||||
|
||||
|
||||
def auth_import(lutris: bool = False, wine_prefix: str = None) -> bool:
|
||||
'''
|
||||
import Data from existing Egl installation
|
||||
|
||||
:param lutris only linux automate using lutris wine prefix:
|
||||
:param wine_prefix only linux path to wine_prefix:
|
||||
:return success:
|
||||
'''
|
||||
print(lutris, wine_prefix)
|
||||
# Linux
|
||||
if not core.egl.appdata_path:
|
||||
lutris_wine_users = os.path.expanduser('~/Games/epic-games-store/drive_c/users')
|
||||
wine_pfx_users = None
|
||||
if lutris and os.path.exists(lutris_wine_users):
|
||||
print(f'Found Lutris EGL WINE prefix at "{lutris_wine_users}"')
|
||||
wine_pfx_users = lutris_wine_users
|
||||
|
||||
elif wine_prefix:
|
||||
if not os.path.exists(wine_prefix):
|
||||
print("invalid path")
|
||||
wine_pfx_users = os.path.join(wine_prefix, "drive_c/users")
|
||||
else:
|
||||
print("insert parameter")
|
||||
return False
|
||||
|
||||
appdata_dir = os.path.join(wine_pfx_users, getuser(),
|
||||
'Local Settings/Application Data/EpicGamesLauncher',
|
||||
'Saved/Config/Windows')
|
||||
|
||||
if not os.path.exists(appdata_dir):
|
||||
print("No EGL appdata")
|
||||
return False
|
||||
core.egl.appdata_path = appdata_dir
|
||||
|
||||
try:
|
||||
cli.auth(Namespace(import_egs_auth=True))
|
||||
except:
|
||||
pass
|
||||
if core.auth_import():
|
||||
print("Successfully logged in")
|
||||
print(f"Logged in as {core.lgd.userdata['displayName']}")
|
||||
return True
|
||||
else:
|
||||
print("Error: No valid session found")
|
||||
return False
|
||||
except ValueError:
|
||||
print("No session found")
|
||||
return False
|
||||
|
||||
|
||||
def logout():
|
||||
core.lgd.invalidate_userdata()
|
||||
|
||||
|
||||
def install(app_name: str, path: str):
|
||||
pass
|
||||
|
|
Loading…
Reference in a new issue