Skip to content

Commit

Permalink
use filesize for template export
Browse files Browse the repository at this point in the history
Update export_template_manager.cpp
  • Loading branch information
Ughuuu committed Dec 5, 2024
1 parent 05b782b commit 907f902
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 17 additions & 10 deletions editor/export/export_template_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void ExportTemplateManager::_download_current() {
download_progress_hb->show();

if (mirrors_available) {
String mirror_url = _get_selected_mirror();
String mirror_url = _get_selected_mirror()["url"];
if (mirror_url.is_empty()) {
_set_current_progress_status(TTR("There are no mirrors available."), true);
return;
Expand Down Expand Up @@ -289,7 +289,10 @@ void ExportTemplateManager::_refresh_mirrors_completed(int p_status, int p_code,
ERR_CONTINUE(!m.has("url") || !m.has("name"));

mirrors_list->add_item(m["name"]);
mirrors_list->set_item_metadata(i + 1, m["url"]);
Dictionary metadata_dict;
metadata_dict["url"] = m["url"];
metadata_dict["filesize"] = m.get("filesize", -1);
mirrors_list->set_item_metadata(i + 1, metadata_dict);

mirrors_available = true;
}
Expand All @@ -304,7 +307,7 @@ void ExportTemplateManager::_refresh_mirrors_completed(int p_status, int p_code,
is_refreshing_mirrors = false;

if (is_downloading_templates) {
String mirror_url = _get_selected_mirror();
String mirror_url = _get_selected_mirror()["url"];
if (mirror_url.is_empty()) {
_set_current_progress_status(TTR("There are no mirrors available."), true);
return;
Expand All @@ -319,6 +322,7 @@ bool ExportTemplateManager::_humanize_http_status(HTTPRequest *p_request, String
*r_downloaded_bytes = -1;
*r_total_bytes = -1;
bool success = true;
int total_size = _get_selected_mirror()["filesize"];

switch (p_request->get_http_client_status()) {
case HTTPClient::STATUS_DISCONNECTED:
Expand Down Expand Up @@ -348,10 +352,13 @@ bool ExportTemplateManager::_humanize_http_status(HTTPRequest *p_request, String
case HTTPClient::STATUS_BODY:
*r_status = TTR("Downloading");
*r_downloaded_bytes = p_request->get_downloaded_bytes();
*r_total_bytes = p_request->get_body_size();
if (total_size < 0) {
total_size = p_request->get_body_size();
}
*r_total_bytes = total_size;

if (p_request->get_body_size() > 0) {
*r_status += " " + String::humanize_size(p_request->get_downloaded_bytes()) + "/" + String::humanize_size(p_request->get_body_size());
if (total_size > 0) {
*r_status += " " + String::humanize_size(p_request->get_downloaded_bytes()) + "/" + String::humanize_size(total_size);
} else {
*r_status += " " + String::humanize_size(p_request->get_downloaded_bytes());
}
Expand Down Expand Up @@ -580,9 +587,9 @@ void ExportTemplateManager::_uninstall_template_confirmed() {
_update_template_status();
}

String ExportTemplateManager::_get_selected_mirror() const {
Dictionary ExportTemplateManager::_get_selected_mirror() const {
if (mirrors_list->get_item_count() == 1) {
return "";
return Dictionary();
}

int selected = mirrors_list->get_selected_id();
Expand All @@ -597,7 +604,7 @@ String ExportTemplateManager::_get_selected_mirror() const {
void ExportTemplateManager::_mirror_options_button_cbk(int p_id) {
switch (p_id) {
case VISIT_WEB_MIRROR: {
String mirror_url = _get_selected_mirror();
String mirror_url = _get_selected_mirror()["url"];
if (mirror_url.is_empty()) {
EditorNode::get_singleton()->show_warning(TTR("There are no mirrors available."));
return;
Expand All @@ -607,7 +614,7 @@ void ExportTemplateManager::_mirror_options_button_cbk(int p_id) {
} break;

case COPY_MIRROR_URL: {
String mirror_url = _get_selected_mirror();
String mirror_url = _get_selected_mirror()["url"];
if (mirror_url.is_empty()) {
EditorNode::get_singleton()->show_warning(TTR("There are no mirrors available."));
return;
Expand Down
2 changes: 1 addition & 1 deletion editor/export/export_template_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class ExportTemplateManager : public AcceptDialog {
void _uninstall_template(const String &p_version);
void _uninstall_template_confirmed();

String _get_selected_mirror() const;
Dictionary _get_selected_mirror() const;
void _mirror_options_button_cbk(int p_id);
void _installed_table_button_cbk(Object *p_item, int p_column, int p_id, MouseButton p_button);

Expand Down

0 comments on commit 907f902

Please sign in to comment.