-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
79 lines (69 loc) · 2.43 KB
/
Copy pathbuild.ps1
File metadata and controls
79 lines (69 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
param(
[switch]$Clean,
[string]$Icon
)
$ErrorActionPreference = 'Stop'
# Ensure venv
if (-not (Test-Path .\.venv)) {
python -m venv .venv
}
. .\.venv\Scripts\Activate.ps1
pip install -r requirements.txt
# Optionally convert PNG icon to ICO for Windows executables
function Convert-PngToIco($pngPath, $icoOut){
$code = @'
from PIL import Image
import sys
png, ico = sys.argv[1], sys.argv[2]
img = Image.open(png).convert("RGBA")
# Build multi-size ICO for best scaling
sizes = [(16,16),(24,24),(32,32),(48,48),(64,64),(128,128),(256,256)]
img.save(ico, format='ICO', sizes=sizes)
'@
$tmpScript = Join-Path $env:TEMP ('png2ico_' + [System.Guid]::NewGuid().ToString('N') + '.py')
Set-Content -Path $tmpScript -Value $code -Encoding UTF8 -NoNewline
& python $tmpScript $pngPath $icoOut
Remove-Item $tmpScript -ErrorAction SilentlyContinue
}
# Determine icon file to use
$iconIco = $null
if ($Icon) {
if ($Icon.ToLower().EndsWith('.ico')) {
$iconIco = $Icon
} elseif (Test-Path $Icon) {
pip install pillow | Out-Null
$tmpIco = Join-Path $PWD 'icon.auto.ico'
Convert-PngToIco -pngPath $Icon -icoOut $tmpIco
$iconIco = $tmpIco
}
} elseif (Test-Path 'icon.ico') {
$iconIco = 'icon.ico'
} elseif (Test-Path 'icon.png') {
pip install pillow | Out-Null
$tmpIco = Join-Path $PWD 'icon.auto.ico'
Convert-PngToIco -pngPath 'icon.png' -icoOut $tmpIco
$iconIco = $tmpIco
}
# PyInstaller build (smaller with UPX, fast and simple)
pip install pyinstaller
$spec = 'better_advanced_paste.spec'
if (-not (Test-Path $spec)) { throw "Missing $spec" }
if ($Clean) {
Remove-Item -Recurse -Force build, dist -ErrorAction SilentlyContinue
}
# Attempt to use UPX if available in PATH (PyInstaller picks it up automatically)
$hasUpx = (Get-Command upx -ErrorAction SilentlyContinue) -ne $null
if ($hasUpx) { Write-Host 'UPX found: enabling executable compression' }
# Ensure spec references icon.ico; if we only have a generated icon, temporarily copy
if ($iconIco -and (Split-Path -Leaf $iconIco) -ne 'icon.ico') {
Copy-Item $iconIco -Destination 'icon.ico' -Force
}
pyinstaller --noconfirm --clean $spec
# Place final exe at repo root for convenience
$exe = Join-Path 'dist' 'BetterAdvancedPaste.exe'
if (Test-Path $exe) {
Copy-Item $exe -Destination . -Force
Write-Host "Built -> $(Resolve-Path .\BetterAdvancedPaste.exe)"
} else {
Write-Warning 'Build did not produce expected EXE.'
}