Skip to content

Commit 43ee6be

Browse files
committed
[SaveEdit] Add Save As.
1 parent eaad1dc commit 43ee6be

File tree

6 files changed

+141
-83
lines changed

6 files changed

+141
-83
lines changed

projects/Gibbed.BorderlandsOz.SaveEdit/Gibbed.BorderlandsOz.SaveEdit.csproj

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,41 +48,42 @@
4848
<ApplicationIcon>Resources\Jack.ico</ApplicationIcon>
4949
</PropertyGroup>
5050
<ItemGroup>
51-
<Resource Include="Resources\fugue\disk-black.png" />
52-
<Resource Include="Resources\fugue\document-binary.png" />
53-
<Resource Include="Resources\fugue\document.png" />
54-
<Resource Include="Resources\fugue\folder-open-document.png" />
55-
<Resource Include="Resources\fugue\luggage.png" />
56-
<Resource Include="Resources\fugue\piggy-bank.png" />
51+
<Resource Include="Resources\assaultrifle.png" />
5752
<Resource Include="Resources\backpack.png" />
5853
<Resource Include="Resources\bank.png" />
59-
<Resource Include="Resources\stash.png" />
60-
<Resource Include="Resources\Handsome Jack.ico" />
61-
<Resource Include="Resources\Handsome Jack.png" />
62-
<Resource Include="Resources\fugue\exclamation.png" />
54+
<Resource Include="Resources\credits cropped.png" />
6355
<Resource Include="Resources\credits.png" />
6456
<Resource Include="Resources\eridium.png" />
65-
<Resource Include="Resources\credits cropped.png" />
66-
<Resource Include="Resources\assaultrifle.png" />
67-
<Resource Include="Resources\shield.png" />
68-
<Resource Include="Resources\pink seraph crystal.png" />
69-
<Resource Include="Resources\seraph crystal.png" />
70-
<Resource Include="Resources\fugue\scanner.png" />
71-
<Resource Include="Resources\fugue\printer.png" />
72-
<Resource Include="Resources\fugue\document-copy.png" />
73-
<Resource Include="Resources\fugue\document-delete.png" />
57+
<Resource Include="Resources\exclamation mark.png" />
7458
<Resource Include="Resources\fast travel.png" />
75-
<Resource Include="Resources\green vault symbol.png" />
76-
<Resource Include="Resources\red skull.png" />
59+
<Resource Include="Resources\fugue\computer.png" />
7760
<Resource Include="Resources\fugue\control-090.png" />
7861
<Resource Include="Resources\fugue\control-double-090.png" />
79-
<Resource Include="Resources\exclamation mark.png" />
80-
<Resource Include="Resources\question mark.png" />
81-
<Resource Include="Resources\torgue token.png" />
82-
<Resource Include="Resources\fugue\computer.png" />
62+
<Resource Include="Resources\fugue\disk-rename.png" />
63+
<Resource Include="Resources\fugue\disk.png" />
64+
<Resource Include="Resources\fugue\document-binary.png" />
65+
<Resource Include="Resources\fugue\document-copy.png" />
66+
<Resource Include="Resources\fugue\document-delete.png" />
67+
<Resource Include="Resources\fugue\document.png" />
68+
<Resource Include="Resources\fugue\exclamation.png" />
69+
<Resource Include="Resources\fugue\folder-open-document.png" />
70+
<Resource Include="Resources\fugue\luggage.png" />
71+
<Resource Include="Resources\fugue\piggy-bank.png" />
72+
<Resource Include="Resources\fugue\printer.png" />
73+
<Resource Include="Resources\fugue\scanner.png" />
8374
<Resource Include="Resources\fugue\television-image.png" />
8475
<Resource Include="Resources\fugue\television-test.png" />
76+
<Resource Include="Resources\green vault symbol.png" />
77+
<Resource Include="Resources\Handsome Jack.ico" />
78+
<Resource Include="Resources\Handsome Jack.png" />
79+
<Resource Include="Resources\pink seraph crystal.png" />
80+
<Resource Include="Resources\question mark.png" />
81+
<Resource Include="Resources\red skull.png" />
8582
<Resource Include="Resources\scooter.png" />
83+
<Resource Include="Resources\seraph crystal.png" />
84+
<Resource Include="Resources\shield.png" />
85+
<Resource Include="Resources\stash.png" />
86+
<Resource Include="Resources\torgue token.png" />
8687
<Resource Include="Resources\wheel.png" />
8788
</ItemGroup>
8889
<ItemGroup>
-434 Bytes
Binary file not shown.
1.49 KB
Loading
487 Bytes
Loading

projects/Gibbed.BorderlandsOz.SaveEdit/ShellView.xaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
[Shortcut Control+N] = [Action NewSave];
4848
[Shortcut Control+O] = [Action ReadSave];
4949
[Shortcut Control+S] = [Action WriteSave];
50+
[Shortcut Control+Shift+S] = [Action WriteSaveAs];
5051
</c:Message.Attach>
5152
<ToolBar Name="ButtonBar"
5253
DockPanel.Dock="Top">
@@ -86,16 +87,26 @@
8687
</StackPanel>
8788
<Button.ToolTip>Open (Ctrl+O)</Button.ToolTip>
8889
</Button>
89-
<Button IsEnabled="{Binding Path=SaveFile, Converter={StaticResource NullToBooleanConverter1}, ConverterParameter=true}">
90+
<Button IsEnabled="{Binding Path=SavePath, Converter={StaticResource NullToBooleanConverter1}, ConverterParameter=true}">
9091
<c:Message.Attach>[Event Click] = [Action WriteSave]</c:Message.Attach>
9192
<StackPanel Orientation="Horizontal">
9293
<Image Width="16"
9394
Height="16"
94-
Source="Resources\fugue\disk-black.png" />
95+
Source="Resources\fugue\disk.png" />
9596
<Label Content="Save" />
9697
</StackPanel>
9798
<Button.ToolTip>Save (Ctrl+S)</Button.ToolTip>
9899
</Button>
100+
<Button IsEnabled="{Binding Path=SaveFile, Converter={StaticResource NullToBooleanConverter1}, ConverterParameter=true}">
101+
<c:Message.Attach>[Event Click] = [Action WriteSaveAs]</c:Message.Attach>
102+
<StackPanel Orientation="Horizontal">
103+
<Image Width="16"
104+
Height="16"
105+
Source="Resources\fugue\disk-rename.png" />
106+
<Label Content="Save As" />
107+
</StackPanel>
108+
<Button.ToolTip>Save As (Ctrl+Shift+S)</Button.ToolTip>
109+
</Button>
99110
</ToolBar>
100111
<TabControl TabStripPlacement="Top">
101112
<TabItem IsSelected="{Binding Path=IsGeneralSelected}">

projects/Gibbed.BorderlandsOz.SaveEdit/ShellViewModel.cs

Lines changed: 102 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ public AboutViewModel About
152152

153153
#region Fields
154154
private SaveLoad _SaveLoad;
155+
private string _SavePath;
155156
private SaveFile _SaveFile;
156157
private readonly ICommand _NewSaveFromPlayerClass;
157158

@@ -172,6 +173,19 @@ public IEnumerable<PlayerClassDefinition> PlayerClasses
172173
}
173174
}
174175

176+
public string SavePath
177+
{
178+
get { return this._SavePath; }
179+
private set
180+
{
181+
if (this._SavePath != value)
182+
{
183+
this._SavePath = value;
184+
this.NotifyOfPropertyChange(nameof(SavePath));
185+
}
186+
}
187+
}
188+
175189
public SaveFile SaveFile
176190
{
177191
get { return this._SaveFile; }
@@ -350,6 +364,7 @@ public IEnumerable<IResult> ReadSave()
350364
this.Backpack.ImportData(saveFile.SaveGame, saveFile.Platform);
351365
this.Bank.ImportData(saveFile.SaveGame, saveFile.Platform);
352366
this.FastTravel.ImportData(saveFile.SaveGame);
367+
this.SavePath = fileName;
353368
this.SaveFile = saveFile;
354369
this.MaybeSwitchToGeneral();
355370
}
@@ -388,7 +403,6 @@ public IEnumerable<IResult> ReadSave()
388403
.WithIcon(MessageBoxImage.Information);
389404
}
390405

391-
392406
if (this.SaveFile != null &&
393407
this.Backpack.BrokenWeapons.Count > 0)
394408
{
@@ -416,11 +430,12 @@ public IEnumerable<IResult> ReadSave()
416430
else if (result == MessageBoxResult.Cancel)
417431
{
418432
var sb = new StringBuilder();
419-
this.Backpack.BrokenWeapons.ForEach(kv =>
420-
{
421-
sb.AppendLine(kv.Value.ToString());
422-
sb.AppendLine();
423-
});
433+
this.Backpack.BrokenWeapons.ForEach(
434+
kv =>
435+
{
436+
sb.AppendLine(kv.Value.ToString());
437+
sb.AppendLine();
438+
});
424439
if (MyClipboard.SetText(sb.ToString()) != MyClipboard.Result.Success)
425440
{
426441
MessageBox.Show("Clipboard failure.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
@@ -457,11 +472,12 @@ public IEnumerable<IResult> ReadSave()
457472
else if (result == MessageBoxResult.Cancel)
458473
{
459474
var sb = new StringBuilder();
460-
this.Backpack.BrokenItems.ForEach(kv =>
461-
{
462-
sb.AppendLine(kv.Value.ToString());
463-
sb.AppendLine();
464-
});
475+
this.Backpack.BrokenItems.ForEach(
476+
kv =>
477+
{
478+
sb.AppendLine(kv.Value.ToString());
479+
sb.AppendLine();
480+
});
465481
if (MyClipboard.SetText(sb.ToString()) != MyClipboard.Result.Success)
466482
{
467483
MessageBox.Show("Clipboard failure.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
@@ -498,11 +514,12 @@ public IEnumerable<IResult> ReadSave()
498514
else if (result == MessageBoxResult.Cancel)
499515
{
500516
var sb = new StringBuilder();
501-
this.Bank.BrokenSlots.ForEach(kv =>
502-
{
503-
sb.AppendLine(kv.Value.ToString());
504-
sb.AppendLine();
505-
});
517+
this.Bank.BrokenSlots.ForEach(
518+
kv =>
519+
{
520+
sb.AppendLine(kv.Value.ToString());
521+
sb.AppendLine();
522+
});
506523
if (MyClipboard.SetText(sb.ToString()) != MyClipboard.Result.Success)
507524
{
508525
MessageBox.Show("Clipboard failure.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
@@ -514,20 +531,41 @@ public IEnumerable<IResult> ReadSave()
514531
}
515532

516533
public IEnumerable<IResult> WriteSave()
534+
{
535+
if (this.SaveFile == null || string.IsNullOrEmpty(this.SavePath) == true)
536+
{
537+
yield break;
538+
}
539+
540+
var savePath = this.SavePath;
541+
var saveFile = this.SaveFile;
542+
543+
yield return new DelegateResult(
544+
() => WriteSave(savePath, saveFile))
545+
.Rescue()
546+
.Execute(
547+
x =>
548+
new MyMessageBox(
549+
$"An exception was thrown (press Ctrl+C to copy):\n\n{x.ToString()}",
550+
"Error")
551+
.WithIcon(MessageBoxImage.Error).AsCoroutine());
552+
}
553+
554+
public IEnumerable<IResult> WriteSaveAs()
517555
{
518556
if (this.SaveFile == null)
519557
{
520558
yield break;
521559
}
522560

523-
string fileName = null;
561+
string savePath = null;
524562

525-
foreach (var result in this.SaveLoad.SaveFile(s => fileName = s))
563+
foreach (var result in this.SaveLoad.SaveFile(s => savePath = s))
526564
{
527565
yield return result;
528566
}
529567

530-
if (fileName == null)
568+
if (savePath == null)
531569
{
532570
yield break;
533571
}
@@ -537,48 +575,56 @@ public IEnumerable<IResult> WriteSave()
537575
yield return new DelegateResult(
538576
() =>
539577
{
540-
this.General.ExportData(saveFile.SaveGame, out var platform);
541-
this.Character.ExportData(saveFile.SaveGame);
542-
this.Vehicle.ExportData(saveFile.SaveGame);
543-
this.CurrencyOnHand.ExportData(saveFile.SaveGame);
544-
this.Backpack.ExportData(saveFile.SaveGame, platform);
545-
this.Bank.ExportData(saveFile.SaveGame, platform);
546-
this.FastTravel.ExportData(saveFile.SaveGame);
547-
548-
if (saveFile.SaveGame != null &&
549-
saveFile.SaveGame.WeaponData != null)
550-
{
551-
saveFile.SaveGame.WeaponData.RemoveAll(
552-
wd =>
553-
Blacklisting.IsBlacklistedType(wd.Type) == true ||
554-
Blacklisting.IsBlacklistedBalance(wd.Balance) == true);
555-
}
556-
557-
if (saveFile.SaveGame != null &&
558-
saveFile.SaveGame.ItemData != null)
559-
{
560-
saveFile.SaveGame.ItemData.RemoveAll(
561-
wd =>
562-
Blacklisting.IsBlacklistedType(wd.Type) == true ||
563-
Blacklisting.IsBlacklistedBalance(wd.Balance) == true);
564-
}
565-
566-
using (var output = File.Create(fileName))
567-
{
568-
FileFormats.SaveExpansion.AddExpansionSavedataToUnloadableItemData(
569-
saveFile.SaveGame);
570-
saveFile.Platform = platform;
571-
saveFile.Serialize(output);
572-
FileFormats.SaveExpansion
573-
.ExtractExpansionSavedataFromUnloadableItemData(
574-
saveFile.SaveGame);
575-
}
576-
}).Rescue().Execute(
578+
this.WriteSave(savePath, saveFile);
579+
this.SavePath = savePath;
580+
})
581+
.Rescue()
582+
.Execute(
577583
x =>
578584
new MyMessageBox(
579585
$"An exception was thrown (press Ctrl+C to copy):\n\n{x.ToString()}",
580586
"Error")
581587
.WithIcon(MessageBoxImage.Error).AsCoroutine());
582588
}
589+
590+
private void WriteSave(string savePath, SaveFile saveFile)
591+
{
592+
this.General.ExportData(saveFile.SaveGame, out var platform);
593+
this.Character.ExportData(saveFile.SaveGame);
594+
this.Vehicle.ExportData(saveFile.SaveGame);
595+
this.CurrencyOnHand.ExportData(saveFile.SaveGame);
596+
this.Backpack.ExportData(saveFile.SaveGame, platform);
597+
this.Bank.ExportData(saveFile.SaveGame, platform);
598+
this.FastTravel.ExportData(saveFile.SaveGame);
599+
600+
if (saveFile.SaveGame != null &&
601+
saveFile.SaveGame.WeaponData != null)
602+
{
603+
saveFile.SaveGame.WeaponData.RemoveAll(
604+
wd =>
605+
Blacklisting.IsBlacklistedType(wd.Type) == true ||
606+
Blacklisting.IsBlacklistedBalance(wd.Balance) == true);
607+
}
608+
609+
if (saveFile.SaveGame != null &&
610+
saveFile.SaveGame.ItemData != null)
611+
{
612+
saveFile.SaveGame.ItemData.RemoveAll(
613+
wd =>
614+
Blacklisting.IsBlacklistedType(wd.Type) == true ||
615+
Blacklisting.IsBlacklistedBalance(wd.Balance) == true);
616+
}
617+
618+
using (var output = File.Create(savePath))
619+
{
620+
FileFormats.SaveExpansion.AddExpansionSavedataToUnloadableItemData(
621+
saveFile.SaveGame);
622+
saveFile.Platform = platform;
623+
saveFile.Serialize(output);
624+
FileFormats.SaveExpansion
625+
.ExtractExpansionSavedataFromUnloadableItemData(
626+
saveFile.SaveGame);
627+
}
628+
}
583629
}
584630
}

0 commit comments

Comments
 (0)