Sync Saves not pretty
This commit is contained in:
parent
e0dd3fad24
commit
20a9afc21f
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,3 +7,4 @@
|
|||
/dist/
|
||||
/Rare.egg-info/
|
||||
/RareBuild.sh
|
||||
/venv/
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
include Rare/Styles/dark.qss
|
||||
include Rare/Styles/RareStyle.css
|
||||
include README.md
|
|
@ -40,6 +40,7 @@ Using the exe-file could cause an error with the stylesheets
|
|||
### Todos
|
||||
- Download Progressbar
|
||||
- Sync saves
|
||||
|
||||
- Translations
|
||||
- Design(Pretty Stylesheets, Icon view)
|
||||
|
||||
|
|
|
@ -8,7 +8,3 @@ QPushButton#launch_game_button {
|
|||
color: white;
|
||||
}
|
||||
|
||||
QProgressbar {
|
||||
border: 2px solid grey;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
|
|
@ -57,14 +57,7 @@ class GameWidget(QWidget):
|
|||
self.launch_button = QPushButton(play_icon, "Launch")
|
||||
self.launch_button.setObjectName("launch_game_button")
|
||||
self.launch_button.setFixedWidth(120)
|
||||
'''
|
||||
self.launch_button.setStyleSheet("""
|
||||
QPushButton{
|
||||
background-color: blue;
|
||||
color: white;
|
||||
}
|
||||
""")
|
||||
'''
|
||||
|
||||
self.launch_button.clicked.connect(self.launch)
|
||||
if os.name != "nt":
|
||||
self.wine_rating = QLabel("Wine Rating: " + self.get_rating())
|
||||
|
|
|
@ -9,6 +9,7 @@ from legendary.core import LegendaryCore
|
|||
|
||||
from Rare.Tabs.GamesInstalled.GameWidget import GameWidget
|
||||
from Rare.utils import legendaryUtils
|
||||
from Rare.utils.Dialogs.SyncSavesDialog import SyncSavesDialog
|
||||
|
||||
logger = getLogger("InstalledList")
|
||||
|
||||
|
@ -28,10 +29,14 @@ class GameListInstalled(QScrollArea):
|
|||
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||
|
||||
self.layout = QVBoxLayout()
|
||||
|
||||
self.update_button = QPushButton("Update")
|
||||
mini_layout = QHBoxLayout()
|
||||
self.update_button = QPushButton("Manually reload Games")
|
||||
self.update_button.clicked.connect(self.update_list)
|
||||
self.layout.addWidget(self.update_button)
|
||||
mini_layout.addWidget(self.update_button)
|
||||
self.upload_button = QPushButton("Cloud Saves")
|
||||
mini_layout.addWidget(self.upload_button)
|
||||
self.upload_button.clicked.connect(self.sync_saves)
|
||||
self.layout.addLayout(mini_layout)
|
||||
self.widgets = {}
|
||||
games = sorted(self.core.get_installed_list(), key=lambda game: game.title)
|
||||
if games:
|
||||
|
@ -106,3 +111,6 @@ class GameListInstalled(QScrollArea):
|
|||
self.setWidget(QWidget())
|
||||
self.init_ui()
|
||||
self.update()
|
||||
|
||||
def sync_saves(self):
|
||||
SyncSavesDialog(self.core).exec_()
|
||||
|
|
|
@ -18,7 +18,7 @@ class SettingsTab(QScrollArea):
|
|||
self.core = core
|
||||
self.widget = QWidget()
|
||||
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
||||
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
||||
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||
# Settings
|
||||
self.layout = QVBoxLayout()
|
||||
self.layout.addWidget(QLabel("<h1>Rare Settings</h1>"))
|
||||
|
@ -31,7 +31,7 @@ class SettingsTab(QScrollArea):
|
|||
self.rare_form = RareSettingsForm()
|
||||
|
||||
self.logout_button = QPushButton("Logout")
|
||||
self.logout_button.clicked.connect(self.logout)
|
||||
self.logout_button.clicked.connect(self.update_list)
|
||||
self.layout.addWidget(self.logged_in_as)
|
||||
|
||||
self.layout.addWidget(self.rare_form)
|
||||
|
@ -46,6 +46,7 @@ class SettingsTab(QScrollArea):
|
|||
|
||||
self.layout.addWidget(self.info_label)
|
||||
self.layout.addWidget(self.infotext)
|
||||
self.setStyleSheet("QScrollArea{padding-left: 80; padding-right: 80; margin-left: auto; margin-right: auto}")
|
||||
|
||||
self.widget.setLayout(self.layout)
|
||||
self.widget.setFixedWidth(self.width())
|
||||
|
@ -54,3 +55,9 @@ class SettingsTab(QScrollArea):
|
|||
def logout(self):
|
||||
self.core.lgd.invalidate_userdata()
|
||||
exit(0)
|
||||
|
||||
def update_list(self):
|
||||
# del self.widget
|
||||
# self.setWidget(QWidget())
|
||||
self.__init__(self.core)
|
||||
self.update()
|
||||
|
|
|
@ -90,7 +90,6 @@ class UpdateWidget(QWidget):
|
|||
self.update_thread.finish.connect(self.finished)
|
||||
self.update_thread.start()
|
||||
self.button.setDisabled(True)
|
||||
# TODO Wird 1000% nicht funktionieren
|
||||
|
||||
else:
|
||||
logger.info("Terminate process")
|
||||
|
|
|
@ -1,13 +1,26 @@
|
|||
import os
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtGui import QMovie
|
||||
from PyQt5.QtWidgets import *
|
||||
|
||||
|
||||
class CustomQLabel(QLabel):
|
||||
def __init__(self, *__args):
|
||||
super().__init__(*__args)
|
||||
self.app_name_label.setTextInteractionFlags(Qt.TextSelectableByMouse)
|
||||
self.setTextInteractionFlags(Qt.TextSelectableByMouse)
|
||||
|
||||
|
||||
class WaitingSpinner(QLabel):
|
||||
def __init__(self):
|
||||
super(WaitingSpinner, self).__init__()
|
||||
self.setStyleSheet("""
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
""")
|
||||
self.movie = QMovie("Styles/Icons/loader.gif")
|
||||
self.setMovie(self.movie)
|
||||
self.movie.start()
|
||||
|
||||
|
||||
class PathEdit(QWidget):
|
||||
|
@ -19,11 +32,11 @@ class PathEdit(QWidget):
|
|||
self.info_text = infotext
|
||||
self.layout = QHBoxLayout()
|
||||
self.text_edit = QLineEdit(text)
|
||||
self.setObjectName("text_edit")
|
||||
self.path_select = QPushButton("Select Path")
|
||||
self.path_select.clicked.connect(self.set_path)
|
||||
self.layout.addWidget(self.text_edit)
|
||||
self.layout.addWidget(self.path_select)
|
||||
|
||||
self.setLayout(self.layout)
|
||||
|
||||
def setPlaceholderText(self, text: str):
|
||||
|
|
161
Rare/utils/Dialogs/SyncSavesDialog.py
Normal file
161
Rare/utils/Dialogs/SyncSavesDialog.py
Normal file
|
@ -0,0 +1,161 @@
|
|||
import os
|
||||
from logging import getLogger
|
||||
|
||||
from PyQt5.QtCore import QThread, pyqtSignal, QObjectCleanupHandler
|
||||
from PyQt5.QtWidgets import *
|
||||
from legendary.core import LegendaryCore
|
||||
from legendary.models.game import SaveGameStatus
|
||||
|
||||
from Rare.ext.QtExtensions import CustomQLabel, WaitingSpinner
|
||||
|
||||
logger = getLogger("Sync Saves")
|
||||
|
||||
|
||||
class LoadThread(QThread):
|
||||
signal = pyqtSignal(list)
|
||||
|
||||
def __init__(self, core: LegendaryCore):
|
||||
super(LoadThread, self).__init__()
|
||||
self.core = core
|
||||
|
||||
def run(self) -> None:
|
||||
saves = self.core.get_save_games()
|
||||
self.signal.emit(saves)
|
||||
|
||||
|
||||
class SyncGame(QWidget):
|
||||
def __init__(self):
|
||||
super(SyncGame, self).__init__()
|
||||
|
||||
|
||||
class SyncSavesDialog(QDialog):
|
||||
def __init__(self, core: LegendaryCore):
|
||||
super(SyncSavesDialog, self).__init__()
|
||||
self.core = core
|
||||
layout = QVBoxLayout()
|
||||
layout.addWidget(WaitingSpinner())
|
||||
layout.addWidget(QLabel("<h4>Loading Cloud Saves</h4>"))
|
||||
self.setLayout(layout)
|
||||
|
||||
self.start_thread = LoadThread(self.core)
|
||||
self.start_thread.signal.connect(self.setup_ui)
|
||||
self.start_thread.start()
|
||||
self.igames = self.core.get_installed_list()
|
||||
# self.igames = self.core.get_installed_list()
|
||||
# self.saves = self.core.get_save_games()
|
||||
# latest_save = dict()
|
||||
|
||||
# for save in sorted(self.saves, key=lambda a: a.datetime):
|
||||
# latest_save[save.app_name] = save
|
||||
|
||||
# self.setup_ui()
|
||||
|
||||
def setup_ui(self, saves: list):
|
||||
self.start_thread.disconnect()
|
||||
QObjectCleanupHandler().add(self.layout())
|
||||
self.main_layout = QVBoxLayout()
|
||||
self.title = CustomQLabel("<h1>Cloud Saves</h1>\nFound Saves for folowing Games")
|
||||
self.sync_all_button = QPushButton("Sync all games")
|
||||
self.main_layout.addWidget(self.title)
|
||||
self.main_layout.addWidget(self.sync_all_button)
|
||||
self.status = {}
|
||||
|
||||
latest_save = {}
|
||||
for i in saves:
|
||||
latest_save[i.app_name] = i
|
||||
logger.info(f'Got {len(latest_save)} remote save game(s)')
|
||||
|
||||
if len(latest_save) == 0:
|
||||
QMessageBox.information("No Games Found", "Your games don't support cloud save")
|
||||
self.close()
|
||||
return
|
||||
for igame in self.igames:
|
||||
game = self.core.get_game(igame.app_name)
|
||||
if not game.supports_cloud_saves:
|
||||
continue
|
||||
logger.info(f'Checking "{igame.title}" ({igame.app_name})')
|
||||
|
||||
if not igame.save_path:
|
||||
save_path = self.core.get_save_path(igame.app_name)
|
||||
if '%' in save_path or '{' in save_path:
|
||||
status = "PathNotFound"
|
||||
logger.info("Could not find save_path")
|
||||
else:
|
||||
igame.save_path = save_path
|
||||
|
||||
if not os.path.exists(igame.save_path):
|
||||
os.makedirs(igame.save_path)
|
||||
|
||||
res, (dt_local, dt_remote) = self.core.check_savegame_state(igame.save_path,
|
||||
latest_save.get(igame.app_name))
|
||||
if res == SaveGameStatus.NO_SAVE:
|
||||
logger.info('No cloud or local savegame found.')
|
||||
continue
|
||||
widget = QWidget()
|
||||
layout = QVBoxLayout()
|
||||
game_title = CustomQLabel(f"<h2>{igame.title}</h2>")
|
||||
local_save_date = CustomQLabel(f"Local Save date: {dt_local.strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
cloud_save_date = CustomQLabel(f"Cloud save date: {dt_remote.strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
|
||||
if res == SaveGameStatus.SAME_AGE:
|
||||
logger.info(f'Save game for "{igame.title}" is up to date')
|
||||
status = "Game is up to date"
|
||||
upload_button = QPushButton("Upload anyway")
|
||||
download_button = QPushButton("Download anyway")
|
||||
if res == SaveGameStatus.REMOTE_NEWER:
|
||||
status = "Cloud save is newer"
|
||||
download_button = QPushButton("Download Cloud saves")
|
||||
download_button.setStyleSheet("""
|
||||
QPushButton{ background-color: lime}
|
||||
""")
|
||||
upload_button = QPushButton("Upload Saves")
|
||||
logger.info(f'Cloud save for "{igame.title}" is newer:')
|
||||
logger.info(f'- Cloud save date: {dt_remote.strftime("%Y-%m-%d %H:%M:%S")}')
|
||||
if dt_local:
|
||||
logger.info(f'- Local save date: {dt_local.strftime("%Y-%m-%d %H:%M:%S")}')
|
||||
else:
|
||||
logger.info('- Local save date: N/A')
|
||||
upload_button.setDisabled(True)
|
||||
upload_button.setToolTip("No local save")
|
||||
|
||||
elif res == SaveGameStatus.LOCAL_NEWER:
|
||||
status = "local is newer"
|
||||
upload_button = QPushButton("Upload saves")
|
||||
upload_button.setStyleSheet("""
|
||||
QPushButton{ background-color: lime}
|
||||
""")
|
||||
download_button = QPushButton("Download saves")
|
||||
logger.info(f'Local save for "{igame.title}" is newer')
|
||||
if dt_remote:
|
||||
logger.info(f'- Cloud save date: {dt_remote.strftime("%Y-%m-%d %H:%M:%S")}')
|
||||
else:
|
||||
logger.info('- Cloud save date: N/A')
|
||||
download_button.setDisabled(True)
|
||||
logger.info(f'- Local save date: {dt_local.strftime("%Y-%m-%d %H:%M:%S")}')
|
||||
upload_button.app_name = igame.app_name
|
||||
download_button.app_name = igame.app_name
|
||||
upload_button.clicked.connect(lambda: self.upload(upload_button.app_name))
|
||||
download_button.clicked.connect(lambda: self.download_save(download_button.app_name))
|
||||
mini_layout = QHBoxLayout()
|
||||
mini_layout.addWidget(upload_button)
|
||||
mini_layout.addWidget(download_button)
|
||||
layout.addWidget(game_title)
|
||||
layout.addWidget(local_save_date)
|
||||
layout.addWidget(cloud_save_date)
|
||||
layout.addWidget(CustomQLabel(status))
|
||||
layout.addLayout(mini_layout)
|
||||
self.main_layout.addLayout(layout)
|
||||
self.status[igame.app_name] = res, dt_remote, dt_local, igame.save_path, latest_save[igame.app_name]
|
||||
|
||||
self.setLayout(self.main_layout)
|
||||
|
||||
def download_save(self, app_name):
|
||||
logger.info('Downloading saves ')
|
||||
res, dt_remote, dt_local, save_path, latest_save = self.status[app_name]
|
||||
self.core.download_saves(app_name, latest_save.manifest_name, save_path)
|
||||
# todo Threading
|
||||
|
||||
def upload(self, app_name):
|
||||
logger.info("Uplouding saves")
|
||||
res, dt_remote, dt_local, save_path, latest_save = self.status[app_name]
|
||||
self.core.upload_save(app_name, save_path, dt_local)
|
|
@ -11,7 +11,7 @@ rare_config.read(config_path + "config.ini")
|
|||
if not os.path.exists(config_path):
|
||||
os.makedirs(config_path)
|
||||
rare_config["Rare"] = {
|
||||
"IMAGE_DIR": os.path.expanduser("~/.cache/images"),
|
||||
"IMAGE_DIR": os.path.expanduser(f"~/.cache/images"),
|
||||
"theme": "default"
|
||||
}
|
||||
rare_config.write(open(config_path + "config.ini", "w"))
|
||||
|
|
|
@ -80,6 +80,3 @@ def download_images(signal: pyqtSignal, core: LegendaryCore):
|
|||
logger.warning(f"File {IMAGE_DIR}/{game.app_name}/DieselGameBoxTall.png dowsn't exist")
|
||||
signal.emit(i)
|
||||
|
||||
|
||||
def restart():
|
||||
os.execv(sys.executable, ['python'] + sys.argv)
|
||||
|
|
Loading…
Reference in a new issue