{"contents":"import os\nimport subprocess\nfrom pathlib import Path\nfrom typing import Optional\n\n\ndef _extract_wechat_files_path_from_cmdline(cmdline):\n if not cmdline:\n return None\n for i, arg in enumerate(cmdline):\n if arg.startswith(\"--wechat-files-path=\"):\n return arg.split(\"=\", 1)[1]\n if arg == \"--wechat-files-path\" and i + 1 \u003c len(cmdline):\n return cmdline[i + 1]\n return None\n\n\ndef find_wechat_files_path() -\u003e Optional[str]:\n # 1) env override\n for env_key in (\"WECHAT_FILES_PATH\", \"WX_FILES_PATH\", \"XWECHAT_FILES_PATH\"):\n val = os.environ.get(env_key)\n if val and os.path.exists(val):\n return val\n\n # 2) parse running WeChat cmdline via /proc to avoid psutil dependency\n try:\n pgrep = subprocess.run([\"pgrep\", \"-f\", \"WeChat\"], capture_output=True, text=True, check=False)\n if pgrep.returncode == 0:\n for line in pgrep.stdout.splitlines():\n pid = line.strip()\n if not pid.isdigit():\n continue\n try:\n with open(f\"/proc/{pid}/cmdline\", \"rb\") as f:\n cmdline = f.read().split(b\"\\x00\")\n cmdline = [c.decode(errors=\"ignore\") for c in cmdline if c]\n except Exception:\n cmdline = []\n path = _extract_wechat_files_path_from_cmdline(cmdline)\n if path and os.path.exists(path):\n return path\n except Exception:\n pass\n\n # 3) common locations for Linux WeChat AppImage\n home = Path.home()\n candidates = [\n home / \"文档\" / \"xwechat_files\",\n home / \"Documents\" / \"xwechat_files\",\n home / \"xwechat_files\",\n home / \".xwechat\" / \"xwechat_files\",\n home / \".local\" / \"share\" / \"wechat\" / \"xwechat_files\",\n home / \".local\" / \"share\" / \"WeChat Files\",\n ]\n for p in candidates:\n if p.exists():\n return str(p)\n\n # 4) shallow search (one level) for xwechat_files\n for p in (home / \"文档\", home / \"Documents\", home):\n if p.exists():\n target = p / \"xwechat_files\"\n if target.exists():\n return str(target)\n return None\n","is_binary":false,"path":"wxdump_linux/linux/paths.py","ref":""}