# SPDX-FileCopyrightText: 2026 Matvey Shcherbinin # SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL #Requires -Version 5.1 param( [string]$RepoRoot = "", [string]$BuildDir = "", [string]$OutDir = "" ) $ErrorActionPreference = "Stop" if (-not $RepoRoot) { $RepoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).Path } if (-not $BuildDir) { $BuildDir = Join-Path $RepoRoot "build\bin" } if (-not $OutDir) { $OutDir = Join-Path $RepoRoot "dist\portable\KOutNet" } $exe = Join-Path $BuildDir "KOutNet.exe" if (-not (Test-Path $exe)) { throw "Missing $exe - build first." } Write-Host "Portable source: $BuildDir" Write-Host "Portable output: $OutDir" Get-Process -Name KOutNet -EA SilentlyContinue | Stop-Process -Force -EA SilentlyContinue Start-Sleep 1 if (Test-Path $OutDir) { Remove-Item $OutDir -Recurse -Force } New-Item -ItemType Directory -Force -Path $OutDir | Out-Null robocopy $BuildDir $OutDir /E /XD CMakeFiles /XF chat-*.exe crypto-manager.exe file-transfer-handler.exe *-test.exe *Test.exe /NFL /NDL /NJH /NJS /nc /ns /np | Out-Null if ($LASTEXITCODE -ge 8) { throw "robocopy failed: $LASTEXITCODE" } $ucrt = $env:MSYSTEM_PREFIX if (-not $ucrt) { foreach ($c in @("C:\tools\msys64\ucrt64","C:\msys64\ucrt64")) { if (Test-Path $c) { $ucrt=$c; break } } } if ($ucrt) { $tlsSrc = Join-Path $ucrt "share\qt6\plugins\tls" if (Test-Path $tlsSrc) { New-Item -ItemType Directory -Force -Path (Join-Path $OutDir "tls") | Out-Null Copy-Item (Join-Path $tlsSrc "*") (Join-Path $OutDir "tls") -Force } $ca = Join-Path $ucrt "etc\ssl\certs\ca-bundle.crt" if (Test-Path $ca) { New-Item -ItemType Directory -Force -Path (Join-Path $OutDir "ssl\certs") | Out-Null Copy-Item $ca (Join-Path $OutDir "ssl\certs\ca-bundle.crt") -Force } # qqc2-desktop-style ships as the QML module org.kde.desktop. Bundling it is # what makes StyleSelector::hasKdeDesktopStyle() true on Windows, so the # Kirigami-geometried controls keep the same metrics as on Linux. The Qt # Quick Controls style is frozen at the first control, so this has to be in # the portable tree before launch, not set from QML later. $desktopStyleSrc = Join-Path $ucrt "share\qt6\qml\org\kde\desktop" if (Test-Path $desktopStyleSrc) { $desktopStyleDst = Join-Path $OutDir "share\qt6\qml\org\kde\desktop" New-Item -ItemType Directory -Force -Path (Split-Path $desktopStyleDst -Parent) | Out-Null Copy-Item $desktopStyleSrc $desktopStyleDst -Recurse -Force Write-Host "Bundled qqc2-desktop-style (org.kde.desktop)." } else { Write-Host "qqc2-desktop-style not found at $desktopStyleSrc; Fusion will be used." -ForegroundColor Yellow } # Breeze colour schemes: KColorSchemeManager looks these up by id # (BreezeLight / BreezeDark). The application's own colours now come from # AppPalette, but some KF6/Kirigami internals still ask the manager, and # shipping the files keeps those answers identical on both platforms. $schemesSrc = Join-Path $ucrt "share\color-schemes" if (Test-Path $schemesSrc) { $schemesDst = Join-Path $OutDir "share\color-schemes" New-Item -ItemType Directory -Force -Path $schemesDst | Out-Null Copy-Item (Join-Path $schemesSrc "*.colors") $schemesDst -Force -EA SilentlyContinue Write-Host "Bundled Breeze colour schemes." } } $localeSrc = Join-Path $RepoRoot "src\locale" if (Test-Path $localeSrc) { Get-ChildItem $localeSrc -Directory | ForEach-Object { $d = Join-Path $OutDir ("share\locale\" + $_.Name + "\LC_MESSAGES") New-Item -ItemType Directory -Force -Path $d | Out-Null $mo = Join-Path $_.FullName "LC_MESSAGES\koutnet.mo" if (Test-Path $mo) { Copy-Item $mo (Join-Path $d "koutnet.mo") -Force } } } $qt = "[Paths]`r`nPrefix = .`r`nLibraries = .`r`nPlugins = .`r`nImports = share/qt6/qml`r`nQmlImports = share/qt6/qml`r`nQml2Imports = share/qt6/qml`r`n" [IO.File]::WriteAllText((Join-Path $OutDir "qt.conf"), $qt) $bat = "@echo off`r`ncd /d `"%~dp0`"`r`nset PATH=%~dp0;%PATH%`r`nset QT_PLUGIN_PATH=%~dp0`r`nset QT_QPA_PLATFORM_PLUGIN_PATH=%~dp0platforms`r`nset QML2_IMPORT_PATH=%~dp0share\qt6\qml`r`nset QML_IMPORT_PATH=%~dp0share\qt6\qml`r`nset XDG_DATA_DIRS=%~dp0share`r`nif exist `"%~dp0share\qt6\qml\org\kde\desktop`" set QT_QUICK_CONTROLS_STYLE=org.kde.desktop`r`nif exist `"%~dp0ssl\certs\ca-bundle.crt`" set SSL_CERT_FILE=%~dp0ssl\certs\ca-bundle.crt`r`nstart `"`" `"%~dp0KOutNet.exe`"`r`n" [IO.File]::WriteAllText((Join-Path $OutDir "Start-KOutNet.bat"), $bat) $mb = [math]::Round(((Get-ChildItem $OutDir -Recurse -File | Measure-Object Length -Sum).Sum)/1MB,1) Write-Host "Done. $mb MB -> $OutDir"