diff --git a/src/HandyWinget/Common/Helper.cs b/src/HandyWinget/Common/Helper.cs index 3056431..334d4da 100644 --- a/src/HandyWinget/Common/Helper.cs +++ b/src/HandyWinget/Common/Helper.cs @@ -1,4 +1,6 @@ using System; +using System.Text; +using System.Globalization; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; @@ -329,10 +331,16 @@ public static IEnumerable GetInstalledAppList() /// installed app line details, extracted from winget list command /// /// + 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 {