From 1e22d83a4b3cc35d1bb69f93efbc2e0e60ec09c3 Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Wed, 1 May 2024 12:14:51 +0100 Subject: [PATCH] Improve resource pack downloading (#1042) * Improve resource pack downloading Fixed trackback in GUI. Added message dialog to allow the user to retry downloading. * Reformatted --- amulet_map_editor/lang/en.lang | 1 + .../edit/api/canvas/base_edit_canvas.py | 83 +++++++++++-------- 2 files changed, 49 insertions(+), 35 deletions(-) diff --git a/amulet_map_editor/lang/en.lang b/amulet_map_editor/lang/en.lang index 0a7febab..8e3b32bd 100644 --- a/amulet_map_editor/lang/en.lang +++ b/amulet_map_editor/lang/en.lang @@ -143,6 +143,7 @@ program_3d_edit.canvas.java_rp_failed=Failed to download the latest Java resourc program_3d_edit.canvas.java_rp_failed_default=Check your internet connection and restart Amulet. program_3d_edit.canvas.java_rp_failed_mac_certificates=The certificates to access the internet were not installed.\nRun the "Install Certificates.command" program that can be found in "Applications/Python 3.x". program_3d_edit.canvas.loading_resource_packs=Loading resource packs +program_3d_edit.canvas.retry_download=Failed to download the resource pack. Do you want to retry? program_3d_edit.canvas.creating_texture_atlas=Creating texture atlas program_3d_edit.canvas.setting_up_renderer=Setting up renderer diff --git a/amulet_map_editor/programs/edit/api/canvas/base_edit_canvas.py b/amulet_map_editor/programs/edit/api/canvas/base_edit_canvas.py index 70a8d05c..8acb33a7 100644 --- a/amulet_map_editor/programs/edit/api/canvas/base_edit_canvas.py +++ b/amulet_map_editor/programs/edit/api/canvas/base_edit_canvas.py @@ -145,42 +145,55 @@ def thread_setup(self) -> Generator[OperationYieldType, None, None]: yield 0.1, lang.get( "program_3d_edit.canvas.downloading_java_vanilla_resource_pack" ) - gen = get_java_vanilla_latest_iter() - try: - while True: - yield next(gen) * 0.4 + 0.1 - except StopIteration as e: - packs.append(e.value) - except Exception as e: - if sys.platform == "darwin" and "CERTIFICATE_VERIFY_FAILED" in str(e): - msg = lang.get( - "program_3d_edit.canvas.java_rp_failed_mac_certificates" - ) - else: - msg = lang.get("program_3d_edit.canvas.java_rp_failed_default") - log.error( - msg, - exc_info=True, - ) - wait = True - - def show_error(): - nonlocal wait - try: - dialog = TracebackDialog( - self, - lang.get("program_3d_edit.canvas.java_rp_failed"), - f"{msg}\n{e}", - traceback.format_exc(), + while True: + gen = get_java_vanilla_latest_iter() + try: + while True: + yield next(gen) * 0.4 + 0.1 + except StopIteration as e: + packs.append(e.value) + break + except Exception as e: + if sys.platform == "darwin" and "CERTIFICATE_VERIFY_FAILED" in str( + e + ): + msg = lang.get( + "program_3d_edit.canvas.java_rp_failed_mac_certificates" ) - dialog.ShowModal() - dialog.Destroy() - finally: - wait = False - - wx.CallAfter(show_error) - while wait: - time.sleep(0.1) + else: + msg = lang.get("program_3d_edit.canvas.java_rp_failed_default") + log.error( + msg, + exc_info=True, + ) + wait = True + tb = traceback.format_exc() + + def show_error(): + nonlocal wait + try: + dialog = TracebackDialog( + self, + lang.get("program_3d_edit.canvas.java_rp_failed"), + f"{msg}\n{e}", + tb, + ) + dialog.ShowModal() + dialog.Destroy() + finally: + wait = False + + wx.CallAfter(show_error) + while wait: + time.sleep(0.1) + + msg = wx.MessageDialog( + self, + lang.get("program_3d_edit.canvas.retry_download"), + style=wx.YES_NO, + ) + if msg.ShowModal() == wx.ID_NO: + break yield 0.5, lang.get("program_3d_edit.canvas.loading_resource_packs") packs += [pack for pack in user_packs if isinstance(pack, JavaResourcePack)]