Skip to content

Commit 5745471

Browse files
committed
Version 2.1: fix logic and bugs
1 parent cdf6a85 commit 5745471

File tree

9 files changed

+140
-46
lines changed

9 files changed

+140
-46
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
config.json
2+
build/
3+
dist/
4+
*.spec

CleanMyWechat.zip

41 MB
Binary file not shown.

images/config.ui

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ QCheckBox::indicator::checked {
287287
}</string>
288288
</property>
289289
<property name="text">
290-
<string>是否清理该账号</string>
290+
<string>是否对该账号进行下列内容的清理</string>
291291
</property>
292292
</widget>
293293
</item>
@@ -306,6 +306,40 @@ QCheckBox::indicator::checked {
306306
</item>
307307
</layout>
308308
</item>
309+
310+
<item>
311+
<layout class="QHBoxLayout" name="horizontalLayout_100">
312+
<item>
313+
<spacer name="horizontalSpacer_100">
314+
<property name="orientation">
315+
<enum>Qt::Horizontal</enum>
316+
</property>
317+
<property name="sizeType">
318+
<enum>QSizePolicy::Maximum</enum>
319+
</property>
320+
<property name="sizeHint" stdset="0">
321+
<size>
322+
<width>80</width>
323+
<height>20</height>
324+
</size>
325+
</property>
326+
</spacer>
327+
</item>
328+
<item>
329+
<widget class="QLabel" name="label_2">
330+
<property name="font">
331+
<font>
332+
<family>Microsoft YaHei</family>
333+
</font>
334+
</property>
335+
<property name="text">
336+
<string>请勾选你要清理的文件格式:</string>
337+
</property>
338+
</widget>
339+
</item>
340+
</layout>
341+
</item>
342+
309343
<item>
310344
<layout class="QHBoxLayout" name="horizontalLayout_7">
311345
<item>
@@ -550,7 +584,7 @@ QCheckBox::indicator::checked {
550584
</font>
551585
</property>
552586
<property name="text">
553-
<string>需要删除多久以前的文件:</string>
587+
<string>需要保留多久以内的文件:</string>
554588
</property>
555589
</widget>
556590
</item>
@@ -651,7 +685,7 @@ QCheckBox::indicator::checked {
651685
}</string>
652686
</property>
653687
<property name="text">
654-
<string>Clean My Wechat - 设置页面</string>
688+
<string>Clean My Wechat V2.1 - 设置页面</string>
655689
</property>
656690
<property name="alignment">
657691
<set>Qt::AlignCenter</set>

images/main.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ QProgressBar::chunk {
441441
}</string>
442442
</property>
443443
<property name="text">
444-
<string>Clean My Wechat - 清除微信无用数据</string>
444+
<string>Clean My Wechat V2.1 - 清除微信无用数据</string>
445445
</property>
446446
<property name="alignment">
447447
<set>Qt::AlignCenter</set>

main.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

@@ -127,7 +127,7 @@ def open_file(self):
127127
list_ = os.listdir(openfile_path)
128128
user_list = [
129129
elem for elem in list_
130-
if elem != 'All Users' and elem != 'Applet'
130+
if elem != 'All Users' and elem != 'Applet' and elem != 'WMPF'
131131
]
132132
# 如果已有用户配置,那么写入新的用户配置,否则默认写入新配置
133133
dir_list = []
@@ -141,7 +141,7 @@ def open_file(self):
141141
user_config.append({
142142
"wechat_id": user_wx_id,
143143
"clean_days": "365",
144-
"is_clean": False,
144+
"is_clean": True,
145145
"clean_pic_cache": True,
146146
"clean_file": False,
147147
"clean_pic": True,
@@ -165,8 +165,9 @@ def save_config(self):
165165

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

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

206207
def create_config(self):
207-
true = True
208208
if not os.path.exists(working_dir + "/config.json"):
209209
if not self.check_wechat_exists():
210210
self.setWarninginfo("默认位置没有微信,请自定义位置")
@@ -215,21 +215,21 @@ def create_config(self):
215215
self.config["users"].append({
216216
"wechat_id": value,
217217
"clean_days": 365,
218-
"is_clean": False,
219-
"clean_pic_cache": true,
218+
"is_clean": True,
219+
"clean_pic_cache": True,
220220
"clean_file": False,
221-
"clean_pic": true,
222-
"clean_video": true,
223-
"is_timer": true,
221+
"clean_pic": True,
222+
"clean_video": True,
223+
"is_timer": True,
224224
"timer": "0h"
225225
})
226226
with open(
227227
working_dir + "/config.json", "w", encoding="utf-8") as f:
228228
json.dump(self.config, f)
229229
self.load_config()
230-
self.setSuccessinfo("加载配置文件成功")
230+
self.setSuccessinfo("请确认每个账号的删除内容及时间,以防误删!")
231231
else:
232-
self.setSuccessinfo("加载配置文件成功")
232+
self.setSuccessinfo("请确认每个账号的删除内容及时间,以防误删!")
233233
self.load_config()
234234

235235
def update_config(self):
@@ -430,6 +430,10 @@ def justdoit(self):
430430
for thread in thread_list:
431431
thread.run()
432432

433+
def show_config_window(self):
434+
self.config_window = ConfigWindow()
435+
self.setSuccessinfo("已经准备好,可以开始了!")
436+
433437
def __init__(self):
434438
super().__init__()
435439
loadUi(working_dir + "/images/main.ui", self)
@@ -438,13 +442,19 @@ def __init__(self):
438442
self._eventfilter()
439443
self.doFadeIn()
440444
self.config_exists = True
445+
self.show()
441446

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

447-
self.show()
452+
timer = QTimer(self)
453+
timer.timeout.connect(self.show_config_window)
454+
timer.setSingleShot(True) # 只执行一次
455+
456+
# 设置定时器的时间间隔,这里设置为 1000ms(1秒)
457+
timer.start(1000)
448458

449459

450460
if __name__ == '__main__':

readme.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
**现已经支持 Windows 系统中的所有微信版本。**
1212

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

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

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

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

3130
## 运行截图
3231

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

4342
欢迎 PR!
4443

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

5848
其他需求详见 Issue
5949

test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import winreg
2+
3+
def read_registry_value(key_path, value_name):
4+
try:
5+
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key_path)
6+
value, _ = winreg.QueryValueEx(key, value_name)
7+
winreg.CloseKey(key)
8+
return value
9+
except FileNotFoundError:
10+
print("Registry key not found.")
11+
except PermissionError:
12+
print("Permission denied.")
13+
except Exception as e:
14+
print("Error occurred:", str(e))
15+
16+
# 注册表路径和字段名
17+
registry_key_path = r"software\tencent\wechat"
18+
value_name = "FileSavePath"
19+
20+
# 读取字段值
21+
value = read_registry_value(registry_key_path, value_name)
22+
23+
# 打印字段值
24+
if value:
25+
print("FileSavePath value:", value)
888 Bytes
Binary file not shown.

utils/selectVersion.py

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
import getpass
33
import json
44
import os
5+
import winreg
56

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

89
def check_dir(file_path):
910
list_ = os.listdir(file_path)
10-
if 'All Users' in list_ or 'Applet' in list_:
11+
if 'All Users' in list_ or 'Applet' in list_ or 'WMPF' in list_:
1112
return 0
1213
else:
1314
return 1
@@ -26,6 +27,32 @@ def existing_user_config():
2627
else:
2728
return {}
2829

30+
def read_registry_value(key_path, value_name):
31+
try:
32+
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key_path)
33+
value, _ = winreg.QueryValueEx(key, value_name)
34+
winreg.CloseKey(key)
35+
return value
36+
except FileNotFoundError:
37+
print("Registry key not found.")
38+
except PermissionError:
39+
print("Permission denied.")
40+
except Exception as e:
41+
print("Error occurred:", str(e))
42+
43+
def get_dir_name(filepath):
44+
dirlist = []
45+
names = []
46+
list_ = os.listdir(filepath)
47+
# 换用lambda 表达式更安全,remove函数如果不存在对象会抛出异常
48+
list_ = [element for element in list_ if element != 'All Users' and element != 'Applet' and element != 'WMPF']
49+
for i in range(0, len(list_)):
50+
file_path = os.path.join(filepath, list_[i])
51+
if os.path.isdir(file_path):
52+
dirlist.append(file_path)
53+
names.append(list_[i])
54+
return (dirlist, names)
55+
2956
class selectVersion:
3057

3158
def getAllPath(self):
@@ -35,16 +62,21 @@ def getAllPath(self):
3562
'forwin10': 'C:\\Users\\' + user + '\\AppData\\Local\\Packages\\TencentWeChatLimited.forWindows10_sdtnhv12zgd7a\\LocalCache\\Roaming\\Tencent\\WeChatAppStore\\WeChatAppStore Files',
3663
'foruwp': 'C:\\Users\\' + user + '\\AppData\\Local\\Packages\\TencentWeChatLimited.WeChatUWP_sdtnhv12zgd7a\\LocalCache\\Roaming\\Tencent\\WeChatAppStore\\WeChatAppStore Files'
3764
}
38-
dirlist = []
3965
for key in dic:
4066
if os.path.exists(dic[key]):
41-
list_ = os.listdir(dic[key])
42-
# 换用lambda 表达式更安全,remove函数如果不存在对象会抛出异常
43-
list_ = [element for element in list_ if element != 'All Users' and element != 'Applet']
44-
for i in range(0, len(list_)):
45-
file_path = os.path.join(dic[key], list_[i])
46-
if os.path.isdir(file_path):
47-
dirlist.append(file_path)
48-
return (dirlist,list_)
49-
else:
50-
return ([],[])
67+
return get_dir_name(dic[key])
68+
69+
# 注册表路径和字段名
70+
registry_key_path = r"software\tencent\wechat"
71+
value_name = "FileSavePath"
72+
73+
# 读取字段值
74+
value = read_registry_value(registry_key_path, value_name)
75+
76+
if value and value != 'MyDocument:' and os.path.isdir(value):
77+
fpath = os.path.join(value, 'WeChat Files')
78+
print(fpath)
79+
return get_dir_name(fpath)
80+
else:
81+
return ([], [])
82+

0 commit comments

Comments
 (0)