Update disable logic and add unique identifier for programs

This commit is contained in:
Jeremy Wu
2019-09-10 07:57:03 +10:00
parent 4a6242b3a0
commit 10fb76377c
7 changed files with 94 additions and 42 deletions

View File

@@ -96,8 +96,14 @@ namespace Wox.Plugin.Program
{
lock (IndexLock)
{
var results1 = _win32s.AsParallel().Select(p => p.Result(query.Search, _context.API));
var results2 = _uwps.AsParallel().Select(p => p.Result(query.Search, _context.API));
var results1 = _win32s.AsParallel()
.Where(p => p.Enabled)
.Select(p => p.Result(query.Search, _context.API));
var results2 = _uwps.AsParallel()
.Where(p => p.Enabled)
.Select(p => p.Result(query.Search, _context.API));
var result = results1.Concat(results2).Where(r => r.Score > 0).ToList();
return result;
}
@@ -123,9 +129,9 @@ namespace Wox.Plugin.Program
lock (IndexLock)
{
var allUWPs = support ? UWP.All() : new UWP.Application[] { };
_uwps = support ? UWP.All() : new UWP.Application[] { };
_uwps = UWP.RetainApplications(allUWPs, _settings.ProgramSources, _settings.EnableProgramSourceOnly);
//_uwps = UWP.RetainApplications(allUWPs, _settings.ProgramSources, _settings.EnableProgramSourceOnly);
}
}

View File

@@ -160,7 +160,14 @@ namespace Wox.Plugin.Program.Programs
}
return u.Apps;
}).ToArray();
return applications;
var updatedListWithoutDisabledApps = applications
.Where(t1 => !Main._settings.ProgramSources
.Any(x => !x.Enabled
&& x.UniqueIdentifier == t1.UniqueIdentifier))
.Select(x => x);
return updatedListWithoutDisabledApps.ToArray();
}
else
{
@@ -202,20 +209,6 @@ namespace Wox.Plugin.Program.Programs
}
}
public static Application[] RetainApplications(Application[] applications, List<Settings.ProgramSource> applicationsToRetainPaths, bool enableProgramSourceOnly)
{
if(enableProgramSourceOnly)
return applications
.Where(t1 => applicationsToRetainPaths
.Any(x => x.Location == t1.Package.Location
&& x.Enabled))
.Select(t1 => t1).ToArray();
// Do not return if the application is disabled for indexing
return applications.Where(t1 => !applicationsToRetainPaths.Any(x => x.Location == t1.Package.Location && !x.Enabled))
.Select(t1 => t1).ToArray();
}
public override string ToString()
{
return FamilyName;
@@ -243,6 +236,7 @@ namespace Wox.Plugin.Program.Programs
public class Application : IProgram
{
public string AppListEntry { get; set; }
public string UniqueIdentifier { get; set; }
public string DisplayName { get; set; }
public string Description { get; set; }
public string UserModelId { get; set; }
@@ -337,6 +331,7 @@ namespace Wox.Plugin.Program.Programs
public Application(IAppxManifestApplication manifestApp, UWP package)
{
UserModelId = manifestApp.GetAppUserModelId();
UniqueIdentifier = manifestApp.GetAppUserModelId();
DisplayName = manifestApp.GetStringValue("DisplayName");
Description = manifestApp.GetStringValue("Description");
BackgroundColor = manifestApp.GetStringValue("BackgroundColor");

View File

@@ -18,6 +18,7 @@ namespace Wox.Plugin.Program.Programs
public class Win32 : IProgram
{
public string Name { get; set; }
public string UniqueIdentifier { get; set; }
public string IcoPath { get; set; }
public string FullPath { get; set; }
public string ParentDirectory { get; set; }
@@ -128,6 +129,7 @@ namespace Wox.Plugin.Program.Programs
Name = Path.GetFileNameWithoutExtension(path),
IcoPath = path,
FullPath = path,
UniqueIdentifier = path,
ParentDirectory = Directory.GetParent(path).FullName,
Description = string.Empty,
Valid = true,
@@ -264,18 +266,13 @@ namespace Wox.Plugin.Program.Programs
private static ParallelQuery<Win32> UnregisteredPrograms(List<Settings.ProgramSource> sources, string[] suffixes)
{
var list = new List<string>();
var listToAdd = new List<string>();
sources.Where(s => Directory.Exists(s.Location) && s.Enabled)
.SelectMany(s => ProgramPaths(s.Location, suffixes))
.ToList()
.ForEach(x => list.Add(x));
.ForEach(x => listToAdd.Add(x));
sources.Where(s => File.Exists(s.Location) && s.Enabled)
.Select(s => s.Location)
.ToList()
.ForEach(x => list.Add(x));
var paths = list.ToArray();
var paths = listToAdd.ToArray();
var programs1 = paths.AsParallel().Where(p => Extension(p) == ExeExtension).Select(ExeProgram);
var programs2 = paths.AsParallel().Where(p => Extension(p) == ShortcutExtension).Select(ExeProgram);
@@ -288,11 +285,18 @@ namespace Wox.Plugin.Program.Programs
private static ParallelQuery<Win32> StartMenuPrograms(string[] suffixes)
{
var disabledProgramsList = Main._settings.ProgramSources.Where(x => !x.Enabled).Select(x => x);
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 paths = paths1.Concat(paths2).ToArray();
var toFilter = paths1.Concat(paths2);
toFilter.Where(t1 => !disabledProgramsList.Any(x => !x.Enabled && x.UniqueIdentifier == t1)).Select(t1 => t1);
var paths = toFilter.ToArray();
var programs1 = paths.AsParallel().Where(p => Extension(p) == ShortcutExtension).Select(LnkProgram);
var programs2 = paths.AsParallel().Where(p => Extension(p) == ApplicationReferenceExtension).Select(Win32Program);
var programs = programs1.Concat(programs2).Where(p => p.Valid);
@@ -319,7 +323,12 @@ namespace Wox.Plugin.Program.Programs
programs.AddRange(ProgramsFromRegistryKey(root));
}
}
var filtered = programs.AsParallel().Where(p => suffixes.Contains(Extension(p.ExecutableName)));
var disabledProgramsList = Main._settings.ProgramSources.Where(x => !x.Enabled).Select(x => x);
var toFilter = programs.AsParallel().Where(p => suffixes.Contains(Extension(p.ExecutableName)));
var filtered = toFilter.Where(t1 => !disabledProgramsList.Any(x => !x.Enabled && x.UniqueIdentifier == t1.UniqueIdentifier)).Select(t1 => t1);
return filtered;
}
@@ -399,10 +408,6 @@ namespace Wox.Plugin.Program.Programs
var unregistered = UnregisteredPrograms(settings.ProgramSources, settings.ProgramSuffixes);
programs = programs.Concat(unregistered);
if (settings.EnableProgramSourceOnly)
return programs.ToArray();
if (settings.EnableRegistrySource)
{
var appPaths = AppPathsPrograms(settings.ProgramSuffixes);

View File

@@ -17,6 +17,13 @@ namespace Wox.Plugin.Program
internal const char SuffixSeperator = ';';
/// <summary>
/// Contains user added folder location contents as well as all user disabled applications
/// </summary>
/// <remarks>
/// <para>Win32 class applications sets UniqueIdentifier using their full path</para>
/// <para>UWP class applications sets UniqueIdentifier using their Application User Model ID</para>
/// </remarks>
public class ProgramSource
{
private string name;
@@ -24,6 +31,7 @@ namespace Wox.Plugin.Program
public string Location { get; set; }
public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; }
public bool Enabled { get; set; } = true;
public string UniqueIdentifier { get; set; }
}
}
}

View File

@@ -18,38 +18,73 @@ namespace Wox.Plugin.Program.Views.Commands
return list;
}
internal static void LoadAllApplications(this List<ProgramSource> listToUpdate)
internal static void LoadAllApplications(this List<ProgramSource> list)
{
Main._win32s
Main._win32s
.Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
.ToList()
.ForEach(t1 => ProgramSetting.ProgramSettingDisplayList.Add(new ProgramSource { Name = t1.Name, Location = t1.ParentDirectory, Enabled = t1.Enabled }));
.ForEach(t1 => ProgramSetting.ProgramSettingDisplayList
.Add(
new ProgramSource {
Name = t1.Name,
Location = t1.ParentDirectory,
UniqueIdentifier = t1.UniqueIdentifier,
Enabled = t1.Enabled
}));
Main._uwps
.Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
.ToList()
.ForEach(t1 => ProgramSetting.ProgramSettingDisplayList.Add(new ProgramSource { Name = t1.DisplayName, Location = t1.Package.Location, Enabled = t1.Enabled }));
.ForEach(t1 => ProgramSetting.ProgramSettingDisplayList
.Add(
new ProgramSource {
Name = t1.DisplayName,
Location = t1.Package.Location,
UniqueIdentifier = t1.UniqueIdentifier,
Enabled = t1.Enabled
})
);
}
internal static void DisableProgramSources(this List<ProgramSource> listToUpdate, List<ProgramSource> selectedprogramSourcesToDisable)
internal static void DisableProgramSources(this List<ProgramSource> list, List<ProgramSource> selectedprogramSourcesToDisable)
{
ProgramSetting.ProgramSettingDisplayList
.Where(t1 => selectedprogramSourcesToDisable.Any(x => x.Name == t1.Name && x.Location == t1.Location && t1.Enabled))
.Where(t1 => selectedprogramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled))
.ToList()
.ForEach(t1 => t1.Enabled = false);
Main._win32s
.Where(t1 => selectedprogramSourcesToDisable.Any(x => x.Name == t1.Name && x.Location == t1.ParentDirectory && t1.Enabled))
.Where(t1 => selectedprogramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled))
.ToList()
.ForEach(t1 => t1.Enabled = false);
Main._uwps
.Where(t1 => selectedprogramSourcesToDisable.Any(x => x.Name == t1.DisplayName && x.Location == t1.Package.Location && t1.Enabled))
.Where(t1 => selectedprogramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled))
.ToList()
.ForEach(t1 => t1.Enabled = false);
}
internal static void StoreDisabledInSettings(this List<ProgramSource> list)
{
Main._settings.ProgramSources
.Where(t1 => selectedprogramSourcesToDisable.Any(x => x.Name == t1.Name && x.Location == t1.Location && t1.Enabled))
.Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && !x.Enabled))
.ToList()
.ForEach(t1 => t1.Enabled = false);
ProgramSetting.ProgramSettingDisplayList
.Where(t1 => !t1.Enabled
&& !Main._settings.ProgramSources.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && !x.Enabled))
.ToList()
.ForEach(x => Main._settings.ProgramSources
.Add(
new Settings.ProgramSource
{
Name = x.Name,
Location = x.Location,
UniqueIdentifier = x.UniqueIdentifier,
Enabled = false
}
));
}
}
}

View File

@@ -13,6 +13,7 @@ namespace Wox.Plugin.Program.Views.Models
public string Location { get; set; }
public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; }
public string UniqueIdentifier { get; set; }
public bool Enabled { get; set; } = true;
}
}

View File

@@ -168,6 +168,8 @@ namespace Wox.Plugin.Program.Views
.SelectedItems.Cast<ProgramSource>()
.ToList());
ProgramSettingDisplayList.StoreDisabledInSettings();
programSourceView.SelectedItems.Clear();
programSourceView.Items.Refresh();