Compare commits
	
		
			5 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 9d92d4be56 | |||
| 83f1811968 | |||
| ffc16830b5 | |||
| 57d50d4e6e | |||
| 6675a46cb6 | 
| @@ -1,4 +1,5 @@ | |||||||
| import os | import os | ||||||
|  | import sys | ||||||
| import webbrowser | import webbrowser | ||||||
| import threading | import threading | ||||||
| import tkinter as tk | import tkinter as tk | ||||||
| @@ -9,7 +10,7 @@ import subprocess | |||||||
| import logging | import logging | ||||||
| import requests | import requests | ||||||
|  |  | ||||||
| logging.basicConfig( | logging.basicConfig(  # 配置日志记录器 | ||||||
|     level=logging.INFO, |     level=logging.INFO, | ||||||
|     format="%(asctime)s - %(levelname)s - %(message)s", |     format="%(asctime)s - %(levelname)s - %(message)s", | ||||||
|     handlers=[ |     handlers=[ | ||||||
| @@ -18,6 +19,17 @@ logging.basicConfig( | |||||||
|     ], |     ], | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | proxy = {"http": None, "https": None}  # Requests代理设置 | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def format_size(size):  # 格式化文件/目录大小 | ||||||
|  |     units = ["B", "KB", "MB", "GB", "TB"] | ||||||
|  |     index = 0 | ||||||
|  |     while size >= 1024 and index < len(units) - 1: | ||||||
|  |         size /= 1024.0 | ||||||
|  |         index += 1 | ||||||
|  |     return f"{size:.2f} {units[index]}" | ||||||
|  |  | ||||||
|  |  | ||||||
| class FolderScanner(threading.Thread): | class FolderScanner(threading.Thread): | ||||||
|     def __init__(self, start_path, queue, progress_queue): |     def __init__(self, start_path, queue, progress_queue): | ||||||
| @@ -45,7 +57,7 @@ class FolderScanner(threading.Thread): | |||||||
|                 self.queue.put((folder_path, size, dirpath, "folder")) |                 self.queue.put((folder_path, size, dirpath, "folder")) | ||||||
|                 scanned_items += 1 |                 scanned_items += 1 | ||||||
|                 self.update_progress(scanned_items, folder_path) |                 self.update_progress(scanned_items, folder_path) | ||||||
|                 logging.info(f"扫描目录: {folder_path} 大小: {size} 字节") |                 logging.info(f"扫描目录: {folder_path} 大小: {format_size(size)} ") | ||||||
|  |  | ||||||
|             for filename in filenames: |             for filename in filenames: | ||||||
|                 file_path = os.path.join(dirpath, filename) |                 file_path = os.path.join(dirpath, filename) | ||||||
| @@ -53,7 +65,7 @@ class FolderScanner(threading.Thread): | |||||||
|                 self.queue.put((file_path, size, dirpath, "file")) |                 self.queue.put((file_path, size, dirpath, "file")) | ||||||
|                 scanned_items += 1 |                 scanned_items += 1 | ||||||
|                 self.update_progress(scanned_items, file_path) |                 self.update_progress(scanned_items, file_path) | ||||||
|                 logging.info(f"扫描文件: {file_path} 大小: {size} 字节") |                 logging.info(f"扫描文件: {file_path} 大小: {format_size(size)} ") | ||||||
|  |  | ||||||
|     def get_size(self, path):  # 获取文件/目录大小 |     def get_size(self, path):  # 获取文件/目录大小 | ||||||
|         total_size = 0 |         total_size = 0 | ||||||
| @@ -74,7 +86,7 @@ class App(tk.Tk): | |||||||
|     def __init__(self, start_path):  # 初始化 |     def __init__(self, start_path):  # 初始化 | ||||||
|         super().__init__() |         super().__init__() | ||||||
|         self.withdraw() |         self.withdraw() | ||||||
|         self.title("目录扫描器 V1.4.1") |         self.title("目录扫描器 V1.4.3") | ||||||
|         self.start_path = start_path |         self.start_path = start_path | ||||||
|         self.queue = Queue() |         self.queue = Queue() | ||||||
|         self.progress_queue = Queue() |         self.progress_queue = Queue() | ||||||
| @@ -169,7 +181,7 @@ class App(tk.Tk): | |||||||
|         try: |         try: | ||||||
|             # 发送 GET 请求获取最新的 Release |             # 发送 GET 请求获取最新的 Release | ||||||
|             response = requests.get( |             response = requests.get( | ||||||
|                 f"{base_url}/{repo_owner}/{repo_name}/releases/latest" |                 f"{base_url}/{repo_owner}/{repo_name}/releases/latest", proxies=proxy | ||||||
|             ) |             ) | ||||||
|  |  | ||||||
|             if response.status_code == 200: |             if response.status_code == 200: | ||||||
| @@ -223,7 +235,7 @@ class App(tk.Tk): | |||||||
|     def show_about(self): |     def show_about(self): | ||||||
|         messagebox.showinfo( |         messagebox.showinfo( | ||||||
|             "关于", |             "关于", | ||||||
|             "一款开源的文件/目录扫描工具\n可以直观地展示目录的文件结构以及文件大小\n\n软件版本 V1.4.1\n作者 ahdoawhfo\n", |             "一款开源的文件/目录扫描工具\n可以直观地展示目录的文件结构以及文件大小\n\n软件版本 V1.4.3\n作者 ahdoawhfo\n", | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|     def on_double_click(self, event):  # V1.2 Update:当双击的是文件时,打开文件 |     def on_double_click(self, event):  # V1.2 Update:当双击的是文件时,打开文件 | ||||||
| @@ -243,17 +255,9 @@ class App(tk.Tk): | |||||||
|             self.start_path = new_path |             self.start_path = new_path | ||||||
|             self.refresh_tree() |             self.refresh_tree() | ||||||
|  |  | ||||||
|     def format_size(self, size):  # 格式化文件/目录大小 |  | ||||||
|         units = ["B", "KB", "MB", "GB", "TB"] |  | ||||||
|         index = 0 |  | ||||||
|         while size >= 1024 and index < len(units) - 1: |  | ||||||
|             size /= 1024.0 |  | ||||||
|             index += 1 |  | ||||||
|         return f"{size:.2f} {units[index]}" |  | ||||||
|  |  | ||||||
|     def populate_root(self):  # 初始化根目录 |     def populate_root(self):  # 初始化根目录 | ||||||
|         size = self.scanner.get_size(self.start_path) |         size = self.scanner.get_size(self.start_path) | ||||||
|         formatted_size = self.format_size(size) |         formatted_size = format_size(size) | ||||||
|         self.tree.insert( |         self.tree.insert( | ||||||
|             "", |             "", | ||||||
|             "end", |             "end", | ||||||
| @@ -273,7 +277,7 @@ class App(tk.Tk): | |||||||
|                     return |                     return | ||||||
|  |  | ||||||
|                 path, size, parent, tag = item |                 path, size, parent, tag = item | ||||||
|                 formatted_size = self.format_size(size) |                 formatted_size = format_size(size) | ||||||
|                 parent_iid = self.get_iid(parent) |                 parent_iid = self.get_iid(parent) | ||||||
|                 if parent == self.start_path: |                 if parent == self.start_path: | ||||||
|                     parent_iid = self.start_path |                     parent_iid = self.start_path | ||||||
| @@ -462,8 +466,7 @@ class App(tk.Tk): | |||||||
|     def on_close(self):  # 关闭程序 |     def on_close(self):  # 关闭程序 | ||||||
|         if self.scanner.is_alive(): |         if self.scanner.is_alive(): | ||||||
|             self.scanner.join() |             self.scanner.join() | ||||||
|         root.destroy() |         sys.exit(0) | ||||||
|         exit() |  | ||||||
|  |  | ||||||
|     def set_window_size(self):  # 设置窗口大小 |     def set_window_size(self):  # 设置窗口大小 | ||||||
|         screen_width = self.winfo_screenwidth() |         screen_width = self.winfo_screenwidth() | ||||||
| @@ -526,12 +529,12 @@ class UpdateManager: | |||||||
|         repo_owner = "ahdoawhfo" |         repo_owner = "ahdoawhfo" | ||||||
|         repo_name = "SpaceSniffer" |         repo_name = "SpaceSniffer" | ||||||
|         base_url = "https://git.a6.wiki/api/v1/repos" |         base_url = "https://git.a6.wiki/api/v1/repos" | ||||||
|         current_version = "1.4.1"  # 替换成你的当前软件版本 |         current_version = "1.4.3"  # 替换成你的当前软件版本 | ||||||
|  |  | ||||||
|         try: |         try: | ||||||
|             # 发送 GET 请求获取最新的 Release |             # 发送 GET 请求获取最新的 Release | ||||||
|             response = requests.get( |             response = requests.get( | ||||||
|                 f"{base_url}/{repo_owner}/{repo_name}/releases/latest" |                 f"{base_url}/{repo_owner}/{repo_name}/releases/latest", proxies=proxy | ||||||
|             ) |             ) | ||||||
|  |  | ||||||
|             if response.status_code == 200: |             if response.status_code == 200: | ||||||
| @@ -575,8 +578,6 @@ class UpdateManager: | |||||||
|     def show_message(self, title, message): |     def show_message(self, title, message): | ||||||
|         if self.root: |         if self.root: | ||||||
|             messagebox.showinfo(title, message) |             messagebox.showinfo(title, message) | ||||||
|         else: |  | ||||||
|             print(f"{title}: {message}") |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def clear_log_file(): | def clear_log_file(): | ||||||
| @@ -584,9 +585,8 @@ def clear_log_file(): | |||||||
|     try: |     try: | ||||||
|         with open(log_file, "w", encoding="utf-8") as f: |         with open(log_file, "w", encoding="utf-8") as f: | ||||||
|             f.truncate(0)  # 清空文件内容 |             f.truncate(0)  # 清空文件内容 | ||||||
|         print(f"已清空日志文件 {log_file} 的内容") |  | ||||||
|     except Exception as e: |     except Exception as e: | ||||||
|         print(f"清空日志文件内容时发生错误: {e}") |         messagebox.showinfo("Error", f"清空日志文件内容时发生错误: {e}") | ||||||
|  |  | ||||||
|  |  | ||||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||||
| @@ -596,13 +596,12 @@ if __name__ == "__main__": | |||||||
|     update_manager = UpdateManager(root, is_startup=True) |     update_manager = UpdateManager(root, is_startup=True) | ||||||
|     proceed = update_manager.check_latest_release() |     proceed = update_manager.check_latest_release() | ||||||
|     if not proceed: |     if not proceed: | ||||||
|         root.destroy() |         sys.exit(0) | ||||||
|         exit() |     messagebox.showinfo("提示", "请选择你要扫描的目录") | ||||||
|     start_path = filedialog.askdirectory() |     start_path = filedialog.askdirectory() | ||||||
|     if start_path: |     if start_path: | ||||||
|         app = App(start_path) |         app = App(start_path) | ||||||
|         app.mainloop() |         app.mainloop() | ||||||
|     else: |     else: | ||||||
|         messagebox.showinfo("提示", "没有选中任何目录,程序即将退出") |         messagebox.showinfo("提示", "没有选中任何目录,程序即将退出") | ||||||
|         root.destroy() |         sys.exit(0) | ||||||
|         exit() |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user