Skip to content

Commit

Permalink
Add more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
elpatron68 committed Oct 14, 2022
1 parent 7341190 commit 37398ab
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions SnowRunner-Tool/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public MainWindow(ILogger logger, string[] args)
/// </summary>
private void ReadBackups()
{
_logger.Information("Reading list of existin backups");
List<Backup> allBackups = new List<Backup>();
// Add SnowRunner backup directories
try
Expand All @@ -141,10 +142,12 @@ private void ReadBackups()
{
// No existing SnowRunner backups
}

_logger.Information("Added backups made by SnowRunner: " + allBackups.Count);

// Add own zipped backups
allBackups.AddRange(Backup.GetSrtBackups(MyBackupDir, Platform));
var MyBackups = Backup.GetSrtBackups(MyBackupDir, Platform);
_logger.Information("Added backups made by SnowRunner: " + MyBackups.Count);
allBackups.AddRange(MyBackups);

try
{
Expand All @@ -155,6 +158,7 @@ private void ReadBackups()
dgBackups.ItemsSource = allBackups;
dgBackups.Items.SortDescriptions.Clear();
dgBackups.Items.SortDescriptions.Add(new SortDescription("Timestamp", ListSortDirection.Descending));
_logger.Debug("Refreshing table");
dgBackups.Items.Refresh();
});
}
Expand All @@ -176,6 +180,7 @@ private void ReadBackups()

private void UpdateSaveGameSlotMenus()
{
_logger.Debug("Updating save game slot menu items");
bool saveGameExists;
string saveFile;

Expand All @@ -202,14 +207,15 @@ private void UpdateSaveGameSlotMenus()

private void RestoreBackup_Click(object sender, RoutedEventArgs e)
{
_logger.Information("Start restoring a backup");
bool copyResult = false;
if (BackupScheduler.IsActive())
{
_ = MetroMessage("Attention!", "The game has to be closed before a backup can be restored.");
}
else
{
int SavegameSlot=0;
int SavegameSlot = 0;

String source = e.Source.ToString();
if (source.Contains("#_1"))
Expand All @@ -228,7 +234,8 @@ private void RestoreBackup_Click(object sender, RoutedEventArgs e)
{
SavegameSlot = 4;
}

_logger.Debug("Slot: " + SavegameSlot);

ContextMenu contextMenu = this.FindName("Restore") as ContextMenu;
DataGrid item = (DataGrid)contextMenu.PlacementTarget;

Expand All @@ -241,19 +248,24 @@ private void RestoreBackup_Click(object sender, RoutedEventArgs e)
Backup restoreItem = (Backup)item.SelectedCells[0].Item;

// Create a backup before restore
_logger.Debug("Backing up current save game before restoring");
_ = Backup.BackupCurrentSavegame(SRProfile, MyBackupDir, "safety-bak");

string backupSource = string.Equals(restoreItem.Type, "Game-Backup", StringComparison.OrdinalIgnoreCase)
? SRBackupDir + @"\" + restoreItem.BackupName
: MyBackupDir + @"\" + restoreItem.BackupName;

_logger.Information(String.Format("Restoring {0}, slot {1} to {2}", backupSource, SavegameSlot, SRProfile));
copyResult = Backup.RestoreBackup(backupSource, SRProfile, SavegameSlot, SavegameExtension);
if (copyResult)
{
_logger.Debug("Restore was successful");
_ = MetroDonateMessage("Next time better luck", "The selected saved game has successfully been restored. A backup of your former save game has been made.\n\n" +
"As I may have saved your a** this time (again?), consider to buy me a \U0001F37A or a \U00002615!");
}
else
{
_logger.Warning("Restore failed");
_ = MetroMessage("File not found", "The selected backup slot contains no corresponding save game file. Select a valid slot or restore all slots.");
}

Expand Down

0 comments on commit 37398ab

Please sign in to comment.