mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
Remove duplicated programs loading from registry
This commit is contained in:
@@ -338,73 +338,48 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
|
|
||||||
private static IEnumerable<Win32> ProgramsFromRegistryKey(RegistryKey root)
|
private static IEnumerable<Win32> ProgramsFromRegistryKey(RegistryKey root)
|
||||||
{
|
{
|
||||||
var programs = root.GetSubKeyNames()
|
return root
|
||||||
.Select(subkey => ProgramFromRegistrySubkey(root, subkey))
|
.GetSubKeyNames()
|
||||||
.Where(p => !string.IsNullOrEmpty(p.Name));
|
.Select(x => GetProgramRegistryPath(root, x))
|
||||||
return programs;
|
.Distinct()
|
||||||
|
.Select(x => ProgramFromRegistrySubkey(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Win32 ProgramFromRegistrySubkey(RegistryKey root, string subkey)
|
private static string GetProgramRegistryPath(RegistryKey root, string subkey)
|
||||||
{
|
{
|
||||||
|
var path = string.Empty;
|
||||||
|
|
||||||
using (var key = root.OpenSubKey(subkey))
|
using (var key = root.OpenSubKey(subkey))
|
||||||
{
|
{
|
||||||
if (key != null)
|
if (key == null)
|
||||||
{
|
return string.Empty;
|
||||||
var defaultValue = string.Empty;
|
|
||||||
var path = key.GetValue(defaultValue) as string;
|
|
||||||
if (!string.IsNullOrEmpty(path))
|
|
||||||
{
|
|
||||||
// fix path like this: ""\"C:\\folder\\executable.exe\""
|
|
||||||
path = path.Trim('"', ' ');
|
|
||||||
path = Environment.ExpandEnvironmentVariables(path);
|
|
||||||
|
|
||||||
if (File.Exists(path))
|
var defaultValue = string.Empty;
|
||||||
{
|
path = key.GetValue(defaultValue) as string;
|
||||||
var entry = Win32Program(path);
|
|
||||||
entry.ExecutableName = subkey;
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return new Win32();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return new Win32();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return new Win32();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(path))
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
|
// fix path like this: ""\"C:\\folder\\executable.exe\""
|
||||||
|
return path = path.Trim('"', ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
//private static Win32 ScoreFilter(Win32 p)
|
private static Win32 ProgramFromRegistrySubkey(string path)
|
||||||
//{
|
{
|
||||||
// var start = new[] { "启动", "start" };
|
if (string.IsNullOrEmpty(path))
|
||||||
// var doc = new[] { "帮助", "help", "文档", "documentation" };
|
return new Win32();
|
||||||
// var uninstall = new[] { "卸载", "uninstall" };
|
|
||||||
|
|
||||||
// var contained = start.Any(s => p.Name.ToLower().Contains(s));
|
path = Environment.ExpandEnvironmentVariables(path);
|
||||||
// if (contained)
|
|
||||||
// {
|
|
||||||
// p.Score += 10;
|
|
||||||
// }
|
|
||||||
// contained = doc.Any(d => p.Name.ToLower().Contains(d));
|
|
||||||
// if (contained)
|
|
||||||
// {
|
|
||||||
// p.Score -= 10;
|
|
||||||
// }
|
|
||||||
// contained = uninstall.Any(u => p.Name.ToLower().Contains(u));
|
|
||||||
// if (contained)
|
|
||||||
// {
|
|
||||||
// p.Score -= 20;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return p;
|
if (!File.Exists(path))
|
||||||
//}
|
return new Win32();
|
||||||
|
|
||||||
|
var entry = Win32Program(path);
|
||||||
|
entry.ExecutableName = Path.GetFileName(path);
|
||||||
|
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
public static Win32[] All(Settings settings)
|
public static Win32[] All(Settings settings)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user