-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathupdate_jar.ps1
More file actions
74 lines (61 loc) · 2.52 KB
/
update_jar.ps1
File metadata and controls
74 lines (61 loc) · 2.52 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
param(
[string]$JarPath = "custom_spider.jar",
[string]$SourceDir = "goProxy"
)
# Ensure 7z is available
$7zCmd = Get-Command "7z" -ErrorAction SilentlyContinue
if (-not $7zCmd) {
Write-Error "Please ensure 7-Zip is installed and added to your system PATH."
exit 1
}
# Check if target file exists
if (-not (Test-Path $JarPath)) {
Write-Error "Target file not found: $JarPath"
exit 1
}
$ArmPath = Join-Path $SourceDir "goProxy-arm"
$Arm64Path = Join-Path $SourceDir "goProxy-arm64"
if (-not (Test-Path $ArmPath) -or -not (Test-Path $Arm64Path)) {
Write-Error "Compiled goProxy files not found. Please run build_goproxy.ps1 first."
exit 1
}
Write-Host "Updating assets directory in $JarPath..." -ForegroundColor Cyan
$TempAssetsDir = "temp_assets_for_jar\assets"
New-Item -ItemType Directory -Force -Path $TempAssetsDir | Out-Null
Copy-Item -Path $ArmPath -Destination $TempAssetsDir -Force
Copy-Item -Path $Arm64Path -Destination $TempAssetsDir -Force
try {
# 为了避免在 jar 中创建 temp_assets_for_jar 目录,我们需要进入到该目录后再执行打包
# 使用 Push-Location 和 Pop-Location 来切换工作目录
Push-Location "temp_assets_for_jar"
# 构造相对路径的 jar 文件路径,因为我们改变了工作目录
$AbsoluteJarPath = Resolve-Path "..\$JarPath"
$updateCmd = "7z u `"$AbsoluteJarPath`" `"assets\*`""
Invoke-Expression $updateCmd | Out-Null
if ($LASTEXITCODE -ne 0) {
throw "7z command failed with exit code: $LASTEXITCODE"
}
Pop-Location
Write-Host "Successfully updated files to assets directory in $JarPath." -ForegroundColor Green
} catch {
if ((Get-Location).Path -like "*temp_assets_for_jar*") {
Pop-Location
}
Write-Error "Failed to update jar file: $_"
Remove-Item -Path "temp_assets_for_jar" -Recurse -Force -ErrorAction SilentlyContinue
exit 1
} finally {
Remove-Item -Path "temp_assets_for_jar" -Recurse -Force -ErrorAction SilentlyContinue
}
Write-Host "Calculating MD5 for $JarPath..." -ForegroundColor Cyan
try {
$md5Hash = (Get-FileHash -Path $JarPath -Algorithm MD5).Hash.ToLower()
$Md5FilePath = "$JarPath.md5"
$md5Hash | Out-File -FilePath $Md5FilePath -Encoding ascii
Write-Host "MD5 Calculation complete: $md5Hash" -ForegroundColor Green
Write-Host "MD5 written to file: $Md5FilePath" -ForegroundColor Green
} catch {
Write-Error "Failed to calculate MD5: $_"
exit 1
}
Write-Host "All operations completed successfully!" -ForegroundColor Green