Skip to content

Commit 20b73b4

Browse files
author
Zhao Zuohong
committed
显示报错信息
1 parent 8a11084 commit 20b73b4

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

main.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,25 +144,35 @@ def prepare_to_install(path, new_hash, pattern_list):
144144

145145
version_name = ""
146146

147+
failed_list = []
148+
147149

148150
def remove_files():
149151
global remove_list
152+
global failed_list
150153
for subpath in remove_list:
151154
path = pathlib.Path(conf["install_dir"]) / conf["dir_name"] / subpath
152-
path.unlink()
155+
try:
156+
path.unlink()
157+
except Exception as e:
158+
failed_list.append({"path": path, "reason": str(e)})
153159
remove_list = []
154160

155161

156162
def download_single_file(subpath):
163+
global failed_list
157164
mirror = conf["mirror"]
158165
if not mirror.endswith("/"):
159166
mirror += "/"
160167
url = f"{mirror}{version_name}/{subpath}"
161-
r = requests.get(url)
162-
path = pathlib.Path(conf["install_dir"]) / conf["dir_name"] / subpath
163-
path.parent.mkdir(exist_ok=True, parents=True)
164-
with path.open("wb") as f:
165-
f.write(r.content)
168+
try:
169+
r = requests.get(url)
170+
path = pathlib.Path(conf["install_dir"]) / conf["dir_name"] / subpath
171+
path.parent.mkdir(exist_ok=True, parents=True)
172+
with path.open("wb") as f:
173+
f.write(r.content)
174+
except Exception as e:
175+
failed_list.append({"path": path, "reason": str(e)})
166176
return subpath
167177

168178

@@ -208,6 +218,7 @@ def download_all_files(window):
208218
window["versions"].update(values=[v["display_name"] for v in versions])
209219
window["status"].update("已获取版本列表")
210220
elif event == "开始安装":
221+
failed_list = []
211222
if not conf["dir_name"]:
212223
sg.popup_error("子文件夹不可为空!")
213224
continue
@@ -247,7 +258,16 @@ def download_all_files(window):
247258
else:
248259
window["status"].update("安装已取消")
249260
elif event == "-download-finish-":
250-
window["status"].update("安装完成!")
261+
if failed_list:
262+
window["status"].update("安装失败!")
263+
sg.popup_scrolled(
264+
"\n".join([f"{i['path']}: {i['reason']}" for i in failed_list]),
265+
yes_no=True,
266+
size=(80, 24),
267+
title="安装失败",
268+
)
269+
else:
270+
window["status"].update("安装完成!")
251271

252272

253273
window.close()

0 commit comments

Comments
 (0)