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:
Divyansh Srivastava
2020-06-22 12:34:57 -07:00
committed by GitHub
parent 73125574e6
commit 196055e50e
3 changed files with 75 additions and 20 deletions

View File

@@ -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<Win32> StartMenuPrograms(string[] suffixes)
private static ParallelQuery<Win32> IndexPath(string[] suffixes, List<string> 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<string> toFilter = new List<string>();
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<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)
{
// 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.

View File

@@ -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 = ';';

View File

@@ -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<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]
public void DedupFunction_whenCalled_mustNotRemovelnkWhichdoesNotHaveExe()
{