From 38946d6d496faa22d4b7b8d49aec0152fe845d21 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Thu, 16 Mar 2023 00:04:24 +0100 Subject: [PATCH 1/5] More scenarios in winget output fixed --- .../functions/Get-WingetOutdatedApps.ps1 | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 index 53cc0a7..41524ea 100644 --- a/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 +++ b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 @@ -17,7 +17,7 @@ function Get-WingetOutdatedApps { } #Split winget output to lines - $lines = $upgradeResult.Split([Environment]::NewLine) | Where-Object { $_ -and $_ -notmatch "--include-unknown" } + $lines = $upgradeResult.Split([Environment]::NewLine) | Where-Object { $_ -and ($_ -notmatch "--include-unknown") -and ($_ -notmatch "update the source:") -and ($_ -notmatch "require explicit targeting") -and ($_ -notmatch "^(\d*)\s+(upgrade\w*)\s+(available\.)$") } # Find the line that starts with "------" $fl = 0 @@ -38,9 +38,16 @@ function Get-WingetOutdatedApps { # Now cycle in real package and split accordingly $upgradeList = @() - For ($i = $fl + 2; $i -lt $lines.Length - 1; $i++) { + For ($i = $fl + 2; $i -lt $lines.Length; $i++) { $line = $lines[$i] - if ($line) { + if ($line -and $line -match "^(Name)\s+(Id)\s+(Version)\s+(Available)$") { + #Get header titles + $index = $lines[$fl] -split '\s+' + $idStart = $lines[$i].IndexOf($index[1]) + $versionStart = $lines[$i].IndexOf($index[2]) + $availableStart = $lines[$i].IndexOf($index[3]) + } + if ($line -and ($line -notmatch "^(Name)\s+(Id)\s+(Version)\s+(Available)$") -and (-not $line.StartsWith("-----"))) { $software = [Software]::new() $software.Name = $line.Substring(0, $idStart).TrimEnd() $software.Id = $line.Substring($idStart, $versionStart - $idStart).TrimEnd() From 24aa53184d17739163b4a575bc4857063edec17f Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Thu, 16 Mar 2023 00:21:57 +0100 Subject: [PATCH 2/5] Forgon an $i --- Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 index 41524ea..04104b3 100644 --- a/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 +++ b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 @@ -42,7 +42,7 @@ function Get-WingetOutdatedApps { $line = $lines[$i] if ($line -and $line -match "^(Name)\s+(Id)\s+(Version)\s+(Available)$") { #Get header titles - $index = $lines[$fl] -split '\s+' + $index = $lines[$i] -split '\s+' $idStart = $lines[$i].IndexOf($index[1]) $versionStart = $lines[$i].IndexOf($index[2]) $availableStart = $lines[$i].IndexOf($index[3]) From 1fcd0dccb4ee54a28fb3b280da560f7c77e737f1 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 17 Mar 2023 20:57:08 +0100 Subject: [PATCH 3/5] Language independent --- .../functions/Get-WingetOutdatedApps.ps1 | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 index 04104b3..7fff94c 100644 --- a/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 +++ b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 @@ -17,7 +17,7 @@ function Get-WingetOutdatedApps { } #Split winget output to lines - $lines = $upgradeResult.Split([Environment]::NewLine) | Where-Object { $_ -and ($_ -notmatch "--include-unknown") -and ($_ -notmatch "update the source:") -and ($_ -notmatch "require explicit targeting") -and ($_ -notmatch "^(\d*)\s+(upgrade\w*)\s+(available\.)$") } + $lines = $upgradeResult.Split([Environment]::NewLine) | Where-Object { $_ } # Find the line that starts with "------" $fl = 0 @@ -40,14 +40,20 @@ function Get-WingetOutdatedApps { $upgradeList = @() For ($i = $fl + 2; $i -lt $lines.Length; $i++) { $line = $lines[$i] - if ($line -and $line -match "^(Name)\s+(Id)\s+(Version)\s+(Available)$") { + if ($line -and $line.StartsWith("-----")) { + #Get header line + $fl = $i - 1 + #Get header titles - $index = $lines[$i] -split '\s+' - $idStart = $lines[$i].IndexOf($index[1]) - $versionStart = $lines[$i].IndexOf($index[2]) - $availableStart = $lines[$i].IndexOf($index[3]) - } - if ($line -and ($line -notmatch "^(Name)\s+(Id)\s+(Version)\s+(Available)$") -and (-not $line.StartsWith("-----"))) { + $index = $lines[$fl] -split '\s+' + + # Line $fl has the header, we can find char where we find ID and Version + $idStart = $lines[$fl].IndexOf($index[1]) + $versionStart = $lines[$fl].IndexOf($index[2]) + $availableStart = $lines[$fl].IndexOf($index[3]) + } + #(Alphanumeric Literal . Alphanumeric) - the only thing in common for lines with applications + if ($line -and ($line -match "\w\.\w")) { $software = [Software]::new() $software.Name = $line.Substring(0, $idStart).TrimEnd() $software.Id = $line.Substring($idStart, $versionStart - $idStart).TrimEnd() From 9c7943d26d0a7575992ba78bf759670dae51b203 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 18 Mar 2023 10:30:04 +0100 Subject: [PATCH 4/5] unique description --- Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 index 7fff94c..b06cb59 100644 --- a/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 +++ b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 @@ -52,7 +52,7 @@ function Get-WingetOutdatedApps { $versionStart = $lines[$fl].IndexOf($index[2]) $availableStart = $lines[$fl].IndexOf($index[3]) } - #(Alphanumeric Literal . Alphanumeric) - the only thing in common for lines with applications + #(Alphanumeric | Literal . | Alphanumeric) - the only unique thing in common for lines with applications if ($line -and ($line -match "\w\.\w")) { $software = [Software]::new() $software.Name = $line.Substring(0, $idStart).TrimEnd() From f9e786f7038e7f21fd276e110b17d26ba819e4a5 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 19 Mar 2023 10:44:52 +0100 Subject: [PATCH 5/5] Final --- Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 index b06cb59..d0e861b 100644 --- a/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 +++ b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 @@ -40,7 +40,7 @@ function Get-WingetOutdatedApps { $upgradeList = @() For ($i = $fl + 2; $i -lt $lines.Length; $i++) { $line = $lines[$i] - if ($line -and $line.StartsWith("-----")) { + if ($line.StartsWith("-----")) { #Get header line $fl = $i - 1 @@ -53,7 +53,7 @@ function Get-WingetOutdatedApps { $availableStart = $lines[$fl].IndexOf($index[3]) } #(Alphanumeric | Literal . | Alphanumeric) - the only unique thing in common for lines with applications - if ($line -and ($line -match "\w\.\w")) { + if ($line -match "\w\.\w") { $software = [Software]::new() $software.Name = $line.Substring(0, $idStart).TrimEnd() $software.Id = $line.Substring($idStart, $versionStart - $idStart).TrimEnd()