Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slow chocolatey search #321

Merged
merged 1 commit into from
Oct 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions source/UninstallTools/Factory/ChocolateyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,24 @@ public IList<ApplicationUninstallerEntry> GetUninstallerEntries(ListGenerationPr

if (!ChocoIsAvailable) return results;

var result = StartProcessAndReadOutput(ChocoFullFilename, @"list -l -nocolor -y -r");
var result = StartProcessAndReadOutput(ChocoFullFilename, @"list -lo -nocolor --detail");

if (string.IsNullOrEmpty(result)) return results;

var appEntries = result.Split(NewlineSeparators, StringSplitOptions.RemoveEmptyEntries);
var appNames = appEntries.Select(x =>
{
var i = x.IndexOf('|');
if (i <= 0) return null;
return new { name = x.Substring(0, i), version = x.Substring(i + 1) };
}).Where(x => x != null);
var re = new System.Text.RegularExpressions.Regex(@"\n\w");
var match = re.Match(result);
if (!match.Success) return results;
var begin = match.Index + 1;

foreach (var appName in appNames)
while(true)
{
var info = StartProcessAndReadOutput(ChocoFullFilename, "info -l -nocolor -y -v " + appName.name);
match = match.NextMatch();
if (!match.Success) break;
var end = match.Index + 1;
var info = result.Substring(begin, end-begin);
int i = info.IndexOf(' '), j = info.IndexOf("\r\n");
var appName = new { name = info.Substring(0, i), version = info.Substring(i+1, j-i-1) };

var kvps = ExtractPackageInformation(info);
if (kvps.Count == 0) continue;

Expand Down Expand Up @@ -122,6 +125,7 @@ public IList<ApplicationUninstallerEntry> GetUninstallerEntries(ListGenerationPr
entry.AdditionalJunk.Add(junk);

results.Add(entry);
begin = end;
}

return results;
Expand Down