"""Local installation hints; no fixed drive, execution, or downloaded client code.""" from __future__ import annotations import os from pathlib import Path def registry_locations(): """WeCom's Executable is a path; DataLocation can also be a numeric flag.""" result = {"executables": [], "data": []} try: import winreg except ImportError: return result for hive in (winreg.HKEY_CURRENT_USER, winreg.HKEY_LOCAL_MACHINE): for view in (winreg.KEY_WOW64_32KEY, winreg.KEY_WOW64_64KEY): try: with winreg.OpenKey(hive, r"Software\Tencent\WXWork", 0, winreg.KEY_READ | view) as key: for name, group in (("Executable", "executables"), ("DataLocation", "data")): try: value, _ = winreg.QueryValueEx(key, name) except OSError: continue if not isinstance(value, str): continue value = os.path.expandvars(value.strip().strip('"')) if os.path.isabs(value) and value not in result[group]: result[group].append(value) except OSError: continue return result def installed_executables(): paths = registry_locations()["executables"] for variable in ("ProgramFiles(x86)", "ProgramFiles", "LOCALAPPDATA"): root = os.environ.get(variable, "").strip() if root: paths.append(str(Path(root) / "WXWork" / "WXWork.exe")) seen = set() result = [] for value in paths: path = Path(value) identity = os.path.normcase(os.path.abspath(path)) if identity not in seen and path.name.lower() == "wxwork.exe" and path.is_file(): result.append(path) seen.add(identity) return result def protocol_database_status(account, *, initialize=False): """Check the logged-in account, never an arbitrary readable historical account.""" from reply_database import LiveReplyDatabase from wxwork_db import DatabaseReadError, detect_wxwork_dir source=detect_wxwork_dir(account=account) if not source: return {"ready": False, "status": "database_not_found", "label": "当前账号数据目录未找到", "message": "未找到当前登录账号的消息库。若聊天数据移到其他盘,请选择企业微信数据目录;可选择 WXWork、账号目录或 Data 目录。"} try: database = LiveReplyDatabase._open_database(account=account, initialize=initialize, source_directory=source, load_metadata=False) database.close() except (DatabaseReadError, OSError, ValueError) as exc: return {"ready": False, "status": "database_unavailable", "label": "本机消息库未就绪", "message": str(exc)} return {"ready": True, "status": "ready", "label": "当前账号可读取", "message": "当前账号消息库已核对"}