@aiyiran/myclaw 1.0.17 → 1.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/wsl2.js +71 -26
package/package.json
CHANGED
package/wsl2.js
CHANGED
|
@@ -50,13 +50,17 @@ function launchElevatedPS(script) {
|
|
|
50
50
|
: path.join(os.tmpdir(), 'myclaw');
|
|
51
51
|
try { fs.mkdirSync(tmpDir, { recursive: true }); } catch {}
|
|
52
52
|
const scriptPath = path.join(tmpDir, 'wsl2_installer.ps1');
|
|
53
|
-
|
|
53
|
+
|
|
54
|
+
// UTF-8 with BOM — PowerShell 需要 BOM 才能正确读取中文
|
|
55
|
+
const BOM = '\uFEFF';
|
|
56
|
+
fs.writeFileSync(scriptPath, BOM + script, 'utf8');
|
|
57
|
+
|
|
58
|
+
// 用 -NoExit 确保即使脚本出错窗口也不会关闭
|
|
59
|
+
const escaped = scriptPath.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
60
|
+
const cmd = `powershell -Command "Start-Process powershell -ArgumentList @('-NoProfile','-ExecutionPolicy','Bypass','-NoExit','-File','${escaped}') -Verb RunAs"`;
|
|
54
61
|
|
|
55
62
|
try {
|
|
56
|
-
execSync(
|
|
57
|
-
`powershell -Command "Start-Process powershell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File \\"${scriptPath}\\"' -Verb RunAs"`,
|
|
58
|
-
{ stdio: 'inherit' }
|
|
59
|
-
);
|
|
63
|
+
execSync(cmd, { stdio: 'inherit' });
|
|
60
64
|
return true;
|
|
61
65
|
} catch (err) {
|
|
62
66
|
console.error('[' + C.r + '错误' + C.nc + '] 无法获取管理员权限: ' + err.message);
|
|
@@ -66,36 +70,66 @@ function launchElevatedPS(script) {
|
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
/**
|
|
69
|
-
*
|
|
73
|
+
* 生成「拖拽 / 盘符搜索 / 回车」的 PowerShell 交互代码片段
|
|
70
74
|
* @param {string} prompt 提示文字
|
|
71
75
|
* @param {string} destVar 目标文件变量名(如 $msi, $tarPath)
|
|
72
76
|
* @param {string} cdnUrl CDN 下载地址
|
|
73
77
|
* @param {string} desc 文件描述(如 "WSL 安装包")
|
|
78
|
+
* @param {string} fileName 要搜索的文件名(如 "wsl_full.msi")
|
|
74
79
|
*/
|
|
75
|
-
function makeAskLocalOrCDN(prompt, destVar, cdnUrl, desc) {
|
|
80
|
+
function makeAskLocalOrCDN(prompt, destVar, cdnUrl, desc, fileName) {
|
|
76
81
|
return `
|
|
77
82
|
Write-Host ''
|
|
78
|
-
Write-Host '
|
|
79
|
-
Write-Host '
|
|
80
|
-
Write-Host '
|
|
81
|
-
Write-Host '
|
|
82
|
-
Write-Host '
|
|
83
|
-
Write-Host '
|
|
83
|
+
Write-Host ' +---------------------------------------------+'
|
|
84
|
+
Write-Host ' | ${desc} '
|
|
85
|
+
Write-Host ' | '
|
|
86
|
+
Write-Host ' | [1] 拖拽文件到此窗口 + 回车 '
|
|
87
|
+
Write-Host ' | [2] 输入U盘盘符 (如 F) + 回车 -> 自动搜索 '
|
|
88
|
+
Write-Host ' | [3] 直接回车 -> 从网络下载 '
|
|
89
|
+
Write-Host ' +---------------------------------------------+'
|
|
84
90
|
Write-Host ''
|
|
85
|
-
$userInput = Read-Host '
|
|
91
|
+
$userInput = Read-Host ' 请输入路径/盘符/回车'
|
|
86
92
|
$userInput = $userInput.Trim().Trim('"')
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
$resolved = ''
|
|
94
|
+
|
|
95
|
+
if ($userInput) {
|
|
96
|
+
# 判断是否为单个盘符 (如 F, G, d)
|
|
97
|
+
if ($userInput -match '^[a-zA-Z]$') {
|
|
98
|
+
$drive = $userInput.ToUpper()
|
|
99
|
+
Write-Host " 正在搜索 $drive:\\ 中的 ${fileName}..."
|
|
100
|
+
$found = Get-ChildItem -Path "$drive:\\" -Filter '${fileName}' -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
101
|
+
if ($found) {
|
|
102
|
+
Write-Host " 找到: $($found.FullName)"
|
|
103
|
+
$resolved = $found.FullName
|
|
104
|
+
} else {
|
|
105
|
+
Write-Host " 未在 $drive:\\ 中找到 ${fileName}"
|
|
106
|
+
}
|
|
107
|
+
} elseif (Test-Path $userInput -PathType Leaf) {
|
|
108
|
+
# 直接就是文件路径(拖拽)
|
|
109
|
+
$resolved = $userInput
|
|
110
|
+
} elseif (Test-Path $userInput -PathType Container) {
|
|
111
|
+
# 是目录,在里面搜索
|
|
112
|
+
Write-Host " 正在搜索 $userInput 中的 ${fileName}..."
|
|
113
|
+
$found = Get-ChildItem -Path $userInput -Filter '${fileName}' -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
114
|
+
if ($found) {
|
|
115
|
+
Write-Host " 找到: $($found.FullName)"
|
|
116
|
+
$resolved = $found.FullName
|
|
117
|
+
} else {
|
|
118
|
+
Write-Host " 未在该目录中找到 ${fileName}"
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
Write-Host " [警告] 路径不存在: $userInput"
|
|
122
|
+
}
|
|
96
123
|
}
|
|
97
124
|
|
|
98
|
-
if (
|
|
125
|
+
if ($resolved) {
|
|
126
|
+
Write-Host " 使用本地文件: $resolved"
|
|
127
|
+
Copy-Item $resolved ${destVar} -Force
|
|
128
|
+
Write-Host ' [OK]'
|
|
129
|
+
} else {
|
|
130
|
+
if ($userInput) {
|
|
131
|
+
Write-Host ' 将改为从网络下载...'
|
|
132
|
+
}
|
|
99
133
|
if (-Not (Test-Path ${destVar})) {
|
|
100
134
|
Write-Host ' 正在从网络下载...'
|
|
101
135
|
try {
|
|
@@ -151,7 +185,8 @@ function runPhase1() {
|
|
|
151
185
|
'拖拽 WSL 安装包或回车下载',
|
|
152
186
|
'$msi',
|
|
153
187
|
WSL_CDN.wsl,
|
|
154
|
-
'WSL 安装包 (wsl_full.msi)'
|
|
188
|
+
'WSL 安装包 (wsl_full.msi)',
|
|
189
|
+
'wsl_full.msi'
|
|
155
190
|
);
|
|
156
191
|
|
|
157
192
|
const ps = `
|
|
@@ -257,7 +292,8 @@ function runPhase2() {
|
|
|
257
292
|
'拖拽 tar 包或回车下载',
|
|
258
293
|
'$tarPath',
|
|
259
294
|
WSL_CDN.rootfs,
|
|
260
|
-
'Linux 环境包 (openclaw-rootfs.tar)'
|
|
295
|
+
'Linux 环境包 (openclaw-rootfs.tar)',
|
|
296
|
+
'openclaw-rootfs.tar'
|
|
261
297
|
);
|
|
262
298
|
|
|
263
299
|
const ps = `
|
|
@@ -288,6 +324,15 @@ $installed = $false
|
|
|
288
324
|
${askTar}
|
|
289
325
|
|
|
290
326
|
Write-Host ' 正在导入 (可能需要几分钟)...'
|
|
327
|
+
|
|
328
|
+
# 如果已存在同名发行版,先卸载
|
|
329
|
+
$existing = wsl -l -q 2>$null | Out-String
|
|
330
|
+
if ($existing -match $distroName) {
|
|
331
|
+
Write-Host ' 检测到旧的 OpenClaw 发行版,正在卸载...'
|
|
332
|
+
wsl --unregister $distroName 2>$null
|
|
333
|
+
Write-Host ' [OK] 旧版已卸载'
|
|
334
|
+
}
|
|
335
|
+
|
|
291
336
|
try {
|
|
292
337
|
New-Item -ItemType Directory -Force -Path $installDir | Out-Null
|
|
293
338
|
wsl --import $distroName $installDir $tarPath 2>$null
|