fix: 兼容微信新目录结构多一层嵌套导致账号目录识别失败的问题

修复 scanWxids 和 scanWxidCandidates 在 2.0b4.0.9/xwechat_files/wxid_xxx
结构下扫描不到账号目录的问题,增加往下多扫一层的兜底逻辑

Fixes #541
This commit is contained in:
hicccc77
2026-03-28 17:28:52 +08:00
parent 9b8da7774d
commit 5f6b0e8960

View File

@@ -218,11 +218,11 @@ export class DbPathService {
scanWxidCandidates(rootPath: string): WxidInfo[] { scanWxidCandidates(rootPath: string): WxidInfo[] {
const wxids: WxidInfo[] = [] const wxids: WxidInfo[] = []
try { const scanOneLevelForCandidates = (scanPath: string) => {
if (existsSync(rootPath)) { if (!existsSync(scanPath)) return
const entries = readdirSync(rootPath) const entries = readdirSync(scanPath)
for (const entry of entries) { for (const entry of entries) {
const entryPath = join(rootPath, entry) const entryPath = join(scanPath, entry)
let stat: ReturnType<typeof statSync> let stat: ReturnType<typeof statSync>
try { stat = statSync(entryPath) } catch { continue } try { stat = statSync(entryPath) } catch { continue }
if (!stat.isDirectory()) continue if (!stat.isDirectory()) continue
@@ -233,6 +233,18 @@ export class DbPathService {
} }
} }
try {
scanOneLevelForCandidates(rootPath)
// 兜底:往下再找一层(兼容 2.0b4.0.9/xwechat_files/wxid_xxx 结构)
if (wxids.length === 0 && existsSync(rootPath)) {
const subDirs = readdirSync(rootPath)
for (const sub of subDirs) {
const subPath = join(rootPath, sub)
try { if (!statSync(subPath).isDirectory()) continue } catch { continue }
scanOneLevelForCandidates(subPath)
}
}
if (wxids.length === 0) { if (wxids.length === 0) {
const rootName = basename(rootPath) const rootName = basename(rootPath)
@@ -282,6 +294,25 @@ export class DbPathService {
const modifiedTime = this.getAccountModifiedTime(fullPath) const modifiedTime = this.getAccountModifiedTime(fullPath)
wxids.push({ wxid: account, modifiedTime }) wxids.push({ wxid: account, modifiedTime })
} }
// 兜底:如果一层找不到,尝试往下再找一层子目录(兼容 2.0b4.0.9/xwechat_files/wxid_xxx 结构)
if (wxids.length === 0) {
try {
const subDirs = readdirSync(rootPath)
for (const sub of subDirs) {
const subPath = join(rootPath, sub)
try {
if (!statSync(subPath).isDirectory()) continue
} catch { continue }
const subAccounts = this.findAccountDirs(subPath)
for (const account of subAccounts) {
const fullPath = join(subPath, account)
const modifiedTime = this.getAccountModifiedTime(fullPath)
wxids.push({ wxid: account, modifiedTime })
}
}
} catch { }
}
} catch { } } catch { }
const sorted = wxids.sort((a, b) => { const sorted = wxids.sort((a, b) => {