@@ -26,25 +26,41 @@ class WCDBRealtimeError(RuntimeError):
2626_WCDB_API_DLL_SELECTED : Optional [Path ] = None
2727
2828
29+ def _is_project_wcdb_api_dll_path (path : Path ) -> bool :
30+ try :
31+ resolved = path .resolve (strict = False )
32+ except Exception :
33+ resolved = path
34+
35+ try :
36+ default_resolved = _DEFAULT_WCDB_API_DLL .resolve (strict = False )
37+ except Exception :
38+ default_resolved = _DEFAULT_WCDB_API_DLL
39+
40+ if resolved == default_resolved :
41+ return True
42+
43+ parts = tuple (str (part ).lower () for part in resolved .parts )
44+ allowed_suffixes = (
45+ ("backend" , "native" , "wcdb_api.dll" ),
46+ ("wechat_decrypt_tool" , "native" , "wcdb_api.dll" ),
47+ )
48+ return any (parts [- len (suffix ) :] == suffix for suffix in allowed_suffixes )
49+
50+
2951def _candidate_wcdb_api_dll_paths () -> list [Path ]:
30- """Return possible locations for wcdb_api.dll (prefer WeFlow's newer build when present) ."""
52+ """Return allowed locations for wcdb_api.dll."""
3153 cands : list [Path ] = []
3254
3355 env = str (os .environ .get ("WECHAT_TOOL_WCDB_API_DLL_PATH" , "" ) or "" ).strip ()
3456 if env :
35- cands .append (Path (env ))
36-
37- # Repo checkout convenience: reuse bundled WeFlow / echotrace DLLs when available.
38- try :
39- repo_root = Path (__file__ ).resolve ().parents [2 ]
40- except Exception :
41- repo_root = Path .cwd ()
57+ env_path = Path (env )
58+ if _is_project_wcdb_api_dll_path (env_path ):
59+ cands .append (env_path )
60+ else :
61+ logger .warning ("[wcdb] ignore external wcdb_api.dll override: %s" , env_path )
4262
43- for p in [
44- repo_root / "WeFlow" / "resources" / "wcdb_api.dll" ,
45- repo_root / "echotrace" / "assets" / "dll" / "wcdb_api.dll" ,
46- _DEFAULT_WCDB_API_DLL ,
47- ]:
63+ for p in (_DEFAULT_WCDB_API_DLL ,):
4864 if p not in cands :
4965 cands .append (p )
5066
0 commit comments