[Settings]Fix crash on View Diagnostic data click (#35635)

This commit is contained in:
Stefan Markovic 2024-10-29 15:20:24 +01:00 committed by GitHub
parent da52d485a6
commit b204353308
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1259,20 +1259,28 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
string localLowEtwDirPath = Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), "AppData", "LocalLow", "Microsoft", "PowerToys", "etw"); 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 etwDirPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\PowerToys\\etw");
string[] localLowEtlFiles = Directory.GetFiles(localLowEtwDirPath, "*.etl"); if (Directory.Exists(localLowEtwDirPath))
foreach (string file in localLowEtlFiles)
{ {
string fileName = Path.GetFileName(file); if (!Directory.Exists(etwDirPath))
string destFile = Path.Combine(etwDirPath, fileName);
try
{ {
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}");
}
} }
} }