@@ -144,25 +144,35 @@ def prepare_to_install(path, new_hash, pattern_list):
144144
145145version_name = ""
146146
147+ failed_list = []
148+
147149
148150def 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
156162def 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
253273window .close ()
0 commit comments