mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 12:46:47 +02:00
Index Desktop Applications (#4422)
* Added support to index desktop app * Fixed dedup for url files * Added internet shortcut scheme for epic games * Added test for internet shortcut dedup * Updated hostname for steam game
This commit is contained in:
committed by
GitHub
parent
73125574e6
commit
196055e50e
@@ -13,6 +13,7 @@ using Microsoft.Plugin.Program.Logger;
|
|||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace Microsoft.Plugin.Program.Programs
|
namespace Microsoft.Plugin.Program.Programs
|
||||||
{
|
{
|
||||||
@@ -240,10 +241,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
AcceleratorModifiers = (ModifierKeys.Control | ModifierKeys.Shift),
|
AcceleratorModifiers = (ModifierKeys.Control | ModifierKeys.Shift),
|
||||||
Action = _ =>
|
Action = _ =>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", ParentDirectory));
|
Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", ParentDirectory));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -292,26 +290,24 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
string[] lines = System.IO.File.ReadAllLines(path);
|
string[] lines = System.IO.File.ReadAllLines(path);
|
||||||
string appName = string.Empty;
|
string appName = string.Empty;
|
||||||
string iconPath = string.Empty;
|
string iconPath = string.Empty;
|
||||||
|
string urlPath = string.Empty;
|
||||||
string scheme = string.Empty;
|
string scheme = string.Empty;
|
||||||
bool validApp = false;
|
bool validApp = false;
|
||||||
|
|
||||||
const string steamScheme = "steam";
|
Regex InternetShortcutURLPrefixes = new Regex(@"^steam:\/\/(rungameid|run)\/|^com\.epicgames\.launcher:\/\/apps\/");
|
||||||
|
|
||||||
const string urlPrefix = "URL=";
|
const string urlPrefix = "URL=";
|
||||||
const string iconFilePrefix = "IconFile=";
|
const string iconFilePrefix = "IconFile=";
|
||||||
const string hostnameRun = "run";
|
|
||||||
const string hostnameRunGameId = "rungameid";
|
|
||||||
|
|
||||||
foreach(string line in lines)
|
foreach(string line in lines)
|
||||||
{
|
{
|
||||||
if(line.StartsWith(urlPrefix))
|
if(line.StartsWith(urlPrefix))
|
||||||
{
|
{
|
||||||
var urlPath = line.Substring(urlPrefix.Length);
|
urlPath = line.Substring(urlPrefix.Length);
|
||||||
Uri uri = new Uri(urlPath);
|
Uri uri = new Uri(urlPath);
|
||||||
|
|
||||||
// To filter out only those steam shortcuts which have 'run' or 'rungameid' as the hostname
|
// To filter out only those steam shortcuts which have 'run' or 'rungameid' as the hostname
|
||||||
if(uri.Scheme.Equals(steamScheme, StringComparison.OrdinalIgnoreCase)
|
if(InternetShortcutURLPrefixes.Match(urlPath).Success)
|
||||||
&& (uri.Host.Equals(hostnameRun, StringComparison.OrdinalIgnoreCase)
|
|
||||||
|| uri.Host.Equals(hostnameRunGameId, StringComparison.OrdinalIgnoreCase)))
|
|
||||||
{
|
{
|
||||||
validApp = true;
|
validApp = true;
|
||||||
}
|
}
|
||||||
@@ -335,7 +331,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
Name = Path.GetFileNameWithoutExtension(path),
|
Name = Path.GetFileNameWithoutExtension(path),
|
||||||
ExecutableName = Path.GetFileName(path),
|
ExecutableName = Path.GetFileName(path),
|
||||||
IcoPath = iconPath,
|
IcoPath = iconPath,
|
||||||
FullPath = path.ToLower(),
|
FullPath = urlPath,
|
||||||
UniqueIdentifier = path,
|
UniqueIdentifier = path,
|
||||||
ParentDirectory = Directory.GetParent(path).FullName,
|
ParentDirectory = Directory.GetParent(path).FullName,
|
||||||
Valid = true,
|
Valid = true,
|
||||||
@@ -522,16 +518,17 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
return programs1.Concat(programs2).Concat(programs3);
|
return programs1.Concat(programs2).Concat(programs3);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ParallelQuery<Win32> StartMenuPrograms(string[] suffixes)
|
private static ParallelQuery<Win32> IndexPath(string[] suffixes, List<string> IndexLocation)
|
||||||
{
|
{
|
||||||
var disabledProgramsList = Main._settings.DisabledProgramSources;
|
var disabledProgramsList = Main._settings.DisabledProgramSources;
|
||||||
|
|
||||||
var directory1 = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
|
IEnumerable<string> toFilter = new List<string>();
|
||||||
var directory2 = Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms);
|
foreach (string location in IndexLocation)
|
||||||
var paths1 = ProgramPaths(directory1, suffixes);
|
{
|
||||||
var paths2 = ProgramPaths(directory2, suffixes);
|
var _paths = ProgramPaths(location, suffixes);
|
||||||
|
toFilter = toFilter.Concat(_paths);
|
||||||
var toFilter = paths1.Concat(paths2);
|
}
|
||||||
|
|
||||||
var paths = toFilter
|
var paths = toFilter
|
||||||
.Where(t1 => !disabledProgramsList.Any(x => x.UniqueIdentifier == t1))
|
.Where(t1 => !disabledProgramsList.Any(x => x.UniqueIdentifier == t1))
|
||||||
.Select(t1 => t1)
|
.Select(t1 => t1)
|
||||||
@@ -545,6 +542,23 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
return programs1.Concat(programs2).Where(p => p.Valid).Concat(programs3).Where(p => p.Valid);
|
return programs1.Concat(programs2).Where(p => p.Valid).Concat(programs3).Where(p => p.Valid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ParallelQuery<Win32> StartMenuPrograms(string[] suffixes)
|
||||||
|
{
|
||||||
|
var directory1 = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
|
||||||
|
var directory2 = Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms);
|
||||||
|
List<string> IndexLocation = new List<string>() { directory1, directory2};
|
||||||
|
|
||||||
|
return IndexPath(suffixes, IndexLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ParallelQuery<Win32> DesktopPrograms(string[] suffixes)
|
||||||
|
{
|
||||||
|
var directory1 = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
||||||
|
List<string> IndexLocation = new List<string>() { directory1 };
|
||||||
|
|
||||||
|
return IndexPath(suffixes, IndexLocation);
|
||||||
|
}
|
||||||
|
|
||||||
private static ParallelQuery<Win32> AppPathsPrograms(string[] suffixes)
|
private static ParallelQuery<Win32> AppPathsPrograms(string[] suffixes)
|
||||||
{
|
{
|
||||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/ee872121
|
// https://msdn.microsoft.com/en-us/library/windows/desktop/ee872121
|
||||||
@@ -688,6 +702,12 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
programs = programs.Concat(startMenu);
|
programs = programs.Concat(startMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (settings.EnableDesktopSource)
|
||||||
|
{
|
||||||
|
var desktop = DesktopPrograms(settings.ProgramSuffixes);
|
||||||
|
programs = programs.Concat(desktop);
|
||||||
|
}
|
||||||
|
|
||||||
return DeduplicatePrograms(programs);
|
return DeduplicatePrograms(programs);
|
||||||
}
|
}
|
||||||
#if DEBUG //This is to make developer aware of any unhandled exception and add in handling.
|
#if DEBUG //This is to make developer aware of any unhandled exception and add in handling.
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ namespace Microsoft.Plugin.Program
|
|||||||
|
|
||||||
public bool EnableStartMenuSource { get; set; } = true;
|
public bool EnableStartMenuSource { get; set; } = true;
|
||||||
|
|
||||||
|
public bool EnableDesktopSource { get; set; } = true;
|
||||||
|
|
||||||
public bool EnableRegistrySource { get; set; } = true;
|
public bool EnableRegistrySource { get; set; } = true;
|
||||||
|
|
||||||
internal const char SuffixSeparator = ';';
|
internal const char SuffixSeparator = ';';
|
||||||
|
|||||||
@@ -126,6 +126,24 @@ namespace Wox.Test.Plugins
|
|||||||
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\test proxy.lnk"
|
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\test proxy.lnk"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Win32 dummy_internetShortcut_app = new Win32
|
||||||
|
{
|
||||||
|
Name = "Shop Titans",
|
||||||
|
ExecutableName = "Shop Titans.url",
|
||||||
|
FullPath = "steam://rungameid/1258080",
|
||||||
|
ParentDirectory = "C:\\Users\\temp\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Steam",
|
||||||
|
LnkResolvedPath = null
|
||||||
|
};
|
||||||
|
|
||||||
|
Win32 dummy_internetShortcut_app_duplicate = new Win32
|
||||||
|
{
|
||||||
|
Name = "Shop Titans",
|
||||||
|
ExecutableName = "Shop Titans.url",
|
||||||
|
FullPath = "steam://rungameid/1258080",
|
||||||
|
ParentDirectory = "C:\\Users\\temp\\Desktop",
|
||||||
|
LnkResolvedPath = null
|
||||||
|
};
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void DedupFunction_whenCalled_mustRemoveDuplicateNotepads()
|
public void DedupFunction_whenCalled_mustRemoveDuplicateNotepads()
|
||||||
{
|
{
|
||||||
@@ -141,6 +159,21 @@ namespace Wox.Test.Plugins
|
|||||||
Assert.AreEqual(apps.Length, 1);
|
Assert.AreEqual(apps.Length, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void DedupFunction_whenCalled_MustRemoveInternetShortcuts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
List<Win32> prgms = new List<Win32>();
|
||||||
|
prgms.Add(dummy_internetShortcut_app);
|
||||||
|
prgms.Add(dummy_internetShortcut_app_duplicate);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
Win32[] apps = Win32.DeduplicatePrograms(prgms.AsParallel());
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.AreEqual(apps.Length, 1);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void DedupFunction_whenCalled_mustNotRemovelnkWhichdoesNotHaveExe()
|
public void DedupFunction_whenCalled_mustNotRemovelnkWhichdoesNotHaveExe()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user