Skip to content

feat(windows): resolve MyDocument: token in Weixin data-root ini#63

Open
Icy-Cat wants to merge 1 commit into
jackwener:mainfrom
Icy-Cat:feat/windows-mydocument-keyword
Open

feat(windows): resolve MyDocument: token in Weixin data-root ini#63
Icy-Cat wants to merge 1 commit into
jackwener:mainfrom
Icy-Cat:feat/windows-mydocument-keyword

Conversation

@Icy-Cat
Copy link
Copy Markdown

@Icy-Cat Icy-Cat commented May 15, 2026

Problem

The data-root ini under %APPDATA%\Tencent\xwechat\config\*.ini is observed to contain either:

  • A plain absolute path, e.g. D:\WeChatFiles — the historical form, handled correctly.
  • The literal token MyDocument:not handled, silently fails.

detect_db_dir_impl() previously did PathBuf::from(content).is_dir(), which returns false for the token, so auto-detect drops the ini even though the user's Weixin data is right there.

The case where this bites: users who relocated their Documents folder (e.g. to D:\Documents via the standard Windows shell-folder redirect) run wx init and see 未能自动检测到微信数据目录 with no hint as to why.

Reproduction on my machine:

$ cat "$APPDATA\Tencent\xwechat\config\<hash>.ini"
MyDocument:
$ wx init
检测微信数据目录...
错误: 未能自动检测到微信数据目录
...

The actual Weixin db lives at D:\Documents\xwechat_files\wxid_xxx\db_storage.

Fix

Empirically the token denotes "the calling user's Documents folder". Resolve it via SHGetKnownFolderPath(FOLDERID_Documents), which honours the standard shell-folder redirect at HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Personal.

  • Plain absolute paths still pass through unchanged.
  • Accepts the token case-insensitively, with or without a trailing \ / /.
  • Adds Win32_UI_Shell + Win32_System_Com features to the windows crate (needed for SHGetKnownFolderPath + CoTaskMemFree).

Tests

Added two Windows-only unit tests in config::tests:

  • resolve_windows_data_root_passes_through_absolute_path — regression guard for the legacy form.
  • resolve_windows_data_root_recognises_mydocument_keyword — calls the resolver with each casing/suffix variant and asserts the result equals SHGetKnownFolderPath(FOLDERID_Documents).

Caveats

  • I did not have a Rust toolchain on the machine that authored this patch, so I did not run cargo test locally. The API surface used (SHGetKnownFolderPath, CoTaskMemFree, HANDLE::default()) is the standard windows-rs 0.58 pattern but please confirm CI passes before merging.
  • Paired PR: fix(init): show config.json path in auto-detect error #62 improves the error message that fires when auto-detect fails, so even if the resolver misses a future ini variant the user is pointed at the right file.

The data-root ini under %APPDATA%\Tencent\xwechat\config\*.ini is
observed to contain either a plain absolute path (e.g. D:\WeChatFiles)
or the literal token 'MyDocument:'. The token form is not a real
filesystem path, so detect_db_dir_impl() — which previously did
PathBuf::from(content).is_dir() — silently failed on it, even though
the user's Weixin data was sitting in their (possibly relocated)
Documents folder.

Empirically the token denotes 'the calling user's Documents folder'.
We resolve it via SHGetKnownFolderPath(FOLDERID_Documents), which
honours the standard Windows shell-folder redirect (HKCU User Shell
Folders\Personal), so users who moved Documents to e.g. D:\Documents
now auto-detect correctly.

Plain absolute paths still pass through unchanged.

Adds Win32_UI_Shell + Win32_System_Com features to the windows crate
(needed for SHGetKnownFolderPath and CoTaskMemFree).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant