1414import configparser
1515import logging
1616import os
17- import shutil
18- import threading
1917import time
2018import tkinter .filedialog
2119import tkinter .messagebox
2220import tkinter .ttk as ttk
2321import winreg
2422from datetime import datetime
2523from concurrent .futures import ThreadPoolExecutor , as_completed
24+ from shutil import copy2 as shutil_copy2 , move as shutil_move , Error as shutil_Error
25+ from threading import Thread
2626
27- import win32api
2827import win32com .client as com
29- import win32gui
3028from filecmp import dircmp
3129from PIL import Image
3230from mttkinter import mtTkinter as tk
3331from pathlib import Path
3432from psutil import disk_partitions , pids , boot_time
3533from pystray import MenuItem , Menu , Icon
34+ from win32api import GetVolumeInformation
35+ from win32gui import FindWindow , ShowWindow
3636from win10toast import ToastNotifier
3737from winshell import CreateShortcut
3838
@@ -213,7 +213,7 @@ def launch(self):
213213 row = 3 , column = 0 , padx = 10 , pady = 0 , ipadx = 150 , sticky = 'W' )
214214 self .progress_root .protocol (
215215 'WM_DELETE_WINDOW' , lambda : self .sync_bar_on_exit ())
216- self .roll_bar = threading . Thread (target = self .show_running , daemon = True )
216+ self .roll_bar = Thread (target = self .show_running , daemon = True )
217217 self .roll_bar .start ()
218218 self .initialization_done = True
219219
@@ -244,11 +244,11 @@ def __init__(self):
244244 self .continue_this_progress = False
245245
246246 def opened_proc_root (self ):
247- hwnd = win32gui . FindWindow (self .classname , 'Movefile Setting' )
247+ hwnd = FindWindow (self .classname , 'Movefile Setting' )
248248 if hwnd :
249249 temp_root = tk .Tk ()
250250 temp_root .withdraw ()
251- win32gui . ShowWindow (hwnd , 5 )
251+ ShowWindow (hwnd , 5 )
252252 tkinter .messagebox .showinfo (
253253 title = "Movefile" , message = "The app's running!" )
254254 temp_root .quit ()
@@ -455,7 +455,7 @@ def scan_removable_disks(s_uuid=None):
455455 disk_list .append (item .mountpoint )
456456 if disk_list :
457457 for pf in disk_list :
458- seria_data = win32api . GetVolumeInformation (pf )
458+ seria_data = GetVolumeInformation (pf )
459459 area_name = seria_data [0 ]
460460 area_number = seria_data [1 ]
461461 fso = com .Dispatch ("Scripting.FileSystemObject" )
@@ -497,7 +497,7 @@ def detect_removable_disks_thread():
497497 disk_list .remove (pf )
498498 area_data_list .remove (number_book [pf ])
499499 else :
500- seria_number = win32api . GetVolumeInformation (pf )
500+ seria_number = GetVolumeInformation (pf )
501501 area_name = seria_number [0 ]
502502 area_number = seria_number [1 ]
503503 if area_number not in area_data_list :
@@ -664,7 +664,7 @@ def run_cleanfile(baroot):
664664 del_item (for_path + '\\ ' + item )
665665 if for_path != '' : # 如果 new path 有内容就移动到 new path, 否则删除
666666 try :
667- shutil . move (item_path , for_path )
667+ shutil_move (item_path , for_path )
668668 except :
669669 cf_error_name += (item + ', ' )
670670 else :
@@ -686,12 +686,12 @@ def run_cleanfile(baroot):
686686 cfdic ["main_progress_label2" ][lang_num ],
687687 cfdic ["current_file_label" ][lang_num ],
688688 lang_num )
689- clean_bar_root_task = threading . Thread (
689+ clean_bar_root_task = Thread (
690690 target = lambda : clean_bar_root .launch (), daemon = True )
691691 clean_bar_root_task .start ()
692692 while not clean_bar_root .initialization_done :
693693 time .sleep (0.01 )
694- run_tasks = threading . Thread (
694+ run_tasks = Thread (
695695 target = lambda : run_cleanfile (clean_bar_root ), daemon = True )
696696 run_tasks .start ()
697697
@@ -871,8 +871,8 @@ def synchronize_files(baroot, task):
871871 # Create parent directories if needed
872872 dest_path .parent .mkdir (parents = True , exist_ok = True )
873873 try :
874- shutil . copy2 (source_file_path , dest_file_path )
875- except shutil . Error :
874+ shutil_copy2 (source_file_path , dest_file_path )
875+ except shutil_Error :
876876 return source_file_path
877877 return None
878878
@@ -916,13 +916,13 @@ def run_sync_tasks(baroot):
916916 sf_ltd ["main_progress_label2" ][language_number ],
917917 sf_ltd ["current_file_label" ][language_number ],
918918 language_number )
919- sync_bar_root_task = threading . Thread (
919+ sync_bar_root_task = Thread (
920920 target = lambda : sync_bar_root .launch (), daemon = True )
921921 sync_bar_root_task .start ()
922922 while not sync_bar_root .initialization_done :
923923 time .sleep (0.01 )
924924 sf_progress_done = False
925- run_tasks = threading . Thread (
925+ run_tasks = Thread (
926926 target = lambda : run_sync_tasks (sync_bar_root ), daemon = True )
927927 run_tasks .start ()
928928 while not sf_progress_done :
@@ -1780,7 +1780,7 @@ def savefile(function, save_name='New_Setting'): # 保存文件
17801780 else :
17811781 disk_data = sf_entry_select_removable .get ()
17821782 sf_data .set (save_name , 'disk_number' ,
1783- str (win32api . GetVolumeInformation (disk_data .split (':' )[0 ][- 1 ] + ':' )[1 ]))
1783+ str (GetVolumeInformation (disk_data .split (':' )[0 ][- 1 ] + ':' )[1 ]))
17841784 sf_data .set (save_name , 'path_2' , sf_entry_path_2 .get ())
17851785 sf_data .set (save_name , 'mode' , sf_entry_mode .get ())
17861786 sf_data .set (save_name , 'lock_folder' ,
@@ -2061,7 +2061,7 @@ def sf_operate_from_root():
20612061 lockfolder = sf_entry_lock_folder .get ()
20622062 lockfile = sf_entry_lock_file .get ()
20632063 if len (path1 ) == 2 :
2064- area_name = win32api . GetVolumeInformation (path1 )[0 ]
2064+ area_name = GetVolumeInformation (path1 )[0 ]
20652065 if mode == 'single' :
20662066 single_sync = True
20672067 else :
@@ -2082,12 +2082,12 @@ def change_language(language):
20822082
20832083 def continue_going ():
20842084 if cf_or_sf .get () == 'cf' and not ZFunc .cf_has_error ():
2085- cf_operator = threading . Thread (
2085+ cf_operator = Thread (
20862086 target = lambda : cf_operate_from_root (), daemon = True )
20872087 cf_operator .start ()
20882088 root .withdraw ()
20892089 elif cf_or_sf .get () == 'sf' and not ZFunc .sf_has_error ():
2090- sf_operator = threading . Thread (
2090+ sf_operator = Thread (
20912091 target = lambda : sf_operate_from_root (), daemon = True )
20922092 sf_operator .start ()
20932093 root .withdraw ()
@@ -2234,12 +2234,12 @@ def ask_sync_disk():
22342234 if startup_visit :
22352235 root .withdraw ()
22362236
2237- butt_icon = threading . Thread (target = task_menu .run , daemon = True )
2237+ butt_icon = Thread (target = task_menu .run , daemon = True )
22382238 butt_icon .start ()
2239- background_detect = threading . Thread (
2239+ background_detect = Thread (
22402240 target = lambda : detect_removable_disks_thread (), daemon = True )
22412241 background_detect .start ()
2242- ask_permit = threading . Thread (target = lambda : ask_sync_disk (), daemon = True )
2242+ ask_permit = Thread (target = lambda : ask_sync_disk (), daemon = True )
22432243 ask_permit .start ()
22442244
22452245 root .mainloop ()
@@ -2258,7 +2258,7 @@ def main():
22582258 f"Movefile Start \n Visits today: { visits_today } \n Time since startup: { initial_data .boot_time } \n Startup visit: { str (boot_visit )} " )
22592259
22602260 if visits_today == 1 and boot_visit :
2261- autorun_options = threading . Thread (
2261+ autorun_options = Thread (
22622262 target = lambda : startup_autorun (), daemon = True )
22632263 autorun_options .start ()
22642264
0 commit comments