Skip to content

Commit

Permalink
增加了国内网络环境 API/下载链接
Browse files Browse the repository at this point in the history
  • Loading branch information
Ad-closeNN committed Nov 16, 2024
1 parent f67ef98 commit ae7a6ec
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 36 additions & 2 deletions Modules/Download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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:
Expand Down
39 changes: 37 additions & 2 deletions Modules/Patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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"]:
Expand Down
11 changes: 0 additions & 11 deletions Modules/Pycache_Clear.py

This file was deleted.

0 comments on commit ae7a6ec

Please sign in to comment.