WeChatMsg/app/util/path.py

48 lines
1.5 KiB
Python
Raw Normal View History

2023-11-20 23:08:10 +08:00
import os
import winreg
2023-11-20 23:08:10 +08:00
2023-11-23 22:58:27 +08:00
from app.person_pc import MePC
2023-11-24 23:49:37 +08:00
from app.util import dat2pic
2023-11-20 23:08:10 +08:00
2023-12-03 00:03:00 +08:00
os.makedirs('./data/image', exist_ok=True)
2023-11-21 21:48:54 +08:00
2023-11-20 23:08:10 +08:00
def get_abs_path(path):
2023-11-21 21:48:54 +08:00
# return os.path.join(os.getcwd(), 'app/data/icons/404.png')
2023-11-20 23:08:10 +08:00
if path:
2023-11-27 19:26:31 +08:00
base_path = os.getcwd() + "/data/image"
2023-11-28 21:51:49 +08:00
output_path = dat2pic.decode_dat(os.path.join(MePC().wx_dir, path), base_path) # './data/image')
return output_path if output_path else ':/icons/icons/404.png'
2023-11-20 23:08:10 +08:00
else:
2023-11-23 22:58:27 +08:00
return ':/icons/icons/404.png'
2023-12-03 00:03:00 +08:00
def mkdir(path):
if not os.path.exists(path):
os.mkdir(path)
def wx_path():
try:
## 获取当前用户名
user_home = os.environ.get("USERPROFILE")
## 找到3ebffe94.ini配置文件
f = open(user_home + '\\AppData\\Roaming\\Tencent\\WeChat\\All Users\\config\\3ebffe94.ini', encoding='utf-8')
txt = f.read()
f.close()
# 打开Windows注册表
reg_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
# 获取“我的文档”路径的注册表键值
documents_path_value = winreg.QueryValueEx(reg_key, "Personal")
# 输出路径
##读取文件将路径放到wx_location变量里
if txt == 'MyDocument:':
wx_location = documents_path_value[0] + '\WeChat Files'
else:
wx_location = txt + "\WeChat Files"
return wx_location
except FileNotFoundError:
return '.'