|
| 1 | +param( |
| 2 | + [Parameter(Mandatory = $true)] |
| 3 | + [string]$BuildDir, |
| 4 | + [Parameter(Mandatory = $true)] |
| 5 | + [string]$VcpkgRoot |
| 6 | +) |
| 7 | + |
| 8 | +$ErrorActionPreference = "Stop" |
| 9 | + |
| 10 | +$buildDirAbs = (Resolve-Path $BuildDir).Path |
| 11 | +$exePath = Join-Path $buildDirAbs "OpenGothicStarter.exe" |
| 12 | +if (-not (Test-Path $exePath)) { |
| 13 | + throw "Launcher executable not found: $exePath" |
| 14 | +} |
| 15 | + |
| 16 | +$candidateRuntimeDirs = @( |
| 17 | + (Join-Path $buildDirAbs "vcpkg_installed/x64-windows/bin"), |
| 18 | + (Join-Path $VcpkgRoot "installed/x64-windows/bin") |
| 19 | +) |
| 20 | + |
| 21 | +if ($env:GITHUB_WORKSPACE) { |
| 22 | + $candidateRuntimeDirs += (Join-Path $env:GITHUB_WORKSPACE "vcpkg_installed/x64-windows/bin") |
| 23 | +} |
| 24 | + |
| 25 | +$runtimeDirs = $candidateRuntimeDirs | Where-Object { $_ -and (Test-Path $_) } | Select-Object -Unique |
| 26 | +if (-not $runtimeDirs) { |
| 27 | + throw "Could not find any vcpkg runtime directories. Checked: $($candidateRuntimeDirs -join ', ')" |
| 28 | +} |
| 29 | + |
| 30 | +function Get-DllDependents { |
| 31 | + param([string]$BinaryPath) |
| 32 | + |
| 33 | + $output = & dumpbin /dependents $BinaryPath 2>$null |
| 34 | + if ($LASTEXITCODE -ne 0) { |
| 35 | + throw "dumpbin failed for '$BinaryPath'" |
| 36 | + } |
| 37 | + |
| 38 | + return $output | |
| 39 | + ForEach-Object { $_.Trim() } | |
| 40 | + Where-Object { $_ -match '^[A-Za-z0-9._-]+\.dll$' } | |
| 41 | + Sort-Object -Unique |
| 42 | +} |
| 43 | + |
| 44 | +function Find-RuntimeDllPath { |
| 45 | + param( |
| 46 | + [string]$DllName, |
| 47 | + [string[]]$SearchDirs |
| 48 | + ) |
| 49 | + |
| 50 | + foreach ($dir in $SearchDirs) { |
| 51 | + $candidate = Join-Path $dir $DllName |
| 52 | + if (Test-Path $candidate) { |
| 53 | + return $candidate |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + return $null |
| 58 | +} |
| 59 | + |
| 60 | +$seenDllNames = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase) |
| 61 | +$queuedBinaries = [System.Collections.Generic.Queue[string]]::new() |
| 62 | +$queuedBinaries.Enqueue($exePath) |
| 63 | +$bundledCount = 0 |
| 64 | +$bundledDllNames = [System.Collections.Generic.List[string]]::new() |
| 65 | + |
| 66 | +while ($queuedBinaries.Count -gt 0) { |
| 67 | + $binary = $queuedBinaries.Dequeue() |
| 68 | + foreach ($dllName in Get-DllDependents -BinaryPath $binary) { |
| 69 | + if (-not $seenDllNames.Add($dllName)) { |
| 70 | + continue |
| 71 | + } |
| 72 | + |
| 73 | + $sourceDll = Find-RuntimeDllPath -DllName $dllName -SearchDirs $runtimeDirs |
| 74 | + if (-not $sourceDll) { |
| 75 | + continue |
| 76 | + } |
| 77 | + |
| 78 | + $destDll = Join-Path $buildDirAbs $dllName |
| 79 | + Copy-Item $sourceDll $destDll -Force |
| 80 | + $bundledCount += 1 |
| 81 | + $bundledDllNames.Add($dllName) |
| 82 | + $queuedBinaries.Enqueue($destDll) |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +if ($bundledCount -eq 0) { |
| 87 | + throw "No vcpkg runtime DLLs were bundled for '$exePath'." |
| 88 | +} |
| 89 | + |
| 90 | +$bundledDllNames.Sort() |
| 91 | +Write-Host "Bundled $bundledCount runtime DLL(s) into '$buildDirAbs':" |
| 92 | +foreach ($dllName in $bundledDllNames) { |
| 93 | + Write-Host " - $dllName" |
| 94 | +} |
0 commit comments