From 37398abe357466311ee892412a73186ab4af0cc2 Mon Sep 17 00:00:00 2001 From: elpatron68 Date: Fri, 14 Oct 2022 20:30:22 +0200 Subject: [PATCH] Add more logging --- SnowRunner-Tool/MainWindow.xaml.cs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/SnowRunner-Tool/MainWindow.xaml.cs b/SnowRunner-Tool/MainWindow.xaml.cs index 4f6b955..9248387 100644 --- a/SnowRunner-Tool/MainWindow.xaml.cs +++ b/SnowRunner-Tool/MainWindow.xaml.cs @@ -131,6 +131,7 @@ public MainWindow(ILogger logger, string[] args) /// private void ReadBackups() { + _logger.Information("Reading list of existin backups"); List allBackups = new List(); // Add SnowRunner backup directories try @@ -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 { @@ -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(); }); } @@ -176,6 +180,7 @@ private void ReadBackups() private void UpdateSaveGameSlotMenus() { + _logger.Debug("Updating save game slot menu items"); bool saveGameExists; string saveFile; @@ -202,6 +207,7 @@ private void UpdateSaveGameSlotMenus() private void RestoreBackup_Click(object sender, RoutedEventArgs e) { + _logger.Information("Start restoring a backup"); bool copyResult = false; if (BackupScheduler.IsActive()) { @@ -209,7 +215,7 @@ private void RestoreBackup_Click(object sender, RoutedEventArgs e) } else { - int SavegameSlot=0; + int SavegameSlot = 0; String source = e.Source.ToString(); if (source.Contains("#_1")) @@ -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; @@ -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."); }