diff --git a/.gitignore b/.gitignore index 68bc17f..166bc6c 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,5 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + +Test.py \ No newline at end of file diff --git a/Modules/Download.py b/Modules/Download.py index e847f3b..6fc9126 100644 --- a/Modules/Download.py +++ b/Modules/Download.py @@ -4,8 +4,24 @@ def need_download(): global unzip_folder import requests - # 调用 GitHub API 获取最新版本信息 - url = "https://api.github.com/repos/LiteLoaderQQNT/LiteLoaderQQNT/releases/latest" + import socket + # 检测 Google 是否能连接 + def check_google(): + try: + socket.create_connection(("google.com", 443), timeout=1) + logging("[System] 当前网络环境内可连接 Google") + return True + except (socket.timeout, socket.error): + logging("[System] 当前网络环境内无法连接 Google") + return False # 无法连接 Google 或连接过慢(1s) + + # 调用 GitHub/KGitHub API 获取最新版本信息 + if check_google(): # 检查 True/False + url = "https://api.github.com/repos/LiteLoaderQQNT/LiteLoaderQQNT/releases/latest" + logging("[Download] 已使用官方源获取 API 信息") + else: + url = "https://api.kkgithub.com/repos/LiteLoaderQQNT/LiteLoaderQQNT/releases/latest" + logging("[Download] 已使用 KKGitHub 方式获取 API 信息") response = requests.get(url) data = response.json() @@ -15,6 +31,24 @@ def need_download(): if "LiteLoaderQQNT.zip" in asset["browser_download_url"]: download_url = asset["browser_download_url"] break + + if check_google(): + while True: + download_way = input("\n你当前的环境可以连接 Google,是否使用官方下载源下载 LiteLoaderQQNT?\n(y/n)\n> ").lower() + if download_way == "y" or download_way == "yes": + logging("[Download] 未更改 LiteLoaderQQNT.zip 下载链接,继续使用官方下载源") + break + elif download_way == "n" or download_way == "no": + print("已使用 ghproxy.cn 进行加速下载") + download_url = download_url.replace("github.com", "ghproxy.cn/?q=https://github.com") # 替换新的下载链接 + logging("[Download] 已更改 LiteLoaderQQNT.zip 下载源至 ghproxy.cn") + break + else: + continue + else: + download_url = download_url.replace("github.com", "ghproxy.cn/?q=https://github.com") # 替换新的下载链接 + logging("[Download] 最终的 LiteLoaderQQNT.zip 下载链接为:" + download_url) + # 下载 if download_url: diff --git a/Modules/Patch.py b/Modules/Patch.py index c74ab8b..c0df5d8 100644 --- a/Modules/Patch.py +++ b/Modules/Patch.py @@ -16,8 +16,26 @@ def patch(): logging("[System] 最大计算值:" + str(maxbit) + ",为 32 位操作系统") bit = "86" # 系统位数: 32 位 - # 调用 GitHub API 获取最新版本信息 - url = "https://api.github.com/repos/LiteLoaderQQNT/QQNTFileVerifyPatch/releases/latest" + # 检测网络环境 + import socket + def check_google(): + global cg + try: + socket.create_connection(("google.com", 443), timeout=1) + logging("[System] 当前网络环境内可连接 Google") + cg = 0 + except (socket.timeout, socket.error): + logging("[System] 当前网络环境内无法连接 Google") + cg = 1 # 无法连接 Google 或连接过慢(1s) + check_google() + + # 调用 GitHub/KGitHub API 获取最新版本信息 + if cg == 0: # 检查 True/False + url = "https://api.github.com/repos/LiteLoaderQQNT/QQNTFileVerifyPatch/releases/latest" + logging("[Patch] 已使用官方源获取补丁 API 信息") + else: + url = "https://api.kkgithub.com/repos/LiteLoaderQQNT/QQNTFileVerifyPatch/releases/latest" + logging("[Patch] 已使用 KKGitHub 方式获取补丁 API 信息") response = requests.get(url) data = response.json() @@ -28,6 +46,23 @@ def patch(): download_url = asset["browser_download_url"] break + if cg == 0: + while True: + download_way = input("\n------------\n你当前的环境可以连接 Google,是否使用官方下载源下载\033[1m补丁\033[0m?\n(y/n)\n> ").lower() + if download_way == "y" or download_way == "yes": + logging("[Download] 未更改补丁下载链接,继续使用官方下载源") + break + elif download_way == "n" or download_way == "no": + print("已使用 ghproxy.cn 进行加速下载") + download_url = download_url.replace("github.com", "ghproxy.cn/?q=https://github.com") # 替换新的下载链接 + logging("[Download] 已更改补丁下载源至 ghproxy.cn") + break + else: + continue + else: + download_url = download_url.replace("github.com", "ghproxy.cn/?q=https://github.com") # 替换新的下载链接 + logging("[Download] 最终的补丁下载链接为:" + download_url) + # 提取包含 "dbghelp_x{bit}.dll" 的 dbghelp.dll 文件大小 github_file_size = "" for asset in data["assets"]: diff --git a/Modules/Pycache_Clear.py b/Modules/Pycache_Clear.py deleted file mode 100644 index e2e9ba9..0000000 --- a/Modules/Pycache_Clear.py +++ /dev/null @@ -1,11 +0,0 @@ -"""清理傻逼""" - -def pycache_clear(): - import os - os.system("echo off") - os.system("""for /d /r %i in (__pycache__) do rd /s /q "%i""") - os.system("del /q build") - os.system("del /f /q MainPage.spec") - os.system("cls") - os.system("echo on") -pycache_clear() \ No newline at end of file