Skip to content

Commit

Permalink
Version 2.1: fix logic and bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
blackboxo committed Jun 5, 2023
1 parent cdf6a85 commit 5745471
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 46 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
config.json
build/
dist/
*.spec
Binary file added CleanMyWechat.zip
Binary file not shown.
40 changes: 37 additions & 3 deletions images/config.ui
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ QCheckBox::indicator::checked {
}</string>
</property>
<property name="text">
<string>是否清理该账号</string>
<string>是否对该账号进行下列内容的清理</string>
</property>
</widget>
</item>
Expand All @@ -306,6 +306,40 @@ QCheckBox::indicator::checked {
</item>
</layout>
</item>

<item>
<layout class="QHBoxLayout" name="horizontalLayout_100">
<item>
<spacer name="horizontalSpacer_100">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>80</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<family>Microsoft YaHei</family>
</font>
</property>
<property name="text">
<string>请勾选你要清理的文件格式:</string>
</property>
</widget>
</item>
</layout>
</item>

<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
Expand Down Expand Up @@ -550,7 +584,7 @@ QCheckBox::indicator::checked {
</font>
</property>
<property name="text">
<string>需要删除多久以前的文件:</string>
<string>需要保留多久以内的文件:</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -651,7 +685,7 @@ QCheckBox::indicator::checked {
}</string>
</property>
<property name="text">
<string>Clean My Wechat - 设置页面</string>
<string>Clean My Wechat V2.1 - 设置页面</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
Expand Down
2 changes: 1 addition & 1 deletion images/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ QProgressBar::chunk {
}</string>
</property>
<property name="text">
<string>Clean My Wechat - 清除微信无用数据</string>
<string>Clean My Wechat V2.1 - 清除微信无用数据</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
Expand Down
42 changes: 26 additions & 16 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from PyQt5.QtWidgets import QApplication, QMainWindow, QGraphicsDropShadowEffect, QListWidgetItem, QListView, QWidget, \
QLabel, QHBoxLayout, QFileDialog
from PyQt5.QtCore import Qt, QPropertyAnimation, QEasingCurve, QThread, pyqtSignal, QMutex, QSize, QEvent, QPoint
from PyQt5.QtCore import Qt, QPropertyAnimation, QEasingCurve, QThread, pyqtSignal, QMutex, QSize, QEvent, QPoint, QTimer
from PyQt5.QtGui import QMouseEvent, QCursor, QColor
from PyQt5.uic import loadUi

Expand Down Expand Up @@ -127,7 +127,7 @@ def open_file(self):
list_ = os.listdir(openfile_path)
user_list = [
elem for elem in list_
if elem != 'All Users' and elem != 'Applet'
if elem != 'All Users' and elem != 'Applet' and elem != 'WMPF'
]
# 如果已有用户配置,那么写入新的用户配置,否则默认写入新配置
dir_list = []
Expand All @@ -141,7 +141,7 @@ def open_file(self):
user_config.append({
"wechat_id": user_wx_id,
"clean_days": "365",
"is_clean": False,
"is_clean": True,
"clean_pic_cache": True,
"clean_file": False,
"clean_pic": True,
Expand All @@ -165,8 +165,9 @@ def save_config(self):

def check_wechat_exists(self):
self.selectVersion = selectVersion()
self.version_scan = self.selectVersion.getAllPath()[0]
self.users_scan = self.selectVersion.getAllPath()[1]
self.scan = self.selectVersion.getAllPath()
self.version_scan = self.scan[0]
self.users_scan = self.scan[1]
if len(self.version_scan) == 0:
return False
else:
Expand All @@ -188,7 +189,7 @@ def load_config(self):
self.check_video.setChecked(self.config["users"][0]["clean_video"])
self.check_picscache.setChecked(
self.config["users"][0]["clean_pic_cache"])
self.setSuccessinfo("加载配置文件成功")
self.setSuccessinfo("请确认每个账号的删除内容及时间,以防误删!")

def refresh_ui(self):
self.config = open(working_dir + "/config.json", encoding="utf-8")
Expand All @@ -204,7 +205,6 @@ def refresh_ui(self):
self.check_picscache.setChecked(value["clean_pic_cache"])

def create_config(self):
true = True
if not os.path.exists(working_dir + "/config.json"):
if not self.check_wechat_exists():
self.setWarninginfo("默认位置没有微信,请自定义位置")
Expand All @@ -215,21 +215,21 @@ def create_config(self):
self.config["users"].append({
"wechat_id": value,
"clean_days": 365,
"is_clean": False,
"clean_pic_cache": true,
"is_clean": True,
"clean_pic_cache": True,
"clean_file": False,
"clean_pic": true,
"clean_video": true,
"is_timer": true,
"clean_pic": True,
"clean_video": True,
"is_timer": True,
"timer": "0h"
})
with open(
working_dir + "/config.json", "w", encoding="utf-8") as f:
json.dump(self.config, f)
self.load_config()
self.setSuccessinfo("加载配置文件成功")
self.setSuccessinfo("请确认每个账号的删除内容及时间,以防误删!")
else:
self.setSuccessinfo("加载配置文件成功")
self.setSuccessinfo("请确认每个账号的删除内容及时间,以防误删!")
self.load_config()

def update_config(self):
Expand Down Expand Up @@ -430,6 +430,10 @@ def justdoit(self):
for thread in thread_list:
thread.run()

def show_config_window(self):
self.config_window = ConfigWindow()
self.setSuccessinfo("已经准备好,可以开始了!")

def __init__(self):
super().__init__()
loadUi(working_dir + "/images/main.ui", self)
Expand All @@ -438,13 +442,19 @@ def __init__(self):
self._eventfilter()
self.doFadeIn()
self.config_exists = True
self.show()

# 判断配置文件是否存在
if not os.path.exists(working_dir + "/config.json"):
self.setWarninginfo("配置文件不存在!请单击“设置”创建配置文件")
self.setWarninginfo("首次使用,即将自动弹出配置窗口")
self.config_exists = False

self.show()
timer = QTimer(self)
timer.timeout.connect(self.show_config_window)
timer.setSingleShot(True) # 只执行一次

# 设置定时器的时间间隔,这里设置为 1000ms(1秒)
timer.start(1000)


if __name__ == '__main__':
Expand Down
18 changes: 4 additions & 14 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
**现已经支持 Windows 系统中的所有微信版本。**

[国内地址 - 点击下载](
https://www.lanzoux.com/iamuhh1owmb)
https://wwvs.lanzouj.com/is77n0yap4dc)

[Github Release - 点击下载](
https://github.com/blackboxo/CleanMyWechat/releases/download/v2.0/CleanMyWechat.zip)
https://github.com/blackboxo/CleanMyWechat/releases/download/v2.1/CleanMyWechat.zip)

**碰到无法清理的,请记得勾选第一个选项,勾选后才会清理该账号下的内容。**

Expand All @@ -26,7 +26,6 @@ https://github.com/blackboxo/CleanMyWechat/releases/download/v2.0/CleanMyWechat.
3. 自由设置想要删除的文件类型,包括图片类缓存、文件、图片、视频;
4. 自由设置需要删除的文件的距离时间,默认 365 天;
5. 删除后的文件放置在回收站中,检查后自行清空,防止删错需要的文件;
6. 支持删除进度的显示;

## 运行截图

Expand All @@ -42,18 +41,9 @@ https://github.com/blackboxo/CleanMyWechat/releases/download/v2.0/CleanMyWechat.

欢迎 PR!

- [ ] Bug:由于微信文件保存路径更改等导致的空配置文件 config.json 引起的闪退,可以考虑读取注册表,详见此 [Issue](https://github.com/blackboxo/CleanMyWechat/issues/45)
- [ ] 界面逻辑优化 [Issue](https://github.com/blackboxo/CleanMyWechat/issues/31)
- [ ] Mac 版本的开发,微信 Mac 版存在缓存大量占用问题
- [ ] Mac 版本的开发
- [ ] 增加企业微信的支持
- [ ] Windows XP 系统的支持
- [ ] 有用户有每日定时删除的需求,考虑让应用开机自启动并常驻后台,或者“将选项变成参数加到快捷方式里运行自动执行”
- [ ] 增加应用打包后的签名
- [x] ~~自动识别出的多个微信账号的路径,让用户选择哪几个账号的需要删除,并记录参数~~
- [x] ~~更改为以天为单位~~
- [x] ~~增加多个微信路径的支持,支持保存路径~~
- [x] ~~支持 Microsoft Store 下载的微信 for Windows 版本~~
- [x] ~~支持 Microsoft Store 下载的微信 UWP 版本~~
- [ ] Windows XP/7 系统的支持

其他需求详见 Issue

Expand Down
25 changes: 25 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import winreg

def read_registry_value(key_path, value_name):
try:
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key_path)
value, _ = winreg.QueryValueEx(key, value_name)
winreg.CloseKey(key)
return value
except FileNotFoundError:
print("Registry key not found.")
except PermissionError:
print("Permission denied.")
except Exception as e:
print("Error occurred:", str(e))

# 注册表路径和字段名
registry_key_path = r"software\tencent\wechat"
value_name = "FileSavePath"

# 读取字段值
value = read_registry_value(registry_key_path, value_name)

# 打印字段值
if value:
print("FileSavePath value:", value)
Binary file modified utils/__pycache__/selectVersion.cpython-38.pyc
Binary file not shown.
56 changes: 44 additions & 12 deletions utils/selectVersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import getpass
import json
import os
import winreg

working_dir = os.path.split(os.path.realpath(__file__))[0]

def check_dir(file_path):
list_ = os.listdir(file_path)
if 'All Users' in list_ or 'Applet' in list_:
if 'All Users' in list_ or 'Applet' in list_ or 'WMPF' in list_:
return 0
else:
return 1
Expand All @@ -26,6 +27,32 @@ def existing_user_config():
else:
return {}

def read_registry_value(key_path, value_name):
try:
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key_path)
value, _ = winreg.QueryValueEx(key, value_name)
winreg.CloseKey(key)
return value
except FileNotFoundError:
print("Registry key not found.")
except PermissionError:
print("Permission denied.")
except Exception as e:
print("Error occurred:", str(e))

def get_dir_name(filepath):
dirlist = []
names = []
list_ = os.listdir(filepath)
# 换用lambda 表达式更安全,remove函数如果不存在对象会抛出异常
list_ = [element for element in list_ if element != 'All Users' and element != 'Applet' and element != 'WMPF']
for i in range(0, len(list_)):
file_path = os.path.join(filepath, list_[i])
if os.path.isdir(file_path):
dirlist.append(file_path)
names.append(list_[i])
return (dirlist, names)

class selectVersion:

def getAllPath(self):
Expand All @@ -35,16 +62,21 @@ def getAllPath(self):
'forwin10': 'C:\\Users\\' + user + '\\AppData\\Local\\Packages\\TencentWeChatLimited.forWindows10_sdtnhv12zgd7a\\LocalCache\\Roaming\\Tencent\\WeChatAppStore\\WeChatAppStore Files',
'foruwp': 'C:\\Users\\' + user + '\\AppData\\Local\\Packages\\TencentWeChatLimited.WeChatUWP_sdtnhv12zgd7a\\LocalCache\\Roaming\\Tencent\\WeChatAppStore\\WeChatAppStore Files'
}
dirlist = []
for key in dic:
if os.path.exists(dic[key]):
list_ = os.listdir(dic[key])
# 换用lambda 表达式更安全,remove函数如果不存在对象会抛出异常
list_ = [element for element in list_ if element != 'All Users' and element != 'Applet']
for i in range(0, len(list_)):
file_path = os.path.join(dic[key], list_[i])
if os.path.isdir(file_path):
dirlist.append(file_path)
return (dirlist,list_)
else:
return ([],[])
return get_dir_name(dic[key])

# 注册表路径和字段名
registry_key_path = r"software\tencent\wechat"
value_name = "FileSavePath"

# 读取字段值
value = read_registry_value(registry_key_path, value_name)

if value and value != 'MyDocument:' and os.path.isdir(value):
fpath = os.path.join(value, 'WeChat Files')
print(fpath)
return get_dir_name(fpath)
else:
return ([], [])

0 comments on commit 5745471

Please sign in to comment.