From dad15b4c27ccf734de7192f726917ea270a64843 Mon Sep 17 00:00:00 2001 From: Vitaly Date: Wed, 18 Sep 2024 14:49:27 +0200 Subject: [PATCH] Fixed a bug where the local screenshot file wasn't deleted correctly when errors occurred. Closes #630. --- src/srcrepair/FrmMainW.cs | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/srcrepair/FrmMainW.cs b/src/srcrepair/FrmMainW.cs index 2cc0c11c..f87fa738 100644 --- a/src/srcrepair/FrmMainW.cs +++ b/src/srcrepair/FrmMainW.cs @@ -731,7 +731,7 @@ private void SetAppStrings() { // Save last Steam path in application's settings... Properties.Settings.Default.LastSteamPath = App.SteamClient.FullSteamPath; - + // Add Steam client installation path to Troubleshooting page... PS_StPath.Text = string.Format(PS_StPath.Text, App.SteamClient.FullSteamPath); } @@ -949,10 +949,10 @@ private void HandlePasteMultiple() /// private async Task HandleHUDScreenshot() { - string HUDScreenshotFile = string.Empty; + string HUDScreenshotFile = GetHUDScreenshotFileName(); try { - HUDScreenshotFile = await DownloadHUDScreenshot(AppSelector.Text, HD_HSel.Text); + await DownloadHUDScreenshotTask(GetHUDScreenshotURL(), HUDScreenshotFile); HD_GB_Pbx.Image = Image.FromFile(HUDScreenshotFile); } catch (Exception Ex) @@ -1836,26 +1836,18 @@ await Task.Run(() => /// /// Gets a screenshot of selected HUD in a separate thread. /// - /// Selected game name. - /// Selected HUD name. - /// Returns full path to the HUD screenshot file. - private async Task DownloadHUDScreenshot(string SelectedGame, string SelectedHUD) + /// Selected game name. + /// Selected HUD name. + private async Task DownloadHUDScreenshotTask(string ScreenURL, string ScreenFile) { - // Generating full file name for HUD screenshot... - string ScreenFile = Path.Combine(App.AppHUDDir, Path.GetFileName(App.SourceGames[SelectedGame].HUDMan[SelectedHUD].Preview)); - - // Downloading file if it doesn't exists... if (!File.Exists(ScreenFile)) { using (WebClient Downloader = new WebClient()) { Downloader.Headers.Add("User-Agent", App.UserAgent); - await Downloader.DownloadFileTaskAsync(App.SourceGames[SelectedGame].HUDMan[SelectedHUD].Preview, ScreenFile); + await Downloader.DownloadFileTaskAsync(ScreenURL, ScreenFile); } } - - // Returning result to callback... - return ScreenFile; } /// @@ -3215,13 +3207,13 @@ private void SB_App_DoubleClick(object sender, EventArgs e) { // Changing Safe Clean status... Properties.Settings.Default.SafeCleanup = !Properties.Settings.Default.SafeCleanup; - + // Showing message about consequences of disabling... if (!Properties.Settings.Default.SafeCleanup) { MessageBox.Show(AppStrings.AppSafeClnDisabled, Properties.Resources.AppName, MessageBoxButtons.OK, MessageBoxIcon.Information); } - + // Updating status bar... CheckSafeClnStatus(); }