diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/Win32.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/Win32.cs index a7651c2a09..bfbc1438cd 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/Win32.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/Win32.cs @@ -13,6 +13,7 @@ using Microsoft.Plugin.Program.Logger; using Wox.Plugin; using System.Windows.Input; using System.Reflection; +using System.Text.RegularExpressions; namespace Microsoft.Plugin.Program.Programs { @@ -240,10 +241,7 @@ namespace Microsoft.Plugin.Program.Programs AcceleratorModifiers = (ModifierKeys.Control | ModifierKeys.Shift), Action = _ => { - - Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", ParentDirectory)); - return true; } } @@ -292,26 +290,24 @@ namespace Microsoft.Plugin.Program.Programs string[] lines = System.IO.File.ReadAllLines(path); string appName = string.Empty; string iconPath = string.Empty; + string urlPath = string.Empty; string scheme = string.Empty; bool validApp = false; - const string steamScheme = "steam"; + Regex InternetShortcutURLPrefixes = new Regex(@"^steam:\/\/(rungameid|run)\/|^com\.epicgames\.launcher:\/\/apps\/"); + const string urlPrefix = "URL="; const string iconFilePrefix = "IconFile="; - const string hostnameRun = "run"; - const string hostnameRunGameId = "rungameid"; foreach(string line in lines) { if(line.StartsWith(urlPrefix)) { - var urlPath = line.Substring(urlPrefix.Length); + urlPath = line.Substring(urlPrefix.Length); Uri uri = new Uri(urlPath); // To filter out only those steam shortcuts which have 'run' or 'rungameid' as the hostname - if(uri.Scheme.Equals(steamScheme, StringComparison.OrdinalIgnoreCase) - && (uri.Host.Equals(hostnameRun, StringComparison.OrdinalIgnoreCase) - || uri.Host.Equals(hostnameRunGameId, StringComparison.OrdinalIgnoreCase))) + if(InternetShortcutURLPrefixes.Match(urlPath).Success) { validApp = true; } @@ -335,7 +331,7 @@ namespace Microsoft.Plugin.Program.Programs Name = Path.GetFileNameWithoutExtension(path), ExecutableName = Path.GetFileName(path), IcoPath = iconPath, - FullPath = path.ToLower(), + FullPath = urlPath, UniqueIdentifier = path, ParentDirectory = Directory.GetParent(path).FullName, Valid = true, @@ -522,16 +518,17 @@ namespace Microsoft.Plugin.Program.Programs return programs1.Concat(programs2).Concat(programs3); } - private static ParallelQuery StartMenuPrograms(string[] suffixes) + private static ParallelQuery IndexPath(string[] suffixes, List IndexLocation) { - var disabledProgramsList = Main._settings.DisabledProgramSources; - - var directory1 = Environment.GetFolderPath(Environment.SpecialFolder.Programs); - var directory2 = Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms); - var paths1 = ProgramPaths(directory1, suffixes); - var paths2 = ProgramPaths(directory2, suffixes); - - var toFilter = paths1.Concat(paths2); + var disabledProgramsList = Main._settings.DisabledProgramSources; + + IEnumerable toFilter = new List(); + foreach (string location in IndexLocation) + { + var _paths = ProgramPaths(location, suffixes); + toFilter = toFilter.Concat(_paths); + } + var paths = toFilter .Where(t1 => !disabledProgramsList.Any(x => x.UniqueIdentifier == 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); } + private static ParallelQuery StartMenuPrograms(string[] suffixes) + { + var directory1 = Environment.GetFolderPath(Environment.SpecialFolder.Programs); + var directory2 = Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms); + List IndexLocation = new List() { directory1, directory2}; + + return IndexPath(suffixes, IndexLocation); + } + + private static ParallelQuery DesktopPrograms(string[] suffixes) + { + var directory1 = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + List IndexLocation = new List() { directory1 }; + + return IndexPath(suffixes, IndexLocation); + } + private static ParallelQuery AppPathsPrograms(string[] suffixes) { // https://msdn.microsoft.com/en-us/library/windows/desktop/ee872121 @@ -688,6 +702,12 @@ namespace Microsoft.Plugin.Program.Programs programs = programs.Concat(startMenu); } + if (settings.EnableDesktopSource) + { + var desktop = DesktopPrograms(settings.ProgramSuffixes); + programs = programs.Concat(desktop); + } + return DeduplicatePrograms(programs); } #if DEBUG //This is to make developer aware of any unhandled exception and add in handling. diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Settings.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Settings.cs index b49b7c7773..79b9a9d32a 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Settings.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Settings.cs @@ -13,6 +13,8 @@ namespace Microsoft.Plugin.Program public bool EnableStartMenuSource { get; set; } = true; + public bool EnableDesktopSource { get; set; } = true; + public bool EnableRegistrySource { get; set; } = true; internal const char SuffixSeparator = ';'; diff --git a/src/modules/launcher/Wox.Test/Plugins/ProgramPluginTest.cs b/src/modules/launcher/Wox.Test/Plugins/ProgramPluginTest.cs index abf45b7888..9cdec9566e 100644 --- a/src/modules/launcher/Wox.Test/Plugins/ProgramPluginTest.cs +++ b/src/modules/launcher/Wox.Test/Plugins/ProgramPluginTest.cs @@ -126,6 +126,24 @@ namespace Wox.Test.Plugins 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] public void DedupFunction_whenCalled_mustRemoveDuplicateNotepads() { @@ -141,6 +159,21 @@ namespace Wox.Test.Plugins Assert.AreEqual(apps.Length, 1); } + [Test] + public void DedupFunction_whenCalled_MustRemoveInternetShortcuts() + { + // Arrange + List prgms = new List(); + 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] public void DedupFunction_whenCalled_mustNotRemovelnkWhichdoesNotHaveExe() {