|
@@ -0,0 +1,88 @@
|
|
|
|
|
+param(
|
|
|
|
|
+ [switch]$RunBuild
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+# Post-build helper for Windows:
|
|
|
|
|
+# - optionally runs the tauri windows build when -RunBuild is passed
|
|
|
|
|
+# - finds the generated release EXE and copies it to a Chinese-named exe alongside the original
|
|
|
|
|
+
|
|
|
|
|
+Set-StrictMode -Version Latest
|
|
|
|
|
+
|
|
|
|
|
+$repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
|
|
|
+Set-Location $repoRoot
|
|
|
|
|
+
|
|
|
|
|
+if ($RunBuild) {
|
|
|
|
|
+ Write-Output "Running npm install and tauri windows build..."
|
|
|
|
|
+ npm install
|
|
|
|
|
+ npm run tauri:build:windows
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+$possibleDirs = @(
|
|
|
|
|
+ "$repoRoot\src-tauri\target\release",
|
|
|
|
|
+ "$repoRoot\src-tauri\target\x86_64-pc-windows-msvc\release",
|
|
|
|
|
+ "$repoRoot\src-tauri\target\x86_64-pc-windows-msvc\release\bundle\nsis"
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+$foundExe = $null
|
|
|
|
|
+$foundDir = $null
|
|
|
|
|
+foreach ($dir in $possibleDirs) {
|
|
|
|
|
+ if (-not (Test-Path $dir)) { continue }
|
|
|
|
|
+ $candidate = Get-ChildItem -Path $dir -Filter *.exe -File -Recurse -ErrorAction SilentlyContinue |
|
|
|
|
|
+ Where-Object { $_.Name -notmatch 'setup|bundle|uninstaller' } |
|
|
|
|
|
+ Sort-Object LastWriteTime -Descending |
|
|
|
|
|
+ Select-Object -First 1
|
|
|
|
|
+ if ($candidate) {
|
|
|
|
|
+ $foundExe = $candidate
|
|
|
|
|
+ $foundDir = $dir
|
|
|
|
|
+ break
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+if (-not $foundExe) {
|
|
|
|
|
+ Write-Error "No executable (.exe) found in any of: `n$($possibleDirs -join "`n")"
|
|
|
|
|
+ Exit 1
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+$destName = 'BUFF选品-STEAM扫货(游铛铛).exe'
|
|
|
|
|
+$tauriConf = Join-Path $repoRoot 'src-tauri\tauri.conf.json'
|
|
|
|
|
+$productName = $null
|
|
|
|
|
+if (Test-Path $tauriConf) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $json = Get-Content -Path $tauriConf -Raw | ConvertFrom-Json -ErrorAction Stop
|
|
|
|
|
+ if ($json.package -and $json.package.productName) {
|
|
|
|
|
+ $productName = $json.package.productName
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ Write-Warning "Failed to read tauri.conf.json: $($_.Exception.Message)"
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+if (-not $productName) {
|
|
|
|
|
+ $productName = $foundExe.BaseName
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+# Sanitize filename: remove characters invalid in Windows filenames
|
|
|
|
|
+$invalidChars = [System.IO.Path]::GetInvalidFileNameChars()
|
|
|
|
|
+$sanitized = $productName
|
|
|
|
|
+foreach ($c in $invalidChars) {
|
|
|
|
|
+ $sanitized = $sanitized -replace [regex]::Escape($c), '-'
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+# Ensure .exe extension
|
|
|
|
|
+if (-not $sanitized.ToLower().EndsWith('.exe')) {
|
|
|
|
|
+ $sanitized = "$sanitized.exe"
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+$destPath = Join-Path $foundDir $sanitized
|
|
|
|
|
+
|
|
|
|
|
+Try {
|
|
|
|
|
+ Copy-Item -Path $foundExe.FullName -Destination $destPath -Force
|
|
|
|
|
+ Write-Output "Copied '$($foundExe.Name)' -> '$sanitized' in $foundDir"
|
|
|
|
|
+} Catch {
|
|
|
|
|
+ Write-Error "Failed to copy exe: $($_.Exception.Message)"
|
|
|
|
|
+ Exit 1
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+Exit 0
|
|
|
|
|
+
|
|
|
|
|
+
|