-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-windows-package.ps1
More file actions
353 lines (276 loc) · 9.61 KB
/
Copy pathbuild-windows-package.ps1
File metadata and controls
353 lines (276 loc) · 9.61 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
param(
[string]$OutputDir = "dist",
[string]$PackageName = "chatify-windows-x64",
[switch]$SkipInstaller,
[string]$IsccPath = ""
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$RepoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $RepoRoot
$ReleaseTargetsLibrary = Join-Path $RepoRoot "scripts/release-targets.ps1"
if (-not (Test-Path -Path $ReleaseTargetsLibrary)) {
throw "Missing release target library script: $ReleaseTargetsLibrary"
}
. $ReleaseTargetsLibrary
function Assert-CommandAvailable {
param([Parameter(Mandatory = $true)][string]$CommandName)
if (-not (Get-Command $CommandName -ErrorAction SilentlyContinue)) {
throw "Required command '$CommandName' was not found in PATH."
}
}
function Get-CargoVersion {
param([string]$CargoTomlPath)
$versionLine = Select-String -Path $CargoTomlPath -Pattern '^version\s*=\s*"([^"]+)"' | Select-Object -First 1
if (-not $versionLine) {
throw "Could not determine package version from $CargoTomlPath"
}
return $versionLine.Matches[0].Groups[1].Value
}
function Resolve-IsccPath {
param([string]$ExplicitPath)
if (-not [string]::IsNullOrWhiteSpace($ExplicitPath)) {
if (Test-Path -Path $ExplicitPath) {
return (Resolve-Path $ExplicitPath).Path
}
throw "Provided -IsccPath does not exist: $ExplicitPath"
}
$command = Get-Command iscc.exe -ErrorAction SilentlyContinue
if ($command -and (Test-Path -Path $command.Source)) {
return $command.Source
}
$candidates = @(
(Join-Path ${env:ProgramFiles(x86)} "Inno Setup 6\ISCC.exe"),
(Join-Path $env:ProgramFiles "Inno Setup 6\\ISCC.exe"),
(Join-Path $env:LOCALAPPDATA "Programs\\Inno Setup 6\\ISCC.exe")
)
foreach ($candidate in $candidates) {
if (-not [string]::IsNullOrWhiteSpace($candidate) -and (Test-Path -Path $candidate)) {
return $candidate
}
}
return $null
}
function Get-ReleaseBinaryPath {
param(
[Parameter(Mandatory = $true)]
[string]$Binary
)
$binaryPath = Join-Path $RepoRoot ("target/release/{0}.exe" -f $Binary)
if (-not (Test-Path -Path $binaryPath)) {
throw ("Expected release binary was not found: {0}" -f $binaryPath)
}
return $binaryPath
}
function Invoke-CargoReleaseBuild {
param(
[Parameter(Mandatory = $true)]
[string]$Package,
[Parameter(Mandatory = $true)]
[string]$Binary
)
Write-Host ("Building {0} ({1})..." -f $Binary, $Package)
& cargo build --release --locked -p $Package --bin $Binary
if ($LASTEXITCODE -ne 0) {
throw ("Build failed for binary '{0}' in package '{1}'." -f $Binary, $Package)
}
}
Assert-CommandAvailable -CommandName "cargo"
$ReleaseTargets = Assert-ChatifyReleaseTargets
$Version = Get-CargoVersion -CargoTomlPath (Join-Path $RepoRoot "Cargo.toml")
Write-Host "Building release binaries..."
foreach ($target in $ReleaseTargets) {
Invoke-CargoReleaseBuild -Package $target.Package -Binary $target.Binary
}
$PackageRoot = Join-Path $RepoRoot $OutputDir
$PackageDir = Join-Path $PackageRoot $PackageName
$ZipPath = Join-Path $PackageRoot ("{0}.zip" -f $PackageName)
$InstallerPath = Join-Path $PackageRoot ("chatify-setup-{0}.exe" -f $Version)
if (Test-Path $PackageDir) {
Remove-Item -Recurse -Force $PackageDir
}
if (Test-Path $ZipPath) {
Remove-Item -Force $ZipPath
}
if (Test-Path $InstallerPath) {
Remove-Item -Force $InstallerPath
}
if (Test-Path "$InstallerPath.sha256") {
Remove-Item -Force "$InstallerPath.sha256"
}
New-Item -ItemType Directory -Path $PackageDir -Force | Out-Null
$serverBinaryPath = Get-ReleaseBinaryPath -Binary "chatify-server"
$clientBinaryPath = Get-ReleaseBinaryPath -Binary "chatify-client"
$launcherBinaryPath = Get-ReleaseBinaryPath -Binary "chatify"
Copy-Item $launcherBinaryPath (Join-Path $PackageDir "chatify.exe")
Copy-Item $serverBinaryPath (Join-Path $PackageDir "chatify-server.exe")
Copy-Item $clientBinaryPath (Join-Path $PackageDir "chatify-client.exe")
Copy-Item (Join-Path $RepoRoot "LICENSE") (Join-Path $PackageDir "LICENSE")
$ServerBat = @"
@echo off
setlocal
cd /d "%~dp0"
set HOST=0.0.0.0
set PORT=8765
set DATA_DIR=%LOCALAPPDATA%\Chatify
set DB_PATH=%DATA_DIR%\chatify.db
if not "%~1"=="" set HOST=%~1
if not "%~2"=="" set PORT=%~2
if not exist "%DATA_DIR%" mkdir "%DATA_DIR%"
echo Starting Chatify server on %HOST%:%PORT%
echo Server data: %DATA_DIR%
chatify-server.exe --host %HOST% --port %PORT% --db "%DB_PATH%" --enable-self-registration
"@
$ClientBat = @"
@echo off
setlocal
cd /d "%~dp0"
set HOST=127.0.0.1
set PORT=8765
if not "%~1"=="" set HOST=%~1
if not "%~2"=="" set PORT=%~2
echo Starting Chatify client to %HOST%:%PORT%
chatify-client.exe --host %HOST% --port %PORT%
"@
$StartAllBat = @"
@echo off
setlocal
cd /d "%~dp0"
set HOST=127.0.0.1
set PORT=8765
set DATA_DIR=%LOCALAPPDATA%\Chatify
set DB_PATH=%DATA_DIR%\chatify.db
if not "%~1"=="" set HOST=%~1
if not "%~2"=="" set PORT=%~2
echo Launching Chatify server and client...
if not exist "%DATA_DIR%" mkdir "%DATA_DIR%"
start "Chatify Server" cmd /k call "%~dp0start-server.bat" 0.0.0.0 %PORT%
timeout /t 1 /nobreak >nul
start "Chatify Client" cmd /k "cd /d %~dp0 && chatify-client.exe --host %HOST% --port %PORT%"
"@
$LauncherCmd = @"
@echo off
setlocal
cd /d "%~dp0"
set DEFAULT_HOST=127.0.0.1
set DEFAULT_PORT=8765
set DATA_DIR=%LOCALAPPDATA%\Chatify
set DB_PATH=%DATA_DIR%\chatify.db
if exist "%~dp0chatify.exe" (
"%~dp0chatify.exe"
exit /b %ERRORLEVEL%
)
:menu
cls
echo ===================================
echo Chatify Launcher
echo ===================================
echo [1] Host on this machine
echo [2] Join existing server
echo [Q] Quit
echo.
set /p CHOICE=Select mode:
if /I "%CHOICE%"=="1" goto host
if /I "%CHOICE%"=="2" goto join
if /I "%CHOICE%"=="Q" exit /b 0
echo Invalid option.
timeout /t 1 /nobreak >nul
goto menu
:host
set PORT=%DEFAULT_PORT%
set /p PORT=Server port [%DEFAULT_PORT%]:
if "%PORT%"=="" set PORT=%DEFAULT_PORT%
echo Starting server on 0.0.0.0:%PORT%
if not exist "%DATA_DIR%" mkdir "%DATA_DIR%"
start "Chatify Server" cmd /k call "%~dp0start-server.bat" 0.0.0.0 %PORT%
timeout /t 1 /nobreak >nul
echo Connecting local client to 127.0.0.1:%PORT%
start "Chatify Client" cmd /k "cd /d %~dp0 && chatify-client.exe --host 127.0.0.1 --port %PORT%"
exit /b 0
:join
set HOST=%DEFAULT_HOST%
set PORT=%DEFAULT_PORT%
set /p HOST=Server host/IP [%DEFAULT_HOST%]:
if "%HOST%"=="" set HOST=%DEFAULT_HOST%
set /p PORT=Server port [%DEFAULT_PORT%]:
if "%PORT%"=="" set PORT=%DEFAULT_PORT%
echo Connecting to %HOST%:%PORT%
chatify-client.exe --host %HOST% --port %PORT%
exit /b %ERRORLEVEL%
"@
$ReadmeTxt = @"
Chatify Windows Package
=======================
Files:
- chatify.exe
- chatify-server.exe
- chatify-client.exe
- chatify-launcher.cmd
- start-chatify.bat
- start-server.bat
- start-client.bat
Quick Start:
1) Run chatify.exe
Launcher modes:
- [1] Start here (starts a local server + local client)
- [2] Host for others (starts a LAN server + local client)
- [3] Join a server (choose a saved server or enter host/port)
- [4] Server only
- [5] Manage saved servers
- [6] Open README
After first setup:
- Press Enter in chatify.exe to reconnect with the last saved mode, host, and port.
Manual mode:
1) Run start-server.bat
2) Run start-client.bat
Server data:
- The Windows launcher stores server data in %LOCALAPPDATA%\Chatify.
- The database key is written as %LOCALAPPDATA%\Chatify\chatify.db.key.
Optional parameters:
- start-server.bat [host] [port]
- start-client.bat [host] [port]
- start-chatify.bat [host] [port]
Examples:
- start-server.bat 0.0.0.0 8765
- start-client.bat 127.0.0.1 8765
Integrity:
- chatify-windows-x64.zip.sha256 contains SHA256 for the ZIP.
"@
Set-Content -Path (Join-Path $PackageDir "start-server.bat") -Value $ServerBat -Encoding ASCII
Set-Content -Path (Join-Path $PackageDir "start-client.bat") -Value $ClientBat -Encoding ASCII
Set-Content -Path (Join-Path $PackageDir "start-chatify.bat") -Value $StartAllBat -Encoding ASCII
Set-Content -Path (Join-Path $PackageDir "chatify-launcher.cmd") -Value $LauncherCmd -Encoding ASCII
Set-Content -Path (Join-Path $PackageDir "README.txt") -Value $ReadmeTxt -Encoding ASCII
Compress-Archive -Path $PackageDir -DestinationPath $ZipPath -CompressionLevel Optimal
$ZipHash = (Get-FileHash -Path $ZipPath -Algorithm SHA256).Hash.ToLowerInvariant()
$HashFilePath = "$ZipPath.sha256"
"$ZipHash $([System.IO.Path]::GetFileName($ZipPath))" | Set-Content -Path $HashFilePath -Encoding ASCII
Write-Host "Package created: $ZipPath"
Write-Host "Checksum created: $HashFilePath"
Write-Host "Contents ready in: $PackageDir"
if ($SkipInstaller) {
Write-Host "Installer build skipped (-SkipInstaller)."
return
}
$CompilerPath = Resolve-IsccPath -ExplicitPath $IsccPath
if (-not $CompilerPath) {
Write-Warning "ISCC.exe not found. Install Inno Setup 6 or pass -IsccPath to generate a Windows installer."
return
}
$InstallerScript = Join-Path $RepoRoot "windows/chatify-installer.iss"
if (-not (Test-Path $InstallerScript)) {
throw "Missing installer script: $InstallerScript"
}
Write-Host "Building installer with Inno Setup..."
& $CompilerPath "/DSourceDir=$PackageDir" "/DOutputDir=$PackageRoot" "/DMyAppVersion=$Version" $InstallerScript
if ($LASTEXITCODE -ne 0) {
throw "Installer build failed."
}
if (-not (Test-Path $InstallerPath)) {
throw "Installer was not generated at expected path: $InstallerPath"
}
$InstallerHash = (Get-FileHash -Path $InstallerPath -Algorithm SHA256).Hash.ToLowerInvariant()
$InstallerHashPath = "$InstallerPath.sha256"
"$InstallerHash $([System.IO.Path]::GetFileName($InstallerPath))" | Set-Content -Path $InstallerHashPath -Encoding ASCII
Write-Host "Installer created: $InstallerPath"
Write-Host "Installer checksum created: $InstallerHashPath"