mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-03-26 23:55:50 +00:00
fix: 支持微信 4.0.5+ 新数据目录结构 (Application Support/com.tencent.xinWeChat/2.0b4.0.x)
- dbPathService.autoDetect: 自动枚举版本目录(如 2.0b4.0.9),优先检测新路径 - dbPathService.getDefaultPath: 同步返回新版本路径 - keyServiceMac.resolveXwechatRootFromPath: 兼容新路径标记 - keyServiceMac.getKvcommCandidates: 补充新路径下的 kvcomm 推导 Fixes #551
This commit is contained in:
@@ -93,27 +93,39 @@ export class DbPathService {
|
|||||||
const possiblePaths: string[] = []
|
const possiblePaths: string[] = []
|
||||||
const home = homedir()
|
const home = homedir()
|
||||||
|
|
||||||
// macOS 微信路径(固定)
|
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
|
// macOS 微信 4.0.5+ 新路径(优先检测)
|
||||||
|
const appSupportBase = join(home, 'Library', 'Containers', 'com.tencent.xinWeChat', 'Data', 'Library', 'Application Support', 'com.tencent.xinWeChat')
|
||||||
|
if (existsSync(appSupportBase)) {
|
||||||
|
try {
|
||||||
|
const entries = readdirSync(appSupportBase)
|
||||||
|
for (const entry of entries) {
|
||||||
|
// 匹配形如 2.0b4.0.9 的版本目录
|
||||||
|
if (/^\d+\.\d+b\d+\.\d+/.test(entry) || /^\d+\.\d+\.\d+/.test(entry)) {
|
||||||
|
possiblePaths.push(join(appSupportBase, entry))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch { }
|
||||||
|
}
|
||||||
|
// macOS 旧路径兜底
|
||||||
possiblePaths.push(join(home, 'Library', 'Containers', 'com.tencent.xinWeChat', 'Data', 'Documents', 'xwechat_files'))
|
possiblePaths.push(join(home, 'Library', 'Containers', 'com.tencent.xinWeChat', 'Data', 'Documents', 'xwechat_files'))
|
||||||
} else {
|
} else {
|
||||||
// Windows 微信4.x 数据目录
|
// Windows 微信4.x 数据目录
|
||||||
possiblePaths.push(join(home, 'Documents', 'xwechat_files'))
|
possiblePaths.push(join(home, 'Documents', 'xwechat_files'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (const path of possiblePaths) {
|
for (const path of possiblePaths) {
|
||||||
if (existsSync(path)) {
|
if (!existsSync(path)) continue
|
||||||
const rootName = path.split(/[/\\]/).pop()?.toLowerCase()
|
|
||||||
if (rootName !== 'xwechat_files' && rootName !== 'wechat files') {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查是否有有效的账号目录
|
// 检查是否有有效的账号目录,或本身就是账号目录
|
||||||
const accounts = this.findAccountDirs(path)
|
const accounts = this.findAccountDirs(path)
|
||||||
if (accounts.length > 0) {
|
if (accounts.length > 0) {
|
||||||
return { success: true, path }
|
return { success: true, path }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果该目录本身就是账号目录(直接包含 db_storage 等)
|
||||||
|
if (this.isAccountDir(path)) {
|
||||||
|
return { success: true, path }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,6 +307,20 @@ export class DbPathService {
|
|||||||
getDefaultPath(): string {
|
getDefaultPath(): string {
|
||||||
const home = homedir()
|
const home = homedir()
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
|
// 优先返回 4.0.5+ 新路径
|
||||||
|
const appSupportBase = join(home, 'Library', 'Containers', 'com.tencent.xinWeChat', 'Data', 'Library', 'Application Support', 'com.tencent.xinWeChat')
|
||||||
|
if (existsSync(appSupportBase)) {
|
||||||
|
try {
|
||||||
|
const entries = readdirSync(appSupportBase)
|
||||||
|
for (const entry of entries) {
|
||||||
|
if (/^\d+\.\d+b\d+\.\d+/.test(entry) || /^\d+\.\d+\.\d+/.test(entry)) {
|
||||||
|
const candidate = join(appSupportBase, entry)
|
||||||
|
if (existsSync(candidate)) return candidate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch { }
|
||||||
|
}
|
||||||
|
// 旧版本路径兜底
|
||||||
return join(home, 'Library', 'Containers', 'com.tencent.xinWeChat', 'Data', 'Documents', 'xwechat_files')
|
return join(home, 'Library', 'Containers', 'com.tencent.xinWeChat', 'Data', 'Documents', 'xwechat_files')
|
||||||
}
|
}
|
||||||
return join(home, 'Documents', 'xwechat_files')
|
return join(home, 'Documents', 'xwechat_files')
|
||||||
|
|||||||
@@ -935,10 +935,17 @@ export class KeyServiceMac {
|
|||||||
private resolveXwechatRootFromPath(accountPath?: string): string | null {
|
private resolveXwechatRootFromPath(accountPath?: string): string | null {
|
||||||
const normalized = String(accountPath || '').replace(/\\/g, '/').replace(/\/+$/, '')
|
const normalized = String(accountPath || '').replace(/\\/g, '/').replace(/\/+$/, '')
|
||||||
if (!normalized) return null
|
if (!normalized) return null
|
||||||
|
|
||||||
|
// 旧路径:xwechat_files
|
||||||
const marker = '/xwechat_files'
|
const marker = '/xwechat_files'
|
||||||
const markerIdx = normalized.indexOf(marker)
|
const markerIdx = normalized.indexOf(marker)
|
||||||
if (markerIdx < 0) return null
|
if (markerIdx >= 0) return normalized.slice(0, markerIdx + marker.length)
|
||||||
return normalized.slice(0, markerIdx + marker.length)
|
|
||||||
|
// 新路径(微信 4.0.5+):Application Support/com.tencent.xinWeChat/2.0b4.0.9
|
||||||
|
const newMarkerMatch = normalized.match(/^(.*\/com\.tencent\.xinWeChat\/(?:\d+\.\d+b\d+\.\d+|\d+\.\d+\.\d+))(\/|$)/)
|
||||||
|
if (newMarkerMatch) return newMarkerMatch[1]
|
||||||
|
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
private pushAccountIdCandidates(candidates: string[], value?: string): void {
|
private pushAccountIdCandidates(candidates: string[], value?: string): void {
|
||||||
@@ -1096,6 +1103,16 @@ export class KeyServiceMac {
|
|||||||
candidates.add(`${base}/app_data/net/kvcomm`)
|
candidates.add(`${base}/app_data/net/kvcomm`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 微信 4.0.5+ 新路径推导:版本目录同级的 net/kvcomm
|
||||||
|
const newMarkerMatch = normalized.match(/^(.*\/com\.tencent\.xinWeChat\/(?:\d+\.\d+b\d+\.\d+|\d+\.\d+\.\d+))/)
|
||||||
|
if (newMarkerMatch) {
|
||||||
|
const versionBase = newMarkerMatch[1]
|
||||||
|
candidates.add(`${versionBase}/net/kvcomm`)
|
||||||
|
// 上级目录也尝试
|
||||||
|
const parentBase = versionBase.replace(/\/[^\/]+$/, '')
|
||||||
|
candidates.add(`${parentBase}/net/kvcomm`)
|
||||||
|
}
|
||||||
|
|
||||||
let cursor = accountPath
|
let cursor = accountPath
|
||||||
for (let i = 0; i < 6; i++) {
|
for (let i = 0; i < 6; i++) {
|
||||||
candidates.add(join(cursor, 'net', 'kvcomm'))
|
candidates.add(join(cursor, 'net', 'kvcomm'))
|
||||||
|
|||||||
Reference in New Issue
Block a user