Login, launchdialog download features
This commit is contained in:
parent
75b39cb189
commit
98c8cbb8a5
78
Rare/Components/Launch/LaunchDialog.py
Normal file
78
Rare/Components/Launch/LaunchDialog.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
from logging import getLogger
|
||||
|
||||
from PyQt5.QtCore import QThread, pyqtSignal
|
||||
from PyQt5.QtWidgets import QDialog, QLabel, QProgressBar, QVBoxLayout
|
||||
from legendary.core import LegendaryCore
|
||||
|
||||
from Rare.utils.Dialogs.Login.LoginDialog import LoginDialog
|
||||
from Rare.utils.utils import download_images
|
||||
logger = getLogger("Login")
|
||||
|
||||
class LaunchThread(QThread):
|
||||
download_progess = pyqtSignal(int)
|
||||
action = pyqtSignal(str)
|
||||
|
||||
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, self.core)
|
||||
self.action.emit("finish")
|
||||
|
||||
class LoginThread(QThread):
|
||||
def __init__(self, core: LegendaryCore):
|
||||
super(LoginThread, self).__init__()
|
||||
self.core = core
|
||||
|
||||
def run(self):
|
||||
logger.info("Try if you are logged in")
|
||||
try:
|
||||
if self.core.login():
|
||||
logger.info("You are logged in")
|
||||
else:
|
||||
self.run()
|
||||
except ValueError:
|
||||
logger.info("You are not logged in. Open Login Window")
|
||||
login_window = LoginDialog(self.core)
|
||||
if not login_window.login():
|
||||
return
|
||||
|
||||
|
||||
class LaunchDialog(QDialog):
|
||||
def __init__(self, core: LegendaryCore):
|
||||
super(LaunchDialog, self).__init__()
|
||||
self.core = core
|
||||
self.login_thread = LoginThread(core)
|
||||
self.login_thread.finished.connect(self.launch)
|
||||
self.login_thread.start()
|
||||
|
||||
self.title = QLabel("<h3>"+self.tr("Launching Rare")+"</h3>")
|
||||
self.info_pb = QProgressBar()
|
||||
self.info_text = QLabel(self.tr("Logging in"))
|
||||
self.layout = QVBoxLayout()
|
||||
|
||||
self.layout.addWidget(self.title)
|
||||
self.layout.addWidget(self.info_pb)
|
||||
self.layout.addWidget(self.info_text)
|
||||
|
||||
self.setLayout(self.layout)
|
||||
|
||||
|
||||
def launch(self):
|
||||
self.info_pb.setMaximum(len(self.core.get_game_list()))
|
||||
self.info_text.setText("Downloading Images")
|
||||
self.thread = LaunchThread(self.core, self)
|
||||
self.thread.download_progess.connect(self.update_pb)
|
||||
self.thread.action.connect(self.info)
|
||||
self.thread.start()
|
||||
|
||||
def update_pb(self, i: int):
|
||||
self.info_pb.setValue(i)
|
||||
|
||||
def info(self, text: str):
|
||||
if text == "finish":
|
||||
self.close()
|
||||
self.info_text.setText(text)
|
0
Rare/Components/Launch/__init__.py
Normal file
0
Rare/Components/Launch/__init__.py
Normal file
|
@ -108,6 +108,7 @@ class DownloadTab(QWidget):
|
|||
|
||||
def install_game(self, options: {}):
|
||||
game = self.core.get_game(options["app_name"])
|
||||
|
||||
dlm, analysis, igame = self.core.prepare_download(
|
||||
game=game,
|
||||
base_path=options["options"]["path"],
|
||||
|
|
|
@ -27,23 +27,19 @@ class GameList(QScrollArea):
|
|||
self.widgets=[]
|
||||
self.layout = FlowLayout()
|
||||
# Installed Games
|
||||
for game in self.core.get_installed_list():
|
||||
for game in sorted(self.core.get_installed_list(), key=lambda x: x.title):
|
||||
# continue
|
||||
widget = GameWidgetInstalled(self.core, game)
|
||||
self.layout.addWidget(widget)
|
||||
widget.update_list.connect(self.update_list)
|
||||
|
||||
uninstalled_games = []
|
||||
installed = []
|
||||
installed = [i.app_name for i in self.core.get_installed_list()]
|
||||
print(len(installed))
|
||||
# get Uninstalled games
|
||||
print(len(self.core.get_game_list()))
|
||||
for game in sorted(self.core.get_game_list(), key=lambda x: x.app_title):
|
||||
if not game.app_name in installed:
|
||||
uninstalled_games.append(game)
|
||||
# add uninstalled to gui
|
||||
print(len(uninstalled_games))
|
||||
for game in uninstalled_games:
|
||||
widget = GameWidgetUninstalled(self.core, game)
|
||||
widget.install_game.connect(lambda options: self.install_game.emit(options))
|
||||
|
@ -68,6 +64,5 @@ class GameList(QScrollArea):
|
|||
def update_list(self):
|
||||
print("Updating List")
|
||||
self.setWidget(QWidget())
|
||||
self.core.login()
|
||||
self.init_ui()
|
||||
self.update()
|
|
@ -39,6 +39,7 @@ class GameWidgetInstalled(QWidget):
|
|||
else:
|
||||
logger.warning(f"No Image found: {self.game.title}")
|
||||
pixmap = None
|
||||
|
||||
if pixmap:
|
||||
w = 200
|
||||
pixmap = pixmap.scaled(w, int(w * 4 / 3))
|
||||
|
|
41
Rare/Main.py
41
Rare/Main.py
|
@ -2,20 +2,17 @@ import logging
|
|||
import os
|
||||
import sys
|
||||
|
||||
import requests
|
||||
from PyQt5.QtCore import QTranslator, pyqtSignal
|
||||
from PyQt5.QtWidgets import QApplication, QMessageBox
|
||||
|
||||
from PyQt5.QtCore import QTranslator
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
from legendary.core import LegendaryCore
|
||||
|
||||
from Rare import style_path, lang_path
|
||||
from Rare.Components.Launch.LaunchDialog import LaunchDialog
|
||||
from Rare.Components.MainWindow import MainWindow
|
||||
|
||||
# from Rare.Start.Launch import LaunchDialog
|
||||
# from Rare.Start.Login import LoginWindow
|
||||
# from Rare.utils.RareUtils import get_lang
|
||||
from Rare.utils.Dialogs.Login.LoginDialog import LoginDialog
|
||||
from Rare.utils.utils import download_images, get_lang
|
||||
from Rare.utils.utils import get_lang
|
||||
|
||||
logging.basicConfig(
|
||||
format='[%(name)s] %(levelname)s: %(message)s',
|
||||
|
@ -39,35 +36,9 @@ def main():
|
|||
# Style
|
||||
app.setStyleSheet(open(style_path + "RareStyle.qss").read())
|
||||
|
||||
# Offline mode (not completed)
|
||||
offline = True
|
||||
# Login
|
||||
logger.info("Try if you are logged in")
|
||||
try:
|
||||
if core.login():
|
||||
logger.info("You are logged in")
|
||||
offline = False
|
||||
else:
|
||||
logger.error("Login Failed")
|
||||
main()
|
||||
|
||||
except ValueError:
|
||||
# If not Logged in: Start Login window
|
||||
logger.info("You are not logged in. Open Login Window")
|
||||
login_window = LoginDialog(core)
|
||||
if not login_window.login():
|
||||
return
|
||||
|
||||
# Start Offline mode
|
||||
except requests.exceptions.ConnectionError:
|
||||
offline = True
|
||||
QMessageBox.information(None, "Offline", "You are offline. Launching Rare in offline mode")
|
||||
# Launch Offlienmode
|
||||
if not offline:
|
||||
# launch_dialog = LaunchDialog(core)
|
||||
# launch_dialog.exec_()
|
||||
pass
|
||||
# mainwindow = MainWindow(core)
|
||||
launch_dialog = LaunchDialog(core)
|
||||
launch_dialog.exec_()
|
||||
mainwindow = MainWindow(core)
|
||||
|
||||
app.exec_()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import json
|
||||
import os
|
||||
import shutil
|
||||
from logging import getLogger
|
||||
|
||||
import requests
|
||||
|
@ -20,7 +21,13 @@ def download_images(signal: pyqtSignal, core: LegendaryCore):
|
|||
|
||||
# Download Images
|
||||
for i, game in enumerate(sorted(core.get_game_list(), key=lambda x: x.app_title)):
|
||||
download_image(game)
|
||||
signal.emit(i)
|
||||
|
||||
|
||||
def download_image(game, force=False):
|
||||
if force:
|
||||
shutil.rmtree(f"{IMAGE_DIR}/{game.app_name}")
|
||||
if not os.path.isdir(f"{IMAGE_DIR}/" + game.app_name):
|
||||
os.mkdir(f"{IMAGE_DIR}/" + game.app_name)
|
||||
|
||||
|
@ -28,7 +35,7 @@ def download_images(signal: pyqtSignal, core: LegendaryCore):
|
|||
json_data = {"DieselGameBoxTall": None, "DieselGameBoxLogo": None}
|
||||
else:
|
||||
json_data = json.load(open(f"{IMAGE_DIR}/{game.app_name}/image.json", "r"))
|
||||
|
||||
# Download
|
||||
for image in game.metadata["keyImages"]:
|
||||
if image["type"] == "DieselGameBoxTall" or image["type"] == "DieselGameBoxLogo":
|
||||
|
||||
|
@ -43,7 +50,7 @@ def download_images(signal: pyqtSignal, core: LegendaryCore):
|
|||
with open(f"{IMAGE_DIR}/{game.app_name}/{image['type']}.png", "wb") as f:
|
||||
f.write(requests.get(url).content)
|
||||
f.close()
|
||||
|
||||
# scale and grey
|
||||
if not os.path.isfile(f'{IMAGE_DIR}/' + game.app_name + '/UninstalledArt.png'):
|
||||
|
||||
if os.path.isfile(f'{IMAGE_DIR}/' + game.app_name + '/DieselGameBoxTall.png'):
|
||||
|
@ -78,7 +85,6 @@ def download_images(signal: pyqtSignal, core: LegendaryCore):
|
|||
uninstalledArt.save(f'{IMAGE_DIR}/' + game.app_name + '/UninstalledArt.png')
|
||||
else:
|
||||
logger.warning(f"File {IMAGE_DIR}/{game.app_name}/DieselGameBoxTall.png dowsn't exist")
|
||||
signal.emit(i)
|
||||
|
||||
|
||||
def get_lang():
|
||||
|
|
Loading…
Reference in a new issue