# Install the puz command: one file in %LOCALAPPDATA%\Programs\puz, added to your PATH. # Remove it: delete that folder, and take it out of your PATH in Settings. & { $ErrorActionPreference = "Stop" $ProgressPreference = "SilentlyContinue" # Older Windows PowerShell may not offer TLS 1.2 on its own. [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 if (-not [Environment]::Is64BitOperatingSystem) { Write-Host "There is no puz build for 32-bit Windows." return } $dir = if ($env:PUZ_BIN) { $env:PUZ_BIN } else { Join-Path $env:LOCALAPPDATA "Programs\puz" } New-Item -ItemType Directory -Force -Path $dir | Out-Null $exe = Join-Path $dir "puz.exe" $new = Join-Path $dir "puz.new.exe" try { Invoke-WebRequest -UseBasicParsing -Uri "https://swords.cx/cli/puz-windows-x64.exe" -OutFile $new } catch { Remove-Item -Force -ErrorAction SilentlyContinue $new Write-Host "https://swords.cx has no puz build for Windows yet, or can't be reached." return } # Windows can't replace a program while it runs, but it can rename it. Move an old puz aside first. if (Test-Path $exe) { Remove-Item -Force -ErrorAction SilentlyContinue "$exe.old" Move-Item -Force $exe "$exe.old" } Move-Item -Force $new $exe # Add the folder to the user's PATH (for new windows) and to this window's PATH. $userPath = [Environment]::GetEnvironmentVariable("Path", "User") $parts = @($userPath -split ";" | Where-Object { $_ }) if ($parts -notcontains $dir) { [Environment]::SetEnvironmentVariable("Path", (($parts + $dir) -join ";"), "User") } if (@($env:Path -split ";") -notcontains $dir) { $env:Path = "$env:Path;$dir" } Write-Host "Installed puz in $dir" -ForegroundColor Green # The first run: puz asks for your name and an optional email. With no console (CI), or with # PUZ_NO_SETUP=1, nothing is asked. A setup that fails never fails the install. $asked = $false if (-not $env:PUZ_NO_SETUP -and -not $env:CI -and [Environment]::UserInteractive -and -not [Console]::IsInputRedirected) { & $exe help setup *> $null if ($LASTEXITCODE -eq 0) { Write-Host "" & $exe setup $asked = $LASTEXITCODE -eq 0 } } if (-not $asked) { Write-Host "Try it: puz publish hello-world.puz" } }