2023-01-05 12:25:55 +00:00
/**************************************************************************/
/* export_template_manager.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
2018-01-04 23:50:27 +00:00
2017-03-21 02:31:41 +00:00
# include "export_template_manager.h"
2017-04-28 18:04:09 +00:00
2021-06-11 12:51:48 +00:00
# include "core/io/dir_access.h"
2018-09-11 16:13:45 +00:00
# include "core/io/json.h"
# include "core/io/zip_io.h"
# include "core/version.h"
2022-02-12 01:46:22 +00:00
# include "editor/editor_node.h"
2022-02-14 13:00:03 +00:00
# include "editor/editor_paths.h"
2022-02-12 01:46:22 +00:00
# include "editor/editor_scale.h"
2022-07-31 18:14:15 +00:00
# include "editor/editor_settings.h"
2022-07-20 22:45:01 +00:00
# include "editor/progress_dialog.h"
# include "scene/gui/file_dialog.h"
2022-11-19 11:45:49 +00:00
# include "scene/gui/menu_button.h"
2022-07-31 18:14:15 +00:00
# include "scene/gui/separator.h"
2022-07-20 22:45:01 +00:00
# include "scene/gui/tree.h"
# include "scene/main/http_request.h"
2017-11-17 20:48:24 +00:00
2021-05-20 20:15:49 +00:00
void ExportTemplateManager : : _update_template_status ( ) {
// Fetch installed templates from the file system.
2022-03-23 09:08:58 +00:00
Ref < DirAccess > da = DirAccess : : create ( DirAccess : : ACCESS_FILESYSTEM ) ;
2022-07-29 00:36:26 +00:00
const String & templates_dir = EditorPaths : : get_singleton ( ) - > get_export_templates_dir ( ) ;
2017-03-21 02:31:41 +00:00
2021-05-20 20:15:49 +00:00
Error err = da - > change_dir ( templates_dir ) ;
ERR_FAIL_COND_MSG ( err ! = OK , " Could not access templates directory at ' " + templates_dir + " '. " ) ;
2017-03-21 02:31:41 +00:00
2022-05-13 13:04:37 +00:00
RBSet < String > templates ;
2021-05-20 20:15:49 +00:00
da - > list_dir_begin ( ) ;
2017-03-21 02:31:41 +00:00
if ( err = = OK ) {
2021-05-20 20:15:49 +00:00
String c = da - > get_next ( ) ;
2021-12-09 09:42:46 +00:00
while ( ! c . is_empty ( ) ) {
2021-05-20 20:15:49 +00:00
if ( da - > current_is_dir ( ) & & ! c . begins_with ( " . " ) ) {
2017-03-21 02:31:41 +00:00
templates . insert ( c ) ;
}
2021-05-20 20:15:49 +00:00
c = da - > get_next ( ) ;
2017-03-21 02:31:41 +00:00
}
}
2021-05-20 20:15:49 +00:00
da - > list_dir_end ( ) ;
2017-03-21 02:31:41 +00:00
2021-05-20 20:15:49 +00:00
// Update the state of the current version.
Refactor version macros and fix related bugs
The previous logic with VERSION_MKSTRING was a bit unwieldy, so there were
several places hardcoding their own variant of the version string, potentially
with bugs (e.g. forgetting the patch number when defined).
The new logic defines:
- VERSION_BRANCH, the main 'major.minor' version (e.g. 3.1)
- VERSION_NUMBER, which can be 'major.minor' or 'major.minor.patch',
depending on whether the latter is defined (e.g. 3.1.4)
- VERSION_FULL_CONFIG, which contains the version status (e.g. stable)
and the module-specific suffix (e.g. mono)
- VERSION_FULL_BUILD, same as above but with build/reference name
(e.g. official, custom_build, mageia, etc.)
Note: Slight change here, as the previous format had the build name
*before* the module-specific suffix; now it's after
- VERSION_FULL_NAME, same as before, so VERSION_FULL_BUILD prefixed
with "Godot v" for readability
Bugs fixed thanks to that:
- Export templates version matching now properly takes VERSION_PATCH
into account by relying on VERSION_FULL_CONFIG.
- ClassDB hash no longer takes the build name into account, but limits
itself to VERSION_FULL_CONFIG (build name is cosmetic, not relevant
for the API hash).
- Docs XML no longer hardcode the VERSION_STATUS, this was annoying.
- Small cleanup in Windows .rc file thanks to new macros.
2018-02-23 18:48:49 +00:00
String current_version = VERSION_FULL_CONFIG ;
2021-05-20 20:15:49 +00:00
current_value - > set_text ( current_version ) ;
2017-03-21 02:31:41 +00:00
if ( templates . has ( current_version ) ) {
2021-05-20 20:15:49 +00:00
current_missing_label - > hide ( ) ;
current_installed_label - > show ( ) ;
current_installed_hb - > show ( ) ;
current_version_exists = true ;
} else {
current_installed_label - > hide ( ) ;
current_missing_label - > show ( ) ;
2017-03-21 02:31:41 +00:00
2021-05-20 20:15:49 +00:00
current_installed_hb - > hide ( ) ;
current_version_exists = false ;
}
2017-03-21 02:31:41 +00:00
2021-05-20 20:15:49 +00:00
if ( is_downloading_templates ) {
install_options_vb - > hide ( ) ;
download_progress_hb - > show ( ) ;
2017-03-21 02:31:41 +00:00
} else {
2021-05-20 20:15:49 +00:00
download_progress_hb - > hide ( ) ;
install_options_vb - > show ( ) ;
2019-08-12 15:05:25 +00:00
2021-05-20 20:15:49 +00:00
if ( templates . has ( current_version ) ) {
2022-08-30 00:34:01 +00:00
current_installed_path - > set_text ( templates_dir . path_join ( current_version ) ) ;
2019-08-12 15:05:25 +00:00
}
2017-03-21 02:31:41 +00:00
}
2021-05-20 20:15:49 +00:00
// Update the list of other installed versions.
installed_table - > clear ( ) ;
TreeItem * installed_root = installed_table - > create_item ( ) ;
2022-05-13 13:04:37 +00:00
for ( RBSet < String > : : Element * E = templates . back ( ) ; E ; E = E - > prev ( ) ) {
2021-05-20 20:15:49 +00:00
String version_string = E - > get ( ) ;
if ( version_string = = current_version ) {
2021-03-12 23:32:53 +00:00
continue ;
2017-03-21 02:31:41 +00:00
}
2021-03-12 23:32:53 +00:00
2021-05-20 20:15:49 +00:00
TreeItem * ti = installed_table - > create_item ( installed_root ) ;
ti - > set_text ( 0 , version_string ) ;
2021-07-17 21:22:52 +00:00
ti - > add_button ( 0 , get_theme_icon ( SNAME ( " Folder " ) , SNAME ( " EditorIcons " ) ) , OPEN_TEMPLATE_FOLDER , false , TTR ( " Open the folder containing these templates. " ) ) ;
ti - > add_button ( 0 , get_theme_icon ( SNAME ( " Remove " ) , SNAME ( " EditorIcons " ) ) , UNINSTALL_TEMPLATE , false , TTR ( " Uninstall these templates. " ) ) ;
2021-05-20 20:15:49 +00:00
}
}
void ExportTemplateManager : : _download_current ( ) {
if ( is_downloading_templates ) {
return ;
}
is_downloading_templates = true ;
2017-03-21 02:31:41 +00:00
2021-05-20 20:15:49 +00:00
install_options_vb - > hide ( ) ;
download_progress_hb - > show ( ) ;
2017-03-21 02:31:41 +00:00
2021-05-20 20:15:49 +00:00
if ( mirrors_available ) {
String mirror_url = _get_selected_mirror ( ) ;
if ( mirror_url . is_empty ( ) ) {
_set_current_progress_status ( TTR ( " There are no mirrors available. " ) , true ) ;
return ;
}
2017-03-21 02:31:41 +00:00
2021-05-20 20:15:49 +00:00
_download_template ( mirror_url , true ) ;
2022-04-07 10:23:40 +00:00
} else if ( ! is_refreshing_mirrors ) {
2021-05-20 20:15:49 +00:00
_set_current_progress_status ( TTR ( " Retrieving the mirror list... " ) ) ;
_refresh_mirrors ( ) ;
2017-03-21 02:31:41 +00:00
}
}
2021-05-20 20:15:49 +00:00
void ExportTemplateManager : : _download_template ( const String & p_url , bool p_skip_check ) {
if ( ! p_skip_check & & is_downloading_templates ) {
return ;
}
is_downloading_templates = true ;
install_options_vb - > hide ( ) ;
download_progress_hb - > show ( ) ;
_set_current_progress_status ( TTR ( " Starting the download... " ) ) ;
2022-08-30 00:34:01 +00:00
download_templates - > set_download_file ( EditorPaths : : get_singleton ( ) - > get_cache_dir ( ) . path_join ( " tmp_templates.tpz " ) ) ;
2021-05-20 20:15:49 +00:00
download_templates - > set_use_threads ( true ) ;
2022-03-20 12:56:11 +00:00
const String proxy_host = EDITOR_GET ( " network/http_proxy/host " ) ;
const int proxy_port = EDITOR_GET ( " network/http_proxy/port " ) ;
2021-12-09 03:34:32 +00:00
download_templates - > set_http_proxy ( proxy_host , proxy_port ) ;
download_templates - > set_https_proxy ( proxy_host , proxy_port ) ;
2021-05-20 20:15:49 +00:00
Error err = download_templates - > request ( p_url ) ;
if ( err ! = OK ) {
_set_current_progress_status ( TTR ( " Error requesting URL: " ) + " " + p_url , true ) ;
return ;
}
set_process ( true ) ;
_set_current_progress_status ( TTR ( " Connecting to the mirror... " ) ) ;
2017-03-21 02:31:41 +00:00
}
2021-05-20 20:15:49 +00:00
void ExportTemplateManager : : _download_template_completed ( int p_status , int p_code , const PackedStringArray & headers , const PackedByteArray & p_data ) {
switch ( p_status ) {
case HTTPRequest : : RESULT_CANT_RESOLVE : {
_set_current_progress_status ( TTR ( " Can't resolve the requested address. " ) , true ) ;
} break ;
case HTTPRequest : : RESULT_BODY_SIZE_LIMIT_EXCEEDED :
case HTTPRequest : : RESULT_CONNECTION_ERROR :
case HTTPRequest : : RESULT_CHUNKED_BODY_SIZE_MISMATCH :
2022-09-07 06:25:47 +00:00
case HTTPRequest : : RESULT_TLS_HANDSHAKE_ERROR :
2021-05-20 20:15:49 +00:00
case HTTPRequest : : RESULT_CANT_CONNECT : {
_set_current_progress_status ( TTR ( " Can't connect to the mirror. " ) , true ) ;
} break ;
case HTTPRequest : : RESULT_NO_RESPONSE : {
_set_current_progress_status ( TTR ( " No response from the mirror. " ) , true ) ;
} break ;
case HTTPRequest : : RESULT_REQUEST_FAILED : {
_set_current_progress_status ( TTR ( " Request failed. " ) , true ) ;
} break ;
case HTTPRequest : : RESULT_REDIRECT_LIMIT_REACHED : {
_set_current_progress_status ( TTR ( " Request ended up in a redirect loop. " ) , true ) ;
} break ;
default : {
if ( p_code ! = 200 ) {
_set_current_progress_status ( TTR ( " Request failed: " ) + " " + itos ( p_code ) , true ) ;
} else {
_set_current_progress_status ( TTR ( " Download complete; extracting templates... " ) ) ;
String path = download_templates - > get_download_file ( ) ;
is_downloading_templates = false ;
bool ret = _install_file_selected ( path , true ) ;
if ( ret ) {
// Clean up downloaded file.
2022-03-23 09:08:58 +00:00
Ref < DirAccess > da = DirAccess : : create ( DirAccess : : ACCESS_FILESYSTEM ) ;
2021-05-20 20:15:49 +00:00
Error err = da - > remove ( path ) ;
if ( err ! = OK ) {
EditorNode : : get_singleton ( ) - > add_io_error ( TTR ( " Cannot remove temporary file: " ) + " \n " + path + " \n " ) ;
}
} else {
EditorNode : : get_singleton ( ) - > add_io_error ( vformat ( TTR ( " Templates installation failed. \n The problematic templates archives can be found at '%s'. " ) , path ) ) ;
}
}
} break ;
}
set_process ( false ) ;
2017-03-21 02:31:41 +00:00
}
2021-05-20 20:15:49 +00:00
void ExportTemplateManager : : _cancel_template_download ( ) {
if ( ! is_downloading_templates ) {
return ;
}
2017-03-21 02:31:41 +00:00
2021-05-20 20:15:49 +00:00
download_templates - > cancel_request ( ) ;
download_progress_hb - > hide ( ) ;
install_options_vb - > show ( ) ;
is_downloading_templates = false ;
}
2017-03-21 02:31:41 +00:00
2021-05-20 20:15:49 +00:00
void ExportTemplateManager : : _refresh_mirrors ( ) {
if ( is_refreshing_mirrors ) {
return ;
}
is_refreshing_mirrors = true ;
String current_version = VERSION_FULL_CONFIG ;
const String mirrors_metadata_url = " https://godotengine.org/mirrorlist/ " + current_version + " .json " ;
request_mirrors - > request ( mirrors_metadata_url ) ;
}
void ExportTemplateManager : : _refresh_mirrors_completed ( int p_status , int p_code , const PackedStringArray & headers , const PackedByteArray & p_data ) {
if ( p_status ! = HTTPRequest : : RESULT_SUCCESS | | p_code ! = 200 ) {
EditorNode : : get_singleton ( ) - > show_warning ( TTR ( " Error getting the list of mirrors. " ) ) ;
is_refreshing_mirrors = false ;
if ( is_downloading_templates ) {
_cancel_template_download ( ) ;
}
return ;
}
String response_json ;
{
const uint8_t * r = p_data . ptr ( ) ;
response_json . parse_utf8 ( ( const char * ) r , p_data . size ( ) ) ;
}
2020-12-29 18:12:33 +00:00
JSON json ;
Error err = json . parse ( response_json ) ;
2021-05-20 20:15:49 +00:00
if ( err ! = OK ) {
EditorNode : : get_singleton ( ) - > show_warning ( TTR ( " Error parsing JSON with the list of mirrors. Please report this issue! " ) ) ;
is_refreshing_mirrors = false ;
if ( is_downloading_templates ) {
_cancel_template_download ( ) ;
}
return ;
}
mirrors_list - > clear ( ) ;
mirrors_list - > add_item ( TTR ( " Best available mirror " ) , 0 ) ;
mirrors_available = false ;
2022-09-29 09:53:28 +00:00
Dictionary mirror_data = json . get_data ( ) ;
if ( mirror_data . has ( " mirrors " ) ) {
Array mirrors = mirror_data [ " mirrors " ] ;
2021-05-20 20:15:49 +00:00
for ( int i = 0 ; i < mirrors . size ( ) ; i + + ) {
Dictionary m = mirrors [ i ] ;
ERR_CONTINUE ( ! m . has ( " url " ) | | ! m . has ( " name " ) ) ;
mirrors_list - > add_item ( m [ " name " ] ) ;
mirrors_list - > set_item_metadata ( i + 1 , m [ " url " ] ) ;
mirrors_available = true ;
}
}
if ( ! mirrors_available ) {
EditorNode : : get_singleton ( ) - > show_warning ( TTR ( " No download links found for this version. Direct download is only available for official releases. " ) ) ;
if ( is_downloading_templates ) {
_cancel_template_download ( ) ;
}
}
is_refreshing_mirrors = false ;
if ( is_downloading_templates ) {
String mirror_url = _get_selected_mirror ( ) ;
if ( mirror_url . is_empty ( ) ) {
_set_current_progress_status ( TTR ( " There are no mirrors available. " ) , true ) ;
return ;
}
_download_template ( mirror_url , true ) ;
}
}
bool ExportTemplateManager : : _humanize_http_status ( HTTPRequest * p_request , String * r_status , int * r_downloaded_bytes , int * r_total_bytes ) {
* r_status = " " ;
* r_downloaded_bytes = - 1 ;
* r_total_bytes = - 1 ;
bool success = true ;
switch ( p_request - > get_http_client_status ( ) ) {
case HTTPClient : : STATUS_DISCONNECTED :
* r_status = TTR ( " Disconnected " ) ;
success = false ;
break ;
case HTTPClient : : STATUS_RESOLVING :
* r_status = TTR ( " Resolving " ) ;
break ;
case HTTPClient : : STATUS_CANT_RESOLVE :
* r_status = TTR ( " Can't Resolve " ) ;
success = false ;
break ;
case HTTPClient : : STATUS_CONNECTING :
* r_status = TTR ( " Connecting... " ) ;
break ;
case HTTPClient : : STATUS_CANT_CONNECT :
* r_status = TTR ( " Can't Connect " ) ;
success = false ;
break ;
case HTTPClient : : STATUS_CONNECTED :
* r_status = TTR ( " Connected " ) ;
break ;
case HTTPClient : : STATUS_REQUESTING :
* r_status = TTR ( " Requesting... " ) ;
break ;
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 ( p_request - > get_body_size ( ) > 0 ) {
* r_status + = " " + String : : humanize_size ( p_request - > get_downloaded_bytes ( ) ) + " / " + String : : humanize_size ( p_request - > get_body_size ( ) ) ;
} else {
* r_status + = " " + String : : humanize_size ( p_request - > get_downloaded_bytes ( ) ) ;
}
break ;
case HTTPClient : : STATUS_CONNECTION_ERROR :
* r_status = TTR ( " Connection Error " ) ;
success = false ;
break ;
2022-09-07 06:25:47 +00:00
case HTTPClient : : STATUS_TLS_HANDSHAKE_ERROR :
* r_status = TTR ( " TLS Handshake Error " ) ;
2021-05-20 20:15:49 +00:00
success = false ;
break ;
}
return success ;
}
void ExportTemplateManager : : _set_current_progress_status ( const String & p_status , bool p_error ) {
download_progress_bar - > hide ( ) ;
download_progress_label - > set_text ( p_status ) ;
if ( p_error ) {
2022-02-08 09:14:58 +00:00
download_progress_label - > add_theme_color_override ( " font_color " , get_theme_color ( SNAME ( " error_color " ) , SNAME ( " Editor " ) ) ) ;
2021-05-20 20:15:49 +00:00
} else {
2022-02-08 09:14:58 +00:00
download_progress_label - > add_theme_color_override ( " font_color " , get_theme_color ( SNAME ( " font_color " ) , SNAME ( " Label " ) ) ) ;
2021-05-20 20:15:49 +00:00
}
}
void ExportTemplateManager : : _set_current_progress_value ( float p_value , const String & p_status ) {
download_progress_bar - > show ( ) ;
download_progress_bar - > set_value ( p_value ) ;
download_progress_label - > set_text ( p_status ) ;
}
2017-03-21 02:31:41 +00:00
2021-05-20 20:15:49 +00:00
void ExportTemplateManager : : _install_file ( ) {
install_file_dialog - > popup_file_dialog ( ) ;
2017-03-21 02:31:41 +00:00
}
2021-05-20 20:15:49 +00:00
bool ExportTemplateManager : : _install_file_selected ( const String & p_file , bool p_skip_progress ) {
2022-05-11 12:15:58 +00:00
Ref < FileAccess > io_fa ;
zlib_filefunc_def io = zipio_create_io ( & io_fa ) ;
2017-03-21 02:31:41 +00:00
unzFile pkg = unzOpen2 ( p_file . utf8 ( ) . get_data ( ) , & io ) ;
if ( ! pkg ) {
2021-05-20 20:15:49 +00:00
EditorNode : : get_singleton ( ) - > show_warning ( TTR ( " Can't open the export templates file. " ) ) ;
2018-08-13 10:46:02 +00:00
return false ;
2017-03-21 02:31:41 +00:00
}
int ret = unzGoToFirstFile ( pkg ) ;
2021-05-20 20:15:49 +00:00
// Count them and find version.
int fc = 0 ;
2017-03-21 02:31:41 +00:00
String version ;
2019-02-25 18:37:51 +00:00
String contents_dir ;
2017-03-21 02:31:41 +00:00
while ( ret = = UNZ_OK ) {
unz_file_info info ;
char fname [ 16384 ] ;
2020-04-01 23:20:12 +00:00
ret = unzGetCurrentFileInfo ( pkg , & info , fname , 16384 , nullptr , 0 , nullptr , 0 ) ;
2022-04-05 10:40:26 +00:00
if ( ret ! = UNZ_OK ) {
break ;
}
2017-03-21 02:31:41 +00:00
2022-01-05 12:27:11 +00:00
String file = String : : utf8 ( fname ) ;
2017-03-21 02:31:41 +00:00
if ( file . ends_with ( " version.txt " ) ) {
2022-09-29 09:53:28 +00:00
Vector < uint8_t > uncomp_data ;
uncomp_data . resize ( info . uncompressed_size ) ;
2017-03-21 02:31:41 +00:00
2021-05-20 20:15:49 +00:00
// Read.
2017-08-21 19:15:36 +00:00
unzOpenCurrentFile ( pkg ) ;
2022-09-29 09:53:28 +00:00
ret = unzReadCurrentFile ( pkg , uncomp_data . ptrw ( ) , uncomp_data . size ( ) ) ;
2022-04-16 21:50:48 +00:00
ERR_BREAK_MSG ( ret < 0 , vformat ( " An error occurred while attempting to read from file: %s. This file will not be used. " , file ) ) ;
2017-03-21 02:31:41 +00:00
unzCloseCurrentFile ( pkg ) ;
String data_str ;
2022-09-29 09:53:28 +00:00
data_str . parse_utf8 ( ( const char * ) uncomp_data . ptr ( ) , uncomp_data . size ( ) ) ;
2017-03-21 02:31:41 +00:00
data_str = data_str . strip_edges ( ) ;
2018-02-25 14:24:33 +00:00
// Version number should be of the form major.minor[.patch].status[.module_config]
// so it can in theory have 3 or more slices.
if ( data_str . get_slice_count ( " . " ) < 3 ) {
2021-05-20 20:15:49 +00:00
EditorNode : : get_singleton ( ) - > show_warning ( vformat ( TTR ( " Invalid version.txt format inside the export templates file: %s. " ) , data_str ) ) ;
2017-03-21 02:31:41 +00:00
unzClose ( pkg ) ;
2018-08-13 10:46:02 +00:00
return false ;
2017-03-21 02:31:41 +00:00
}
2018-02-25 14:24:33 +00:00
version = data_str ;
2019-02-25 18:37:51 +00:00
contents_dir = file . get_base_dir ( ) . trim_suffix ( " / " ) . trim_suffix ( " \\ " ) ;
2017-03-21 02:31:41 +00:00
}
2018-07-16 07:05:45 +00:00
if ( file . get_file ( ) . size ( ) ! = 0 ) {
fc + + ;
}
2017-03-21 02:31:41 +00:00
ret = unzGoToNextFile ( pkg ) ;
}
2021-12-09 09:42:46 +00:00
if ( version . is_empty ( ) ) {
2021-05-20 20:15:49 +00:00
EditorNode : : get_singleton ( ) - > show_warning ( TTR ( " No version.txt found inside the export templates file. " ) ) ;
2017-03-21 02:31:41 +00:00
unzClose ( pkg ) ;
2018-08-13 10:46:02 +00:00
return false ;
2017-03-21 02:31:41 +00:00
}
2022-03-23 09:08:58 +00:00
Ref < DirAccess > d = DirAccess : : create ( DirAccess : : ACCESS_FILESYSTEM ) ;
2022-08-30 00:34:01 +00:00
String template_path = EditorPaths : : get_singleton ( ) - > get_export_templates_dir ( ) . path_join ( version ) ;
2017-03-21 02:31:41 +00:00
Error err = d - > make_dir_recursive ( template_path ) ;
if ( err ! = OK ) {
2021-05-20 20:15:49 +00:00
EditorNode : : get_singleton ( ) - > show_warning ( TTR ( " Error creating path for extracting templates: " ) + " \n " + template_path ) ;
2017-03-21 02:31:41 +00:00
unzClose ( pkg ) ;
2018-08-13 10:46:02 +00:00
return false ;
2017-03-21 02:31:41 +00:00
}
2020-04-01 23:20:12 +00:00
EditorProgress * p = nullptr ;
2021-05-20 20:15:49 +00:00
if ( ! p_skip_progress ) {
2017-12-17 18:47:50 +00:00
p = memnew ( EditorProgress ( " ltask " , TTR ( " Extracting Export Templates " ) , fc ) ) ;
}
2017-03-21 02:31:41 +00:00
fc = 0 ;
2021-05-20 20:15:49 +00:00
ret = unzGoToFirstFile ( pkg ) ;
2017-03-21 02:31:41 +00:00
while ( ret = = UNZ_OK ) {
2021-05-20 20:15:49 +00:00
// Get filename.
2017-03-21 02:31:41 +00:00
unz_file_info info ;
char fname [ 16384 ] ;
2022-04-05 10:40:26 +00:00
ret = unzGetCurrentFileInfo ( pkg , & info , fname , 16384 , nullptr , 0 , nullptr , 0 ) ;
if ( ret ! = UNZ_OK ) {
break ;
}
2017-03-21 02:31:41 +00:00
2022-01-05 12:27:11 +00:00
String file_path ( String : : utf8 ( fname ) . simplify_path ( ) ) ;
2019-02-25 18:37:51 +00:00
String file = file_path . get_file ( ) ;
2017-03-21 02:31:41 +00:00
2018-07-16 07:05:45 +00:00
if ( file . size ( ) = = 0 ) {
ret = unzGoToNextFile ( pkg ) ;
continue ;
}
2022-09-29 09:53:28 +00:00
Vector < uint8_t > uncomp_data ;
uncomp_data . resize ( info . uncompressed_size ) ;
2017-03-21 02:31:41 +00:00
2021-05-20 20:15:49 +00:00
// Read
2017-08-21 19:15:36 +00:00
unzOpenCurrentFile ( pkg ) ;
2022-09-29 09:53:28 +00:00
ret = unzReadCurrentFile ( pkg , uncomp_data . ptrw ( ) , uncomp_data . size ( ) ) ;
2022-04-16 21:50:48 +00:00
ERR_BREAK_MSG ( ret < 0 , vformat ( " An error occurred while attempting to read from file: %s. This file will not be used. " , file ) ) ;
2017-03-21 02:31:41 +00:00
unzCloseCurrentFile ( pkg ) ;
2019-02-27 23:25:55 +00:00
String base_dir = file_path . get_base_dir ( ) . trim_suffix ( " / " ) ;
2019-02-25 18:37:51 +00:00
if ( base_dir ! = contents_dir & & base_dir . begins_with ( contents_dir ) ) {
2019-02-27 23:25:55 +00:00
base_dir = base_dir . substr ( contents_dir . length ( ) , file_path . length ( ) ) . trim_prefix ( " / " ) ;
2022-08-30 00:34:01 +00:00
file = base_dir . path_join ( file ) ;
2019-02-25 18:37:51 +00:00
2022-03-23 09:08:58 +00:00
Ref < DirAccess > da = DirAccess : : create ( DirAccess : : ACCESS_FILESYSTEM ) ;
ERR_CONTINUE ( da . is_null ( ) ) ;
2019-02-25 18:37:51 +00:00
2022-08-30 00:34:01 +00:00
String output_dir = template_path . path_join ( base_dir ) ;
2019-02-25 18:37:51 +00:00
if ( ! DirAccess : : exists ( output_dir ) ) {
Error mkdir_err = da - > make_dir_recursive ( output_dir ) ;
ERR_CONTINUE ( mkdir_err ! = OK ) ;
}
}
2017-12-17 18:47:50 +00:00
if ( p ) {
p - > step ( TTR ( " Importing: " ) + " " + file , fc ) ;
}
2017-03-21 02:31:41 +00:00
2022-08-30 00:34:01 +00:00
String to_write = template_path . path_join ( file ) ;
2022-03-23 09:08:58 +00:00
Ref < FileAccess > f = FileAccess : : open ( to_write , FileAccess : : WRITE ) ;
2017-03-21 02:31:41 +00:00
2022-03-23 09:08:58 +00:00
if ( f . is_null ( ) ) {
2017-12-18 19:44:19 +00:00
ret = unzGoToNextFile ( pkg ) ;
fc + + ;
2019-09-25 08:28:50 +00:00
ERR_CONTINUE_MSG ( true , " Can't open file from path ' " + String ( to_write ) + " '. " ) ;
2017-12-18 19:44:19 +00:00
}
2022-09-29 09:53:28 +00:00
f - > store_buffer ( uncomp_data . ptr ( ) , uncomp_data . size ( ) ) ;
2022-04-12 07:12:40 +00:00
f . unref ( ) ; // close file.
2019-04-07 18:46:52 +00:00
# ifndef WINDOWS_ENABLED
FileAccess : : set_unix_permissions ( to_write , ( info . external_fa > > 16 ) & 0x01FF ) ;
# endif
2017-03-21 02:31:41 +00:00
ret = unzGoToNextFile ( pkg ) ;
fc + + ;
}
2017-12-17 18:47:50 +00:00
if ( p ) {
memdelete ( p ) ;
}
2017-03-21 02:31:41 +00:00
unzClose ( pkg ) ;
2021-05-20 20:15:49 +00:00
_update_template_status ( ) ;
2023-04-07 15:44:36 +00:00
EditorSettings : : get_singleton ( ) - > set_meta ( " export_template_download_directory " , p_file . get_base_dir ( ) ) ;
2018-08-13 10:46:02 +00:00
return true ;
2017-03-21 02:31:41 +00:00
}
2021-05-20 20:15:49 +00:00
void ExportTemplateManager : : _uninstall_template ( const String & p_version ) {
uninstall_confirm - > set_text ( vformat ( TTR ( " Remove templates for the version '%s'? " ) , p_version ) ) ;
uninstall_confirm - > popup_centered ( ) ;
uninstall_version = p_version ;
2017-03-21 02:31:41 +00:00
}
2021-05-20 20:15:49 +00:00
void ExportTemplateManager : : _uninstall_template_confirmed ( ) {
2022-03-23 09:08:58 +00:00
Ref < DirAccess > da = DirAccess : : create ( DirAccess : : ACCESS_FILESYSTEM ) ;
2022-07-29 00:36:26 +00:00
const String & templates_dir = EditorPaths : : get_singleton ( ) - > get_export_templates_dir ( ) ;
2017-11-04 18:08:13 +00:00
2021-05-20 20:15:49 +00:00
Error err = da - > change_dir ( templates_dir ) ;
ERR_FAIL_COND_MSG ( err ! = OK , " Could not access templates directory at ' " + templates_dir + " '. " ) ;
err = da - > change_dir ( uninstall_version ) ;
2022-08-30 00:34:01 +00:00
ERR_FAIL_COND_MSG ( err ! = OK , " Could not access templates directory at ' " + templates_dir . path_join ( uninstall_version ) + " '. " ) ;
2017-11-02 02:12:28 +00:00
2021-05-20 20:15:49 +00:00
err = da - > erase_contents_recursive ( ) ;
2022-08-30 00:34:01 +00:00
ERR_FAIL_COND_MSG ( err ! = OK , " Could not remove all templates in ' " + templates_dir . path_join ( uninstall_version ) + " '. " ) ;
2017-11-02 02:12:28 +00:00
2021-05-20 20:15:49 +00:00
da - > change_dir ( " .. " ) ;
err = da - > remove ( uninstall_version ) ;
2022-08-30 00:34:01 +00:00
ERR_FAIL_COND_MSG ( err ! = OK , " Could not remove templates directory at ' " + templates_dir . path_join ( uninstall_version ) + " '. " ) ;
2017-11-02 02:12:28 +00:00
2021-05-20 20:15:49 +00:00
_update_template_status ( ) ;
}
2017-11-02 02:12:28 +00:00
2021-05-20 20:15:49 +00:00
String ExportTemplateManager : : _get_selected_mirror ( ) const {
if ( mirrors_list - > get_item_count ( ) = = 1 ) {
return " " ;
2017-11-02 02:12:28 +00:00
}
2021-05-20 20:15:49 +00:00
int selected = mirrors_list - > get_selected_id ( ) ;
if ( selected = = 0 ) {
// This is a special "best available" value; so pick the first available mirror from the rest of the list.
selected = 1 ;
2017-11-02 02:12:28 +00:00
}
2021-05-20 20:15:49 +00:00
return mirrors_list - > get_item_metadata ( selected ) ;
2017-11-02 02:12:28 +00:00
}
2020-05-14 12:29:06 +00:00
2021-05-20 20:15:49 +00:00
void ExportTemplateManager : : _mirror_options_button_cbk ( int p_id ) {
switch ( p_id ) {
case VISIT_WEB_MIRROR : {
String mirror_url = _get_selected_mirror ( ) ;
if ( mirror_url . is_empty ( ) ) {
EditorNode : : get_singleton ( ) - > show_warning ( TTR ( " There are no mirrors available. " ) ) ;
return ;
}
OS : : get_singleton ( ) - > shell_open ( mirror_url ) ;
2017-11-02 02:12:28 +00:00
} break ;
2021-05-20 20:15:49 +00:00
case COPY_MIRROR_URL : {
String mirror_url = _get_selected_mirror ( ) ;
if ( mirror_url . is_empty ( ) ) {
EditorNode : : get_singleton ( ) - > show_warning ( TTR ( " There are no mirrors available. " ) ) ;
return ;
2017-11-02 02:12:28 +00:00
}
2021-05-20 20:15:49 +00:00
DisplayServer : : get_singleton ( ) - > clipboard_set ( mirror_url ) ;
2017-11-02 02:12:28 +00:00
} break ;
}
}
2021-09-18 07:33:18 +00:00
void ExportTemplateManager : : _installed_table_button_cbk ( Object * p_item , int p_column , int p_id , MouseButton p_button ) {
if ( p_button ! = MouseButton : : LEFT ) {
return ;
}
2021-05-20 20:15:49 +00:00
TreeItem * ti = Object : : cast_to < TreeItem > ( p_item ) ;
if ( ! ti ) {
2018-01-26 19:38:08 +00:00
return ;
}
2021-05-20 20:15:49 +00:00
switch ( p_id ) {
case OPEN_TEMPLATE_FOLDER : {
String version_string = ti - > get_text ( 0 ) ;
_open_template_folder ( version_string ) ;
} break ;
2017-11-02 02:12:28 +00:00
2021-05-20 20:15:49 +00:00
case UNINSTALL_TEMPLATE : {
String version_string = ti - > get_text ( 0 ) ;
_uninstall_template ( version_string ) ;
} break ;
2017-11-02 02:12:28 +00:00
}
2021-05-20 20:15:49 +00:00
}
2017-11-02 02:12:28 +00:00
2021-05-20 20:15:49 +00:00
void ExportTemplateManager : : _open_template_folder ( const String & p_version ) {
2022-07-29 00:36:26 +00:00
const String & templates_dir = EditorPaths : : get_singleton ( ) - > get_export_templates_dir ( ) ;
2022-08-30 00:34:01 +00:00
OS : : get_singleton ( ) - > shell_open ( " file:// " + templates_dir . path_join ( p_version ) ) ;
2017-11-02 02:12:28 +00:00
}
2021-05-20 20:15:49 +00:00
void ExportTemplateManager : : popup_manager ( ) {
_update_template_status ( ) ;
_refresh_mirrors ( ) ;
popup_centered ( Size2 ( 720 , 280 ) * EDSCALE ) ;
2018-02-01 01:15:06 +00:00
}
2021-05-20 20:15:49 +00:00
void ExportTemplateManager : : ok_pressed ( ) {
if ( ! is_downloading_templates ) {
hide ( ) ;
return ;
2020-03-06 17:00:16 +00:00
}
2017-11-02 02:12:28 +00:00
2021-05-20 20:15:49 +00:00
hide_dialog_accept - > popup_centered ( ) ;
}
2017-11-02 02:12:28 +00:00
2021-05-20 20:15:49 +00:00
void ExportTemplateManager : : _hide_dialog ( ) {
hide ( ) ;
2017-11-02 02:12:28 +00:00
}
2019-04-07 18:46:52 +00:00
bool ExportTemplateManager : : can_install_android_template ( ) {
2022-08-30 00:34:01 +00:00
const String templates_dir = EditorPaths : : get_singleton ( ) - > get_export_templates_dir ( ) . path_join ( VERSION_FULL_CONFIG ) ;
return FileAccess : : exists ( templates_dir . path_join ( " android_source.zip " ) ) ;
2019-04-07 18:46:52 +00:00
}
Error ExportTemplateManager : : install_android_template ( ) {
2022-08-30 00:34:01 +00:00
const String & templates_path = EditorPaths : : get_singleton ( ) - > get_export_templates_dir ( ) . path_join ( VERSION_FULL_CONFIG ) ;
const String & source_zip = templates_path . path_join ( " android_source.zip " ) ;
2021-07-15 13:12:56 +00:00
ERR_FAIL_COND_V ( ! FileAccess : : exists ( source_zip ) , ERR_CANT_OPEN ) ;
return install_android_template_from_file ( source_zip ) ;
}
Error ExportTemplateManager : : install_android_template_from_file ( const String & p_file ) {
2019-09-03 00:31:51 +00:00
// To support custom Android builds, we install the Java source code and buildsystem
// from android_source.zip to the project's res://android folder.
2019-08-27 14:42:15 +00:00
2022-03-23 09:08:58 +00:00
Ref < DirAccess > da = DirAccess : : create ( DirAccess : : ACCESS_RESOURCES ) ;
ERR_FAIL_COND_V ( da . is_null ( ) , ERR_CANT_CREATE ) ;
2019-04-07 18:46:52 +00:00
2019-08-27 14:42:15 +00:00
// Make res://android dir (if it does not exist).
2019-04-07 18:46:52 +00:00
da - > make_dir ( " android " ) ;
{
2019-08-27 14:42:15 +00:00
// Add version, to ensure building won't work if template and Godot version don't match.
2022-03-23 09:08:58 +00:00
Ref < FileAccess > f = FileAccess : : open ( " res://android/.build_version " , FileAccess : : WRITE ) ;
ERR_FAIL_COND_V ( f . is_null ( ) , ERR_CANT_CREATE ) ;
2019-04-07 18:46:52 +00:00
f - > store_line ( VERSION_FULL_CONFIG ) ;
}
2019-10-18 16:59:04 +00:00
// Create the android plugins directory.
Error err = da - > make_dir_recursive ( " android/plugins " ) ;
ERR_FAIL_COND_V ( err ! = OK , err ) ;
err = da - > make_dir_recursive ( " android/build " ) ;
2019-04-07 18:46:52 +00:00
ERR_FAIL_COND_V ( err ! = OK , err ) ;
2019-10-18 16:59:04 +00:00
{
// Add an empty .gdignore file to avoid scan.
2022-03-23 09:08:58 +00:00
Ref < FileAccess > f = FileAccess : : open ( " res://android/build/.gdignore " , FileAccess : : WRITE ) ;
ERR_FAIL_COND_V ( f . is_null ( ) , ERR_CANT_CREATE ) ;
2019-10-18 16:59:04 +00:00
f - > store_line ( " " ) ;
}
2019-04-07 18:46:52 +00:00
2019-08-27 14:42:15 +00:00
// Uncompress source template.
2022-05-11 12:15:58 +00:00
Ref < FileAccess > io_fa ;
zlib_filefunc_def io = zipio_create_io ( & io_fa ) ;
2019-04-07 18:46:52 +00:00
2021-07-15 13:12:56 +00:00
unzFile pkg = unzOpen2 ( p_file . utf8 ( ) . get_data ( ) , & io ) ;
2019-08-21 17:32:58 +00:00
ERR_FAIL_COND_V_MSG ( ! pkg , ERR_CANT_OPEN , " Android sources not in ZIP format. " ) ;
2019-04-07 18:46:52 +00:00
int ret = unzGoToFirstFile ( pkg ) ;
int total_files = 0 ;
2019-08-27 14:42:15 +00:00
// Count files to unzip.
2019-04-07 18:46:52 +00:00
while ( ret = = UNZ_OK ) {
total_files + + ;
ret = unzGoToNextFile ( pkg ) ;
}
ret = unzGoToFirstFile ( pkg ) ;
2019-08-27 14:42:15 +00:00
ProgressDialog : : get_singleton ( ) - > add_task ( " uncompress_src " , TTR ( " Uncompressing Android Build Sources " ) , total_files ) ;
2019-04-07 18:46:52 +00:00
2022-05-19 15:00:06 +00:00
HashSet < String > dirs_tested ;
2019-04-07 18:46:52 +00:00
int idx = 0 ;
while ( ret = = UNZ_OK ) {
2019-08-27 14:42:15 +00:00
// Get file path.
2019-04-07 18:46:52 +00:00
unz_file_info info ;
2019-08-27 14:42:15 +00:00
char fpath [ 16384 ] ;
2020-04-01 23:20:12 +00:00
ret = unzGetCurrentFileInfo ( pkg , & info , fpath , 16384 , nullptr , 0 , nullptr , 0 ) ;
2022-04-05 10:40:26 +00:00
if ( ret ! = UNZ_OK ) {
break ;
}
2019-04-07 18:46:52 +00:00
2022-01-05 12:27:11 +00:00
String path = String : : utf8 ( fpath ) ;
2019-08-27 14:42:15 +00:00
String base_dir = path . get_base_dir ( ) ;
2019-04-07 18:46:52 +00:00
2019-08-27 14:42:15 +00:00
if ( ! path . ends_with ( " / " ) ) {
2022-09-29 09:53:28 +00:00
Vector < uint8_t > uncomp_data ;
uncomp_data . resize ( info . uncompressed_size ) ;
2019-04-07 18:46:52 +00:00
2019-08-27 14:42:15 +00:00
// Read.
2019-04-07 18:46:52 +00:00
unzOpenCurrentFile ( pkg ) ;
2022-09-29 09:53:28 +00:00
unzReadCurrentFile ( pkg , uncomp_data . ptrw ( ) , uncomp_data . size ( ) ) ;
2019-04-07 18:46:52 +00:00
unzCloseCurrentFile ( pkg ) ;
if ( ! dirs_tested . has ( base_dir ) ) {
2022-08-30 00:34:01 +00:00
da - > make_dir_recursive ( String ( " android/build " ) . path_join ( base_dir ) ) ;
2019-04-07 18:46:52 +00:00
dirs_tested . insert ( base_dir ) ;
}
2022-08-30 00:34:01 +00:00
String to_write = String ( " res://android/build " ) . path_join ( path ) ;
2022-03-23 09:08:58 +00:00
Ref < FileAccess > f = FileAccess : : open ( to_write , FileAccess : : WRITE ) ;
if ( f . is_valid ( ) ) {
2022-09-29 09:53:28 +00:00
f - > store_buffer ( uncomp_data . ptr ( ) , uncomp_data . size ( ) ) ;
2022-04-12 07:12:40 +00:00
f . unref ( ) ; // close file.
2019-04-07 18:46:52 +00:00
# ifndef WINDOWS_ENABLED
FileAccess : : set_unix_permissions ( to_write , ( info . external_fa > > 16 ) & 0x01FF ) ;
# endif
} else {
2019-11-06 16:03:04 +00:00
ERR_PRINT ( " Can't uncompress file: " + to_write ) ;
2019-04-07 18:46:52 +00:00
}
}
2019-08-27 14:42:15 +00:00
ProgressDialog : : get_singleton ( ) - > task_step ( " uncompress_src " , path , idx ) ;
idx + + ;
ret = unzGoToNextFile ( pkg ) ;
}
ProgressDialog : : get_singleton ( ) - > end_task ( " uncompress_src " ) ;
unzClose ( pkg ) ;
2019-04-07 18:46:52 +00:00
return OK ;
}
2021-05-20 20:15:49 +00:00
void ExportTemplateManager : : _notification ( int p_what ) {
switch ( p_what ) {
2022-08-29 09:04:31 +00:00
case NOTIFICATION_ENTER_TREE :
2021-05-20 20:15:49 +00:00
case NOTIFICATION_THEME_CHANGED : {
2022-02-08 09:14:58 +00:00
current_value - > add_theme_font_override ( " font " , get_theme_font ( SNAME ( " main " ) , SNAME ( " EditorFonts " ) ) ) ;
current_missing_label - > add_theme_color_override ( " font_color " , get_theme_color ( SNAME ( " error_color " ) , SNAME ( " Editor " ) ) ) ;
current_installed_label - > add_theme_color_override ( " font_color " , get_theme_color ( SNAME ( " disabled_font_color " ) , SNAME ( " Editor " ) ) ) ;
2021-05-20 20:15:49 +00:00
2021-09-25 18:07:42 +00:00
mirror_options_button - > set_icon ( get_theme_icon ( SNAME ( " GuiTabMenuHl " ) , SNAME ( " EditorIcons " ) ) ) ;
2021-05-20 20:15:49 +00:00
} break ;
2017-03-21 02:31:41 +00:00
2021-05-20 20:15:49 +00:00
case NOTIFICATION_VISIBILITY_CHANGED : {
if ( ! is_visible ( ) ) {
set_process ( false ) ;
} else if ( is_visible ( ) & & is_downloading_templates ) {
set_process ( true ) ;
}
} break ;
2017-03-21 02:31:41 +00:00
2021-05-20 20:15:49 +00:00
case NOTIFICATION_PROCESS : {
update_countdown - = get_process_delta_time ( ) ;
if ( update_countdown > 0 ) {
return ;
}
update_countdown = 0.5 ;
2017-03-21 02:31:41 +00:00
2021-05-20 20:15:49 +00:00
String status ;
int downloaded_bytes ;
int total_bytes ;
bool success = _humanize_http_status ( download_templates , & status , & downloaded_bytes , & total_bytes ) ;
2017-03-21 02:31:41 +00:00
2021-05-20 20:15:49 +00:00
if ( downloaded_bytes > = 0 ) {
if ( total_bytes > 0 ) {
_set_current_progress_value ( float ( downloaded_bytes ) / total_bytes , status ) ;
} else {
_set_current_progress_value ( 0 , status ) ;
}
} else {
_set_current_progress_status ( status ) ;
}
2017-03-21 02:31:41 +00:00
2021-05-20 20:15:49 +00:00
if ( ! success ) {
set_process ( false ) ;
}
} break ;
2017-03-21 02:31:41 +00:00
2021-05-20 20:15:49 +00:00
case NOTIFICATION_WM_CLOSE_REQUEST : {
// This won't stop the window from closing, but will show the alert if the download is active.
ok_pressed ( ) ;
} break ;
}
}
2017-03-21 02:31:41 +00:00
2021-05-20 20:15:49 +00:00
void ExportTemplateManager : : _bind_methods ( ) {
}
2017-03-21 02:31:41 +00:00
2021-05-20 20:15:49 +00:00
ExportTemplateManager : : ExportTemplateManager ( ) {
2017-03-21 02:31:41 +00:00
set_title ( TTR ( " Export Template Manager " ) ) ;
set_hide_on_ok ( false ) ;
2022-07-08 00:31:19 +00:00
set_ok_button_text ( TTR ( " Close " ) ) ;
2021-05-20 20:15:49 +00:00
// Downloadable export templates are only available for stable and official alpha/beta/RC builds
// (which always have a number following their status, e.g. "alpha1").
// Therefore, don't display download-related features when using a development version
// (whose builds aren't numbered).
downloads_available =
String ( VERSION_STATUS ) ! = String ( " dev " ) & &
String ( VERSION_STATUS ) ! = String ( " alpha " ) & &
String ( VERSION_STATUS ) ! = String ( " beta " ) & &
String ( VERSION_STATUS ) ! = String ( " rc " ) ;
VBoxContainer * main_vb = memnew ( VBoxContainer ) ;
add_child ( main_vb ) ;
// Current version controls.
HBoxContainer * current_hb = memnew ( HBoxContainer ) ;
main_vb - > add_child ( current_hb ) ;
Label * current_label = memnew ( Label ) ;
2021-07-08 13:29:15 +00:00
current_label - > set_theme_type_variation ( " HeaderSmall " ) ;
2021-05-20 20:15:49 +00:00
current_label - > set_text ( TTR ( " Current Version: " ) ) ;
current_hb - > add_child ( current_label ) ;
current_value = memnew ( Label ) ;
current_hb - > add_child ( current_value ) ;
// Current version statuses.
// Status: Current version is missing.
current_missing_label = memnew ( Label ) ;
2021-07-08 13:29:15 +00:00
current_missing_label - > set_theme_type_variation ( " HeaderSmall " ) ;
2021-05-20 20:15:49 +00:00
current_missing_label - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2021-11-25 02:58:47 +00:00
current_missing_label - > set_horizontal_alignment ( HORIZONTAL_ALIGNMENT_RIGHT ) ;
2021-05-20 20:15:49 +00:00
current_missing_label - > set_text ( TTR ( " Export templates are missing. Download them or install from a file. " ) ) ;
current_hb - > add_child ( current_missing_label ) ;
// Status: Current version is installed.
current_installed_label = memnew ( Label ) ;
2021-07-08 13:29:15 +00:00
current_installed_label - > set_theme_type_variation ( " HeaderSmall " ) ;
2021-05-20 20:15:49 +00:00
current_installed_label - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2021-11-25 02:58:47 +00:00
current_installed_label - > set_horizontal_alignment ( HORIZONTAL_ALIGNMENT_RIGHT ) ;
2021-05-20 20:15:49 +00:00
current_installed_label - > set_text ( TTR ( " Export templates are installed and ready to be used. " ) ) ;
current_hb - > add_child ( current_installed_label ) ;
current_installed_label - > hide ( ) ;
// Currently installed template.
current_installed_hb = memnew ( HBoxContainer ) ;
main_vb - > add_child ( current_installed_hb ) ;
current_installed_path = memnew ( LineEdit ) ;
current_installed_path - > set_editable ( false ) ;
current_installed_path - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
current_installed_hb - > add_child ( current_installed_path ) ;
current_open_button = memnew ( Button ) ;
current_open_button - > set_text ( TTR ( " Open Folder " ) ) ;
2022-08-25 10:42:17 +00:00
current_open_button - > set_tooltip_text ( TTR ( " Open the folder containing installed templates for the current version. " ) ) ;
2021-05-20 20:15:49 +00:00
current_installed_hb - > add_child ( current_open_button ) ;
2022-07-28 20:56:41 +00:00
current_open_button - > connect ( " pressed " , callable_mp ( this , & ExportTemplateManager : : _open_template_folder ) . bind ( VERSION_FULL_CONFIG ) ) ;
2021-05-20 20:15:49 +00:00
current_uninstall_button = memnew ( Button ) ;
current_uninstall_button - > set_text ( TTR ( " Uninstall " ) ) ;
2022-08-25 10:42:17 +00:00
current_uninstall_button - > set_tooltip_text ( TTR ( " Uninstall templates for the current version. " ) ) ;
2021-05-20 20:15:49 +00:00
current_installed_hb - > add_child ( current_uninstall_button ) ;
2022-07-28 20:56:41 +00:00
current_uninstall_button - > connect ( " pressed " , callable_mp ( this , & ExportTemplateManager : : _uninstall_template ) . bind ( VERSION_FULL_CONFIG ) ) ;
2021-05-20 20:15:49 +00:00
main_vb - > add_child ( memnew ( HSeparator ) ) ;
// Download and install section.
HBoxContainer * install_templates_hb = memnew ( HBoxContainer ) ;
main_vb - > add_child ( install_templates_hb ) ;
// Download and install buttons are available.
install_options_vb = memnew ( VBoxContainer ) ;
install_options_vb - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
install_templates_hb - > add_child ( install_options_vb ) ;
HBoxContainer * download_install_hb = memnew ( HBoxContainer ) ;
install_options_vb - > add_child ( download_install_hb ) ;
Label * mirrors_label = memnew ( Label ) ;
mirrors_label - > set_text ( TTR ( " Download from: " ) ) ;
download_install_hb - > add_child ( mirrors_label ) ;
mirrors_list = memnew ( OptionButton ) ;
mirrors_list - > set_custom_minimum_size ( Size2 ( 280 , 0 ) * EDSCALE ) ;
download_install_hb - > add_child ( mirrors_list ) ;
mirrors_list - > add_item ( TTR ( " Best available mirror " ) , 0 ) ;
request_mirrors = memnew ( HTTPRequest ) ;
mirrors_list - > add_child ( request_mirrors ) ;
request_mirrors - > connect ( " request_completed " , callable_mp ( this , & ExportTemplateManager : : _refresh_mirrors_completed ) ) ;
mirror_options_button = memnew ( MenuButton ) ;
2021-08-03 15:53:36 +00:00
mirror_options_button - > get_popup ( ) - > add_item ( TTR ( " Open in Web Browser " ) , VISIT_WEB_MIRROR ) ;
mirror_options_button - > get_popup ( ) - > add_item ( TTR ( " Copy Mirror URL " ) , COPY_MIRROR_URL ) ;
2021-05-20 20:15:49 +00:00
download_install_hb - > add_child ( mirror_options_button ) ;
mirror_options_button - > get_popup ( ) - > connect ( " id_pressed " , callable_mp ( this , & ExportTemplateManager : : _mirror_options_button_cbk ) ) ;
download_install_hb - > add_spacer ( ) ;
Button * download_current_button = memnew ( Button ) ;
download_current_button - > set_text ( TTR ( " Download and Install " ) ) ;
2022-08-25 10:42:17 +00:00
download_current_button - > set_tooltip_text ( TTR ( " Download and install templates for the current version from the best possible mirror. " ) ) ;
2021-05-20 20:15:49 +00:00
download_install_hb - > add_child ( download_current_button ) ;
download_current_button - > connect ( " pressed " , callable_mp ( this , & ExportTemplateManager : : _download_current ) ) ;
// Update downloads buttons to prevent unsupported downloads.
if ( ! downloads_available ) {
download_current_button - > set_disabled ( true ) ;
2022-08-25 10:42:17 +00:00
download_current_button - > set_tooltip_text ( TTR ( " Official export templates aren't available for development builds. " ) ) ;
2021-05-20 20:15:49 +00:00
}
2017-11-02 02:12:28 +00:00
2021-05-20 20:15:49 +00:00
HBoxContainer * install_file_hb = memnew ( HBoxContainer ) ;
2021-11-25 02:58:47 +00:00
install_file_hb - > set_alignment ( BoxContainer : : ALIGNMENT_END ) ;
2021-05-20 20:15:49 +00:00
install_options_vb - > add_child ( install_file_hb ) ;
install_file_button = memnew ( Button ) ;
install_file_button - > set_text ( TTR ( " Install from File " ) ) ;
2022-08-25 10:42:17 +00:00
install_file_button - > set_tooltip_text ( TTR ( " Install templates from a local file. " ) ) ;
2021-05-20 20:15:49 +00:00
install_file_hb - > add_child ( install_file_button ) ;
install_file_button - > connect ( " pressed " , callable_mp ( this , & ExportTemplateManager : : _install_file ) ) ;
// Templates are being downloaded; buttons unavailable.
download_progress_hb = memnew ( HBoxContainer ) ;
download_progress_hb - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
install_templates_hb - > add_child ( download_progress_hb ) ;
download_progress_hb - > hide ( ) ;
download_progress_bar = memnew ( ProgressBar ) ;
download_progress_bar - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
download_progress_bar - > set_v_size_flags ( Control : : SIZE_SHRINK_CENTER ) ;
download_progress_bar - > set_min ( 0 ) ;
download_progress_bar - > set_max ( 1 ) ;
download_progress_bar - > set_value ( 0 ) ;
download_progress_bar - > set_step ( 0.01 ) ;
download_progress_hb - > add_child ( download_progress_bar ) ;
download_progress_label = memnew ( Label ) ;
download_progress_label - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
download_progress_hb - > add_child ( download_progress_label ) ;
Button * download_cancel_button = memnew ( Button ) ;
download_cancel_button - > set_text ( TTR ( " Cancel " ) ) ;
2022-08-25 10:42:17 +00:00
download_cancel_button - > set_tooltip_text ( TTR ( " Cancel the download of the templates. " ) ) ;
2021-05-20 20:15:49 +00:00
download_progress_hb - > add_child ( download_cancel_button ) ;
download_cancel_button - > connect ( " pressed " , callable_mp ( this , & ExportTemplateManager : : _cancel_template_download ) ) ;
2017-11-02 02:12:28 +00:00
download_templates = memnew ( HTTPRequest ) ;
2021-05-20 20:15:49 +00:00
install_templates_hb - > add_child ( download_templates ) ;
download_templates - > connect ( " request_completed " , callable_mp ( this , & ExportTemplateManager : : _download_template_completed ) ) ;
main_vb - > add_child ( memnew ( HSeparator ) ) ;
// Other installed templates table.
HBoxContainer * installed_versions_hb = memnew ( HBoxContainer ) ;
main_vb - > add_child ( installed_versions_hb ) ;
Label * installed_label = memnew ( Label ) ;
2021-07-08 13:29:15 +00:00
installed_label - > set_theme_type_variation ( " HeaderSmall " ) ;
2021-05-20 20:15:49 +00:00
installed_label - > set_text ( TTR ( " Other Installed Versions: " ) ) ;
installed_versions_hb - > add_child ( installed_label ) ;
installed_table = memnew ( Tree ) ;
installed_table - > set_hide_root ( true ) ;
installed_table - > set_custom_minimum_size ( Size2 ( 0 , 100 ) * EDSCALE ) ;
installed_table - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
main_vb - > add_child ( installed_table ) ;
2021-09-18 07:33:18 +00:00
installed_table - > connect ( " button_clicked " , callable_mp ( this , & ExportTemplateManager : : _installed_table_button_cbk ) ) ;
2021-05-20 20:15:49 +00:00
// Dialogs.
uninstall_confirm = memnew ( ConfirmationDialog ) ;
uninstall_confirm - > set_title ( TTR ( " Uninstall Template " ) ) ;
add_child ( uninstall_confirm ) ;
uninstall_confirm - > connect ( " confirmed " , callable_mp ( this , & ExportTemplateManager : : _uninstall_template_confirmed ) ) ;
install_file_dialog = memnew ( FileDialog ) ;
install_file_dialog - > set_title ( TTR ( " Select Template File " ) ) ;
install_file_dialog - > set_access ( FileDialog : : ACCESS_FILESYSTEM ) ;
install_file_dialog - > set_file_mode ( FileDialog : : FILE_MODE_OPEN_FILE ) ;
2023-04-07 15:44:36 +00:00
install_file_dialog - > set_current_dir ( EditorSettings : : get_singleton ( ) - > get_meta ( " export_template_download_directory " , " " ) ) ;
2022-07-04 21:26:26 +00:00
install_file_dialog - > add_filter ( " *.tpz " , TTR ( " Godot Export Templates " ) ) ;
2022-07-28 20:56:41 +00:00
install_file_dialog - > connect ( " file_selected " , callable_mp ( this , & ExportTemplateManager : : _install_file_selected ) . bind ( false ) ) ;
2021-05-20 20:15:49 +00:00
add_child ( install_file_dialog ) ;
hide_dialog_accept = memnew ( AcceptDialog ) ;
hide_dialog_accept - > set_text ( TTR ( " The templates will continue to download. \n You may experience a short editor freeze when they finish. " ) ) ;
add_child ( hide_dialog_accept ) ;
hide_dialog_accept - > connect ( " confirmed " , callable_mp ( this , & ExportTemplateManager : : _hide_dialog ) ) ;
2017-03-21 02:31:41 +00:00
}