prepare-openssl-for-windows.ps1 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Run after `npm run tauri build`. Copies OpenSSL DLLs next to the release exe and builds dist-portable/ for distribution.
  2. # NSIS cannot be re-run without Tauri's plugin path; use dist-portable or install OpenSSL on target PCs.
  3. $ErrorActionPreference = "Stop"
  4. function Get-OpenSslBinDir {
  5. if ($env:OPENSSL_ROOT) {
  6. $b = Join-Path $env:OPENSSL_ROOT "bin"
  7. if (Test-Path (Join-Path $b "libcrypto-3-x64.dll")) { return $b }
  8. }
  9. foreach ($p in @(
  10. "C:\Program Files\OpenSSL-Win64\bin",
  11. "C:\Program Files (x86)\OpenSSL-Win64\bin"
  12. )) {
  13. if (Test-Path (Join-Path $p "libcrypto-3-x64.dll")) { return $p }
  14. }
  15. return $null
  16. }
  17. $ProjectRoot = Split-Path -Parent $PSScriptRoot
  18. $ReleaseDir = Join-Path $ProjectRoot "src-tauri\target\release"
  19. $PortableDir = Join-Path $ProjectRoot "dist-portable"
  20. if (-not (Test-Path $ReleaseDir)) {
  21. Write-Host "ERROR: $ReleaseDir not found. Run npm run tauri build first." -ForegroundColor Red
  22. exit 1
  23. }
  24. $sslBin = Get-OpenSslBinDir
  25. if (-not $sslBin) {
  26. Write-Host "ERROR: libcrypto-3-x64.dll not found." -ForegroundColor Red
  27. Write-Host "Install OpenSSL Win64 FULL from https://slproweb.com/products/Win32OpenSSL.html or set OPENSSL_ROOT."
  28. exit 1
  29. }
  30. $crypto = Join-Path $sslBin "libcrypto-3-x64.dll"
  31. $sslDll = Join-Path $sslBin "libssl-3-x64.dll"
  32. if (-not (Test-Path $sslDll)) {
  33. Write-Host "ERROR: libssl-3-x64.dll missing in $sslBin" -ForegroundColor Red
  34. exit 1
  35. }
  36. Copy-Item $crypto $ReleaseDir -Force
  37. Copy-Item $sslDll $ReleaseDir -Force
  38. Write-Host "Copied OpenSSL DLLs to $ReleaseDir"
  39. $mainExe = Get-ChildItem $ReleaseDir -Filter "*.exe" -File -ErrorAction SilentlyContinue |
  40. Sort-Object Length -Descending |
  41. Select-Object -First 1
  42. if (-not $mainExe) {
  43. Write-Host "WARN: No main exe found in release root; skipped dist-portable." -ForegroundColor Yellow
  44. exit 0
  45. }
  46. New-Item -ItemType Directory -Path $PortableDir -Force | Out-Null
  47. Copy-Item $mainExe.FullName $PortableDir -Force
  48. Copy-Item $crypto $PortableDir -Force
  49. Copy-Item $sslDll $PortableDir -Force
  50. $readme = @(
  51. "Buff client (portable folder)",
  52. "",
  53. "Copy EVERY file in this folder to the same directory on the target PC, then run the exe.",
  54. "Do not copy only the exe; OpenSSL DLLs are required.",
  55. "",
  56. "Files:",
  57. " - $($mainExe.Name)",
  58. " - libcrypto-3-x64.dll",
  59. " - libssl-3-x64.dll"
  60. ) -join [Environment]::NewLine
  61. Set-Content -Path (Join-Path $PortableDir "README-portable.txt") -Value $readme -Encoding UTF8
  62. Write-Host ""
  63. Write-Host "Portable folder ready: $PortableDir" -ForegroundColor Green
  64. Write-Host "Distribute the entire dist-portable directory (exe + 2 dlls + README-portable.txt)."