From 015ac3731b71ae7d04ba7a7c836497b662a08a2b Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Tue, 17 Sep 2024 12:07:28 +0200 Subject: [PATCH] Set Repo as Variable --- Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 | 3 +++ .../functions/Get-WAUAvailableVersion.ps1 | 12 ++++++------ .../functions/Invoke-PostUpdateActions.ps1 | 2 +- Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 | 6 +++--- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 index 8208061..4ad1785 100644 --- a/Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -13,6 +13,9 @@ $null = cmd /c '' [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 $Script:ProgressPreference = 'SilentlyContinue' +#Set GitHub Repo +$Script:GitHub_Repo = "Winget-AutoUpdate" + #Log initialization $LogFile = "$WorkingDir\logs\updates.log" diff --git a/Sources/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 b/Sources/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 index 24b289e..b3e0e03 100644 --- a/Sources/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 +++ b/Sources/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 @@ -10,12 +10,12 @@ function Get-WAUAvailableVersion { try { #Get latest pre-release info - $WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases' + $WAUurl = "https://api.github.com/repos/Romanitho/$GitHub_Repo/releases" $WAUAvailableVersion = ((Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v", "") } catch { - $url = "https://github.com/Romanitho/Winget-AutoUpdate/releases" - $link = ((Invoke-WebRequest $url -UseBasicParsing).Links.href -match "/Winget-AutoUpdate/releases/tag/v*")[0] + $url = "https://github.com/Romanitho/$GitHub_Repo/releases" + $link = ((Invoke-WebRequest $url -UseBasicParsing).Links.href -match "/$GitHub_Repo/releases/tag/v*")[0] $WAUAvailableVersion = $link.Trim().Split("v")[-1] } @@ -24,12 +24,12 @@ function Get-WAUAvailableVersion { try { #Get latest stable info - $WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases/latest' + $WAUurl = "https://api.github.com/repos/Romanitho/$GitHub_Repo/releases/latest" $WAUAvailableVersion = ((Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v", "") } catch { - $url = "https://github.com/Romanitho/Winget-AutoUpdate/releases/latest" - $link = ((Invoke-WebRequest $url -UseBasicParsing).Links.href -match "/Winget-AutoUpdate/releases/tag/v*")[0] + $url = "https://github.com/Romanitho/$GitHub_Repo/releases/latest" + $link = ((Invoke-WebRequest $url -UseBasicParsing).Links.href -match "/$GitHub_Repo/releases/tag/v*")[0] $WAUAvailableVersion = $link.Trim().Split("v")[-1] } diff --git a/Sources/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 b/Sources/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 index 00eb446..744d7ce 100644 --- a/Sources/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 +++ b/Sources/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 @@ -156,7 +156,7 @@ function Invoke-PostUpdateActions { #Add 1 to counter file try { - Invoke-RestMethod -Uri "https://github.com/Romanitho/Winget-AutoUpdate/releases/download/v$($WAUConfig.DisplayVersion)/WAU_InstallCounter" | Out-Null + Invoke-RestMethod -Uri "https://github.com/Romanitho/$GitHub_Repo/releases/download/v$($WAUConfig.DisplayVersion)/WAU_InstallCounter" | Out-Null } catch { Write-ToLog "-> Not able to report installation." "Yellow" diff --git a/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 b/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 index ee41962..437d44c 100644 --- a/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 +++ b/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 @@ -2,7 +2,7 @@ function Update-WAU { - $OnClickAction = "https://github.com/Romanitho/Winget-AutoUpdate/releases" + $OnClickAction = "https://github.com/Romanitho/$GitHub_Repo/releases" $Button1Text = $NotifLocale.local.outputs.output[10].message #Send available update notification @@ -21,7 +21,7 @@ function Update-WAU { #Download the zip Write-ToLog "Downloading the GitHub Repository Zip version $WAUAvailableVersion" "Cyan" - Invoke-RestMethod -Uri "https://github.com/Romanitho/Winget-AutoUpdate/releases/download/v$($WAUAvailableVersion)/WAU.zip" -OutFile $ZipFile + Invoke-RestMethod -Uri "https://github.com/Romanitho/$GitHub_Repo/releases/download/v$($WAUAvailableVersion)/WAU.zip" -OutFile $ZipFile #Extract Zip File Write-ToLog "Unzipping the WAU Update package" "Cyan" @@ -74,7 +74,7 @@ function Update-WAU { #Download the msi Write-ToLog "Downloading the GitHub Repository MSI version $WAUAvailableVersion" "Cyan" $MsiFile = "$env:temp\WAU.msi" - Invoke-RestMethod -Uri "https://github.com/Romanitho/Winget-AutoUpdate/releases/download/v$($WAUAvailableVersion)/WAU.msi" -OutFile $MsiFile + Invoke-RestMethod -Uri "https://github.com/Romanitho/$GitHub_Repo/releases/download/v$($WAUAvailableVersion)/WAU.msi" -OutFile $MsiFile #Migrate registry to save current WAU settings Write-ToLog "Saving current config before updating with MSI"