feat: 支持中文路径

This commit is contained in:
cc
2026-01-29 21:59:29 +08:00
parent 26fbfd2c98
commit b3aaea16f2
2 changed files with 11 additions and 12 deletions

View File

@@ -18,8 +18,7 @@ export class DbPathService {
// 微信4.x 数据目录 // 微信4.x 数据目录
possiblePaths.push(join(home, 'Documents', 'xwechat_files')) possiblePaths.push(join(home, 'Documents', 'xwechat_files'))
// 旧版微信数据目录
possiblePaths.push(join(home, 'Documents', 'WeChat Files'))
for (const path of possiblePaths) { for (const path of possiblePaths) {
if (existsSync(path)) { if (existsSync(path)) {
@@ -27,7 +26,7 @@ export class DbPathService {
if (rootName !== 'xwechat_files' && rootName !== 'wechat files') { if (rootName !== 'xwechat_files' && rootName !== 'wechat files') {
continue continue
} }
// 检查是否有有效的账号目录 // 检查是否有有效的账号目录
const accounts = this.findAccountDirs(path) const accounts = this.findAccountDirs(path)
if (accounts.length > 0) { if (accounts.length > 0) {
@@ -47,10 +46,10 @@ export class DbPathService {
*/ */
findAccountDirs(rootPath: string): string[] { findAccountDirs(rootPath: string): string[] {
const accounts: string[] = [] const accounts: string[] = []
try { try {
const entries = readdirSync(rootPath) const entries = readdirSync(rootPath)
for (const entry of entries) { for (const entry of entries) {
const entryPath = join(rootPath, entry) const entryPath = join(rootPath, entry)
let stat: ReturnType<typeof statSync> let stat: ReturnType<typeof statSync>
@@ -59,7 +58,7 @@ export class DbPathService {
} catch { } catch {
continue continue
} }
if (stat.isDirectory()) { if (stat.isDirectory()) {
if (!this.isPotentialAccountName(entry)) continue if (!this.isPotentialAccountName(entry)) continue
@@ -69,8 +68,8 @@ export class DbPathService {
} }
} }
} }
} catch {} } catch { }
return accounts return accounts
} }
@@ -124,7 +123,7 @@ export class DbPathService {
*/ */
scanWxids(rootPath: string): WxidInfo[] { scanWxids(rootPath: string): WxidInfo[] {
const wxids: WxidInfo[] = [] const wxids: WxidInfo[] = []
try { try {
if (this.isAccountDir(rootPath)) { if (this.isAccountDir(rootPath)) {
const wxid = basename(rootPath) const wxid = basename(rootPath)
@@ -133,14 +132,14 @@ export class DbPathService {
} }
const accounts = this.findAccountDirs(rootPath) const accounts = this.findAccountDirs(rootPath)
for (const account of accounts) { for (const account of accounts) {
const fullPath = join(rootPath, account) const fullPath = join(rootPath, account)
const modifiedTime = this.getAccountModifiedTime(fullPath) const modifiedTime = this.getAccountModifiedTime(fullPath)
wxids.push({ wxid: account, modifiedTime }) wxids.push({ wxid: account, modifiedTime })
} }
} catch {} } catch { }
return wxids.sort((a, b) => { return wxids.sort((a, b) => {
if (b.modifiedTime !== a.modifiedTime) return b.modifiedTime - a.modifiedTime if (b.modifiedTime !== a.modifiedTime) return b.modifiedTime - a.modifiedTime
return a.wxid.localeCompare(b.wxid) return a.wxid.localeCompare(b.wxid)

Binary file not shown.