Skip to content

Commit 8f51403

Browse files
committed
Better user messages for cloud saves
1 parent 6dbbbb8 commit 8f51403

File tree

3 files changed

+121
-34
lines changed

3 files changed

+121
-34
lines changed

gamevault/Helper/Integrations/SaveGameHelper.cs

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ internal SaveGameHelper()
5555
{
5656
zipHelper = new SevenZipHelper();
5757
}
58-
internal async Task<bool> RestoreBackup(int gameId, string installationDir)
58+
internal async Task<CloudSaveStatus> RestoreBackup(int gameId, string installationDir)
5959
{
60-
if (!LoginManager.Instance.IsLoggedIn() || !SettingsViewModel.Instance.CloudSaves || !SettingsViewModel.Instance.License.IsActive())
61-
return false;
60+
if (!LoginManager.Instance.IsLoggedIn() || !SettingsViewModel.Instance.License.IsActive())
61+
return CloudSaveStatus.Failed;
62+
63+
if (!SettingsViewModel.Instance.CloudSaves)
64+
return CloudSaveStatus.SettingDisabled;
6265

6366
using (HttpClient client = new HttpClient())
6467
{
@@ -106,7 +109,11 @@ internal async Task<bool> RestoreBackup(int gameId, string installationDir)
106109
process.WaitForExit();
107110
ProcessShepherd.Instance.RemoveProcess(process);
108111
Directory.Delete(tempFolder, true);
109-
return true;
112+
return CloudSaveStatus.Success;
113+
}
114+
else
115+
{
116+
return CloudSaveStatus.UpToDate;
110117
}
111118
}
112119
}
@@ -123,7 +130,7 @@ internal async Task<bool> RestoreBackup(int gameId, string installationDir)
123130
}
124131
}
125132
}
126-
return false;
133+
return CloudSaveStatus.Failed;
127134
}
128135
private string GetGameInstallationId(string installationDir)
129136
{
@@ -141,22 +148,42 @@ internal async Task BackupSaveGamesFromIds(List<int> gameIds)
141148
var removedIds = runningGameIds.Except(gameIds).ToList();
142149

143150
foreach (var removedId in removedIds)
144-
{
145-
if (!LoginManager.Instance.IsLoggedIn() || !SettingsViewModel.Instance.CloudSaves)
151+
{
152+
if (!SettingsViewModel.Instance.CloudSaves || !SettingsViewModel.Instance.License.IsActive())
153+
{
154+
break;
155+
}
156+
if (!LoginManager.Instance.IsLoggedIn())
146157
{
158+
MainWindowViewModel.Instance.AppBarText = "Can not synchronize the cloud saves, because you are offline";
147159
break;
148160
}
149161
try
150162
{
151163
MainWindowViewModel.Instance.AppBarText = "Uploading Savegame to the Server...";
152-
bool success = await BackupSaveGame(removedId);
153-
if (success)
154-
{
155-
MainWindowViewModel.Instance.AppBarText = "Successfully synchronized the cloud saves";
156-
}
157-
else
164+
CloudSaveStatus status = await BackupSaveGame(removedId);
165+
switch (status)
158166
{
159-
MainWindowViewModel.Instance.AppBarText = "Failed to upload your Savegame to the Server";
167+
case CloudSaveStatus.Success:
168+
{
169+
MainWindowViewModel.Instance.AppBarText = "Successfully synchronized the cloud saves";
170+
break;
171+
}
172+
case CloudSaveStatus.BackupCreationFailed:
173+
{
174+
MainWindowViewModel.Instance.AppBarText = "Failed to create a copy of your Savegame";
175+
break;
176+
}
177+
case CloudSaveStatus.BackupUploadFailed:
178+
{
179+
MainWindowViewModel.Instance.AppBarText = "Failed to upload your Savegame to the Server";
180+
break;
181+
}
182+
case CloudSaveStatus.Failed:
183+
{
184+
MainWindowViewModel.Instance.AppBarText = "Something went wrong during the Backup";
185+
break;
186+
}
160187
}
161188
}
162189
catch (Exception ex)
@@ -171,10 +198,13 @@ internal async Task BackupSaveGamesFromIds(List<int> gameIds)
171198
// Remove IDs that are no longer in the new list
172199
runningGameIds = runningGameIds.Intersect(gameIds).ToList();
173200
}
174-
internal async Task<bool> BackupSaveGame(int gameId)
201+
internal async Task<CloudSaveStatus> BackupSaveGame(int gameId)
175202
{
176-
if (!SettingsViewModel.Instance.CloudSaves || !SettingsViewModel.Instance.License.IsActive())
177-
return false;
203+
if (!SettingsViewModel.Instance.CloudSaves)
204+
return CloudSaveStatus.SettingDisabled;
205+
206+
if (!SettingsViewModel.Instance.License.IsActive())
207+
return CloudSaveStatus.Failed;
178208

179209
var installedGame = InstallViewModel.Instance?.InstalledGames?.FirstOrDefault(g => g.Key?.ID == gameId);
180210
string gameMetadataTitle = installedGame?.Key?.Metadata?.Title ?? "";
@@ -184,23 +214,24 @@ internal async Task<bool> BackupSaveGame(int gameId)
184214
PrepareConfigFile(installedGame?.Value!, Path.Combine(AppFilePath.CloudSaveConfigDir, "config.yaml"));
185215
string title = await SearchForLudusaviGameTitle(gameMetadataTitle);
186216
if (string.IsNullOrEmpty(title))
187-
return false;
217+
return CloudSaveStatus.Failed;
218+
188219
string tempFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
189220
Directory.CreateDirectory(tempFolder);
190221
await CreateBackup(title, tempFolder);
191222
string archive = Path.Combine(tempFolder, "backup.zip");
192223
if (Directory.GetFiles(tempFolder, "mapping.yaml", SearchOption.AllDirectories).Length == 0)
193224
{
194225
Directory.Delete(tempFolder, true);
195-
return false;
226+
return CloudSaveStatus.BackupCreationFailed;
196227
}
197228
await zipHelper.PackArchive(tempFolder, archive);
198229

199230
bool success = await UploadSavegame(archive, gameId, installationDir);
200231
Directory.Delete(tempFolder, true);
201-
return success;
232+
return success ? CloudSaveStatus.Success : CloudSaveStatus.BackupUploadFailed;
202233
}
203-
return false;
234+
return CloudSaveStatus.Failed;
204235
}
205236
public void PrepareConfigFile(string installationPath, string yamlPath)
206237
{
@@ -371,6 +402,15 @@ private ProcessStartInfo CreateProcessHeader(bool redirectConsole = false)
371402
return info;
372403
}
373404
}
405+
public enum CloudSaveStatus
406+
{
407+
Success,
408+
Failed,
409+
UpToDate,
410+
SettingDisabled,
411+
BackupCreationFailed,
412+
BackupUploadFailed
413+
}
374414
public class LudusaviManifestEntry
375415
{
376416
public string Uri { get; set; }

gamevault/UserControls/GameViewUserControl.xaml.cs

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -407,23 +407,48 @@ private void Share_Click(object sender, RoutedEventArgs e)
407407
private async void BackupCloudSaves_Click(object sender, RoutedEventArgs e)
408408
{
409409
try
410-
{
410+
{
411411
if (!SettingsViewModel.Instance.License.IsActive())
412412
{
413413
MainWindowViewModel.Instance.SetActiveControl(MainControl.Settings);
414414
MainWindowViewModel.Instance.Settings.SetTabIndex(4);
415415
return;
416416
}
417-
MainWindowViewModel.Instance.AppBarText = "Uploading Savegame to the Server...";
418-
((FrameworkElement)sender).IsEnabled = false;
419-
bool success = await SaveGameHelper.Instance.BackupSaveGame(ViewModel!.Game!.ID);
420-
if (success)
417+
if (!LoginManager.Instance.IsLoggedIn())
421418
{
422-
MainWindowViewModel.Instance.AppBarText = "Successfully synchronized the cloud saves";
419+
MainWindowViewModel.Instance.AppBarText = "Can not synchronize the cloud saves, because you are offline";
420+
return;
423421
}
424-
else
422+
MainWindowViewModel.Instance.AppBarText = "Uploading Savegame to the Server...";
423+
((FrameworkElement)sender).IsEnabled = false;
424+
CloudSaveStatus status = await SaveGameHelper.Instance.BackupSaveGame(ViewModel!.Game!.ID);
425+
switch (status)
425426
{
426-
MainWindowViewModel.Instance.AppBarText = "Failed to upload your Savegame to the Server";
427+
case CloudSaveStatus.Success:
428+
{
429+
MainWindowViewModel.Instance.AppBarText = "Successfully synchronized the cloud saves";
430+
break;
431+
}
432+
case CloudSaveStatus.BackupCreationFailed:
433+
{
434+
MainWindowViewModel.Instance.AppBarText = "Failed to get your Savegame";
435+
break;
436+
}
437+
case CloudSaveStatus.BackupUploadFailed:
438+
{
439+
MainWindowViewModel.Instance.AppBarText = "Failed to upload your Savegame to the Server";
440+
break;
441+
}
442+
case CloudSaveStatus.SettingDisabled:
443+
{
444+
MainWindowViewModel.Instance.AppBarText = "Activate Cloud Saves under Settings -> GameVault+ -> Cloud Saves";
445+
break;
446+
}
447+
case CloudSaveStatus.Failed:
448+
{
449+
MainWindowViewModel.Instance.AppBarText = "Something went wrong during the backup";
450+
break;
451+
}
427452
}
428453
}
429454
catch
@@ -445,10 +470,29 @@ private async void RestoreCloudSaves_Click(object sender, RoutedEventArgs e)
445470
MainWindowViewModel.Instance.AppBarText = $"Syncing cloud save...";
446471
((FrameworkElement)sender).IsEnabled = false;
447472
string installationDir = InstallViewModel.Instance.InstalledGames.First(g => g.Key.ID == ViewModel!.Game!.ID).Value;
448-
bool success = await SaveGameHelper.Instance.RestoreBackup(ViewModel!.Game!.ID, installationDir);
449-
if (success)
473+
CloudSaveStatus status = await SaveGameHelper.Instance.RestoreBackup(ViewModel!.Game!.ID, installationDir);
474+
switch (status)
450475
{
451-
MainWindowViewModel.Instance.AppBarText = "Successfully synchronized the cloud save";
476+
case CloudSaveStatus.Success:
477+
{
478+
MainWindowViewModel.Instance.AppBarText = "Successfully synchronized the cloud save";
479+
break;
480+
}
481+
case CloudSaveStatus.UpToDate:
482+
{
483+
MainWindowViewModel.Instance.AppBarText = "Your Savegame is up to date";
484+
break;
485+
}
486+
case CloudSaveStatus.SettingDisabled:
487+
{
488+
MainWindowViewModel.Instance.AppBarText = "Activate Cloud Saves under Settings -> GameVault+ -> Cloud Saves";
489+
break;
490+
}
491+
case CloudSaveStatus.Failed:
492+
{
493+
MainWindowViewModel.Instance.AppBarText = "Failed to restore the Savegame";
494+
break;
495+
}
452496
}
453497
}
454498
catch

gamevault/UserControls/InstallUserControl.xaml.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,11 @@ public static async Task PlayGame(int gameId)
300300

301301
string path = "";
302302
KeyValuePair<Game, string> result = InstallViewModel.Instance.InstalledGames.Where(g => g.Key.ID == gameId).FirstOrDefault();
303-
MainWindowViewModel.Instance.AppBarText = $"Syncing cloud save...";
304-
await SaveGameHelper.Instance.RestoreBackup(gameId, result.Value);
303+
if (SettingsViewModel.Instance.CloudSaves)
304+
{
305+
MainWindowViewModel.Instance.AppBarText = $"Syncing cloud save...";
306+
await SaveGameHelper.Instance.RestoreBackup(gameId, result.Value);
307+
}
305308

306309
if (!result.Equals(default(KeyValuePair<Game, string>)))
307310
{

0 commit comments

Comments
 (0)