diff --git a/projects/Gibbed.BorderlandsOz.SaveEdit/Gibbed.BorderlandsOz.SaveEdit.csproj b/projects/Gibbed.BorderlandsOz.SaveEdit/Gibbed.BorderlandsOz.SaveEdit.csproj index 548576d..f31b14a 100644 --- a/projects/Gibbed.BorderlandsOz.SaveEdit/Gibbed.BorderlandsOz.SaveEdit.csproj +++ b/projects/Gibbed.BorderlandsOz.SaveEdit/Gibbed.BorderlandsOz.SaveEdit.csproj @@ -48,41 +48,42 @@ Resources\Jack.ico - - - - - - + - - - - + - - - - - - - - - + - - + - - - - + + + + + + + + + + + + + + + + + + + + + + diff --git a/projects/Gibbed.BorderlandsOz.SaveEdit/Resources/fugue/disk-black.png b/projects/Gibbed.BorderlandsOz.SaveEdit/Resources/fugue/disk-black.png deleted file mode 100644 index 6178478..0000000 Binary files a/projects/Gibbed.BorderlandsOz.SaveEdit/Resources/fugue/disk-black.png and /dev/null differ diff --git a/projects/Gibbed.BorderlandsOz.SaveEdit/Resources/fugue/disk-rename.png b/projects/Gibbed.BorderlandsOz.SaveEdit/Resources/fugue/disk-rename.png new file mode 100644 index 0000000..ebd6ad6 Binary files /dev/null and b/projects/Gibbed.BorderlandsOz.SaveEdit/Resources/fugue/disk-rename.png differ diff --git a/projects/Gibbed.BorderlandsOz.SaveEdit/Resources/fugue/disk.png b/projects/Gibbed.BorderlandsOz.SaveEdit/Resources/fugue/disk.png new file mode 100644 index 0000000..d884947 Binary files /dev/null and b/projects/Gibbed.BorderlandsOz.SaveEdit/Resources/fugue/disk.png differ diff --git a/projects/Gibbed.BorderlandsOz.SaveEdit/ShellView.xaml b/projects/Gibbed.BorderlandsOz.SaveEdit/ShellView.xaml index 92be987..8d6f657 100644 --- a/projects/Gibbed.BorderlandsOz.SaveEdit/ShellView.xaml +++ b/projects/Gibbed.BorderlandsOz.SaveEdit/ShellView.xaml @@ -47,6 +47,7 @@ [Shortcut Control+N] = [Action NewSave]; [Shortcut Control+O] = [Action ReadSave]; [Shortcut Control+S] = [Action WriteSave]; + [Shortcut Control+Shift+S] = [Action WriteSaveAs]; @@ -86,16 +87,26 @@ Open (Ctrl+O) - + diff --git a/projects/Gibbed.BorderlandsOz.SaveEdit/ShellViewModel.cs b/projects/Gibbed.BorderlandsOz.SaveEdit/ShellViewModel.cs index a97ac5e..a94f393 100644 --- a/projects/Gibbed.BorderlandsOz.SaveEdit/ShellViewModel.cs +++ b/projects/Gibbed.BorderlandsOz.SaveEdit/ShellViewModel.cs @@ -152,6 +152,7 @@ public AboutViewModel About #region Fields private SaveLoad _SaveLoad; + private string _SavePath; private SaveFile _SaveFile; private readonly ICommand _NewSaveFromPlayerClass; @@ -172,6 +173,19 @@ public IEnumerable PlayerClasses } } + public string SavePath + { + get { return this._SavePath; } + private set + { + if (this._SavePath != value) + { + this._SavePath = value; + this.NotifyOfPropertyChange(nameof(SavePath)); + } + } + } + public SaveFile SaveFile { get { return this._SaveFile; } @@ -350,6 +364,7 @@ public IEnumerable ReadSave() this.Backpack.ImportData(saveFile.SaveGame, saveFile.Platform); this.Bank.ImportData(saveFile.SaveGame, saveFile.Platform); this.FastTravel.ImportData(saveFile.SaveGame); + this.SavePath = fileName; this.SaveFile = saveFile; this.MaybeSwitchToGeneral(); } @@ -388,7 +403,6 @@ public IEnumerable ReadSave() .WithIcon(MessageBoxImage.Information); } - if (this.SaveFile != null && this.Backpack.BrokenWeapons.Count > 0) { @@ -416,11 +430,12 @@ public IEnumerable ReadSave() else if (result == MessageBoxResult.Cancel) { var sb = new StringBuilder(); - this.Backpack.BrokenWeapons.ForEach(kv => - { - sb.AppendLine(kv.Value.ToString()); - sb.AppendLine(); - }); + this.Backpack.BrokenWeapons.ForEach( + kv => + { + sb.AppendLine(kv.Value.ToString()); + sb.AppendLine(); + }); if (MyClipboard.SetText(sb.ToString()) != MyClipboard.Result.Success) { MessageBox.Show("Clipboard failure.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); @@ -457,11 +472,12 @@ public IEnumerable ReadSave() else if (result == MessageBoxResult.Cancel) { var sb = new StringBuilder(); - this.Backpack.BrokenItems.ForEach(kv => - { - sb.AppendLine(kv.Value.ToString()); - sb.AppendLine(); - }); + this.Backpack.BrokenItems.ForEach( + kv => + { + sb.AppendLine(kv.Value.ToString()); + sb.AppendLine(); + }); if (MyClipboard.SetText(sb.ToString()) != MyClipboard.Result.Success) { MessageBox.Show("Clipboard failure.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); @@ -498,11 +514,12 @@ public IEnumerable ReadSave() else if (result == MessageBoxResult.Cancel) { var sb = new StringBuilder(); - this.Bank.BrokenSlots.ForEach(kv => - { - sb.AppendLine(kv.Value.ToString()); - sb.AppendLine(); - }); + this.Bank.BrokenSlots.ForEach( + kv => + { + sb.AppendLine(kv.Value.ToString()); + sb.AppendLine(); + }); if (MyClipboard.SetText(sb.ToString()) != MyClipboard.Result.Success) { MessageBox.Show("Clipboard failure.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); @@ -514,20 +531,41 @@ public IEnumerable ReadSave() } public IEnumerable WriteSave() + { + if (this.SaveFile == null || string.IsNullOrEmpty(this.SavePath) == true) + { + yield break; + } + + var savePath = this.SavePath; + var saveFile = this.SaveFile; + + yield return new DelegateResult( + () => WriteSave(savePath, saveFile)) + .Rescue() + .Execute( + x => + new MyMessageBox( + $"An exception was thrown (press Ctrl+C to copy):\n\n{x.ToString()}", + "Error") + .WithIcon(MessageBoxImage.Error).AsCoroutine()); + } + + public IEnumerable WriteSaveAs() { if (this.SaveFile == null) { yield break; } - string fileName = null; + string savePath = null; - foreach (var result in this.SaveLoad.SaveFile(s => fileName = s)) + foreach (var result in this.SaveLoad.SaveFile(s => savePath = s)) { yield return result; } - if (fileName == null) + if (savePath == null) { yield break; } @@ -537,48 +575,56 @@ public IEnumerable WriteSave() yield return new DelegateResult( () => { - this.General.ExportData(saveFile.SaveGame, out var platform); - this.Character.ExportData(saveFile.SaveGame); - this.Vehicle.ExportData(saveFile.SaveGame); - this.CurrencyOnHand.ExportData(saveFile.SaveGame); - this.Backpack.ExportData(saveFile.SaveGame, platform); - this.Bank.ExportData(saveFile.SaveGame, platform); - this.FastTravel.ExportData(saveFile.SaveGame); - - if (saveFile.SaveGame != null && - saveFile.SaveGame.WeaponData != null) - { - saveFile.SaveGame.WeaponData.RemoveAll( - wd => - Blacklisting.IsBlacklistedType(wd.Type) == true || - Blacklisting.IsBlacklistedBalance(wd.Balance) == true); - } - - if (saveFile.SaveGame != null && - saveFile.SaveGame.ItemData != null) - { - saveFile.SaveGame.ItemData.RemoveAll( - wd => - Blacklisting.IsBlacklistedType(wd.Type) == true || - Blacklisting.IsBlacklistedBalance(wd.Balance) == true); - } - - using (var output = File.Create(fileName)) - { - FileFormats.SaveExpansion.AddExpansionSavedataToUnloadableItemData( - saveFile.SaveGame); - saveFile.Platform = platform; - saveFile.Serialize(output); - FileFormats.SaveExpansion - .ExtractExpansionSavedataFromUnloadableItemData( - saveFile.SaveGame); - } - }).Rescue().Execute( + this.WriteSave(savePath, saveFile); + this.SavePath = savePath; + }) + .Rescue() + .Execute( x => new MyMessageBox( $"An exception was thrown (press Ctrl+C to copy):\n\n{x.ToString()}", "Error") .WithIcon(MessageBoxImage.Error).AsCoroutine()); } + + private void WriteSave(string savePath, SaveFile saveFile) + { + this.General.ExportData(saveFile.SaveGame, out var platform); + this.Character.ExportData(saveFile.SaveGame); + this.Vehicle.ExportData(saveFile.SaveGame); + this.CurrencyOnHand.ExportData(saveFile.SaveGame); + this.Backpack.ExportData(saveFile.SaveGame, platform); + this.Bank.ExportData(saveFile.SaveGame, platform); + this.FastTravel.ExportData(saveFile.SaveGame); + + if (saveFile.SaveGame != null && + saveFile.SaveGame.WeaponData != null) + { + saveFile.SaveGame.WeaponData.RemoveAll( + wd => + Blacklisting.IsBlacklistedType(wd.Type) == true || + Blacklisting.IsBlacklistedBalance(wd.Balance) == true); + } + + if (saveFile.SaveGame != null && + saveFile.SaveGame.ItemData != null) + { + saveFile.SaveGame.ItemData.RemoveAll( + wd => + Blacklisting.IsBlacklistedType(wd.Type) == true || + Blacklisting.IsBlacklistedBalance(wd.Balance) == true); + } + + using (var output = File.Create(savePath)) + { + FileFormats.SaveExpansion.AddExpansionSavedataToUnloadableItemData( + saveFile.SaveGame); + saveFile.Platform = platform; + saveFile.Serialize(output); + FileFormats.SaveExpansion + .ExtractExpansionSavedataFromUnloadableItemData( + saveFile.SaveGame); + } + } } }