forked from xrgzs/xrsys-osc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
129 lines (116 loc) · 4.63 KB
/
build.ps1
File metadata and controls
129 lines (116 loc) · 4.63 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
#Requires -Version 7
$ErrorActionPreference = 'Stop'
# 切换到当前目录
Set-Location $PSScriptRoot
# 下载文件
function Test-Hashes {
param (
[hashtable]$Hashes,
[string]$Algorithm
)
return $Hashes.GetEnumerator() | ForEach-Object {
$file = $_.Key
$expectedHash = $_.Value
Write-Host -ForegroundColor Blue "Verifying $file $Algorithm hash ..."
Write-Host -ForegroundColor Gray "Expected: $expectedHash"
$actualHash = (Get-FileHash -Path $file -Algorithm $Algorithm).Hash
Write-Host -ForegroundColor Gray "Actual : $actualHash"
if ($actualHash -ne $expectedHash) {
# return $false
Write-Error "$file hash not match."
}
else {
Write-Host -ForegroundColor Green "$file hash match."
}
}
}
function Test-SHA256 ([hashtable]$Hashes) { return Test-Hashes -Hashes $Hashes -Algorithm "SHA256" }
function Invoke-RobustRequest {
param(
[Parameter(Mandatory = $true)]
[string]$Uri,
[Parameter(Mandatory = $true)]
[string]$OutFile
)
if ([string]::IsNullOrWhiteSpace($Uri)) {
throw "URL cannot be null or empty! OutFile: $OutFile"
}
for ($retry = 1; $retry -le 3; $retry++) {
try {
Invoke-WebRequest -Uri $Uri -OutFile $OutFile -ConnectionTimeoutSeconds 5 -AllowInsecureRedirect
return
}
catch {
if ($retry -eq 3) {
throw "Failed after 3 retries! URL: '$Uri', Error: $_"
}
Write-Host "Retry $retry failed for '$Uri', trying again ($retry / 3)... Error: $_"
Start-Sleep -Seconds 2
}
}
}
function Get-LanzouFile {
param(
[Parameter(Mandatory = $true, Position = 0)]
[string]
$Uri,
[Parameter(Mandatory = $true, Position = 1)]
[string]
$OutFile
)
Write-Host "Downloading $Uri to $OutFile..."
try {
Write-Host "Using api.xrgzs.top to parse link..."
Invoke-RobustRequest -Uri "https://api.xrgzs.top/sdlp/lanzou/?type=down&url=$Uri" -OutFile $OutFile
}
catch {
try {
Write-Host "Using lz.qaiu.top to parse link..."
Invoke-RobustRequest -Uri "https://lz.qaiu.top/parser?url=$Uri" -OutFile $OutFile
}
catch {
Write-Error "Failed to download $Uri. ($_)"
}
}
}
# 检查
if (Test-Path "$env:NSISDIR\makensis.exe") {
$nsisDir = "$env:NSISDIR"
}
elseif (Test-Path "C:\Program Files (x86)\NSIS\makensis.exe") {
$nsisDir = "C:\Program Files (x86)\NSIS"
}
else {
Write-Host "Cannot find nsis!"
exit 1
}
Write-Host "version: $env:GITHUB_WORKFLOW_VERSION"
Write-Host "nsisDir: $nsisDir"
if (Test-Path 'osc\xrsoft.exe') {
Write-Host "xrsoft.exe already exists."
}
else {
# 下载所需文件
# Get-LanzouFile -Uri "https://xrgzs.lanzouv.com/idHOf2bfs3te" -OutFile "osc\xrkms\KMS_VL_ALL_AIO.cmd"
Invoke-RobustRequest -Uri "https://nos.netease.com/ysf/bb28b9686ffcacb2876588c53377c00a.cmd" -OutFile "osc\xrkms\KMS_VL_ALL_AIO.cmd"
# Get-LanzouFile -Uri "https://xrgzs.lanzoum.com/ivVCK3nlbwxe" -OutFile "osc\xrkms\HEU.exe"
Invoke-RobustRequest -Uri "https://nos.netease.com/ysf/952745b06c87be10fad90403f9c8f5d6.exe" -OutFile "osc\xrkms\HEU.exe"
# Get-LanzouFile -Uri "https://xrgzs.lanzouv.com/iqnTr2wxjufc" -OutFile "osc\xrsoft.exe"
Invoke-RobustRequest -Uri "https://raw.githubusercontent.com/massgravel/Microsoft-Activation-Scripts/refs/heads/master/MAS/Separate-Files-Version/Activators/TSforge_Activation.cmd" -OutFile "osc\xrkms\TSforge_Activation.cmd"
# 下载其他文件
Invoke-RobustRequest -Uri "https://pan.qzyun.net/f/MlLjf0/oscoffline.bat" -OutFile "osc\oscoffline.bat" -ErrorAction Stop
}
# 验证文件
Test-SHA256 -Hashes @{
"osc\xrkms\KMS_VL_ALL_AIO.cmd" = "FB229FDCBA766AC801C635CF398ACA3158B25A659FBB7326946E951B5ED0EACA"
"osc\xrkms\HEU.exe" = "C90C4330DFB4917462B15C35D7A0AF5FA926C4922AC5AADD9978A844B1193FA6"
}
# 构建
if (-not $env:GITHUB_WORKFLOW_VERSION) {
$env:GITHUB_WORKFLOW_VERSION = "2.6.0.0"
}
Set-Content -Path "osc\apifiles\Version.txt" -Value $env:GITHUB_WORKFLOW_VERSION
& "$nsisDir\makensis.exe" /V4 /DCUSTOM_VERSION=$env:GITHUB_WORKFLOW_VERSION "osc.nsi" || exit 1
$env:GITHUB_WORKFLOW_VERSION | Out-File -FilePath "osc.exe.ver"
(Get-FileHash -Path "osc.exe" -Algorithm SHA256).Hash | Out-File -FilePath "osc.exe.sha256"
(Get-FileHash -Path "osc.exe" -Algorithm MD5).Hash | Out-File -FilePath "osc.exe.md5"