From 20b73b4a975f424b358191efdbec564f2be6556f Mon Sep 17 00:00:00 2001 From: Zhao Zuohong Date: Thu, 7 Sep 2023 16:29:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=8A=A5=E9=94=99=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 27762cb..594aad1 100755 --- a/main.py +++ b/main.py @@ -144,25 +144,35 @@ def prepare_to_install(path, new_hash, pattern_list): version_name = "" +failed_list = [] + def remove_files(): global remove_list + global failed_list for subpath in remove_list: path = pathlib.Path(conf["install_dir"]) / conf["dir_name"] / subpath - path.unlink() + try: + path.unlink() + except Exception as e: + failed_list.append({"path": path, "reason": str(e)}) remove_list = [] def download_single_file(subpath): + global failed_list mirror = conf["mirror"] if not mirror.endswith("/"): mirror += "/" url = f"{mirror}{version_name}/{subpath}" - r = requests.get(url) - path = pathlib.Path(conf["install_dir"]) / conf["dir_name"] / subpath - path.parent.mkdir(exist_ok=True, parents=True) - with path.open("wb") as f: - f.write(r.content) + try: + r = requests.get(url) + path = pathlib.Path(conf["install_dir"]) / conf["dir_name"] / subpath + path.parent.mkdir(exist_ok=True, parents=True) + with path.open("wb") as f: + f.write(r.content) + except Exception as e: + failed_list.append({"path": path, "reason": str(e)}) return subpath @@ -208,6 +218,7 @@ def download_all_files(window): window["versions"].update(values=[v["display_name"] for v in versions]) window["status"].update("已获取版本列表") elif event == "开始安装": + failed_list = [] if not conf["dir_name"]: sg.popup_error("子文件夹不可为空!") continue @@ -247,7 +258,16 @@ def download_all_files(window): else: window["status"].update("安装已取消") elif event == "-download-finish-": - window["status"].update("安装完成!") + if failed_list: + window["status"].update("安装失败!") + sg.popup_scrolled( + "\n".join([f"{i['path']}: {i['reason']}" for i in failed_list]), + yes_no=True, + size=(80, 24), + title="安装失败", + ) + else: + window["status"].update("安装完成!") window.close()