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

Login only once. Browser save login

This commit is contained in:
Dummerle 2020-11-28 11:44:26 +01:00
parent 77ffefc664
commit 1ce098c278
10 changed files with 68 additions and 88 deletions

View file

@ -5,6 +5,7 @@ from logging import getLogger
from PyQt5.QtCore import QThread, pyqtSignal, QProcess
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QWidget, QLabel, QHBoxLayout, QVBoxLayout, QPushButton, QStyle
from legendary.core import LegendaryCore
from Rare.Dialogs import InstallDialog, GameSettingsDialog
from Rare.utils import legendaryUtils
@ -36,8 +37,9 @@ class GameWidget(QWidget):
proc: QProcess
signal = pyqtSignal(str)
def __init__(self, game):
def __init__(self, game, core: LegendaryCore):
super(GameWidget, self).__init__()
self.core = core
self.game = game
self.title = game.title
self.app_name = game.app_name
@ -86,9 +88,10 @@ class GameWidget(QWidget):
self.setLayout(self.layout)
def launch(self):
print("Launch")
if not self.game_running:
logger.info(f"launching {self.title}")
self.proc = legendaryUtils.launch_game(self.app_name)
self.proc = legendaryUtils.launch_game(self.app_name, self.core)
if not self.proc:
print("Fail")
return
@ -118,7 +121,8 @@ class GameWidget(QWidget):
settings_dialog = GameSettingsDialog(self.game)
action = settings_dialog.get_settings()
if action == "uninstall":
legendaryUtils.uninstall(self.app_name)
legendaryUtils.uninstall(self.app_name, self.core)
self.signal.emit(self.app_name)
@ -131,8 +135,6 @@ class UninstalledGameWidget(QWidget):
self.layout = QHBoxLayout()
self.game = game
pixmap = QPixmap(f"../images/{game.app_name}/UninstalledArt.png")
pixmap = pixmap.scaled(120, 160)
self.image = QLabel()
@ -164,4 +166,12 @@ class UninstalledGameWidget(QWidget):
if data != 0:
path = data.get("install_path")
logger.info(f"install {self.app_name} in path {path}")
legendaryUtils.install(self.app_name, path=path)
# TODO
self.proc = QProcess()
self.proc.start("legendary", f"-y --base-path {path} {self.app_name}".split(" "))
self.proc.finished.connect(self.download_finished)
# legendaryUtils.install(self.app_name, path=path)
def download_finished(self):
self.setVisible(False)
logger.info("Download finished")

View file

@ -9,13 +9,14 @@ class LaunchThread(QThread):
download_progess = pyqtSignal(int)
action = pyqtSignal(str)
def __init__(self, parent=None):
def __init__(self, core: LegendaryCore, parent=None):
super(LaunchThread, self).__init__(parent)
self.core = core
def run(self):
self.action.emit("Login")
self.action.emit("Downloading Images")
download_images(self.download_progess)
download_images(self.download_progess, self.core)
self.action.emit("finish")
@ -24,7 +25,7 @@ class LaunchDialog(QDialog):
super(LaunchDialog, self).__init__()
self.title = QLabel("<h3>Launching Rare</h3>")
self.thread = LaunchThread(self)
self.thread = LaunchThread(core, self)
self.thread.download_progess.connect(self.update_pb)
self.thread.action.connect(self.info)
self.info_pb = QProgressBar()

View file

@ -4,7 +4,7 @@ from json import loads
from logging import getLogger
from PyQt5.QtCore import QUrl, pyqtSignal
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile, QWebEnginePage
from PyQt5.QtWidgets import QDialog, QWidget, QVBoxLayout, QLabel, QPushButton, QStackedLayout
from legendary.core import LegendaryCore
@ -14,6 +14,9 @@ logger = getLogger("LoginWindow")
class LoginBrowser(QWebEngineView):
def __init__(self):
super(LoginBrowser, self).__init__()
self.browser_profile = QWebEngineProfile("storage", self)
self.webpage = QWebEnginePage(self.browser_profile, self)
self.setPage(self.webpage)
def createWindow(self, webengine_window_type):
return self

View file

@ -4,7 +4,7 @@ import sys
from PyQt5.QtWidgets import QApplication
from legendary.core import LegendaryCore
from Launch import LaunchDialog
from Rare.Launch import LaunchDialog
from Rare.Login import LoginWindow
from Rare.MainWindow import MainWindow
@ -16,15 +16,17 @@ logger = logging.getLogger("Rare")
core = LegendaryCore()
def main():
app = QApplication(sys.argv)
logger.info("Try if you are logged in")
try:
core.login()
logger.info("You are logged in")
if core.login():
logger.info("You are logged in")
else:
logger.error("Login Failed")
main()
except ValueError:
logger.info("You ar not logged in. Open Login Window")

View file

@ -18,10 +18,10 @@ class TabWidget(QTabWidget):
def __init__(self, parent, core):
super(QWidget, self).__init__(parent)
self.game_list = GameListInstalled(self)
self.game_list = GameListInstalled(self, core)
self.addTab(self.game_list, "Games")
self.uninstalled_games = GameListUninstalled(self)
self.uninstalled_games = GameListUninstalled(self, core)
self.addTab(self.uninstalled_games, "Install Games")
self.update_tab = UpdateList(self)

View file

@ -3,22 +3,24 @@ import signal
from logging import getLogger
from PyQt5.QtCore import QUrl, Qt
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile, QWebEnginePage
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QScrollArea, QLineEdit, QPushButton, QFormLayout, QGroupBox, \
QComboBox, QHBoxLayout, QTableWidget, QTableWidgetItem
from legendary.core import LegendaryCore
from Rare.GameWidget import GameWidget, UninstalledGameWidget
from Rare.utils import legendaryConfig, RareConfig
from Rare.utils.legendaryUtils import get_installed, get_not_installed, logout, get_updates, get_name, update
from Rare.utils.legendaryUtils import logout, get_updates, get_name, update
logger = getLogger("TabWidgets")
class BrowserTab(QWebEngineView):
# TODO Save login
def __init__(self, parent):
super(BrowserTab, self).__init__(parent=parent)
self.profile = QWebEngineProfile("storage", self)
self.webpage = QWebEnginePage(self.profile, self)
self.setPage(self.webpage)
self.load(QUrl("https://www.epicgames.com/store/"))
self.show()
@ -31,9 +33,7 @@ class Settings(QScrollArea):
super(Settings, self).__init__(parent=parent)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
# Settings
self.layout = QVBoxLayout()
self.layout.addWidget(QLabel("<h1>Rare Settings</h1>"))
self.logged_in_as = QLabel(f"Logged in as {get_name()}")
@ -158,16 +158,17 @@ class Settings(QScrollArea):
class GameListInstalled(QScrollArea):
def __init__(self, parent):
def __init__(self, parent, core: LegendaryCore):
super(GameListInstalled, self).__init__(parent=parent)
self.widget = QWidget()
self.core = core
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.layout = QVBoxLayout()
self.widgets = {}
for i in get_installed():
widget = GameWidget(i)
for i in sorted(core.get_installed_list(), key=lambda game: game.title):
widget = GameWidget(i, core)
widget.signal.connect(self.remove_game)
self.widgets[i.app_name] = widget
self.layout.addWidget(widget)
@ -183,7 +184,7 @@ class GameListInstalled(QScrollArea):
class GameListUninstalled(QScrollArea):
def __init__(self, parent):
def __init__(self, parent, core: LegendaryCore):
super(GameListUninstalled, self).__init__(parent=parent)
self.widget = QWidget()
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
@ -197,7 +198,13 @@ class GameListUninstalled(QScrollArea):
self.layout.addWidget(self.filter)
self.widgets_uninstalled = []
for game in get_not_installed():
games = []
installed = [i.app_name for i in core.get_installed_list()]
for game in core.get_game_list():
if not game.app_name in installed:
games.append(game)
games = sorted(games, key=lambda x: x.app_title)
for game in games:
game_widget = UninstalledGameWidget(game)
self.layout.addWidget(game_widget)
self.widgets_uninstalled.append(game_widget)

View file

@ -1 +1 @@
__version__="0.0.1"
__version__ = "0.0.1"

View file

@ -19,7 +19,6 @@ if not cfg.sections():
"LOGLEVEL": logging.INFO
}
with open(config_path + '/Rare.ini', 'w') as configfile:
cfg.write(configfile)

View file

@ -4,21 +4,19 @@ from logging import getLogger
import requests
from PIL import Image
from PyQt5.QtCore import pyqtSignal
from Rare.utils import legendaryUtils
from legendary.core import LegendaryCore
logger = getLogger("Utils")
def download_images(signal: pyqtSignal):
def download_images(signal: pyqtSignal, core: LegendaryCore):
IMAGE_DIR = "../images"
if not os.path.isdir(IMAGE_DIR):
os.mkdir(IMAGE_DIR)
logger.info("Create Image dir")
# Download Images
for i, game in enumerate(legendaryUtils.get_games()):
for i, game in enumerate(sorted(core.get_game_list(), key=lambda x: x.app_title)):
for image in game.metadata["keyImages"]:
if image["type"] == "DieselGameBoxTall" or image["type"] == "DieselGameBoxLogo":
if not os.path.isfile(f"{IMAGE_DIR}/{game.app_name}/{image['type']}.png"):
@ -30,6 +28,8 @@ def download_images(signal: pyqtSignal):
with open(f"{IMAGE_DIR}/{game.app_name}/{image['type']}.png", "wb") as f:
f.write(requests.get(url).content)
f.close()
else:
logger.info(f"Image for {game.app_title} exists")
if not os.path.isfile(f'{IMAGE_DIR}/' + game.app_name + '/UninstalledArt.png'):

View file

@ -1,7 +1,6 @@
import logging
import os
import subprocess
from getpass import getuser
from PyQt5.QtCore import QProcess, QProcessEnvironment
from legendary.core import LegendaryCore
@ -52,10 +51,11 @@ def get_games_sorted():
logging.error("No login")
def launch_game(app_name: str, offline: bool = False, skip_version_check: bool = False, username_override=None,
def launch_game(app_name: str, lgd_core: LegendaryCore, 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)
game = lgd_core.get_installed_game(app_name)
if not game:
print("Game not found")
return None
@ -68,23 +68,23 @@ def launch_game(app_name: str, offline: bool = False, skip_version_check: bool =
if not offline:
print("logging in")
if not core.login():
if not lgd_core.login():
return None
if not skip_version_check and not core.is_noupdate_game(app_name):
# check updates
try:
latest = core.get_asset(app_name, update=True)
latest = lgd_core.get_asset(app_name, update=True)
except ValueError:
print("Metadata doesn't exist")
return None
if latest.build_version != game.version:
print("Please update game")
return None
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)
params, cwd, env = lgd_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)
process = QProcess()
process.setWorkingDirectory(cwd)
environment = QProcessEnvironment()
@ -94,47 +94,6 @@ def launch_game(app_name: str, offline: bool = False, skip_version_check: bool =
process.start(params[0], params[1:])
return process
# return subprocess.Popen(params, cwd=cwd, env=env)
def auth_import(lutris: bool = False, wine_prefix: str = None) -> bool:
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:
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 get_updates():
@ -165,9 +124,8 @@ def get_name():
return core.lgd.userdata["displayName"]
def uninstall(app_name: str):
core.uninstall_game(core.get_installed_game(app_name))
def uninstall(app_name: str, lgd_core):
lgd_core.uninstall_game(core.get_installed_game(app_name))
# logger.info("Uninstalling " + app_name)