-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode_image.ps1
More file actions
61 lines (49 loc) · 2.89 KB
/
Copy pathencode_image.ps1
File metadata and controls
61 lines (49 loc) · 2.89 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
# ===================================================================
# Pack-Assets.ps1
# Run this ONCE (or again whenever you swap images) on your own machine.
# It reads your two PNGs and your SOURCE script (which still has the
# empty $LogoBase64 / $HeroBase64 placeholders), bakes the images in as
# Base64 text, and writes the result to a separate BUILD file. The
# source template is never modified, so you can re-run this as many
# times as you like without worrying about state. Compile the build
# file with ps2exe whenever you're ready.
# ===================================================================
param(
[string]$SourcePath = ".\Script_Exe_BurntToast.ps1",
[string]$OutputPath = ".\build\Script_Exe_BurntToast.ps1",
[string]$LogoPath = ".\water-logo.png",
[string]$HeroPath = ".\water-banner.png"
)
if (-not (Test-Path $SourcePath)) { throw "Can't find $SourcePath" }
if (-not (Test-Path $LogoPath)) { throw "Can't find $LogoPath" }
if (-not (Test-Path $HeroPath)) { throw "Can't find $HeroPath" }
$resolvedSource = (Resolve-Path $SourcePath).Path
$resolvedOutput = [IO.Path]::GetFullPath((Join-Path (Get-Location) $OutputPath))
if ($resolvedSource -eq $resolvedOutput) {
throw "SourcePath and OutputPath resolve to the same file ($resolvedSource). Pick a different -OutputPath so your source template stays untouched."
}
$logoB64 = [Convert]::ToBase64String([IO.File]::ReadAllBytes((Resolve-Path $LogoPath)))
$heroB64 = [Convert]::ToBase64String([IO.File]::ReadAllBytes((Resolve-Path $HeroPath)))
$content = Get-Content -Path $SourcePath -Raw
$logoPattern = '\$LogoBase64\s*=\s*".*?"\s*#\s*<-- PACK:LOGO -->'
$heroPattern = '\$HeroBase64\s*=\s*".*?"\s*#\s*<-- PACK:HERO -->'
if ($content -notmatch $logoPattern) {
throw "Couldn't find the '# <-- PACK:LOGO -->' placeholder line in $SourcePath. Is this the right source file?"
}
if ($content -notmatch $heroPattern) {
throw "Couldn't find the '# <-- PACK:HERO -->' placeholder line in $SourcePath. Is this the right source file?"
}
$content = $content -replace $logoPattern, "`$LogoBase64 = `"$logoB64`" # <-- PACK:LOGO -->"
$content = $content -replace $heroPattern, "`$HeroBase64 = `"$heroB64`" # <-- PACK:HERO -->"
$outputDir = Split-Path $resolvedOutput -Parent
if ($outputDir -and -not (Test-Path $outputDir)) {
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
}
Set-Content -Path $resolvedOutput -Value $content -Encoding utf8
$totalKB = [math]::Round(($logoB64.Length + $heroB64.Length) / 1024, 1)
Write-Host "Done. Built $resolvedOutput with both images baked in (~$totalKB KB)."
Write-Host "Source template $resolvedSource was left untouched -- re-run this any time you swap images."
Write-Host ""
Write-Host "Next: compile the build file with ps2exe, e.g."
$exampleCmd = 'Invoke-ps2exe -inputFile "' + $resolvedOutput + '" -outputFile ".\HydrationReminder.exe" -supportOS -noConsole'
Write-Host " $exampleCmd"