Winget-AutoUpdate icon indicating copy to clipboard operation
Winget-AutoUpdate copied to clipboard

[Bug] Chinese softwares have not been updated

Open lilianxiong opened this issue 2 years ago • 2 comments

I modified the function myself.

Now it works fine for Chinese software, is there a better solution to make it adapt to global languages.

"C:\ProgramData\Winget-AutoUpdate\functions\Get-WingetOutdatedApps.ps1"

#Function to get outdated app list, in formatted array

function Get-WingetOutdatedApps {
    class Software {
        [string]$Name
        [string]$Id
        [string]$Version
        [string]$AvailableVersion
    }

    #Get list of available upgrades on winget format
    Write-Log "Checking application updates on Winget Repository..." "yellow"
    $prev = [Console]::OutputEncoding
    [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()
    $upgradeResult = & $Winget upgrade | Out-String
    [Console]::OutputEncoding = $prev

    #Start Convertion of winget format to an array. Check if "-----" exists
    if (!($upgradeResult -match "-----")) {
        return
    }

    #Split winget output to lines
    $lines = $upgradeResult.Split([Environment]::NewLine) | Where-Object { $_ }

    # Find the line that starts with "------"
    $fl = 0
    while (-not $lines[$fl].StartsWith("-----")) {
        $fl++
    }
    
    #Get header line 
    $fl = $fl - 1

    #Get header titles
    $index = $lines[$fl] -split '\s+'

    # Line $fl has the header, we can find char where we find ID and Version
    $indexLength = @()
    $indexLength += [System.Text.Encoding]::UTF8.GetByteCount($($index[0] -replace '[\u4e00-\u9fa5]', '**'))
    $indexLength += [System.Text.Encoding]::UTF8.GetByteCount($($index[1] -replace '[\u4e00-\u9fa5]', '**'))
    $indexLength += [System.Text.Encoding]::UTF8.GetByteCount($($index[2] -replace '[\u4e00-\u9fa5]', '**'))
    $indexLength += [System.Text.Encoding]::UTF8.GetByteCount($($index[3] -replace '[\u4e00-\u9fa5]', '**'))
    $indexLength += [System.Text.Encoding]::UTF8.GetByteCount($($index[4] -replace '[\u4e00-\u9fa5]', '**'))
    $indexDeclination = @()
    $indexDeclination += $($indexLength[0] - $index[0].Length)
    $indexDeclination += $($indexLength[1] - $index[1].Length + $indexDeclination[0])
    $indexDeclination += $($indexLength[2] - $index[2].Length + $indexDeclination[1])
    $indexDeclination += $($indexLength[3] - $index[3].Length + $indexDeclination[2])
    $idStart        = $lines[$fl].IndexOf($index[1]) + $indexDeclination[0]
    $versionStart   = $lines[$fl].IndexOf($index[2]) + $indexDeclination[1]
    $availableStart = $lines[$fl].IndexOf($index[3]) + $indexDeclination[2]
    $sourceStart    = $lines[$fl].IndexOf($index[4]) + $indexDeclination[3]

    # Now cycle in real package and split accordingly
    $upgradeList = @()
    For ($i = $fl + 2; $i -le $lines.Length; $i++) {
        $line = $lines[$i]
        if ([System.Text.Encoding]::UTF8.GetByteCount($($line -replace '[\u4e00-\u9fa5]', '**')) -gt ($sourceStart + 5) -and -not $line.Contains("--include-unknown")) {
            $software = [Software]::new()
            $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 - $nameDeclination).TrimEnd()
            $software.Version = $line.Substring($versionStart - $nameDeclination, $availableStart - $versionStart - $nameDeclination).TrimEnd()
            $software.AvailableVersion = $line.Substring($availableStart - $nameDeclination, $sourceStart - $availableStart - $nameDeclination).TrimEnd()
            #add formated soft to list
            $upgradeList += $software
        }
    }

    return $upgradeList
}
log

##################################################

CHECK FOR APP UPDATES - 2022/7/2

################################################## 14:10:02 - Notification Level: Full. Notification Language: English 14:10:02 - Checking internet connection... 14:10:02 - Connected ! 14:10:06 - Winget Version: v1.3.0-preview 14:10:06 - WAU current version: 1.11.5 14:10:06 - WAU AutoUpdate is Enabled. 14:10:07 - WAU is up to date. 14:10:07 - WAU uses Black List config 14:10:07 - Checking application updates on Winget Repository... -> Available update : Honeyview. Current version : 5.45. Available version : 5.46. -> Available update : Microsoft Edge WebView2 Runtime. Current version : 103.0.1264.37. Available version : 103.0.1264.44. -> Available update : 腾讯会议. Current version : 3.8.6.428. Available version : 3.9.4.403. -> Available update : 腾讯QQ. Current version : 9.6.1.28732. Available version : 9.6.2.28755. -> Available update : Adobe Acrobat DC (64-bit). Current version : 22.001.20085. Available version : 22.001.20117. 14:10:09 - Honeyview : Skipped upgrade because it is in the excluded app list 14:10:09 - Microsoft Edge WebView2 Runtime : Skipped upgrade because it is in the excluded app list 14:10:09 - Updating 腾讯会议 from 3.8.6.428 to 3.9.4.403... 14:10:13 - ########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID 'Tencent.TencentMeeting' ########## -\|/

███▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 1024 KB / 7.87 MB ███████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 2.00 MB / 7.87 MB ███████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 3.00 MB / 7.87 MB ███████████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 4.00 MB / 7.87 MB ███████████████████▒▒▒▒▒▒▒▒▒▒▒ 5.00 MB / 7.87 MB ██████████████████████▒▒▒▒▒▒▒▒ 6.00 MB / 7.87 MB ██████████████████████████▒▒▒▒ 7.00 MB / 7.87 MB ██████████████████████████████ 7.87 MB / 7.87 MB

Name Id Version Available Source

腾讯会议 Tencent.TencentMeeting 3.8.6.428 3.9.4.403 winget 1 upgrades available.

(1/1) Found 腾讯会议 [Tencent.TencentMeeting] Version 3.9.4.403 This application is licensed to you by its owner. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages. Downloading https://updatecdn.meeting.qq.com/cos/792d4d48f1ada6bc002f842833d4a957/TencentMeeting_0300000000_3.9.4.403.publish.exe -\|/-\|/-\|/-

█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 6.00 MB / 148 MB ██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 13.0 MB / 148 MB ████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 21.0 MB / 148 MB █████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 29.0 MB / 148 MB ███████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 37.0 MB / 148 MB ████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 44.0 MB / 148 MB █████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 49.0 MB / 148 MB ███████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 55.0 MB / 148 MB ████████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 62.0 MB / 148 MB █████████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 68.0 MB / 148 MB ███████████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 75.0 MB / 148 MB ████████████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 80.0 MB / 148 MB █████████████████▒▒▒▒▒▒▒▒▒▒▒▒▒ 87.0 MB / 148 MB ███████████████████▒▒▒▒▒▒▒▒▒▒▒ 94.0 MB / 148 MB ████████████████████▒▒▒▒▒▒▒▒▒▒ 100 MB / 148 MB █████████████████████▒▒▒▒▒▒▒▒▒ 107 MB / 148 MB ██████████████████████▒▒▒▒▒▒▒▒ 113 MB / 148 MB ████████████████████████▒▒▒▒▒▒ 120 MB / 148 MB █████████████████████████▒▒▒▒▒ 127 MB / 148 MB ██████████████████████████▒▒▒▒ 133 MB / 148 MB ████████████████████████████▒▒ 140 MB / 148 MB █████████████████████████████▒ 146 MB / 148 MB ██████████████████████████████ 148 MB / 148 MB Successfully verified installer hash Starting package install... -\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\ Successfully installed

14:11:08 - Checking application updates on Winget Repository... 14:11:09 - ########## WINGET UPGRADE PROCESS FINISHED FOR APPLICATION ID 'Tencent.TencentMeeting' ########## 14:11:09 - 腾讯会议 updated to 3.9.4.403 !

lilianxiong avatar Jul 02 '22 06:07 lilianxiong

Hello. Thanks for your contribution. feel free to propose a pull request to get credited :)

by the way, I was thinking to do a $upgradeResult = & $Winget upgrade --source Winget | Out-String and this way we can save a column in the display (and remove the $sourceStart things)

from this:
image

to this:
image

so function would become shorter. Here was my first working draft (and your extra work need to be added):

function Get-WingetOutdatedApps {
    class Software {
        [string]$Name
        [string]$Id
        [string]$Version
        [string]$AvailableVersion
    }

    #Get list of available upgrades on winget format
    Write-Log "Checking application updates on Winget Repository..." "yellow"
    $upgradeResult = & $Winget upgrade --source winget | Out-String

    #Start Convertion of winget format to an array. Check if "-----" exists
    if (!($upgradeResult -match "-----")) {
        return
    }

    #Split winget output to lines
    $lines = $upgradeResult.Split([Environment]::NewLine) | Where-Object { $_ }

    # Find the line that starts with "------"
    $fl = 0
    while (-not $lines[$fl].StartsWith("-----")) {
        $fl++
    }
    
    #Get header line 
    $fl = $fl - 1

    #Get header titles
    $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])

    # Now cycle in real package and split accordingly
    $upgradeList = @()
    For ($i = $fl + 2; $i -lt $lines.Length -1; $i++) {
        $line = $lines[$i]
        if ($line) {
            $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()
            #add formated soft to list
            $upgradeList += $software
        }
    }

    return $upgradeList
}

Romanitho avatar Jul 04 '22 23:07 Romanitho

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Aug 05 '22 03:08 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Aug 19 '22 03:08 github-actions[bot]