From 9aeb8a2e4f30fb829017ded77faa0ab9fe68ef70 Mon Sep 17 00:00:00 2001 From: Taco <1141374791@qq.com> Date: Sat, 29 Jul 2023 21:02:59 +0800 Subject: [PATCH] Fix double-byte and half-width characters --- .../functions/Get-WingetOutdatedApps.ps1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 index 5a518da..59eaffa 100644 --- a/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 +++ b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 @@ -32,9 +32,9 @@ function Get-WingetOutdatedApps { $index = $lines[$fl] -split '(?<=\s)(?!\s)' # Line $fl has the header, we can find char where we find ID and Version [and manage non latin characters] - $idStart = [System.Text.Encoding]::UTF8.GetByteCount($($index[0] -replace '[\u4e00-\u9fa5]', '**')) - $versionStart = $idStart + [System.Text.Encoding]::UTF8.GetByteCount($($index[1] -replace '[\u4e00-\u9fa5]', '**')) - $availableStart = $versionStart + [System.Text.Encoding]::UTF8.GetByteCount($($index[2] -replace '[\u4e00-\u9fa5]', '**')) + $idStart = $($index[0] -replace '[\u4e00-\u9fa5]', '**').Length + $versionStart = $idStart + $($index[1] -replace '[\u4e00-\u9fa5]', '**').Length + $availableStart = $versionStart + $($index[2] -replace '[\u4e00-\u9fa5]', '**').Length # Now cycle in real package and split accordingly $upgradeList = @() @@ -48,15 +48,15 @@ function Get-WingetOutdatedApps { $index = $lines[$fl] -split '(?<=\s)(?!\s)' # Line $fl has the header, we can find char where we find ID and Version [and manage non latin characters] - $idStart = [System.Text.Encoding]::UTF8.GetByteCount($($index[0] -replace '[\u4e00-\u9fa5]', '**')) - $versionStart = $idStart + [System.Text.Encoding]::UTF8.GetByteCount($($index[1] -replace '[\u4e00-\u9fa5]', '**')) - $availableStart = $versionStart + [System.Text.Encoding]::UTF8.GetByteCount($($index[2] -replace '[\u4e00-\u9fa5]', '**')) + $idStart = $($index[0] -replace '[\u4e00-\u9fa5]', '**').Length + $versionStart = $idStart + $($index[1] -replace '[\u4e00-\u9fa5]', '**').Length + $availableStart = $versionStart + $($index[2] -replace '[\u4e00-\u9fa5]', '**').Length } #(Alphanumeric | Literal . | Alphanumeric) - the only unique thing in common for lines with applications if ($line -match "\w\.\w") { $software = [Software]::new() #Manage non latin characters - $nameDeclination = $([System.Text.Encoding]::UTF8.GetByteCount($($line.Substring(0, $idStart) -replace '[\u4e00-\u9fa5]', '**')) - $line.Substring(0, $idStart).Length) + $nameDeclination = $($line.Substring(0, $idStart) -replace '[\u4e00-\u9fa5]', '**').Length - $line.Substring(0, $idStart).Length $software.Name = $line.Substring(0, $idStart - $nameDeclination).TrimEnd() $software.Id = $line.Substring($idStart - $nameDeclination, $versionStart - $idStart).TrimEnd() $software.Version = $line.Substring($versionStart - $nameDeclination, $availableStart - $versionStart).TrimEnd()