feat(Go_Updater): 添加全新 Go 语言实现的自动更新器

- 新增多个源文件和目录,包括 app.rc、assets、build 脚本等
- 实现了与 MirrorChyan API 交互的客户端逻辑
- 添加了版本检查、更新检测和下载 URL 生成等功能
- 嵌入了配置模板和资源文件系统
- 提供了完整的构建和发布流程
This commit is contained in:
2025-07-20 16:30:14 +08:00
parent 97c283797a
commit 228e66315c
32 changed files with 8226 additions and 0 deletions

111
Go_Updater/build.ps1 Normal file
View File

@@ -0,0 +1,111 @@
# Lightweight Updater Build Script (PowerShell)
param(
[string]$Version = "1.0.0",
[string]$OutputName = "AUTO_MAA_Go_Updater.exe",
[switch]$Compress = $false
)
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "AUTO_MAA_Go_Updater Build Script" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
# Set build variables
$BuildDir = "build"
$DistDir = "dist"
$BuildTime = (Get-Date).ToString("yyyy-MM-ddTHH:mm:ssZ")
# Get git commit hash
try {
$GitCommit = (git rev-parse --short HEAD 2>$null).Trim()
if (-not $GitCommit) { $GitCommit = "unknown" }
} catch {
$GitCommit = "unknown"
}
Write-Host "Build Information:" -ForegroundColor Yellow
Write-Host "- Version: $Version"
Write-Host "- Build Time: $BuildTime"
Write-Host "- Git Commit: $GitCommit"
Write-Host "- Target: Windows 64-bit"
Write-Host ""
# Create build directories
if (-not (Test-Path $BuildDir)) { New-Item -ItemType Directory -Path $BuildDir | Out-Null }
if (-not (Test-Path $DistDir)) { New-Item -ItemType Directory -Path $DistDir | Out-Null }
# Set environment variables
$env:GOOS = "windows"
$env:GOARCH = "amd64"
$env:CGO_ENABLED = "1"
# Set build flags
$LdFlags = "-s -w -X lightweight-updater/version.Version=$Version -X lightweight-updater/version.BuildTime=$BuildTime -X lightweight-updater/version.GitCommit=$GitCommit"
Write-Host "Building application..." -ForegroundColor Green
# Ensure icon resource is compiled
if (-not (Test-Path "app.syso")) {
Write-Host "Compiling icon resource..." -ForegroundColor Yellow
if (Get-Command rsrc -ErrorAction SilentlyContinue) {
rsrc -ico icon/AUTO_MAA_Go_Updater.ico -o app.syso
if ($LASTEXITCODE -ne 0) {
Write-Host "Warning: Failed to compile icon resource" -ForegroundColor Yellow
} else {
Write-Host "Icon resource compiled successfully" -ForegroundColor Green
}
} else {
Write-Host "Warning: rsrc not found. Install with: go install github.com/akavel/rsrc@latest" -ForegroundColor Yellow
}
}
# Build the application
$BuildCommand = "go build -ldflags=`"$LdFlags`" -o $BuildDir\$OutputName ."
Invoke-Expression $BuildCommand
if ($LASTEXITCODE -ne 0) {
Write-Host "Build failed!" -ForegroundColor Red
exit 1
}
Write-Host "Build completed successfully!" -ForegroundColor Green
# Get file information
$OutputFile = Get-Item "$BuildDir\$OutputName"
$FileSizeMB = [math]::Round($OutputFile.Length / 1MB, 2)
Write-Host ""
Write-Host "Build Results:" -ForegroundColor Yellow
Write-Host "- Output: $($OutputFile.FullName)"
Write-Host "- Size: $($OutputFile.Length) bytes (~$FileSizeMB MB)"
# Check file size requirement
if ($FileSizeMB -gt 10) {
Write-Host "WARNING: File size exceeds 10MB requirement!" -ForegroundColor Red
} else {
Write-Host "File size meets requirements (<10MB)" -ForegroundColor Green
}
# Optional UPX compression
if ($Compress) {
Write-Host ""
Write-Host "Compressing with UPX..." -ForegroundColor Yellow
if (Get-Command upx -ErrorAction SilentlyContinue) {
upx --best "$BuildDir\$OutputName"
$CompressedFile = Get-Item "$BuildDir\$OutputName"
$CompressedSizeMB = [math]::Round($CompressedFile.Length / 1MB, 2)
Write-Host "- Compressed Size: $($CompressedFile.Length) bytes (~$CompressedSizeMB MB)" -ForegroundColor Green
} else {
Write-Host "UPX not found. Skipping compression." -ForegroundColor Yellow
}
}
# Copy to dist directory
Copy-Item "$BuildDir\$OutputName" "$DistDir\$OutputName" -Force
Write-Host "- Copied to: $DistDir\$OutputName"
Write-Host ""
Write-Host "Build script completed successfully!" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan