From 86c894eb35e88b091d6b99a5a194009b25fa7ce5 Mon Sep 17 00:00:00 2001 From: Taco <1141374791@qq.com> Date: Tue, 25 Jul 2023 14:08:58 +0800 Subject: [PATCH] Handle Chinese characters in apps' names --- Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 index 9a463b1..de966d1 100644 --- a/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 +++ b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 @@ -55,10 +55,12 @@ function Get-WingetOutdatedApps { #(Alphanumeric | Literal . | Alphanumeric) - the only unique thing in common for lines with applications if ($line -match "\w\.\w") { $software = [Software]::new() - $software.Name = $line.Substring(0, $idStart).TrimEnd() - $software.Id = $line.Substring($idStart, $versionStart - $idStart).TrimEnd() - $software.Version = $line.Substring($versionStart, $availableStart - $versionStart).TrimEnd() - $software.AvailableVersion = $line.Substring($availableStart).TrimEnd() + #Manage non latin characters + $nameDeclination = $([System.Text.Encoding]::UTF8.GetByteCount($($line.Substring(0, $idStart) -replace '[\u4e00-\u9fa5]', '**')) - $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() + $software.AvailableVersion = $line.Substring($availableStart - $nameDeclination).TrimEnd() #add formated soft to list $upgradeList += $software }