From 6de09166e889365c23cc3f24b7ee623794a07051 Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Mon, 30 Sep 2024 23:40:36 +0200 Subject: [PATCH 1/3] copy mods from current location --- Sources/Winget-AutoUpdate/config/WAU-MSI_Actions.ps1 | 11 ++++++++++- Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 | 12 ++++++++++-- Sources/Wix/build.wxs | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Sources/Winget-AutoUpdate/config/WAU-MSI_Actions.ps1 b/Sources/Winget-AutoUpdate/config/WAU-MSI_Actions.ps1 index dae4fd8..93ec4c5 100644 --- a/Sources/Winget-AutoUpdate/config/WAU-MSI_Actions.ps1 +++ b/Sources/Winget-AutoUpdate/config/WAU-MSI_Actions.ps1 @@ -2,6 +2,7 @@ param( [Parameter(Mandatory = $false)] [string] $AppListPath, [Parameter(Mandatory = $false)] [string] $InstallPath, + [Parameter(Mandatory = $false)] [string] $CurrentDir, [Parameter(Mandatory = $false)] [string] $Upgrade, [Parameter(Mandatory = $False)] [Switch] $Uninstall = $false ) @@ -9,6 +10,7 @@ param( #For troubleshooting Write-Output "AppListPath: $AppListPath" Write-Output "InstallPath: $InstallPath" +Write-Output "CurrentDir: $CurrentDir" Write-Output "Upgrade: $Upgrade" Write-Output "Uninstall: $Uninstall" @@ -120,6 +122,13 @@ function Install-WingetAutoUpdate { Copy-Item -Path $AppListPath -Destination $InstallPath } + #Copy Mods to install folder + $ModsFolder = Join-Path $CurrentDir "Mods" + if (Test-Path $ModsFolder) { + Write-Output "-> Copying $ModsFolder to $InstallPath\mods" + Copy-Item -Path $ModsFolder -Destination "$InstallPath\mods" -Recurse + } + #Secure folders if not installed to ProgramFiles if ($InstallPath -notlike "$env:ProgramFiles*") { @@ -157,7 +166,7 @@ function Install-WingetAutoUpdate { #Add 1 to Github counter file try { - Invoke-RestMethod -Uri "https://github.com/Romanitho/Winget-AutoUpdate/releases/download/v$($WAUconfig.ProductVersion)/WAU_InstallCounter" | Out-Null + Invoke-WebRequest -Uri "https://github.com/Romanitho/Winget-AutoUpdate/releases/download/v$($WAUconfig.ProductVersion)/WAU_InstallCounter" -UseBasicParsing | Out-Null Write-Host "-> Reported installation." } catch { diff --git a/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 b/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 index b91ae3e..030e609 100644 --- a/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 +++ b/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 @@ -11,9 +11,14 @@ function Update-WAU { #Run WAU update try { - #Download the msi Write-ToLog "Downloading the GitHub Repository version $WAUAvailableVersion" "Cyan" - $MsiFile = "$env:temp\WAU.msi" + + #Create an unpredictable temp folder for security reasons + $MsiFolder = "$env:temp\WAU_$(Get-Date -Format yyyyMMddHHmmss)" + New-Item -ItemType Directory -Path $MsiFolder + + #Download the msi + $MsiFile = Join-Path $MsiFolder "WAU.msi" Invoke-RestMethod -Uri "https://github.com/Romanitho/Winget-AutoUpdate/releases/download/v$($WAUAvailableVersion)/WAU.msi" -OutFile $MsiFile #Update WAU @@ -27,6 +32,9 @@ function Update-WAU { $MessageType = "success" Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text + #Remove temp folder and content + Remove-Item $MsiFolder -Recurse -Force + exit 0 } diff --git a/Sources/Wix/build.wxs b/Sources/Wix/build.wxs index 37450ee..518c656 100644 --- a/Sources/Wix/build.wxs +++ b/Sources/Wix/build.wxs @@ -251,7 +251,7 @@ - + From 0cf8ca2047466293c6d53dc3328292c0cbf5fa1d Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Tue, 1 Oct 2024 00:02:33 +0200 Subject: [PATCH 2/3] Update WAU-MSI_Actions.ps1 --- Sources/Winget-AutoUpdate/config/WAU-MSI_Actions.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Winget-AutoUpdate/config/WAU-MSI_Actions.ps1 b/Sources/Winget-AutoUpdate/config/WAU-MSI_Actions.ps1 index 93ec4c5..309ec1d 100644 --- a/Sources/Winget-AutoUpdate/config/WAU-MSI_Actions.ps1 +++ b/Sources/Winget-AutoUpdate/config/WAU-MSI_Actions.ps1 @@ -125,8 +125,8 @@ function Install-WingetAutoUpdate { #Copy Mods to install folder $ModsFolder = Join-Path $CurrentDir "Mods" if (Test-Path $ModsFolder) { - Write-Output "-> Copying $ModsFolder to $InstallPath\mods" - Copy-Item -Path $ModsFolder -Destination "$InstallPath\mods" -Recurse + Write-Output "-> Copying $ModsFolder to $InstallPath" + Copy-Item -Path $ModsFolder -Destination "$InstallPath" -Recurse } #Secure folders if not installed to ProgramFiles From 4095e126db33560b29968653105028df58a882e1 Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Tue, 1 Oct 2024 00:13:38 +0200 Subject: [PATCH 3/3] remove mods on uninstall --- Sources/Winget-AutoUpdate/config/WAU-MSI_Actions.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/Winget-AutoUpdate/config/WAU-MSI_Actions.ps1 b/Sources/Winget-AutoUpdate/config/WAU-MSI_Actions.ps1 index 309ec1d..57821c7 100644 --- a/Sources/Winget-AutoUpdate/config/WAU-MSI_Actions.ps1 +++ b/Sources/Winget-AutoUpdate/config/WAU-MSI_Actions.ps1 @@ -192,7 +192,7 @@ function Uninstall-WingetAutoUpdate { Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False Get-ScheduledTask -TaskName "Winget-AutoUpdate-Policies" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False - #If upgrade, keep app list. Else, remove. + #If upgrade, keep app list and mods. Else, remove. if ($Upgrade -like "#{*}") { Write-Output "-> Upgrade detected. Keeping *.txt app lists" } @@ -202,6 +202,7 @@ function Uninstall-WingetAutoUpdate { Write-Output "-> Removing items: $AppLists" Remove-Item $AppLists -Force } + Remove-Item "$InstallPath\mods" -Recurse -Force } $ConfFolder = Get-Item (Join-Path "$InstallPath" "config") -ErrorAction SilentlyContinue