Merge pull request #688 from Romanitho/fix

Fixes and minor changes
pull/689/head
Romain 2024-09-04 16:12:47 +02:00 committed by GitHub
commit 92f679eb93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 68 additions and 62 deletions

View File

@ -28,13 +28,14 @@ if ( $psversionTable.PSEdition -eq "core" ) {
import-Module -name Appx -UseWIndowsPowershell -WarningAction:SilentlyContinue import-Module -name Appx -UseWIndowsPowershell -WarningAction:SilentlyContinue
} }
$Script:WAUConfiguratorVersion = Get-Content ".\Winget-AutoUpdate\Version.txt" $Script:WorkingDir = (Get-Location).Path
$Script:WAUConfiguratorVersion = Get-Content "$WorkingDir\Winget-AutoUpdate\Version.txt"
<# FUNCTIONS #> <# FUNCTIONS #>
. ".\Winget-AutoUpdate\functions\Update-WinGet.ps1" . "$WorkingDir\Winget-AutoUpdate\functions\Update-WinGet.ps1"
. ".\Winget-AutoUpdate\functions\Get-WingetCmd.ps1" . "$WorkingDir\Winget-AutoUpdate\functions\Get-WingetCmd.ps1"
#Function to start or update popup #Function to start or update popup
Function Start-PopUp ($Message) { Function Start-PopUp ($Message) {
@ -183,12 +184,12 @@ function Start-Installations {
if ($WAUUseWhiteList) { if ($WAUUseWhiteList) {
$WAUParameters += "-UseWhiteList " $WAUParameters += "-UseWhiteList "
if ($WAUListPath) { if ($WAUListPath) {
Copy-Item $WAUListPath -Destination ".\included_apps.txt" -Force -ErrorAction SilentlyContinue Copy-Item $WAUListPath -Destination "$WorkingDir\included_apps.txt" -Force -ErrorAction SilentlyContinue
} }
} }
else { else {
if ($WAUListPath) { if ($WAUListPath) {
Copy-Item $WAUListPath -Destination ".\excluded_apps.txt" -Force -ErrorAction SilentlyContinue Copy-Item $WAUListPath -Destination "$WorkingDir\excluded_apps.txt" -Force -ErrorAction SilentlyContinue
} }
} }
if ($WAUDesktopShortcut) { if ($WAUDesktopShortcut) {
@ -202,7 +203,7 @@ function Start-Installations {
} }
#Install Winget-Autoupdate #Install Winget-Autoupdate
Start-Process "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -Command ""& '.\Winget-AutoUpdate-Install.ps1' $WAUParameters""" -Wait -Verb RunAs Start-Process "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -Command ""& '$WorkingDir\Winget-AutoUpdate-Install.ps1' $WAUParameters""" -Wait -Verb RunAs
} }
@ -275,7 +276,7 @@ function Start-Uninstallations ($AppToUninstall) {
#Run Winget-Install -Uninstall #Run Winget-Install -Uninstall
$AppsToUninstall = "'$($AppToUninstall -join "','")'" $AppsToUninstall = "'$($AppToUninstall -join "','")'"
Start-Process "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -Command `".\Winget-AutoUpdate\Winget-Install.ps1 -AppIDs $AppsToUninstall -Uninstall`"" -Wait -Verb RunAs Start-Process "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -Command `"$WorkingDir\Winget-AutoUpdate\Winget-Install.ps1 -AppIDs $AppsToUninstall -Uninstall`"" -Wait -Verb RunAs
Close-PopUp Close-PopUp
} }

View File

@ -299,9 +299,8 @@ if (Test-Network) {
if ($outdated -like "No update found.*") { if ($outdated -like "No update found.*") {
Write-ToLog "$outdated" "cyan" Write-ToLog "$outdated" "cyan"
} }
#Run only if $outdated is populated! #Run only if $outdated is populated!
if ($outdated) { else {
#Log list of app to update #Log list of app to update
foreach ($app in $outdated) { foreach ($app in $outdated) {
#List available updates #List available updates

View File

@ -13,64 +13,70 @@ function Get-WingetOutdatedApps {
#Start Conversion of winget format to an array. Check if "-----" exists (Winget Error Handling) #Start Conversion of winget format to an array. Check if "-----" exists (Winget Error Handling)
if (!($upgradeResult -match "-----")) { if (!($upgradeResult -match "-----")) {
return "No update found. Winget upgrade output:`n$upgradeResult"
return "No update found. 'Winget upgrade' output:`n$upgradeResult"
} }
else {
#Split winget output to lines #Split winget output to lines
$lines = $upgradeResult.Split([Environment]::NewLine) | Where-Object { $_ } $lines = $upgradeResult.Split([Environment]::NewLine) | Where-Object { $_ }
# Find the line that starts with "------" # Find the line that starts with "------"
$fl = 0 $fl = 0
while (-not $lines[$fl].StartsWith("-----")) { while (-not $lines[$fl].StartsWith("-----")) {
$fl++ $fl++
}
#Get header line
$fl = $fl - 1
#Get header titles [without remove separator]
$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 = $($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 = @()
For ($i = $fl + 2; $i -lt $lines.Length; $i++) {
$line = $lines[$i] -replace "[\u2026]", " " #Fix "..." in long names
if ($line.StartsWith("-----")) {
#Get header line
$fl = $i - 1
#Get header titles [without remove separator]
$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 = $($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") { #Get header line
$software = [Software]::new() $fl = $fl - 1
#Manage non latin characters
$nameDeclination = $($line.Substring(0, $idStart) -replace '[\u4e00-\u9fa5]', '**').Length - $line.Substring(0, $idStart).Length #Get header titles [without remove separator]
$software.Name = $line.Substring(0, $idStart - $nameDeclination).TrimEnd() $index = $lines[$fl] -split '(?<=\s)(?!\s)'
$software.Id = $line.Substring($idStart - $nameDeclination, $versionStart - $idStart).TrimEnd()
$software.Version = $line.Substring($versionStart - $nameDeclination, $availableStart - $versionStart).TrimEnd() # Line $fl has the header, we can find char where we find ID and Version [and manage non latin characters]
$software.AvailableVersion = $line.Substring($availableStart - $nameDeclination).TrimEnd() $idStart = $($index[0] -replace '[\u4e00-\u9fa5]', '**').Length
#add formatted soft to list $versionStart = $idStart + $($index[1] -replace '[\u4e00-\u9fa5]', '**').Length
$upgradeList += $software $availableStart = $versionStart + $($index[2] -replace '[\u4e00-\u9fa5]', '**').Length
# Now cycle in real package and split accordingly
$upgradeList = @()
For ($i = $fl + 2; $i -lt $lines.Length; $i++) {
$line = $lines[$i] -replace "[\u2026]", " " #Fix "..." in long names
if ($line.StartsWith("-----")) {
#Get header line
$fl = $i - 1
#Get header titles [without remove separator]
$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 = $($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 = $($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()
$software.AvailableVersion = $line.Substring($availableStart - $nameDeclination).TrimEnd()
#add formatted soft to list
$upgradeList += $software
}
} }
#If current user is not system, remove system apps from list
if ($IsSystem -eq $false) {
$SystemApps = Get-Content -Path "$WorkingDir\config\winget_system_apps.txt" -ErrorAction SilentlyContinue
$upgradeList = $upgradeList | Where-Object { $SystemApps -notcontains $_.Id }
}
return $upgradeList | Sort-Object { Get-Random }
} }
#If current user is not system, remove system apps from list
if ($IsSystem -eq $false) {
$SystemApps = Get-Content -Path "$WorkingDir\config\winget_system_apps.txt" -ErrorAction SilentlyContinue
$upgradeList = $upgradeList | Where-Object { $SystemApps -notcontains $_.Id }
}
return $upgradeList | Sort-Object { Get-Random }
} }