Deduping results for program plugin (#2375)

* Removing description from title

* adjusting subtitle

* removing accidently paste

* removing desc for uwp apps

* Getting dups removed from list if LNK exists

* adjusting subtitle

* removing accidently paste

* Getting dups removed from list if LNK exists

* changed to normal forloop
This commit is contained in:
Clint Rutkas 2020-04-24 09:35:21 -07:00 committed by GitHub
parent 8a2fd5bf5e
commit 08a7394c1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 9 deletions

View File

@ -282,7 +282,7 @@ namespace Wox.Plugin.Program.Programs
var result = new Result var result = new Result
{ {
SubTitle = "UWP Application", SubTitle = "UWP application",
Icon = Logo, Icon = Logo,
Score = score, Score = score,
ContextData = this, ContextData = this,

View File

@ -53,7 +53,7 @@ namespace Wox.Plugin.Program.Programs
var result = new Result var result = new Result
{ {
SubTitle = "Win32 Application", SubTitle = "Win32 application",
IcoPath = IcoPath, IcoPath = IcoPath,
Score = score, Score = score,
ContextData = this, ContextData = this,
@ -148,8 +148,9 @@ namespace Wox.Plugin.Program.Programs
var p = new Win32 var p = new Win32
{ {
Name = Path.GetFileNameWithoutExtension(path), Name = Path.GetFileNameWithoutExtension(path),
ExecutableName = Path.GetFileName(path),
IcoPath = path, IcoPath = path,
FullPath = path, FullPath = path.ToLower(),
UniqueIdentifier = path, UniqueIdentifier = path,
ParentDirectory = Directory.GetParent(path).FullName, ParentDirectory = Directory.GetParent(path).FullName,
Description = string.Empty, Description = string.Empty,
@ -191,7 +192,8 @@ namespace Wox.Plugin.Program.Programs
if (extension == ExeExtension && File.Exists(target)) if (extension == ExeExtension && File.Exists(target))
{ {
program.LnkResolvedPath = program.FullPath; program.LnkResolvedPath = program.FullPath;
program.FullPath = target; program.FullPath = Path.GetFullPath(target).ToLower();
program.ExecutableName = Path.GetFileName(target);
buffer = new StringBuilder(MAX_PATH); buffer = new StringBuilder(MAX_PATH);
link.GetDescription(buffer, MAX_PATH); link.GetDescription(buffer, MAX_PATH);
@ -239,10 +241,12 @@ namespace Wox.Plugin.Program.Programs
{ {
var program = Win32Program(path); var program = Win32Program(path);
var info = FileVersionInfo.GetVersionInfo(path); var info = FileVersionInfo.GetVersionInfo(path);
if (!string.IsNullOrEmpty(info.FileDescription)) if (!string.IsNullOrEmpty(info.FileDescription))
{ {
program.Description = info.FileDescription; program.Description = info.FileDescription;
} }
return program; return program;
} }
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException) catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
@ -257,10 +261,14 @@ namespace Wox.Plugin.Program.Programs
private static IEnumerable<string> ProgramPaths(string directory, string[] suffixes) private static IEnumerable<string> ProgramPaths(string directory, string[] suffixes)
{ {
if (!Directory.Exists(directory)) if (!Directory.Exists(directory))
{
return new string[] { }; return new string[] { };
}
var files = new List<string>(); var files = new List<string>();
var folderQueue = new Queue<string>(); var folderQueue = new Queue<string>();
folderQueue.Enqueue(directory); folderQueue.Enqueue(directory);
do do
{ {
var currentDirectory = folderQueue.Dequeue(); var currentDirectory = folderQueue.Dequeue();
@ -298,12 +306,14 @@ namespace Wox.Plugin.Program.Programs
$"|Permission denied when trying to load programs from {currentDirectory}", e); $"|Permission denied when trying to load programs from {currentDirectory}", e);
} }
} while (folderQueue.Any()); } while (folderQueue.Any());
return files; return files;
} }
private static string Extension(string path) private static string Extension(string path)
{ {
var extension = Path.GetExtension(path)?.ToLower(); var extension = Path.GetExtension(path)?.ToLower();
if (!string.IsNullOrEmpty(extension)) if (!string.IsNullOrEmpty(extension))
{ {
return extension.Substring(1); return extension.Substring(1);
@ -353,11 +363,8 @@ namespace Wox.Plugin.Program.Programs
var programs1 = paths.AsParallel().Where(p => Extension(p) == ShortcutExtension).Select(LnkProgram); var programs1 = paths.AsParallel().Where(p => Extension(p) == ShortcutExtension).Select(LnkProgram);
var programs2 = paths.AsParallel().Where(p => Extension(p) == ApplicationReferenceExtension).Select(Win32Program); var programs2 = paths.AsParallel().Where(p => Extension(p) == ApplicationReferenceExtension).Select(Win32Program);
var allValidPrograms = programs1.Concat(programs2).Where(p => p.Valid);
//var programsWithLnk = allValidPrograms.Where(x => !string.IsNullOrEmpty(x.LnkResolvedPath));
return allValidPrograms; return programs1.Concat(programs2).Where(p => p.Valid);
} }
private static ParallelQuery<Win32> AppPathsPrograms(string[] suffixes) private static ParallelQuery<Win32> AppPathsPrograms(string[] suffixes)
@ -450,6 +457,7 @@ namespace Wox.Plugin.Program.Programs
var unregistered = UnregisteredPrograms(settings.ProgramSources, settings.ProgramSuffixes); var unregistered = UnregisteredPrograms(settings.ProgramSources, settings.ProgramSuffixes);
programs = programs.Concat(unregistered); programs = programs.Concat(unregistered);
if (settings.EnableRegistrySource) if (settings.EnableRegistrySource)
{ {
var appPaths = AppPathsPrograms(settings.ProgramSuffixes); var appPaths = AppPathsPrograms(settings.ProgramSuffixes);
@ -462,7 +470,15 @@ namespace Wox.Plugin.Program.Programs
programs = programs.Concat(startMenu); programs = programs.Concat(startMenu);
} }
return programs.ToArray(); var programsWithoutLnk = programs.Where(x => string.IsNullOrEmpty(x.LnkResolvedPath));
var programsAsList = programs.ToList();
foreach(var app in programsWithoutLnk)
{
programsAsList.RemoveAll(x => (x.FullPath == app.FullPath) && string.IsNullOrEmpty(x.LnkResolvedPath));
}
return programsAsList.ToArray();
} }
#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.
catch (Exception e) catch (Exception e)