@@ -64,6 +64,7 @@ def excepthook(exc_type, exc_value, exc_traceback):
6464import datetime , time , re , math , shutil , json , logging
6565
6666from utils .deleteThread import *
67+ from utils .cleanupManifest import combine_cleanup_results , write_cleanup_manifest
6768from utils .multiDeleteThread import multiDeleteThread
6869from utils .selectVersion import *
6970from utils .selectVersion import check_dir , existing_user_config , find_all_wechat_paths , get_dir_name , \
@@ -104,6 +105,7 @@ def ensure_writable_dir(path):
104105STATE_PATH = os .path .join (working_dir , "clean_state.json" )
105106WHITELIST_PATH = os .path .join (working_dir , "whitelist.txt" )
106107PREVIEW_PATH = os .path .join (working_dir , "last_scan_preview.txt" )
108+ CLEANUP_MANIFEST_DIR = os .path .join (working_dir , "cleanup_manifests" )
107109APP_ICON_PATH = os .path .join (resource_dir , "images" , "wechat.png" )
108110
109111logging .basicConfig (
@@ -1052,8 +1054,11 @@ def execute_delete(self):
10521054
10531055 share_thread_arr = [0 ]
10541056 direct_delete = load_config_file ().get ("global" , {}).get ("direct_delete" , False )
1057+ self .cleanup_results = []
1058+ self .cleanup_expected_threads = 1
10551059 thread = multiDeleteThread (selected_files , selected_dirs , share_thread_arr , direct_delete = direct_delete )
10561060 thread .delete_process_signal .connect (self .callback )
1061+ thread .delete_complete_signal .connect (self .on_delete_complete )
10571062 self .thread_list .append (thread )
10581063 thread .start ()
10591064
@@ -1771,6 +1776,26 @@ def callback(self, v):
17711776 self .auto_clean_running = False
17721777 return
17731778
1779+ def on_delete_complete (self , result ):
1780+ if not hasattr (self , "cleanup_results" ):
1781+ self .cleanup_results = []
1782+ self .cleanup_results .append (result )
1783+ expected = max (1 , int (getattr (self , "cleanup_expected_threads" , 1 )))
1784+ if len (self .cleanup_results ) < expected :
1785+ return
1786+
1787+ combined = combine_cleanup_results (self .cleanup_results )
1788+ manifest_path = write_cleanup_manifest (combined , CLEANUP_MANIFEST_DIR )
1789+ self .last_cleanup_manifest = manifest_path
1790+ logging .info ("清理审计记录已保存:%s" , manifest_path )
1791+
1792+ failed_count = combined .get ("failed_count" , 0 )
1793+ skipped_count = combined .get ("skipped_count" , 0 )
1794+ if failed_count :
1795+ self .setWarninginfo (f"清理完成,但有 { failed_count } 个失败。审计记录:{ manifest_path } " )
1796+ else :
1797+ self .setSuccessinfo (f"清理完成,审计记录已保存:{ manifest_path } 。跳过 { skipped_count } 个受保护或不存在的路径。" )
1798+
17741799 def should_run_auto_clean (self , config ):
17751800 global_config = config .get ("global" , {})
17761801 if not global_config .get ("auto_clean_enable" , False ):
@@ -1804,6 +1829,8 @@ def justdoit(self, auto_mode=False):
18041829 detail_lines = []
18051830 share_thread_arr = [0 ]
18061831 system_cache_added = False
1832+ self .cleanup_results = []
1833+ self .cleanup_expected_threads = 0
18071834
18081835 for i , value in enumerate (self .config .get ("users" , [])):
18091836 file_list = []
@@ -1832,6 +1859,7 @@ def justdoit(self, auto_mode=False):
18321859 direct_delete = self .config .get ("global" , {}).get ("direct_delete" , False )
18331860 thread = multiDeleteThread (file_list , dir_list , share_thread_arr , direct_delete = direct_delete )
18341861 thread .delete_process_signal .connect (self .callback )
1862+ thread .delete_complete_signal .connect (self .on_delete_complete )
18351863 self .thread_list .append (thread )
18361864
18371865 if not need_clean :
@@ -1842,6 +1870,7 @@ def justdoit(self, auto_mode=False):
18421870 self .total_file = total_file
18431871 self .total_dir = total_dir
18441872 self .total_size = total_stats .get ("total_size" , 0 )
1873+ self .cleanup_expected_threads = len (self .thread_list )
18451874 self .bar_progress .setRange (0 , 100 )
18461875 self .bar_progress .setValue (0 )
18471876 if not auto_mode or self .config .get ("global" , {}).get ("auto_clean_confirm" , True ):
0 commit comments