# SPDX-FileCopyrightText: 2026 Matvey Shcherbinin # SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL #Requires -Version 5.1 # Simple KOutNet Windows installer. # Copies the portable runtime next to this script (or -Source) into # %LOCALAPPDATA%\KOutNet, writes Start Menu + Desktop shortcuts, optional uninstaller. [CmdletBinding()] param( [string]$Source = "", [string]$InstallDir = "", [switch]$NoDesktopShortcut, [switch]$Uninstall ) $ErrorActionPreference = "Stop" $AppName = "KOutNet" $Publisher = "bitzuka" function Get-DefaultSource { $here = $PSScriptRoot if (Test-Path (Join-Path $here "KOutNet.exe")) { return $here } # repo: packaging/windows → ../../dist/portable/KOutNet and ../../build/bin $repo = Resolve-Path (Join-Path $here "..\..") -ErrorAction SilentlyContinue if ($repo) { $portable = Join-Path $repo "dist\portable\KOutNet" if (Test-Path (Join-Path $portable "KOutNet.exe")) { return $portable } $build = Join-Path $repo "build\bin" if (Test-Path (Join-Path $build "KOutNet.exe")) { return $build } } $desk = Join-Path ([Environment]::GetFolderPath("Desktop")) "KOutNet" if (Test-Path (Join-Path $desk "KOutNet.exe")) { return $desk } throw "KOutNet.exe not found. Pass -Source path to the portable folder." } function Stop-KOutNet { Get-Process -Name "KOutNet" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue Start-Sleep -Seconds 1 } function New-Shortcut { param([string]$Path, [string]$Target, [string]$WorkDir, [string]$Icon) $w = New-Object -ComObject WScript.Shell $s = $w.CreateShortcut($Path) $s.TargetPath = $Target $s.WorkingDirectory = $WorkDir $s.IconLocation = $Icon $s.Description = $AppName $s.Save() } if ([string]::IsNullOrWhiteSpace($InstallDir)) { $InstallDir = Join-Path $env:LOCALAPPDATA $AppName } if ($Uninstall) { Stop-KOutNet $startMenu = Join-Path $env:APPDATA "Microsoft\Windows\Start Menu\Programs\$AppName" $desktop = Join-Path ([Environment]::GetFolderPath("Desktop")) "$AppName.lnk" if (Test-Path $startMenu) { Remove-Item $startMenu -Recurse -Force -ErrorAction SilentlyContinue } if (Test-Path $desktop) { Remove-Item $desktop -Force -ErrorAction SilentlyContinue } $unreg = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\$AppName" if (Test-Path $unreg) { Remove-Item $unreg -Recurse -Force -ErrorAction SilentlyContinue } if (Test-Path $InstallDir) { Remove-Item $InstallDir -Recurse -Force -ErrorAction SilentlyContinue } Write-Host "Uninstalled $AppName from $InstallDir" exit 0 } if ([string]::IsNullOrWhiteSpace($Source)) { $Source = Get-DefaultSource } $exe = Join-Path $Source "KOutNet.exe" if (-not (Test-Path $exe)) { throw "Missing $exe" } Write-Host "Installing $AppName" Write-Host " from: $Source" Write-Host " to: $InstallDir" Stop-KOutNet New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null robocopy $Source $InstallDir /E /XD .git /XF Install-KOutNet.ps1 *.iss /NFL /NDL /NJH /NJS /nc /ns /np | Out-Null if ($LASTEXITCODE -ge 8) { throw "robocopy failed with code $LASTEXITCODE" } $targetExe = Join-Path $InstallDir "KOutNet.exe" if (-not (Test-Path $targetExe)) { throw "Install failed: $targetExe missing" } # Prefer launcher bat if present (sets QML/SSL paths) $launch = Join-Path $InstallDir "Start-KOutNet.bat" if (-not (Test-Path $launch)) { @" @echo off cd /d "%~dp0" set PATH=%~dp0;%PATH% set QT_PLUGIN_PATH=%~dp0 set QT_QPA_PLATFORM_PLUGIN_PATH=%~dp0platforms set QML2_IMPORT_PATH=%~dp0share\qt6\qml set QML_IMPORT_PATH=%~dp0share\qt6\qml if exist "%~dp0ssl\certs\ca-bundle.crt" set SSL_CERT_FILE=%~dp0ssl\certs\ca-bundle.crt start "" "%~dp0KOutNet.exe" "@ | Set-Content -Path $launch -Encoding ASCII } $startMenu = Join-Path $env:APPDATA "Microsoft\Windows\Start Menu\Programs\$AppName" New-Item -ItemType Directory -Force -Path $startMenu | Out-Null New-Shortcut -Path (Join-Path $startMenu "$AppName.lnk") -Target $launch -WorkDir $InstallDir -Icon "$targetExe,0" New-Shortcut -Path (Join-Path $startMenu "Uninstall $AppName.lnk") -Target "powershell.exe" -WorkDir $InstallDir -Icon "$targetExe,0" # fix uninstall shortcut args $w = New-Object -ComObject WScript.Shell $u = $w.CreateShortcut((Join-Path $startMenu "Uninstall $AppName.lnk")) $u.TargetPath = "powershell.exe" $u.Arguments = "-NoProfile -ExecutionPolicy Bypass -File `"$InstallDir\Install-KOutNet.ps1`" -Uninstall -InstallDir `"$InstallDir`"" $u.WorkingDirectory = $InstallDir $u.IconLocation = "$targetExe,0" $u.Save() if (-not $NoDesktopShortcut) { $desktop = Join-Path ([Environment]::GetFolderPath("Desktop")) "$AppName.lnk" New-Shortcut -Path $desktop -Target $launch -WorkDir $InstallDir -Icon "$targetExe,0" } Copy-Item $PSCommandPath (Join-Path $InstallDir "Install-KOutNet.ps1") -Force # HKCU uninstall entry (no admin) $unreg = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\$AppName" New-Item -Path $unreg -Force | Out-Null $ver = "0.0.0" try { $vi = [Diagnostics.FileVersionInfo]::GetVersionInfo($targetExe) if ($vi.FileVersion) { $ver = $vi.FileVersion } } catch {} Set-ItemProperty $unreg -Name "DisplayName" -Value $AppName Set-ItemProperty $unreg -Name "DisplayIcon" -Value $targetExe Set-ItemProperty $unreg -Name "Publisher" -Value $Publisher Set-ItemProperty $unreg -Name "InstallLocation" -Value $InstallDir Set-ItemProperty $unreg -Name "DisplayVersion" -Value $ver Set-ItemProperty $unreg -Name "UninstallString" -Value "powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"$InstallDir\Install-KOutNet.ps1`" -Uninstall -InstallDir `"$InstallDir`"" Set-ItemProperty $unreg -Name "NoModify" -Value 1 -Type DWord Set-ItemProperty $unreg -Name "NoRepair" -Value 1 -Type DWord $sizeKb = [int]((Get-ChildItem $InstallDir -Recurse -File -ErrorAction SilentlyContinue | Measure-Object Length -Sum).Sum / 1KB) Set-ItemProperty $unreg -Name "EstimatedSize" -Value $sizeKb -Type DWord Write-Host "" Write-Host "Done. Installed to: $InstallDir" Write-Host "Start Menu: $AppName" if (-not $NoDesktopShortcut) { Write-Host "Desktop shortcut created." } Write-Host "Uninstall: Start Menu -> Uninstall $AppName" Write-Host " or: powershell -File `"$InstallDir\Install-KOutNet.ps1`" -Uninstall"