Skip to content

Commit a92daf7

Browse files
authored
Fix: Fixed PowerToys Peek detection for custom install paths (#18374)
1 parent 37fc0b9 commit a92daf7

File tree

1 file changed

+46
-14
lines changed

1 file changed

+46
-14
lines changed

src/Files.App/Services/PreviewPopupProviders/PowerToysPeekProvider.cs

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System.IO;
5+
using Microsoft.Win32;
56

67
namespace Files.App.Services.PreviewPopupProviders
78
{
@@ -48,28 +49,59 @@ private async Task DoPreviewAsync(string path)
4849
public async Task<bool> DetectAvailability()
4950
{
5051
var exeName = "PowerToys.Peek.UI.exe";
51-
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
52-
var perUserPath = Path.Combine(localAppData, "PowerToys", "WinUI3Apps", exeName);
53-
54-
// User path
55-
if (File.Exists(perUserPath))
52+
if (FindPeekPathFromRegistry(exeName) is { } registryPath && File.Exists(registryPath))
5653
{
57-
_peekExecutablePath = perUserPath;
54+
_peekExecutablePath = registryPath;
5855
return true;
5956
}
6057

61-
// Machine-wide path
62-
string programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
63-
string machinePath = Path.Combine(programFiles, "PowerToys", "WinUI3Apps", exeName);
58+
// Not found
59+
return false;
60+
}
61+
62+
private static string? FindPeekPathFromRegistry(string exeName)
63+
{
64+
string[] uninstallRegistryPaths =
65+
[
66+
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
67+
@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall",
68+
];
6469

65-
if (File.Exists(machinePath))
70+
foreach (var hive in new[] { RegistryHive.CurrentUser, RegistryHive.LocalMachine })
6671
{
67-
_peekExecutablePath = machinePath;
68-
return true;
72+
foreach (var uninstallPath in uninstallRegistryPaths)
73+
{
74+
try
75+
{
76+
using var baseKey = RegistryKey.OpenBaseKey(hive, RegistryView.Default);
77+
using var uninstallKey = baseKey.OpenSubKey(uninstallPath);
78+
if (uninstallKey is null)
79+
continue;
80+
81+
foreach (var subKeyName in uninstallKey.GetSubKeyNames())
82+
{
83+
using var appKey = uninstallKey.OpenSubKey(subKeyName);
84+
if (appKey is null)
85+
continue;
86+
87+
var displayName = appKey.GetValue("DisplayName") as string;
88+
if (string.IsNullOrWhiteSpace(displayName)
89+
|| displayName.IndexOf("PowerToys", StringComparison.OrdinalIgnoreCase) < 0)
90+
continue;
91+
92+
var installLocation = appKey.GetValue("InstallLocation") as string;
93+
if (!string.IsNullOrWhiteSpace(installLocation))
94+
return Path.Combine(installLocation, "WinUI3Apps", exeName);
95+
}
96+
}
97+
catch
98+
{
99+
// Ignore registry access issues and continue fallback resolution.
100+
}
101+
}
69102
}
70103

71-
// Not found
72-
return false;
104+
return null;
73105
}
74106
}
75107
}

0 commit comments

Comments
 (0)