From 00b50a9193e637558c0fd765211a5e3e188c8b08 Mon Sep 17 00:00:00 2001 From: Stefan Markovic Date: Mon, 28 Oct 2024 20:38:13 +0100 Subject: [PATCH] [Settings] Fix crash on View Diagnostic data click --- .../ViewModels/GeneralViewModel.cs | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs index e5a0d92aa8..6a2340f8c6 100644 --- a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs @@ -1259,20 +1259,28 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels string localLowEtwDirPath = Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), "AppData", "LocalLow", "Microsoft", "PowerToys", "etw"); string etwDirPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\PowerToys\\etw"); - string[] localLowEtlFiles = Directory.GetFiles(localLowEtwDirPath, "*.etl"); - - foreach (string file in localLowEtlFiles) + if (Directory.Exists(localLowEtwDirPath)) { - string fileName = Path.GetFileName(file); - string destFile = Path.Combine(etwDirPath, fileName); - - try + if (!Directory.Exists(etwDirPath)) { - File.Copy(file, destFile, overwrite: true); + Directory.CreateDirectory(etwDirPath); } - catch (Exception ex) + + string[] localLowEtlFiles = Directory.GetFiles(localLowEtwDirPath, "*.etl"); + + foreach (string file in localLowEtlFiles) { - Logger.LogError($"Failed to copy etl file: {fileName}. Error: {ex.Message}"); + string fileName = Path.GetFileName(file); + string destFile = Path.Combine(etwDirPath, fileName); + + try + { + File.Copy(file, destFile, overwrite: true); + } + catch (Exception ex) + { + Logger.LogError($"Failed to copy etl file: {fileName}. Error: {ex.Message}"); + } } }