-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
122 lines (115 loc) · 4.62 KB
/
build.ps1
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
$ErrorActionPreference = 'Stop'
# 切换到当前目录
Set-Location $PSScriptRoot
# 下载文件
function Get-LanzouLink {
param(
[Parameter(Mandatory = $true, Position = 0)]
[string]
$Uri
)
$sharekey = $Uri -split '/' | Select-Object -Last 1
if ((Invoke-RestMethod -Uri "https://lanzoui.com/$sharekey") -match 'src="(\/fn\?.\w+)') {
$fn = Invoke-RestMethod -Uri ('https://lanzoui.com/' + $Matches[1])
}
else {
throw "Failed to get fn. Please check whether the URL is correct."
}
if ($fn -match '\/ajaxm\.php\?file=\d+') {
$ajaxm = $Matches[0]
}
else {
throw "Failed to get ajaxm.php."
}
if ($fn -match "'sign':'(\w+)'") {
$sign = $Matches[1]
}
else {
throw "Failed to get sign."
}
$ajax = Invoke-RestMethod -Uri ('https://lanzoui.com/' + $ajaxm) -Method Post `
-Headers @{ referer = "https://lanzoui.com/" } `
-Body @{ 'action' = 'downprocess'; 'signs' = '?ctdf'; 'sign' = $sign; 'kd' = '1' }
$directlink = $ajax.dom + '/file/' + $ajax.url
try {
Invoke-WebRequest -Uri $directlink -Method Head -MaximumRedirection 0 -ErrorAction SilentlyContinue `
-Headers @{ "Accept-Language" = "zh-CN,zh;q=0.9" }
}
catch {
$directlink = $_.Exception.Response.Headers.Location.OriginalString
}
Write-Host -ForegroundColor Yellow "Direct Link of $sharekey is: $directlink"
if ($directlink) {
return $directlink
}
else {
throw "Failed to get direct link."
}
}
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 PowerShell Function to parse link..."
$directlink = Get-LanzouLink -Uri $Uri
Invoke-WebRequest -Uri $directlink -OutFile $OutFile -ConnectionTimeoutSeconds 5 -AllowInsecureRedirect
}
catch {
try {
Write-Host "Using api.xrgzs.top to parse link..."
Invoke-WebRequest -Uri "https://api.xrgzs.top/lanzou/?type=down&url=$Uri" -OutFile $OutFile -ConnectionTimeoutSeconds 5 -AllowInsecureRedirect
}
catch {
try {
Write-Host "Using api.hanximeng.com to parse link..."
Invoke-WebRequest -Uri "https://api.hanximeng.com/lanzou/?type=down&url=$Uri" -OutFile $OutFile -ConnectionTimeoutSeconds 5 -AllowInsecureRedirect
}
catch {
try {
Write-Host "Using lz.qaiu.top to parse link..."
Invoke-WebRequest -Uri "https://lz.qaiu.top/parser?url=$Uri" -OutFile $OutFile -ConnectionTimeoutSeconds 5 -AllowInsecureRedirect
}
catch {
Write-Error "Failed to download $Uri. ($_)"
}
}
}
}
}
# 检查
Write-Host "version: $env:GITHUB_WORKFLOW_VERSION"
if (-not (Test-Path "C:\Program Files (x86)\NSIS\makensis.exe")) {
Write-Host "Cannot find nsis!"
exit 1
}
if (Test-Path 'osc\xrsoft.exe') {
Write-Host "xrsoft.exe already exists."
}
else {
# 下载所需文件
Get-LanzouFile -Uri "https://xrgzs.lanzouv.com/irdVI27gi2pg" -OutFile "osc\runtime\DirectX_Redist_Repack_x86_x64_Final.exe"
Get-LanzouFile -Uri "https://xrgzs.lanzouv.com/it4vE2i2cq3e" -OutFile "osc\runtime\flash.exe"
Get-LanzouFile -Uri "https://xrgzs.lanzouv.com/iHwLb2eee7gd" -OutFile "osc\runtime\MSVCRedist.AIO.exe"
Get-LanzouFile -Uri "https://xrgzs.lanzouv.com/idHOf2bfs3te" -OutFile "osc\xrkms\KMS_VL_ALL_AIO.cmd"
Get-LanzouFile -Uri "https://xrgzs.lanzouv.com/iBqWU2js0kgb" -OutFile "osc\xrkms\kms.exe"
Get-LanzouFile -Uri "https://xrgzs.lanzouv.com/ixdbP27giisf" -OutFile "osc\xrsoft.exe"
# 下载其他文件
Invoke-WebRequest -Uri "http://url.xrgzs.top/osconline" -OutFile "osc\oscoffline.bat" -ErrorAction Stop
Invoke-WebRequest -Uri "http://url.xrgzs.top/oscsoft" -OutFile "osc\oscsoftof.txt" -ErrorAction Stop
}
# 构建
if (-not $env:GITHUB_WORKFLOW_VERSION) {
$env:GITHUB_WORKFLOW_VERSION = "2.5.0.0"
}
Set-Content -Path "osc\apifiles\Version.txt" -Value $env:GITHUB_WORKFLOW_VERSION
& "C:\Program Files (x86)\NSIS\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"