From f6320e71895102668f069424f01a9365bda665b1 Mon Sep 17 00:00:00 2001 From: cforth Date: Tue, 21 Apr 2020 14:59:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=E6=96=87=E4=BB=B6=E5=A4=B9=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E5=8A=A0=E5=AF=86=E8=A7=A3=E5=AF=86=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cryptor.py | 10 ++++++++++ libs/CFCrypto.py | 19 +++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Cryptor.py b/Cryptor.py index 8ee553d..dbb4099 100644 --- a/Cryptor.py +++ b/Cryptor.py @@ -440,9 +440,14 @@ def dir_decrypt(self, dir_path, output_dir_path, password, is_decrypt_name): # 文件夹名称加密 def dir_name_md5_encrypt(self, dir_path, password): self.crypto_task = DirNameCrypto(password) + max_length = count_files(dir_path) try: crypto_thread = Thread(target=self.crypto_task.encrypt, args=(dir_path,)) + update_task_length_thread = Thread(target=self.update_task_now_length, args=(self.crypto_task, max_length,)) + update_process_thread = Thread(target=self.update_process_bar, args=(max_length,)) crypto_thread.start() + update_task_length_thread.start() + update_process_thread.start() except Exception as e: logging.warning("Convert error: ", e) tkmessagebox.showerror("错误", "输入文件格式或者密码错误!") @@ -450,9 +455,14 @@ def dir_name_md5_encrypt(self, dir_path, password): # 文件夹名称解密 def dir_name_md5_decrypt(self, dir_path, password): self.crypto_task = DirNameCrypto(password) + max_length = count_files(dir_path) try: crypto_thread = Thread(target=self.crypto_task.decrypt, args=(dir_path,)) + update_task_length_thread = Thread(target=self.update_task_now_length, args=(self.crypto_task, max_length,)) + update_process_thread = Thread(target=self.update_process_bar, args=(max_length,)) crypto_thread.start() + update_task_length_thread.start() + update_process_thread.start() except Exception as e: logging.warning("Convert error: ", e) tkmessagebox.showerror("错误", "输入文件格式或者密码错误!") diff --git a/libs/CFCrypto.py b/libs/CFCrypto.py index 58b65ca..398caa3 100644 --- a/libs/CFCrypto.py +++ b/libs/CFCrypto.py @@ -417,13 +417,19 @@ def file_name_decrypt(self, file_name_md5): return file_name # 文件夹处理方法 - @staticmethod - def dir_handle(input_dir, name_handle_func): + def dir_handle(self, input_dir, name_handle_func): real_input_dir = os.path.abspath(input_dir).replace('\\', '/') if not os.path.exists(real_input_dir): raise ValueError('Input Dir not exists: %s', real_input_dir) + + self.crypto_status = True + self.stop_flag = False + self.read_count = 0 + for path, subdir, files in os.walk(input_dir, topdown=False): for d in subdir: + if not self.crypto_status: + break original_dir = os.path.join(os.path.abspath(path), d) try: rename_dir = os.path.join(os.path.abspath(path), name_handle_func(d)) @@ -431,15 +437,20 @@ def dir_handle(input_dir, name_handle_func): except Exception as e: logging.exception(e) for f in files: + if not self.crypto_status: + break original_file = os.path.join(os.path.abspath(path), f) try: rename_file = os.path.join(os.path.abspath(path), name_handle_func(f)) os.rename(original_file, rename_file) except Exception as e: logging.exception(e) + self.read_count += 1 + + self.crypto_status = False def encrypt(self, input_dir): - DirNameCrypto.dir_handle(input_dir, self.file_name_encrypt) + self.dir_handle(input_dir, self.file_name_encrypt) # 保存文件名MD5值字典 if not self.config_file: input_dir_name = os.path.basename(os.path.abspath(input_dir)) @@ -456,7 +467,7 @@ def decrypt(self, input_dir): self.config_file = os.path.join(os.path.dirname(os.path.abspath(input_dir)), encrypt_config_name) with open(self.config_file, "r") as f: self.file_name_md5_dict = json.load(f) - DirNameCrypto.dir_handle(input_dir, self.file_name_decrypt) + self.dir_handle(input_dir, self.file_name_decrypt) # 文件MD5值生成