Skip to content

Commit

Permalink
Index Desktop Applications (#4422)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dsrivastavv committed Jun 22, 2020
1 parent 7312557 commit 196055e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Wox.Plugin;
using System.Windows.Input;
using System.Reflection;
using System.Text.RegularExpressions;

namespace Microsoft.Plugin.Program.Programs
{
Expand Down Expand Up @@ -240,10 +241,7 @@ public List<ContextMenuResult> ContextMenus(IPublicAPI api)
AcceleratorModifiers = (ModifierKeys.Control | ModifierKeys.Shift),
Action = _ =>
{
Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", ParentDirectory));
return true;
}
}
Expand Down Expand Up @@ -292,26 +290,24 @@ private static Win32 InternetShortcutProgram(string path)
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;
}
Expand All @@ -335,7 +331,7 @@ private static Win32 InternetShortcutProgram(string path)
Name = Path.GetFileNameWithoutExtension(path),
ExecutableName = Path.GetFileName(path),
IcoPath = iconPath,
FullPath = path.ToLower(),
FullPath = urlPath,
UniqueIdentifier = path,
ParentDirectory = Directory.GetParent(path).FullName,
Valid = true,
Expand Down Expand Up @@ -522,16 +518,17 @@ private static ParallelQuery<Win32> UnregisteredPrograms(List<Settings.ProgramSo
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)
Expand All @@ -545,6 +542,23 @@ private static ParallelQuery<Win32> StartMenuPrograms(string[] suffixes)
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
Expand Down Expand Up @@ -688,6 +702,12 @@ public static Win32[] All(Settings settings)
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class Settings

public bool EnableStartMenuSource { get; set; } = true;

public bool EnableDesktopSource { get; set; } = true;

public bool EnableRegistrySource { get; set; } = true;

internal const char SuffixSeparator = ';';
Expand Down
33 changes: 33 additions & 0 deletions src/modules/launcher/Wox.Test/Plugins/ProgramPluginTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,24 @@ public class ProgramPluginTest
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()
{
Expand All @@ -141,6 +159,21 @@ public void DedupFunction_whenCalled_mustRemoveDuplicateNotepads()
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()
{
Expand Down

0 comments on commit 196055e

Please sign in to comment.