Skip to content

Commit

Permalink
- Double click on the entry in the savegame list to load it. Yay!
Browse files Browse the repository at this point in the history
- SE window now shows the name of the savegame that is being edited.
  • Loading branch information
AnthonyZJiang committed May 28, 2018
1 parent 4ef8ff3 commit de39f99
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 102 deletions.
2 changes: 1 addition & 1 deletion D-OS Save Editor/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
<ColumnDefinition Width="250"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ListBox Grid.Row="0" x:Name="SavegameListBox" Margin="0,10,10,0" SelectionChanged="SavegameListBox_OnSelectionChanged" Height="400" MaxWidth="240" Width="240"/>
<ListBox Grid.Row="0" x:Name="SavegameListBox" Margin="0,10,10,0" SelectionChanged="SavegameListBox_OnSelectionChanged" Height="400" MaxWidth="240" Width="240" MouseDoubleClick="LoadButton_OnClick"/>
<Button x:Name="RefreshButton" Style="{StaticResource RefreshImageButtonStyle}" Grid.Row="1" Width="20" Height="20" HorizontalAlignment="Right" Margin="0, 5,10,0" Padding="0" VerticalAlignment="Top" Click="RefreshButton_OnClick"/>
<Button Content="About" Grid.Row="1" HorizontalAlignment="Left" Margin="35,30,0,0" Click="AboutButton_OnClick"/>
<Button Style="{StaticResource BugReportButtonStyle}" Grid.Row="1" Width="20" Height="18" HorizontalAlignment="Left" Margin="0,30,20,0" Padding="0" VerticalAlignment="Top" Click="BugReportButton_OnClick" ToolTip="Bug report"/>
Expand Down
207 changes: 106 additions & 101 deletions D-OS Save Editor/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,111 @@ private void LoadSavegamesPath(string dir)
return null;
}

private async Task LoadSavegame()
{
LoadButton.IsEnabled = false;

if (SavegameListBox.SelectedItem == null) return;

var unpackDir = GetTempPath() + "DOSSE" + DirectorySeparatorChar + "unpackaged";
var saveGameName = ((TextBlock)SavegameListBox.SelectedItem).Uid;

// check backup
switch (IsBackedUp(saveGameName))
{
case BackupStatus.None:
var dlgResult = MessageBox.Show(this, "The savegame is not backed up. Do you want to make a backup first?",
"No backup found.", MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (dlgResult == MessageBoxResult.Yes)
BackupSavegame(saveGameName);
break;
case BackupStatus.Current:
break;
case BackupStatus.Old:
dlgResult = MessageBox.Show(this,
"The backup seems to be old because it failed checksum validation. Do you want to make a new backup?",
"Old backup found", MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (dlgResult == MessageBoxResult.Yes)
BackupSavegame(saveGameName);
break;
case BackupStatus.NoChecksum:
dlgResult = MessageBox.Show(this,
"The backup may be old because it does not have a checksum file. Do you want to make a new backup?",
"No checksum file", MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (dlgResult == MessageBoxResult.No) return;
else break;
case BackupStatus.NoImage:
dlgResult = MessageBox.Show(this,
"The backup may be old because it does not have a checksum file. Do you want to make a new backup?",
"No image file", MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (dlgResult == MessageBoxResult.No) return;
else break;
}

var savegame = new Savegame(
DirectoryTextBox.Text + DirectorySeparatorChar + saveGameName + DirectorySeparatorChar + saveGameName + ".lsv",
unpackDir,
(Game)GameEditionTextBlock.Tag);

// unpack
var progressIndicator = new ProgressIndicator($"Loading {saveGameName}", false) { Owner = Application.Current.MainWindow };
var progress = new Progress<string>();
progress.ProgressChanged += (o, s) =>
{
progressIndicator.ProgressText = s;
};

if (_getMetaBackgroundWorker.IsBusy)
progressIndicator.ProgressText = "Waiting for meta info...";

progressIndicator.Show();

while (_getMetaBackgroundWorker.IsBusy)
await Task.Delay(5);

// TODO DNSA (Do Not Show Again) message box
// version check
if (MainWindowData.Meta.IsOutdatedVersion)
{
var dlgResult = MessageBox.Show(this,
$"It appears that the version of your game is different from what this SE is purposely created for (ver. {DataTable.SupportedGameVersion}). As a result, changes made to your savegame may corrupt the savegame.\n\nMake sure you make a backup before continuing.",
"Game version incompatible", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
if (dlgResult == MessageBoxResult.Cancel)
{
progressIndicator.Close();
return;
}

}
// mod check
if (MainWindowData.Meta.IsModWarning)
{
var dlgResult = MessageBox.Show(this,
"It appears that you have used mods. As a result, changes made to your savegame may corrupt the savegame.\n\nMake sure you make a backup before continuing.",
"Mods found", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
if (dlgResult == MessageBoxResult.Cancel)
{
progressIndicator.Close();
return;
}
}

var unpackTask = await UnpackSaveAsync(savegame, progress);
progressIndicator.Close();
if (!unpackTask) return;

SaveEditor se;
try
{
se = new SaveEditor(savegame) { Owner = Application.Current.MainWindow };
}
catch
{
return;
}
se.ShowDialog();
}

/// <summary>
/// Unpacks lsv files
/// </summary>
Expand Down Expand Up @@ -414,107 +519,7 @@ private async void SavegameListBox_OnSelectionChanged(object sender, SelectionCh

private async void LoadButton_OnClick(object sender, RoutedEventArgs e)
{
LoadButton.IsEnabled = false;

if (SavegameListBox.SelectedItem == null) return;

var unpackDir = GetTempPath() + "DOSSE" + DirectorySeparatorChar + "unpackaged";
var saveGameName = ((TextBlock)SavegameListBox.SelectedItem).Uid;

// check backup
switch (IsBackedUp(saveGameName))
{
case BackupStatus.None:
var dlgResult = MessageBox.Show(this, "The savegame is not backed up. Do you want to make a backup first?",
"No backup found.", MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (dlgResult == MessageBoxResult.Yes)
BackupSavegame(saveGameName);
break;
case BackupStatus.Current:
break;
case BackupStatus.Old:
dlgResult = MessageBox.Show(this,
"The backup seems to be old because it failed checksum validation. Do you want to make a new backup?",
"Old backup found", MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (dlgResult == MessageBoxResult.Yes)
BackupSavegame(saveGameName);
break;
case BackupStatus.NoChecksum:
dlgResult = MessageBox.Show(this,
"The backup may be old because it does not have a checksum file. Do you want to make a new backup?",
"No checksum file", MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (dlgResult == MessageBoxResult.No) return;
else break;
case BackupStatus.NoImage:
dlgResult = MessageBox.Show(this,
"The backup may be old because it does not have a checksum file. Do you want to make a new backup?",
"No image file", MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (dlgResult == MessageBoxResult.No) return;
else break;
}

var savegame = new Savegame(
DirectoryTextBox.Text + DirectorySeparatorChar + saveGameName + DirectorySeparatorChar + saveGameName + ".lsv",
unpackDir,
(Game)GameEditionTextBlock.Tag);

// unpack
var progressIndicator = new ProgressIndicator($"Loading {saveGameName}", false) {Owner = Application.Current.MainWindow};
var progress = new Progress<string>();
progress.ProgressChanged += (o, s) =>
{
progressIndicator.ProgressText = s;
};

if (_getMetaBackgroundWorker.IsBusy)
progressIndicator.ProgressText = "Waiting for meta info...";

progressIndicator.Show();

while (_getMetaBackgroundWorker.IsBusy)
await Task.Delay(5);

// TODO DNSA (Do Not Show Again) message box
// version check
if (MainWindowData.Meta.IsOutdatedVersion)
{
var dlgResult = MessageBox.Show(this,
$"It appears that the version of your game is different from what this SE is purposely created for (ver. {DataTable.SupportedGameVersion}). As a result, changes made to your savegame may corrupt the savegame.\n\nMake sure you make a backup before continuing.",
"Game version incompatible", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
if (dlgResult == MessageBoxResult.Cancel)
{
progressIndicator.Close();
return;
}

}
// mod check
if (MainWindowData.Meta.IsModWarning)
{
var dlgResult = MessageBox.Show(this,
"It appears that you have used mods. As a result, changes made to your savegame may corrupt the savegame.\n\nMake sure you make a backup before continuing.",
"Mods found", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
if (dlgResult == MessageBoxResult.Cancel)
{
progressIndicator.Close();
return;
}
}

var unpackTask = await UnpackSaveAsync(savegame, progress);
progressIndicator.Close();
if (!unpackTask) return;

SaveEditor se;
try
{
se = new SaveEditor(savegame) { Owner = Application.Current.MainWindow };
}
catch
{
return;
}
se.ShowDialog();
await LoadSavegame();
}

private void BackupButton_OnClick(object sender, RoutedEventArgs e)
Expand Down
2 changes: 2 additions & 0 deletions D-OS Save Editor/SE/SaveEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public SaveEditor(Savegame savegame)
InitializeComponent();
Savegame = savegame;

Title = $"D-OS Save Editor: {savegame.SavegameName.Substring(0,savegame.SavegameName.Length-4)}";

// make a copy of players
try
{
Expand Down

1 comment on commit de39f99

@Greavox
Copy link
Contributor

@Greavox Greavox commented on de39f99 Jun 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job again! It's easier too use

Please sign in to comment.