param( [string]$BootstrapBaseUrl = "", [Parameter(ValueFromRemainingArguments = $true)] [string[]]$RemainingArgs ) $ErrorActionPreference = "Stop" function Test-HasNamedArgument { param( [Parameter(Mandatory = $true)][string[]]$Args, [Parameter(Mandatory = $true)][string]$Name ) foreach ($arg in $Args) { if ($arg -ieq $Name) { return $true } } return $false } function Get-LocalInstallScriptPath { if ([string]::IsNullOrWhiteSpace($PSScriptRoot)) { return "" } $candidate = Join-Path $PSScriptRoot "windows\install.ps1" if (Test-Path -LiteralPath $candidate) { return $candidate } return "" } function Save-WebBootstrapScripts { param( [Parameter(Mandatory = $true)][string]$BaseUrl, [Parameter(Mandatory = $true)][string]$DestinationRoot ) $scriptFiles = @( "release/common.ps1", "windows/assert-public-install.ps1", "windows/Get-GamibaseHostInventory.ps1", "windows/Get-GamibaseVersionState.ps1", "windows/Install-GamibaseUEPlugin.ps1", "windows/Install-GamibaseVSCodeExtension.ps1", "windows/install.ps1", "windows/public-install-common.ps1", "windows/Uninstall-GamibaseUEPlugin.ps1" ) $normalizedBaseUrl = $BaseUrl.TrimEnd("/") foreach ($relativePath in $scriptFiles) { $destinationPath = Join-Path $DestinationRoot ($relativePath -replace "/", "\") $destinationDir = Split-Path -Parent $destinationPath if (-not (Test-Path -LiteralPath $destinationDir)) { New-Item -ItemType Directory -Path $destinationDir -Force | Out-Null } $scriptUri = "{0}/{1}" -f $normalizedBaseUrl, $relativePath Invoke-WebRequest -Uri $scriptUri -OutFile $destinationPath } return (Join-Path $DestinationRoot "windows\install.ps1") } $effectiveArgs = @($RemainingArgs) $hasReleaseManifest = Test-HasNamedArgument -Args $effectiveArgs -Name "-ReleaseManifest" $hasRepositoryOwner = Test-HasNamedArgument -Args $effectiveArgs -Name "-RepositoryOwner" $hasRepositoryName = Test-HasNamedArgument -Args $effectiveArgs -Name "-RepositoryName" if (-not $hasReleaseManifest -and -not $hasRepositoryOwner -and -not $hasRepositoryName) { $effectiveArgs = @( "-ReleaseManifest", "https://gamibase.ai/release-manifest.json" ) + $effectiveArgs } $installScriptPath = Get-LocalInstallScriptPath $tempRoot = "" if ([string]::IsNullOrWhiteSpace($installScriptPath)) { $baseUrl = if ([string]::IsNullOrWhiteSpace($BootstrapBaseUrl)) { "https://gamibase.ai" } else { $BootstrapBaseUrl } $tempRoot = Join-Path ([System.IO.Path]::GetTempPath()) ("gamibase-install-" + [System.Guid]::NewGuid().ToString("N")) New-Item -ItemType Directory -Path $tempRoot -Force | Out-Null $installScriptPath = Save-WebBootstrapScripts -BaseUrl $baseUrl -DestinationRoot $tempRoot } try { & $installScriptPath @effectiveArgs $exitCode = if ($LASTEXITCODE -is [int]) { [int]$LASTEXITCODE } else { 0 } exit $exitCode } finally { if (-not [string]::IsNullOrWhiteSpace($tempRoot) -and (Test-Path -LiteralPath $tempRoot)) { Remove-Item -LiteralPath $tempRoot -Recurse -Force -ErrorAction SilentlyContinue } }