diff --git a/src/Enums/CloudSyncAction.cs b/src/Enums/CloudSyncAction.cs new file mode 100644 index 0000000..8e82d62 --- /dev/null +++ b/src/Enums/CloudSyncAction.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LegendaryLibraryNS.Enums +{ + public enum CloudSyncAction + { + Download, + Upload, + ForceDownload, + ForceUpload + } +} diff --git a/src/LegendaryCloud.cs b/src/LegendaryCloud.cs index dedc80d..cd868d1 100644 --- a/src/LegendaryCloud.cs +++ b/src/LegendaryCloud.cs @@ -1,5 +1,6 @@ using CliWrap; using CliWrap.EventStream; +using LegendaryLibraryNS.Enums; using LegendaryLibraryNS.Models; using Playnite.Common; using Playnite.SDK; @@ -123,7 +124,7 @@ public static string CalculateGameSavesPath(string gameName, string gameID, stri } - public static void SyncGameSaves(string gameName, string gameID, string gameInstallDir, bool download) + public static void SyncGameSaves(string gameName, string gameID, string gameInstallDir, CloudSyncAction cloudSyncAction, bool manualSync = false) { var cloudSyncEnabled = LegendaryLibrary.GetSettings().SyncGameSaves; var gamesSettings = LegendaryGameSettingsView.LoadSavedGamesSettings(); @@ -136,10 +137,14 @@ public static void SyncGameSaves(string gameName, string gameID, string gameInst { cloudSyncEnabled = (bool)gameSettings.AutoSyncSaves; } + if (manualSync) + { + cloudSyncEnabled = true; + } if (cloudSyncEnabled) { var cloudSaveFolder = CalculateGameSavesPath(gameName, gameID, gameInstallDir); - if (gameSettings?.CloudSaveFolder != "") + if (!gameSettings.CloudSaveFolder.IsNullOrEmpty()) { cloudSaveFolder = gameSettings.CloudSaveFolder; } @@ -154,14 +159,26 @@ public static void SyncGameSaves(string gameName, string gameID, string gameInst { a.ProgressMaxValue = 100; a.CurrentProgressValue = 0; + var cloudArgs = new List(); + cloudArgs.AddRange(new[] { "-y", "sync-saves", gameID }); var skippedActivity = "--skip-upload"; - if (download == false) + if (cloudSyncAction == CloudSyncAction.Upload || cloudSyncAction == CloudSyncAction.ForceUpload) { skippedActivity = "--skip-download"; } + cloudArgs.Add(skippedActivity); + if (cloudSyncAction == CloudSyncAction.ForceDownload) + { + cloudArgs.Add("--force-download"); + } + else if (cloudSyncAction == CloudSyncAction.ForceUpload) + { + cloudArgs.Add("--force-upload"); + } + cloudArgs.AddRange(new[] { "--save-path", cloudSaveFolder }); var cmd = Cli.Wrap(LegendaryLauncher.ClientExecPath) .WithEnvironmentVariables(LegendaryLauncher.DefaultEnvironmentVariables) - .WithArguments(new[] { "-y", "sync-saves", gameID, skippedActivity, "--save-path", cloudSaveFolder }); + .WithArguments(cloudArgs); await foreach (var cmdEvent in cmd.ListenAsync()) { switch (cmdEvent) diff --git a/src/LegendaryGameSettingsView.xaml b/src/LegendaryGameSettingsView.xaml index 15c5b7b..a1133c9 100644 --- a/src/LegendaryGameSettingsView.xaml +++ b/src/LegendaryGameSettingsView.xaml @@ -59,30 +59,38 @@ - - - - - - - - - - - - - - - - - - + + diff --git a/src/LegendaryGameSettingsView.xaml.cs b/src/LegendaryGameSettingsView.xaml.cs index 047ab54..4478cda 100644 --- a/src/LegendaryGameSettingsView.xaml.cs +++ b/src/LegendaryGameSettingsView.xaml.cs @@ -9,6 +9,7 @@ using Playnite.Common; using Playnite.SDK; using Playnite.SDK.Models; +using LegendaryLibraryNS.Enums; namespace LegendaryLibraryNS { @@ -143,10 +144,22 @@ private void LegendaryGameSettingsViewUC_Loaded(object sender, RoutedEventArgs e EnableOfflineModeChk.IsEnabled = true; } } + var cloudSyncActions = new Dictionary + { + { CloudSyncAction.Download, ResourceProvider.GetString(LOC.LegendaryDownload) }, + { CloudSyncAction.Upload, ResourceProvider.GetString(LOC.LegendaryUpload) }, + { CloudSyncAction.ForceDownload, ResourceProvider.GetString(LOC.LegendaryForceDownload) }, + { CloudSyncAction.ForceUpload, ResourceProvider.GetString(LOC.LegendaryForceUpload) } + }; + ManualSyncSavesCBo.ItemsSource = cloudSyncActions; + ManualSyncSavesCBo.SelectedIndex = 0; + + + cloudPath = LegendaryCloud.CalculateGameSavesPath(Game.Name, Game.GameId, Game.InstallDirectory); if (cloudPath.IsNullOrEmpty()) { - CloudSavesGrid.Visibility = Visibility.Collapsed; + CloudSavesSP.Visibility = Visibility.Collapsed; CloudSavesNotSupportedTB.Visibility = Visibility.Visible; } } @@ -187,5 +200,15 @@ private void AutoSyncChk_Click(object sender, RoutedEventArgs e) playniteAPI.Dialogs.ShowMessage(ResourceProvider.GetString(LOC.LegendarySyncGameSavesWarn), "", MessageBoxButton.OK, MessageBoxImage.Warning); } } + + private void SyncBtn_Click(object sender, RoutedEventArgs e) + { + var result = playniteAPI.Dialogs.ShowMessage(ResourceProvider.GetString(LOC.LegendaryCloudSaveConfirm), ResourceProvider.GetString(LOC.LegendaryCloudSaves), MessageBoxButton.YesNo, MessageBoxImage.Question); + if (result == MessageBoxResult.Yes) + { + CloudSyncAction selectedCloudSyncAction = (CloudSyncAction)ManualSyncSavesCBo.SelectedValue; + LegendaryCloud.SyncGameSaves(Game.Name, GameID, Game.InstallDirectory, selectedCloudSyncAction, true); + } + } } } diff --git a/src/LegendaryLibrary.cs b/src/LegendaryLibrary.cs index 36b5d53..9a3236b 100644 --- a/src/LegendaryLibrary.cs +++ b/src/LegendaryLibrary.cs @@ -354,12 +354,12 @@ public void MigrateOnlineGames() public override void OnGameStarting(OnGameStartingEventArgs args) { - LegendaryCloud.SyncGameSaves(args.Game.Name, args.Game.GameId, args.Game.InstallDirectory, true); + LegendaryCloud.SyncGameSaves(args.Game.Name, args.Game.GameId, args.Game.InstallDirectory, CloudSyncAction.Download); } public override void OnGameStopped(OnGameStoppedEventArgs args) { - LegendaryCloud.SyncGameSaves(args.Game.Name, args.Game.GameId, args.Game.InstallDirectory, false); + LegendaryCloud.SyncGameSaves(args.Game.Name, args.Game.GameId, args.Game.InstallDirectory, CloudSyncAction.Upload); } public override IEnumerable GetSidebarItems() diff --git a/src/LegendaryLibrary.csproj b/src/LegendaryLibrary.csproj index f445b83..3fbb06f 100644 --- a/src/LegendaryLibrary.csproj +++ b/src/LegendaryLibrary.csproj @@ -157,6 +157,7 @@ + diff --git a/src/Localization/en_US.xaml b/src/Localization/en_US.xaml index dbda89d..4d09db4 100644 --- a/src/Localization/en_US.xaml +++ b/src/Localization/en_US.xaml @@ -100,4 +100,11 @@ Sync saves to the cloud Calculate path This game doesn't support cloud saves. + Manual sync saves + Sync + Download + Upload + Force download + Force upload + Cloud saves feature is experimental. It's recommended to backup game saves in case something goes wrong. Are you sure you want to continue? \ No newline at end of file diff --git a/src/LocalizationKeys.cs b/src/LocalizationKeys.cs index acd9d4c..f52054e 100644 --- a/src/LocalizationKeys.cs +++ b/src/LocalizationKeys.cs @@ -601,5 +601,33 @@ public static class LOC /// This game doesn't support cloud saves. /// public const string LegendaryCloudSavesNotSupported = "LOCLegendaryCloudSavesNotSupported"; + /// + /// Manual sync saves + /// + public const string LegendaryManualSyncSaves = "LOCLegendaryManualSyncSaves"; + /// + /// Sync + /// + public const string LegendarySync = "LOCLegendarySync"; + /// + /// Download + /// + public const string LegendaryDownload = "LOCLegendaryDownload"; + /// + /// Upload + /// + public const string LegendaryUpload = "LOCLegendaryUpload"; + /// + /// Force download + /// + public const string LegendaryForceDownload = "LOCLegendaryForceDownload"; + /// + /// Force upload + /// + public const string LegendaryForceUpload = "LOCLegendaryForceUpload"; + /// + /// Cloud saves feature is experimental. It's recommended to backup game saves in case something goes wrong. Are you sure you want to continue? + /// + public const string LegendaryCloudSaveConfirm = "LOCLegendaryCloudSaveConfirm"; } }