build-windows.ps1 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. param(
  2. [switch]$RunBuild
  3. )
  4. # Post-build helper (Steam求购 custom edition / dakehu):
  5. # Copies release EXE to SteamQG.exe. Does NOT overwrite steamSH_V*.exe or SteamSH_Portable.zip.
  6. Set-StrictMode -Version Latest
  7. $repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
  8. Set-Location $repoRoot
  9. if ($RunBuild) {
  10. Write-Output "Running npm install and tauri windows build..."
  11. npm install
  12. npm run tauri:build:windows
  13. }
  14. # Prefer known app binary names, then largest exe > 15MB (skip installer/setup)
  15. $searchDirs = @(
  16. "$repoRoot\src-tauri\target\release",
  17. "$repoRoot\src-tauri\target\x86_64-pc-windows-msvc\release"
  18. )
  19. $foundExe = $null
  20. foreach ($dir in $searchDirs) {
  21. if (-not (Test-Path $dir)) { continue }
  22. foreach ($name in @("steamSH.exe", "your-app-name.exe")) {
  23. $p = Join-Path $dir $name
  24. if (Test-Path $p) {
  25. $item = Get-Item $p
  26. if ($item.Length -gt 15MB) {
  27. $foundExe = $item
  28. break
  29. }
  30. }
  31. }
  32. if ($foundExe) { break }
  33. $candidate = Get-ChildItem -Path $dir -Filter *.exe -File -ErrorAction SilentlyContinue |
  34. Where-Object { $_.Name -notmatch 'setup|bundle|uninstall|installer|SteamQG' -and $_.Length -gt 15MB } |
  35. Sort-Object Length -Descending |
  36. Select-Object -First 1
  37. if ($candidate) {
  38. $foundExe = $candidate
  39. break
  40. }
  41. }
  42. if (-not $foundExe) {
  43. Write-Error "No app executable (>15MB) found under release dirs"
  44. Exit 1
  45. }
  46. $destName = 'SteamQG.exe'
  47. $destPath = Join-Path $foundExe.DirectoryName $destName
  48. $rootDestPath = Join-Path $repoRoot $destName
  49. Try {
  50. Copy-Item -Path $foundExe.FullName -Destination $destPath -Force
  51. Write-Output "Copied '$($foundExe.Name)' ($([math]::Round($foundExe.Length/1MB,2)) MB) -> '$destName' in $($foundExe.DirectoryName)"
  52. Copy-Item -Path $foundExe.FullName -Destination $rootDestPath -Force
  53. Write-Output "Copied -> '$destName' in $repoRoot"
  54. Write-Output "Note: old artifacts steamSH_V*.exe / SteamSH_Portable.zip were NOT modified"
  55. } Catch {
  56. Write-Error "Failed to copy exe: $($_.Exception.Message)"
  57. Exit 1
  58. }
  59. Exit 0