mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
Merge branch 'enable_userselected_programloading' into dev
This commit is contained in:
@@ -275,7 +275,7 @@ namespace Wox.Plugin.Program.Programs
|
||||
.ToList()
|
||||
.ForEach(x => listToAdd.Add(x));
|
||||
|
||||
var paths = listToAdd.ToArray();
|
||||
var paths = listToAdd.Distinct().ToArray();
|
||||
|
||||
var programs1 = paths.AsParallel().Where(p => Extension(p) == ExeExtension).Select(ExeProgram);
|
||||
var programs2 = paths.AsParallel().Where(p => Extension(p) == ShortcutExtension).Select(ExeProgram);
|
||||
@@ -299,6 +299,7 @@ namespace Wox.Plugin.Program.Programs
|
||||
var paths = toFilter
|
||||
.Where(t1 => !disabledProgramsList.Any(x => x.UniqueIdentifier == t1))
|
||||
.Select(t1 => t1)
|
||||
.Distinct()
|
||||
.ToArray();
|
||||
|
||||
var programs1 = paths.AsParallel().Where(p => Extension(p) == ShortcutExtension).Select(LnkProgram);
|
||||
@@ -307,7 +308,6 @@ namespace Wox.Plugin.Program.Programs
|
||||
return programs;
|
||||
}
|
||||
|
||||
|
||||
private static ParallelQuery<Win32> AppPathsPrograms(string[] suffixes)
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/ee872121
|
||||
@@ -317,14 +317,14 @@ namespace Wox.Plugin.Program.Programs
|
||||
{
|
||||
if (root != null)
|
||||
{
|
||||
programs.AddRange(ProgramsFromRegistryKey(root));
|
||||
programs.AddRange(GetProgramsFromRegistry(root));
|
||||
}
|
||||
}
|
||||
using (var root = Registry.CurrentUser.OpenSubKey(appPaths))
|
||||
{
|
||||
if (root != null)
|
||||
{
|
||||
programs.AddRange(ProgramsFromRegistryKey(root));
|
||||
programs.AddRange(GetProgramsFromRegistry(root));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,79 +336,54 @@ namespace Wox.Plugin.Program.Programs
|
||||
return filtered;
|
||||
}
|
||||
|
||||
private static IEnumerable<Win32> ProgramsFromRegistryKey(RegistryKey root)
|
||||
private static IEnumerable<Win32> GetProgramsFromRegistry(RegistryKey root)
|
||||
{
|
||||
var programs = root.GetSubKeyNames()
|
||||
.Select(subkey => ProgramFromRegistrySubkey(root, subkey))
|
||||
.Where(p => !string.IsNullOrEmpty(p.Name));
|
||||
return programs;
|
||||
return root
|
||||
.GetSubKeyNames()
|
||||
.Select(x => GetProgramPathFromRegistrySubKeys(root, x))
|
||||
.Distinct()
|
||||
.Select(x => GetProgramFromPath(x));
|
||||
}
|
||||
|
||||
private static Win32 ProgramFromRegistrySubkey(RegistryKey root, string subkey)
|
||||
private static string GetProgramPathFromRegistrySubKeys(RegistryKey root, string subkey)
|
||||
{
|
||||
var path = string.Empty;
|
||||
|
||||
using (var key = root.OpenSubKey(subkey))
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
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 (key == null)
|
||||
return string.Empty;
|
||||
|
||||
if (File.Exists(path))
|
||||
{
|
||||
var entry = Win32Program(path);
|
||||
entry.ExecutableName = subkey;
|
||||
return entry;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Win32();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Win32();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Win32();
|
||||
}
|
||||
var defaultValue = string.Empty;
|
||||
path = key.GetValue(defaultValue) as string;
|
||||
}
|
||||
|
||||
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)
|
||||
//{
|
||||
// var start = new[] { "启动", "start" };
|
||||
// var doc = new[] { "帮助", "help", "文档", "documentation" };
|
||||
// var uninstall = new[] { "卸载", "uninstall" };
|
||||
private static Win32 GetProgramFromPath(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
return new Win32();
|
||||
|
||||
// var contained = start.Any(s => p.Name.ToLower().Contains(s));
|
||||
// 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;
|
||||
// }
|
||||
path = Environment.ExpandEnvironmentVariables(path);
|
||||
|
||||
// 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)
|
||||
{
|
||||
ParallelQuery<Win32> programs = new List<Win32>().AsParallel();
|
||||
var programs = new List<Win32>().AsParallel();
|
||||
|
||||
var unregistered = UnregisteredPrograms(settings.ProgramSources, settings.ProgramSuffixes);
|
||||
programs = programs.Concat(unregistered);
|
||||
@@ -422,8 +397,8 @@ namespace Wox.Plugin.Program.Programs
|
||||
{
|
||||
var startMenu = StartMenuPrograms(settings.ProgramSuffixes);
|
||||
programs = programs.Concat(startMenu);
|
||||
}
|
||||
//.Select(ScoreFilter);
|
||||
}
|
||||
|
||||
return programs.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user