feat(utils): 更新器支持指定线程数
This commit is contained in:
@@ -853,6 +853,9 @@ class GlobalConfig(QConfig):
|
|||||||
update_UpdateType = OptionsConfigItem(
|
update_UpdateType = OptionsConfigItem(
|
||||||
"Update", "UpdateType", "main", OptionsValidator(["main", "dev"])
|
"Update", "UpdateType", "main", OptionsValidator(["main", "dev"])
|
||||||
)
|
)
|
||||||
|
update_ThreadNumb = RangeConfigItem(
|
||||||
|
"Update", "ThreadNumb", 8, RangeValidator(1, 32)
|
||||||
|
)
|
||||||
update_ProxyUrlList = ConfigItem("Update", "ProxyUrlList", [], UrlListValidator())
|
update_ProxyUrlList = ConfigItem("Update", "ProxyUrlList", [], UrlListValidator())
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -447,9 +447,9 @@ class UrlListSettingCard(ExpandSettingCard):
|
|||||||
self.window(),
|
self.window(),
|
||||||
)
|
)
|
||||||
if choice.exec():
|
if choice.exec():
|
||||||
self.__removeFolder(item)
|
self.__removeUrl(item)
|
||||||
|
|
||||||
def __removeFolder(self, item: UrlItem):
|
def __removeUrl(self, item: UrlItem):
|
||||||
"""remove folder"""
|
"""remove folder"""
|
||||||
if item.url not in self.urls:
|
if item.url not in self.urls:
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -356,7 +356,15 @@ class MemberManager(QWidget):
|
|||||||
maa_version.append(0)
|
maa_version.append(0)
|
||||||
|
|
||||||
self.downloader = DownloadManager(
|
self.downloader = DownloadManager(
|
||||||
Path(folder), "MAA", maa_version, [], {}
|
Path(folder),
|
||||||
|
"MAA",
|
||||||
|
maa_version,
|
||||||
|
[],
|
||||||
|
{
|
||||||
|
"thread_numb": Config.global_config.get(
|
||||||
|
Config.global_config.update_ThreadNumb
|
||||||
|
)
|
||||||
|
},
|
||||||
)
|
)
|
||||||
self.downloader.show()
|
self.downloader.show()
|
||||||
self.downloader.run()
|
self.downloader.run()
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ from qfluentwidgets import (
|
|||||||
HyperlinkCard,
|
HyperlinkCard,
|
||||||
HeaderCardWidget,
|
HeaderCardWidget,
|
||||||
SwitchSettingCard,
|
SwitchSettingCard,
|
||||||
|
RangeSettingCard,
|
||||||
ExpandGroupSettingCard,
|
ExpandGroupSettingCard,
|
||||||
PushSettingCard,
|
PushSettingCard,
|
||||||
ComboBoxSettingCard,
|
ComboBoxSettingCard,
|
||||||
@@ -391,7 +392,10 @@ class Setting(QWidget):
|
|||||||
{
|
{
|
||||||
"proxy_list": Config.global_config.get(
|
"proxy_list": Config.global_config.get(
|
||||||
Config.global_config.update_ProxyUrlList
|
Config.global_config.update_ProxyUrlList
|
||||||
)
|
),
|
||||||
|
"thread_numb": Config.global_config.get(
|
||||||
|
Config.global_config.update_ThreadNumb
|
||||||
|
),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
# 完成更新器的更新后更新主程序
|
# 完成更新器的更新后更新主程序
|
||||||
@@ -857,6 +861,12 @@ class UpdaterSettingCard(HeaderCardWidget):
|
|||||||
content="选择AUTO_MAA的更新类别",
|
content="选择AUTO_MAA的更新类别",
|
||||||
texts=["稳定版", "公测版"],
|
texts=["稳定版", "公测版"],
|
||||||
)
|
)
|
||||||
|
self.card_ThreadNumb = RangeSettingCard(
|
||||||
|
configItem=Config.global_config.update_ThreadNumb,
|
||||||
|
icon=FluentIcon.PAGE_RIGHT,
|
||||||
|
title="下载器线程数",
|
||||||
|
content="更新器的下载线程数,建议仅在下载速度较慢时适量拉高",
|
||||||
|
)
|
||||||
self.card_ProxyUrlList = UrlListSettingCard(
|
self.card_ProxyUrlList = UrlListSettingCard(
|
||||||
icon=FluentIcon.SETTING,
|
icon=FluentIcon.SETTING,
|
||||||
configItem=Config.global_config.update_ProxyUrlList,
|
configItem=Config.global_config.update_ProxyUrlList,
|
||||||
@@ -874,6 +884,7 @@ class UpdaterSettingCard(HeaderCardWidget):
|
|||||||
Layout = QVBoxLayout()
|
Layout = QVBoxLayout()
|
||||||
Layout.addWidget(self.card_IfAutoUpdate)
|
Layout.addWidget(self.card_IfAutoUpdate)
|
||||||
Layout.addWidget(self.card_UpdateType)
|
Layout.addWidget(self.card_UpdateType)
|
||||||
|
Layout.addWidget(self.card_ThreadNumb)
|
||||||
Layout.addWidget(self.card_ProxyUrlList)
|
Layout.addWidget(self.card_ProxyUrlList)
|
||||||
Layout.addWidget(self.card_CheckUpdate)
|
Layout.addWidget(self.card_CheckUpdate)
|
||||||
self.viewLayout.addLayout(Layout)
|
self.viewLayout.addLayout(Layout)
|
||||||
|
|||||||
@@ -369,21 +369,25 @@ class DownloadManager(QDialog):
|
|||||||
response = requests.head(url)
|
response = requests.head(url)
|
||||||
|
|
||||||
self.file_size = int(response.headers.get("content-length", 0))
|
self.file_size = int(response.headers.get("content-length", 0))
|
||||||
part_size = self.file_size // 8
|
part_size = self.file_size // self.config["thread_numb"]
|
||||||
self.downloaded_size = 0
|
self.downloaded_size = 0
|
||||||
self.last_download_size = 0
|
self.last_download_size = 0
|
||||||
self.last_time = time.time()
|
self.last_time = time.time()
|
||||||
self.speed = 0
|
self.speed = 0
|
||||||
|
|
||||||
# 拆分下载任务,启用多线程下载
|
# 拆分下载任务,启用多线程下载
|
||||||
for i in range(8):
|
for i in range(self.config["thread_numb"]):
|
||||||
|
|
||||||
if self.isInterruptionRequested:
|
if self.isInterruptionRequested:
|
||||||
break
|
break
|
||||||
|
|
||||||
# 计算单任务下载范围
|
# 计算单任务下载范围
|
||||||
start_byte = i * part_size
|
start_byte = i * part_size
|
||||||
end_byte = (i + 1) * part_size - 1 if i != 7 else self.file_size - 1
|
end_byte = (
|
||||||
|
(i + 1) * part_size - 1
|
||||||
|
if (i != self.config["thread_numb"] - 1)
|
||||||
|
else self.file_size - 1
|
||||||
|
)
|
||||||
|
|
||||||
# 创建下载子线程
|
# 创建下载子线程
|
||||||
self.download_process_dict[f"part{i}"] = DownloadProcess(
|
self.download_process_dict[f"part{i}"] = DownloadProcess(
|
||||||
@@ -445,7 +449,7 @@ class DownloadManager(QDialog):
|
|||||||
|
|
||||||
# 合并下载的分段文件
|
# 合并下载的分段文件
|
||||||
with self.download_path.open(mode="wb") as outfile:
|
with self.download_path.open(mode="wb") as outfile:
|
||||||
for i in range(8):
|
for i in range(self.config["thread_numb"]):
|
||||||
with self.download_path.with_suffix(f".part{i}").open(
|
with self.download_path.with_suffix(f".part{i}").open(
|
||||||
mode="rb"
|
mode="rb"
|
||||||
) as infile:
|
) as infile:
|
||||||
@@ -588,7 +592,7 @@ if __name__ == "__main__":
|
|||||||
else:
|
else:
|
||||||
main_version_current = [0, 0, 0, 0]
|
main_version_current = [0, 0, 0, 0]
|
||||||
|
|
||||||
# 从本地配置文件获取更新类型
|
# 从本地配置文件获取更新信息
|
||||||
if (app_path / "config/config.json").exists():
|
if (app_path / "config/config.json").exists():
|
||||||
with (app_path / "config/config.json").open(mode="r", encoding="utf-8") as f:
|
with (app_path / "config/config.json").open(mode="r", encoding="utf-8") as f:
|
||||||
config = json.load(f)
|
config = json.load(f)
|
||||||
@@ -600,9 +604,14 @@ if __name__ == "__main__":
|
|||||||
proxy_list = config["Update"]["ProxyUrlList"]
|
proxy_list = config["Update"]["ProxyUrlList"]
|
||||||
else:
|
else:
|
||||||
proxy_list = []
|
proxy_list = []
|
||||||
|
if "Update" in config and "ThreadNumb" in config["Update"]:
|
||||||
|
thread_numb = config["Update"]["ThreadNumb"]
|
||||||
|
else:
|
||||||
|
thread_numb = 8
|
||||||
else:
|
else:
|
||||||
update_type = "main"
|
update_type = "main"
|
||||||
proxy_list = []
|
proxy_list = []
|
||||||
|
thread_numb = 8
|
||||||
|
|
||||||
# 从远程服务器获取最新版本信息
|
# 从远程服务器获取最新版本信息
|
||||||
for _ in range(3):
|
for _ in range(3):
|
||||||
@@ -623,7 +632,10 @@ if __name__ == "__main__":
|
|||||||
sys.exit(f"获取版本信息时出错:\n{err}")
|
sys.exit(f"获取版本信息时出错:\n{err}")
|
||||||
|
|
||||||
# 合并代理列表
|
# 合并代理列表
|
||||||
download_config = {"proxy_list": list(set(proxy_list + remote_proxy_list))}
|
download_config = {
|
||||||
|
"proxy_list": list(set(proxy_list + remote_proxy_list)),
|
||||||
|
"thread_numb": thread_numb,
|
||||||
|
}
|
||||||
|
|
||||||
# 启动更新线程
|
# 启动更新线程
|
||||||
if main_version_remote > main_version_current:
|
if main_version_remote > main_version_current:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"main_version": "4.2.5.2",
|
"main_version": "4.2.5.2",
|
||||||
"updater_version": "1.1.2.2",
|
"updater_version": "1.2.0.0",
|
||||||
"announcement": "\n## 新增功能\n- 屏蔽MuMu模拟器开屏广告功能上线\n- 更新器支持多线程下载\n## 修复BUG\n- 修复统计信息HTML模板公招匹配错误\n## 程序优化\n- 暂无",
|
"announcement": "\n## 新增功能\n- 屏蔽MuMu模拟器开屏广告功能上线\n- 更新器支持多线程下载\n## 修复BUG\n- 修复统计信息HTML模板公招匹配错误\n## 程序优化\n- 暂无",
|
||||||
"proxy_list": [
|
"proxy_list": [
|
||||||
"",
|
"",
|
||||||
|
|||||||
Reference in New Issue
Block a user