-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
318 lines (257 loc) · 11.4 KB
/
main.py
File metadata and controls
318 lines (257 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
import tkinter
import customtkinter
import os
import object
import time
from tkinter import filedialog
import threading
import sys
#set to dark mode
customtkinter.set_appearance_mode("dark")
def add_directory():
directory = filedialog.askdirectory().replace("/","\\")
if directory not in directories and directory:
directories.append(directory)
direcory_object=object.fileDirectory(master=frame_01, directory=directory, height=26,
fg_color="#090909", directories=directories)
direcory_object.pack(anchor="w", fill="x", padx=50)
direcory_object.line.pack(fill="x", padx=100)
object.save_paths(directories)
initializing_done = False
temporary_file_count = 0
temporary_file_info = []
class scan():
def initializing_(directories):
def initializing():
global temporary_file_count
global initializing_done
temporary_file_count = 0
for directory in directories:
if end_task:
break
directory = [directory+"\\"+path for path in os.listdir(directory)]
index = 0
while index<len(directory):
if end_task:
break
try:
if os.path.isfile(directory[index]):
temporary_file_count +=1
else:
try:
directory += [directory[index]+"\\"+path for path in os.listdir(directory[index])]
except NotADirectoryError:
#print("not a File Or Directory",end=" ")
pass
except PermissionError:
#print("Access is denied",end=" ")
pass
index +=1
initializing_done = True
threading.Thread(target=initializing).start()
def scanning():
#reset
global temporary_file_info
temporary_file_info = []
def scanning_():
global temporary_file_count
scanned_file_count = 0 ;
scanned_file_size = 0;
for directory in directories:
if scan_stop or end_task:
break
globals()[directory+"_frame"].directory_name.configure(text=directory)
directory_files = [directory+"\\"+path for path in os.listdir(directory)]
directory_len = len(directory.split("\\"))
index = 0
total_file_size = 0
file_count = 0
while index<len(directory_files):
if scan_stop or end_task:
break
try:
if os.path.isfile(directory_files[index]):
scanned_file_count +=1
file_size = os.path.getsize(directory_files[index])
total_file_size += file_size
scanned_file_size += file_size
file_count +=1
total_file_count_size_label.configure(text="Files : "+str(scanned_file_count) + " | " +object.convert(scanned_file_size) )
scan_button.set_progress("scanning",scanned_file_count/temporary_file_count*100)
globals()[directory+"_frame"].file_names.insert("end","\\".join(directory_files[index].split("\\")[directory_len:])+"\n")
globals()[directory+"_frame"].file_sizes.insert("end",object.convert(file_size)+"\n")
globals()[directory+"_frame"].file_count_total_size.configure(text=str(file_count)+" | "+object.convert(total_file_size))
#file_lists_listbox.insert("end",file.split("/")[-1]+"\n")
temporary_file_info.append({"name":directory_files[index], "size":os.path.getsize(directory_files[index])})
else:
try:
directory_files += [directory_files[index]+"\\"+path for path in os.listdir(directory_files[index])]
except NotADirectoryError:
#print("not a File Or Directory",end=" ")
pass
except PermissionError:
#print("Access is denied",end=" ")
pass
index +=1
if not scan_stop_by_user:
set_cleaning_window()
elif not end_task:
set_normal_window()
set_scanning_window()
threading.Thread(target=scanning_).start()
def cleaning():
def cleaning_():
i = 0
cleaned_size = 0
file_count = len(temporary_file_info)
total_file_count_size_label.configure(text="Files : 0 | 0 B")
for file in temporary_file_info:
if end_task:
break
try:
os.remove(file["name"])
print(file["name"])
except:
print("del failed..")
i +=1
cleaned_size += file["size"]
total_file_count_size_label.configure(text="Files : " + str(i) + " | "+object.convert(cleaned_size))
scan_button.set_progress("cleaning",i/file_count*100)
set_normal_window()
threading.Thread(target=cleaning_).start()
class frame():
def __init__(self, width=None, height=None):
self.width = width
self.height = height
def set_normal_window():
for widget in scanned_files_frame.outputFrame.winfo_children():
widget.destroy()
directory_add_btn.configure(command=add_directory)
global scan_stop
global scan_stopped
global scan_stop_by_user
scan_stop = False
scan_stopped = True
scan_stop_by_user = False
scan_button.set_normal()
total_file_count_size_label.place_forget()
scanned_files_frame.place_forget()
main_frame2.place_forget()
scanned_files_frame.place_forget()
scan_button.configure(command=scan_start)
frame_01.bind("<Configure>", configure_directory)
frame_01.place(relwidth=1, relheight=1)
main_frame.place(y=275, relwidth=0.8, relx=0.1, relheight=1, height=-300)
directory_add_btn.place(y=243 ,relx=0.1 ,x=205)
label01.place(y=245, relx=0.1)
def stop_scanning():
global scan_stop
global scan_stop_by_user
scan_stop = True
scan_stop_by_user = True
def waitng():
while not scan_stopped:
time.sleep(0.2)
threading.Thread(target=waitng).start()
def set_scanning_window():
global scan_stopped
scan_stopped = False
frame_01.bind("<Configure>", object.pass_e)
frame_01.place_forget()
main_frame.place_forget()
directory_add_btn.place_forget()
label01.place_forget()
scan_button.configure(command=stop_scanning)
total_file_count_size_label.place(relx=0.9, y=220, x=-200)
main_frame2.place(relwidth=0.8, relheight=1, relx=0.1, y=250, height=-250)
scanned_files_frame.place(relwidth=1, relheight=1)
scanned_files_frame.bind("<Configure>", set_scanned_file_frames)
set_scanned_file_frames(frame(root.winfo_width()*0.8, root.winfo_height()-250))
def create_directory_frames():
for directory in directories:
globals()[directory+"_frame"] = object.scannedFileInfoFrame(master=scanned_files_frame.outputFrame ,fg_color="#090909")
def scan_start():
directory_add_btn.configure(command=object.pass_)
global initializing_done
initializing_done = False
scan_button.configure(command=object.pass_)
scan_button.set_initializing()
scan.initializing_(directories)
create_directory_frames()
def waiting():
while not initializing_done:
time.sleep(1)
scan_button.initializing = False
def waiting_2():
while not scan_button.initializing_success:
time.sleep(1)
scan_button.set_scanning()
scan.scanning()
threading.Thread(target=waiting_2).start()
threading.Thread(target=waiting).start()
#scan_button.initializing = False
def start_clean():
scan_button.configure(command=object.pass_)
scan_button.set_progress("cleaning",0)
scan.cleaning()
def set_cleaning_window():
scan_button.set_clean()
scan_button.configure(command=start_clean)
end_task = False
def sys_exit():
global end_task ;
end_task = True
root.destroy()
os._exit(1)
root = customtkinter.CTk(fg_color="#090909")
root.geometry("958x484")
root.minsize(958,484)
root.title("PC Cleaner")
root.iconbitmap("src/icon/main2.ico")
root.protocol("WM_DELETE_WINDOW", sys_exit)
scan_button = object.scanButton(master=root)
scan_button.pack()
label01 = customtkinter.CTkLabel(master=root, text="Temporary File Locations : ", height=10,
text_font=("arial", 11, "bold"), fg_color="#090909")
directory_add_btn = customtkinter.CTkButton(master=root, text="+ Add", width=12, height=12, text_font=("arial", 9, "bold"),
fg_color="#202020", border_color="#303030", border_width=1, command=add_directory)
main_frame = customtkinter.CTkFrame(master=root, fg_color="#090909")
frame_01 = object.scrollableFrame(master=main_frame, fg_color="#090909")
total_file_count_size_label = tkinter.Label(master=root, bg="#090909", fg="#ffffff", font=("arial", 10, "bold"), text="Files : 0 | 0 B")
main_frame2 = customtkinter.CTkFrame(master=root, fg_color="#090909")
scanned_files_frame = object.scrollableFrame(main_frame2, fg_color="#090909")
user_name = os.getlogin()
#default
directories = [
"C:\\Users\\{}\\AppData\\Local\\Temp\\".format(user_name),
"C:\\Users\\{}\\AppData\\Local\\Microsoft\\Windows\\Explorer\\".format(user_name),
"C:\\Windows\\Temp\\",
"C:\\Windows\\Prefetch\\",
"C:\\Windows\\debug\\",
"C:\\Windows\\SoftwareDistribution\\Download\\"
] + object.get_saved_paths()
for default_directory in directories[:6]:
default_direcory_object = object.fileDirectory(master=frame_01, directory=default_directory, height=26,
fg_color="#090909", directories=directories)
default_direcory_object.pack(fill="x", padx=50)
default_direcory_object.remove_btn.configure(state="disabled")
default_direcory_object.line.pack(fill="x", padx=100)
for directory in directories[6:]:
direcory_object = object.fileDirectory(master=frame_01, directory=directory, height=26,
fg_color="#090909", directories=directories)
direcory_object.pack(fill="x", padx=50)
direcory_object.line.pack(fill="x", padx=100)
def configure_directory(e):
default_direcory_object.configure(width=e.width-100)
def set_scanned_file_frames(e):
print(e.width," x ",e.height)
height_ = e.height/3
x_ = 0
y_ = 0
width_ = e.width
for directory in directories:
globals()[directory+"_frame"].place(height=height_, width=width_-30, y=y_, x=x_)
y_ += height_+20
scanned_files_frame.configureWinfo(width=e.width, height=y_)
set_normal_window()
root.mainloop()