|
|
@ -15,7 +15,33 @@ class FileTransferApp: |
|
|
self.root.title("蜗牛创造的高速文件传输") |
|
|
self.root.title("蜗牛创造的高速文件传输") |
|
|
self.root.geometry("900x700") |
|
|
self.root.geometry("900x700") |
|
|
self.root.configure(bg='white') # 设置窗口背景为白色 |
|
|
self.root.configure(bg='white') # 设置窗口背景为白色 |
|
|
|
|
|
|
|
|
|
|
|
# 初始化各页面状态 |
|
|
|
|
|
self.page_states = { |
|
|
|
|
|
'welcome': {}, |
|
|
|
|
|
'send': { |
|
|
|
|
|
'is_running': False, |
|
|
|
|
|
'frpc_process': None, |
|
|
|
|
|
'p2p_process': None, |
|
|
|
|
|
'key_entry_text': '', |
|
|
|
|
|
'file_path': '', |
|
|
|
|
|
'output_content': '' |
|
|
|
|
|
}, |
|
|
|
|
|
'receive': { |
|
|
|
|
|
'is_running': False, |
|
|
|
|
|
'frpc_process': None, |
|
|
|
|
|
'p2p_process': None, |
|
|
|
|
|
'key_entry_text': '', |
|
|
|
|
|
'save_path': '.\\received_files', |
|
|
|
|
|
'output_content': '' |
|
|
|
|
|
}, |
|
|
|
|
|
'cloud': { |
|
|
|
|
|
'is_running': False, |
|
|
|
|
|
'cloud_process': None, |
|
|
|
|
|
'output_content': '' |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
self.current_page = None |
|
|
# 设置样式 |
|
|
# 设置样式 |
|
|
self.setup_styles() |
|
|
self.setup_styles() |
|
|
|
|
|
|
|
|
@ -25,7 +51,83 @@ class FileTransferApp: |
|
|
|
|
|
|
|
|
# 显示欢迎界面 |
|
|
# 显示欢迎界面 |
|
|
self.show_welcome_screen() |
|
|
self.show_welcome_screen() |
|
|
|
|
|
|
|
|
|
|
|
def save_current_page_state(self): |
|
|
|
|
|
"""保存当前页面的状态""" |
|
|
|
|
|
if self.current_page == 'send': |
|
|
|
|
|
self.page_states['send']['key_entry_text'] = self.send_key_entry.get() |
|
|
|
|
|
self.page_states['send']['file_path'] = self.file_path_var.get() |
|
|
|
|
|
self.page_states['send']['output_content'] = self.send_output.get(1.0, tk.END) |
|
|
|
|
|
|
|
|
|
|
|
elif self.current_page == 'receive': |
|
|
|
|
|
self.page_states['receive']['key_entry_text'] = self.receive_key_entry.get() |
|
|
|
|
|
self.page_states['receive']['save_path'] = self.receive_path_var.get() |
|
|
|
|
|
self.page_states['receive']['output_content'] = self.receive_output.get(1.0, tk.END) |
|
|
|
|
|
|
|
|
|
|
|
elif self.current_page == 'cloud': |
|
|
|
|
|
self.page_states['cloud']['output_content'] = self.cloud_output.get(1.0, tk.END) |
|
|
|
|
|
def restore_page_state(self, page_name): |
|
|
|
|
|
"""恢复指定页面的状态""" |
|
|
|
|
|
state = self.page_states[page_name] |
|
|
|
|
|
|
|
|
|
|
|
if page_name == 'send': |
|
|
|
|
|
self.send_key_entry.delete(0, tk.END) |
|
|
|
|
|
self.send_key_entry.insert(0, state['key_entry_text']) |
|
|
|
|
|
self.file_path_var.set(state['file_path']) |
|
|
|
|
|
|
|
|
|
|
|
self.send_output.config(state='normal') |
|
|
|
|
|
self.send_output.delete(1.0, tk.END) |
|
|
|
|
|
self.send_output.insert(1.0, state['output_content']) |
|
|
|
|
|
self.send_output.config(state='disabled') |
|
|
|
|
|
|
|
|
|
|
|
# 恢复按钮状态 |
|
|
|
|
|
if state['is_running']: |
|
|
|
|
|
self.send_connect_button.config(state='disabled') |
|
|
|
|
|
self.send_stop_button.config(state='normal') |
|
|
|
|
|
self.send_file_button.config(state='normal' if state['file_path'] else 'disabled') |
|
|
|
|
|
else: |
|
|
|
|
|
self.send_connect_button.config(state='normal') |
|
|
|
|
|
self.send_stop_button.config(state='disabled') |
|
|
|
|
|
self.send_file_button.config(state='disabled') |
|
|
|
|
|
|
|
|
|
|
|
self.update_send_status("运行中" if state['is_running'] else "等待连接") |
|
|
|
|
|
|
|
|
|
|
|
elif page_name == 'receive': |
|
|
|
|
|
self.receive_key_entry.delete(0, tk.END) |
|
|
|
|
|
self.receive_key_entry.insert(0, state['key_entry_text']) |
|
|
|
|
|
self.receive_path_var.set(state['save_path']) |
|
|
|
|
|
|
|
|
|
|
|
self.receive_output.config(state='normal') |
|
|
|
|
|
self.receive_output.delete(1.0, tk.END) |
|
|
|
|
|
self.receive_output.insert(1.0, state['output_content']) |
|
|
|
|
|
self.receive_output.config(state='disabled') |
|
|
|
|
|
|
|
|
|
|
|
# 恢复按钮状态 |
|
|
|
|
|
if state['is_running']: |
|
|
|
|
|
self.connect_button.config(state='disabled') |
|
|
|
|
|
self.stop_button.config(state='normal') |
|
|
|
|
|
else: |
|
|
|
|
|
self.connect_button.config(state='normal') |
|
|
|
|
|
self.stop_button.config(state='disabled') |
|
|
|
|
|
|
|
|
|
|
|
self.update_status("运行中" if state['is_running'] else "等待连接") |
|
|
|
|
|
|
|
|
|
|
|
elif page_name == 'cloud': |
|
|
|
|
|
self.cloud_output.config(state='normal') |
|
|
|
|
|
self.cloud_output.delete(1.0, tk.END) |
|
|
|
|
|
self.cloud_output.insert(1.0, state['output_content']) |
|
|
|
|
|
self.cloud_output.config(state='disabled') |
|
|
|
|
|
|
|
|
|
|
|
# 恢复按钮状态 |
|
|
|
|
|
if state['is_running']: |
|
|
|
|
|
self.cloud_start_button.config(state='disabled') |
|
|
|
|
|
self.cloud_stop_button.config(state='normal') |
|
|
|
|
|
self.cloud_status_label.config(text="📊 状态: 加速服务运行中", fg="#27ae60") |
|
|
|
|
|
else: |
|
|
|
|
|
self.cloud_start_button.config(state='normal') |
|
|
|
|
|
self.cloud_stop_button.config(state='disabled') |
|
|
|
|
|
self.cloud_status_label.config(text="📊 状态: 等待启动加速服务", fg="#7f8c8d") |
|
|
|
|
|
|
|
|
def setup_styles(self): |
|
|
def setup_styles(self): |
|
|
"""设置界面样式""" |
|
|
"""设置界面样式""" |
|
|
style = ttk.Style() |
|
|
style = ttk.Style() |
|
|
@ -42,7 +144,10 @@ class FileTransferApp: |
|
|
|
|
|
|
|
|
def show_welcome_screen(self): |
|
|
def show_welcome_screen(self): |
|
|
"""显示欢迎界面""" |
|
|
"""显示欢迎界面""" |
|
|
|
|
|
if self.current_page: |
|
|
|
|
|
self.save_current_page_state() |
|
|
self.clear_frame() |
|
|
self.clear_frame() |
|
|
|
|
|
self.current_page = 'welcome' |
|
|
|
|
|
|
|
|
# 顶部logo区域 |
|
|
# 顶部logo区域 |
|
|
logo_frame = tk.Frame(self.main_frame, bg='white') |
|
|
logo_frame = tk.Frame(self.main_frame, bg='white') |
|
|
@ -168,7 +273,10 @@ class FileTransferApp: |
|
|
footer_label.pack() |
|
|
footer_label.pack() |
|
|
def show_cloud_accel_screen(self): |
|
|
def show_cloud_accel_screen(self): |
|
|
"""显示网盘加速界面""" |
|
|
"""显示网盘加速界面""" |
|
|
|
|
|
if self.current_page: |
|
|
|
|
|
self.save_current_page_state() |
|
|
self.clear_frame() |
|
|
self.clear_frame() |
|
|
|
|
|
self.current_page = 'cloud' |
|
|
|
|
|
|
|
|
# 标题栏 |
|
|
# 标题栏 |
|
|
title_frame = tk.Frame(self.main_frame, bg='white') |
|
|
title_frame = tk.Frame(self.main_frame, bg='white') |
|
|
@ -256,6 +364,9 @@ class FileTransferApp: |
|
|
# 进程引用 |
|
|
# 进程引用 |
|
|
self.cloud_process = None |
|
|
self.cloud_process = None |
|
|
self.is_cloud_running = False |
|
|
self.is_cloud_running = False |
|
|
|
|
|
# 恢复状态 |
|
|
|
|
|
if hasattr(self, 'cloud_output'): |
|
|
|
|
|
self.restore_page_state('cloud') |
|
|
|
|
|
|
|
|
def create_kodcloud_ini(self): |
|
|
def create_kodcloud_ini(self): |
|
|
"""创建kodcloud.ini配置文件""" |
|
|
"""创建kodcloud.ini配置文件""" |
|
|
@ -316,6 +427,7 @@ bind_port = 8089 |
|
|
universal_newlines=True, |
|
|
universal_newlines=True, |
|
|
creationflags=subprocess.CREATE_NO_WINDOW # 不创建窗口 |
|
|
creationflags=subprocess.CREATE_NO_WINDOW # 不创建窗口 |
|
|
) |
|
|
) |
|
|
|
|
|
self.page_states['cloud']['cloud_process'] = self.cloud_process |
|
|
|
|
|
|
|
|
# 更新状态 |
|
|
# 更新状态 |
|
|
self.is_cloud_running = True |
|
|
self.is_cloud_running = True |
|
|
@ -329,6 +441,8 @@ bind_port = 8089 |
|
|
# 启动输出监控线程 |
|
|
# 启动输出监控线程 |
|
|
output_thread = threading.Thread(target=self.monitor_cloud_output, daemon=True) |
|
|
output_thread = threading.Thread(target=self.monitor_cloud_output, daemon=True) |
|
|
output_thread.start() |
|
|
output_thread.start() |
|
|
|
|
|
# 更新状态 |
|
|
|
|
|
self.page_states['cloud']['is_running'] = True |
|
|
|
|
|
|
|
|
except Exception as e: |
|
|
except Exception as e: |
|
|
self.append_cloud_output(f"❌ 启动加速服务失败: {e}\n") |
|
|
self.append_cloud_output(f"❌ 启动加速服务失败: {e}\n") |
|
|
@ -352,10 +466,17 @@ bind_port = 8089 |
|
|
self.cloud_status_label.config(text="📊 状态: 服务已停止", fg="#7f8c8d") |
|
|
self.cloud_status_label.config(text="📊 状态: 服务已停止", fg="#7f8c8d") |
|
|
self.append_cloud_output("✅ 加速服务已停止\n") |
|
|
self.append_cloud_output("✅ 加速服务已停止\n") |
|
|
|
|
|
|
|
|
|
|
|
# 更新状态 |
|
|
|
|
|
self.page_states['cloud']['is_running'] = False |
|
|
|
|
|
|
|
|
def append_cloud_output(self, message): |
|
|
def append_cloud_output(self, message): |
|
|
"""向网盘加速输出框添加消息""" |
|
|
"""向网盘加速输出框添加消息""" |
|
|
self.cloud_output.config(state='normal') |
|
|
self.cloud_output.config(state='normal') |
|
|
self.cloud_output.insert(tk.END, message) |
|
|
self.cloud_output.insert(tk.END, message) |
|
|
|
|
|
self.cloud_output.see(tk.END) |
|
|
|
|
|
self.cloud_output.config(state='disabled') |
|
|
|
|
|
# 更新状态存储 |
|
|
|
|
|
self.page_states['cloud']['output_content'] = self.cloud_output.get(1.0, tk.END) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_styled_button(self, parent, text, command, bg_color, width=10): |
|
|
def create_styled_button(self, parent, text, command, bg_color, width=10): |
|
|
@ -376,7 +497,10 @@ bind_port = 8089 |
|
|
|
|
|
|
|
|
def show_send_screen(self): |
|
|
def show_send_screen(self): |
|
|
"""显示发送界面""" |
|
|
"""显示发送界面""" |
|
|
|
|
|
if self.current_page: |
|
|
|
|
|
self.save_current_page_state() |
|
|
self.clear_frame() |
|
|
self.clear_frame() |
|
|
|
|
|
self.current_page = 'send' |
|
|
|
|
|
|
|
|
# 标题栏 |
|
|
# 标题栏 |
|
|
title_frame = tk.Frame(self.main_frame, bg='white') |
|
|
title_frame = tk.Frame(self.main_frame, bg='white') |
|
|
@ -474,11 +598,22 @@ bind_port = 8089 |
|
|
self.send_frpc_process = None |
|
|
self.send_frpc_process = None |
|
|
self.send_p2p_process = None |
|
|
self.send_p2p_process = None |
|
|
self.is_send_running = False |
|
|
self.is_send_running = False |
|
|
|
|
|
# 初始化或恢复状态 |
|
|
|
|
|
if not hasattr(self, 'send_key_entry'): |
|
|
|
|
|
# 第一次创建界面 |
|
|
|
|
|
self.send_key_entry = tk.Entry(key_frame, font=("Microsoft YaHei", 10), width=40, relief='solid', bd=1) |
|
|
|
|
|
self.file_path_var = tk.StringVar() |
|
|
|
|
|
# ... 其他控件初始化 |
|
|
|
|
|
else: |
|
|
|
|
|
# 恢复状态 |
|
|
|
|
|
self.restore_page_state('send') |
|
|
|
|
|
|
|
|
def show_receive_screen(self): |
|
|
def show_receive_screen(self): |
|
|
"""显示接收界面""" |
|
|
"""显示接收界面""" |
|
|
|
|
|
if self.current_page: |
|
|
|
|
|
self.save_current_page_state() |
|
|
self.clear_frame() |
|
|
self.clear_frame() |
|
|
|
|
|
self.current_page = 'receive' |
|
|
|
|
|
|
|
|
# 标题栏 |
|
|
# 标题栏 |
|
|
title_frame = tk.Frame(self.main_frame, bg='white') |
|
|
title_frame = tk.Frame(self.main_frame, bg='white') |
|
|
@ -575,7 +710,15 @@ bind_port = 8089 |
|
|
self.p2p_process = None |
|
|
self.p2p_process = None |
|
|
self.is_running = False |
|
|
self.is_running = False |
|
|
self.current_stage = "idle" |
|
|
self.current_stage = "idle" |
|
|
|
|
|
# 初始化或恢复状态 |
|
|
|
|
|
if not hasattr(self, 'receive_key_entry'): |
|
|
|
|
|
# 第一次创建界面 |
|
|
|
|
|
self.receive_key_entry = tk.Entry(key_frame, font=("Microsoft YaHei", 10), width=40, relief='solid', bd=1) |
|
|
|
|
|
self.receive_path_var = tk.StringVar(value=".\\received_files") |
|
|
|
|
|
# ... 其他控件初始化 |
|
|
|
|
|
else: |
|
|
|
|
|
# 恢复状态 |
|
|
|
|
|
self.restore_page_state('receive') |
|
|
def browse_receive_path(self): |
|
|
def browse_receive_path(self): |
|
|
"""浏览选择接收文件保存路径""" |
|
|
"""浏览选择接收文件保存路径""" |
|
|
folder_path = filedialog.askdirectory( |
|
|
folder_path = filedialog.askdirectory( |
|
|
@ -673,7 +816,8 @@ bind_port = {bport} |
|
|
universal_newlines=True, |
|
|
universal_newlines=True, |
|
|
creationflags=subprocess.CREATE_NO_WINDOW # 不创建窗口 |
|
|
creationflags=subprocess.CREATE_NO_WINDOW # 不创建窗口 |
|
|
) |
|
|
) |
|
|
|
|
|
self.page_states['send']['p2p_process'] = self.send_p2p_process |
|
|
|
|
|
|
|
|
# 启动输出监控线程 |
|
|
# 启动输出监控线程 |
|
|
output_thread = threading.Thread(target=self.monitor_send_frpc_output, daemon=True) |
|
|
output_thread = threading.Thread(target=self.monitor_send_frpc_output, daemon=True) |
|
|
output_thread.start() |
|
|
output_thread.start() |
|
|
@ -791,7 +935,10 @@ bind_port = {bport} |
|
|
# 在新线程中执行NATCC |
|
|
# 在新线程中执行NATCC |
|
|
self.send_process_thread = threading.Thread(target=self.execute_send_frpc, daemon=True) |
|
|
self.send_process_thread = threading.Thread(target=self.execute_send_frpc, daemon=True) |
|
|
self.send_process_thread.start() |
|
|
self.send_process_thread.start() |
|
|
|
|
|
# 更新状态 |
|
|
|
|
|
self.page_states['send']['is_running'] = True |
|
|
|
|
|
self.page_states['send']['key_entry_text'] = key |
|
|
|
|
|
self.page_states['send']['file_path'] = self.file_path_var.get() |
|
|
def start_file_send(self): |
|
|
def start_file_send(self): |
|
|
"""开始发送文件""" |
|
|
"""开始发送文件""" |
|
|
if not self.file_path_var.get(): |
|
|
if not self.file_path_var.get(): |
|
|
@ -833,7 +980,9 @@ bind_port = {bport} |
|
|
self.send_stop_button.config(state='disabled') |
|
|
self.send_stop_button.config(state='disabled') |
|
|
self.update_send_status("已停止") |
|
|
self.update_send_status("已停止") |
|
|
self.append_send_output("所有进程已停止\n") |
|
|
self.append_send_output("所有进程已停止\n") |
|
|
|
|
|
# 更新状态 |
|
|
|
|
|
self.page_states['send']['is_running'] = False |
|
|
|
|
|
|
|
|
def update_send_status(self, status): |
|
|
def update_send_status(self, status): |
|
|
"""更新发送状态标签""" |
|
|
"""更新发送状态标签""" |
|
|
self.send_status_label.config(text=f"状态: {status}") |
|
|
self.send_status_label.config(text=f"状态: {status}") |
|
|
@ -844,7 +993,8 @@ bind_port = {bport} |
|
|
self.send_output.insert(tk.END, message) |
|
|
self.send_output.insert(tk.END, message) |
|
|
self.send_output.see(tk.END) |
|
|
self.send_output.see(tk.END) |
|
|
self.send_output.config(state='disabled') |
|
|
self.send_output.config(state='disabled') |
|
|
|
|
|
# 更新状态存储 |
|
|
|
|
|
self.page_states['send']['output_content'] = self.send_output.get(1.0, tk.END) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_service_ini(self, token, sk, sern, bport): |
|
|
def create_service_ini(self, token, sk, sern, bport): |
|
|
@ -886,7 +1036,8 @@ local_port = {bport} |
|
|
universal_newlines=True, |
|
|
universal_newlines=True, |
|
|
creationflags=subprocess.CREATE_NO_WINDOW # 不创建窗口 |
|
|
creationflags=subprocess.CREATE_NO_WINDOW # 不创建窗口 |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
self.page_states['receive']['frpc_process'] = self.frpc_process |
|
|
# 启动输出监控线程 |
|
|
# 启动输出监控线程 |
|
|
output_thread = threading.Thread(target=self.monitor_frpc_output, daemon=True) |
|
|
output_thread = threading.Thread(target=self.monitor_frpc_output, daemon=True) |
|
|
output_thread.start() |
|
|
output_thread.start() |
|
|
@ -968,7 +1119,8 @@ local_port = {bport} |
|
|
universal_newlines=True, |
|
|
universal_newlines=True, |
|
|
creationflags=subprocess.CREATE_NO_WINDOW # 不创建窗口 |
|
|
creationflags=subprocess.CREATE_NO_WINDOW # 不创建窗口 |
|
|
) |
|
|
) |
|
|
|
|
|
self.page_states['receive']['p2p_process'] = self.p2p_process |
|
|
|
|
|
|
|
|
self.append_output("[P2P] 启动P2P文件接收器...\n") |
|
|
self.append_output("[P2P] 启动P2P文件接收器...\n") |
|
|
self.append_output(f"[P2P] 使用PSK: {self.current_psk}\n") |
|
|
self.append_output(f"[P2P] 使用PSK: {self.current_psk}\n") |
|
|
self.append_output(f"[P2P] 文件保存路径: {save_path}\n") |
|
|
self.append_output(f"[P2P] 文件保存路径: {save_path}\n") |
|
|
@ -1049,7 +1201,11 @@ local_port = {bport} |
|
|
# 在新线程中执行 |
|
|
# 在新线程中执行 |
|
|
self.process_thread = threading.Thread(target=self.execute_frpc, daemon=True) |
|
|
self.process_thread = threading.Thread(target=self.execute_frpc, daemon=True) |
|
|
self.process_thread.start() |
|
|
self.process_thread.start() |
|
|
|
|
|
|
|
|
|
|
|
# 更新状态 |
|
|
|
|
|
self.page_states['receive']['is_running'] = True |
|
|
|
|
|
self.page_states['receive']['key_entry_text'] = key |
|
|
|
|
|
self.page_states['receive']['save_path'] = self.receive_path_var.get() |
|
|
|
|
|
|
|
|
def stop_frpc_connection(self): |
|
|
def stop_frpc_connection(self): |
|
|
"""停止所有进程""" |
|
|
"""停止所有进程""" |
|
|
@ -1078,7 +1234,8 @@ local_port = {bport} |
|
|
self.stop_button.config(state='disabled') |
|
|
self.stop_button.config(state='disabled') |
|
|
self.update_status("已停止") |
|
|
self.update_status("已停止") |
|
|
self.append_output("所有进程已停止\n") |
|
|
self.append_output("所有进程已停止\n") |
|
|
|
|
|
self.page_states['receive']['is_running'] = False |
|
|
|
|
|
|
|
|
def update_status(self, status): |
|
|
def update_status(self, status): |
|
|
"""更新状态标签""" |
|
|
"""更新状态标签""" |
|
|
self.status_label.config(text=f"状态: {status}") |
|
|
self.status_label.config(text=f"状态: {status}") |
|
|
@ -1089,6 +1246,8 @@ local_port = {bport} |
|
|
self.receive_output.insert(tk.END, message) |
|
|
self.receive_output.insert(tk.END, message) |
|
|
self.receive_output.see(tk.END) # 自动滚动到底部 |
|
|
self.receive_output.see(tk.END) # 自动滚动到底部 |
|
|
self.receive_output.config(state='disabled') |
|
|
self.receive_output.config(state='disabled') |
|
|
|
|
|
# 更新状态存储 |
|
|
|
|
|
self.page_states['receive']['output_content'] = self.receive_output.get(1.0, tk.END) |
|
|
|
|
|
|
|
|
# 创建主窗口并运行程序 |
|
|
# 创建主窗口并运行程序 |
|
|
if __name__ == "__main__": |
|
|
if __name__ == "__main__": |
|
|
|