param( [string]$SourceDir = "", [string]$OutputDir = "", [string]$ZipFile = "", [string]$SdkVersion = "0.1.0", [switch]$IncludeDemoMainApp, [switch]$IncludeQtRuntime ) $ErrorActionPreference = "Stop" $RepoRoot = Split-Path -Parent $PSScriptRoot $DefaultSdkName = if ($IncludeQtRuntime) { "UpdateClientSDK-With-QtDll" } else { "UpdateClientSDK" } if ([string]::IsNullOrWhiteSpace($SourceDir)) { $SourceDir = Join-Path $RepoRoot "out/bin/Release" } if ([string]::IsNullOrWhiteSpace($OutputDir)) { $OutputDir = Join-Path $RepoRoot "dist/$DefaultSdkName" } if ([string]::IsNullOrWhiteSpace($ZipFile)) { $ZipFile = Join-Path $RepoRoot "dist/$DefaultSdkName.zip" } $source = (Resolve-Path $SourceDir).Path $requiredFiles = @("Launcher.exe", "Updater.exe", "Bootstrap.exe") foreach ($name in $requiredFiles) { $path = Join-Path $source $name if (-not (Test-Path $path)) { throw "SDK source directory is missing required file: $path" } } $debugArtifacts = Get-ChildItem $source -Recurse -File | Where-Object { $_.Name -match '^(Qt5.*d|qwindowsd|libEGLd|libGLESv2d|msvcp.*d|vcruntime.*d)\.dll$' -or $_.Extension -in @('.pdb', '.ilk') } if ($debugArtifacts) { throw "SDK source directory contains Debug artifacts. Use a clean Release output directory. Example: $($debugArtifacts[0].FullName)" } if (Test-Path $OutputDir) { Remove-Item $OutputDir -Recurse -Force } New-Item $OutputDir -ItemType Directory -Force | Out-Null $binDir = Join-Path $OutputDir "bin" $configDir = Join-Path $OutputDir "config" $scriptsDir = Join-Path $OutputDir "scripts" $commonDir = Join-Path $OutputDir "Common" New-Item $binDir,$configDir,$scriptsDir,$commonDir -ItemType Directory -Force | Out-Null $excludedTopLevel = @("config", "update", "update_temp", "manifest_public_key.pem") if (-not $IncludeDemoMainApp) { $excludedTopLevel += "MainApp.exe" } if (-not $IncludeQtRuntime) { $excludedTopLevel += @( "bearer", "iconengines", "imageformats", "platforms", "styles", "translations" ) } function Test-IsQtRuntimeFile { param([System.IO.FileSystemInfo]$Item) if ($IncludeQtRuntime -or $Item.PSIsContainer) { return $false } return ( $Item.Name -match '^Qt5.*\.dll$' -or $Item.Name -match '^vc_redist.*\.exe$' -or $Item.Name -match '^vcredist.*\.exe$' -or $Item.Name -match '^vcruntime.*\.dll$' -or $Item.Name -match '^msvcp.*\.dll$' -or $Item.Name -match '^concrt.*\.dll$' -or $Item.Name -in @( "libEGL.dll", "libGLESv2.dll", "opengl32sw.dll", "d3dcompiler_47.dll" ) ) } Get-ChildItem $source -Force | Where-Object { $_.Name -notin $excludedTopLevel -and -not (Test-IsQtRuntimeFile $_) } | Copy-Item -Destination $binDir -Recurse -Force $commonSourceDir = Join-Path $RepoRoot "Common" $commonSourceFiles = @( "ConfigHelper.h", "ConfigHelper.cpp", "IntegrityHelper.h", "IntegrityHelper.cpp", "TicketHelper.h", "TicketHelper.cpp", "UpdatePathPolicy.h", "UpdatePathPolicy.cpp" ) foreach ($commonFile in $commonSourceFiles) { $commonPath = Join-Path $commonSourceDir $commonFile if (-not (Test-Path $commonPath)) { throw "SDK Common integration source is missing: $commonPath" } Copy-Item $commonPath (Join-Path $commonDir $commonFile) -Force } $sdkGuideName = [string]::Concat("SIMCAE", [char]0x6253, [char]0x5305, [char]0x4e0a, [char]0x4f20, ".md") $sdkGuideSource = Join-Path $RepoRoot $sdkGuideName if (Test-Path $sdkGuideSource) { Copy-Item $sdkGuideSource (Join-Path $OutputDir $sdkGuideName) -Force } else { throw "SIMCAE packaging guide is missing: $sdkGuideSource" } Copy-Item (Join-Path $PSScriptRoot "package-client.ps1") (Join-Path $scriptsDir "package-client.ps1") -Force Copy-Item (Join-Path $PSScriptRoot "package-sdk.ps1") (Join-Path $scriptsDir "package-sdk.ps1") -Force Copy-Item (Join-Path $PSScriptRoot "install-sdk.ps1") (Join-Path $scriptsDir "install-sdk.ps1") -Force @{ sdk_version = $SdkVersion generated_at = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ") sdk_type = "external-updater-runtime" required_entry = "Launcher.exe" contains_demo_main_app = [bool]$IncludeDemoMainApp contains_qt_runtime = [bool]$IncludeQtRuntime contains_final_config = $false docs_entry = $sdkGuideName word_guide_included = $false integration_sources = $commonSourceFiles } | ConvertTo-Json -Depth 3 | Set-Content (Join-Path $OutputDir "sdk_manifest.json") -Encoding UTF8 $zipParent = Split-Path $ZipFile -Parent New-Item $zipParent -ItemType Directory -Force | Out-Null if (Test-Path $ZipFile) { Remove-Item $ZipFile -Force } Compress-Archive -Path (Join-Path $OutputDir "*") -DestinationPath $ZipFile -CompressionLevel Optimal Write-Host "SDK directory: $OutputDir" Write-Host "SDK zip: $ZipFile" Write-Host "SDK version: $SdkVersion"