
&"$PSScriptRoot/../Scripts/vars.ps1"

if (-Not(Test-Path "$ROOT/Var/Upgrade/sg.zip" -PathType Leaf))
{
    #TODO cant use v14 loaders if encrypted with 13
	#$url = "https://www.sourceguardian.com/loaders/download/loaders.windows-x86_64.zip"
	$url = "https://releases.cedarportal.co.uk/sg.zip"
	Invoke-WebRequest -Uri $url -OutFile "$ROOT/Var/Upgrade/sg.zip" -SkipCertificateCheck
}

Expand-Archive -Force "$ROOT/Var/Upgrade/sg.zip" -DestinationPath "$ROOT/Var/Upgrade/sg/"

Copy-Item "$ROOT/Var/Upgrade/sg/ixed.$PHP_VERSION.win" "$PHPdir\ext\"

# check SourceGuardian copied
$phpOutput = &"$PHPexe" -m
if ($phpOutput -match ".*" + "SourceGuardian" + ".*")
{
	Remove-Item "$ROOT/Var/Upgrade/sg.zip"
}
 else
{
	Write-Host "PHP Upgrade failed"
	Write-Host $PHPdir
	Write-Host $phpVersion
	Write-Host $phpOutput
}
