From ca38a68a7544ce49d5ea938ac4d183eac397e639 Mon Sep 17 00:00:00 2001 From: hicccc77 <98377878+hicccc77@users.noreply.github.com> Date: Thu, 26 Mar 2026 15:08:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=B9=E5=96=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81=20-3001=20=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=B9=B6=E5=A2=9E=E5=BC=BA=20db=5Fstorage=20=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=85=BC=E5=AE=B9=E6=80=A7\n\n-=20formatInit?= =?UTF-8?q?ProtectionError=20=E8=BF=94=E5=9B=9E=E5=8F=AF=E8=AF=BB=E7=9A=84?= =?UTF-8?q?=E4=B8=AD=E6=96=87=E9=94=99=E8=AF=AF=E8=AF=B4=E6=98=8E=EF=BC=8C?= =?UTF-8?q?=E6=9B=BF=E4=BB=A3=E8=A3=B8=E9=94=99=E8=AF=AF=E7=A0=81\n-=20res?= =?UTF-8?q?olveDbStoragePath=20=E6=96=B0=E5=A2=9E=E5=90=91=E4=B8=8A?= =?UTF-8?q?=E6=9F=A5=E6=89=BE=EF=BC=88=E6=9C=80=E5=A4=9A2=E7=BA=A7?= =?UTF-8?q?=EF=BC=89=E5=85=9C=E5=BA=95=E9=80=BB=E8=BE=91\n-=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20findDbStorageRecursive=20=E9=80=92=E5=BD=92?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=EF=BC=88=E6=9C=80=E5=A4=9A3=E5=B1=82?= =?UTF-8?q?=EF=BC=89=E5=85=9C=E5=BA=95\n-=20=E8=A7=A3=E5=86=B3=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=20wx=5Fkey=20=E8=8E=B7=E5=8F=96=E5=AF=86=E9=92=A5?= =?UTF-8?q?=E5=90=8E=E5=9B=A0=E8=B7=AF=E5=BE=84=E5=B1=82=E7=BA=A7=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E5=AF=BC=E8=87=B4=20-3001=20=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98\n\nFixes=20#552?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/services/wcdbCore.ts | 55 ++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/electron/services/wcdbCore.ts b/electron/services/wcdbCore.ts index 9bb2a9d..df535fa 100644 --- a/electron/services/wcdbCore.ts +++ b/electron/services/wcdbCore.ts @@ -304,7 +304,17 @@ export class WcdbCore { } private formatInitProtectionError(code: number): string { - return `错误码: ${code}` + const messages: Record = { + '-3001': '未找到数据库目录 (db_storage),请确认已选择正确的微信数据目录(应包含以 wxid_ 开头的子文件夹)', + '-3002': '未找到 session.db 文件,请确认微信已登录并且数据目录完整', + '-3003': '数据库句柄无效,请重试', + '-3004': '恢复数据库连接失败,请重试', + '-2301': '动态库加载失败,请检查安装是否完整', + '-2302': 'WCDB 初始化异常,请重试', + '-2303': 'WCDB 未能成功初始化', + } + const msg = messages[String(code) as keyof typeof messages] + return msg ? `${msg} (错误码: ${code})` : `操作失败,错误码: ${code}` } private isLogEnabled(): boolean { @@ -480,6 +490,49 @@ export class WcdbCore { } } catch { } } + // 兜底:向上查找 db_storage(最多 2 级),处理用户选择了子目录的情况 + try { + let parent = normalized + for (let i = 0; i < 2; i++) { + const up = join(parent, '..') + if (up === parent) break + parent = up + const candidateUp = join(parent, 'db_storage') + if (existsSync(candidateUp)) return candidateUp + if (wxid) { + const viaWxidUp = join(parent, wxid, 'db_storage') + if (existsSync(viaWxidUp)) return viaWxidUp + } + } + } catch { } + // 兜底:递归搜索 basePath 下的 db_storage 目录(最多 3 层深) + try { + const found = this.findDbStorageRecursive(normalized, 3) + if (found) return found + } catch { } + return null + } + + private findDbStorageRecursive(dir: string, maxDepth: number): string | null { + if (maxDepth <= 0) return null + try { + const entries = readdirSync(dir) + for (const entry of entries) { + if (entry.toLowerCase() === 'db_storage') { + const candidate = join(dir, entry) + try { if (statSync(candidate).isDirectory()) return candidate } catch { } + } + } + for (const entry of entries) { + const entryPath = join(dir, entry) + try { + if (statSync(entryPath).isDirectory()) { + const found = this.findDbStorageRecursive(entryPath, maxDepth - 1) + if (found) return found + } + } catch { } + } + } catch { } return null }