dsh-bili-watch 0.2.21 → 0.2.22
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/index.js +16 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -357,21 +357,32 @@ function writeDepsCfg(patch) {
|
|
|
357
357
|
}
|
|
358
358
|
|
|
359
359
|
/**
|
|
360
|
-
* 弹原生选目录框(Windows)。脚本里只用 ASCII,避免 PS 5.1 按 ANSI
|
|
360
|
+
* 弹原生选目录框(Windows)。脚本里只用 ASCII,避免 PS 5.1 按 ANSI 解码中文变乱;
|
|
361
|
+
* 选中的路径经 UTF-8 文件回传,不走 stdout——PS 5.1 的管道输出是当前代码页(中文系统为 GBK),
|
|
362
|
+
* 中文路径经管道会变成问号(2026-10-24 实测:「D:\007 Dsh工作区」显示成「D:\007 Dsh????」)。
|
|
361
363
|
* 取消返回 null;非 Windows 直接报错,让面板提示手填。
|
|
362
364
|
*/
|
|
363
365
|
function pickFolderDialog() {
|
|
364
366
|
return new Promise((resolve, reject) => {
|
|
365
367
|
if (process.platform !== 'win32') return reject(new Error('folder picker is Windows only; set the path manually'))
|
|
366
|
-
const
|
|
368
|
+
const outFile = join(tmpdir(), `bili-watch-pick-${Date.now()}.txt`)
|
|
369
|
+
const script = [
|
|
370
|
+
'Add-Type -AssemblyName System.Windows.Forms',
|
|
371
|
+
'$d = New-Object System.Windows.Forms.FolderBrowserDialog',
|
|
372
|
+
'$d.Description = "bili-watch cache folder"',
|
|
373
|
+
'if ($d.ShowDialog() -eq "OK") { [IO.File]::WriteAllText(\'' + outFile + '\', $d.SelectedPath, (New-Object Text.UTF8Encoding($false))) }',
|
|
374
|
+
].join('; ')
|
|
367
375
|
const ps = spawn('powershell.exe', ['-NoProfile', '-STA', '-Command', script], { windowsHide: false })
|
|
368
|
-
let out = ''
|
|
369
376
|
let err = ''
|
|
370
|
-
ps.stdout.on('data', (c) => { out += c })
|
|
371
377
|
ps.stderr.on('data', (c) => { err += c })
|
|
372
378
|
ps.on('close', (code) => {
|
|
379
|
+
let picked = ''
|
|
380
|
+
try {
|
|
381
|
+
if (existsSync(outFile)) picked = readFileSync(outFile, 'utf8').trim()
|
|
382
|
+
} catch {}
|
|
383
|
+
try { rmSync(outFile, { force: true }) } catch {}
|
|
373
384
|
if (code !== 0) return reject(new Error(err.trim() || ('powershell exit ' + code)))
|
|
374
|
-
resolve(
|
|
385
|
+
resolve(picked || null)
|
|
375
386
|
})
|
|
376
387
|
ps.on('error', reject)
|
|
377
388
|
})
|