@aiyiran/myclaw 1.0.18 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/wsl2.js +62 -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.19",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
package/wsl2.js CHANGED
@@ -70,36 +70,66 @@ 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
+ 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
+ }
100
123
  }
101
124
 
102
- if (-Not $userInput) {
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
+ }
103
133
  if (-Not (Test-Path ${destVar})) {
104
134
  Write-Host ' 正在从网络下载...'
105
135
  try {
@@ -155,7 +185,8 @@ function runPhase1() {
155
185
  '拖拽 WSL 安装包或回车下载',
156
186
  '$msi',
157
187
  WSL_CDN.wsl,
158
- 'WSL 安装包 (wsl_full.msi)'
188
+ 'WSL 安装包 (wsl_full.msi)',
189
+ 'wsl_full.msi'
159
190
  );
160
191
 
161
192
  const ps = `
@@ -261,7 +292,8 @@ function runPhase2() {
261
292
  '拖拽 tar 包或回车下载',
262
293
  '$tarPath',
263
294
  WSL_CDN.rootfs,
264
- 'Linux 环境包 (openclaw-rootfs.tar)'
295
+ 'Linux 环境包 (openclaw-rootfs.tar)',
296
+ 'openclaw-rootfs.tar'
265
297
  );
266
298
 
267
299
  const ps = `
@@ -292,6 +324,15 @@ $installed = $false
292
324
  ${askTar}
293
325
 
294
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
+
295
336
  try {
296
337
  New-Item -ItemType Directory -Force -Path $installDir | Out-Null
297
338
  wsl --import $distroName $installDir $tarPath 2>$null