mirror of
https://github.com/hyb-oyqq/FRAISEMOE-Addons-Installer-NEXT.git
synced 2026-04-05 21:42:51 +00:00
feat(core): 优化主程序和下载管理器逻辑
- 移除冗余注释,简化代码可读性。 - 更新隐私协议管理器的异常处理逻辑,确保用户体验流畅。 - 改进下载管理器中的下载流程,优化用户选择游戏的对话框逻辑。 - 调整下载线程设置,确保更高效的下载管理。
This commit is contained in:
@@ -30,15 +30,14 @@ class IpOptimizer:
|
||||
|
||||
ip_txt_path = resource_path("ip.txt")
|
||||
|
||||
# 正确的参数设置,根据cfst帮助文档
|
||||
command = [
|
||||
cst_path,
|
||||
"-n", "1000", # 延迟测速线程数 (默认200)
|
||||
"-p", "1", # 显示结果数量 (默认10个)
|
||||
"-url", url, # 指定测速地址
|
||||
"-f", ip_txt_path, # IP文件
|
||||
"-dd", # 禁用下载测速,按延迟排序
|
||||
"-o"," " # 不写入结果文件
|
||||
"-n", "1000", # 延迟测速线程数
|
||||
"-p", "1", # 显示结果数量
|
||||
"-url", url,
|
||||
"-f", ip_txt_path,
|
||||
"-dd", # 禁用下载测速
|
||||
"-o"," " # 不写入结果文件
|
||||
]
|
||||
|
||||
creation_flags = subprocess.CREATE_NO_WINDOW if sys.platform == 'win32' else 0
|
||||
@@ -57,11 +56,9 @@ class IpOptimizer:
|
||||
bufsize=0
|
||||
)
|
||||
|
||||
# 更新正则表达式以匹配cfst输出中的IP格式
|
||||
# 匹配格式: IP地址在行首,后面跟着一些数字和文本
|
||||
ip_pattern = re.compile(r'^(\d+\.\d+\.\d+\.\d+)\s+.*')
|
||||
|
||||
# 标记是否已经找到结果表头和完成标记
|
||||
found_header = False
|
||||
found_completion = False
|
||||
|
||||
@@ -72,7 +69,7 @@ class IpOptimizer:
|
||||
|
||||
optimal_ip = None
|
||||
timeout_counter = 0
|
||||
max_timeout = 300 # 增加超时时间到5分钟
|
||||
max_timeout = 300 # 超时时间5分钟
|
||||
|
||||
while True:
|
||||
if self.process.poll() is not None:
|
||||
@@ -98,35 +95,29 @@ class IpOptimizer:
|
||||
if cleaned_line:
|
||||
print(cleaned_line)
|
||||
|
||||
# 检测结果表头
|
||||
if "IP 地址" in cleaned_line and "平均延迟" in cleaned_line:
|
||||
print("检测到IP结果表头,准备获取IP地址...")
|
||||
found_header = True
|
||||
continue
|
||||
|
||||
# 检测完成标记
|
||||
if "完整测速结果已写入" in cleaned_line or "按下 回车键 或 Ctrl+C 退出" in cleaned_line:
|
||||
print("检测到测速完成信息")
|
||||
found_completion = True
|
||||
|
||||
# 如果已经找到了IP,可以退出了
|
||||
if optimal_ip:
|
||||
break
|
||||
|
||||
# 已找到表头后,尝试匹配IP地址行
|
||||
if found_header:
|
||||
match = ip_pattern.search(cleaned_line)
|
||||
if match and not optimal_ip: # 只保存第一个匹配的IP(最优IP)
|
||||
if match and not optimal_ip:
|
||||
optimal_ip = match.group(1)
|
||||
print(f"找到最优 IP: {optimal_ip}")
|
||||
# 找到最优IP后立即退出循环,不等待完成标记
|
||||
break
|
||||
|
||||
except Exception as e:
|
||||
print(f"读取输出时发生错误: {e}")
|
||||
break
|
||||
|
||||
# 确保完全读取输出后再发送退出信号
|
||||
if self.process and self.process.poll() is None:
|
||||
try:
|
||||
if self.process.stdin and not self.process.stdin.closed:
|
||||
@@ -166,14 +157,13 @@ class IpOptimizer:
|
||||
print(f"错误: ipv6.txt 未在资源路径中找到。")
|
||||
return None
|
||||
|
||||
# 正确的参数设置,根据cfst帮助文档
|
||||
command = [
|
||||
cst_path,
|
||||
"-n", "1000", # 延迟测速线程数,IPv6测试线程稍少
|
||||
"-p", "1", # 显示结果数量 (默认10个)
|
||||
"-url", url, # 指定测速地址
|
||||
"-f", ipv6_txt_path, # IPv6文件
|
||||
"-dd", # 禁用下载测速,按延迟排序
|
||||
"-n", "1000", # 延迟测速线程数
|
||||
"-p", "1", # 显示结果数量
|
||||
"-url", url,
|
||||
"-f", ipv6_txt_path,
|
||||
"-dd", # 禁用下载测速
|
||||
"-o", " " # 不写入结果文件
|
||||
]
|
||||
|
||||
@@ -193,11 +183,9 @@ class IpOptimizer:
|
||||
bufsize=0
|
||||
)
|
||||
|
||||
# 更新正则表达式以匹配cfst输出中的IPv6格式
|
||||
# IPv6格式更加复杂,可能有多种表示形式
|
||||
# IPv6格式可能有多种表示形式
|
||||
ipv6_pattern = re.compile(r'^([0-9a-fA-F:]+)\s+.*')
|
||||
|
||||
# 标记是否已经找到结果表头和完成标记
|
||||
found_header = False
|
||||
found_completion = False
|
||||
|
||||
@@ -208,7 +196,7 @@ class IpOptimizer:
|
||||
|
||||
optimal_ipv6 = None
|
||||
timeout_counter = 0
|
||||
max_timeout = 300 # 增加超时时间到5分钟
|
||||
max_timeout = 300 # 超时时间5分钟
|
||||
|
||||
while True:
|
||||
if self.process.poll() is not None:
|
||||
@@ -234,35 +222,29 @@ class IpOptimizer:
|
||||
if cleaned_line:
|
||||
print(cleaned_line)
|
||||
|
||||
# 检测结果表头
|
||||
if "IP 地址" in cleaned_line and "平均延迟" in cleaned_line:
|
||||
print("检测到IPv6结果表头,准备获取IPv6地址...")
|
||||
found_header = True
|
||||
continue
|
||||
|
||||
# 检测完成标记
|
||||
if "完整测速结果已写入" in cleaned_line or "按下 回车键 或 Ctrl+C 退出" in cleaned_line:
|
||||
print("检测到IPv6测速完成信息")
|
||||
found_completion = True
|
||||
|
||||
# 如果已经找到了IPv6,可以退出了
|
||||
if optimal_ipv6:
|
||||
break
|
||||
|
||||
# 已找到表头后,尝试匹配IPv6地址行
|
||||
if found_header:
|
||||
match = ipv6_pattern.search(cleaned_line)
|
||||
if match and not optimal_ipv6: # 只保存第一个匹配的IPv6(最优IPv6)
|
||||
if match and not optimal_ipv6:
|
||||
optimal_ipv6 = match.group(1)
|
||||
print(f"找到最优 IPv6: {optimal_ipv6}")
|
||||
# 找到最优IPv6后立即退出循环,不等待完成标记
|
||||
break
|
||||
|
||||
except Exception as e:
|
||||
print(f"读取输出时发生错误: {e}")
|
||||
break
|
||||
|
||||
# 确保完全读取输出后再发送退出信号
|
||||
if self.process and self.process.poll() is None:
|
||||
try:
|
||||
if self.process.stdin and not self.process.stdin.closed:
|
||||
@@ -324,14 +306,3 @@ class IpOptimizerThread(QThread):
|
||||
|
||||
def stop(self):
|
||||
self.optimizer.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# 用于直接测试此模块
|
||||
test_url = "https://speed.cloudflare.com/__down?during=download&bytes=104857600"
|
||||
optimizer = IpOptimizer()
|
||||
ip = optimizer.get_optimal_ip(test_url)
|
||||
if ip:
|
||||
print(f"为 {test_url} 找到的最优 IP 是: {ip}")
|
||||
else:
|
||||
print(f"未能为 {test_url} 找到最优 IP。")
|
||||
Reference in New Issue
Block a user