/
DemienMedich
/
BodyweightBase
Обзор
Документация
Войти
/
DemienMedich
/
BodyweightBase
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
package.ps1
158 строк
6 KB
DemienMedich
Harden package verification and clean startup
18 июл 2026, 21:15
18 июл 2026, 21:15
35f16e9
Код
Авторство
О чём код?
param( [string]$QtRoot = "Z:\Soft\Qt\6.8.3\msvc2022_64", [string]$VcVars = "Z:\Soft\VC2022\VC\Auxiliary\Build\vcvars64.bat", [string]$Configuration = "Release", [string]$PythonCommand = "python", [switch]$SkipBuild ) $ErrorActionPreference = "Stop" $buildScript = Join-Path $PSScriptRoot "build.ps1" $buildDirectory = Join-Path $PSScriptRoot "build" $appExe = Join-Path $buildDirectory "BodyweightBaseCppApp.exe" $packageRoot = Join-Path $PSScriptRoot "dist" $packageDirectory = Join-Path $packageRoot "BodyweightBaseCpp" $packageExe = Join-Path $packageDirectory "BodyweightBaseCppApp.exe" $manifestPath = Join-Path $packageDirectory "PACKAGE_MANIFEST.txt" $frameHashManifestName = "EXERCISE_FRAMES.sha256" $frameHashManifestPath = Join-Path $packageDirectory $frameHashManifestName $thirdPartyNoticesSource = Join-Path $PSScriptRoot "THIRD_PARTY_NOTICES.txt" $thirdPartyNoticesTarget = Join-Path $packageDirectory "THIRD_PARTY_NOTICES.txt" $privacyNoticeSource = Join-Path $PSScriptRoot "PRIVACY_AND_DATA.txt" $privacyNoticeTarget = Join-Path $packageDirectory "PRIVACY_AND_DATA.txt" $archivePath = Join-Path $packageRoot "BodyweightBaseCpp.zip" $archiveHashPath = "$archivePath.sha256" $windeployqt = Join-Path $QtRoot "bin\windeployqt.exe" $assetAudit = Join-Path $PSScriptRoot "tools\audit_exercise_frames.py" & $PythonCommand -B $assetAudit if ($LASTEXITCODE -ne 0) { throw "Exercise frame audit failed with exit code $LASTEXITCODE" } if (-not $SkipBuild) { & $buildScript -QtRoot $QtRoot -VcVars $VcVars if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } } if (-not (Test-Path $appExe)) { throw "Application executable was not found: $appExe" } if (-not (Test-Path $windeployqt)) { throw "windeployqt was not found: $windeployqt" } if (-not (Test-Path $VcVars)) { throw "Visual C++ environment script was not found: $VcVars" } if (-not (Test-Path $thirdPartyNoticesSource)) { throw "Third-party notices file was not found: $thirdPartyNoticesSource" } if (-not (Test-Path $privacyNoticeSource)) { throw "Privacy and data notice file was not found: $privacyNoticeSource" } if (Test-Path $packageDirectory) { Remove-Item -LiteralPath $packageDirectory -Recurse -Force } New-Item -ItemType Directory -Path $packageDirectory | Out-Null Copy-Item -LiteralPath $appExe -Destination $packageExe Copy-Item -LiteralPath $thirdPartyNoticesSource -Destination $thirdPartyNoticesTarget Copy-Item -LiteralPath $privacyNoticeSource -Destination $privacyNoticeTarget $assetSource = Join-Path $PSScriptRoot "Assets\ExerciseFrames" $assetTarget = Join-Path $packageDirectory "Assets\ExerciseFrames" if (Test-Path $assetSource) { Copy-Item -LiteralPath $assetSource -Destination $assetTarget -Recurse } $qmlDirectory = Join-Path $PSScriptRoot "app" $deployCommand = "call `"$VcVars`" && `"$windeployqt`" --release --compiler-runtime --no-translations --skip-plugin-types qmltooling,generic --qmldir `"$qmlDirectory`" --dir `"$packageDirectory`" `"$packageExe`"" cmd /c $deployCommand if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } $unusedControlStyleDirectories = @("FluentWinUI3", "Fusion", "Imagine", "Material", "Universal", "Windows") foreach ($styleDirectory in $unusedControlStyleDirectories) { $stylePath = Join-Path $packageDirectory "qml\QtQuick\Controls\$styleDirectory" if (Test-Path $stylePath) { Remove-Item -LiteralPath $stylePath -Recurse -Force } } $unusedControlStyleLibraries = @( "Qt6QuickControls2FluentWinUI3StyleImpl.dll", "Qt6QuickControls2Fusion.dll", "Qt6QuickControls2FusionStyleImpl.dll", "Qt6QuickControls2Imagine.dll", "Qt6QuickControls2ImagineStyleImpl.dll", "Qt6QuickControls2Material.dll", "Qt6QuickControls2MaterialStyleImpl.dll", "Qt6QuickControls2Universal.dll", "Qt6QuickControls2UniversalStyleImpl.dll", "Qt6QuickControls2WindowsStyleImpl.dll" ) foreach ($library in $unusedControlStyleLibraries) { $libraryPath = Join-Path $packageDirectory $library if (Test-Path $libraryPath) { Remove-Item -LiteralPath $libraryPath -Force } } $exerciseFrameFiles = if (Test-Path $assetTarget) { @(Get-ChildItem -LiteralPath $assetTarget -Recurse -File | Sort-Object FullName) } else { @() } $unexpectedFrameFiles = @($exerciseFrameFiles | Where-Object { $_.Extension -cne ".png" -or $_.DirectoryName -cne $assetTarget }) if ($unexpectedFrameFiles.Count -gt 0) { throw "Packaged exercise frame directory contains non-lowercase-PNG files: $($unexpectedFrameFiles.Name -join ', ')" } $frameHashes = foreach ($frameFile in $exerciseFrameFiles) { $relativeFramePath = $frameFile.FullName.Substring($packageDirectory.Length + 1).Replace('\', '/') $frameHash = (Get-FileHash -LiteralPath $frameFile.FullName -Algorithm SHA256).Hash "$frameHash $relativeFramePath" } Set-Content -LiteralPath $frameHashManifestPath -Value $frameHashes -Encoding ASCII $files = Get-ChildItem -LiteralPath $packageDirectory -Recurse -File $packageSizeBytes = ($files | Measure-Object Length -Sum).Sum $exerciseFrameCount = $exerciseFrameFiles.Count $manifest = @( "BodyweightBaseCpp package" "CreatedAtUtc=$((Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"))" "Configuration=$Configuration" "QtRoot=$QtRoot" "Executable=BodyweightBaseCppApp.exe" "PayloadFileCount=$($files.Count)" "PayloadSizeBytes=$packageSizeBytes" "ExerciseFrameCount=$exerciseFrameCount" "ExerciseFrameHashManifest=$frameHashManifestName" "AssetAuditPassed=true" "IncludesQtRuntime=true" "IncludesVcRedist=true" "IncludesThirdPartyNotices=true" "IncludesPrivacyNotice=true" ) Set-Content -LiteralPath $manifestPath -Value $manifest -Encoding UTF8 if (Test-Path $archivePath) { Remove-Item -LiteralPath $archivePath -Force } if (Test-Path $archiveHashPath) { Remove-Item -LiteralPath $archiveHashPath -Force } Compress-Archive -LiteralPath $packageDirectory -DestinationPath $archivePath -CompressionLevel Optimal $archiveHash = Get-FileHash -LiteralPath $archivePath -Algorithm SHA256 Set-Content -LiteralPath $archiveHashPath -Value "$($archiveHash.Hash) $(Split-Path $archivePath -Leaf)" -Encoding ASCII Write-Host "Package created: $packageDirectory" Write-Host "Archive created: $archivePath" Write-Host "SHA256: $($archiveHash.Hash)"