1
0
Fork 0
mirror of synced 2024-09-30 01:07:47 +13:00

Open cloud save dialog after playing a game, if no action set on start

This commit is contained in:
lennard 2023-04-07 19:37:27 +02:00 committed by Dummerle
parent 3f17a69e65
commit f1fa0ada1a
5 changed files with 28 additions and 19 deletions

View file

@ -18,6 +18,7 @@ class CloudSaveDialog(QDialog, Ui_SyncSaveDialog):
DOWNLOAD = 2 DOWNLOAD = 2
UPLOAD = 1 UPLOAD = 1
CANCEL = 0 CANCEL = 0
SKIP = 3
def __init__( def __init__(
self, self,
@ -49,10 +50,13 @@ class CloudSaveDialog(QDialog, Ui_SyncSaveDialog):
self.sync_ui.age_label_remote.setText( self.sync_ui.age_label_remote.setText(
f"<b>{newer}</b>" if dt_remote > dt_local else " " f"<b>{newer}</b>" if dt_remote > dt_local else " "
) )
# Set status, if one of them is None
elif dt_remote and not dt_local: elif dt_remote and not dt_local:
self.status = self.DOWNLOAD self.status = self.DOWNLOAD
else: elif not dt_remote and dt_local:
self.status = self.UPLOAD self.status = self.UPLOAD
else:
self.status = self.SKIP
self.sync_ui.date_info_local.setText(dt_local.strftime("%A, %d. %B %Y %X") if dt_local else "None") self.sync_ui.date_info_local.setText(dt_local.strftime("%A, %d. %B %Y %X") if dt_local else "None")
self.sync_ui.date_info_remote.setText(dt_remote.strftime("%A, %d. %B %Y %X") if dt_remote else "None") self.sync_ui.date_info_remote.setText(dt_remote.strftime("%A, %d. %B %Y %X") if dt_remote else "None")
@ -68,8 +72,8 @@ class CloudSaveDialog(QDialog, Ui_SyncSaveDialog):
self.layout().setSizeConstraint(QLayout.SetFixedSize) self.layout().setSizeConstraint(QLayout.SetFixedSize)
def get_action(self): def get_action(self):
if self.status: if self.status == self.SKIP:
return self.status return self.SKIP
self.exec_() self.exec_()
return self.status return self.status

View file

@ -136,6 +136,8 @@ class RareLauncher(RareApp):
self.core = LegendaryCore() self.core = LegendaryCore()
self.args = args self.args = args
self.no_sync_on_exit = False
game = self.core.get_game(self.app_name) game = self.core.get_game(self.app_name)
self.rgame = RareGameSlim(self.core, game) self.rgame = RareGameSlim(self.core, game)
@ -201,19 +203,23 @@ class RareLauncher(RareApp):
self.rgame.signals.widget.update.connect(lambda: self.on_exit(exit_code)) self.rgame.signals.widget.update.connect(lambda: self.on_exit(exit_code))
state, (dt_local, dt_remote) = self.rgame.save_game_state state, (dt_local, dt_remote) = self.rgame.save_game_state
if state == SaveGameStatus.LOCAL_NEWER:
if state == SaveGameStatus.LOCAL_NEWER and not self.no_sync_on_exit:
action = CloudSaveDialog.UPLOAD action = CloudSaveDialog.UPLOAD
else: else:
action = CloudSaveDialog(self.rgame.igame, dt_local, dt_remote).get_action() action = CloudSaveDialog(self.rgame.igame, dt_local, dt_remote).get_action()
if not action:
self.on_exit(exit_code)
return
if self.console:
self.console.log("Syncing saves...")
if action == CloudSaveDialog.UPLOAD: if action == CloudSaveDialog.UPLOAD:
if self.console:
self.console.log("upload saves...")
self.rgame.upload_saves() self.rgame.upload_saves()
elif action == CloudSaveDialog.DOWNLOAD: elif action == CloudSaveDialog.DOWNLOAD:
if self.console:
self.console.log("Download saves...")
self.rgame.download_saves() self.rgame.download_saves()
else:
self.on_exit(exit_code)
def game_finished(self, exit_code): def game_finished(self, exit_code):
self.logger.info("Game finished") self.logger.info("Game finished")
@ -309,6 +315,8 @@ class RareLauncher(RareApp):
_, (dt_local, dt_remote) = self.rgame.save_game_state _, (dt_local, dt_remote) = self.rgame.save_game_state
dlg = CloudSaveDialog(self.rgame.igame, dt_local, dt_remote) dlg = CloudSaveDialog(self.rgame.igame, dt_local, dt_remote)
action = dlg.get_action() action = dlg.get_action()
if action == CloudSaveDialog.CANCEL:
self.no_sync_on_exit = True
if self.console: if self.console:
if action == CloudSaveDialog.DOWNLOAD: if action == CloudSaveDialog.DOWNLOAD:
self.console.log("Downloading saves") self.console.log("Downloading saves")

View file

@ -546,7 +546,6 @@ class RareGame(RareGameSlim):
skip_update_check: bool = False, skip_update_check: bool = False,
wine_bin: Optional[str] = None, wine_bin: Optional[str] = None,
wine_pfx: Optional[str] = None, wine_pfx: Optional[str] = None,
ask_sync_saves: bool = False,
) -> bool: ) -> bool:
if not self.can_launch: if not self.can_launch:
return False return False
@ -562,8 +561,6 @@ class RareGame(RareGameSlim):
args.extend(["--wine-bin", wine_bin]) args.extend(["--wine-bin", wine_bin])
if wine_pfx: if wine_pfx:
args.extend(["--wine-prefix", wine_pfx]) args.extend(["--wine-prefix", wine_pfx])
if ask_sync_saves:
args.extend("--ask-sync-saves")
QProcess.startDetached(executable, args) QProcess.startDetached(executable, args)
logger.info(f"Start new Process: ({executable} {' '.join(args)})") logger.info(f"Start new Process: ({executable} {' '.join(args)})")

View file

@ -14,7 +14,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_SyncWidget(object): class Ui_SyncWidget(object):
def setupUi(self, SyncWidget): def setupUi(self, SyncWidget):
SyncWidget.setObjectName("SyncWidget") SyncWidget.setObjectName("SyncWidget")
SyncWidget.resize(422, 127) SyncWidget.resize(438, 137)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0) sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0) sizePolicy.setVerticalStretch(0)
@ -44,6 +44,7 @@ class Ui_SyncWidget(object):
self.icon_local.setObjectName("icon_local") self.icon_local.setObjectName("icon_local")
self.local_layout.addWidget(self.icon_local) self.local_layout.addWidget(self.icon_local)
self.age_label_local = QtWidgets.QLabel(self.local_gb) self.age_label_local = QtWidgets.QLabel(self.local_gb)
self.age_label_local.setText("")
self.age_label_local.setAlignment(QtCore.Qt.AlignCenter) self.age_label_local.setAlignment(QtCore.Qt.AlignCenter)
self.age_label_local.setObjectName("age_label_local") self.age_label_local.setObjectName("age_label_local")
self.local_layout.addWidget(self.age_label_local) self.local_layout.addWidget(self.age_label_local)
@ -72,7 +73,7 @@ class Ui_SyncWidget(object):
self.icon_remote.setObjectName("icon_remote") self.icon_remote.setObjectName("icon_remote")
self.cloud_layout.addWidget(self.icon_remote) self.cloud_layout.addWidget(self.icon_remote)
self.age_label_remote = QtWidgets.QLabel(self.cloud_gb) self.age_label_remote = QtWidgets.QLabel(self.cloud_gb)
self.age_label_remote.setText("remote_age_error") self.age_label_remote.setText("")
self.age_label_remote.setAlignment(QtCore.Qt.AlignCenter) self.age_label_remote.setAlignment(QtCore.Qt.AlignCenter)
self.age_label_remote.setObjectName("age_label_remote") self.age_label_remote.setObjectName("age_label_remote")
self.cloud_layout.addWidget(self.age_label_remote) self.cloud_layout.addWidget(self.age_label_remote)
@ -87,7 +88,6 @@ class Ui_SyncWidget(object):
def retranslateUi(self, SyncWidget): def retranslateUi(self, SyncWidget):
_translate = QtCore.QCoreApplication.translate _translate = QtCore.QCoreApplication.translate
self.local_gb.setTitle(_translate("SyncWidget", "Local")) self.local_gb.setTitle(_translate("SyncWidget", "Local"))
self.age_label_local.setText(_translate("SyncWidget", "local_age_error"))
self.upload_button.setText(_translate("SyncWidget", "Upload")) self.upload_button.setText(_translate("SyncWidget", "Upload"))
self.cloud_gb.setTitle(_translate("SyncWidget", "Cloud")) self.cloud_gb.setTitle(_translate("SyncWidget", "Cloud"))
self.download_button.setText(_translate("SyncWidget", "Download")) self.download_button.setText(_translate("SyncWidget", "Download"))

View file

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>422</width> <width>438</width>
<height>127</height> <height>137</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -67,7 +67,7 @@
<item> <item>
<widget class="QLabel" name="age_label_local"> <widget class="QLabel" name="age_label_local">
<property name="text"> <property name="text">
<string>local_age_error</string> <string/>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignCenter</set> <set>Qt::AlignCenter</set>
@ -125,7 +125,7 @@
<item> <item>
<widget class="QLabel" name="age_label_remote"> <widget class="QLabel" name="age_label_remote">
<property name="text"> <property name="text">
<string notr="true">remote_age_error</string> <string notr="true"/>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignCenter</set> <set>Qt::AlignCenter</set>