Merge pull request #493 from Romanitho/MinorChanges

Minor changes
pull/494/head
Romain 2023-11-21 12:58:44 +01:00 committed by GitHub
commit bfa764a7e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 44 deletions

View File

@ -81,8 +81,7 @@ if ($IsSystem) {
Invoke-PostUpdateActions Invoke-PostUpdateActions
} }
#Run Scope Machine funtion if run as System #Run Scope Machine funtion if run as System
$SettingsPath = "$Env:windir\system32\config\systemprofile\AppData\Local\Microsoft\WinGet\Settings\defaultState\settings.json" Add-ScopeMachine
Add-ScopeMachine $SettingsPath
} }
#Get Notif Locale function #Get Notif Locale function
@ -92,9 +91,14 @@ Write-ToLog "Notification Level: $($WAUConfig.WAU_NotificationLevel). Notificati
#Check network connectivity #Check network connectivity
if (Test-Network) { if (Test-Network) {
#Check if Winget is installed and get Winget cmd #Check if Winget is installed and get Winget cmd
$TestWinget = Get-WingetCmd $Script:Winget = Get-WingetCmd
if ($Winget) {
#Log Winget installed version
$WingetVer = & $Winget --version
Write-ToLog "Winget Version: $WingetVer"
if ($TestWinget) {
#Get Current Version #Get Current Version
$WAUCurrentVersion = $WAUConfig.DisplayVersion $WAUCurrentVersion = $WAUConfig.DisplayVersion
Write-ToLog "WAU current version: $WAUCurrentVersion" Write-ToLog "WAU current version: $WAUCurrentVersion"

View File

@ -1,20 +1,32 @@
#Function to configure the prefered scope option as Machine #Function to configure the prefered scope option as Machine
function Add-ScopeMachine ($SettingsPath) { function Add-ScopeMachine {
#Get Settings path for system or current user
if ([System.Security.Principal.WindowsIdentity]::GetCurrent().IsSystem) {
$SettingsPath = "$Env:windir\System32\config\systemprofile\AppData\Local\Microsoft\WinGet\Settings\settings.json"
}
else {
$SettingsPath = "$env:LOCALAPPDATA\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json"
}
$ConfigFile = @{}
#Check if setting file exist, if not create it
if (Test-Path $SettingsPath) { if (Test-Path $SettingsPath) {
$ConfigFile = Get-Content -Path $SettingsPath | Where-Object { $_ -notmatch '//' } | ConvertFrom-Json $ConfigFile = Get-Content -Path $SettingsPath | Where-Object { $_ -notmatch '//' } | ConvertFrom-Json
} }
if (!$ConfigFile) { else {
$ConfigFile = @{} New-Item -Path $SettingsPath -Force | Out-Null
} }
if ($ConfigFile.installBehavior.preferences.scope) {
$ConfigFile.installBehavior.preferences.scope = "Machine" if ($ConfigFile.installBehavior.preferences) {
Add-Member -InputObject $ConfigFile.installBehavior.preferences -MemberType NoteProperty -Name "scope" -Value "Machine" -Force
} }
else { else {
$Scope = New-Object PSObject -Property $(@{scope = "Machine" }) $Scope = New-Object PSObject -Property $(@{scope = "Machine" })
$Preference = New-Object PSObject -Property $(@{preferences = $Scope }) $Preference = New-Object PSObject -Property $(@{preferences = $Scope })
Add-Member -InputObject $ConfigFile -MemberType NoteProperty -Name 'installBehavior' -Value $Preference -Force Add-Member -InputObject $ConfigFile -MemberType NoteProperty -Name "installBehavior" -Value $Preference -Force
} }
$ConfigFile | ConvertTo-Json -Depth 100 | Out-File $SettingsPath -Encoding utf8 -Force
} $ConfigFile | ConvertTo-Json -Depth 100 | Out-File $SettingsPath -Encoding utf8 -Force
}

View File

@ -2,39 +2,22 @@
Function Get-WingetCmd { Function Get-WingetCmd {
#Get WinGet Path (if Admin context) $WingetCmd = $null
# Includes Workaround for ARM64 (removed X64 and replaces it with a wildcard)
$ResolveWingetPath = Resolve-Path "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') }
if ($ResolveWingetPath) { #Get WinGet Path
#If multiple version, pick last one try {
$WingetPath = $ResolveWingetPath[-1].Path #Get Admin Context Winget Location
$WingetInfo = (Get-Item "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_8wekyb3d8bbwe\winget.exe").VersionInfo | Sort-Object -Property FileVersionRaw
#If multiple versions, pick most recent one
$WingetCmd = $WingetInfo[-1].FileName
} }
catch {
#If running under System or Admin context obtain Winget from Program Files #Get User context Winget Location
if((([System.Security.Principal.WindowsIdentity]::GetCurrent().User) -eq "S-1-5-18") -or ($WingetPath)){
if (Test-Path "$WingetPath\winget.exe") {
$Script:Winget = "$WingetPath\winget.exe"
}
}else{
#Get Winget Location in User context
if (Test-Path "$env:LocalAppData\Microsoft\WindowsApps\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\winget.exe") { if (Test-Path "$env:LocalAppData\Microsoft\WindowsApps\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\winget.exe") {
$Script:Winget = "$env:LocalAppData\Microsoft\WindowsApps\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\winget.exe" $WingetCmd = "$env:LocalAppData\Microsoft\WindowsApps\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\winget.exe"
} }
} }
If(!($Script:Winget)){ return $WingetCmd
Write-ToLog "Winget not installed or detected !" "Red"
return $false
}
#Run winget to list apps and accept source agrements (necessary on first run) }
& $Winget list --accept-source-agreements -s winget | Out-Null
#Log Winget installed version
$WingetVer = & $Winget --version
Write-ToLog "Winget Version: $WingetVer"
return $true
}

View File

@ -68,12 +68,12 @@ Function Update-WinGet {
#If multiple versions, pick most recent one #If multiple versions, pick most recent one
$WingetCmd = $WingetInfo[-1].FileName $WingetCmd = $WingetInfo[-1].FileName
& $WingetCmd source reset --force & $WingetCmd source reset --force
Write-ToLog "-> WinGet sources reset." "green" Write-ToLog "-> WinGet sources reset.`n" "green"
$return = "success" $return = "success"
} }
catch { catch {
Write-ToLog "-> Failed to install WinGet MSIXBundle for App Installer..." "red" Write-ToLog "-> Failed to install WinGet MSIXBundle for App Installer...`n" "red"
#Force Store Apps to update #Force Store Apps to update
Update-StoreApps Update-StoreApps
$return = "fail" $return = "fail"
@ -86,7 +86,7 @@ Function Update-WinGet {
return $return return $return
} }
else { else {
Write-ToLog "-> WinGet is up to date: v$WinGetInstalledVersion" "Green" Write-ToLog "-> WinGet is up to date: v$WinGetInstalledVersion`n" "Green"
return "current" return "current"
} }
} }