I wrote this to update
<#
.SYNOPSIS
Upgrade GAMADV-XTD3 tool if a new version is available.
.DESCRIPTION
This script checks if the GAM tool is installed and accessible in the system PATH. If it's installed,
it checks the current version of GAMADV-XTD3 and compares it with the latest version available on GitHub.
If an update is available, it downloads and upgrades GAMADV-XTD3.
.PARAMETER TempPath
The path to the temporary directory where temporary files are stored. Default is 'C:\Temp'.
.PARAMETER DownloadPath
The path where the downloaded files will be saved. Default is 'C:\Temp\gamdown'.
.EXAMPLE
Upgrade-GAMADVXTD3 -TempPath "D:\Temp" -DownloadPath "D:\Temp\gamdown"
#>
param (
[string]$TempPath = 'C:\Temp',
[string]$DownloadPath = 'C:\Temp\gamdown'
)
try {
# Check if GAM tool is installed and accessible in the system PATH.
if (-not (Get-Command -Name gam.exe -ErrorAction SilentlyContinue)) {
throw "GAM tool is not found. Please make sure it is installed and accessible in the system PATH."
}
# Check if TempPath is $null or empty. If yes, throw an error.
if ([string]::IsNullOrWhiteSpace($TempPath)) {
throw "TempPath parameter cannot be null or empty."
}
# Check if DownloadPath is $null or empty. If yes, throw an error.
if ([string]::IsNullOrWhiteSpace($DownloadPath)) {
throw "DownloadPath parameter cannot be null or empty."
}
# Check the current version of GAMADV-XTD3 and retrieve the latest version from GitHub.
$GAMCheck = & gam.exe version checkrc
$regex = '(?s)^.+\bCurrent: ([\d.]+).+\bLatest: ([\d.]+).*$'
$CurrentVersion, $LatestVersion = -split (($GAMCheck -join "`n") -replace $regex, '$1 $2')
# Check if GAM is properly installed and the version check returned an exit code of 1 (error).
if ($LASTEXITCODE -eq 1) {
# Check if C:\Temp directory exists. If not, create it.
if (-not (Test-Path $TempPath)) {
New-Item -Path $TempPath -ItemType Directory -Force | Out-Null
}
Write-Host "Upgrade needed ..."
# Check if 'gamdown' directory exists. If yes, delete it.
if (Test-Path $DownloadPath) {
Remove-Item -Path $DownloadPath -Force -Recurse | Out-Null
}
# Create the 'gamdown' directory.
New-Item -Path $DownloadPath -ItemType Directory -Force | Out-Null
$DownloadURL = "
https://github.com/taers232c/GAMADV-XTD3/releases/download/v$($LatestVersion)/gamadv-xtd3-$($LatestVersion)-windows-x86_64.zip"
Invoke-WebRequest -Uri $DownloadURL -OutFile (Join-Path $DownloadPath 'output.zip') | Wait-Process
Expand-Archive -Path (Join-Path $DownloadPath 'output.zip') -DestinationPath $DownloadPath -Force
# Remove and move the upgraded directory to the installation directory.
Remove-Item -LiteralPath 'C:\gamadv-xtd3\gam' -Force -Recurse
Move-Item -Path (Join-Path $DownloadPath 'gamadv-xtd3') -Destination 'C:\gamadv-xtd3\gam' -Force
Remove-Item -LiteralPath $DownloadPath -Force -Recurse
$GAMCheck = & gam.exe version checkrc
$NewCurrent = -split (($GAMCheck -join "`n") -replace $regex, '$1')
return [PSCustomObject]@{
CurrentVersion = [string]$CurrentVersion
LatestVersion = [string]$LatestVersion
Upgraded = $true
NewCurrent = [string]$NewCurrent
Result = $LASTEXITCODE
}
}
else {
Write-Warning "No update needed."
exit
}
}
catch {
Write-Warning $_
exit
}
I am not responsible for problems