@aiyiran/myclaw 1.0.18 → 1.0.20

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/wsl2.js +63 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiyiran/myclaw",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
package/wsl2.js CHANGED
@@ -70,36 +70,67 @@ function launchElevatedPS(script) {
70
70
  }
71
71
 
72
72
  /**
73
- * 生成「拖拽或回车」的 PowerShell 交互代码片段
73
+ * 生成「拖拽 / 盘符搜索 / 回车」的 PowerShell 交互代码片段
74
74
  * @param {string} prompt 提示文字
75
75
  * @param {string} destVar 目标文件变量名(如 $msi, $tarPath)
76
76
  * @param {string} cdnUrl CDN 下载地址
77
77
  * @param {string} desc 文件描述(如 "WSL 安装包")
78
+ * @param {string} fileName 要搜索的文件名(如 "wsl_full.msi")
78
79
  */
79
- function makeAskLocalOrCDN(prompt, destVar, cdnUrl, desc) {
80
+ function makeAskLocalOrCDN(prompt, destVar, cdnUrl, desc, fileName) {
80
81
  return `
81
82
  Write-Host ''
82
- Write-Host ' ┌─────────────────────────────────────────┐'
83
- Write-Host ' 如有 ${desc} 的本地文件: │'
84
- Write-Host ' │ 请将文件拖拽到此窗口,然后按回车 │'
85
- Write-Host ' │ │'
86
- Write-Host ' 没有?直接按回车,自动从网络下载 │'
87
- 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 ' +---------------------------------------------+'
88
90
  Write-Host ''
89
- $userInput = Read-Host ' 拖拽文件或直接回车'
91
+ $userInput = Read-Host ' 请输入路径/盘符/回车'
90
92
  $userInput = $userInput.Trim().Trim('"')
91
-
92
- if ($userInput -and (Test-Path $userInput)) {
93
- Write-Host " 使用本地文件: $userInput"
94
- Copy-Item $userInput ${destVar} -Force
95
- Write-Host ' [OK]'
96
- } elseif ($userInput) {
97
- Write-Host " [警告] 文件不存在: $userInput"
98
- Write-Host ' 将改为从网络下载...'
99
- $userInput = ''
93
+ $resolved = ''
94
+
95
+ if ($userInput) {
96
+ # 判断是否为单个盘符 (如 F, G, d)
97
+ if ($userInput -match '^[a-zA-Z]$') {
98
+ $drive = $userInput.ToUpper()
99
+ $drivePath = $drive + ':'
100
+ Write-Host " 正在搜索 $drivePath 中的 ${fileName}..."
101
+ $found = Get-ChildItem -Path $drivePath -Filter '${fileName}' -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
102
+ if ($found) {
103
+ Write-Host " 找到: $($found.FullName)"
104
+ $resolved = $found.FullName
105
+ } else {
106
+ Write-Host " 未在 $drivePath 中找到 ${fileName}"
107
+ }
108
+ } elseif (Test-Path $userInput -PathType Leaf) {
109
+ # 直接就是文件路径(拖拽)
110
+ $resolved = $userInput
111
+ } elseif (Test-Path $userInput -PathType Container) {
112
+ # 是目录,在里面搜索
113
+ Write-Host " 正在搜索 $userInput 中的 ${fileName}..."
114
+ $found = Get-ChildItem -Path $userInput -Filter '${fileName}' -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
115
+ if ($found) {
116
+ Write-Host " 找到: $($found.FullName)"
117
+ $resolved = $found.FullName
118
+ } else {
119
+ Write-Host " 未在该目录中找到 ${fileName}"
120
+ }
121
+ } else {
122
+ Write-Host " [警告] 路径不存在: $userInput"
123
+ }
100
124
  }
101
125
 
102
- if (-Not $userInput) {
126
+ if ($resolved) {
127
+ Write-Host " 使用本地文件: $resolved"
128
+ Copy-Item $resolved ${destVar} -Force
129
+ Write-Host ' [OK]'
130
+ } else {
131
+ if ($userInput) {
132
+ Write-Host ' 将改为从网络下载...'
133
+ }
103
134
  if (-Not (Test-Path ${destVar})) {
104
135
  Write-Host ' 正在从网络下载...'
105
136
  try {
@@ -155,7 +186,8 @@ function runPhase1() {
155
186
  '拖拽 WSL 安装包或回车下载',
156
187
  '$msi',
157
188
  WSL_CDN.wsl,
158
- 'WSL 安装包 (wsl_full.msi)'
189
+ 'WSL 安装包 (wsl_full.msi)',
190
+ 'wsl_full.msi'
159
191
  );
160
192
 
161
193
  const ps = `
@@ -261,7 +293,8 @@ function runPhase2() {
261
293
  '拖拽 tar 包或回车下载',
262
294
  '$tarPath',
263
295
  WSL_CDN.rootfs,
264
- 'Linux 环境包 (openclaw-rootfs.tar)'
296
+ 'Linux 环境包 (openclaw-rootfs.tar)',
297
+ 'openclaw-rootfs.tar'
265
298
  );
266
299
 
267
300
  const ps = `
@@ -292,6 +325,15 @@ $installed = $false
292
325
  ${askTar}
293
326
 
294
327
  Write-Host ' 正在导入 (可能需要几分钟)...'
328
+
329
+ # 如果已存在同名发行版,先卸载
330
+ $existing = wsl -l -q 2>$null | Out-String
331
+ if ($existing -match $distroName) {
332
+ Write-Host ' 检测到旧的 OpenClaw 发行版,正在卸载...'
333
+ wsl --unregister $distroName 2>$null
334
+ Write-Host ' [OK] 旧版已卸载'
335
+ }
336
+
295
337
  try {
296
338
  New-Item -ItemType Directory -Force -Path $installDir | Out-Null
297
339
  wsl --import $distroName $installDir $tarPath 2>$null