feat(windows): resolve MyDocument: token in Weixin data-root ini#63
Open
Icy-Cat wants to merge 1 commit into
Open
feat(windows): resolve MyDocument: token in Weixin data-root ini#63Icy-Cat wants to merge 1 commit into
Icy-Cat wants to merge 1 commit into
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The data-root ini under
%APPDATA%\Tencent\xwechat\config\*.iniis observed to contain either:D:\WeChatFiles— the historical form, handled correctly.MyDocument:— not handled, silently fails.detect_db_dir_impl()previously didPathBuf::from(content).is_dir(), which returnsfalsefor 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:\Documentsvia the standard Windows shell-folder redirect) runwx initand see未能自动检测到微信数据目录with no hint as to why.Reproduction on my machine:
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 atHKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Personal.\//.Win32_UI_Shell+Win32_System_Comfeatures to thewindowscrate (needed forSHGetKnownFolderPath+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 equalsSHGetKnownFolderPath(FOLDERID_Documents).Caveats
cargo testlocally. The API surface used (SHGetKnownFolderPath,CoTaskMemFree,HANDLE::default()) is the standard windows-rs 0.58 pattern but please confirm CI passes before merging.