Improve resource pack downloading (#1042)

* Improve resource pack downloading

Fixed trackback in GUI.
Added message dialog to allow the user to retry downloading.

* Reformatted
This commit is contained in:
gentlegiantJGC 2024-05-01 12:14:51 +01:00 committed by GitHub
parent 9a3d9c5a3a
commit 1e22d83a4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 48 additions and 34 deletions

View File

@ -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_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.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.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.creating_texture_atlas=Creating texture atlas
program_3d_edit.canvas.setting_up_renderer=Setting up renderer program_3d_edit.canvas.setting_up_renderer=Setting up renderer

View File

@ -145,14 +145,18 @@ class BaseEditCanvas(EventCanvas):
yield 0.1, lang.get( yield 0.1, lang.get(
"program_3d_edit.canvas.downloading_java_vanilla_resource_pack" "program_3d_edit.canvas.downloading_java_vanilla_resource_pack"
) )
while True:
gen = get_java_vanilla_latest_iter() gen = get_java_vanilla_latest_iter()
try: try:
while True: while True:
yield next(gen) * 0.4 + 0.1 yield next(gen) * 0.4 + 0.1
except StopIteration as e: except StopIteration as e:
packs.append(e.value) packs.append(e.value)
break
except Exception as e: except Exception as e:
if sys.platform == "darwin" and "CERTIFICATE_VERIFY_FAILED" in str(e): if sys.platform == "darwin" and "CERTIFICATE_VERIFY_FAILED" in str(
e
):
msg = lang.get( msg = lang.get(
"program_3d_edit.canvas.java_rp_failed_mac_certificates" "program_3d_edit.canvas.java_rp_failed_mac_certificates"
) )
@ -163,6 +167,7 @@ class BaseEditCanvas(EventCanvas):
exc_info=True, exc_info=True,
) )
wait = True wait = True
tb = traceback.format_exc()
def show_error(): def show_error():
nonlocal wait nonlocal wait
@ -171,7 +176,7 @@ class BaseEditCanvas(EventCanvas):
self, self,
lang.get("program_3d_edit.canvas.java_rp_failed"), lang.get("program_3d_edit.canvas.java_rp_failed"),
f"{msg}\n{e}", f"{msg}\n{e}",
traceback.format_exc(), tb,
) )
dialog.ShowModal() dialog.ShowModal()
dialog.Destroy() dialog.Destroy()
@ -182,6 +187,14 @@ class BaseEditCanvas(EventCanvas):
while wait: while wait:
time.sleep(0.1) 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") yield 0.5, lang.get("program_3d_edit.canvas.loading_resource_packs")
packs += [pack for pack in user_packs if isinstance(pack, JavaResourcePack)] packs += [pack for pack in user_packs if isinstance(pack, JavaResourcePack)]
packs.append(get_java_vanilla_fix()) packs.append(get_java_vanilla_fix())