From a3d6439166bc45c381acbee8ef19cad7aea83350 Mon Sep 17 00:00:00 2001 From: Chen-I Lim Date: Mon, 1 Mar 2021 16:24:38 -0800 Subject: [PATCH] Webview2 installer cleanup --- win-wpf/Focalboard/Webview2Installer.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/win-wpf/Focalboard/Webview2Installer.cs b/win-wpf/Focalboard/Webview2Installer.cs index 831fb4821..3937a7f64 100644 --- a/win-wpf/Focalboard/Webview2Installer.cs +++ b/win-wpf/Focalboard/Webview2Installer.cs @@ -20,9 +20,9 @@ namespace Focalboard { private string filePath; public Webview2Installer() { - const string filename = "MicrosoftEdgeWebview2Setup.exe"; - var downloadsFolder = UserDataPaths.GetDefault().Downloads; - filePath = Path.Combine(downloadsFolder, filename); + var filename = $"{Guid.NewGuid().ToString()} MicrosoftEdgeWebview2Setup.exe"; + filePath = Path.Combine(System.IO.Path.GetTempPath(), filename); + Debug.WriteLine($"Webview2Installer.filePath: {filePath}"); } public void DownloadAndInstall() { @@ -39,7 +39,7 @@ namespace Focalboard { wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged); wc.DownloadFileCompleted += new AsyncCompletedEventHandler(wc_DownloadFileCompleted); } catch (Exception ex) { - MessageBox.Show(ex.Message.ToString()); + MessageBox.Show($"Webview2 download ERROR: {ex.Message}", "Download error"); } } @@ -59,6 +59,15 @@ namespace Focalboard { } private void Proc_Exited(object sender, EventArgs e) { + // Delete downloaded installer + try { + if (File.Exists(filePath)) { + File.Delete(filePath); + } + } catch (Exception ex) { + Debug.WriteLine($"Delete file failed. Error: {ex.Message}, filePath: {filePath}"); + } + var proc = (Process)sender; exitCode = proc.ExitCode; InstallCompleted?.Invoke(this, e);