Repository navigation
Expand file tree
/
Copy pathcompile.ps1
More file actions
57 lines (54 loc) · 2.92 KB
/
Copy pathcompile.ps1
File metadata and controls
57 lines (54 loc) · 2.92 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
# Compile GameBoost.cs -> GameBoost.exe with embedded icon (csc /win32icon)
# Note: keep this file ASCII-only. PowerShell 5.1 reads no-BOM files as ANSI/GBK,
# and non-ASCII string literals break parsing (caused a false COMPILE_OK before).
# Resolve paths relative to this script so the repo is portable to any directory.
$root = if ($PSScriptRoot) { $PSScriptRoot } else { Split-Path -Parent $MyInvocation.MyCommand.Path }
$src = Join-Path $root "src\GameBoost.cs"
$out = Join-Path $root "GameBoost.new.exe"
$final = Join-Path $root "GameBoost.exe"
$ico = Join-Path $root "icon\icon.ico"
$resultFile = Join-Path $root "compile_result.txt"
$fw = "$env:WINDIR\Microsoft.NET\Framework64\v4.0.30319"
if (-not (Test-Path "$fw\csc.exe")) { $fw = "$env:WINDIR\Microsoft.NET\Framework\v4.0.30319" }
$csc = "$fw\csc.exe"
# csc.exe is a .NET app: at startup it builds a case-insensitive env dictionary.
# If proxy tools inject both http_proxy and HTTP_PROXY, csc crashes with
# "An item with the same key has already been added" before compiling anything.
# Clear all proxy vars for this session so the child process inherits a clean env.
foreach ($n in @('http_proxy','https_proxy','all_proxy','HTTP_PROXY','HTTPS_PROXY','ALL_PROXY')) {
Remove-Item "env:$n" -ErrorAction SilentlyContinue
}
try {
if (-not (Test-Path $csc)) { throw "csc.exe not found under $fw" }
$args = @(
"/nologo", "/target:winexe", "/platform:anycpu", "/unsafe",
"/out:`"$out`"",
"/r:System.Windows.Forms.dll", "/r:System.Drawing.dll",
"/r:System.Web.Extensions.dll", "/r:System.Management.dll",
"/r:System.ServiceProcess.dll"
)
if (Test-Path $ico) { $args += "/win32icon:`"$ico`"" }
$args += "`"$src`""
# csc writes localized output; force UTF-8 to keep stderr pipe small
$p = Start-Process -FilePath $csc -ArgumentList $args -NoNewWindow -Wait -PassThru `
-RedirectStandardOutput "$env:TEMP\gb_csc_out.txt" -RedirectStandardError "$env:TEMP\gb_csc_err.txt"
if ($p.ExitCode -ne 0 -or -not (Test-Path $out)) {
throw ("csc failed: " + (Get-Content "$env:TEMP\gb_csc_err.txt", "$env:TEMP\gb_csc_out.txt" -ErrorAction SilentlyContinue | Out-String))
}
if (Test-Path $final) {
try { Remove-Item $final -Force -ErrorAction Stop }
catch {
# target exe locked by a running instance: rename it aside, then retry
try { Rename-Item $final "$final.bak" -Force } catch {}
Start-Sleep -Seconds 1
if (Test-Path $final) { Remove-Item $final -Force -ErrorAction SilentlyContinue }
}
}
Move-Item $out $final -Force -ErrorAction Stop
if (-not (Test-Path $final)) { throw "deploy failed: target exe missing" }
"COMPILE_OK" | Out-File $resultFile -Encoding utf8
} catch {
$msg = "COMPILE_FAIL: " + $_.Exception.Message
if ($_.ErrorDetails) { $msg += "`nDETAIL: " + $_.ErrorDetails.Message }
$msg | Out-File $resultFile -Encoding utf8
}