mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +02:00
Leave only exe programs from start menus #198
This commit is contained in:
@@ -21,6 +21,7 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
public string ParentDirectory { get; set; }
|
public string ParentDirectory { get; set; }
|
||||||
public string ExecutableName { get; set; }
|
public string ExecutableName { get; set; }
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
|
public bool Valid { get; set; }
|
||||||
|
|
||||||
private const string ShortcutExtension = "lnk";
|
private const string ShortcutExtension = "lnk";
|
||||||
private const string ApplicationReferenceExtension = "appref-ms";
|
private const string ApplicationReferenceExtension = "appref-ms";
|
||||||
@@ -125,7 +126,8 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
IcoPath = path,
|
IcoPath = path,
|
||||||
FullPath = path,
|
FullPath = path,
|
||||||
ParentDirectory = Directory.GetParent(path).FullName,
|
ParentDirectory = Directory.GetParent(path).FullName,
|
||||||
Description = string.Empty
|
Description = string.Empty,
|
||||||
|
Valid = true
|
||||||
};
|
};
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@@ -133,7 +135,6 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
private static Win32 LnkProgram(string path)
|
private static Win32 LnkProgram(string path)
|
||||||
{
|
{
|
||||||
var program = Win32Program(path);
|
var program = Win32Program(path);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var link = new ShellLink();
|
var link = new ShellLink();
|
||||||
@@ -144,20 +145,23 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
|
|
||||||
const int MAX_PATH = 260;
|
const int MAX_PATH = 260;
|
||||||
StringBuilder buffer = new StringBuilder(MAX_PATH);
|
StringBuilder buffer = new StringBuilder(MAX_PATH);
|
||||||
link.GetDescription(buffer, MAX_PATH);
|
|
||||||
var description = buffer.ToString();
|
var data = new _WIN32_FIND_DATAW();
|
||||||
if (!string.IsNullOrEmpty(description))
|
const uint SLGP_SHORTPATH = 1;
|
||||||
{
|
link.GetPath(buffer, buffer.Capacity, ref data, SLGP_SHORTPATH);
|
||||||
program.Description = description;
|
var target = buffer.ToString();
|
||||||
}
|
if (!string.IsNullOrEmpty(target) && Extension(target) == ExeExtension)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
program.Valid = true;
|
||||||
|
|
||||||
buffer = new StringBuilder(MAX_PATH);
|
buffer = new StringBuilder(MAX_PATH);
|
||||||
var data = new _WIN32_FIND_DATAW();
|
link.GetDescription(buffer, MAX_PATH);
|
||||||
const uint SLGP_SHORTPATH = 1;
|
var description = buffer.ToString();
|
||||||
link.GetPath(buffer, buffer.Capacity, ref data, SLGP_SHORTPATH);
|
if (!string.IsNullOrEmpty(description))
|
||||||
var target = buffer.ToString();
|
{
|
||||||
if (!string.IsNullOrEmpty(target))
|
program.Description = description;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
var info = FileVersionInfo.GetVersionInfo(target);
|
var info = FileVersionInfo.GetVersionInfo(target);
|
||||||
if (!string.IsNullOrEmpty(info.FileDescription))
|
if (!string.IsNullOrEmpty(info.FileDescription))
|
||||||
@@ -166,6 +170,10 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
program.Valid = false;
|
||||||
|
}
|
||||||
return program;
|
return program;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
@@ -237,7 +245,8 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
var paths = paths1.Concat(paths2).ToArray();
|
var paths = paths1.Concat(paths2).ToArray();
|
||||||
var programs1 = paths.AsParallel().Where(p => Extension(p) == ShortcutExtension).Select(LnkProgram);
|
var programs1 = paths.AsParallel().Where(p => Extension(p) == ShortcutExtension).Select(LnkProgram);
|
||||||
var programs2 = paths.AsParallel().Where(p => Extension(p) == ApplicationReferenceExtension).Select(Win32Program);
|
var programs2 = paths.AsParallel().Where(p => Extension(p) == ApplicationReferenceExtension).Select(Win32Program);
|
||||||
return programs1.Concat(programs2);
|
var programs = programs1.Concat(programs2).Where(p => p.Valid);
|
||||||
|
return programs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user