Skip to content

Commit

Permalink
Improve resource pack downloading (#1042)
Browse files Browse the repository at this point in the history
* Improve resource pack downloading

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

* Reformatted
  • Loading branch information
gentlegiantJGC authored May 1, 2024
1 parent 9a3d9c5 commit 1e22d83
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 35 deletions.
1 change: 1 addition & 0 deletions amulet_map_editor/lang/en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
83 changes: 48 additions & 35 deletions amulet_map_editor/programs/edit/api/canvas/base_edit_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 1e22d83

Please sign in to comment.