forked from wanzi6666/NTQQ-sign-to-Lagrange-sign
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.ps1
More file actions
216 lines (183 loc) · 7.12 KB
/
start.ps1
File metadata and controls
216 lines (183 loc) · 7.12 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# SignerServer 启动脚本 (PowerShell 版本)
# 推荐使用此脚本,更稳定可靠
param(
[string]$QQPath = "",
[switch]$Force
)
$ErrorActionPreference = "Stop"
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " SignerServer 启动脚本 (PowerShell)" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 查找 QQ 安装路径
function Find-QQPath {
Write-Host "[查找] 正在搜索 QQ 安装位置..." -ForegroundColor Yellow
# 方法1: 从注册表查询(旧版QQ)
try {
$regPath = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\QQ"
if (Test-Path $regPath) {
$uninstallString = (Get-ItemProperty -Path $regPath).UninstallString
if ($uninstallString) {
$qqDir = Split-Path $uninstallString -Parent
$qqExe = Join-Path $qqDir "QQ.exe"
if (Test-Path $qqExe) {
Write-Host "[找到] 旧版 QQ: $qqExe" -ForegroundColor Green
return $qqExe
}
}
}
} catch {
# 忽略注册表查询错误
}
# 方法2: 搜索常见安装位置
$searchPaths = @(
"$env:USERPROFILE\Documents\qqnt",
"C:\Users\$env:USERNAME\Documents\qqnt",
"C:\Program Files\Tencent\QQNT",
"C:\Program Files (x86)\Tencent\QQ",
"D:\Program Files\Tencent\QQNT",
"D:\Tencent\QQNT"
)
foreach ($path in $searchPaths) {
# 查找所有可能的版本目录
if (Test-Path $path) {
# 直接在根目录查找
$qqExe = Join-Path $path "QQ.exe"
if (Test-Path $qqExe) {
Write-Host "[找到] QQNT: $qqExe" -ForegroundColor Green
return $qqExe
}
# 在版本子目录中查找
$versionDirs = Get-ChildItem -Path $path -Directory -ErrorAction SilentlyContinue |
Where-Object { $_.Name -match '^\d+' }
foreach ($vDir in $versionDirs) {
$qqExe = Join-Path $vDir.FullName "QQ.exe"
if (Test-Path $qqExe) {
Write-Host "[找到] QQNT: $qqExe" -ForegroundColor Green
return $qqExe
}
}
}
}
return $null
}
# 查找或使用指定的 QQ 路径
if ($QQPath) {
if (-not (Test-Path $QQPath)) {
Write-Host "[错误] 指定的 QQ 路径不存在: $QQPath" -ForegroundColor Red
exit 1
}
Write-Host "[使用] 指定的 QQ: $QQPath" -ForegroundColor Green
} else {
$QQPath = Find-QQPath
if (-not $QQPath) {
Write-Host "[错误] 未找到 QQ 安装" -ForegroundColor Red
Write-Host ""
Write-Host "请检查以下位置或手动指定:" -ForegroundColor Yellow
Write-Host " - $env:USERPROFILE\Documents\qqnt"
Write-Host " - C:\Program Files\Tencent\QQNT"
Write-Host " - C:\Program Files (x86)\Tencent\QQ"
Write-Host ""
Write-Host "使用方法: .\start.ps1 -QQPath 'C:\Path\To\QQ.exe'" -ForegroundColor Cyan
Read-Host "按回车键退出"
exit 1
}
}
$QQDir = Split-Path $QQPath -Parent
Write-Host ""
# 查找 SignerServer.dll
$scriptDir = Split-Path $MyInvocation.MyCommand.Path -Parent
$dllSource = Join-Path $scriptDir "SignerServer.dll"
# 尝试在 build 目录中查找
if (-not (Test-Path $dllSource)) {
$buildDll = Join-Path $scriptDir "build\msvc-release\SignerServer.dll"
if (Test-Path $buildDll) {
$dllSource = $buildDll
}
}
if (-not (Test-Path $dllSource)) {
Write-Host "[错误] 未找到 SignerServer.dll" -ForegroundColor Red
Write-Host ""
Write-Host "请先编译项目:" -ForegroundColor Yellow
Write-Host " cmake --preset=msvc-release"
Write-Host " cmake --build --preset=msvc-release"
Write-Host ""
Write-Host "编译后的 DLL 应该在:" -ForegroundColor Yellow
Write-Host " build\msvc-release\SignerServer.dll"
Read-Host "按回车键退出"
exit 1
}
$dllTarget = Join-Path $QQDir "dbghelp.dll"
# 检查是否需要复制 DLL
$needCopy = $true
if ((Test-Path $dllTarget) -and -not $Force) {
Write-Host "[检测] dbghelp.dll 已存在" -ForegroundColor Yellow
$choice = Read-Host "是否替换现有的 dbghelp.dll? (Y/N)"
if ($choice -notmatch '^[Yy]') {
$needCopy = $false
Write-Host "[跳过] 保留现有 DLL" -ForegroundColor Cyan
}
}
if ($needCopy) {
try {
Write-Host "[复制] 将 SignerServer.dll 复制为 dbghelp.dll..." -ForegroundColor Yellow
Copy-Item -Path $dllSource -Destination $dllTarget -Force
Write-Host "[成功] DLL 已复制到: $dllTarget" -ForegroundColor Green
} catch {
Write-Host "[错误] 复制失败(可能需要管理员权限)" -ForegroundColor Red
Write-Host "错误信息: $($_.Exception.Message)" -ForegroundColor Red
# 尝试以管理员身份重新运行
$choice = Read-Host "是否以管理员身份重新运行? (Y/N)"
if ($choice -match '^[Yy]') {
Write-Host "[提权] 正在以管理员身份重新启动..." -ForegroundColor Yellow
$arguments = "-NoProfile -ExecutionPolicy Bypass -File `"$($MyInvocation.MyCommand.Path)`""
if ($QQPath) { $arguments += " -QQPath `"$QQPath`"" }
if ($Force) { $arguments += " -Force" }
Start-Process powershell.exe -ArgumentList $arguments -Verb RunAs
exit 0
}
exit 1
}
}
Write-Host ""
# 检查 load.js
$loadScript = Join-Path $scriptDir "load.js"
$useLoadScript = Test-Path $loadScript
if (-not $useLoadScript) {
Write-Host "[警告] load.js 不存在,使用标准模式启动" -ForegroundColor Yellow
}
# 设置环境变量
$env:ELECTRON_RUN_AS_NODE = "1"
# 启动 QQ
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "[启动] 正在启动 QQ..." -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "QQ 路径: $QQPath" -ForegroundColor White
Write-Host "工作目录: $QQDir" -ForegroundColor White
if ($useLoadScript) {
Write-Host "加载脚本: $loadScript" -ForegroundColor White
}
Write-Host ""
try {
Set-Location $QQDir
if ($useLoadScript) {
& $QQPath $loadScript $args
} else {
& $QQPath $args
}
if ($LASTEXITCODE -ne 0) {
throw "QQ 启动失败,退出代码: $LASTEXITCODE"
}
Write-Host ""
Write-Host "[提示] QQ 已启动,请检查:" -ForegroundColor Green
Write-Host " 1. 控制台是否显示 'Sign initialized successfully!'" -ForegroundColor White
Write-Host " 2. 访问 http://localhost:8080/ping 验证服务" -ForegroundColor White
Write-Host ""
} catch {
Write-Host ""
Write-Host "[错误] QQ 启动失败" -ForegroundColor Red
Write-Host "错误信息: $($_.Exception.Message)" -ForegroundColor Red
Read-Host "按回车键退出"
exit 1
}
Read-Host "按回车键退出"