This repository was archived by the owner on Apr 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbuild.ps1
More file actions
169 lines (139 loc) · 6.13 KB
/
Copy pathbuild.ps1
File metadata and controls
169 lines (139 loc) · 6.13 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
# HyTaLauncher Build Script
# Reads secrets from .env file and injects into Config.cs before build
param(
[switch]$Portable,
[switch]$Release,
[switch]$Sign
)
$ErrorActionPreference = "Stop"
# Read .env file
$envFile = ".env"
$apiKey = ""
$mirrorUrl = ""
$russifierUrl = ""
$onlineFixUrl = ""
$certPassword = ""
if (Test-Path $envFile) {
Get-Content $envFile | ForEach-Object {
if ($_ -match "^CURSEFORGE_API_KEY=(.+)$") {
$apiKey = $matches[1].Trim()
}
if ($_ -match "^MIRROR_URL=(.+)$") {
$mirrorUrl = $matches[1].Trim()
}
if ($_ -match "^RUSSIFIER_URL=(.+)$") {
$russifierUrl = $matches[1].Trim()
}
if ($_ -match "^ONLINEFIX_URL=(.+)$") {
$onlineFixUrl = $matches[1].Trim()
}
if ($_ -match "^CERT_PASSWORD=(.+)$") {
$certPassword = $matches[1].Trim()
}
}
}
# Function to sign executable
function Sign-Executable {
param([string]$FilePath)
$certPath = "HyTaLauncher.pfx"
if (-not (Test-Path $certPath)) {
Write-Host "Certificate not found. Run create-certificate.ps1 first." -ForegroundColor Yellow
return $false
}
if ([string]::IsNullOrEmpty($certPassword)) {
Write-Host "CERT_PASSWORD not found in .env file" -ForegroundColor Yellow
return $false
}
Write-Host "Signing $FilePath..." -ForegroundColor Cyan
try {
$certPassword_secure = ConvertTo-SecureString -String $certPassword -Force -AsPlainText
# Use signtool if available, otherwise use Set-AuthenticodeSignature
$signtool = "C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\signtool.exe"
if (Test-Path $signtool) {
& $signtool sign /f $certPath /p $certPassword /fd SHA256 /tr http://timestamp.digicert.com /td SHA256 $FilePath
} else {
# Fallback to PowerShell signing
$cert = Get-PfxCertificate -FilePath $certPath -Password $certPassword_secure
Set-AuthenticodeSignature -FilePath $FilePath -Certificate $cert -TimestampServer "http://timestamp.digicert.com" | Out-Null
}
Write-Host "Signed successfully: $FilePath" -ForegroundColor Green
return $true
}
catch {
Write-Host "Failed to sign: $_" -ForegroundColor Red
return $false
}
}
# Warnings for missing secrets
if ([string]::IsNullOrEmpty($apiKey)) {
Write-Host "Warning: CURSEFORGE_API_KEY not found - Mods feature will not work" -ForegroundColor Yellow
}
if ([string]::IsNullOrEmpty($mirrorUrl)) {
Write-Host "Warning: MIRROR_URL not found - Mirror feature will not work" -ForegroundColor Yellow
}
if ([string]::IsNullOrEmpty($russifierUrl)) {
Write-Host "Warning: RUSSIFIER_URL not found - Russifier feature will not work" -ForegroundColor Yellow
}
if ([string]::IsNullOrEmpty($onlineFixUrl)) {
Write-Host "Warning: ONLINEFIX_URL not found - Online fix feature will not work" -ForegroundColor Yellow
}
# Backup and modify Config.cs
$configPath = "HyTaLauncher\Config.cs"
$configContent = Get-Content $configPath -Raw
$configBackup = $configContent
# Escape special regex characters in replacement - use [regex]::Escape for pattern
$configContent = $configContent -replace [regex]::Escape('#{CURSEFORGE_API_KEY}#'), $apiKey
$configContent = $configContent -replace [regex]::Escape('#{MIRROR_URL}#'), $mirrorUrl
$configContent = $configContent -replace [regex]::Escape('#{RUSSIFIER_URL}#'), $russifierUrl
$configContent = $configContent -replace [regex]::Escape('#{ONLINEFIX_URL}#'), $onlineFixUrl
Set-Content $configPath $configContent
try {
# Build
$config = if ($Release) { "Release" } else { "Debug" }
Write-Host "Building HyTaLauncher ($config)..." -ForegroundColor Cyan
if ($Portable) {
dotnet publish HyTaLauncher -c $config -r win-x64 --self-contained true -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true
if ($LASTEXITCODE -eq 0) {
$exePath = "HyTaLauncher\bin\$config\net8.0-windows\win-x64\publish\HyTaLauncher.exe"
# Sign executable if requested
if ($Sign) {
Sign-Executable -FilePath $exePath
}
# Create portable zip
$publishDir = "HyTaLauncher\bin\$config\net8.0-windows\win-x64\publish"
$portableDir = "portable"
$version = "1.0.7"
$zipName = "HyTaLauncher_Portable_$version.zip"
if (Test-Path $portableDir) { Remove-Item -Recurse -Force $portableDir }
New-Item -ItemType Directory -Path $portableDir | Out-Null
Copy-Item "$publishDir\HyTaLauncher.exe" $portableDir
Copy-Item -Recurse "HyTaLauncher\Fonts" "$portableDir\Fonts"
Copy-Item -Recurse "HyTaLauncher\Languages" "$portableDir\Languages"
# Copy Addons folder if exists
if (Test-Path "HyTaLauncher\Addons") {
Copy-Item -Recurse "HyTaLauncher\Addons" "$portableDir\Addons"
}
if (Test-Path $zipName) { Remove-Item $zipName }
Compress-Archive -Path "$portableDir\*" -DestinationPath $zipName -CompressionLevel Optimal
Remove-Item -Recurse -Force $portableDir
Write-Host "Portable build created: $zipName" -ForegroundColor Green
}
} else {
dotnet build HyTaLauncher -c $config
if ($LASTEXITCODE -eq 0 -and $Sign) {
$exePath = "HyTaLauncher\bin\$config\net8.0-windows\HyTaLauncher.exe"
if (Test-Path $exePath) {
Sign-Executable -FilePath $exePath
}
}
}
if ($LASTEXITCODE -eq 0) {
Write-Host "Build successful!" -ForegroundColor Green
} else {
Write-Host "Build failed!" -ForegroundColor Red
}
}
finally {
# Restore Config.cs
Set-Content $configPath $configBackup
}