Skip to content
Open
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
12 changes: 10 additions & 2 deletions src/HandyWinget/Common/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Text;
using System.Globalization;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
Expand Down Expand Up @@ -329,10 +331,16 @@ public static IEnumerable<string> GetInstalledAppList()
/// <param name="line">installed app line details, extracted from winget list command</param>
/// <param name="packageId"></param>
/// <returns></returns>
private static Regex re = new Regex("[ ]{2,}", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public static (string packageId, string version, string availableVersion) ParseInstalledApp(string line, string packageId)
{
line = Regex.Replace(line, "[ ]{2,}", " ", RegexOptions.IgnoreCase); // remove more than 2 spaces
line = Regex.Replace(line, $@".*(?=({Regex.Escape(packageId)}))", "", RegexOptions.IgnoreCase); // remove everythings before package id
line = re.Replace(line, " ");
int startIndex = line.IndexOf(packageId);
if(startIndex < 0)
{
return (packageId: null, version: null, availableVersion: null);
}
line = line.Substring(startIndex);
var lines = line.Split(" ");
if (lines.Count() >= 3) // available version exist
{
Expand Down