mirror of
https://github.com/godotengine/godot.git
synced 2025-02-02 20:21:20 +00:00
Merge pull request #50771 from naithar/feature/platform-export-refactoring-4.0
This commit is contained in:
commit
6f043f7a19
@ -30,7 +30,10 @@ if env["tools"]:
|
||||
reg_exporters_inc = '#include "register_exporters.h"\n'
|
||||
reg_exporters = "void register_exporters() {\n"
|
||||
for e in env.platform_exporters:
|
||||
env.add_source_files(env.editor_sources, "#platform/" + e + "/export/export.cpp")
|
||||
# Glob all .cpp files in export folder
|
||||
files = Glob("#platform/" + e + "/export/" + "*.cpp")
|
||||
env.add_source_files(env.editor_sources, files)
|
||||
|
||||
reg_exporters += "\tregister_" + e + "_exporter();\n"
|
||||
reg_exporters_inc += '#include "platform/' + e + '/export/export.h"\n'
|
||||
reg_exporters += "}\n"
|
||||
|
File diff suppressed because it is too large
Load Diff
2945
platform/android/export/export_plugin.cpp
Normal file
2945
platform/android/export/export_plugin.cpp
Normal file
File diff suppressed because it is too large
Load Diff
255
platform/android/export/export_plugin.h
Normal file
255
platform/android/export/export_plugin.h
Normal file
@ -0,0 +1,255 @@
|
||||
/*************************************************************************/
|
||||
/* export_plugin.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/io/dir_access.h"
|
||||
#include "core/io/file_access.h"
|
||||
#include "core/io/image_loader.h"
|
||||
#include "core/io/json.h"
|
||||
#include "core/io/marshalls.h"
|
||||
#include "core/io/zip_io.h"
|
||||
#include "core/os/os.h"
|
||||
#include "core/templates/safe_refcount.h"
|
||||
#include "core/version.h"
|
||||
#include "drivers/png/png_driver_common.h"
|
||||
#include "editor/editor_export.h"
|
||||
#include "editor/editor_log.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "main/splash.gen.h"
|
||||
#include "platform/android/logo.gen.h"
|
||||
#include "platform/android/run_icon.gen.h"
|
||||
|
||||
#include "godot_plugin_config.h"
|
||||
#include "gradle_export_util.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
const String SPLASH_CONFIG_XML_CONTENT = R"SPLASH(<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/splash_bg_color" />
|
||||
<item>
|
||||
<bitmap
|
||||
android:gravity="center"
|
||||
android:filter="%s"
|
||||
android:src="@drawable/splash" />
|
||||
</item>
|
||||
</layer-list>
|
||||
)SPLASH";
|
||||
|
||||
struct LauncherIcon {
|
||||
const char *export_path;
|
||||
int dimensions = 0;
|
||||
};
|
||||
|
||||
class EditorExportPlatformAndroid : public EditorExportPlatform {
|
||||
GDCLASS(EditorExportPlatformAndroid, EditorExportPlatform);
|
||||
|
||||
Ref<ImageTexture> logo;
|
||||
Ref<ImageTexture> run_icon;
|
||||
|
||||
struct Device {
|
||||
String id;
|
||||
String name;
|
||||
String description;
|
||||
int api_level = 0;
|
||||
};
|
||||
|
||||
struct APKExportData {
|
||||
zipFile apk;
|
||||
EditorProgress *ep = nullptr;
|
||||
};
|
||||
|
||||
struct CustomExportData {
|
||||
bool debug;
|
||||
Vector<String> libs;
|
||||
};
|
||||
|
||||
Vector<PluginConfigAndroid> plugins;
|
||||
String last_plugin_names;
|
||||
uint64_t last_custom_build_time = 0;
|
||||
SafeFlag plugins_changed;
|
||||
Mutex plugins_lock;
|
||||
Vector<Device> devices;
|
||||
SafeFlag devices_changed;
|
||||
Mutex device_lock;
|
||||
Thread check_for_changes_thread;
|
||||
SafeFlag quit_request;
|
||||
|
||||
static void _check_for_changes_poll_thread(void *ud);
|
||||
|
||||
String get_project_name(const String &p_name) const;
|
||||
|
||||
String get_package_name(const String &p_package) const;
|
||||
|
||||
bool is_package_name_valid(const String &p_package, String *r_error = nullptr) const;
|
||||
|
||||
static bool _should_compress_asset(const String &p_path, const Vector<uint8_t> &p_data);
|
||||
|
||||
static zip_fileinfo get_zip_fileinfo();
|
||||
|
||||
static Vector<String> get_abis();
|
||||
|
||||
/// List the gdap files in the directory specified by the p_path parameter.
|
||||
static Vector<String> list_gdap_files(const String &p_path);
|
||||
|
||||
static Vector<PluginConfigAndroid> get_plugins();
|
||||
|
||||
static Vector<PluginConfigAndroid> get_enabled_plugins(const Ref<EditorExportPreset> &p_presets);
|
||||
|
||||
static Error store_in_apk(APKExportData *ed, const String &p_path, const Vector<uint8_t> &p_data, int compression_method = Z_DEFLATED);
|
||||
|
||||
static Error save_apk_so(void *p_userdata, const SharedObject &p_so);
|
||||
|
||||
static Error save_apk_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key);
|
||||
|
||||
static Error ignore_apk_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key);
|
||||
|
||||
static Error copy_gradle_so(void *p_userdata, const SharedObject &p_so);
|
||||
|
||||
void _get_permissions(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, Vector<String> &r_permissions);
|
||||
|
||||
void _write_tmp_manifest(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, bool p_debug);
|
||||
|
||||
void _fix_manifest(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_manifest, bool p_give_internet);
|
||||
|
||||
static String _parse_string(const uint8_t *p_bytes, bool p_utf8);
|
||||
|
||||
void _fix_resources(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &r_manifest);
|
||||
|
||||
void _load_image_data(const Ref<Image> &p_splash_image, Vector<uint8_t> &p_data);
|
||||
|
||||
void _process_launcher_icons(const String &p_file_name, const Ref<Image> &p_source_image, int dimension, Vector<uint8_t> &p_data);
|
||||
|
||||
String load_splash_refs(Ref<Image> &splash_image, Ref<Image> &splash_bg_color_image);
|
||||
|
||||
void load_icon_refs(const Ref<EditorExportPreset> &p_preset, Ref<Image> &icon, Ref<Image> &foreground, Ref<Image> &background);
|
||||
|
||||
void store_image(const LauncherIcon launcher_icon, const Vector<uint8_t> &data);
|
||||
|
||||
void store_image(const String &export_path, const Vector<uint8_t> &data);
|
||||
|
||||
void _copy_icons_to_gradle_project(const Ref<EditorExportPreset> &p_preset,
|
||||
const String &processed_splash_config_xml,
|
||||
const Ref<Image> &splash_image,
|
||||
const Ref<Image> &splash_bg_color_image,
|
||||
const Ref<Image> &main_image,
|
||||
const Ref<Image> &foreground,
|
||||
const Ref<Image> &background);
|
||||
|
||||
static Vector<String> get_enabled_abis(const Ref<EditorExportPreset> &p_preset);
|
||||
|
||||
public:
|
||||
typedef Error (*EditorExportSaveFunction)(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key);
|
||||
|
||||
public:
|
||||
virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) override;
|
||||
|
||||
virtual void get_export_options(List<ExportOption> *r_options) override;
|
||||
|
||||
virtual String get_name() const override;
|
||||
|
||||
virtual String get_os_name() const override;
|
||||
|
||||
virtual Ref<Texture2D> get_logo() const override;
|
||||
|
||||
virtual bool should_update_export_options() override;
|
||||
|
||||
virtual bool poll_export() override;
|
||||
|
||||
virtual int get_options_count() const override;
|
||||
|
||||
virtual String get_options_tooltip() const override;
|
||||
|
||||
virtual String get_option_label(int p_index) const override;
|
||||
|
||||
virtual String get_option_tooltip(int p_index) const override;
|
||||
|
||||
virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) override;
|
||||
|
||||
virtual Ref<Texture2D> get_run_icon() const override;
|
||||
|
||||
static String get_adb_path();
|
||||
|
||||
static String get_apksigner_path();
|
||||
|
||||
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
|
||||
|
||||
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override;
|
||||
|
||||
inline bool is_clean_build_required(Vector<PluginConfigAndroid> enabled_plugins) {
|
||||
String plugin_names = PluginConfigAndroid::get_plugins_names(enabled_plugins);
|
||||
bool first_build = last_custom_build_time == 0;
|
||||
bool have_plugins_changed = false;
|
||||
|
||||
if (!first_build) {
|
||||
have_plugins_changed = plugin_names != last_plugin_names;
|
||||
if (!have_plugins_changed) {
|
||||
for (int i = 0; i < enabled_plugins.size(); i++) {
|
||||
if (enabled_plugins.get(i).last_updated > last_custom_build_time) {
|
||||
have_plugins_changed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
last_custom_build_time = OS::get_singleton()->get_unix_time();
|
||||
last_plugin_names = plugin_names;
|
||||
|
||||
return have_plugins_changed || first_build;
|
||||
}
|
||||
|
||||
String get_apk_expansion_fullpath(const Ref<EditorExportPreset> &p_preset, const String &p_path);
|
||||
|
||||
Error save_apk_expansion_file(const Ref<EditorExportPreset> &p_preset, const String &p_path);
|
||||
|
||||
void get_command_line_flags(const Ref<EditorExportPreset> &p_preset, const String &p_path, int p_flags, Vector<uint8_t> &r_command_line_flags);
|
||||
|
||||
Error sign_apk(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &export_path, EditorProgress &ep);
|
||||
|
||||
void _clear_assets_directory();
|
||||
|
||||
void _remove_copied_libs();
|
||||
|
||||
String join_list(List<String> parts, const String &separator) const;
|
||||
|
||||
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) override;
|
||||
|
||||
Error export_project_helper(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int export_format, bool should_sign, int p_flags);
|
||||
|
||||
virtual void get_platform_features(List<String> *r_features) override;
|
||||
|
||||
virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) override;
|
||||
|
||||
EditorExportPlatformAndroid();
|
||||
|
||||
~EditorExportPlatformAndroid();
|
||||
};
|
@ -1,5 +1,5 @@
|
||||
/*************************************************************************/
|
||||
/* godot_plugin_config.h */
|
||||
/* godot_plugin_config.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
@ -28,78 +28,23 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef GODOT_PLUGIN_CONFIG_H
|
||||
#define GODOT_PLUGIN_CONFIG_H
|
||||
|
||||
#include "core/error/error_list.h"
|
||||
#include "core/io/config_file.h"
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
/*
|
||||
The `config` section and fields are required and defined as follow:
|
||||
- **name**: name of the plugin.
|
||||
- **binary_type**: can be either `local` or `remote`. The type affects the **binary** field.
|
||||
- **binary**:
|
||||
- if **binary_type** is `local`, then this should be the filename of the plugin `aar` file in the `res://android/plugins` directory (e.g: `MyPlugin.aar`).
|
||||
- if **binary_type** is `remote`, then this should be a declaration for a remote gradle binary (e.g: "org.godot.example:my-plugin:0.0.0").
|
||||
|
||||
The `dependencies` section and fields are optional and defined as follow:
|
||||
- **local**: contains a list of local `.aar` binary files the plugin depends on. The local binary dependencies must also be located in the `res://android/plugins` directory.
|
||||
- **remote**: contains a list of remote binary gradle dependencies for the plugin.
|
||||
- **custom_maven_repos**: contains a list of urls specifying custom maven repos required for the plugin's dependencies.
|
||||
|
||||
See https://github.com/godotengine/godot/issues/38157#issuecomment-618773871
|
||||
*/
|
||||
struct PluginConfigAndroid {
|
||||
inline static const char *PLUGIN_CONFIG_EXT = ".gdap";
|
||||
|
||||
inline static const char *CONFIG_SECTION = "config";
|
||||
inline static const char *CONFIG_NAME_KEY = "name";
|
||||
inline static const char *CONFIG_BINARY_TYPE_KEY = "binary_type";
|
||||
inline static const char *CONFIG_BINARY_KEY = "binary";
|
||||
|
||||
inline static const char *DEPENDENCIES_SECTION = "dependencies";
|
||||
inline static const char *DEPENDENCIES_LOCAL_KEY = "local";
|
||||
inline static const char *DEPENDENCIES_REMOTE_KEY = "remote";
|
||||
inline static const char *DEPENDENCIES_CUSTOM_MAVEN_REPOS_KEY = "custom_maven_repos";
|
||||
|
||||
inline static const char *BINARY_TYPE_LOCAL = "local";
|
||||
inline static const char *BINARY_TYPE_REMOTE = "remote";
|
||||
|
||||
inline static const char *PLUGIN_VALUE_SEPARATOR = "|";
|
||||
|
||||
// Set to true when the config file is properly loaded.
|
||||
bool valid_config = false;
|
||||
// Unix timestamp of last change to this plugin.
|
||||
uint64_t last_updated = 0;
|
||||
|
||||
// Required config section
|
||||
String name;
|
||||
String binary_type;
|
||||
String binary;
|
||||
|
||||
// Optional dependencies section
|
||||
Vector<String> local_dependencies;
|
||||
Vector<String> remote_dependencies;
|
||||
Vector<String> custom_maven_repos;
|
||||
};
|
||||
|
||||
#include "godot_plugin_config.h"
|
||||
/*
|
||||
* Set of prebuilt plugins.
|
||||
* Currently unused, this is just for future reference:
|
||||
*/
|
||||
// static const PluginConfigAndroid MY_PREBUILT_PLUGIN = {
|
||||
// /*.valid_config =*/true,
|
||||
// /*.last_updated =*/0,
|
||||
// /*.name =*/"GodotPayment",
|
||||
// /*.binary_type =*/"local",
|
||||
// /*.binary =*/"res://android/build/libs/plugins/GodotPayment.release.aar",
|
||||
// /*.local_dependencies =*/{},
|
||||
// /*.remote_dependencies =*/String("com.android.billingclient:billing:2.2.1").split("|"),
|
||||
// /*.custom_maven_repos =*/{}
|
||||
// /*.valid_config =*/true,
|
||||
// /*.last_updated =*/0,
|
||||
// /*.name =*/"GodotPayment",
|
||||
// /*.binary_type =*/"local",
|
||||
// /*.binary =*/"res://android/build/libs/plugins/GodotPayment.release.aar",
|
||||
// /*.local_dependencies =*/{},
|
||||
// /*.remote_dependencies =*/String("com.android.billingclient:billing:2.2.1").split("|"),
|
||||
// /*.custom_maven_repos =*/{}
|
||||
// };
|
||||
|
||||
static inline String resolve_local_dependency_path(String plugin_config_dir, String dependency_path) {
|
||||
String PluginConfigAndroid::resolve_local_dependency_path(String plugin_config_dir, String dependency_path) {
|
||||
String absolute_path;
|
||||
if (!dependency_path.is_empty()) {
|
||||
if (dependency_path.is_absolute_path()) {
|
||||
@ -112,7 +57,7 @@ static inline String resolve_local_dependency_path(String plugin_config_dir, Str
|
||||
return absolute_path;
|
||||
}
|
||||
|
||||
static inline PluginConfigAndroid resolve_prebuilt_plugin(PluginConfigAndroid prebuilt_plugin, String plugin_config_dir) {
|
||||
PluginConfigAndroid PluginConfigAndroid::resolve_prebuilt_plugin(PluginConfigAndroid prebuilt_plugin, String plugin_config_dir) {
|
||||
PluginConfigAndroid resolved = prebuilt_plugin;
|
||||
resolved.binary = resolved.binary_type == PluginConfigAndroid::BINARY_TYPE_LOCAL ? resolve_local_dependency_path(plugin_config_dir, prebuilt_plugin.binary) : prebuilt_plugin.binary;
|
||||
if (!prebuilt_plugin.local_dependencies.is_empty()) {
|
||||
@ -124,13 +69,13 @@ static inline PluginConfigAndroid resolve_prebuilt_plugin(PluginConfigAndroid pr
|
||||
return resolved;
|
||||
}
|
||||
|
||||
static inline Vector<PluginConfigAndroid> get_prebuilt_plugins(String plugins_base_dir) {
|
||||
Vector<PluginConfigAndroid> PluginConfigAndroid::get_prebuilt_plugins(String plugins_base_dir) {
|
||||
Vector<PluginConfigAndroid> prebuilt_plugins;
|
||||
// prebuilt_plugins.push_back(resolve_prebuilt_plugin(MY_PREBUILT_PLUGIN, plugins_base_dir));
|
||||
return prebuilt_plugins;
|
||||
}
|
||||
|
||||
static inline bool is_plugin_config_valid(PluginConfigAndroid plugin_config) {
|
||||
bool PluginConfigAndroid::is_plugin_config_valid(PluginConfigAndroid plugin_config) {
|
||||
bool valid_name = !plugin_config.name.is_empty();
|
||||
bool valid_binary_type = plugin_config.binary_type == PluginConfigAndroid::BINARY_TYPE_LOCAL ||
|
||||
plugin_config.binary_type == PluginConfigAndroid::BINARY_TYPE_REMOTE;
|
||||
@ -155,7 +100,7 @@ static inline bool is_plugin_config_valid(PluginConfigAndroid plugin_config) {
|
||||
return valid_name && valid_binary && valid_binary_type && valid_local_dependencies;
|
||||
}
|
||||
|
||||
static inline uint64_t get_plugin_modification_time(const PluginConfigAndroid &plugin_config, const String &config_path) {
|
||||
uint64_t PluginConfigAndroid::get_plugin_modification_time(const PluginConfigAndroid &plugin_config, const String &config_path) {
|
||||
uint64_t last_updated = FileAccess::get_modified_time(config_path);
|
||||
last_updated = MAX(last_updated, FileAccess::get_modified_time(plugin_config.binary));
|
||||
|
||||
@ -167,7 +112,7 @@ static inline uint64_t get_plugin_modification_time(const PluginConfigAndroid &p
|
||||
return last_updated;
|
||||
}
|
||||
|
||||
static inline PluginConfigAndroid load_plugin_config(Ref<ConfigFile> config_file, const String &path) {
|
||||
PluginConfigAndroid PluginConfigAndroid::load_plugin_config(Ref<ConfigFile> config_file, const String &path) {
|
||||
PluginConfigAndroid plugin_config = {};
|
||||
|
||||
if (config_file.is_valid()) {
|
||||
@ -201,7 +146,7 @@ static inline PluginConfigAndroid load_plugin_config(Ref<ConfigFile> config_file
|
||||
return plugin_config;
|
||||
}
|
||||
|
||||
static inline String get_plugins_binaries(String binary_type, Vector<PluginConfigAndroid> plugins_configs) {
|
||||
String PluginConfigAndroid::get_plugins_binaries(String binary_type, Vector<PluginConfigAndroid> plugins_configs) {
|
||||
String plugins_binaries;
|
||||
if (!plugins_configs.is_empty()) {
|
||||
Vector<String> binaries;
|
||||
@ -230,7 +175,7 @@ static inline String get_plugins_binaries(String binary_type, Vector<PluginConfi
|
||||
return plugins_binaries;
|
||||
}
|
||||
|
||||
static inline String get_plugins_custom_maven_repos(Vector<PluginConfigAndroid> plugins_configs) {
|
||||
String PluginConfigAndroid::get_plugins_custom_maven_repos(Vector<PluginConfigAndroid> plugins_configs) {
|
||||
String custom_maven_repos;
|
||||
if (!plugins_configs.is_empty()) {
|
||||
Vector<String> repos_urls;
|
||||
@ -248,7 +193,7 @@ static inline String get_plugins_custom_maven_repos(Vector<PluginConfigAndroid>
|
||||
return custom_maven_repos;
|
||||
}
|
||||
|
||||
static inline String get_plugins_names(Vector<PluginConfigAndroid> plugins_configs) {
|
||||
String PluginConfigAndroid::get_plugins_names(Vector<PluginConfigAndroid> plugins_configs) {
|
||||
String plugins_names;
|
||||
if (!plugins_configs.is_empty()) {
|
||||
Vector<String> names;
|
||||
@ -265,5 +210,3 @@ static inline String get_plugins_names(Vector<PluginConfigAndroid> plugins_confi
|
||||
|
||||
return plugins_names;
|
||||
}
|
||||
|
||||
#endif // GODOT_PLUGIN_CONFIG_H
|
106
platform/android/export/godot_plugin_config.h
Normal file
106
platform/android/export/godot_plugin_config.h
Normal file
@ -0,0 +1,106 @@
|
||||
/*************************************************************************/
|
||||
/* godot_plugin_config.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef ANDROID_GODOT_PLUGIN_CONFIG_H
|
||||
#define ANDROID_GODOT_PLUGIN_CONFIG_H
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/error/error_list.h"
|
||||
#include "core/io/config_file.h"
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
/*
|
||||
The `config` section and fields are required and defined as follow:
|
||||
- **name**: name of the plugin.
|
||||
- **binary_type**: can be either `local` or `remote`. The type affects the **binary** field.
|
||||
- **binary**:
|
||||
- if **binary_type** is `local`, then this should be the filename of the plugin `aar` file in the `res://android/plugins` directory (e.g: `MyPlugin.aar`).
|
||||
- if **binary_type** is `remote`, then this should be a declaration for a remote gradle binary (e.g: "org.godot.example:my-plugin:0.0.0").
|
||||
|
||||
The `dependencies` section and fields are optional and defined as follow:
|
||||
- **local**: contains a list of local `.aar` binary files the plugin depends on. The local binary dependencies must also be located in the `res://android/plugins` directory.
|
||||
- **remote**: contains a list of remote binary gradle dependencies for the plugin.
|
||||
- **custom_maven_repos**: contains a list of urls specifying custom maven repos required for the plugin's dependencies.
|
||||
|
||||
See https://github.com/godotengine/godot/issues/38157#issuecomment-618773871
|
||||
*/
|
||||
struct PluginConfigAndroid {
|
||||
inline static const char *PLUGIN_CONFIG_EXT = ".gdap";
|
||||
|
||||
inline static const char *CONFIG_SECTION = "config";
|
||||
inline static const char *CONFIG_NAME_KEY = "name";
|
||||
inline static const char *CONFIG_BINARY_TYPE_KEY = "binary_type";
|
||||
inline static const char *CONFIG_BINARY_KEY = "binary";
|
||||
|
||||
inline static const char *DEPENDENCIES_SECTION = "dependencies";
|
||||
inline static const char *DEPENDENCIES_LOCAL_KEY = "local";
|
||||
inline static const char *DEPENDENCIES_REMOTE_KEY = "remote";
|
||||
inline static const char *DEPENDENCIES_CUSTOM_MAVEN_REPOS_KEY = "custom_maven_repos";
|
||||
|
||||
inline static const char *BINARY_TYPE_LOCAL = "local";
|
||||
inline static const char *BINARY_TYPE_REMOTE = "remote";
|
||||
|
||||
inline static const char *PLUGIN_VALUE_SEPARATOR = "|";
|
||||
|
||||
// Set to true when the config file is properly loaded.
|
||||
bool valid_config = false;
|
||||
// Unix timestamp of last change to this plugin.
|
||||
uint64_t last_updated = 0;
|
||||
|
||||
// Required config section
|
||||
String name;
|
||||
String binary_type;
|
||||
String binary;
|
||||
|
||||
// Optional dependencies section
|
||||
Vector<String> local_dependencies;
|
||||
Vector<String> remote_dependencies;
|
||||
Vector<String> custom_maven_repos;
|
||||
|
||||
static String resolve_local_dependency_path(String plugin_config_dir, String dependency_path);
|
||||
|
||||
static PluginConfigAndroid resolve_prebuilt_plugin(PluginConfigAndroid prebuilt_plugin, String plugin_config_dir);
|
||||
|
||||
static Vector<PluginConfigAndroid> get_prebuilt_plugins(String plugins_base_dir);
|
||||
|
||||
static bool is_plugin_config_valid(PluginConfigAndroid plugin_config);
|
||||
|
||||
static uint64_t get_plugin_modification_time(const PluginConfigAndroid &plugin_config, const String &config_path);
|
||||
|
||||
static PluginConfigAndroid load_plugin_config(Ref<ConfigFile> config_file, const String &path);
|
||||
|
||||
static String get_plugins_binaries(String binary_type, Vector<PluginConfigAndroid> plugins_configs);
|
||||
|
||||
static String get_plugins_custom_maven_repos(Vector<PluginConfigAndroid> plugins_configs);
|
||||
|
||||
static String get_plugins_names(Vector<PluginConfigAndroid> plugins_configs);
|
||||
};
|
||||
|
||||
#endif // GODOT_PLUGIN_CONFIG_H
|
252
platform/android/export/gradle_export_util.cpp
Normal file
252
platform/android/export/gradle_export_util.cpp
Normal file
@ -0,0 +1,252 @@
|
||||
/*************************************************************************/
|
||||
/* gradle_export_util.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "gradle_export_util.h"
|
||||
|
||||
int _get_android_orientation_value(DisplayServer::ScreenOrientation screen_orientation) {
|
||||
switch (screen_orientation) {
|
||||
case DisplayServer::SCREEN_PORTRAIT:
|
||||
return 1;
|
||||
case DisplayServer::SCREEN_REVERSE_LANDSCAPE:
|
||||
return 8;
|
||||
case DisplayServer::SCREEN_REVERSE_PORTRAIT:
|
||||
return 9;
|
||||
case DisplayServer::SCREEN_SENSOR_LANDSCAPE:
|
||||
return 11;
|
||||
case DisplayServer::SCREEN_SENSOR_PORTRAIT:
|
||||
return 12;
|
||||
case DisplayServer::SCREEN_SENSOR:
|
||||
return 13;
|
||||
case DisplayServer::SCREEN_LANDSCAPE:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
String _get_android_orientation_label(DisplayServer::ScreenOrientation screen_orientation) {
|
||||
switch (screen_orientation) {
|
||||
case DisplayServer::SCREEN_PORTRAIT:
|
||||
return "portrait";
|
||||
case DisplayServer::SCREEN_REVERSE_LANDSCAPE:
|
||||
return "reverseLandscape";
|
||||
case DisplayServer::SCREEN_REVERSE_PORTRAIT:
|
||||
return "reversePortrait";
|
||||
case DisplayServer::SCREEN_SENSOR_LANDSCAPE:
|
||||
return "userLandscape";
|
||||
case DisplayServer::SCREEN_SENSOR_PORTRAIT:
|
||||
return "userPortrait";
|
||||
case DisplayServer::SCREEN_SENSOR:
|
||||
return "fullUser";
|
||||
case DisplayServer::SCREEN_LANDSCAPE:
|
||||
default:
|
||||
return "landscape";
|
||||
}
|
||||
}
|
||||
|
||||
// Utility method used to create a directory.
|
||||
Error create_directory(const String &p_dir) {
|
||||
if (!DirAccess::exists(p_dir)) {
|
||||
DirAccess *filesystem_da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
||||
ERR_FAIL_COND_V_MSG(!filesystem_da, ERR_CANT_CREATE, "Cannot create directory '" + p_dir + "'.");
|
||||
Error err = filesystem_da->make_dir_recursive(p_dir);
|
||||
ERR_FAIL_COND_V_MSG(err, ERR_CANT_CREATE, "Cannot create directory '" + p_dir + "'.");
|
||||
memdelete(filesystem_da);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
// Writes p_data into a file at p_path, creating directories if necessary.
|
||||
// Note: this will overwrite the file at p_path if it already exists.
|
||||
Error store_file_at_path(const String &p_path, const Vector<uint8_t> &p_data) {
|
||||
String dir = p_path.get_base_dir();
|
||||
Error err = create_directory(dir);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
FileAccess *fa = FileAccess::open(p_path, FileAccess::WRITE);
|
||||
ERR_FAIL_COND_V_MSG(!fa, ERR_CANT_CREATE, "Cannot create file '" + p_path + "'.");
|
||||
fa->store_buffer(p_data.ptr(), p_data.size());
|
||||
memdelete(fa);
|
||||
return OK;
|
||||
}
|
||||
|
||||
// Writes string p_data into a file at p_path, creating directories if necessary.
|
||||
// Note: this will overwrite the file at p_path if it already exists.
|
||||
Error store_string_at_path(const String &p_path, const String &p_data) {
|
||||
String dir = p_path.get_base_dir();
|
||||
Error err = create_directory(dir);
|
||||
if (err != OK) {
|
||||
if (OS::get_singleton()->is_stdout_verbose()) {
|
||||
print_error("Unable to write data into " + p_path);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
FileAccess *fa = FileAccess::open(p_path, FileAccess::WRITE);
|
||||
ERR_FAIL_COND_V_MSG(!fa, ERR_CANT_CREATE, "Cannot create file '" + p_path + "'.");
|
||||
fa->store_string(p_data);
|
||||
memdelete(fa);
|
||||
return OK;
|
||||
}
|
||||
|
||||
// Implementation of EditorExportSaveFunction.
|
||||
// This method will only be called as an input to export_project_files.
|
||||
// It is used by the export_project_files method to save all the asset files into the gradle project.
|
||||
// It's functionality mirrors that of the method save_apk_file.
|
||||
// This method will be called ONLY when custom build is enabled.
|
||||
Error rename_and_store_file_in_gradle_project(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key) {
|
||||
String dst_path = p_path.replace_first("res://", "res://android/build/assets/");
|
||||
print_verbose("Saving project files from " + p_path + " into " + dst_path);
|
||||
Error err = store_file_at_path(dst_path, p_data);
|
||||
return err;
|
||||
}
|
||||
|
||||
// Creates strings.xml files inside the gradle project for different locales.
|
||||
Error _create_project_name_strings_files(const Ref<EditorExportPreset> &p_preset, const String &project_name) {
|
||||
print_verbose("Creating strings resources for supported locales for project " + project_name);
|
||||
// Stores the string into the default values directory.
|
||||
String processed_default_xml_string = vformat(godot_project_name_xml_string, project_name.xml_escape(true));
|
||||
store_string_at_path("res://android/build/res/values/godot_project_name_string.xml", processed_default_xml_string);
|
||||
|
||||
// Searches the Gradle project res/ directory to find all supported locales
|
||||
DirAccessRef da = DirAccess::open("res://android/build/res");
|
||||
if (!da) {
|
||||
if (OS::get_singleton()->is_stdout_verbose()) {
|
||||
print_error("Unable to open Android resources directory.");
|
||||
}
|
||||
return ERR_CANT_OPEN;
|
||||
}
|
||||
da->list_dir_begin();
|
||||
while (true) {
|
||||
String file = da->get_next();
|
||||
if (file == "") {
|
||||
break;
|
||||
}
|
||||
if (!file.begins_with("values-")) {
|
||||
// NOTE: This assumes all directories that start with "values-" are for localization.
|
||||
continue;
|
||||
}
|
||||
String locale = file.replace("values-", "").replace("-r", "_");
|
||||
String property_name = "application/config/name_" + locale;
|
||||
String locale_directory = "res://android/build/res/" + file + "/godot_project_name_string.xml";
|
||||
if (ProjectSettings::get_singleton()->has_setting(property_name)) {
|
||||
String locale_project_name = ProjectSettings::get_singleton()->get(property_name);
|
||||
String processed_xml_string = vformat(godot_project_name_xml_string, locale_project_name.xml_escape(true));
|
||||
print_verbose("Storing project name for locale " + locale + " under " + locale_directory);
|
||||
store_string_at_path(locale_directory, processed_xml_string);
|
||||
} else {
|
||||
// TODO: Once the legacy build system is deprecated we don't need to have xml files for this else branch
|
||||
store_string_at_path(locale_directory, processed_default_xml_string);
|
||||
}
|
||||
}
|
||||
da->list_dir_end();
|
||||
return OK;
|
||||
}
|
||||
|
||||
String bool_to_string(bool v) {
|
||||
return v ? "true" : "false";
|
||||
}
|
||||
|
||||
String _get_gles_tag() {
|
||||
bool min_gles3 = ProjectSettings::get_singleton()->get("rendering/driver/driver_name") == "GLES3" &&
|
||||
!ProjectSettings::get_singleton()->get("rendering/driver/fallback_to_gles2");
|
||||
return min_gles3 ? " <uses-feature android:glEsVersion=\"0x00030000\" android:required=\"true\" />\n" : "";
|
||||
}
|
||||
|
||||
String _get_screen_sizes_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||
String manifest_screen_sizes = " <supports-screens \n tools:node=\"replace\"";
|
||||
String sizes[] = { "small", "normal", "large", "xlarge" };
|
||||
size_t num_sizes = sizeof(sizes) / sizeof(sizes[0]);
|
||||
for (size_t i = 0; i < num_sizes; i++) {
|
||||
String feature_name = vformat("screen/support_%s", sizes[i]);
|
||||
String feature_support = bool_to_string(p_preset->get(feature_name));
|
||||
String xml_entry = vformat("\n android:%sScreens=\"%s\"", sizes[i], feature_support);
|
||||
manifest_screen_sizes += xml_entry;
|
||||
}
|
||||
manifest_screen_sizes += " />\n";
|
||||
return manifest_screen_sizes;
|
||||
}
|
||||
|
||||
String _get_xr_features_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||
String manifest_xr_features;
|
||||
bool uses_xr = (int)(p_preset->get("xr_features/xr_mode")) == 1;
|
||||
if (uses_xr) {
|
||||
int hand_tracking_index = p_preset->get("xr_features/hand_tracking"); // 0: none, 1: optional, 2: required
|
||||
if (hand_tracking_index == 1) {
|
||||
manifest_xr_features += " <uses-feature tools:node=\"replace\" android:name=\"oculus.software.handtracking\" android:required=\"false\" />\n";
|
||||
} else if (hand_tracking_index == 2) {
|
||||
manifest_xr_features += " <uses-feature tools:node=\"replace\" android:name=\"oculus.software.handtracking\" android:required=\"true\" />\n";
|
||||
}
|
||||
}
|
||||
return manifest_xr_features;
|
||||
}
|
||||
|
||||
String _get_instrumentation_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||
String package_name = p_preset->get("package/unique_name");
|
||||
String manifest_instrumentation_text = vformat(
|
||||
" <instrumentation\n"
|
||||
" tools:node=\"replace\"\n"
|
||||
" android:name=\".GodotInstrumentation\"\n"
|
||||
" android:icon=\"@mipmap/icon\"\n"
|
||||
" android:label=\"@string/godot_project_name_string\"\n"
|
||||
" android:targetPackage=\"%s\" />\n",
|
||||
package_name);
|
||||
return manifest_instrumentation_text;
|
||||
}
|
||||
|
||||
String _get_activity_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||
bool uses_xr = (int)(p_preset->get("xr_features/xr_mode")) == 1;
|
||||
String orientation = _get_android_orientation_label(DisplayServer::ScreenOrientation(int(GLOBAL_GET("display/window/handheld/orientation"))));
|
||||
String manifest_activity_text = vformat(
|
||||
" <activity android:name=\"com.godot.game.GodotApp\" "
|
||||
"tools:replace=\"android:screenOrientation\" "
|
||||
"android:screenOrientation=\"%s\">\n",
|
||||
orientation);
|
||||
if (!uses_xr) {
|
||||
manifest_activity_text += " <meta-data tools:node=\"remove\" android:name=\"com.oculus.vr.focusaware\" />\n";
|
||||
}
|
||||
manifest_activity_text += " </activity>\n";
|
||||
return manifest_activity_text;
|
||||
}
|
||||
|
||||
String _get_application_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||
String manifest_application_text = vformat(
|
||||
" <application android:label=\"@string/godot_project_name_string\"\n"
|
||||
" android:allowBackup=\"%s\"\n"
|
||||
" android:icon=\"@mipmap/icon\"\n"
|
||||
" android:isGame=\"%s\"\n"
|
||||
" tools:replace=\"android:allowBackup,android:isGame\"\n"
|
||||
" tools:ignore=\"GoogleAppIndexingWarning\">\n\n",
|
||||
bool_to_string(p_preset->get("user_data_backup/allow")),
|
||||
bool_to_string(p_preset->get("package/classify_as_game")));
|
||||
|
||||
manifest_application_text += _get_activity_tag(p_preset);
|
||||
manifest_application_text += " </application>\n";
|
||||
return manifest_application_text;
|
||||
}
|
@ -44,225 +44,43 @@ const String godot_project_name_xml_string = R"(<?xml version="1.0" encoding="ut
|
||||
</resources>
|
||||
)";
|
||||
|
||||
int _get_android_orientation_value(DisplayServer::ScreenOrientation screen_orientation) {
|
||||
switch (screen_orientation) {
|
||||
case DisplayServer::SCREEN_PORTRAIT:
|
||||
return 1;
|
||||
case DisplayServer::SCREEN_REVERSE_LANDSCAPE:
|
||||
return 8;
|
||||
case DisplayServer::SCREEN_REVERSE_PORTRAIT:
|
||||
return 9;
|
||||
case DisplayServer::SCREEN_SENSOR_LANDSCAPE:
|
||||
return 11;
|
||||
case DisplayServer::SCREEN_SENSOR_PORTRAIT:
|
||||
return 12;
|
||||
case DisplayServer::SCREEN_SENSOR:
|
||||
return 13;
|
||||
case DisplayServer::SCREEN_LANDSCAPE:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
int _get_android_orientation_value(DisplayServer::ScreenOrientation screen_orientation);
|
||||
|
||||
String _get_android_orientation_label(DisplayServer::ScreenOrientation screen_orientation) {
|
||||
switch (screen_orientation) {
|
||||
case DisplayServer::SCREEN_PORTRAIT:
|
||||
return "portrait";
|
||||
case DisplayServer::SCREEN_REVERSE_LANDSCAPE:
|
||||
return "reverseLandscape";
|
||||
case DisplayServer::SCREEN_REVERSE_PORTRAIT:
|
||||
return "reversePortrait";
|
||||
case DisplayServer::SCREEN_SENSOR_LANDSCAPE:
|
||||
return "userLandscape";
|
||||
case DisplayServer::SCREEN_SENSOR_PORTRAIT:
|
||||
return "userPortrait";
|
||||
case DisplayServer::SCREEN_SENSOR:
|
||||
return "fullUser";
|
||||
case DisplayServer::SCREEN_LANDSCAPE:
|
||||
default:
|
||||
return "landscape";
|
||||
}
|
||||
}
|
||||
String _get_android_orientation_label(DisplayServer::ScreenOrientation screen_orientation);
|
||||
|
||||
// Utility method used to create a directory.
|
||||
Error create_directory(const String &p_dir) {
|
||||
if (!DirAccess::exists(p_dir)) {
|
||||
DirAccess *filesystem_da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
||||
ERR_FAIL_COND_V_MSG(!filesystem_da, ERR_CANT_CREATE, "Cannot create directory '" + p_dir + "'.");
|
||||
Error err = filesystem_da->make_dir_recursive(p_dir);
|
||||
ERR_FAIL_COND_V_MSG(err, ERR_CANT_CREATE, "Cannot create directory '" + p_dir + "'.");
|
||||
memdelete(filesystem_da);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
Error create_directory(const String &p_dir);
|
||||
|
||||
// Writes p_data into a file at p_path, creating directories if necessary.
|
||||
// Note: this will overwrite the file at p_path if it already exists.
|
||||
Error store_file_at_path(const String &p_path, const Vector<uint8_t> &p_data) {
|
||||
String dir = p_path.get_base_dir();
|
||||
Error err = create_directory(dir);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
FileAccess *fa = FileAccess::open(p_path, FileAccess::WRITE);
|
||||
ERR_FAIL_COND_V_MSG(!fa, ERR_CANT_CREATE, "Cannot create file '" + p_path + "'.");
|
||||
fa->store_buffer(p_data.ptr(), p_data.size());
|
||||
memdelete(fa);
|
||||
return OK;
|
||||
}
|
||||
Error store_file_at_path(const String &p_path, const Vector<uint8_t> &p_data);
|
||||
|
||||
// Writes string p_data into a file at p_path, creating directories if necessary.
|
||||
// Note: this will overwrite the file at p_path if it already exists.
|
||||
Error store_string_at_path(const String &p_path, const String &p_data) {
|
||||
String dir = p_path.get_base_dir();
|
||||
Error err = create_directory(dir);
|
||||
if (err != OK) {
|
||||
if (OS::get_singleton()->is_stdout_verbose()) {
|
||||
print_error("Unable to write data into " + p_path);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
FileAccess *fa = FileAccess::open(p_path, FileAccess::WRITE);
|
||||
ERR_FAIL_COND_V_MSG(!fa, ERR_CANT_CREATE, "Cannot create file '" + p_path + "'.");
|
||||
fa->store_string(p_data);
|
||||
memdelete(fa);
|
||||
return OK;
|
||||
}
|
||||
Error store_string_at_path(const String &p_path, const String &p_data);
|
||||
|
||||
// Implementation of EditorExportSaveFunction.
|
||||
// This method will only be called as an input to export_project_files.
|
||||
// It is used by the export_project_files method to save all the asset files into the gradle project.
|
||||
// It's functionality mirrors that of the method save_apk_file.
|
||||
// This method will be called ONLY when custom build is enabled.
|
||||
Error rename_and_store_file_in_gradle_project(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key) {
|
||||
String dst_path = p_path.replace_first("res://", "res://android/build/assets/");
|
||||
print_verbose("Saving project files from " + p_path + " into " + dst_path);
|
||||
Error err = store_file_at_path(dst_path, p_data);
|
||||
return err;
|
||||
}
|
||||
Error rename_and_store_file_in_gradle_project(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key);
|
||||
|
||||
// Creates strings.xml files inside the gradle project for different locales.
|
||||
Error _create_project_name_strings_files(const Ref<EditorExportPreset> &p_preset, const String &project_name) {
|
||||
print_verbose("Creating strings resources for supported locales for project " + project_name);
|
||||
// Stores the string into the default values directory.
|
||||
String processed_default_xml_string = vformat(godot_project_name_xml_string, project_name.xml_escape(true));
|
||||
store_string_at_path("res://android/build/res/values/godot_project_name_string.xml", processed_default_xml_string);
|
||||
Error _create_project_name_strings_files(const Ref<EditorExportPreset> &p_preset, const String &project_name);
|
||||
|
||||
// Searches the Gradle project res/ directory to find all supported locales
|
||||
DirAccessRef da = DirAccess::open("res://android/build/res");
|
||||
if (!da) {
|
||||
if (OS::get_singleton()->is_stdout_verbose()) {
|
||||
print_error("Unable to open Android resources directory.");
|
||||
}
|
||||
return ERR_CANT_OPEN;
|
||||
}
|
||||
da->list_dir_begin();
|
||||
while (true) {
|
||||
String file = da->get_next();
|
||||
if (file == "") {
|
||||
break;
|
||||
}
|
||||
if (!file.begins_with("values-")) {
|
||||
// NOTE: This assumes all directories that start with "values-" are for localization.
|
||||
continue;
|
||||
}
|
||||
String locale = file.replace("values-", "").replace("-r", "_");
|
||||
String property_name = "application/config/name_" + locale;
|
||||
String locale_directory = "res://android/build/res/" + file + "/godot_project_name_string.xml";
|
||||
if (ProjectSettings::get_singleton()->has_setting(property_name)) {
|
||||
String locale_project_name = ProjectSettings::get_singleton()->get(property_name);
|
||||
String processed_xml_string = vformat(godot_project_name_xml_string, locale_project_name.xml_escape(true));
|
||||
print_verbose("Storing project name for locale " + locale + " under " + locale_directory);
|
||||
store_string_at_path(locale_directory, processed_xml_string);
|
||||
} else {
|
||||
// TODO: Once the legacy build system is deprecated we don't need to have xml files for this else branch
|
||||
store_string_at_path(locale_directory, processed_default_xml_string);
|
||||
}
|
||||
}
|
||||
da->list_dir_end();
|
||||
return OK;
|
||||
}
|
||||
String bool_to_string(bool v);
|
||||
|
||||
String bool_to_string(bool v) {
|
||||
return v ? "true" : "false";
|
||||
}
|
||||
String _get_gles_tag();
|
||||
|
||||
String _get_gles_tag() {
|
||||
bool min_gles3 = ProjectSettings::get_singleton()->get("rendering/driver/driver_name") == "GLES3" &&
|
||||
!ProjectSettings::get_singleton()->get("rendering/driver/fallback_to_gles2");
|
||||
return min_gles3 ? " <uses-feature android:glEsVersion=\"0x00030000\" android:required=\"true\" />\n" : "";
|
||||
}
|
||||
String _get_screen_sizes_tag(const Ref<EditorExportPreset> &p_preset);
|
||||
|
||||
String _get_screen_sizes_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||
String manifest_screen_sizes = " <supports-screens \n tools:node=\"replace\"";
|
||||
String sizes[] = { "small", "normal", "large", "xlarge" };
|
||||
size_t num_sizes = sizeof(sizes) / sizeof(sizes[0]);
|
||||
for (size_t i = 0; i < num_sizes; i++) {
|
||||
String feature_name = vformat("screen/support_%s", sizes[i]);
|
||||
String feature_support = bool_to_string(p_preset->get(feature_name));
|
||||
String xml_entry = vformat("\n android:%sScreens=\"%s\"", sizes[i], feature_support);
|
||||
manifest_screen_sizes += xml_entry;
|
||||
}
|
||||
manifest_screen_sizes += " />\n";
|
||||
return manifest_screen_sizes;
|
||||
}
|
||||
String _get_xr_features_tag(const Ref<EditorExportPreset> &p_preset);
|
||||
|
||||
String _get_xr_features_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||
String manifest_xr_features;
|
||||
bool uses_xr = (int)(p_preset->get("xr_features/xr_mode")) == 1;
|
||||
if (uses_xr) {
|
||||
int hand_tracking_index = p_preset->get("xr_features/hand_tracking"); // 0: none, 1: optional, 2: required
|
||||
if (hand_tracking_index == 1) {
|
||||
manifest_xr_features += " <uses-feature tools:node=\"replace\" android:name=\"oculus.software.handtracking\" android:required=\"false\" />\n";
|
||||
} else if (hand_tracking_index == 2) {
|
||||
manifest_xr_features += " <uses-feature tools:node=\"replace\" android:name=\"oculus.software.handtracking\" android:required=\"true\" />\n";
|
||||
}
|
||||
}
|
||||
return manifest_xr_features;
|
||||
}
|
||||
String _get_instrumentation_tag(const Ref<EditorExportPreset> &p_preset);
|
||||
|
||||
String _get_instrumentation_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||
String package_name = p_preset->get("package/unique_name");
|
||||
String manifest_instrumentation_text = vformat(
|
||||
" <instrumentation\n"
|
||||
" tools:node=\"replace\"\n"
|
||||
" android:name=\".GodotInstrumentation\"\n"
|
||||
" android:icon=\"@mipmap/icon\"\n"
|
||||
" android:label=\"@string/godot_project_name_string\"\n"
|
||||
" android:targetPackage=\"%s\" />\n",
|
||||
package_name);
|
||||
return manifest_instrumentation_text;
|
||||
}
|
||||
String _get_activity_tag(const Ref<EditorExportPreset> &p_preset);
|
||||
|
||||
String _get_activity_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||
bool uses_xr = (int)(p_preset->get("xr_features/xr_mode")) == 1;
|
||||
String orientation = _get_android_orientation_label(DisplayServer::ScreenOrientation(int(GLOBAL_GET("display/window/handheld/orientation"))));
|
||||
String manifest_activity_text = vformat(
|
||||
" <activity android:name=\"com.godot.game.GodotApp\" "
|
||||
"tools:replace=\"android:screenOrientation\" "
|
||||
"android:screenOrientation=\"%s\">\n",
|
||||
orientation);
|
||||
if (!uses_xr) {
|
||||
manifest_activity_text += " <meta-data tools:node=\"remove\" android:name=\"com.oculus.vr.focusaware\" />\n";
|
||||
}
|
||||
manifest_activity_text += " </activity>\n";
|
||||
return manifest_activity_text;
|
||||
}
|
||||
|
||||
String _get_application_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||
String manifest_application_text = vformat(
|
||||
" <application android:label=\"@string/godot_project_name_string\"\n"
|
||||
" android:allowBackup=\"%s\"\n"
|
||||
" android:icon=\"@mipmap/icon\"\n"
|
||||
" android:isGame=\"%s\"\n"
|
||||
" tools:replace=\"android:allowBackup,android:isGame\"\n"
|
||||
" tools:ignore=\"GoogleAppIndexingWarning\">\n\n",
|
||||
bool_to_string(p_preset->get("user_data_backup/allow")),
|
||||
bool_to_string(p_preset->get("package/classify_as_game")));
|
||||
|
||||
manifest_application_text += _get_activity_tag(p_preset);
|
||||
manifest_application_text += " </application>\n";
|
||||
return manifest_application_text;
|
||||
}
|
||||
String _get_application_tag(const Ref<EditorExportPreset> &p_preset);
|
||||
|
||||
#endif //GODOT_GRADLE_EXPORT_UTIL_H
|
||||
|
File diff suppressed because it is too large
Load Diff
1792
platform/iphone/export/export_plugin.cpp
Normal file
1792
platform/iphone/export/export_plugin.cpp
Normal file
File diff suppressed because it is too large
Load Diff
296
platform/iphone/export/export_plugin.h
Normal file
296
platform/iphone/export/export_plugin.h
Normal file
@ -0,0 +1,296 @@
|
||||
/*************************************************************************/
|
||||
/* export_plugin.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef IPHONE_EXPORT_PLUGIN_H
|
||||
#define IPHONE_EXPORT_PLUGIN_H
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/io/file_access.h"
|
||||
#include "core/io/image_loader.h"
|
||||
#include "core/io/marshalls.h"
|
||||
#include "core/io/resource_saver.h"
|
||||
#include "core/io/zip_io.h"
|
||||
#include "core/os/os.h"
|
||||
#include "core/templates/safe_refcount.h"
|
||||
#include "core/version.h"
|
||||
#include "editor/editor_export.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "main/splash.gen.h"
|
||||
#include "platform/iphone/logo.gen.h"
|
||||
#include "string.h"
|
||||
|
||||
#include "godot_plugin_config.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
class EditorExportPlatformIOS : public EditorExportPlatform {
|
||||
GDCLASS(EditorExportPlatformIOS, EditorExportPlatform);
|
||||
|
||||
int version_code;
|
||||
|
||||
Ref<ImageTexture> logo;
|
||||
|
||||
// Plugins
|
||||
SafeFlag plugins_changed;
|
||||
Thread check_for_changes_thread;
|
||||
SafeFlag quit_request;
|
||||
Mutex plugins_lock;
|
||||
Vector<PluginConfigIOS> plugins;
|
||||
|
||||
typedef Error (*FileHandler)(String p_file, void *p_userdata);
|
||||
static Error _walk_dir_recursive(DirAccess *p_da, FileHandler p_handler, void *p_userdata);
|
||||
static Error _codesign(String p_file, void *p_userdata);
|
||||
void _blend_and_rotate(Ref<Image> &p_dst, Ref<Image> &p_src, bool p_rot);
|
||||
|
||||
struct IOSConfigData {
|
||||
String pkg_name;
|
||||
String binary_name;
|
||||
String plist_content;
|
||||
String architectures;
|
||||
String linker_flags;
|
||||
String cpp_code;
|
||||
String modules_buildfile;
|
||||
String modules_fileref;
|
||||
String modules_buildphase;
|
||||
String modules_buildgrp;
|
||||
Vector<String> capabilities;
|
||||
};
|
||||
struct ExportArchitecture {
|
||||
String name;
|
||||
bool is_default = false;
|
||||
|
||||
ExportArchitecture() {}
|
||||
|
||||
ExportArchitecture(String p_name, bool p_is_default) {
|
||||
name = p_name;
|
||||
is_default = p_is_default;
|
||||
}
|
||||
};
|
||||
|
||||
struct IOSExportAsset {
|
||||
String exported_path;
|
||||
bool is_framework = false; // framework is anything linked to the binary, otherwise it's a resource
|
||||
bool should_embed = false;
|
||||
};
|
||||
|
||||
String _get_additional_plist_content();
|
||||
String _get_linker_flags();
|
||||
String _get_cpp_code();
|
||||
void _fix_config_file(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &pfile, const IOSConfigData &p_config, bool p_debug);
|
||||
Error _export_loading_screen_images(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir);
|
||||
Error _export_loading_screen_file(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir);
|
||||
Error _export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir);
|
||||
|
||||
Vector<ExportArchitecture> _get_supported_architectures();
|
||||
Vector<String> _get_preset_architectures(const Ref<EditorExportPreset> &p_preset);
|
||||
|
||||
void _add_assets_to_project(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_project_data, const Vector<IOSExportAsset> &p_additional_assets);
|
||||
Error _export_additional_assets(const String &p_out_dir, const Vector<String> &p_assets, bool p_is_framework, bool p_should_embed, Vector<IOSExportAsset> &r_exported_assets);
|
||||
Error _copy_asset(const String &p_out_dir, const String &p_asset, const String *p_custom_file_name, bool p_is_framework, bool p_should_embed, Vector<IOSExportAsset> &r_exported_assets);
|
||||
Error _export_additional_assets(const String &p_out_dir, const Vector<SharedObject> &p_libraries, Vector<IOSExportAsset> &r_exported_assets);
|
||||
Error _export_ios_plugins(const Ref<EditorExportPreset> &p_preset, IOSConfigData &p_config_data, const String &dest_dir, Vector<IOSExportAsset> &r_exported_assets, bool p_debug);
|
||||
|
||||
bool is_package_name_valid(const String &p_package, String *r_error = nullptr) const {
|
||||
String pname = p_package;
|
||||
|
||||
if (pname.length() == 0) {
|
||||
if (r_error) {
|
||||
*r_error = TTR("Identifier is missing.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < pname.length(); i++) {
|
||||
char32_t c = pname[i];
|
||||
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '.')) {
|
||||
if (r_error) {
|
||||
*r_error = vformat(TTR("The character '%s' is not allowed in Identifier."), String::chr(c));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void _check_for_changes_poll_thread(void *ud) {
|
||||
EditorExportPlatformIOS *ea = (EditorExportPlatformIOS *)ud;
|
||||
|
||||
while (!ea->quit_request.is_set()) {
|
||||
// Nothing to do if we already know the plugins have changed.
|
||||
if (!ea->plugins_changed.is_set()) {
|
||||
MutexLock lock(ea->plugins_lock);
|
||||
|
||||
Vector<PluginConfigIOS> loaded_plugins = get_plugins();
|
||||
|
||||
if (ea->plugins.size() != loaded_plugins.size()) {
|
||||
ea->plugins_changed.set();
|
||||
} else {
|
||||
for (int i = 0; i < ea->plugins.size(); i++) {
|
||||
if (ea->plugins[i].name != loaded_plugins[i].name || ea->plugins[i].last_updated != loaded_plugins[i].last_updated) {
|
||||
ea->plugins_changed.set();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t wait = 3000000;
|
||||
uint64_t time = OS::get_singleton()->get_ticks_usec();
|
||||
while (OS::get_singleton()->get_ticks_usec() - time < wait) {
|
||||
OS::get_singleton()->delay_usec(300000);
|
||||
|
||||
if (ea->quit_request.is_set()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) override;
|
||||
virtual void get_export_options(List<ExportOption> *r_options) override;
|
||||
|
||||
public:
|
||||
virtual String get_name() const override { return "iOS"; }
|
||||
virtual String get_os_name() const override { return "iOS"; }
|
||||
virtual Ref<Texture2D> get_logo() const override { return logo; }
|
||||
|
||||
virtual bool should_update_export_options() override {
|
||||
bool export_options_changed = plugins_changed.is_set();
|
||||
if (export_options_changed) {
|
||||
// don't clear unless we're reporting true, to avoid race
|
||||
plugins_changed.clear();
|
||||
}
|
||||
return export_options_changed;
|
||||
}
|
||||
|
||||
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override {
|
||||
List<String> list;
|
||||
list.push_back("ipa");
|
||||
return list;
|
||||
}
|
||||
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) override;
|
||||
|
||||
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
|
||||
|
||||
virtual void get_platform_features(List<String> *r_features) override {
|
||||
r_features->push_back("mobile");
|
||||
r_features->push_back("iOS");
|
||||
}
|
||||
|
||||
virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) override {
|
||||
}
|
||||
|
||||
EditorExportPlatformIOS();
|
||||
~EditorExportPlatformIOS();
|
||||
|
||||
/// List the gdip files in the directory specified by the p_path parameter.
|
||||
static Vector<String> list_plugin_config_files(const String &p_path, bool p_check_directories) {
|
||||
Vector<String> dir_files;
|
||||
DirAccessRef da = DirAccess::open(p_path);
|
||||
if (da) {
|
||||
da->list_dir_begin();
|
||||
while (true) {
|
||||
String file = da->get_next();
|
||||
if (file.is_empty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (file == "." || file == "..") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (da->current_is_hidden()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (da->current_is_dir()) {
|
||||
if (p_check_directories) {
|
||||
Vector<String> directory_files = list_plugin_config_files(p_path.plus_file(file), false);
|
||||
for (int i = 0; i < directory_files.size(); ++i) {
|
||||
dir_files.push_back(file.plus_file(directory_files[i]));
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (file.ends_with(PluginConfigIOS::PLUGIN_CONFIG_EXT)) {
|
||||
dir_files.push_back(file);
|
||||
}
|
||||
}
|
||||
da->list_dir_end();
|
||||
}
|
||||
|
||||
return dir_files;
|
||||
}
|
||||
|
||||
static Vector<PluginConfigIOS> get_plugins() {
|
||||
Vector<PluginConfigIOS> loaded_plugins;
|
||||
|
||||
String plugins_dir = ProjectSettings::get_singleton()->get_resource_path().plus_file("ios/plugins");
|
||||
|
||||
if (DirAccess::exists(plugins_dir)) {
|
||||
Vector<String> plugins_filenames = list_plugin_config_files(plugins_dir, true);
|
||||
|
||||
if (!plugins_filenames.is_empty()) {
|
||||
Ref<ConfigFile> config_file = memnew(ConfigFile);
|
||||
for (int i = 0; i < plugins_filenames.size(); i++) {
|
||||
PluginConfigIOS config = PluginConfigIOS::load_plugin_config(config_file, plugins_dir.plus_file(plugins_filenames[i]));
|
||||
if (config.valid_config) {
|
||||
loaded_plugins.push_back(config);
|
||||
} else {
|
||||
print_error("Invalid plugin config file " + plugins_filenames[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return loaded_plugins;
|
||||
}
|
||||
|
||||
static Vector<PluginConfigIOS> get_enabled_plugins(const Ref<EditorExportPreset> &p_presets) {
|
||||
Vector<PluginConfigIOS> enabled_plugins;
|
||||
Vector<PluginConfigIOS> all_plugins = get_plugins();
|
||||
for (int i = 0; i < all_plugins.size(); i++) {
|
||||
PluginConfigIOS plugin = all_plugins[i];
|
||||
bool enabled = p_presets->get("plugins/" + plugin.name);
|
||||
if (enabled) {
|
||||
enabled_plugins.push_back(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
return enabled_plugins;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/*************************************************************************/
|
||||
/* godot_plugin_config.h */
|
||||
/* godot_plugin_config.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
@ -28,92 +28,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef GODOT_PLUGIN_CONFIG_H
|
||||
#define GODOT_PLUGIN_CONFIG_H
|
||||
#include "godot_plugin_config.h"
|
||||
|
||||
#include "core/error/error_list.h"
|
||||
#include "core/io/config_file.h"
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/io/dir_access.h"
|
||||
#include "core/io/file_access.h"
|
||||
|
||||
/*
|
||||
The `config` section and fields are required and defined as follow:
|
||||
- **name**: name of the plugin
|
||||
- **binary**: path to static `.a` library
|
||||
|
||||
The `dependencies` and fields are optional.
|
||||
- **linked**: dependencies that should only be linked.
|
||||
- **embedded**: dependencies that should be linked and embedded into application.
|
||||
- **system**: system dependencies that should be linked.
|
||||
- **capabilities**: capabilities that would be used for `UIRequiredDeviceCapabilities` options in Info.plist file.
|
||||
- **files**: files that would be copied into application
|
||||
|
||||
The `plist` section are optional.
|
||||
- **key**: key and value that would be added in Info.plist file.
|
||||
*/
|
||||
|
||||
struct PluginConfigIOS {
|
||||
inline static const char *PLUGIN_CONFIG_EXT = ".gdip";
|
||||
|
||||
inline static const char *CONFIG_SECTION = "config";
|
||||
inline static const char *CONFIG_NAME_KEY = "name";
|
||||
inline static const char *CONFIG_BINARY_KEY = "binary";
|
||||
inline static const char *CONFIG_INITIALIZE_KEY = "initialization";
|
||||
inline static const char *CONFIG_DEINITIALIZE_KEY = "deinitialization";
|
||||
|
||||
inline static const char *DEPENDENCIES_SECTION = "dependencies";
|
||||
inline static const char *DEPENDENCIES_LINKED_KEY = "linked";
|
||||
inline static const char *DEPENDENCIES_EMBEDDED_KEY = "embedded";
|
||||
inline static const char *DEPENDENCIES_SYSTEM_KEY = "system";
|
||||
inline static const char *DEPENDENCIES_CAPABILITIES_KEY = "capabilities";
|
||||
inline static const char *DEPENDENCIES_FILES_KEY = "files";
|
||||
inline static const char *DEPENDENCIES_LINKER_FLAGS = "linker_flags";
|
||||
|
||||
inline static const char *PLIST_SECTION = "plist";
|
||||
|
||||
enum PlistItemType {
|
||||
UNKNOWN,
|
||||
STRING,
|
||||
INTEGER,
|
||||
BOOLEAN,
|
||||
RAW,
|
||||
STRING_INPUT,
|
||||
};
|
||||
|
||||
struct PlistItem {
|
||||
PlistItemType type;
|
||||
String value;
|
||||
};
|
||||
|
||||
// Set to true when the config file is properly loaded.
|
||||
bool valid_config = false;
|
||||
bool supports_targets = false;
|
||||
// Unix timestamp of last change to this plugin.
|
||||
uint64_t last_updated = 0;
|
||||
|
||||
// Required config section
|
||||
String name;
|
||||
String binary;
|
||||
String initialization_method;
|
||||
String deinitialization_method;
|
||||
|
||||
// Optional dependencies section
|
||||
Vector<String> linked_dependencies;
|
||||
Vector<String> embedded_dependencies;
|
||||
Vector<String> system_dependencies;
|
||||
|
||||
Vector<String> files_to_copy;
|
||||
Vector<String> capabilities;
|
||||
|
||||
Vector<String> linker_flags;
|
||||
|
||||
// Optional plist section
|
||||
// String value is default value.
|
||||
// Currently supports `string`, `boolean`, `integer`, `raw`, `string_input` types
|
||||
// <name>:<type> = <value>
|
||||
HashMap<String, PlistItem> plist;
|
||||
};
|
||||
|
||||
static inline String resolve_local_dependency_path(String plugin_config_dir, String dependency_path) {
|
||||
String PluginConfigIOS::resolve_local_dependency_path(String plugin_config_dir, String dependency_path) {
|
||||
String absolute_path;
|
||||
|
||||
if (dependency_path.is_empty()) {
|
||||
@ -130,7 +51,7 @@ static inline String resolve_local_dependency_path(String plugin_config_dir, Str
|
||||
return absolute_path.replace(res_path, "res://");
|
||||
}
|
||||
|
||||
static inline String resolve_system_dependency_path(String dependency_path) {
|
||||
String PluginConfigIOS::resolve_system_dependency_path(String dependency_path) {
|
||||
String absolute_path;
|
||||
|
||||
if (dependency_path.is_empty()) {
|
||||
@ -146,7 +67,7 @@ static inline String resolve_system_dependency_path(String dependency_path) {
|
||||
return system_path.plus_file(dependency_path);
|
||||
}
|
||||
|
||||
static inline Vector<String> resolve_local_dependencies(String plugin_config_dir, Vector<String> p_paths) {
|
||||
Vector<String> PluginConfigIOS::resolve_local_dependencies(String plugin_config_dir, Vector<String> p_paths) {
|
||||
Vector<String> paths;
|
||||
|
||||
for (int i = 0; i < p_paths.size(); i++) {
|
||||
@ -162,7 +83,7 @@ static inline Vector<String> resolve_local_dependencies(String plugin_config_dir
|
||||
return paths;
|
||||
}
|
||||
|
||||
static inline Vector<String> resolve_system_dependencies(Vector<String> p_paths) {
|
||||
Vector<String> PluginConfigIOS::resolve_system_dependencies(Vector<String> p_paths) {
|
||||
Vector<String> paths;
|
||||
|
||||
for (int i = 0; i < p_paths.size(); i++) {
|
||||
@ -178,7 +99,7 @@ static inline Vector<String> resolve_system_dependencies(Vector<String> p_paths)
|
||||
return paths;
|
||||
}
|
||||
|
||||
static inline bool validate_plugin(PluginConfigIOS &plugin_config) {
|
||||
bool PluginConfigIOS::validate_plugin(PluginConfigIOS &plugin_config) {
|
||||
bool valid_name = !plugin_config.name.is_empty();
|
||||
bool valid_binary_name = !plugin_config.binary.is_empty();
|
||||
bool valid_initialize = !plugin_config.initialization_method.is_empty();
|
||||
@ -213,7 +134,7 @@ static inline bool validate_plugin(PluginConfigIOS &plugin_config) {
|
||||
return plugin_config.valid_config;
|
||||
}
|
||||
|
||||
static inline String get_plugin_main_binary(PluginConfigIOS &plugin_config, bool p_debug) {
|
||||
String PluginConfigIOS::get_plugin_main_binary(PluginConfigIOS &plugin_config, bool p_debug) {
|
||||
if (!plugin_config.supports_targets) {
|
||||
return plugin_config.binary;
|
||||
}
|
||||
@ -226,7 +147,7 @@ static inline String get_plugin_main_binary(PluginConfigIOS &plugin_config, bool
|
||||
return plugin_binary_dir.plus_file(plugin_file);
|
||||
}
|
||||
|
||||
static inline uint64_t get_plugin_modification_time(const PluginConfigIOS &plugin_config, const String &config_path) {
|
||||
uint64_t PluginConfigIOS::get_plugin_modification_time(const PluginConfigIOS &plugin_config, const String &config_path) {
|
||||
uint64_t last_updated = FileAccess::get_modified_time(config_path);
|
||||
|
||||
if (!plugin_config.supports_targets) {
|
||||
@ -245,7 +166,7 @@ static inline uint64_t get_plugin_modification_time(const PluginConfigIOS &plugi
|
||||
return last_updated;
|
||||
}
|
||||
|
||||
static inline PluginConfigIOS load_plugin_config(Ref<ConfigFile> config_file, const String &path) {
|
||||
PluginConfigIOS PluginConfigIOS::load_plugin_config(Ref<ConfigFile> config_file, const String &path) {
|
||||
PluginConfigIOS plugin_config = {};
|
||||
|
||||
if (!config_file.is_valid()) {
|
||||
@ -362,5 +283,3 @@ static inline PluginConfigIOS load_plugin_config(Ref<ConfigFile> config_file, co
|
||||
|
||||
return plugin_config;
|
||||
}
|
||||
|
||||
#endif // GODOT_PLUGIN_CONFIG_H
|
132
platform/iphone/export/godot_plugin_config.h
Normal file
132
platform/iphone/export/godot_plugin_config.h
Normal file
@ -0,0 +1,132 @@
|
||||
/*************************************************************************/
|
||||
/* godot_plugin_config.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef IPHONE_GODOT_PLUGIN_CONFIG_H
|
||||
#define IPHONE_GODOT_PLUGIN_CONFIG_H
|
||||
|
||||
#include "core/error/error_list.h"
|
||||
#include "core/io/config_file.h"
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
/*
|
||||
The `config` section and fields are required and defined as follow:
|
||||
- **name**: name of the plugin
|
||||
- **binary**: path to static `.a` library
|
||||
|
||||
The `dependencies` and fields are optional.
|
||||
- **linked**: dependencies that should only be linked.
|
||||
- **embedded**: dependencies that should be linked and embedded into application.
|
||||
- **system**: system dependencies that should be linked.
|
||||
- **capabilities**: capabilities that would be used for `UIRequiredDeviceCapabilities` options in Info.plist file.
|
||||
- **files**: files that would be copied into application
|
||||
|
||||
The `plist` section are optional.
|
||||
- **key**: key and value that would be added in Info.plist file.
|
||||
*/
|
||||
|
||||
struct PluginConfigIOS {
|
||||
inline static const char *PLUGIN_CONFIG_EXT = ".gdip";
|
||||
|
||||
inline static const char *CONFIG_SECTION = "config";
|
||||
inline static const char *CONFIG_NAME_KEY = "name";
|
||||
inline static const char *CONFIG_BINARY_KEY = "binary";
|
||||
inline static const char *CONFIG_INITIALIZE_KEY = "initialization";
|
||||
inline static const char *CONFIG_DEINITIALIZE_KEY = "deinitialization";
|
||||
|
||||
inline static const char *DEPENDENCIES_SECTION = "dependencies";
|
||||
inline static const char *DEPENDENCIES_LINKED_KEY = "linked";
|
||||
inline static const char *DEPENDENCIES_EMBEDDED_KEY = "embedded";
|
||||
inline static const char *DEPENDENCIES_SYSTEM_KEY = "system";
|
||||
inline static const char *DEPENDENCIES_CAPABILITIES_KEY = "capabilities";
|
||||
inline static const char *DEPENDENCIES_FILES_KEY = "files";
|
||||
inline static const char *DEPENDENCIES_LINKER_FLAGS = "linker_flags";
|
||||
|
||||
inline static const char *PLIST_SECTION = "plist";
|
||||
|
||||
enum PlistItemType {
|
||||
UNKNOWN,
|
||||
STRING,
|
||||
INTEGER,
|
||||
BOOLEAN,
|
||||
RAW,
|
||||
STRING_INPUT,
|
||||
};
|
||||
|
||||
struct PlistItem {
|
||||
PlistItemType type;
|
||||
String value;
|
||||
};
|
||||
|
||||
// Set to true when the config file is properly loaded.
|
||||
bool valid_config = false;
|
||||
bool supports_targets = false;
|
||||
// Unix timestamp of last change to this plugin.
|
||||
uint64_t last_updated = 0;
|
||||
|
||||
// Required config section
|
||||
String name;
|
||||
String binary;
|
||||
String initialization_method;
|
||||
String deinitialization_method;
|
||||
|
||||
// Optional dependencies section
|
||||
Vector<String> linked_dependencies;
|
||||
Vector<String> embedded_dependencies;
|
||||
Vector<String> system_dependencies;
|
||||
|
||||
Vector<String> files_to_copy;
|
||||
Vector<String> capabilities;
|
||||
|
||||
Vector<String> linker_flags;
|
||||
|
||||
// Optional plist section
|
||||
// String value is default value.
|
||||
// Currently supports `string`, `boolean`, `integer`, `raw`, `string_input` types
|
||||
// <name>:<type> = <value>
|
||||
HashMap<String, PlistItem> plist;
|
||||
|
||||
static String resolve_local_dependency_path(String plugin_config_dir, String dependency_path);
|
||||
|
||||
static String resolve_system_dependency_path(String dependency_path);
|
||||
|
||||
static Vector<String> resolve_local_dependencies(String plugin_config_dir, Vector<String> p_paths);
|
||||
|
||||
static Vector<String> resolve_system_dependencies(Vector<String> p_paths);
|
||||
|
||||
static bool validate_plugin(PluginConfigIOS &plugin_config);
|
||||
|
||||
static String get_plugin_main_binary(PluginConfigIOS &plugin_config, bool p_debug);
|
||||
|
||||
static uint64_t get_plugin_modification_time(const PluginConfigIOS &plugin_config, const String &config_path);
|
||||
|
||||
static PluginConfigIOS load_plugin_config(Ref<ConfigFile> config_file, const String &path);
|
||||
};
|
||||
|
||||
#endif // GODOT_PLUGIN_CONFIG_H
|
@ -28,971 +28,9 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/io/image_loader.h"
|
||||
#include "core/io/stream_peer_ssl.h"
|
||||
#include "core/io/tcp_server.h"
|
||||
#include "core/io/zip_io.h"
|
||||
#include "editor/editor_export.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "main/splash.gen.h"
|
||||
#include "platform/javascript/logo.gen.h"
|
||||
#include "platform/javascript/run_icon.gen.h"
|
||||
#include "export.h"
|
||||
|
||||
class EditorHTTPServer : public RefCounted {
|
||||
private:
|
||||
Ref<TCPServer> server;
|
||||
Map<String, String> mimes;
|
||||
Ref<StreamPeerTCP> tcp;
|
||||
Ref<StreamPeerSSL> ssl;
|
||||
Ref<StreamPeer> peer;
|
||||
Ref<CryptoKey> key;
|
||||
Ref<X509Certificate> cert;
|
||||
bool use_ssl = false;
|
||||
uint64_t time = 0;
|
||||
uint8_t req_buf[4096];
|
||||
int req_pos = 0;
|
||||
|
||||
void _clear_client() {
|
||||
peer = Ref<StreamPeer>();
|
||||
ssl = Ref<StreamPeerSSL>();
|
||||
tcp = Ref<StreamPeerTCP>();
|
||||
memset(req_buf, 0, sizeof(req_buf));
|
||||
time = 0;
|
||||
req_pos = 0;
|
||||
}
|
||||
|
||||
void _set_internal_certs(Ref<Crypto> p_crypto) {
|
||||
const String cache_path = EditorPaths::get_singleton()->get_cache_dir();
|
||||
const String key_path = cache_path.plus_file("html5_server.key");
|
||||
const String crt_path = cache_path.plus_file("html5_server.crt");
|
||||
bool regen = !FileAccess::exists(key_path) || !FileAccess::exists(crt_path);
|
||||
if (!regen) {
|
||||
key = Ref<CryptoKey>(CryptoKey::create());
|
||||
cert = Ref<X509Certificate>(X509Certificate::create());
|
||||
if (key->load(key_path) != OK || cert->load(crt_path) != OK) {
|
||||
regen = true;
|
||||
}
|
||||
}
|
||||
if (regen) {
|
||||
key = p_crypto->generate_rsa(2048);
|
||||
key->save(key_path);
|
||||
cert = p_crypto->generate_self_signed_certificate(key, "CN=godot-debug.local,O=A Game Dev,C=XXA", "20140101000000", "20340101000000");
|
||||
cert->save(crt_path);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
EditorHTTPServer() {
|
||||
mimes["html"] = "text/html";
|
||||
mimes["js"] = "application/javascript";
|
||||
mimes["json"] = "application/json";
|
||||
mimes["pck"] = "application/octet-stream";
|
||||
mimes["png"] = "image/png";
|
||||
mimes["svg"] = "image/svg";
|
||||
mimes["wasm"] = "application/wasm";
|
||||
server.instantiate();
|
||||
stop();
|
||||
}
|
||||
|
||||
void stop() {
|
||||
server->stop();
|
||||
_clear_client();
|
||||
}
|
||||
|
||||
Error listen(int p_port, IPAddress p_address, bool p_use_ssl, String p_ssl_key, String p_ssl_cert) {
|
||||
use_ssl = p_use_ssl;
|
||||
if (use_ssl) {
|
||||
Ref<Crypto> crypto = Crypto::create();
|
||||
if (crypto.is_null()) {
|
||||
return ERR_UNAVAILABLE;
|
||||
}
|
||||
if (!p_ssl_key.is_empty() && !p_ssl_cert.is_empty()) {
|
||||
key = Ref<CryptoKey>(CryptoKey::create());
|
||||
Error err = key->load(p_ssl_key);
|
||||
ERR_FAIL_COND_V(err != OK, err);
|
||||
cert = Ref<X509Certificate>(X509Certificate::create());
|
||||
err = cert->load(p_ssl_cert);
|
||||
ERR_FAIL_COND_V(err != OK, err);
|
||||
} else {
|
||||
_set_internal_certs(crypto);
|
||||
}
|
||||
}
|
||||
return server->listen(p_port, p_address);
|
||||
}
|
||||
|
||||
bool is_listening() const {
|
||||
return server->is_listening();
|
||||
}
|
||||
|
||||
void _send_response() {
|
||||
Vector<String> psa = String((char *)req_buf).split("\r\n");
|
||||
int len = psa.size();
|
||||
ERR_FAIL_COND_MSG(len < 4, "Not enough response headers, got: " + itos(len) + ", expected >= 4.");
|
||||
|
||||
Vector<String> req = psa[0].split(" ", false);
|
||||
ERR_FAIL_COND_MSG(req.size() < 2, "Invalid protocol or status code.");
|
||||
|
||||
// Wrong protocol
|
||||
ERR_FAIL_COND_MSG(req[0] != "GET" || req[2] != "HTTP/1.1", "Invalid method or HTTP version.");
|
||||
|
||||
const int query_index = req[1].find_char('?');
|
||||
const String path = (query_index == -1) ? req[1] : req[1].substr(0, query_index);
|
||||
|
||||
const String req_file = path.get_file();
|
||||
const String req_ext = path.get_extension();
|
||||
const String cache_path = EditorPaths::get_singleton()->get_cache_dir().plus_file("web");
|
||||
const String filepath = cache_path.plus_file(req_file);
|
||||
|
||||
if (!mimes.has(req_ext) || !FileAccess::exists(filepath)) {
|
||||
String s = "HTTP/1.1 404 Not Found\r\n";
|
||||
s += "Connection: Close\r\n";
|
||||
s += "\r\n";
|
||||
CharString cs = s.utf8();
|
||||
peer->put_data((const uint8_t *)cs.get_data(), cs.size() - 1);
|
||||
return;
|
||||
}
|
||||
const String ctype = mimes[req_ext];
|
||||
|
||||
FileAccess *f = FileAccess::open(filepath, FileAccess::READ);
|
||||
ERR_FAIL_COND(!f);
|
||||
String s = "HTTP/1.1 200 OK\r\n";
|
||||
s += "Connection: Close\r\n";
|
||||
s += "Content-Type: " + ctype + "\r\n";
|
||||
s += "Access-Control-Allow-Origin: *\r\n";
|
||||
s += "Cross-Origin-Opener-Policy: same-origin\r\n";
|
||||
s += "Cross-Origin-Embedder-Policy: require-corp\r\n";
|
||||
s += "Cache-Control: no-store, max-age=0\r\n";
|
||||
s += "\r\n";
|
||||
CharString cs = s.utf8();
|
||||
Error err = peer->put_data((const uint8_t *)cs.get_data(), cs.size() - 1);
|
||||
if (err != OK) {
|
||||
memdelete(f);
|
||||
ERR_FAIL();
|
||||
}
|
||||
|
||||
while (true) {
|
||||
uint8_t bytes[4096];
|
||||
uint64_t read = f->get_buffer(bytes, 4096);
|
||||
if (read == 0) {
|
||||
break;
|
||||
}
|
||||
err = peer->put_data(bytes, read);
|
||||
if (err != OK) {
|
||||
memdelete(f);
|
||||
ERR_FAIL();
|
||||
}
|
||||
}
|
||||
memdelete(f);
|
||||
}
|
||||
|
||||
void poll() {
|
||||
if (!server->is_listening()) {
|
||||
return;
|
||||
}
|
||||
if (tcp.is_null()) {
|
||||
if (!server->is_connection_available()) {
|
||||
return;
|
||||
}
|
||||
tcp = server->take_connection();
|
||||
peer = tcp;
|
||||
time = OS::get_singleton()->get_ticks_usec();
|
||||
}
|
||||
if (OS::get_singleton()->get_ticks_usec() - time > 1000000) {
|
||||
_clear_client();
|
||||
return;
|
||||
}
|
||||
if (tcp->get_status() != StreamPeerTCP::STATUS_CONNECTED) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (use_ssl) {
|
||||
if (ssl.is_null()) {
|
||||
ssl = Ref<StreamPeerSSL>(StreamPeerSSL::create());
|
||||
peer = ssl;
|
||||
ssl->set_blocking_handshake_enabled(false);
|
||||
if (ssl->accept_stream(tcp, key, cert) != OK) {
|
||||
_clear_client();
|
||||
return;
|
||||
}
|
||||
}
|
||||
ssl->poll();
|
||||
if (ssl->get_status() == StreamPeerSSL::STATUS_HANDSHAKING) {
|
||||
// Still handshaking, keep waiting.
|
||||
return;
|
||||
}
|
||||
if (ssl->get_status() != StreamPeerSSL::STATUS_CONNECTED) {
|
||||
_clear_client();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
char *r = (char *)req_buf;
|
||||
int l = req_pos - 1;
|
||||
if (l > 3 && r[l] == '\n' && r[l - 1] == '\r' && r[l - 2] == '\n' && r[l - 3] == '\r') {
|
||||
_send_response();
|
||||
_clear_client();
|
||||
return;
|
||||
}
|
||||
|
||||
int read = 0;
|
||||
ERR_FAIL_COND(req_pos >= 4096);
|
||||
Error err = peer->get_partial_data(&req_buf[req_pos], 1, read);
|
||||
if (err != OK) {
|
||||
// Got an error
|
||||
_clear_client();
|
||||
return;
|
||||
} else if (read != 1) {
|
||||
// Busy, wait next poll
|
||||
return;
|
||||
}
|
||||
req_pos += read;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class EditorExportPlatformJavaScript : public EditorExportPlatform {
|
||||
GDCLASS(EditorExportPlatformJavaScript, EditorExportPlatform);
|
||||
|
||||
Ref<ImageTexture> logo;
|
||||
Ref<ImageTexture> run_icon;
|
||||
Ref<ImageTexture> stop_icon;
|
||||
int menu_options = 0;
|
||||
|
||||
Ref<EditorHTTPServer> server;
|
||||
bool server_quit = false;
|
||||
Mutex server_lock;
|
||||
Thread server_thread;
|
||||
|
||||
enum ExportMode {
|
||||
EXPORT_MODE_NORMAL = 0,
|
||||
EXPORT_MODE_THREADS = 1,
|
||||
EXPORT_MODE_GDNATIVE = 2,
|
||||
};
|
||||
|
||||
String _get_template_name(ExportMode p_mode, bool p_debug) const {
|
||||
String name = "webassembly";
|
||||
switch (p_mode) {
|
||||
case EXPORT_MODE_THREADS:
|
||||
name += "_threads";
|
||||
break;
|
||||
case EXPORT_MODE_GDNATIVE:
|
||||
name += "_gdnative";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (p_debug) {
|
||||
name += "_debug.zip";
|
||||
} else {
|
||||
name += "_release.zip";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
Ref<Image> _get_project_icon() const {
|
||||
Ref<Image> icon;
|
||||
icon.instantiate();
|
||||
const String icon_path = String(GLOBAL_GET("application/config/icon")).strip_edges();
|
||||
if (icon_path.is_empty() || ImageLoader::load_image(icon_path, icon) != OK) {
|
||||
return EditorNode::get_singleton()->get_editor_theme()->get_icon("DefaultProjectIcon", "EditorIcons")->get_image();
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
Ref<Image> _get_project_splash() const {
|
||||
Ref<Image> splash;
|
||||
splash.instantiate();
|
||||
const String splash_path = String(GLOBAL_GET("application/boot_splash/image")).strip_edges();
|
||||
if (splash_path.is_empty() || ImageLoader::load_image(splash_path, splash) != OK) {
|
||||
return Ref<Image>(memnew(Image(boot_splash_png)));
|
||||
}
|
||||
return splash;
|
||||
}
|
||||
|
||||
Error _extract_template(const String &p_template, const String &p_dir, const String &p_name, bool pwa);
|
||||
void _replace_strings(Map<String, String> p_replaces, Vector<uint8_t> &r_template);
|
||||
void _fix_html(Vector<uint8_t> &p_html, const Ref<EditorExportPreset> &p_preset, const String &p_name, bool p_debug, int p_flags, const Vector<SharedObject> p_shared_objects, const Dictionary &p_file_sizes);
|
||||
Error _add_manifest_icon(const String &p_path, const String &p_icon, int p_size, Array &r_arr);
|
||||
Error _build_pwa(const Ref<EditorExportPreset> &p_preset, const String p_path, const Vector<SharedObject> &p_shared_objects);
|
||||
Error _write_or_error(const uint8_t *p_content, int p_len, String p_path);
|
||||
|
||||
static void _server_thread_poll(void *data);
|
||||
|
||||
public:
|
||||
virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) override;
|
||||
|
||||
virtual void get_export_options(List<ExportOption> *r_options) override;
|
||||
|
||||
virtual String get_name() const override;
|
||||
virtual String get_os_name() const override;
|
||||
virtual Ref<Texture2D> get_logo() const override;
|
||||
|
||||
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
|
||||
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override;
|
||||
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) override;
|
||||
|
||||
virtual bool poll_export() override;
|
||||
virtual int get_options_count() const override;
|
||||
virtual String get_option_label(int p_index) const override { return p_index ? TTR("Stop HTTP Server") : TTR("Run in Browser"); }
|
||||
virtual String get_option_tooltip(int p_index) const override { return p_index ? TTR("Stop HTTP Server") : TTR("Run exported HTML in the system's default browser."); }
|
||||
virtual Ref<ImageTexture> get_option_icon(int p_index) const override;
|
||||
virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_option, int p_debug_flags) override;
|
||||
virtual Ref<Texture2D> get_run_icon() const override;
|
||||
|
||||
virtual void get_platform_features(List<String> *r_features) override {
|
||||
r_features->push_back("web");
|
||||
r_features->push_back(get_os_name());
|
||||
}
|
||||
|
||||
virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) override {
|
||||
}
|
||||
|
||||
String get_debug_protocol() const override { return "ws://"; }
|
||||
|
||||
EditorExportPlatformJavaScript();
|
||||
~EditorExportPlatformJavaScript();
|
||||
};
|
||||
|
||||
Error EditorExportPlatformJavaScript::_extract_template(const String &p_template, const String &p_dir, const String &p_name, bool pwa) {
|
||||
FileAccess *src_f = nullptr;
|
||||
zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
|
||||
unzFile pkg = unzOpen2(p_template.utf8().get_data(), &io);
|
||||
|
||||
if (!pkg) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not open template for export:") + "\n" + p_template);
|
||||
return ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (unzGoToFirstFile(pkg) != UNZ_OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Invalid export template:") + "\n" + p_template);
|
||||
unzClose(pkg);
|
||||
return ERR_FILE_CORRUPT;
|
||||
}
|
||||
|
||||
do {
|
||||
//get filename
|
||||
unz_file_info info;
|
||||
char fname[16384];
|
||||
unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 0);
|
||||
|
||||
String file = fname;
|
||||
|
||||
// Skip service worker and offline page if not exporting pwa.
|
||||
if (!pwa && (file == "godot.service.worker.js" || file == "godot.offline.html")) {
|
||||
continue;
|
||||
}
|
||||
Vector<uint8_t> data;
|
||||
data.resize(info.uncompressed_size);
|
||||
|
||||
//read
|
||||
unzOpenCurrentFile(pkg);
|
||||
unzReadCurrentFile(pkg, data.ptrw(), data.size());
|
||||
unzCloseCurrentFile(pkg);
|
||||
|
||||
//write
|
||||
String dst = p_dir.plus_file(file.replace("godot", p_name));
|
||||
FileAccess *f = FileAccess::open(dst, FileAccess::WRITE);
|
||||
if (!f) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + dst);
|
||||
unzClose(pkg);
|
||||
return ERR_FILE_CANT_WRITE;
|
||||
}
|
||||
f->store_buffer(data.ptr(), data.size());
|
||||
memdelete(f);
|
||||
|
||||
} while (unzGoToNextFile(pkg) == UNZ_OK);
|
||||
unzClose(pkg);
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error EditorExportPlatformJavaScript::_write_or_error(const uint8_t *p_content, int p_size, String p_path) {
|
||||
FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE);
|
||||
if (!f) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + p_path);
|
||||
return ERR_FILE_CANT_WRITE;
|
||||
}
|
||||
f->store_buffer(p_content, p_size);
|
||||
memdelete(f);
|
||||
return OK;
|
||||
}
|
||||
|
||||
void EditorExportPlatformJavaScript::_replace_strings(Map<String, String> p_replaces, Vector<uint8_t> &r_template) {
|
||||
String str_template = String::utf8(reinterpret_cast<const char *>(r_template.ptr()), r_template.size());
|
||||
String out;
|
||||
Vector<String> lines = str_template.split("\n");
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
String current_line = lines[i];
|
||||
for (Map<String, String>::Element *E = p_replaces.front(); E; E = E->next()) {
|
||||
current_line = current_line.replace(E->key(), E->get());
|
||||
}
|
||||
out += current_line + "\n";
|
||||
}
|
||||
CharString cs = out.utf8();
|
||||
r_template.resize(cs.length());
|
||||
for (int i = 0; i < cs.length(); i++) {
|
||||
r_template.write[i] = cs[i];
|
||||
}
|
||||
}
|
||||
|
||||
void EditorExportPlatformJavaScript::_fix_html(Vector<uint8_t> &p_html, const Ref<EditorExportPreset> &p_preset, const String &p_name, bool p_debug, int p_flags, const Vector<SharedObject> p_shared_objects, const Dictionary &p_file_sizes) {
|
||||
// Engine.js config
|
||||
Dictionary config;
|
||||
Array libs;
|
||||
for (int i = 0; i < p_shared_objects.size(); i++) {
|
||||
libs.push_back(p_shared_objects[i].path.get_file());
|
||||
}
|
||||
Vector<String> flags;
|
||||
gen_export_flags(flags, p_flags & (~DEBUG_FLAG_DUMB_CLIENT));
|
||||
Array args;
|
||||
for (int i = 0; i < flags.size(); i++) {
|
||||
args.push_back(flags[i]);
|
||||
}
|
||||
config["canvasResizePolicy"] = p_preset->get("html/canvas_resize_policy");
|
||||
config["experimentalVK"] = p_preset->get("html/experimental_virtual_keyboard");
|
||||
config["focusCanvas"] = p_preset->get("html/focus_canvas_on_start");
|
||||
config["gdnativeLibs"] = libs;
|
||||
config["executable"] = p_name;
|
||||
config["args"] = args;
|
||||
config["fileSizes"] = p_file_sizes;
|
||||
|
||||
String head_include;
|
||||
if (p_preset->get("html/export_icon")) {
|
||||
head_include += "<link id='-gd-engine-icon' rel='icon' type='image/png' href='" + p_name + ".icon.png' />\n";
|
||||
head_include += "<link rel='apple-touch-icon' href='" + p_name + ".apple-touch-icon.png'/>\n";
|
||||
}
|
||||
if (p_preset->get("progressive_web_app/enabled")) {
|
||||
head_include += "<link rel='manifest' href='" + p_name + ".manifest.json'>\n";
|
||||
head_include += "<script type='application/javascript'>window.addEventListener('load', () => {if ('serviceWorker' in navigator) {navigator.serviceWorker.register('" +
|
||||
p_name + ".service.worker.js');}});</script>\n";
|
||||
}
|
||||
|
||||
// Replaces HTML string
|
||||
const String str_config = Variant(config).to_json_string();
|
||||
const String custom_head_include = p_preset->get("html/head_include");
|
||||
Map<String, String> replaces;
|
||||
replaces["$GODOT_URL"] = p_name + ".js";
|
||||
replaces["$GODOT_PROJECT_NAME"] = ProjectSettings::get_singleton()->get_setting("application/config/name");
|
||||
replaces["$GODOT_HEAD_INCLUDE"] = head_include + custom_head_include;
|
||||
replaces["$GODOT_CONFIG"] = str_config;
|
||||
_replace_strings(replaces, p_html);
|
||||
}
|
||||
|
||||
Error EditorExportPlatformJavaScript::_add_manifest_icon(const String &p_path, const String &p_icon, int p_size, Array &r_arr) {
|
||||
const String name = p_path.get_file().get_basename();
|
||||
const String icon_name = vformat("%s.%dx%d.png", name, p_size, p_size);
|
||||
const String icon_dest = p_path.get_base_dir().plus_file(icon_name);
|
||||
|
||||
Ref<Image> icon;
|
||||
if (!p_icon.is_empty()) {
|
||||
icon.instantiate();
|
||||
const Error err = ImageLoader::load_image(p_icon, icon);
|
||||
if (err != OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not read file:") + "\n" + p_icon);
|
||||
return err;
|
||||
}
|
||||
if (icon->get_width() != p_size || icon->get_height() != p_size) {
|
||||
icon->resize(p_size, p_size);
|
||||
}
|
||||
} else {
|
||||
icon = _get_project_icon();
|
||||
icon->resize(p_size, p_size);
|
||||
}
|
||||
const Error err = icon->save_png(icon_dest);
|
||||
if (err != OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + icon_dest);
|
||||
return err;
|
||||
}
|
||||
Dictionary icon_dict;
|
||||
icon_dict["sizes"] = vformat("%dx%d", p_size, p_size);
|
||||
icon_dict["type"] = "image/png";
|
||||
icon_dict["src"] = icon_name;
|
||||
r_arr.push_back(icon_dict);
|
||||
return err;
|
||||
}
|
||||
|
||||
Error EditorExportPlatformJavaScript::_build_pwa(const Ref<EditorExportPreset> &p_preset, const String p_path, const Vector<SharedObject> &p_shared_objects) {
|
||||
// Service worker
|
||||
const String dir = p_path.get_base_dir();
|
||||
const String name = p_path.get_file().get_basename();
|
||||
const ExportMode mode = (ExportMode)(int)p_preset->get("variant/export_type");
|
||||
Map<String, String> replaces;
|
||||
replaces["@GODOT_VERSION@"] = "1";
|
||||
replaces["@GODOT_NAME@"] = name;
|
||||
replaces["@GODOT_OFFLINE_PAGE@"] = name + ".offline.html";
|
||||
Array files;
|
||||
replaces["@GODOT_OPT_CACHE@"] = Variant(files).to_json_string();
|
||||
files.push_back(name + ".html");
|
||||
files.push_back(name + ".js");
|
||||
files.push_back(name + ".wasm");
|
||||
files.push_back(name + ".pck");
|
||||
files.push_back(name + ".offline.html");
|
||||
if (p_preset->get("html/export_icon")) {
|
||||
files.push_back(name + ".icon.png");
|
||||
files.push_back(name + ".apple-touch-icon.png");
|
||||
}
|
||||
if (mode == EXPORT_MODE_THREADS) {
|
||||
files.push_back(name + ".worker.js");
|
||||
files.push_back(name + ".audio.worklet.js");
|
||||
} else if (mode == EXPORT_MODE_GDNATIVE) {
|
||||
files.push_back(name + ".side.wasm");
|
||||
for (int i = 0; i < p_shared_objects.size(); i++) {
|
||||
files.push_back(p_shared_objects[i].path.get_file());
|
||||
}
|
||||
}
|
||||
replaces["@GODOT_CACHE@"] = Variant(files).to_json_string();
|
||||
|
||||
const String sw_path = dir.plus_file(name + ".service.worker.js");
|
||||
Vector<uint8_t> sw;
|
||||
{
|
||||
FileAccess *f = FileAccess::open(sw_path, FileAccess::READ);
|
||||
if (!f) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not read file:") + "\n" + sw_path);
|
||||
return ERR_FILE_CANT_READ;
|
||||
}
|
||||
sw.resize(f->get_length());
|
||||
f->get_buffer(sw.ptrw(), sw.size());
|
||||
memdelete(f);
|
||||
f = nullptr;
|
||||
}
|
||||
_replace_strings(replaces, sw);
|
||||
Error err = _write_or_error(sw.ptr(), sw.size(), dir.plus_file(name + ".service.worker.js"));
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// Custom offline page
|
||||
const String offline_page = p_preset->get("progressive_web_app/offline_page");
|
||||
if (!offline_page.is_empty()) {
|
||||
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||
const String offline_dest = dir.plus_file(name + ".offline.html");
|
||||
err = da->copy(ProjectSettings::get_singleton()->globalize_path(offline_page), offline_dest);
|
||||
if (err != OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not read file:") + "\n" + offline_dest);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
// Manifest
|
||||
const char *modes[4] = { "fullscreen", "standalone", "minimal-ui", "browser" };
|
||||
const char *orientations[3] = { "any", "landscape", "portrait" };
|
||||
const int display = CLAMP(int(p_preset->get("progressive_web_app/display")), 0, 4);
|
||||
const int orientation = CLAMP(int(p_preset->get("progressive_web_app/orientation")), 0, 3);
|
||||
|
||||
Dictionary manifest;
|
||||
String proj_name = ProjectSettings::get_singleton()->get_setting("application/config/name");
|
||||
if (proj_name.is_empty()) {
|
||||
proj_name = "Godot Game";
|
||||
}
|
||||
manifest["name"] = proj_name;
|
||||
manifest["start_url"] = "./" + name + ".html";
|
||||
manifest["display"] = String::utf8(modes[display]);
|
||||
manifest["orientation"] = String::utf8(orientations[orientation]);
|
||||
manifest["background_color"] = "#" + p_preset->get("progressive_web_app/background_color").operator Color().to_html(false);
|
||||
|
||||
Array icons_arr;
|
||||
const String icon144_path = p_preset->get("progressive_web_app/icon_144x144");
|
||||
err = _add_manifest_icon(p_path, icon144_path, 144, icons_arr);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
const String icon180_path = p_preset->get("progressive_web_app/icon_180x180");
|
||||
err = _add_manifest_icon(p_path, icon180_path, 180, icons_arr);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
const String icon512_path = p_preset->get("progressive_web_app/icon_512x512");
|
||||
err = _add_manifest_icon(p_path, icon512_path, 512, icons_arr);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
manifest["icons"] = icons_arr;
|
||||
|
||||
CharString cs = Variant(manifest).to_json_string().utf8();
|
||||
err = _write_or_error((const uint8_t *)cs.get_data(), cs.length(), dir.plus_file(name + ".manifest.json"));
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void EditorExportPlatformJavaScript::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) {
|
||||
if (p_preset->get("vram_texture_compression/for_desktop")) {
|
||||
r_features->push_back("s3tc");
|
||||
}
|
||||
|
||||
if (p_preset->get("vram_texture_compression/for_mobile")) {
|
||||
String driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name");
|
||||
if (driver == "GLES2") {
|
||||
r_features->push_back("etc");
|
||||
} else if (driver == "Vulkan") {
|
||||
// FIXME: Review if this is correct.
|
||||
r_features->push_back("etc2");
|
||||
}
|
||||
}
|
||||
ExportMode mode = (ExportMode)(int)p_preset->get("variant/export_type");
|
||||
if (mode == EXPORT_MODE_THREADS) {
|
||||
r_features->push_back("threads");
|
||||
} else if (mode == EXPORT_MODE_GDNATIVE) {
|
||||
r_features->push_back("wasm32");
|
||||
}
|
||||
}
|
||||
|
||||
void EditorExportPlatformJavaScript::get_export_options(List<ExportOption> *r_options) {
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
|
||||
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "variant/export_type", PROPERTY_HINT_ENUM, "Regular,Threads,GDNative"), 0)); // Export type.
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "vram_texture_compression/for_desktop"), true)); // S3TC
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "vram_texture_compression/for_mobile"), false)); // ETC or ETC2, depending on renderer
|
||||
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "html/export_icon"), true));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "html/custom_html_shell", PROPERTY_HINT_FILE, "*.html"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "html/head_include", PROPERTY_HINT_MULTILINE_TEXT), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "html/canvas_resize_policy", PROPERTY_HINT_ENUM, "None,Project,Adaptive"), 2));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "html/focus_canvas_on_start"), true));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "html/experimental_virtual_keyboard"), false));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "progressive_web_app/enabled"), false));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "progressive_web_app/offline_page", PROPERTY_HINT_FILE, "*.html"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "progressive_web_app/display", PROPERTY_HINT_ENUM, "Fullscreen,Standalone,Minimal UI,Browser"), 1));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "progressive_web_app/orientation", PROPERTY_HINT_ENUM, "Any,Landscape,Portrait"), 0));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "progressive_web_app/icon_144x144", PROPERTY_HINT_FILE, "*.png,*.webp,*.svg,*.svgz"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "progressive_web_app/icon_180x180", PROPERTY_HINT_FILE, "*.png,*.webp,*.svg,*.svgz"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "progressive_web_app/icon_512x512", PROPERTY_HINT_FILE, "*.png,*.webp,*.svg,*.svgz"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::COLOR, "progressive_web_app/background_color", PROPERTY_HINT_COLOR_NO_ALPHA), Color()));
|
||||
}
|
||||
|
||||
String EditorExportPlatformJavaScript::get_name() const {
|
||||
return "HTML5";
|
||||
}
|
||||
|
||||
String EditorExportPlatformJavaScript::get_os_name() const {
|
||||
return "HTML5";
|
||||
}
|
||||
|
||||
Ref<Texture2D> EditorExportPlatformJavaScript::get_logo() const {
|
||||
return logo;
|
||||
}
|
||||
|
||||
bool EditorExportPlatformJavaScript::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
|
||||
String err;
|
||||
bool valid = false;
|
||||
ExportMode mode = (ExportMode)(int)p_preset->get("variant/export_type");
|
||||
|
||||
// Look for export templates (first official, and if defined custom templates).
|
||||
bool dvalid = exists_export_template(_get_template_name(mode, true), &err);
|
||||
bool rvalid = exists_export_template(_get_template_name(mode, false), &err);
|
||||
|
||||
if (p_preset->get("custom_template/debug") != "") {
|
||||
dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
|
||||
if (!dvalid) {
|
||||
err += TTR("Custom debug template not found.") + "\n";
|
||||
}
|
||||
}
|
||||
if (p_preset->get("custom_template/release") != "") {
|
||||
rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
|
||||
if (!rvalid) {
|
||||
err += TTR("Custom release template not found.") + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
valid = dvalid || rvalid;
|
||||
r_missing_templates = !valid;
|
||||
|
||||
// Validate the rest of the configuration.
|
||||
|
||||
if (p_preset->get("vram_texture_compression/for_mobile")) {
|
||||
String etc_error = test_etc2();
|
||||
if (etc_error != String()) {
|
||||
valid = false;
|
||||
err += etc_error;
|
||||
}
|
||||
}
|
||||
|
||||
if (!err.is_empty()) {
|
||||
r_error = err;
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
List<String> EditorExportPlatformJavaScript::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
|
||||
List<String> list;
|
||||
list.push_back("html");
|
||||
return list;
|
||||
}
|
||||
|
||||
Error EditorExportPlatformJavaScript::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
|
||||
ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
|
||||
|
||||
const String custom_debug = p_preset->get("custom_template/debug");
|
||||
const String custom_release = p_preset->get("custom_template/release");
|
||||
const String custom_html = p_preset->get("html/custom_html_shell");
|
||||
const bool export_icon = p_preset->get("html/export_icon");
|
||||
const bool pwa = p_preset->get("progressive_web_app/enabled");
|
||||
|
||||
const String base_dir = p_path.get_base_dir();
|
||||
const String base_path = p_path.get_basename();
|
||||
const String base_name = p_path.get_file().get_basename();
|
||||
|
||||
// Find the correct template
|
||||
String template_path = p_debug ? custom_debug : custom_release;
|
||||
template_path = template_path.strip_edges();
|
||||
if (template_path == String()) {
|
||||
ExportMode mode = (ExportMode)(int)p_preset->get("variant/export_type");
|
||||
template_path = find_export_template(_get_template_name(mode, p_debug));
|
||||
}
|
||||
|
||||
if (!DirAccess::exists(base_dir)) {
|
||||
return ERR_FILE_BAD_PATH;
|
||||
}
|
||||
|
||||
if (template_path != String() && !FileAccess::exists(template_path)) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Template file not found:") + "\n" + template_path);
|
||||
return ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
// Export pck and shared objects
|
||||
Vector<SharedObject> shared_objects;
|
||||
String pck_path = base_path + ".pck";
|
||||
Error error = save_pack(p_preset, pck_path, &shared_objects);
|
||||
if (error != OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + pck_path);
|
||||
return error;
|
||||
}
|
||||
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||
for (int i = 0; i < shared_objects.size(); i++) {
|
||||
String dst = base_dir.plus_file(shared_objects[i].path.get_file());
|
||||
error = da->copy(shared_objects[i].path, dst);
|
||||
if (error != OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + shared_objects[i].path.get_file());
|
||||
memdelete(da);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
memdelete(da);
|
||||
da = nullptr;
|
||||
|
||||
// Extract templates.
|
||||
error = _extract_template(template_path, base_dir, base_name, pwa);
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
|
||||
// Parse generated file sizes (pck and wasm, to help show a meaningful loading bar).
|
||||
Dictionary file_sizes;
|
||||
FileAccess *f = nullptr;
|
||||
f = FileAccess::open(pck_path, FileAccess::READ);
|
||||
if (f) {
|
||||
file_sizes[pck_path.get_file()] = (uint64_t)f->get_length();
|
||||
memdelete(f);
|
||||
f = nullptr;
|
||||
}
|
||||
f = FileAccess::open(base_path + ".wasm", FileAccess::READ);
|
||||
if (f) {
|
||||
file_sizes[base_name + ".wasm"] = (uint64_t)f->get_length();
|
||||
memdelete(f);
|
||||
f = nullptr;
|
||||
}
|
||||
|
||||
// Read the HTML shell file (custom or from template).
|
||||
const String html_path = custom_html.is_empty() ? base_path + ".html" : custom_html;
|
||||
Vector<uint8_t> html;
|
||||
f = FileAccess::open(html_path, FileAccess::READ);
|
||||
if (!f) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not read HTML shell:") + "\n" + html_path);
|
||||
return ERR_FILE_CANT_READ;
|
||||
}
|
||||
html.resize(f->get_length());
|
||||
f->get_buffer(html.ptrw(), html.size());
|
||||
memdelete(f);
|
||||
f = nullptr;
|
||||
|
||||
// Generate HTML file with replaced strings.
|
||||
_fix_html(html, p_preset, base_name, p_debug, p_flags, shared_objects, file_sizes);
|
||||
Error err = _write_or_error(html.ptr(), html.size(), p_path);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
html.resize(0);
|
||||
|
||||
// Export splash (why?)
|
||||
Ref<Image> splash = _get_project_splash();
|
||||
const String splash_png_path = base_path + ".png";
|
||||
if (splash->save_png(splash_png_path) != OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + splash_png_path);
|
||||
return ERR_FILE_CANT_WRITE;
|
||||
}
|
||||
|
||||
// Save a favicon that can be accessed without waiting for the project to finish loading.
|
||||
// This way, the favicon can be displayed immediately when loading the page.
|
||||
if (export_icon) {
|
||||
Ref<Image> favicon = _get_project_icon();
|
||||
const String favicon_png_path = base_path + ".icon.png";
|
||||
if (favicon->save_png(favicon_png_path) != OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + favicon_png_path);
|
||||
return ERR_FILE_CANT_WRITE;
|
||||
}
|
||||
favicon->resize(180, 180);
|
||||
const String apple_icon_png_path = base_path + ".apple-touch-icon.png";
|
||||
if (favicon->save_png(apple_icon_png_path) != OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + apple_icon_png_path);
|
||||
return ERR_FILE_CANT_WRITE;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate the PWA worker and manifest
|
||||
if (pwa) {
|
||||
err = _build_pwa(p_preset, p_path, shared_objects);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
bool EditorExportPlatformJavaScript::poll_export() {
|
||||
Ref<EditorExportPreset> preset;
|
||||
|
||||
for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
|
||||
Ref<EditorExportPreset> ep = EditorExport::get_singleton()->get_export_preset(i);
|
||||
if (ep->is_runnable() && ep->get_platform() == this) {
|
||||
preset = ep;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int prev = menu_options;
|
||||
menu_options = preset.is_valid();
|
||||
if (server->is_listening()) {
|
||||
if (menu_options == 0) {
|
||||
MutexLock lock(server_lock);
|
||||
server->stop();
|
||||
} else {
|
||||
menu_options += 1;
|
||||
}
|
||||
}
|
||||
return menu_options != prev;
|
||||
}
|
||||
|
||||
Ref<ImageTexture> EditorExportPlatformJavaScript::get_option_icon(int p_index) const {
|
||||
return p_index == 1 ? stop_icon : EditorExportPlatform::get_option_icon(p_index);
|
||||
}
|
||||
|
||||
int EditorExportPlatformJavaScript::get_options_count() const {
|
||||
return menu_options;
|
||||
}
|
||||
|
||||
Error EditorExportPlatformJavaScript::run(const Ref<EditorExportPreset> &p_preset, int p_option, int p_debug_flags) {
|
||||
if (p_option == 1) {
|
||||
MutexLock lock(server_lock);
|
||||
server->stop();
|
||||
return OK;
|
||||
}
|
||||
|
||||
const String dest = EditorPaths::get_singleton()->get_cache_dir().plus_file("web");
|
||||
DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||
if (!da->dir_exists(dest)) {
|
||||
Error err = da->make_dir_recursive(dest);
|
||||
if (err != OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not create HTTP server directory:") + "\n" + dest);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
const String basepath = dest.plus_file("tmp_js_export");
|
||||
Error err = export_project(p_preset, true, basepath + ".html", p_debug_flags);
|
||||
if (err != OK) {
|
||||
// Export generates several files, clean them up on failure.
|
||||
DirAccess::remove_file_or_error(basepath + ".html");
|
||||
DirAccess::remove_file_or_error(basepath + ".offline.html");
|
||||
DirAccess::remove_file_or_error(basepath + ".js");
|
||||
DirAccess::remove_file_or_error(basepath + ".worker.js");
|
||||
DirAccess::remove_file_or_error(basepath + ".audio.worklet.js");
|
||||
DirAccess::remove_file_or_error(basepath + ".service.worker.js");
|
||||
DirAccess::remove_file_or_error(basepath + ".pck");
|
||||
DirAccess::remove_file_or_error(basepath + ".png");
|
||||
DirAccess::remove_file_or_error(basepath + ".side.wasm");
|
||||
DirAccess::remove_file_or_error(basepath + ".wasm");
|
||||
DirAccess::remove_file_or_error(basepath + ".icon.png");
|
||||
DirAccess::remove_file_or_error(basepath + ".apple-touch-icon.png");
|
||||
return err;
|
||||
}
|
||||
|
||||
const uint16_t bind_port = EDITOR_GET("export/web/http_port");
|
||||
// Resolve host if needed.
|
||||
const String bind_host = EDITOR_GET("export/web/http_host");
|
||||
IPAddress bind_ip;
|
||||
if (bind_host.is_valid_ip_address()) {
|
||||
bind_ip = bind_host;
|
||||
} else {
|
||||
bind_ip = IP::get_singleton()->resolve_hostname(bind_host);
|
||||
}
|
||||
ERR_FAIL_COND_V_MSG(!bind_ip.is_valid(), ERR_INVALID_PARAMETER, "Invalid editor setting 'export/web/http_host': '" + bind_host + "'. Try using '127.0.0.1'.");
|
||||
|
||||
const bool use_ssl = EDITOR_GET("export/web/use_ssl");
|
||||
const String ssl_key = EDITOR_GET("export/web/ssl_key");
|
||||
const String ssl_cert = EDITOR_GET("export/web/ssl_certificate");
|
||||
|
||||
// Restart server.
|
||||
{
|
||||
MutexLock lock(server_lock);
|
||||
|
||||
server->stop();
|
||||
err = server->listen(bind_port, bind_ip, use_ssl, ssl_key, ssl_cert);
|
||||
}
|
||||
if (err != OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Error starting HTTP server:") + "\n" + itos(err));
|
||||
return err;
|
||||
}
|
||||
|
||||
OS::get_singleton()->shell_open(String((use_ssl ? "https://" : "http://") + bind_host + ":" + itos(bind_port) + "/tmp_js_export.html"));
|
||||
// FIXME: Find out how to clean up export files after running the successfully
|
||||
// exported game. Might not be trivial.
|
||||
return OK;
|
||||
}
|
||||
|
||||
Ref<Texture2D> EditorExportPlatformJavaScript::get_run_icon() const {
|
||||
return run_icon;
|
||||
}
|
||||
|
||||
void EditorExportPlatformJavaScript::_server_thread_poll(void *data) {
|
||||
EditorExportPlatformJavaScript *ej = (EditorExportPlatformJavaScript *)data;
|
||||
while (!ej->server_quit) {
|
||||
OS::get_singleton()->delay_usec(1000);
|
||||
{
|
||||
MutexLock lock(ej->server_lock);
|
||||
ej->server->poll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EditorExportPlatformJavaScript::EditorExportPlatformJavaScript() {
|
||||
server.instantiate();
|
||||
server_thread.start(_server_thread_poll, this);
|
||||
|
||||
Ref<Image> img = memnew(Image(_javascript_logo));
|
||||
logo.instantiate();
|
||||
logo->create_from_image(img);
|
||||
|
||||
img = Ref<Image>(memnew(Image(_javascript_run_icon)));
|
||||
run_icon.instantiate();
|
||||
run_icon->create_from_image(img);
|
||||
|
||||
Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
|
||||
if (theme.is_valid()) {
|
||||
stop_icon = theme->get_icon("Stop", "EditorIcons");
|
||||
} else {
|
||||
stop_icon.instantiate();
|
||||
}
|
||||
}
|
||||
|
||||
EditorExportPlatformJavaScript::~EditorExportPlatformJavaScript() {
|
||||
server->stop();
|
||||
server_quit = true;
|
||||
server_thread.wait_to_finish();
|
||||
}
|
||||
#include "export_plugin.h"
|
||||
|
||||
void register_javascript_exporter() {
|
||||
EDITOR_DEF("export/web/http_host", "localhost");
|
||||
|
@ -28,4 +28,9 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef JAVASCRIPT_EXPORT_H
|
||||
#define JAVASCRIPT_EXPORT_H
|
||||
|
||||
void register_javascript_exporter();
|
||||
|
||||
#endif
|
||||
|
671
platform/javascript/export/export_plugin.cpp
Normal file
671
platform/javascript/export/export_plugin.cpp
Normal file
@ -0,0 +1,671 @@
|
||||
/*************************************************************************/
|
||||
/* export_plugin.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "export_plugin.h"
|
||||
|
||||
Error EditorExportPlatformJavaScript::_extract_template(const String &p_template, const String &p_dir, const String &p_name, bool pwa) {
|
||||
FileAccess *src_f = nullptr;
|
||||
zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
|
||||
unzFile pkg = unzOpen2(p_template.utf8().get_data(), &io);
|
||||
|
||||
if (!pkg) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not open template for export:") + "\n" + p_template);
|
||||
return ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (unzGoToFirstFile(pkg) != UNZ_OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Invalid export template:") + "\n" + p_template);
|
||||
unzClose(pkg);
|
||||
return ERR_FILE_CORRUPT;
|
||||
}
|
||||
|
||||
do {
|
||||
//get filename
|
||||
unz_file_info info;
|
||||
char fname[16384];
|
||||
unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 0);
|
||||
|
||||
String file = fname;
|
||||
|
||||
// Skip service worker and offline page if not exporting pwa.
|
||||
if (!pwa && (file == "godot.service.worker.js" || file == "godot.offline.html")) {
|
||||
continue;
|
||||
}
|
||||
Vector<uint8_t> data;
|
||||
data.resize(info.uncompressed_size);
|
||||
|
||||
//read
|
||||
unzOpenCurrentFile(pkg);
|
||||
unzReadCurrentFile(pkg, data.ptrw(), data.size());
|
||||
unzCloseCurrentFile(pkg);
|
||||
|
||||
//write
|
||||
String dst = p_dir.plus_file(file.replace("godot", p_name));
|
||||
FileAccess *f = FileAccess::open(dst, FileAccess::WRITE);
|
||||
if (!f) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + dst);
|
||||
unzClose(pkg);
|
||||
return ERR_FILE_CANT_WRITE;
|
||||
}
|
||||
f->store_buffer(data.ptr(), data.size());
|
||||
memdelete(f);
|
||||
|
||||
} while (unzGoToNextFile(pkg) == UNZ_OK);
|
||||
unzClose(pkg);
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error EditorExportPlatformJavaScript::_write_or_error(const uint8_t *p_content, int p_size, String p_path) {
|
||||
FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE);
|
||||
if (!f) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + p_path);
|
||||
return ERR_FILE_CANT_WRITE;
|
||||
}
|
||||
f->store_buffer(p_content, p_size);
|
||||
memdelete(f);
|
||||
return OK;
|
||||
}
|
||||
|
||||
void EditorExportPlatformJavaScript::_replace_strings(Map<String, String> p_replaces, Vector<uint8_t> &r_template) {
|
||||
String str_template = String::utf8(reinterpret_cast<const char *>(r_template.ptr()), r_template.size());
|
||||
String out;
|
||||
Vector<String> lines = str_template.split("\n");
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
String current_line = lines[i];
|
||||
for (Map<String, String>::Element *E = p_replaces.front(); E; E = E->next()) {
|
||||
current_line = current_line.replace(E->key(), E->get());
|
||||
}
|
||||
out += current_line + "\n";
|
||||
}
|
||||
CharString cs = out.utf8();
|
||||
r_template.resize(cs.length());
|
||||
for (int i = 0; i < cs.length(); i++) {
|
||||
r_template.write[i] = cs[i];
|
||||
}
|
||||
}
|
||||
|
||||
void EditorExportPlatformJavaScript::_fix_html(Vector<uint8_t> &p_html, const Ref<EditorExportPreset> &p_preset, const String &p_name, bool p_debug, int p_flags, const Vector<SharedObject> p_shared_objects, const Dictionary &p_file_sizes) {
|
||||
// Engine.js config
|
||||
Dictionary config;
|
||||
Array libs;
|
||||
for (int i = 0; i < p_shared_objects.size(); i++) {
|
||||
libs.push_back(p_shared_objects[i].path.get_file());
|
||||
}
|
||||
Vector<String> flags;
|
||||
gen_export_flags(flags, p_flags & (~DEBUG_FLAG_DUMB_CLIENT));
|
||||
Array args;
|
||||
for (int i = 0; i < flags.size(); i++) {
|
||||
args.push_back(flags[i]);
|
||||
}
|
||||
config["canvasResizePolicy"] = p_preset->get("html/canvas_resize_policy");
|
||||
config["experimentalVK"] = p_preset->get("html/experimental_virtual_keyboard");
|
||||
config["focusCanvas"] = p_preset->get("html/focus_canvas_on_start");
|
||||
config["gdnativeLibs"] = libs;
|
||||
config["executable"] = p_name;
|
||||
config["args"] = args;
|
||||
config["fileSizes"] = p_file_sizes;
|
||||
|
||||
String head_include;
|
||||
if (p_preset->get("html/export_icon")) {
|
||||
head_include += "<link id='-gd-engine-icon' rel='icon' type='image/png' href='" + p_name + ".icon.png' />\n";
|
||||
head_include += "<link rel='apple-touch-icon' href='" + p_name + ".apple-touch-icon.png'/>\n";
|
||||
}
|
||||
if (p_preset->get("progressive_web_app/enabled")) {
|
||||
head_include += "<link rel='manifest' href='" + p_name + ".manifest.json'>\n";
|
||||
head_include += "<script type='application/javascript'>window.addEventListener('load', () => {if ('serviceWorker' in navigator) {navigator.serviceWorker.register('" +
|
||||
p_name + ".service.worker.js');}});</script>\n";
|
||||
}
|
||||
|
||||
// Replaces HTML string
|
||||
const String str_config = Variant(config).to_json_string();
|
||||
const String custom_head_include = p_preset->get("html/head_include");
|
||||
Map<String, String> replaces;
|
||||
replaces["$GODOT_URL"] = p_name + ".js";
|
||||
replaces["$GODOT_PROJECT_NAME"] = ProjectSettings::get_singleton()->get_setting("application/config/name");
|
||||
replaces["$GODOT_HEAD_INCLUDE"] = head_include + custom_head_include;
|
||||
replaces["$GODOT_CONFIG"] = str_config;
|
||||
_replace_strings(replaces, p_html);
|
||||
}
|
||||
|
||||
Error EditorExportPlatformJavaScript::_add_manifest_icon(const String &p_path, const String &p_icon, int p_size, Array &r_arr) {
|
||||
const String name = p_path.get_file().get_basename();
|
||||
const String icon_name = vformat("%s.%dx%d.png", name, p_size, p_size);
|
||||
const String icon_dest = p_path.get_base_dir().plus_file(icon_name);
|
||||
|
||||
Ref<Image> icon;
|
||||
if (!p_icon.is_empty()) {
|
||||
icon.instantiate();
|
||||
const Error err = ImageLoader::load_image(p_icon, icon);
|
||||
if (err != OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not read file:") + "\n" + p_icon);
|
||||
return err;
|
||||
}
|
||||
if (icon->get_width() != p_size || icon->get_height() != p_size) {
|
||||
icon->resize(p_size, p_size);
|
||||
}
|
||||
} else {
|
||||
icon = _get_project_icon();
|
||||
icon->resize(p_size, p_size);
|
||||
}
|
||||
const Error err = icon->save_png(icon_dest);
|
||||
if (err != OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + icon_dest);
|
||||
return err;
|
||||
}
|
||||
Dictionary icon_dict;
|
||||
icon_dict["sizes"] = vformat("%dx%d", p_size, p_size);
|
||||
icon_dict["type"] = "image/png";
|
||||
icon_dict["src"] = icon_name;
|
||||
r_arr.push_back(icon_dict);
|
||||
return err;
|
||||
}
|
||||
|
||||
Error EditorExportPlatformJavaScript::_build_pwa(const Ref<EditorExportPreset> &p_preset, const String p_path, const Vector<SharedObject> &p_shared_objects) {
|
||||
// Service worker
|
||||
const String dir = p_path.get_base_dir();
|
||||
const String name = p_path.get_file().get_basename();
|
||||
const ExportMode mode = (ExportMode)(int)p_preset->get("variant/export_type");
|
||||
Map<String, String> replaces;
|
||||
replaces["@GODOT_VERSION@"] = "1";
|
||||
replaces["@GODOT_NAME@"] = name;
|
||||
replaces["@GODOT_OFFLINE_PAGE@"] = name + ".offline.html";
|
||||
Array files;
|
||||
replaces["@GODOT_OPT_CACHE@"] = Variant(files).to_json_string();
|
||||
files.push_back(name + ".html");
|
||||
files.push_back(name + ".js");
|
||||
files.push_back(name + ".wasm");
|
||||
files.push_back(name + ".pck");
|
||||
files.push_back(name + ".offline.html");
|
||||
if (p_preset->get("html/export_icon")) {
|
||||
files.push_back(name + ".icon.png");
|
||||
files.push_back(name + ".apple-touch-icon.png");
|
||||
}
|
||||
if (mode == EXPORT_MODE_THREADS) {
|
||||
files.push_back(name + ".worker.js");
|
||||
files.push_back(name + ".audio.worklet.js");
|
||||
} else if (mode == EXPORT_MODE_GDNATIVE) {
|
||||
files.push_back(name + ".side.wasm");
|
||||
for (int i = 0; i < p_shared_objects.size(); i++) {
|
||||
files.push_back(p_shared_objects[i].path.get_file());
|
||||
}
|
||||
}
|
||||
replaces["@GODOT_CACHE@"] = Variant(files).to_json_string();
|
||||
|
||||
const String sw_path = dir.plus_file(name + ".service.worker.js");
|
||||
Vector<uint8_t> sw;
|
||||
{
|
||||
FileAccess *f = FileAccess::open(sw_path, FileAccess::READ);
|
||||
if (!f) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not read file:") + "\n" + sw_path);
|
||||
return ERR_FILE_CANT_READ;
|
||||
}
|
||||
sw.resize(f->get_length());
|
||||
f->get_buffer(sw.ptrw(), sw.size());
|
||||
memdelete(f);
|
||||
f = nullptr;
|
||||
}
|
||||
_replace_strings(replaces, sw);
|
||||
Error err = _write_or_error(sw.ptr(), sw.size(), dir.plus_file(name + ".service.worker.js"));
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// Custom offline page
|
||||
const String offline_page = p_preset->get("progressive_web_app/offline_page");
|
||||
if (!offline_page.is_empty()) {
|
||||
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||
const String offline_dest = dir.plus_file(name + ".offline.html");
|
||||
err = da->copy(ProjectSettings::get_singleton()->globalize_path(offline_page), offline_dest);
|
||||
if (err != OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not read file:") + "\n" + offline_dest);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
// Manifest
|
||||
const char *modes[4] = { "fullscreen", "standalone", "minimal-ui", "browser" };
|
||||
const char *orientations[3] = { "any", "landscape", "portrait" };
|
||||
const int display = CLAMP(int(p_preset->get("progressive_web_app/display")), 0, 4);
|
||||
const int orientation = CLAMP(int(p_preset->get("progressive_web_app/orientation")), 0, 3);
|
||||
|
||||
Dictionary manifest;
|
||||
String proj_name = ProjectSettings::get_singleton()->get_setting("application/config/name");
|
||||
if (proj_name.is_empty()) {
|
||||
proj_name = "Godot Game";
|
||||
}
|
||||
manifest["name"] = proj_name;
|
||||
manifest["start_url"] = "./" + name + ".html";
|
||||
manifest["display"] = String::utf8(modes[display]);
|
||||
manifest["orientation"] = String::utf8(orientations[orientation]);
|
||||
manifest["background_color"] = "#" + p_preset->get("progressive_web_app/background_color").operator Color().to_html(false);
|
||||
|
||||
Array icons_arr;
|
||||
const String icon144_path = p_preset->get("progressive_web_app/icon_144x144");
|
||||
err = _add_manifest_icon(p_path, icon144_path, 144, icons_arr);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
const String icon180_path = p_preset->get("progressive_web_app/icon_180x180");
|
||||
err = _add_manifest_icon(p_path, icon180_path, 180, icons_arr);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
const String icon512_path = p_preset->get("progressive_web_app/icon_512x512");
|
||||
err = _add_manifest_icon(p_path, icon512_path, 512, icons_arr);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
manifest["icons"] = icons_arr;
|
||||
|
||||
CharString cs = Variant(manifest).to_json_string().utf8();
|
||||
err = _write_or_error((const uint8_t *)cs.get_data(), cs.length(), dir.plus_file(name + ".manifest.json"));
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void EditorExportPlatformJavaScript::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) {
|
||||
if (p_preset->get("vram_texture_compression/for_desktop")) {
|
||||
r_features->push_back("s3tc");
|
||||
}
|
||||
|
||||
if (p_preset->get("vram_texture_compression/for_mobile")) {
|
||||
String driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name");
|
||||
if (driver == "GLES2") {
|
||||
r_features->push_back("etc");
|
||||
} else if (driver == "Vulkan") {
|
||||
// FIXME: Review if this is correct.
|
||||
r_features->push_back("etc2");
|
||||
}
|
||||
}
|
||||
ExportMode mode = (ExportMode)(int)p_preset->get("variant/export_type");
|
||||
if (mode == EXPORT_MODE_THREADS) {
|
||||
r_features->push_back("threads");
|
||||
} else if (mode == EXPORT_MODE_GDNATIVE) {
|
||||
r_features->push_back("wasm32");
|
||||
}
|
||||
}
|
||||
|
||||
void EditorExportPlatformJavaScript::get_export_options(List<ExportOption> *r_options) {
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
|
||||
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "variant/export_type", PROPERTY_HINT_ENUM, "Regular,Threads,GDNative"), 0)); // Export type.
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "vram_texture_compression/for_desktop"), true)); // S3TC
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "vram_texture_compression/for_mobile"), false)); // ETC or ETC2, depending on renderer
|
||||
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "html/export_icon"), true));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "html/custom_html_shell", PROPERTY_HINT_FILE, "*.html"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "html/head_include", PROPERTY_HINT_MULTILINE_TEXT), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "html/canvas_resize_policy", PROPERTY_HINT_ENUM, "None,Project,Adaptive"), 2));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "html/focus_canvas_on_start"), true));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "html/experimental_virtual_keyboard"), false));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "progressive_web_app/enabled"), false));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "progressive_web_app/offline_page", PROPERTY_HINT_FILE, "*.html"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "progressive_web_app/display", PROPERTY_HINT_ENUM, "Fullscreen,Standalone,Minimal UI,Browser"), 1));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "progressive_web_app/orientation", PROPERTY_HINT_ENUM, "Any,Landscape,Portrait"), 0));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "progressive_web_app/icon_144x144", PROPERTY_HINT_FILE, "*.png,*.webp,*.svg,*.svgz"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "progressive_web_app/icon_180x180", PROPERTY_HINT_FILE, "*.png,*.webp,*.svg,*.svgz"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "progressive_web_app/icon_512x512", PROPERTY_HINT_FILE, "*.png,*.webp,*.svg,*.svgz"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::COLOR, "progressive_web_app/background_color", PROPERTY_HINT_COLOR_NO_ALPHA), Color()));
|
||||
}
|
||||
|
||||
String EditorExportPlatformJavaScript::get_name() const {
|
||||
return "HTML5";
|
||||
}
|
||||
|
||||
String EditorExportPlatformJavaScript::get_os_name() const {
|
||||
return "HTML5";
|
||||
}
|
||||
|
||||
Ref<Texture2D> EditorExportPlatformJavaScript::get_logo() const {
|
||||
return logo;
|
||||
}
|
||||
|
||||
bool EditorExportPlatformJavaScript::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
|
||||
String err;
|
||||
bool valid = false;
|
||||
ExportMode mode = (ExportMode)(int)p_preset->get("variant/export_type");
|
||||
|
||||
// Look for export templates (first official, and if defined custom templates).
|
||||
bool dvalid = exists_export_template(_get_template_name(mode, true), &err);
|
||||
bool rvalid = exists_export_template(_get_template_name(mode, false), &err);
|
||||
|
||||
if (p_preset->get("custom_template/debug") != "") {
|
||||
dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
|
||||
if (!dvalid) {
|
||||
err += TTR("Custom debug template not found.") + "\n";
|
||||
}
|
||||
}
|
||||
if (p_preset->get("custom_template/release") != "") {
|
||||
rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
|
||||
if (!rvalid) {
|
||||
err += TTR("Custom release template not found.") + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
valid = dvalid || rvalid;
|
||||
r_missing_templates = !valid;
|
||||
|
||||
// Validate the rest of the configuration.
|
||||
|
||||
if (p_preset->get("vram_texture_compression/for_mobile")) {
|
||||
String etc_error = test_etc2();
|
||||
if (etc_error != String()) {
|
||||
valid = false;
|
||||
err += etc_error;
|
||||
}
|
||||
}
|
||||
|
||||
if (!err.is_empty()) {
|
||||
r_error = err;
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
List<String> EditorExportPlatformJavaScript::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
|
||||
List<String> list;
|
||||
list.push_back("html");
|
||||
return list;
|
||||
}
|
||||
|
||||
Error EditorExportPlatformJavaScript::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
|
||||
ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
|
||||
|
||||
const String custom_debug = p_preset->get("custom_template/debug");
|
||||
const String custom_release = p_preset->get("custom_template/release");
|
||||
const String custom_html = p_preset->get("html/custom_html_shell");
|
||||
const bool export_icon = p_preset->get("html/export_icon");
|
||||
const bool pwa = p_preset->get("progressive_web_app/enabled");
|
||||
|
||||
const String base_dir = p_path.get_base_dir();
|
||||
const String base_path = p_path.get_basename();
|
||||
const String base_name = p_path.get_file().get_basename();
|
||||
|
||||
// Find the correct template
|
||||
String template_path = p_debug ? custom_debug : custom_release;
|
||||
template_path = template_path.strip_edges();
|
||||
if (template_path == String()) {
|
||||
ExportMode mode = (ExportMode)(int)p_preset->get("variant/export_type");
|
||||
template_path = find_export_template(_get_template_name(mode, p_debug));
|
||||
}
|
||||
|
||||
if (!DirAccess::exists(base_dir)) {
|
||||
return ERR_FILE_BAD_PATH;
|
||||
}
|
||||
|
||||
if (template_path != String() && !FileAccess::exists(template_path)) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Template file not found:") + "\n" + template_path);
|
||||
return ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
// Export pck and shared objects
|
||||
Vector<SharedObject> shared_objects;
|
||||
String pck_path = base_path + ".pck";
|
||||
Error error = save_pack(p_preset, pck_path, &shared_objects);
|
||||
if (error != OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + pck_path);
|
||||
return error;
|
||||
}
|
||||
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||
for (int i = 0; i < shared_objects.size(); i++) {
|
||||
String dst = base_dir.plus_file(shared_objects[i].path.get_file());
|
||||
error = da->copy(shared_objects[i].path, dst);
|
||||
if (error != OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + shared_objects[i].path.get_file());
|
||||
memdelete(da);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
memdelete(da);
|
||||
da = nullptr;
|
||||
|
||||
// Extract templates.
|
||||
error = _extract_template(template_path, base_dir, base_name, pwa);
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
|
||||
// Parse generated file sizes (pck and wasm, to help show a meaningful loading bar).
|
||||
Dictionary file_sizes;
|
||||
FileAccess *f = nullptr;
|
||||
f = FileAccess::open(pck_path, FileAccess::READ);
|
||||
if (f) {
|
||||
file_sizes[pck_path.get_file()] = (uint64_t)f->get_length();
|
||||
memdelete(f);
|
||||
f = nullptr;
|
||||
}
|
||||
f = FileAccess::open(base_path + ".wasm", FileAccess::READ);
|
||||
if (f) {
|
||||
file_sizes[base_name + ".wasm"] = (uint64_t)f->get_length();
|
||||
memdelete(f);
|
||||
f = nullptr;
|
||||
}
|
||||
|
||||
// Read the HTML shell file (custom or from template).
|
||||
const String html_path = custom_html.is_empty() ? base_path + ".html" : custom_html;
|
||||
Vector<uint8_t> html;
|
||||
f = FileAccess::open(html_path, FileAccess::READ);
|
||||
if (!f) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not read HTML shell:") + "\n" + html_path);
|
||||
return ERR_FILE_CANT_READ;
|
||||
}
|
||||
html.resize(f->get_length());
|
||||
f->get_buffer(html.ptrw(), html.size());
|
||||
memdelete(f);
|
||||
f = nullptr;
|
||||
|
||||
// Generate HTML file with replaced strings.
|
||||
_fix_html(html, p_preset, base_name, p_debug, p_flags, shared_objects, file_sizes);
|
||||
Error err = _write_or_error(html.ptr(), html.size(), p_path);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
html.resize(0);
|
||||
|
||||
// Export splash (why?)
|
||||
Ref<Image> splash = _get_project_splash();
|
||||
const String splash_png_path = base_path + ".png";
|
||||
if (splash->save_png(splash_png_path) != OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + splash_png_path);
|
||||
return ERR_FILE_CANT_WRITE;
|
||||
}
|
||||
|
||||
// Save a favicon that can be accessed without waiting for the project to finish loading.
|
||||
// This way, the favicon can be displayed immediately when loading the page.
|
||||
if (export_icon) {
|
||||
Ref<Image> favicon = _get_project_icon();
|
||||
const String favicon_png_path = base_path + ".icon.png";
|
||||
if (favicon->save_png(favicon_png_path) != OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + favicon_png_path);
|
||||
return ERR_FILE_CANT_WRITE;
|
||||
}
|
||||
favicon->resize(180, 180);
|
||||
const String apple_icon_png_path = base_path + ".apple-touch-icon.png";
|
||||
if (favicon->save_png(apple_icon_png_path) != OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + apple_icon_png_path);
|
||||
return ERR_FILE_CANT_WRITE;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate the PWA worker and manifest
|
||||
if (pwa) {
|
||||
err = _build_pwa(p_preset, p_path, shared_objects);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
bool EditorExportPlatformJavaScript::poll_export() {
|
||||
Ref<EditorExportPreset> preset;
|
||||
|
||||
for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
|
||||
Ref<EditorExportPreset> ep = EditorExport::get_singleton()->get_export_preset(i);
|
||||
if (ep->is_runnable() && ep->get_platform() == this) {
|
||||
preset = ep;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int prev = menu_options;
|
||||
menu_options = preset.is_valid();
|
||||
if (server->is_listening()) {
|
||||
if (menu_options == 0) {
|
||||
MutexLock lock(server_lock);
|
||||
server->stop();
|
||||
} else {
|
||||
menu_options += 1;
|
||||
}
|
||||
}
|
||||
return menu_options != prev;
|
||||
}
|
||||
|
||||
Ref<ImageTexture> EditorExportPlatformJavaScript::get_option_icon(int p_index) const {
|
||||
return p_index == 1 ? stop_icon : EditorExportPlatform::get_option_icon(p_index);
|
||||
}
|
||||
|
||||
int EditorExportPlatformJavaScript::get_options_count() const {
|
||||
return menu_options;
|
||||
}
|
||||
|
||||
Error EditorExportPlatformJavaScript::run(const Ref<EditorExportPreset> &p_preset, int p_option, int p_debug_flags) {
|
||||
if (p_option == 1) {
|
||||
MutexLock lock(server_lock);
|
||||
server->stop();
|
||||
return OK;
|
||||
}
|
||||
|
||||
const String dest = EditorPaths::get_singleton()->get_cache_dir().plus_file("web");
|
||||
DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||
if (!da->dir_exists(dest)) {
|
||||
Error err = da->make_dir_recursive(dest);
|
||||
if (err != OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Could not create HTTP server directory:") + "\n" + dest);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
const String basepath = dest.plus_file("tmp_js_export");
|
||||
Error err = export_project(p_preset, true, basepath + ".html", p_debug_flags);
|
||||
if (err != OK) {
|
||||
// Export generates several files, clean them up on failure.
|
||||
DirAccess::remove_file_or_error(basepath + ".html");
|
||||
DirAccess::remove_file_or_error(basepath + ".offline.html");
|
||||
DirAccess::remove_file_or_error(basepath + ".js");
|
||||
DirAccess::remove_file_or_error(basepath + ".worker.js");
|
||||
DirAccess::remove_file_or_error(basepath + ".audio.worklet.js");
|
||||
DirAccess::remove_file_or_error(basepath + ".service.worker.js");
|
||||
DirAccess::remove_file_or_error(basepath + ".pck");
|
||||
DirAccess::remove_file_or_error(basepath + ".png");
|
||||
DirAccess::remove_file_or_error(basepath + ".side.wasm");
|
||||
DirAccess::remove_file_or_error(basepath + ".wasm");
|
||||
DirAccess::remove_file_or_error(basepath + ".icon.png");
|
||||
DirAccess::remove_file_or_error(basepath + ".apple-touch-icon.png");
|
||||
return err;
|
||||
}
|
||||
|
||||
const uint16_t bind_port = EDITOR_GET("export/web/http_port");
|
||||
// Resolve host if needed.
|
||||
const String bind_host = EDITOR_GET("export/web/http_host");
|
||||
IPAddress bind_ip;
|
||||
if (bind_host.is_valid_ip_address()) {
|
||||
bind_ip = bind_host;
|
||||
} else {
|
||||
bind_ip = IP::get_singleton()->resolve_hostname(bind_host);
|
||||
}
|
||||
ERR_FAIL_COND_V_MSG(!bind_ip.is_valid(), ERR_INVALID_PARAMETER, "Invalid editor setting 'export/web/http_host': '" + bind_host + "'. Try using '127.0.0.1'.");
|
||||
|
||||
const bool use_ssl = EDITOR_GET("export/web/use_ssl");
|
||||
const String ssl_key = EDITOR_GET("export/web/ssl_key");
|
||||
const String ssl_cert = EDITOR_GET("export/web/ssl_certificate");
|
||||
|
||||
// Restart server.
|
||||
{
|
||||
MutexLock lock(server_lock);
|
||||
|
||||
server->stop();
|
||||
err = server->listen(bind_port, bind_ip, use_ssl, ssl_key, ssl_cert);
|
||||
}
|
||||
if (err != OK) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Error starting HTTP server:") + "\n" + itos(err));
|
||||
return err;
|
||||
}
|
||||
|
||||
OS::get_singleton()->shell_open(String((use_ssl ? "https://" : "http://") + bind_host + ":" + itos(bind_port) + "/tmp_js_export.html"));
|
||||
// FIXME: Find out how to clean up export files after running the successfully
|
||||
// exported game. Might not be trivial.
|
||||
return OK;
|
||||
}
|
||||
|
||||
Ref<Texture2D> EditorExportPlatformJavaScript::get_run_icon() const {
|
||||
return run_icon;
|
||||
}
|
||||
|
||||
void EditorExportPlatformJavaScript::_server_thread_poll(void *data) {
|
||||
EditorExportPlatformJavaScript *ej = (EditorExportPlatformJavaScript *)data;
|
||||
while (!ej->server_quit) {
|
||||
OS::get_singleton()->delay_usec(1000);
|
||||
{
|
||||
MutexLock lock(ej->server_lock);
|
||||
ej->server->poll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EditorExportPlatformJavaScript::EditorExportPlatformJavaScript() {
|
||||
server.instantiate();
|
||||
server_thread.start(_server_thread_poll, this);
|
||||
|
||||
Ref<Image> img = memnew(Image(_javascript_logo));
|
||||
logo.instantiate();
|
||||
logo->create_from_image(img);
|
||||
|
||||
img = Ref<Image>(memnew(Image(_javascript_run_icon)));
|
||||
run_icon.instantiate();
|
||||
run_icon->create_from_image(img);
|
||||
|
||||
Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
|
||||
if (theme.is_valid()) {
|
||||
stop_icon = theme->get_icon("Stop", "EditorIcons");
|
||||
} else {
|
||||
stop_icon.instantiate();
|
||||
}
|
||||
}
|
||||
|
||||
EditorExportPlatformJavaScript::~EditorExportPlatformJavaScript() {
|
||||
server->stop();
|
||||
server_quit = true;
|
||||
server_thread.wait_to_finish();
|
||||
}
|
149
platform/javascript/export/export_plugin.h
Normal file
149
platform/javascript/export/export_plugin.h
Normal file
@ -0,0 +1,149 @@
|
||||
/*************************************************************************/
|
||||
/* export_plugin.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef JAVASCRIPT_EXPORT_PLUGIN_H
|
||||
#define JAVASCRIPT_EXPORT_PLUGIN_H
|
||||
|
||||
#include "core/io/image_loader.h"
|
||||
#include "core/io/stream_peer_ssl.h"
|
||||
#include "core/io/tcp_server.h"
|
||||
#include "core/io/zip_io.h"
|
||||
#include "editor/editor_export.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "main/splash.gen.h"
|
||||
#include "platform/javascript/logo.gen.h"
|
||||
#include "platform/javascript/run_icon.gen.h"
|
||||
|
||||
#include "export_server.h"
|
||||
|
||||
class EditorExportPlatformJavaScript : public EditorExportPlatform {
|
||||
GDCLASS(EditorExportPlatformJavaScript, EditorExportPlatform);
|
||||
|
||||
Ref<ImageTexture> logo;
|
||||
Ref<ImageTexture> run_icon;
|
||||
Ref<ImageTexture> stop_icon;
|
||||
int menu_options = 0;
|
||||
|
||||
Ref<EditorHTTPServer> server;
|
||||
bool server_quit = false;
|
||||
Mutex server_lock;
|
||||
Thread server_thread;
|
||||
|
||||
enum ExportMode {
|
||||
EXPORT_MODE_NORMAL = 0,
|
||||
EXPORT_MODE_THREADS = 1,
|
||||
EXPORT_MODE_GDNATIVE = 2,
|
||||
};
|
||||
|
||||
String _get_template_name(ExportMode p_mode, bool p_debug) const {
|
||||
String name = "webassembly";
|
||||
switch (p_mode) {
|
||||
case EXPORT_MODE_THREADS:
|
||||
name += "_threads";
|
||||
break;
|
||||
case EXPORT_MODE_GDNATIVE:
|
||||
name += "_gdnative";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (p_debug) {
|
||||
name += "_debug.zip";
|
||||
} else {
|
||||
name += "_release.zip";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
Ref<Image> _get_project_icon() const {
|
||||
Ref<Image> icon;
|
||||
icon.instantiate();
|
||||
const String icon_path = String(GLOBAL_GET("application/config/icon")).strip_edges();
|
||||
if (icon_path.is_empty() || ImageLoader::load_image(icon_path, icon) != OK) {
|
||||
return EditorNode::get_singleton()->get_editor_theme()->get_icon("DefaultProjectIcon", "EditorIcons")->get_image();
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
Ref<Image> _get_project_splash() const {
|
||||
Ref<Image> splash;
|
||||
splash.instantiate();
|
||||
const String splash_path = String(GLOBAL_GET("application/boot_splash/image")).strip_edges();
|
||||
if (splash_path.is_empty() || ImageLoader::load_image(splash_path, splash) != OK) {
|
||||
return Ref<Image>(memnew(Image(boot_splash_png)));
|
||||
}
|
||||
return splash;
|
||||
}
|
||||
|
||||
Error _extract_template(const String &p_template, const String &p_dir, const String &p_name, bool pwa);
|
||||
void _replace_strings(Map<String, String> p_replaces, Vector<uint8_t> &r_template);
|
||||
void _fix_html(Vector<uint8_t> &p_html, const Ref<EditorExportPreset> &p_preset, const String &p_name, bool p_debug, int p_flags, const Vector<SharedObject> p_shared_objects, const Dictionary &p_file_sizes);
|
||||
Error _add_manifest_icon(const String &p_path, const String &p_icon, int p_size, Array &r_arr);
|
||||
Error _build_pwa(const Ref<EditorExportPreset> &p_preset, const String p_path, const Vector<SharedObject> &p_shared_objects);
|
||||
Error _write_or_error(const uint8_t *p_content, int p_len, String p_path);
|
||||
|
||||
static void _server_thread_poll(void *data);
|
||||
|
||||
public:
|
||||
virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) override;
|
||||
|
||||
virtual void get_export_options(List<ExportOption> *r_options) override;
|
||||
|
||||
virtual String get_name() const override;
|
||||
virtual String get_os_name() const override;
|
||||
virtual Ref<Texture2D> get_logo() const override;
|
||||
|
||||
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
|
||||
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override;
|
||||
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) override;
|
||||
|
||||
virtual bool poll_export() override;
|
||||
virtual int get_options_count() const override;
|
||||
virtual String get_option_label(int p_index) const override { return p_index ? TTR("Stop HTTP Server") : TTR("Run in Browser"); }
|
||||
virtual String get_option_tooltip(int p_index) const override { return p_index ? TTR("Stop HTTP Server") : TTR("Run exported HTML in the system's default browser."); }
|
||||
virtual Ref<ImageTexture> get_option_icon(int p_index) const override;
|
||||
virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_option, int p_debug_flags) override;
|
||||
virtual Ref<Texture2D> get_run_icon() const override;
|
||||
|
||||
virtual void get_platform_features(List<String> *r_features) override {
|
||||
r_features->push_back("web");
|
||||
r_features->push_back(get_os_name());
|
||||
}
|
||||
|
||||
virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) override {
|
||||
}
|
||||
|
||||
String get_debug_protocol() const override { return "ws://"; }
|
||||
|
||||
EditorExportPlatformJavaScript();
|
||||
~EditorExportPlatformJavaScript();
|
||||
};
|
||||
|
||||
#endif
|
254
platform/javascript/export/export_server.h
Normal file
254
platform/javascript/export/export_server.h
Normal file
@ -0,0 +1,254 @@
|
||||
/*************************************************************************/
|
||||
/* export_server.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef JAVASCRIPT_EXPORT_SERVER_H
|
||||
#define JAVASCRIPT_EXPORT_SERVER_H
|
||||
|
||||
#include "core/io/image_loader.h"
|
||||
#include "core/io/stream_peer_ssl.h"
|
||||
#include "core/io/tcp_server.h"
|
||||
#include "core/io/zip_io.h"
|
||||
#include "editor/editor_export.h"
|
||||
#include "editor/editor_node.h"
|
||||
|
||||
class EditorHTTPServer : public RefCounted {
|
||||
private:
|
||||
Ref<TCPServer> server;
|
||||
Map<String, String> mimes;
|
||||
Ref<StreamPeerTCP> tcp;
|
||||
Ref<StreamPeerSSL> ssl;
|
||||
Ref<StreamPeer> peer;
|
||||
Ref<CryptoKey> key;
|
||||
Ref<X509Certificate> cert;
|
||||
bool use_ssl = false;
|
||||
uint64_t time = 0;
|
||||
uint8_t req_buf[4096];
|
||||
int req_pos = 0;
|
||||
|
||||
void _clear_client() {
|
||||
peer = Ref<StreamPeer>();
|
||||
ssl = Ref<StreamPeerSSL>();
|
||||
tcp = Ref<StreamPeerTCP>();
|
||||
memset(req_buf, 0, sizeof(req_buf));
|
||||
time = 0;
|
||||
req_pos = 0;
|
||||
}
|
||||
|
||||
void _set_internal_certs(Ref<Crypto> p_crypto) {
|
||||
const String cache_path = EditorPaths::get_singleton()->get_cache_dir();
|
||||
const String key_path = cache_path.plus_file("html5_server.key");
|
||||
const String crt_path = cache_path.plus_file("html5_server.crt");
|
||||
bool regen = !FileAccess::exists(key_path) || !FileAccess::exists(crt_path);
|
||||
if (!regen) {
|
||||
key = Ref<CryptoKey>(CryptoKey::create());
|
||||
cert = Ref<X509Certificate>(X509Certificate::create());
|
||||
if (key->load(key_path) != OK || cert->load(crt_path) != OK) {
|
||||
regen = true;
|
||||
}
|
||||
}
|
||||
if (regen) {
|
||||
key = p_crypto->generate_rsa(2048);
|
||||
key->save(key_path);
|
||||
cert = p_crypto->generate_self_signed_certificate(key, "CN=godot-debug.local,O=A Game Dev,C=XXA", "20140101000000", "20340101000000");
|
||||
cert->save(crt_path);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
EditorHTTPServer() {
|
||||
mimes["html"] = "text/html";
|
||||
mimes["js"] = "application/javascript";
|
||||
mimes["json"] = "application/json";
|
||||
mimes["pck"] = "application/octet-stream";
|
||||
mimes["png"] = "image/png";
|
||||
mimes["svg"] = "image/svg";
|
||||
mimes["wasm"] = "application/wasm";
|
||||
server.instantiate();
|
||||
stop();
|
||||
}
|
||||
|
||||
void stop() {
|
||||
server->stop();
|
||||
_clear_client();
|
||||
}
|
||||
|
||||
Error listen(int p_port, IPAddress p_address, bool p_use_ssl, String p_ssl_key, String p_ssl_cert) {
|
||||
use_ssl = p_use_ssl;
|
||||
if (use_ssl) {
|
||||
Ref<Crypto> crypto = Crypto::create();
|
||||
if (crypto.is_null()) {
|
||||
return ERR_UNAVAILABLE;
|
||||
}
|
||||
if (!p_ssl_key.is_empty() && !p_ssl_cert.is_empty()) {
|
||||
key = Ref<CryptoKey>(CryptoKey::create());
|
||||
Error err = key->load(p_ssl_key);
|
||||
ERR_FAIL_COND_V(err != OK, err);
|
||||
cert = Ref<X509Certificate>(X509Certificate::create());
|
||||
err = cert->load(p_ssl_cert);
|
||||
ERR_FAIL_COND_V(err != OK, err);
|
||||
} else {
|
||||
_set_internal_certs(crypto);
|
||||
}
|
||||
}
|
||||
return server->listen(p_port, p_address);
|
||||
}
|
||||
|
||||
bool is_listening() const {
|
||||
return server->is_listening();
|
||||
}
|
||||
|
||||
void _send_response() {
|
||||
Vector<String> psa = String((char *)req_buf).split("\r\n");
|
||||
int len = psa.size();
|
||||
ERR_FAIL_COND_MSG(len < 4, "Not enough response headers, got: " + itos(len) + ", expected >= 4.");
|
||||
|
||||
Vector<String> req = psa[0].split(" ", false);
|
||||
ERR_FAIL_COND_MSG(req.size() < 2, "Invalid protocol or status code.");
|
||||
|
||||
// Wrong protocol
|
||||
ERR_FAIL_COND_MSG(req[0] != "GET" || req[2] != "HTTP/1.1", "Invalid method or HTTP version.");
|
||||
|
||||
const int query_index = req[1].find_char('?');
|
||||
const String path = (query_index == -1) ? req[1] : req[1].substr(0, query_index);
|
||||
|
||||
const String req_file = path.get_file();
|
||||
const String req_ext = path.get_extension();
|
||||
const String cache_path = EditorPaths::get_singleton()->get_cache_dir().plus_file("web");
|
||||
const String filepath = cache_path.plus_file(req_file);
|
||||
|
||||
if (!mimes.has(req_ext) || !FileAccess::exists(filepath)) {
|
||||
String s = "HTTP/1.1 404 Not Found\r\n";
|
||||
s += "Connection: Close\r\n";
|
||||
s += "\r\n";
|
||||
CharString cs = s.utf8();
|
||||
peer->put_data((const uint8_t *)cs.get_data(), cs.size() - 1);
|
||||
return;
|
||||
}
|
||||
const String ctype = mimes[req_ext];
|
||||
|
||||
FileAccess *f = FileAccess::open(filepath, FileAccess::READ);
|
||||
ERR_FAIL_COND(!f);
|
||||
String s = "HTTP/1.1 200 OK\r\n";
|
||||
s += "Connection: Close\r\n";
|
||||
s += "Content-Type: " + ctype + "\r\n";
|
||||
s += "Access-Control-Allow-Origin: *\r\n";
|
||||
s += "Cross-Origin-Opener-Policy: same-origin\r\n";
|
||||
s += "Cross-Origin-Embedder-Policy: require-corp\r\n";
|
||||
s += "Cache-Control: no-store, max-age=0\r\n";
|
||||
s += "\r\n";
|
||||
CharString cs = s.utf8();
|
||||
Error err = peer->put_data((const uint8_t *)cs.get_data(), cs.size() - 1);
|
||||
if (err != OK) {
|
||||
memdelete(f);
|
||||
ERR_FAIL();
|
||||
}
|
||||
|
||||
while (true) {
|
||||
uint8_t bytes[4096];
|
||||
uint64_t read = f->get_buffer(bytes, 4096);
|
||||
if (read == 0) {
|
||||
break;
|
||||
}
|
||||
err = peer->put_data(bytes, read);
|
||||
if (err != OK) {
|
||||
memdelete(f);
|
||||
ERR_FAIL();
|
||||
}
|
||||
}
|
||||
memdelete(f);
|
||||
}
|
||||
|
||||
void poll() {
|
||||
if (!server->is_listening()) {
|
||||
return;
|
||||
}
|
||||
if (tcp.is_null()) {
|
||||
if (!server->is_connection_available()) {
|
||||
return;
|
||||
}
|
||||
tcp = server->take_connection();
|
||||
peer = tcp;
|
||||
time = OS::get_singleton()->get_ticks_usec();
|
||||
}
|
||||
if (OS::get_singleton()->get_ticks_usec() - time > 1000000) {
|
||||
_clear_client();
|
||||
return;
|
||||
}
|
||||
if (tcp->get_status() != StreamPeerTCP::STATUS_CONNECTED) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (use_ssl) {
|
||||
if (ssl.is_null()) {
|
||||
ssl = Ref<StreamPeerSSL>(StreamPeerSSL::create());
|
||||
peer = ssl;
|
||||
ssl->set_blocking_handshake_enabled(false);
|
||||
if (ssl->accept_stream(tcp, key, cert) != OK) {
|
||||
_clear_client();
|
||||
return;
|
||||
}
|
||||
}
|
||||
ssl->poll();
|
||||
if (ssl->get_status() == StreamPeerSSL::STATUS_HANDSHAKING) {
|
||||
// Still handshaking, keep waiting.
|
||||
return;
|
||||
}
|
||||
if (ssl->get_status() != StreamPeerSSL::STATUS_CONNECTED) {
|
||||
_clear_client();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
char *r = (char *)req_buf;
|
||||
int l = req_pos - 1;
|
||||
if (l > 3 && r[l] == '\n' && r[l - 1] == '\r' && r[l - 2] == '\n' && r[l - 3] == '\r') {
|
||||
_send_response();
|
||||
_clear_client();
|
||||
return;
|
||||
}
|
||||
|
||||
int read = 0;
|
||||
ERR_FAIL_COND(req_pos >= 4096);
|
||||
Error err = peer->get_partial_data(&req_buf[req_pos], 1, read);
|
||||
if (err != OK) {
|
||||
// Got an error
|
||||
_clear_client();
|
||||
return;
|
||||
} else if (read != 1) {
|
||||
// Busy, wait next poll
|
||||
return;
|
||||
}
|
||||
req_pos += read;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
1085
platform/osx/export/export_plugin.cpp
Normal file
1085
platform/osx/export/export_plugin.cpp
Normal file
File diff suppressed because it is too large
Load Diff
128
platform/osx/export/export_plugin.h
Normal file
128
platform/osx/export/export_plugin.h
Normal file
@ -0,0 +1,128 @@
|
||||
/*************************************************************************/
|
||||
/* export_plugin.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef OSX_EXPORT_PLUGIN_H
|
||||
#define OSX_EXPORT_PLUGIN_H
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/io/dir_access.h"
|
||||
#include "core/io/file_access.h"
|
||||
#include "core/io/marshalls.h"
|
||||
#include "core/io/resource_saver.h"
|
||||
#include "core/io/zip_io.h"
|
||||
#include "core/os/os.h"
|
||||
#include "core/version.h"
|
||||
#include "editor/editor_export.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "platform/osx/logo.gen.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
class EditorExportPlatformOSX : public EditorExportPlatform {
|
||||
GDCLASS(EditorExportPlatformOSX, EditorExportPlatform);
|
||||
|
||||
int version_code = 0;
|
||||
|
||||
Ref<ImageTexture> logo;
|
||||
|
||||
void _fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary);
|
||||
void _make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data);
|
||||
|
||||
Error _notarize(const Ref<EditorExportPreset> &p_preset, const String &p_path);
|
||||
Error _code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_ent_path);
|
||||
Error _create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name);
|
||||
void _zip_folder_recursive(zipFile &p_zip, const String &p_root_path, const String &p_folder, const String &p_pkg_name);
|
||||
|
||||
#ifdef OSX_ENABLED
|
||||
bool use_codesign() const { return true; }
|
||||
bool use_dmg() const { return true; }
|
||||
#else
|
||||
bool use_codesign() const { return false; }
|
||||
bool use_dmg() const { return false; }
|
||||
#endif
|
||||
bool is_package_name_valid(const String &p_package, String *r_error = nullptr) const {
|
||||
String pname = p_package;
|
||||
|
||||
if (pname.length() == 0) {
|
||||
if (r_error) {
|
||||
*r_error = TTR("Identifier is missing.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < pname.length(); i++) {
|
||||
char32_t c = pname[i];
|
||||
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '.')) {
|
||||
if (r_error) {
|
||||
*r_error = vformat(TTR("The character '%s' is not allowed in Identifier."), String::chr(c));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) override;
|
||||
virtual void get_export_options(List<ExportOption> *r_options) override;
|
||||
|
||||
public:
|
||||
virtual String get_name() const override { return "macOS"; }
|
||||
virtual String get_os_name() const override { return "macOS"; }
|
||||
virtual Ref<Texture2D> get_logo() const override { return logo; }
|
||||
|
||||
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override {
|
||||
List<String> list;
|
||||
if (use_dmg()) {
|
||||
list.push_back("dmg");
|
||||
}
|
||||
list.push_back("zip");
|
||||
return list;
|
||||
}
|
||||
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) override;
|
||||
|
||||
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
|
||||
|
||||
virtual void get_platform_features(List<String> *r_features) override {
|
||||
r_features->push_back("pc");
|
||||
r_features->push_back("s3tc");
|
||||
r_features->push_back("macOS");
|
||||
}
|
||||
|
||||
virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) override {
|
||||
}
|
||||
|
||||
EditorExportPlatformOSX();
|
||||
~EditorExportPlatformOSX();
|
||||
};
|
||||
|
||||
#endif
|
474
platform/uwp/export/app_packager.cpp
Normal file
474
platform/uwp/export/app_packager.cpp
Normal file
@ -0,0 +1,474 @@
|
||||
/*************************************************************************/
|
||||
/* app_packager.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "app_packager.h"
|
||||
|
||||
String AppxPackager::hash_block(const uint8_t *p_block_data, size_t p_block_len) {
|
||||
unsigned char hash[32];
|
||||
char base64[45];
|
||||
|
||||
CryptoCore::sha256(p_block_data, p_block_len, hash);
|
||||
size_t len = 0;
|
||||
CryptoCore::b64_encode((unsigned char *)base64, 45, &len, (unsigned char *)hash, 32);
|
||||
base64[44] = '\0';
|
||||
|
||||
return String(base64);
|
||||
}
|
||||
|
||||
void AppxPackager::make_block_map(const String &p_path) {
|
||||
FileAccess *tmp_file = FileAccess::open(p_path, FileAccess::WRITE);
|
||||
|
||||
tmp_file->store_string("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
|
||||
tmp_file->store_string("<BlockMap xmlns=\"http://schemas.microsoft.com/appx/2010/blockmap\" HashMethod=\"http://www.w3.org/2001/04/xmlenc#sha256\">");
|
||||
|
||||
for (int i = 0; i < file_metadata.size(); i++) {
|
||||
FileMeta file = file_metadata[i];
|
||||
|
||||
tmp_file->store_string(
|
||||
"<File Name=\"" + file.name.replace("/", "\\") + "\" Size=\"" + itos(file.uncompressed_size) + "\" LfhSize=\"" + itos(file.lfh_size) + "\">");
|
||||
|
||||
for (int j = 0; j < file.hashes.size(); j++) {
|
||||
tmp_file->store_string("<Block Hash=\"" + file.hashes[j].base64_hash + "\" ");
|
||||
if (file.compressed) {
|
||||
tmp_file->store_string("Size=\"" + itos(file.hashes[j].compressed_size) + "\" ");
|
||||
}
|
||||
tmp_file->store_string("/>");
|
||||
}
|
||||
|
||||
tmp_file->store_string("</File>");
|
||||
}
|
||||
|
||||
tmp_file->store_string("</BlockMap>");
|
||||
|
||||
tmp_file->close();
|
||||
memdelete(tmp_file);
|
||||
}
|
||||
|
||||
String AppxPackager::content_type(String p_extension) {
|
||||
if (p_extension == "png") {
|
||||
return "image/png";
|
||||
} else if (p_extension == "jpg") {
|
||||
return "image/jpg";
|
||||
} else if (p_extension == "xml") {
|
||||
return "application/xml";
|
||||
} else if (p_extension == "exe" || p_extension == "dll") {
|
||||
return "application/x-msdownload";
|
||||
} else {
|
||||
return "application/octet-stream";
|
||||
}
|
||||
}
|
||||
|
||||
void AppxPackager::make_content_types(const String &p_path) {
|
||||
FileAccess *tmp_file = FileAccess::open(p_path, FileAccess::WRITE);
|
||||
|
||||
tmp_file->store_string("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||
tmp_file->store_string("<Types xmlns=\"http://schemas.openxmlformats.org/package/2006/content-types\">");
|
||||
|
||||
Map<String, String> types;
|
||||
|
||||
for (int i = 0; i < file_metadata.size(); i++) {
|
||||
String ext = file_metadata[i].name.get_extension().to_lower();
|
||||
|
||||
if (types.has(ext)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
types[ext] = content_type(ext);
|
||||
|
||||
tmp_file->store_string("<Default Extension=\"" + ext + "\" ContentType=\"" + types[ext] + "\" />");
|
||||
}
|
||||
|
||||
// Appx signature file
|
||||
tmp_file->store_string("<Default Extension=\"p7x\" ContentType=\"application/octet-stream\" />");
|
||||
|
||||
// Override for package files
|
||||
tmp_file->store_string("<Override PartName=\"/AppxManifest.xml\" ContentType=\"application/vnd.ms-appx.manifest+xml\" />");
|
||||
tmp_file->store_string("<Override PartName=\"/AppxBlockMap.xml\" ContentType=\"application/vnd.ms-appx.blockmap+xml\" />");
|
||||
tmp_file->store_string("<Override PartName=\"/AppxSignature.p7x\" ContentType=\"application/vnd.ms-appx.signature\" />");
|
||||
tmp_file->store_string("<Override PartName=\"/AppxMetadata/CodeIntegrity.cat\" ContentType=\"application/vnd.ms-pkiseccat\" />");
|
||||
|
||||
tmp_file->store_string("</Types>");
|
||||
|
||||
tmp_file->close();
|
||||
memdelete(tmp_file);
|
||||
}
|
||||
|
||||
Vector<uint8_t> AppxPackager::make_file_header(FileMeta p_file_meta) {
|
||||
Vector<uint8_t> buf;
|
||||
buf.resize(BASE_FILE_HEADER_SIZE + p_file_meta.name.length());
|
||||
|
||||
int offs = 0;
|
||||
// Write magic
|
||||
offs += buf_put_int32(FILE_HEADER_MAGIC, &buf.write[offs]);
|
||||
|
||||
// Version
|
||||
offs += buf_put_int16(ZIP_VERSION, &buf.write[offs]);
|
||||
|
||||
// Special flag
|
||||
offs += buf_put_int16(GENERAL_PURPOSE, &buf.write[offs]);
|
||||
|
||||
// Compression
|
||||
offs += buf_put_int16(p_file_meta.compressed ? Z_DEFLATED : 0, &buf.write[offs]);
|
||||
|
||||
// File date and time
|
||||
offs += buf_put_int32(0, &buf.write[offs]);
|
||||
|
||||
// CRC-32
|
||||
offs += buf_put_int32(p_file_meta.file_crc32, &buf.write[offs]);
|
||||
|
||||
// Compressed size
|
||||
offs += buf_put_int32(p_file_meta.compressed_size, &buf.write[offs]);
|
||||
|
||||
// Uncompressed size
|
||||
offs += buf_put_int32(p_file_meta.uncompressed_size, &buf.write[offs]);
|
||||
|
||||
// File name length
|
||||
offs += buf_put_int16(p_file_meta.name.length(), &buf.write[offs]);
|
||||
|
||||
// Extra data length
|
||||
offs += buf_put_int16(0, &buf.write[offs]);
|
||||
|
||||
// File name
|
||||
offs += buf_put_string(p_file_meta.name, &buf.write[offs]);
|
||||
|
||||
// Done!
|
||||
return buf;
|
||||
}
|
||||
|
||||
void AppxPackager::store_central_dir_header(const FileMeta &p_file, bool p_do_hash) {
|
||||
Vector<uint8_t> &buf = central_dir_data;
|
||||
int offs = buf.size();
|
||||
buf.resize(buf.size() + BASE_CENTRAL_DIR_SIZE + p_file.name.length());
|
||||
|
||||
// Write magic
|
||||
offs += buf_put_int32(CENTRAL_DIR_MAGIC, &buf.write[offs]);
|
||||
|
||||
// ZIP versions
|
||||
offs += buf_put_int16(ZIP_ARCHIVE_VERSION, &buf.write[offs]);
|
||||
offs += buf_put_int16(ZIP_VERSION, &buf.write[offs]);
|
||||
|
||||
// General purpose flag
|
||||
offs += buf_put_int16(GENERAL_PURPOSE, &buf.write[offs]);
|
||||
|
||||
// Compression
|
||||
offs += buf_put_int16(p_file.compressed ? Z_DEFLATED : 0, &buf.write[offs]);
|
||||
|
||||
// Modification date/time
|
||||
offs += buf_put_int32(0, &buf.write[offs]);
|
||||
|
||||
// Crc-32
|
||||
offs += buf_put_int32(p_file.file_crc32, &buf.write[offs]);
|
||||
|
||||
// File sizes
|
||||
offs += buf_put_int32(p_file.compressed_size, &buf.write[offs]);
|
||||
offs += buf_put_int32(p_file.uncompressed_size, &buf.write[offs]);
|
||||
|
||||
// File name length
|
||||
offs += buf_put_int16(p_file.name.length(), &buf.write[offs]);
|
||||
|
||||
// Extra field length
|
||||
offs += buf_put_int16(0, &buf.write[offs]);
|
||||
|
||||
// Comment length
|
||||
offs += buf_put_int16(0, &buf.write[offs]);
|
||||
|
||||
// Disk number start, internal/external file attributes
|
||||
for (int i = 0; i < 8; i++) {
|
||||
buf.write[offs++] = 0;
|
||||
}
|
||||
|
||||
// Relative offset
|
||||
offs += buf_put_int32(p_file.zip_offset, &buf.write[offs]);
|
||||
|
||||
// File name
|
||||
offs += buf_put_string(p_file.name, &buf.write[offs]);
|
||||
|
||||
// Done!
|
||||
}
|
||||
|
||||
Vector<uint8_t> AppxPackager::make_end_of_central_record() {
|
||||
Vector<uint8_t> buf;
|
||||
buf.resize(ZIP64_END_OF_CENTRAL_DIR_SIZE + 12 + END_OF_CENTRAL_DIR_SIZE); // Size plus magic
|
||||
|
||||
int offs = 0;
|
||||
|
||||
// Write magic
|
||||
offs += buf_put_int32(ZIP64_END_OF_CENTRAL_DIR_MAGIC, &buf.write[offs]);
|
||||
|
||||
// Size of this record
|
||||
offs += buf_put_int64(ZIP64_END_OF_CENTRAL_DIR_SIZE, &buf.write[offs]);
|
||||
|
||||
// Version (yes, twice)
|
||||
offs += buf_put_int16(ZIP_ARCHIVE_VERSION, &buf.write[offs]);
|
||||
offs += buf_put_int16(ZIP_ARCHIVE_VERSION, &buf.write[offs]);
|
||||
|
||||
// Disk number
|
||||
for (int i = 0; i < 8; i++) {
|
||||
buf.write[offs++] = 0;
|
||||
}
|
||||
|
||||
// Number of entries (total and per disk)
|
||||
offs += buf_put_int64(file_metadata.size(), &buf.write[offs]);
|
||||
offs += buf_put_int64(file_metadata.size(), &buf.write[offs]);
|
||||
|
||||
// Size of central dir
|
||||
offs += buf_put_int64(central_dir_data.size(), &buf.write[offs]);
|
||||
|
||||
// Central dir offset
|
||||
offs += buf_put_int64(central_dir_offset, &buf.write[offs]);
|
||||
|
||||
////// ZIP64 locator
|
||||
|
||||
// Write magic for zip64 central dir locator
|
||||
offs += buf_put_int32(ZIP64_END_DIR_LOCATOR_MAGIC, &buf.write[offs]);
|
||||
|
||||
// Disk number
|
||||
for (int i = 0; i < 4; i++) {
|
||||
buf.write[offs++] = 0;
|
||||
}
|
||||
|
||||
// Relative offset
|
||||
offs += buf_put_int64(end_of_central_dir_offset, &buf.write[offs]);
|
||||
|
||||
// Number of disks
|
||||
offs += buf_put_int32(1, &buf.write[offs]);
|
||||
|
||||
/////// End of zip directory
|
||||
|
||||
// Write magic for end central dir
|
||||
offs += buf_put_int32(END_OF_CENTRAL_DIR_MAGIC, &buf.write[offs]);
|
||||
|
||||
// Dummy stuff for Zip64
|
||||
for (int i = 0; i < 4; i++) {
|
||||
buf.write[offs++] = 0x0;
|
||||
}
|
||||
for (int i = 0; i < 12; i++) {
|
||||
buf.write[offs++] = 0xFF;
|
||||
}
|
||||
|
||||
// Size of comments
|
||||
for (int i = 0; i < 2; i++) {
|
||||
buf.write[offs++] = 0;
|
||||
}
|
||||
|
||||
// Done!
|
||||
return buf;
|
||||
}
|
||||
|
||||
void AppxPackager::init(FileAccess *p_fa) {
|
||||
package = p_fa;
|
||||
central_dir_offset = 0;
|
||||
end_of_central_dir_offset = 0;
|
||||
}
|
||||
|
||||
Error AppxPackager::add_file(String p_file_name, const uint8_t *p_buffer, size_t p_len, int p_file_no, int p_total_files, bool p_compress) {
|
||||
if (p_file_no >= 1 && p_total_files >= 1) {
|
||||
if (EditorNode::progress_task_step(progress_task, "File: " + p_file_name, (p_file_no * 100) / p_total_files)) {
|
||||
return ERR_SKIP;
|
||||
}
|
||||
}
|
||||
|
||||
FileMeta meta;
|
||||
meta.name = p_file_name;
|
||||
meta.uncompressed_size = p_len;
|
||||
meta.compressed_size = p_len;
|
||||
meta.compressed = p_compress;
|
||||
meta.zip_offset = package->get_position();
|
||||
|
||||
Vector<uint8_t> file_buffer;
|
||||
|
||||
// Data for compression
|
||||
z_stream strm;
|
||||
FileAccess *strm_f = nullptr;
|
||||
Vector<uint8_t> strm_in;
|
||||
strm_in.resize(BLOCK_SIZE);
|
||||
Vector<uint8_t> strm_out;
|
||||
|
||||
if (p_compress) {
|
||||
strm.zalloc = zipio_alloc;
|
||||
strm.zfree = zipio_free;
|
||||
strm.opaque = &strm_f;
|
||||
|
||||
strm_out.resize(BLOCK_SIZE + 8);
|
||||
|
||||
deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
|
||||
}
|
||||
|
||||
int step = 0;
|
||||
|
||||
while (p_len - step > 0) {
|
||||
size_t block_size = (p_len - step) > BLOCK_SIZE ? (size_t)BLOCK_SIZE : (p_len - step);
|
||||
|
||||
for (uint64_t i = 0; i < block_size; i++) {
|
||||
strm_in.write[i] = p_buffer[step + i];
|
||||
}
|
||||
|
||||
BlockHash bh;
|
||||
bh.base64_hash = hash_block(strm_in.ptr(), block_size);
|
||||
|
||||
if (p_compress) {
|
||||
strm.avail_in = block_size;
|
||||
strm.avail_out = strm_out.size();
|
||||
strm.next_in = (uint8_t *)strm_in.ptr();
|
||||
strm.next_out = strm_out.ptrw();
|
||||
|
||||
int total_out_before = strm.total_out;
|
||||
|
||||
int err = deflate(&strm, Z_FULL_FLUSH);
|
||||
ERR_FAIL_COND_V(err < 0, ERR_BUG); // Negative means bug
|
||||
|
||||
bh.compressed_size = strm.total_out - total_out_before;
|
||||
|
||||
//package->store_buffer(strm_out.ptr(), strm.total_out - total_out_before);
|
||||
int start = file_buffer.size();
|
||||
file_buffer.resize(file_buffer.size() + bh.compressed_size);
|
||||
for (uint64_t i = 0; i < bh.compressed_size; i++) {
|
||||
file_buffer.write[start + i] = strm_out[i];
|
||||
}
|
||||
} else {
|
||||
bh.compressed_size = block_size;
|
||||
//package->store_buffer(strm_in.ptr(), block_size);
|
||||
int start = file_buffer.size();
|
||||
file_buffer.resize(file_buffer.size() + block_size);
|
||||
for (uint64_t i = 0; i < bh.compressed_size; i++) {
|
||||
file_buffer.write[start + i] = strm_in[i];
|
||||
}
|
||||
}
|
||||
|
||||
meta.hashes.push_back(bh);
|
||||
|
||||
step += block_size;
|
||||
}
|
||||
|
||||
if (p_compress) {
|
||||
strm.avail_in = 0;
|
||||
strm.avail_out = strm_out.size();
|
||||
strm.next_in = (uint8_t *)strm_in.ptr();
|
||||
strm.next_out = strm_out.ptrw();
|
||||
|
||||
int total_out_before = strm.total_out;
|
||||
|
||||
deflate(&strm, Z_FINISH);
|
||||
|
||||
//package->store_buffer(strm_out.ptr(), strm.total_out - total_out_before);
|
||||
int start = file_buffer.size();
|
||||
file_buffer.resize(file_buffer.size() + (strm.total_out - total_out_before));
|
||||
for (uint64_t i = 0; i < (strm.total_out - total_out_before); i++) {
|
||||
file_buffer.write[start + i] = strm_out[i];
|
||||
}
|
||||
|
||||
deflateEnd(&strm);
|
||||
meta.compressed_size = strm.total_out;
|
||||
|
||||
} else {
|
||||
meta.compressed_size = p_len;
|
||||
}
|
||||
|
||||
// Calculate file CRC-32
|
||||
uLong crc = crc32(0L, Z_NULL, 0);
|
||||
crc = crc32(crc, p_buffer, p_len);
|
||||
meta.file_crc32 = crc;
|
||||
|
||||
// Create file header
|
||||
Vector<uint8_t> file_header = make_file_header(meta);
|
||||
meta.lfh_size = file_header.size();
|
||||
|
||||
// Store the header and file;
|
||||
package->store_buffer(file_header.ptr(), file_header.size());
|
||||
package->store_buffer(file_buffer.ptr(), file_buffer.size());
|
||||
|
||||
file_metadata.push_back(meta);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void AppxPackager::finish() {
|
||||
// Create and add block map file
|
||||
EditorNode::progress_task_step("export", "Creating block map...", 4);
|
||||
|
||||
const String &tmp_blockmap_file_path = EditorPaths::get_singleton()->get_cache_dir().plus_file("tmpblockmap.xml");
|
||||
make_block_map(tmp_blockmap_file_path);
|
||||
|
||||
FileAccess *blockmap_file = FileAccess::open(tmp_blockmap_file_path, FileAccess::READ);
|
||||
Vector<uint8_t> blockmap_buffer;
|
||||
blockmap_buffer.resize(blockmap_file->get_length());
|
||||
|
||||
blockmap_file->get_buffer(blockmap_buffer.ptrw(), blockmap_buffer.size());
|
||||
|
||||
add_file("AppxBlockMap.xml", blockmap_buffer.ptr(), blockmap_buffer.size(), -1, -1, true);
|
||||
|
||||
blockmap_file->close();
|
||||
memdelete(blockmap_file);
|
||||
|
||||
// Add content types
|
||||
|
||||
EditorNode::progress_task_step("export", "Setting content types...", 5);
|
||||
|
||||
const String &tmp_content_types_file_path = EditorPaths::get_singleton()->get_cache_dir().plus_file("tmpcontenttypes.xml");
|
||||
make_content_types(tmp_content_types_file_path);
|
||||
|
||||
FileAccess *types_file = FileAccess::open(tmp_content_types_file_path, FileAccess::READ);
|
||||
Vector<uint8_t> types_buffer;
|
||||
types_buffer.resize(types_file->get_length());
|
||||
|
||||
types_file->get_buffer(types_buffer.ptrw(), types_buffer.size());
|
||||
|
||||
add_file("[Content_Types].xml", types_buffer.ptr(), types_buffer.size(), -1, -1, true);
|
||||
|
||||
types_file->close();
|
||||
memdelete(types_file);
|
||||
|
||||
// Cleanup generated files.
|
||||
DirAccess::remove_file_or_error(tmp_blockmap_file_path);
|
||||
DirAccess::remove_file_or_error(tmp_content_types_file_path);
|
||||
|
||||
// Pre-process central directory before signing
|
||||
for (int i = 0; i < file_metadata.size(); i++) {
|
||||
store_central_dir_header(file_metadata[i]);
|
||||
}
|
||||
|
||||
// Write central directory
|
||||
EditorNode::progress_task_step("export", "Finishing package...", 6);
|
||||
central_dir_offset = package->get_position();
|
||||
package->store_buffer(central_dir_data.ptr(), central_dir_data.size());
|
||||
|
||||
// End record
|
||||
end_of_central_dir_offset = package->get_position();
|
||||
Vector<uint8_t> end_record = make_end_of_central_record();
|
||||
package->store_buffer(end_record.ptr(), end_record.size());
|
||||
|
||||
package->close();
|
||||
memdelete(package);
|
||||
package = nullptr;
|
||||
}
|
||||
|
||||
AppxPackager::AppxPackager() {}
|
||||
|
||||
AppxPackager::~AppxPackager() {}
|
150
platform/uwp/export/app_packager.h
Normal file
150
platform/uwp/export/app_packager.h
Normal file
@ -0,0 +1,150 @@
|
||||
/*************************************************************************/
|
||||
/* app_packager.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef UWP_APP_PACKAGER_H
|
||||
#define UWP_APP_PACKAGER_H
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/core_bind.h"
|
||||
#include "core/crypto/crypto_core.h"
|
||||
#include "core/io/dir_access.h"
|
||||
#include "core/io/file_access.h"
|
||||
#include "core/io/marshalls.h"
|
||||
#include "core/io/zip_io.h"
|
||||
#include "core/object/class_db.h"
|
||||
#include "core/version.h"
|
||||
#include "editor/editor_export.h"
|
||||
#include "editor/editor_node.h"
|
||||
|
||||
#include "thirdparty/minizip/unzip.h"
|
||||
#include "thirdparty/minizip/zip.h"
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
class AppxPackager {
|
||||
enum {
|
||||
FILE_HEADER_MAGIC = 0x04034b50,
|
||||
DATA_DESCRIPTOR_MAGIC = 0x08074b50,
|
||||
CENTRAL_DIR_MAGIC = 0x02014b50,
|
||||
END_OF_CENTRAL_DIR_MAGIC = 0x06054b50,
|
||||
ZIP64_END_OF_CENTRAL_DIR_MAGIC = 0x06064b50,
|
||||
ZIP64_END_DIR_LOCATOR_MAGIC = 0x07064b50,
|
||||
P7X_SIGNATURE = 0x58434b50,
|
||||
ZIP64_HEADER_ID = 0x0001,
|
||||
ZIP_VERSION = 20,
|
||||
ZIP_ARCHIVE_VERSION = 45,
|
||||
GENERAL_PURPOSE = 0x00,
|
||||
BASE_FILE_HEADER_SIZE = 30,
|
||||
DATA_DESCRIPTOR_SIZE = 24,
|
||||
BASE_CENTRAL_DIR_SIZE = 46,
|
||||
EXTRA_FIELD_LENGTH = 28,
|
||||
ZIP64_HEADER_SIZE = 24,
|
||||
ZIP64_END_OF_CENTRAL_DIR_SIZE = (56 - 12),
|
||||
END_OF_CENTRAL_DIR_SIZE = 42,
|
||||
BLOCK_SIZE = 65536,
|
||||
};
|
||||
|
||||
struct BlockHash {
|
||||
String base64_hash;
|
||||
size_t compressed_size = 0;
|
||||
};
|
||||
|
||||
struct FileMeta {
|
||||
String name;
|
||||
int lfh_size = 0;
|
||||
bool compressed = false;
|
||||
size_t compressed_size = 0;
|
||||
size_t uncompressed_size = 0;
|
||||
Vector<BlockHash> hashes;
|
||||
uLong file_crc32 = 0;
|
||||
ZPOS64_T zip_offset = 0;
|
||||
};
|
||||
|
||||
String progress_task;
|
||||
FileAccess *package = nullptr;
|
||||
|
||||
Set<String> mime_types;
|
||||
|
||||
Vector<FileMeta> file_metadata;
|
||||
|
||||
ZPOS64_T central_dir_offset;
|
||||
ZPOS64_T end_of_central_dir_offset;
|
||||
Vector<uint8_t> central_dir_data;
|
||||
|
||||
String hash_block(const uint8_t *p_block_data, size_t p_block_len);
|
||||
|
||||
void make_block_map(const String &p_path);
|
||||
void make_content_types(const String &p_path);
|
||||
|
||||
_FORCE_INLINE_ unsigned int buf_put_int16(uint16_t p_val, uint8_t *p_buf) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
*p_buf++ = (p_val >> (i * 8)) & 0xFF;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ unsigned int buf_put_int32(uint32_t p_val, uint8_t *p_buf) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
*p_buf++ = (p_val >> (i * 8)) & 0xFF;
|
||||
}
|
||||
return 4;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ unsigned int buf_put_int64(uint64_t p_val, uint8_t *p_buf) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
*p_buf++ = (p_val >> (i * 8)) & 0xFF;
|
||||
}
|
||||
return 8;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ unsigned int buf_put_string(String p_val, uint8_t *p_buf) {
|
||||
for (int i = 0; i < p_val.length(); i++) {
|
||||
*p_buf++ = p_val.utf8().get(i);
|
||||
}
|
||||
return p_val.length();
|
||||
}
|
||||
|
||||
Vector<uint8_t> make_file_header(FileMeta p_file_meta);
|
||||
void store_central_dir_header(const FileMeta &p_file, bool p_do_hash = true);
|
||||
Vector<uint8_t> make_end_of_central_record();
|
||||
|
||||
String content_type(String p_extension);
|
||||
|
||||
public:
|
||||
void set_progress_task(String p_task) { progress_task = p_task; }
|
||||
void init(FileAccess *p_fa);
|
||||
Error add_file(String p_file_name, const uint8_t *p_buffer, size_t p_len, int p_file_no, int p_total_files, bool p_compress = false);
|
||||
void finish();
|
||||
|
||||
AppxPackager();
|
||||
~AppxPackager();
|
||||
};
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
498
platform/uwp/export/export_plugin.cpp
Normal file
498
platform/uwp/export/export_plugin.cpp
Normal file
@ -0,0 +1,498 @@
|
||||
/*************************************************************************/
|
||||
/* export_plugin.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "export_plugin.h"
|
||||
|
||||
#include "platform/uwp/logo.gen.h"
|
||||
|
||||
String EditorExportPlatformUWP::get_name() const {
|
||||
return "UWP";
|
||||
}
|
||||
String EditorExportPlatformUWP::get_os_name() const {
|
||||
return "UWP";
|
||||
}
|
||||
|
||||
List<String> EditorExportPlatformUWP::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
|
||||
List<String> list;
|
||||
list.push_back("appx");
|
||||
return list;
|
||||
}
|
||||
|
||||
Ref<Texture2D> EditorExportPlatformUWP::get_logo() const {
|
||||
return logo;
|
||||
}
|
||||
|
||||
void EditorExportPlatformUWP::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) {
|
||||
r_features->push_back("s3tc");
|
||||
r_features->push_back("etc");
|
||||
switch ((int)p_preset->get("architecture/target")) {
|
||||
case EditorExportPlatformUWP::ARM: {
|
||||
r_features->push_back("arm");
|
||||
} break;
|
||||
case EditorExportPlatformUWP::X86: {
|
||||
r_features->push_back("32");
|
||||
} break;
|
||||
case EditorExportPlatformUWP::X64: {
|
||||
r_features->push_back("64");
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void EditorExportPlatformUWP::get_export_options(List<ExportOption> *r_options) {
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
|
||||
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "architecture/target", PROPERTY_HINT_ENUM, "arm,x86,x64"), 1));
|
||||
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "command_line/extra_args"), ""));
|
||||
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/display_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/short_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/unique_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game.Name"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/description"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/publisher", PROPERTY_HINT_PLACEHOLDER_TEXT, "CN=CompanyName"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/publisher_display_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Company Name"), ""));
|
||||
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "identity/product_guid", PROPERTY_HINT_PLACEHOLDER_TEXT, "00000000-0000-0000-0000-000000000000"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "identity/publisher_guid", PROPERTY_HINT_PLACEHOLDER_TEXT, "00000000-0000-0000-0000-000000000000"), ""));
|
||||
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "signing/certificate", PROPERTY_HINT_GLOBAL_FILE, "*.pfx"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "signing/password"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "signing/algorithm", PROPERTY_HINT_ENUM, "MD5,SHA1,SHA256"), 2));
|
||||
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "version/major"), 1));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "version/minor"), 0));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "version/build"), 0));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "version/revision"), 0));
|
||||
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "orientation/landscape"), true));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "orientation/portrait"), true));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "orientation/landscape_flipped"), true));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "orientation/portrait_flipped"), true));
|
||||
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "images/background_color"), "transparent"));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::OBJECT, "images/store_logo", PROPERTY_HINT_RESOURCE_TYPE, "StreamTexture2D"), Variant()));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::OBJECT, "images/square44x44_logo", PROPERTY_HINT_RESOURCE_TYPE, "StreamTexture2D"), Variant()));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::OBJECT, "images/square71x71_logo", PROPERTY_HINT_RESOURCE_TYPE, "StreamTexture2D"), Variant()));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::OBJECT, "images/square150x150_logo", PROPERTY_HINT_RESOURCE_TYPE, "StreamTexture2D"), Variant()));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::OBJECT, "images/square310x310_logo", PROPERTY_HINT_RESOURCE_TYPE, "StreamTexture2D"), Variant()));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::OBJECT, "images/wide310x150_logo", PROPERTY_HINT_RESOURCE_TYPE, "StreamTexture2D"), Variant()));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::OBJECT, "images/splash_screen", PROPERTY_HINT_RESOURCE_TYPE, "StreamTexture2D"), Variant()));
|
||||
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "tiles/show_name_on_square150x150"), false));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "tiles/show_name_on_wide310x150"), false));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "tiles/show_name_on_square310x310"), false));
|
||||
|
||||
// Capabilities
|
||||
const char **basic = uwp_capabilities;
|
||||
while (*basic) {
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/" + String(*basic)), false));
|
||||
basic++;
|
||||
}
|
||||
|
||||
const char **uap = uwp_uap_capabilities;
|
||||
while (*uap) {
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/" + String(*uap)), false));
|
||||
uap++;
|
||||
}
|
||||
|
||||
const char **device = uwp_device_capabilities;
|
||||
while (*device) {
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/" + String(*device)), false));
|
||||
device++;
|
||||
}
|
||||
}
|
||||
|
||||
bool EditorExportPlatformUWP::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
|
||||
String err;
|
||||
bool valid = false;
|
||||
|
||||
// Look for export templates (first official, and if defined custom templates).
|
||||
|
||||
Platform arch = (Platform)(int)(p_preset->get("architecture/target"));
|
||||
String platform_infix;
|
||||
switch (arch) {
|
||||
case EditorExportPlatformUWP::ARM: {
|
||||
platform_infix = "arm";
|
||||
} break;
|
||||
case EditorExportPlatformUWP::X86: {
|
||||
platform_infix = "x86";
|
||||
} break;
|
||||
case EditorExportPlatformUWP::X64: {
|
||||
platform_infix = "x64";
|
||||
} break;
|
||||
}
|
||||
|
||||
bool dvalid = exists_export_template("uwp_" + platform_infix + "_debug.zip", &err);
|
||||
bool rvalid = exists_export_template("uwp_" + platform_infix + "_release.zip", &err);
|
||||
|
||||
if (p_preset->get("custom_template/debug") != "") {
|
||||
dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
|
||||
if (!dvalid) {
|
||||
err += TTR("Custom debug template not found.") + "\n";
|
||||
}
|
||||
}
|
||||
if (p_preset->get("custom_template/release") != "") {
|
||||
rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
|
||||
if (!rvalid) {
|
||||
err += TTR("Custom release template not found.") + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
valid = dvalid || rvalid;
|
||||
r_missing_templates = !valid;
|
||||
|
||||
// Validate the rest of the configuration.
|
||||
|
||||
if (!_valid_resource_name(p_preset->get("package/short_name"))) {
|
||||
valid = false;
|
||||
err += TTR("Invalid package short name.") + "\n";
|
||||
}
|
||||
|
||||
if (!_valid_resource_name(p_preset->get("package/unique_name"))) {
|
||||
valid = false;
|
||||
err += TTR("Invalid package unique name.") + "\n";
|
||||
}
|
||||
|
||||
if (!_valid_resource_name(p_preset->get("package/publisher_display_name"))) {
|
||||
valid = false;
|
||||
err += TTR("Invalid package publisher display name.") + "\n";
|
||||
}
|
||||
|
||||
if (!_valid_guid(p_preset->get("identity/product_guid"))) {
|
||||
valid = false;
|
||||
err += TTR("Invalid product GUID.") + "\n";
|
||||
}
|
||||
|
||||
if (!_valid_guid(p_preset->get("identity/publisher_guid"))) {
|
||||
valid = false;
|
||||
err += TTR("Invalid publisher GUID.") + "\n";
|
||||
}
|
||||
|
||||
if (!_valid_bgcolor(p_preset->get("images/background_color"))) {
|
||||
valid = false;
|
||||
err += TTR("Invalid background color.") + "\n";
|
||||
}
|
||||
|
||||
if (!p_preset->get("images/store_logo").is_zero() && !_valid_image((Object::cast_to<StreamTexture2D>((Object *)p_preset->get("images/store_logo"))), 50, 50)) {
|
||||
valid = false;
|
||||
err += TTR("Invalid Store Logo image dimensions (should be 50x50).") + "\n";
|
||||
}
|
||||
|
||||
if (!p_preset->get("images/square44x44_logo").is_zero() && !_valid_image((Object::cast_to<StreamTexture2D>((Object *)p_preset->get("images/square44x44_logo"))), 44, 44)) {
|
||||
valid = false;
|
||||
err += TTR("Invalid square 44x44 logo image dimensions (should be 44x44).") + "\n";
|
||||
}
|
||||
|
||||
if (!p_preset->get("images/square71x71_logo").is_zero() && !_valid_image((Object::cast_to<StreamTexture2D>((Object *)p_preset->get("images/square71x71_logo"))), 71, 71)) {
|
||||
valid = false;
|
||||
err += TTR("Invalid square 71x71 logo image dimensions (should be 71x71).") + "\n";
|
||||
}
|
||||
|
||||
if (!p_preset->get("images/square150x150_logo").is_zero() && !_valid_image((Object::cast_to<StreamTexture2D>((Object *)p_preset->get("images/square150x150_logo"))), 150, 150)) {
|
||||
valid = false;
|
||||
err += TTR("Invalid square 150x150 logo image dimensions (should be 150x150).") + "\n";
|
||||
}
|
||||
|
||||
if (!p_preset->get("images/square310x310_logo").is_zero() && !_valid_image((Object::cast_to<StreamTexture2D>((Object *)p_preset->get("images/square310x310_logo"))), 310, 310)) {
|
||||
valid = false;
|
||||
err += TTR("Invalid square 310x310 logo image dimensions (should be 310x310).") + "\n";
|
||||
}
|
||||
|
||||
if (!p_preset->get("images/wide310x150_logo").is_zero() && !_valid_image((Object::cast_to<StreamTexture2D>((Object *)p_preset->get("images/wide310x150_logo"))), 310, 150)) {
|
||||
valid = false;
|
||||
err += TTR("Invalid wide 310x150 logo image dimensions (should be 310x150).") + "\n";
|
||||
}
|
||||
|
||||
if (!p_preset->get("images/splash_screen").is_zero() && !_valid_image((Object::cast_to<StreamTexture2D>((Object *)p_preset->get("images/splash_screen"))), 620, 300)) {
|
||||
valid = false;
|
||||
err += TTR("Invalid splash screen image dimensions (should be 620x300).") + "\n";
|
||||
}
|
||||
|
||||
r_error = err;
|
||||
return valid;
|
||||
}
|
||||
|
||||
Error EditorExportPlatformUWP::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
|
||||
ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
|
||||
|
||||
String src_appx;
|
||||
|
||||
EditorProgress ep("export", "Exporting for UWP", 7, true);
|
||||
|
||||
if (p_debug) {
|
||||
src_appx = p_preset->get("custom_template/debug");
|
||||
} else {
|
||||
src_appx = p_preset->get("custom_template/release");
|
||||
}
|
||||
|
||||
src_appx = src_appx.strip_edges();
|
||||
|
||||
Platform arch = (Platform)(int)p_preset->get("architecture/target");
|
||||
|
||||
if (src_appx == "") {
|
||||
String err, infix;
|
||||
switch (arch) {
|
||||
case ARM: {
|
||||
infix = "_arm_";
|
||||
} break;
|
||||
case X86: {
|
||||
infix = "_x86_";
|
||||
} break;
|
||||
case X64: {
|
||||
infix = "_x64_";
|
||||
} break;
|
||||
}
|
||||
if (p_debug) {
|
||||
src_appx = find_export_template("uwp" + infix + "debug.zip", &err);
|
||||
} else {
|
||||
src_appx = find_export_template("uwp" + infix + "release.zip", &err);
|
||||
}
|
||||
if (src_appx == "") {
|
||||
EditorNode::add_io_error(err);
|
||||
return ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
if (!DirAccess::exists(p_path.get_base_dir())) {
|
||||
return ERR_FILE_BAD_PATH;
|
||||
}
|
||||
|
||||
Error err = OK;
|
||||
|
||||
FileAccess *fa_pack = FileAccess::open(p_path, FileAccess::WRITE, &err);
|
||||
ERR_FAIL_COND_V_MSG(err != OK, ERR_CANT_CREATE, "Cannot create file '" + p_path + "'.");
|
||||
|
||||
AppxPackager packager;
|
||||
packager.init(fa_pack);
|
||||
|
||||
FileAccess *src_f = nullptr;
|
||||
zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
|
||||
|
||||
if (ep.step("Creating package...", 0)) {
|
||||
return ERR_SKIP;
|
||||
}
|
||||
|
||||
unzFile pkg = unzOpen2(src_appx.utf8().get_data(), &io);
|
||||
|
||||
if (!pkg) {
|
||||
EditorNode::add_io_error("Could not find template appx to export:\n" + src_appx);
|
||||
return ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
int ret = unzGoToFirstFile(pkg);
|
||||
|
||||
if (ep.step("Copying template files...", 1)) {
|
||||
return ERR_SKIP;
|
||||
}
|
||||
|
||||
EditorNode::progress_add_task("template_files", "Template files", 100);
|
||||
packager.set_progress_task("template_files");
|
||||
|
||||
int template_files_amount = 9;
|
||||
int template_file_no = 1;
|
||||
|
||||
while (ret == UNZ_OK) {
|
||||
// get file name
|
||||
unz_file_info info;
|
||||
char fname[16834];
|
||||
ret = unzGetCurrentFileInfo(pkg, &info, fname, 16834, nullptr, 0, nullptr, 0);
|
||||
|
||||
String path = fname;
|
||||
|
||||
if (path.ends_with("/")) {
|
||||
// Ignore directories
|
||||
ret = unzGoToNextFile(pkg);
|
||||
continue;
|
||||
}
|
||||
|
||||
Vector<uint8_t> data;
|
||||
bool do_read = true;
|
||||
|
||||
if (path.begins_with("Assets/")) {
|
||||
path = path.replace(".scale-100", "");
|
||||
|
||||
data = _get_image_data(p_preset, path);
|
||||
if (data.size() > 0) {
|
||||
do_read = false;
|
||||
}
|
||||
}
|
||||
|
||||
//read
|
||||
if (do_read) {
|
||||
data.resize(info.uncompressed_size);
|
||||
unzOpenCurrentFile(pkg);
|
||||
unzReadCurrentFile(pkg, data.ptrw(), data.size());
|
||||
unzCloseCurrentFile(pkg);
|
||||
}
|
||||
|
||||
if (path == "AppxManifest.xml") {
|
||||
data = _fix_manifest(p_preset, data, p_flags & (DEBUG_FLAG_DUMB_CLIENT | DEBUG_FLAG_REMOTE_DEBUG));
|
||||
}
|
||||
|
||||
print_line("ADDING: " + path);
|
||||
|
||||
err = packager.add_file(path, data.ptr(), data.size(), template_file_no++, template_files_amount, _should_compress_asset(path, data));
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
ret = unzGoToNextFile(pkg);
|
||||
}
|
||||
|
||||
EditorNode::progress_end_task("template_files");
|
||||
|
||||
if (ep.step("Creating command line...", 2)) {
|
||||
return ERR_SKIP;
|
||||
}
|
||||
|
||||
Vector<String> cl = ((String)p_preset->get("command_line/extra_args")).strip_edges().split(" ");
|
||||
for (int i = 0; i < cl.size(); i++) {
|
||||
if (cl[i].strip_edges().length() == 0) {
|
||||
cl.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(p_flags & DEBUG_FLAG_DUMB_CLIENT)) {
|
||||
cl.push_back("--path");
|
||||
cl.push_back("game");
|
||||
}
|
||||
|
||||
gen_export_flags(cl, p_flags);
|
||||
|
||||
// Command line file
|
||||
Vector<uint8_t> clf;
|
||||
|
||||
// Argc
|
||||
clf.resize(4);
|
||||
encode_uint32(cl.size(), clf.ptrw());
|
||||
|
||||
for (int i = 0; i < cl.size(); i++) {
|
||||
CharString txt = cl[i].utf8();
|
||||
int base = clf.size();
|
||||
clf.resize(base + 4 + txt.length());
|
||||
encode_uint32(txt.length(), &clf.write[base]);
|
||||
memcpy(&clf.write[base + 4], txt.ptr(), txt.length());
|
||||
print_line(itos(i) + " param: " + cl[i]);
|
||||
}
|
||||
|
||||
err = packager.add_file("__cl__.cl", clf.ptr(), clf.size(), -1, -1, false);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (ep.step("Adding project files...", 3)) {
|
||||
return ERR_SKIP;
|
||||
}
|
||||
|
||||
EditorNode::progress_add_task("project_files", "Project Files", 100);
|
||||
packager.set_progress_task("project_files");
|
||||
|
||||
err = export_project_files(p_preset, save_appx_file, &packager);
|
||||
|
||||
EditorNode::progress_end_task("project_files");
|
||||
|
||||
if (ep.step("Closing package...", 7)) {
|
||||
return ERR_SKIP;
|
||||
}
|
||||
|
||||
unzClose(pkg);
|
||||
|
||||
packager.finish();
|
||||
|
||||
#ifdef WINDOWS_ENABLED
|
||||
// Sign with signtool
|
||||
String signtool_path = EditorSettings::get_singleton()->get("export/uwp/signtool");
|
||||
if (signtool_path == String()) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
if (!FileAccess::exists(signtool_path)) {
|
||||
ERR_PRINT("Could not find signtool executable at " + signtool_path + ", aborting.");
|
||||
return ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
static String algs[] = { "MD5", "SHA1", "SHA256" };
|
||||
|
||||
String cert_path = EditorSettings::get_singleton()->get("export/uwp/debug_certificate");
|
||||
String cert_pass = EditorSettings::get_singleton()->get("export/uwp/debug_password");
|
||||
int cert_alg = EditorSettings::get_singleton()->get("export/uwp/debug_algorithm");
|
||||
|
||||
if (!p_debug) {
|
||||
cert_path = p_preset->get("signing/certificate");
|
||||
cert_pass = p_preset->get("signing/password");
|
||||
cert_alg = p_preset->get("signing/algorithm");
|
||||
}
|
||||
|
||||
if (cert_path == String()) {
|
||||
return OK; // Certificate missing, don't try to sign
|
||||
}
|
||||
|
||||
if (!FileAccess::exists(cert_path)) {
|
||||
ERR_PRINT("Could not find certificate file at " + cert_path + ", aborting.");
|
||||
return ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (cert_alg < 0 || cert_alg > 2) {
|
||||
ERR_PRINT("Invalid certificate algorithm " + itos(cert_alg) + ", aborting.");
|
||||
return ERR_INVALID_DATA;
|
||||
}
|
||||
|
||||
List<String> args;
|
||||
args.push_back("sign");
|
||||
args.push_back("/fd");
|
||||
args.push_back(algs[cert_alg]);
|
||||
args.push_back("/a");
|
||||
args.push_back("/f");
|
||||
args.push_back(cert_path);
|
||||
args.push_back("/p");
|
||||
args.push_back(cert_pass);
|
||||
args.push_back(p_path);
|
||||
|
||||
OS::get_singleton()->execute(signtool_path, args);
|
||||
#endif // WINDOWS_ENABLED
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void EditorExportPlatformUWP::get_platform_features(List<String> *r_features) {
|
||||
r_features->push_back("pc");
|
||||
r_features->push_back("UWP");
|
||||
}
|
||||
|
||||
void EditorExportPlatformUWP::resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) {
|
||||
}
|
||||
|
||||
EditorExportPlatformUWP::EditorExportPlatformUWP() {
|
||||
Ref<Image> img = memnew(Image(_uwp_logo));
|
||||
logo.instantiate();
|
||||
logo->create_from_image(img);
|
||||
}
|
448
platform/uwp/export/export_plugin.h
Normal file
448
platform/uwp/export/export_plugin.h
Normal file
@ -0,0 +1,448 @@
|
||||
/*************************************************************************/
|
||||
/* export_plugin.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef UWP_EXPORT_PLUGIN_H
|
||||
#define UWP_EXPORT_PLUGIN_H
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/crypto/crypto_core.h"
|
||||
#include "core/io/dir_access.h"
|
||||
#include "core/io/file_access.h"
|
||||
#include "core/io/marshalls.h"
|
||||
#include "core/io/zip_io.h"
|
||||
#include "core/object/class_db.h"
|
||||
#include "core/version.h"
|
||||
#include "editor/editor_export.h"
|
||||
#include "editor/editor_node.h"
|
||||
|
||||
#include "thirdparty/minizip/unzip.h"
|
||||
#include "thirdparty/minizip/zip.h"
|
||||
|
||||
#include "app_packager.h"
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
// Capabilities
|
||||
static const char *uwp_capabilities[] = {
|
||||
"allJoyn",
|
||||
"codeGeneration",
|
||||
"internetClient",
|
||||
"internetClientServer",
|
||||
"privateNetworkClientServer",
|
||||
nullptr
|
||||
};
|
||||
static const char *uwp_uap_capabilities[] = {
|
||||
"appointments",
|
||||
"blockedChatMessages",
|
||||
"chat",
|
||||
"contacts",
|
||||
"enterpriseAuthentication",
|
||||
"musicLibrary",
|
||||
"objects3D",
|
||||
"picturesLibrary",
|
||||
"phoneCall",
|
||||
"removableStorage",
|
||||
"sharedUserCertificates",
|
||||
"userAccountInformation",
|
||||
"videosLibrary",
|
||||
"voipCall",
|
||||
nullptr
|
||||
};
|
||||
static const char *uwp_device_capabilities[] = {
|
||||
"bluetooth",
|
||||
"location",
|
||||
"microphone",
|
||||
"proximity",
|
||||
"webcam",
|
||||
nullptr
|
||||
};
|
||||
|
||||
class EditorExportPlatformUWP : public EditorExportPlatform {
|
||||
GDCLASS(EditorExportPlatformUWP, EditorExportPlatform);
|
||||
|
||||
Ref<ImageTexture> logo;
|
||||
|
||||
enum Platform {
|
||||
ARM,
|
||||
X86,
|
||||
X64
|
||||
};
|
||||
|
||||
bool _valid_resource_name(const String &p_name) const {
|
||||
if (p_name.is_empty()) {
|
||||
return false;
|
||||
}
|
||||
if (p_name.ends_with(".")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static const char *invalid_names[] = {
|
||||
"CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7",
|
||||
"COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
|
||||
nullptr
|
||||
};
|
||||
|
||||
const char **t = invalid_names;
|
||||
while (*t) {
|
||||
if (p_name == *t) {
|
||||
return false;
|
||||
}
|
||||
t++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _valid_guid(const String &p_guid) const {
|
||||
Vector<String> parts = p_guid.split("-");
|
||||
|
||||
if (parts.size() != 5) {
|
||||
return false;
|
||||
}
|
||||
if (parts[0].length() != 8) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 1; i < 4; i++) {
|
||||
if (parts[i].length() != 4) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (parts[4].length() != 12) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _valid_bgcolor(const String &p_color) const {
|
||||
if (p_color.is_empty()) {
|
||||
return true;
|
||||
}
|
||||
if (p_color.begins_with("#") && p_color.is_valid_html_color()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Colors from https://msdn.microsoft.com/en-us/library/windows/apps/dn934817.aspx
|
||||
static const char *valid_colors[] = {
|
||||
"aliceBlue", "antiqueWhite", "aqua", "aquamarine", "azure", "beige",
|
||||
"bisque", "black", "blanchedAlmond", "blue", "blueViolet", "brown",
|
||||
"burlyWood", "cadetBlue", "chartreuse", "chocolate", "coral", "cornflowerBlue",
|
||||
"cornsilk", "crimson", "cyan", "darkBlue", "darkCyan", "darkGoldenrod",
|
||||
"darkGray", "darkGreen", "darkKhaki", "darkMagenta", "darkOliveGreen", "darkOrange",
|
||||
"darkOrchid", "darkRed", "darkSalmon", "darkSeaGreen", "darkSlateBlue", "darkSlateGray",
|
||||
"darkTurquoise", "darkViolet", "deepPink", "deepSkyBlue", "dimGray", "dodgerBlue",
|
||||
"firebrick", "floralWhite", "forestGreen", "fuchsia", "gainsboro", "ghostWhite",
|
||||
"gold", "goldenrod", "gray", "green", "greenYellow", "honeydew",
|
||||
"hotPink", "indianRed", "indigo", "ivory", "khaki", "lavender",
|
||||
"lavenderBlush", "lawnGreen", "lemonChiffon", "lightBlue", "lightCoral", "lightCyan",
|
||||
"lightGoldenrodYellow", "lightGreen", "lightGray", "lightPink", "lightSalmon", "lightSeaGreen",
|
||||
"lightSkyBlue", "lightSlateGray", "lightSteelBlue", "lightYellow", "lime", "limeGreen",
|
||||
"linen", "magenta", "maroon", "mediumAquamarine", "mediumBlue", "mediumOrchid",
|
||||
"mediumPurple", "mediumSeaGreen", "mediumSlateBlue", "mediumSpringGreen", "mediumTurquoise", "mediumVioletRed",
|
||||
"midnightBlue", "mintCream", "mistyRose", "moccasin", "navajoWhite", "navy",
|
||||
"oldLace", "olive", "oliveDrab", "orange", "orangeRed", "orchid",
|
||||
"paleGoldenrod", "paleGreen", "paleTurquoise", "paleVioletRed", "papayaWhip", "peachPuff",
|
||||
"peru", "pink", "plum", "powderBlue", "purple", "red",
|
||||
"rosyBrown", "royalBlue", "saddleBrown", "salmon", "sandyBrown", "seaGreen",
|
||||
"seaShell", "sienna", "silver", "skyBlue", "slateBlue", "slateGray",
|
||||
"snow", "springGreen", "steelBlue", "tan", "teal", "thistle",
|
||||
"tomato", "transparent", "turquoise", "violet", "wheat", "white",
|
||||
"whiteSmoke", "yellow", "yellowGreen",
|
||||
nullptr
|
||||
};
|
||||
|
||||
const char **color = valid_colors;
|
||||
|
||||
while (*color) {
|
||||
if (p_color == *color) {
|
||||
return true;
|
||||
}
|
||||
color++;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool _valid_image(const StreamTexture2D *p_image, int p_width, int p_height) const {
|
||||
if (!p_image) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Add resource creation or image rescaling to enable other scales:
|
||||
// 1.25, 1.5, 2.0
|
||||
return p_width == p_image->get_width() && p_height == p_image->get_height();
|
||||
}
|
||||
|
||||
Vector<uint8_t> _fix_manifest(const Ref<EditorExportPreset> &p_preset, const Vector<uint8_t> &p_template, bool p_give_internet) const {
|
||||
String result = String::utf8((const char *)p_template.ptr(), p_template.size());
|
||||
|
||||
result = result.replace("$godot_version$", VERSION_FULL_NAME);
|
||||
|
||||
result = result.replace("$identity_name$", p_preset->get("package/unique_name"));
|
||||
result = result.replace("$publisher$", p_preset->get("package/publisher"));
|
||||
|
||||
result = result.replace("$product_guid$", p_preset->get("identity/product_guid"));
|
||||
result = result.replace("$publisher_guid$", p_preset->get("identity/publisher_guid"));
|
||||
|
||||
String version = itos(p_preset->get("version/major")) + "." + itos(p_preset->get("version/minor")) + "." + itos(p_preset->get("version/build")) + "." + itos(p_preset->get("version/revision"));
|
||||
result = result.replace("$version_string$", version);
|
||||
|
||||
Platform arch = (Platform)(int)p_preset->get("architecture/target");
|
||||
String architecture = arch == ARM ? "arm" : (arch == X86 ? "x86" : "x64");
|
||||
result = result.replace("$architecture$", architecture);
|
||||
|
||||
result = result.replace("$display_name$", String(p_preset->get("package/display_name")).is_empty() ? (String)ProjectSettings::get_singleton()->get("application/config/name") : String(p_preset->get("package/display_name")));
|
||||
|
||||
result = result.replace("$publisher_display_name$", p_preset->get("package/publisher_display_name"));
|
||||
result = result.replace("$app_description$", p_preset->get("package/description"));
|
||||
result = result.replace("$bg_color$", p_preset->get("images/background_color"));
|
||||
result = result.replace("$short_name$", p_preset->get("package/short_name"));
|
||||
|
||||
String name_on_tiles = "";
|
||||
if ((bool)p_preset->get("tiles/show_name_on_square150x150")) {
|
||||
name_on_tiles += " <uap:ShowOn Tile=\"square150x150Logo\" />\n";
|
||||
}
|
||||
if ((bool)p_preset->get("tiles/show_name_on_wide310x150")) {
|
||||
name_on_tiles += " <uap:ShowOn Tile=\"wide310x150Logo\" />\n";
|
||||
}
|
||||
if ((bool)p_preset->get("tiles/show_name_on_square310x310")) {
|
||||
name_on_tiles += " <uap:ShowOn Tile=\"square310x310Logo\" />\n";
|
||||
}
|
||||
|
||||
String show_name_on_tiles = "";
|
||||
if (!name_on_tiles.is_empty()) {
|
||||
show_name_on_tiles = "<uap:ShowNameOnTiles>\n" + name_on_tiles + " </uap:ShowNameOnTiles>";
|
||||
}
|
||||
|
||||
result = result.replace("$name_on_tiles$", name_on_tiles);
|
||||
|
||||
String rotations = "";
|
||||
if ((bool)p_preset->get("orientation/landscape")) {
|
||||
rotations += " <uap:Rotation Preference=\"landscape\" />\n";
|
||||
}
|
||||
if ((bool)p_preset->get("orientation/portrait")) {
|
||||
rotations += " <uap:Rotation Preference=\"portrait\" />\n";
|
||||
}
|
||||
if ((bool)p_preset->get("orientation/landscape_flipped")) {
|
||||
rotations += " <uap:Rotation Preference=\"landscapeFlipped\" />\n";
|
||||
}
|
||||
if ((bool)p_preset->get("orientation/portrait_flipped")) {
|
||||
rotations += " <uap:Rotation Preference=\"portraitFlipped\" />\n";
|
||||
}
|
||||
|
||||
String rotation_preference = "";
|
||||
if (!rotations.is_empty()) {
|
||||
rotation_preference = "<uap:InitialRotationPreference>\n" + rotations + " </uap:InitialRotationPreference>";
|
||||
}
|
||||
|
||||
result = result.replace("$rotation_preference$", rotation_preference);
|
||||
|
||||
String capabilities_elements = "";
|
||||
const char **basic = uwp_capabilities;
|
||||
while (*basic) {
|
||||
if ((bool)p_preset->get("capabilities/" + String(*basic))) {
|
||||
capabilities_elements += " <Capability Name=\"" + String(*basic) + "\" />\n";
|
||||
}
|
||||
basic++;
|
||||
}
|
||||
const char **uap = uwp_uap_capabilities;
|
||||
while (*uap) {
|
||||
if ((bool)p_preset->get("capabilities/" + String(*uap))) {
|
||||
capabilities_elements += " <uap:Capability Name=\"" + String(*uap) + "\" />\n";
|
||||
}
|
||||
uap++;
|
||||
}
|
||||
const char **device = uwp_device_capabilities;
|
||||
while (*device) {
|
||||
if ((bool)p_preset->get("capabilities/" + String(*device))) {
|
||||
capabilities_elements += " <DeviceCapability Name=\"" + String(*device) + "\" />\n";
|
||||
}
|
||||
device++;
|
||||
}
|
||||
|
||||
if (!((bool)p_preset->get("capabilities/internetClient")) && p_give_internet) {
|
||||
capabilities_elements += " <Capability Name=\"internetClient\" />\n";
|
||||
}
|
||||
|
||||
String capabilities_string = "<Capabilities />";
|
||||
if (!capabilities_elements.is_empty()) {
|
||||
capabilities_string = "<Capabilities>\n" + capabilities_elements + " </Capabilities>";
|
||||
}
|
||||
|
||||
result = result.replace("$capabilities_place$", capabilities_string);
|
||||
|
||||
Vector<uint8_t> r_ret;
|
||||
r_ret.resize(result.length());
|
||||
|
||||
for (int i = 0; i < result.length(); i++) {
|
||||
r_ret.write[i] = result.utf8().get(i);
|
||||
}
|
||||
|
||||
return r_ret;
|
||||
}
|
||||
|
||||
Vector<uint8_t> _get_image_data(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
|
||||
Vector<uint8_t> data;
|
||||
StreamTexture2D *texture = nullptr;
|
||||
|
||||
if (p_path.find("StoreLogo") != -1) {
|
||||
texture = p_preset->get("images/store_logo").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/store_logo")));
|
||||
} else if (p_path.find("Square44x44Logo") != -1) {
|
||||
texture = p_preset->get("images/square44x44_logo").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/square44x44_logo")));
|
||||
} else if (p_path.find("Square71x71Logo") != -1) {
|
||||
texture = p_preset->get("images/square71x71_logo").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/square71x71_logo")));
|
||||
} else if (p_path.find("Square150x150Logo") != -1) {
|
||||
texture = p_preset->get("images/square150x150_logo").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/square150x150_logo")));
|
||||
} else if (p_path.find("Square310x310Logo") != -1) {
|
||||
texture = p_preset->get("images/square310x310_logo").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/square310x310_logo")));
|
||||
} else if (p_path.find("Wide310x150Logo") != -1) {
|
||||
texture = p_preset->get("images/wide310x150_logo").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/wide310x150_logo")));
|
||||
} else if (p_path.find("SplashScreen") != -1) {
|
||||
texture = p_preset->get("images/splash_screen").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/splash_screen")));
|
||||
} else {
|
||||
ERR_PRINT("Unable to load logo");
|
||||
}
|
||||
|
||||
if (!texture) {
|
||||
return data;
|
||||
}
|
||||
|
||||
String tmp_path = EditorPaths::get_singleton()->get_cache_dir().plus_file("uwp_tmp_logo.png");
|
||||
|
||||
Error err = texture->get_image()->save_png(tmp_path);
|
||||
|
||||
if (err != OK) {
|
||||
String err_string = "Couldn't save temp logo file.";
|
||||
|
||||
EditorNode::add_io_error(err_string);
|
||||
ERR_FAIL_V_MSG(data, err_string);
|
||||
}
|
||||
|
||||
FileAccess *f = FileAccess::open(tmp_path, FileAccess::READ, &err);
|
||||
|
||||
if (err != OK) {
|
||||
String err_string = "Couldn't open temp logo file.";
|
||||
// Cleanup generated file.
|
||||
DirAccess::remove_file_or_error(tmp_path);
|
||||
EditorNode::add_io_error(err_string);
|
||||
ERR_FAIL_V_MSG(data, err_string);
|
||||
}
|
||||
|
||||
data.resize(f->get_length());
|
||||
f->get_buffer(data.ptrw(), data.size());
|
||||
|
||||
f->close();
|
||||
memdelete(f);
|
||||
DirAccess::remove_file_or_error(tmp_path);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static bool _should_compress_asset(const String &p_path, const Vector<uint8_t> &p_data) {
|
||||
/* TODO: This was copied verbatim from Android export. It should be
|
||||
* refactored to the parent class and also be used for .zip export.
|
||||
*/
|
||||
|
||||
/*
|
||||
* By not compressing files with little or not benefit in doing so,
|
||||
* a performance gain is expected at runtime. Moreover, if the APK is
|
||||
* zip-aligned, assets stored as they are can be efficiently read by
|
||||
* Android by memory-mapping them.
|
||||
*/
|
||||
|
||||
// -- Unconditional uncompress to mimic AAPT plus some other
|
||||
|
||||
static const char *unconditional_compress_ext[] = {
|
||||
// From https://github.com/android/platform_frameworks_base/blob/master/tools/aapt/Package.cpp
|
||||
// These formats are already compressed, or don't compress well:
|
||||
".jpg", ".jpeg", ".png", ".gif",
|
||||
".wav", ".mp2", ".mp3", ".ogg", ".aac",
|
||||
".mpg", ".mpeg", ".mid", ".midi", ".smf", ".jet",
|
||||
".rtttl", ".imy", ".xmf", ".mp4", ".m4a",
|
||||
".m4v", ".3gp", ".3gpp", ".3g2", ".3gpp2",
|
||||
".amr", ".awb", ".wma", ".wmv",
|
||||
// Godot-specific:
|
||||
".webp", // Same reasoning as .png
|
||||
".cfb", // Don't let small config files slow-down startup
|
||||
".scn", // Binary scenes are usually already compressed
|
||||
".stex", // Streamable textures are usually already compressed
|
||||
// Trailer for easier processing
|
||||
nullptr
|
||||
};
|
||||
|
||||
for (const char **ext = unconditional_compress_ext; *ext; ++ext) {
|
||||
if (p_path.to_lower().ends_with(String(*ext))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// -- Compressed resource?
|
||||
|
||||
if (p_data.size() >= 4 && p_data[0] == 'R' && p_data[1] == 'S' && p_data[2] == 'C' && p_data[3] == 'C') {
|
||||
// Already compressed
|
||||
return false;
|
||||
}
|
||||
|
||||
// --- TODO: Decide on texture resources according to their image compression setting
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static Error save_appx_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key) {
|
||||
AppxPackager *packager = (AppxPackager *)p_userdata;
|
||||
String dst_path = p_path.replace_first("res://", "game/");
|
||||
|
||||
return packager->add_file(dst_path, p_data.ptr(), p_data.size(), p_file, p_total, _should_compress_asset(p_path, p_data));
|
||||
}
|
||||
|
||||
public:
|
||||
virtual String get_name() const override;
|
||||
virtual String get_os_name() const override;
|
||||
|
||||
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override;
|
||||
|
||||
virtual Ref<Texture2D> get_logo() const override;
|
||||
|
||||
virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) override;
|
||||
|
||||
virtual void get_export_options(List<ExportOption> *r_options) override;
|
||||
|
||||
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
|
||||
|
||||
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) override;
|
||||
|
||||
virtual void get_platform_features(List<String> *r_features) override;
|
||||
|
||||
virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) override;
|
||||
|
||||
EditorExportPlatformUWP();
|
||||
};
|
||||
|
||||
#endif
|
@ -28,317 +28,12 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/io/file_access.h"
|
||||
#include "core/os/os.h"
|
||||
#include "editor/editor_export.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "platform/windows/logo.gen.h"
|
||||
#include "export.h"
|
||||
|
||||
#include "export_plugin.h"
|
||||
|
||||
static Error fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size);
|
||||
|
||||
class EditorExportPlatformWindows : public EditorExportPlatformPC {
|
||||
void _rcedit_add_data(const Ref<EditorExportPreset> &p_preset, const String &p_path);
|
||||
Error _code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path);
|
||||
|
||||
public:
|
||||
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
|
||||
virtual Error sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path);
|
||||
virtual void get_export_options(List<ExportOption> *r_options);
|
||||
};
|
||||
|
||||
Error EditorExportPlatformWindows::sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path) {
|
||||
if (p_preset->get("codesign/enable")) {
|
||||
return _code_sign(p_preset, p_path);
|
||||
} else {
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
Error EditorExportPlatformWindows::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
|
||||
Error err = EditorExportPlatformPC::export_project(p_preset, p_debug, p_path, p_flags);
|
||||
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
_rcedit_add_data(p_preset, p_path);
|
||||
|
||||
if (p_preset->get("codesign/enable") && err == OK) {
|
||||
err = _code_sign(p_preset, p_path);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void EditorExportPlatformWindows::get_export_options(List<ExportOption> *r_options) {
|
||||
EditorExportPlatformPC::get_export_options(r_options);
|
||||
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/enable"), false));
|
||||
#ifdef WINDOWS_ENABLED
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/identity_type", PROPERTY_HINT_ENUM, "Select automatically,Use PKCS12 file (specify *.PFX/*.P12 file),Use certificate store (specify SHA1 hash)"), 0));
|
||||
#endif
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity", PROPERTY_HINT_GLOBAL_FILE, "*.pfx,*.p12"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/password"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/timestamp"), true));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/timestamp_server_url"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/digest_algorithm", PROPERTY_HINT_ENUM, "SHA1,SHA256"), 1));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/description"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "codesign/custom_options"), PackedStringArray()));
|
||||
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.ico"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "1.0.0"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "1.0.0"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/company_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Company Name"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_description"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/trademarks"), ""));
|
||||
}
|
||||
|
||||
void EditorExportPlatformWindows::_rcedit_add_data(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
|
||||
String rcedit_path = EditorSettings::get_singleton()->get("export/windows/rcedit");
|
||||
|
||||
if (rcedit_path == String()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!FileAccess::exists(rcedit_path)) {
|
||||
ERR_PRINT("Could not find rcedit executable at " + rcedit_path + ", no icon or app information data will be included.");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef WINDOWS_ENABLED
|
||||
// On non-Windows we need WINE to run rcedit
|
||||
String wine_path = EditorSettings::get_singleton()->get("export/windows/wine");
|
||||
|
||||
if (wine_path != String() && !FileAccess::exists(wine_path)) {
|
||||
ERR_PRINT("Could not find wine executable at " + wine_path + ", no icon or app information data will be included.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (wine_path == String()) {
|
||||
wine_path = "wine"; // try to run wine from PATH
|
||||
}
|
||||
#endif
|
||||
|
||||
String icon_path = ProjectSettings::get_singleton()->globalize_path(p_preset->get("application/icon"));
|
||||
String file_verion = p_preset->get("application/file_version");
|
||||
String product_version = p_preset->get("application/product_version");
|
||||
String company_name = p_preset->get("application/company_name");
|
||||
String product_name = p_preset->get("application/product_name");
|
||||
String file_description = p_preset->get("application/file_description");
|
||||
String copyright = p_preset->get("application/copyright");
|
||||
String trademarks = p_preset->get("application/trademarks");
|
||||
String comments = p_preset->get("application/comments");
|
||||
|
||||
List<String> args;
|
||||
args.push_back(p_path);
|
||||
if (icon_path != String()) {
|
||||
args.push_back("--set-icon");
|
||||
args.push_back(icon_path);
|
||||
}
|
||||
if (file_verion != String()) {
|
||||
args.push_back("--set-file-version");
|
||||
args.push_back(file_verion);
|
||||
}
|
||||
if (product_version != String()) {
|
||||
args.push_back("--set-product-version");
|
||||
args.push_back(product_version);
|
||||
}
|
||||
if (company_name != String()) {
|
||||
args.push_back("--set-version-string");
|
||||
args.push_back("CompanyName");
|
||||
args.push_back(company_name);
|
||||
}
|
||||
if (product_name != String()) {
|
||||
args.push_back("--set-version-string");
|
||||
args.push_back("ProductName");
|
||||
args.push_back(product_name);
|
||||
}
|
||||
if (file_description != String()) {
|
||||
args.push_back("--set-version-string");
|
||||
args.push_back("FileDescription");
|
||||
args.push_back(file_description);
|
||||
}
|
||||
if (copyright != String()) {
|
||||
args.push_back("--set-version-string");
|
||||
args.push_back("LegalCopyright");
|
||||
args.push_back(copyright);
|
||||
}
|
||||
if (trademarks != String()) {
|
||||
args.push_back("--set-version-string");
|
||||
args.push_back("LegalTrademarks");
|
||||
args.push_back(trademarks);
|
||||
}
|
||||
|
||||
#ifdef WINDOWS_ENABLED
|
||||
OS::get_singleton()->execute(rcedit_path, args);
|
||||
#else
|
||||
// On non-Windows we need WINE to run rcedit
|
||||
args.push_front(rcedit_path);
|
||||
OS::get_singleton()->execute(wine_path, args);
|
||||
#endif
|
||||
}
|
||||
|
||||
Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
|
||||
List<String> args;
|
||||
|
||||
#ifdef WINDOWS_ENABLED
|
||||
String signtool_path = EditorSettings::get_singleton()->get("export/windows/signtool");
|
||||
if (signtool_path != String() && !FileAccess::exists(signtool_path)) {
|
||||
ERR_PRINT("Could not find signtool executable at " + signtool_path + ", aborting.");
|
||||
return ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
if (signtool_path == String()) {
|
||||
signtool_path = "signtool"; // try to run signtool from PATH
|
||||
}
|
||||
#else
|
||||
String signtool_path = EditorSettings::get_singleton()->get("export/windows/osslsigncode");
|
||||
if (signtool_path != String() && !FileAccess::exists(signtool_path)) {
|
||||
ERR_PRINT("Could not find osslsigncode executable at " + signtool_path + ", aborting.");
|
||||
return ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
if (signtool_path == String()) {
|
||||
signtool_path = "osslsigncode"; // try to run signtool from PATH
|
||||
}
|
||||
#endif
|
||||
|
||||
args.push_back("sign");
|
||||
|
||||
//identity
|
||||
#ifdef WINDOWS_ENABLED
|
||||
int id_type = p_preset->get("codesign/identity_type");
|
||||
if (id_type == 0) { //auto select
|
||||
args.push_back("/a");
|
||||
} else if (id_type == 1) { //pkcs12
|
||||
if (p_preset->get("codesign/identity") != "") {
|
||||
args.push_back("/f");
|
||||
args.push_back(p_preset->get("codesign/identity"));
|
||||
} else {
|
||||
EditorNode::add_io_error("codesign: no identity found");
|
||||
return FAILED;
|
||||
}
|
||||
} else if (id_type == 2) { //Windows certificate store
|
||||
if (p_preset->get("codesign/identity") != "") {
|
||||
args.push_back("/sha1");
|
||||
args.push_back(p_preset->get("codesign/identity"));
|
||||
} else {
|
||||
EditorNode::add_io_error("codesign: no identity found");
|
||||
return FAILED;
|
||||
}
|
||||
} else {
|
||||
EditorNode::add_io_error("codesign: invalid identity type");
|
||||
return FAILED;
|
||||
}
|
||||
#else
|
||||
if (p_preset->get("codesign/identity") != "") {
|
||||
args.push_back("-pkcs12");
|
||||
args.push_back(p_preset->get("codesign/identity"));
|
||||
} else {
|
||||
EditorNode::add_io_error("codesign: no identity found");
|
||||
return FAILED;
|
||||
}
|
||||
#endif
|
||||
|
||||
//password
|
||||
if (p_preset->get("codesign/password") != "") {
|
||||
#ifdef WINDOWS_ENABLED
|
||||
args.push_back("/p");
|
||||
#else
|
||||
args.push_back("-pass");
|
||||
#endif
|
||||
args.push_back(p_preset->get("codesign/password"));
|
||||
}
|
||||
|
||||
//timestamp
|
||||
if (p_preset->get("codesign/timestamp")) {
|
||||
if (p_preset->get("codesign/timestamp_server") != "") {
|
||||
#ifdef WINDOWS_ENABLED
|
||||
args.push_back("/tr");
|
||||
args.push_back(p_preset->get("codesign/timestamp_server_url"));
|
||||
args.push_back("/td");
|
||||
if ((int)p_preset->get("codesign/digest_algorithm") == 0) {
|
||||
args.push_back("sha1");
|
||||
} else {
|
||||
args.push_back("sha256");
|
||||
}
|
||||
#else
|
||||
args.push_back("-ts");
|
||||
args.push_back(p_preset->get("codesign/timestamp_server_url"));
|
||||
#endif
|
||||
} else {
|
||||
EditorNode::add_io_error("codesign: invalid timestamp server");
|
||||
return FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
//digest
|
||||
#ifdef WINDOWS_ENABLED
|
||||
args.push_back("/fd");
|
||||
#else
|
||||
args.push_back("-h");
|
||||
#endif
|
||||
if ((int)p_preset->get("codesign/digest_algorithm") == 0) {
|
||||
args.push_back("sha1");
|
||||
} else {
|
||||
args.push_back("sha256");
|
||||
}
|
||||
|
||||
//description
|
||||
if (p_preset->get("codesign/description") != "") {
|
||||
#ifdef WINDOWS_ENABLED
|
||||
args.push_back("/d");
|
||||
#else
|
||||
args.push_back("-n");
|
||||
#endif
|
||||
args.push_back(p_preset->get("codesign/description"));
|
||||
}
|
||||
|
||||
//user options
|
||||
PackedStringArray user_args = p_preset->get("codesign/custom_options");
|
||||
for (int i = 0; i < user_args.size(); i++) {
|
||||
String user_arg = user_args[i].strip_edges();
|
||||
if (!user_arg.is_empty()) {
|
||||
args.push_back(user_arg);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef WINDOWS_ENABLED
|
||||
args.push_back("-in");
|
||||
#endif
|
||||
args.push_back(p_path);
|
||||
#ifndef WINDOWS_ENABLED
|
||||
args.push_back("-out");
|
||||
args.push_back(p_path + "_signed");
|
||||
#endif
|
||||
|
||||
String str;
|
||||
Error err = OS::get_singleton()->execute(signtool_path, args, &str, nullptr, true);
|
||||
ERR_FAIL_COND_V(err != OK, err);
|
||||
|
||||
print_line("codesign (" + p_path + "): " + str);
|
||||
#ifndef WINDOWS_ENABLED
|
||||
if (str.find("SignTool Error") != -1) {
|
||||
#else
|
||||
if (str.find("Failed") != -1) {
|
||||
#endif
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
#ifndef WINDOWS_ENABLED
|
||||
DirAccessRef tmp_dir = DirAccess::create_for_path(p_path.get_base_dir());
|
||||
|
||||
err = tmp_dir->remove(p_path);
|
||||
ERR_FAIL_COND_V(err != OK, err);
|
||||
|
||||
err = tmp_dir->rename(p_path + "_signed", p_path);
|
||||
ERR_FAIL_COND_V(err != OK, err);
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void register_windows_exporter() {
|
||||
EDITOR_DEF("export/windows/rcedit", "");
|
||||
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/windows/rcedit", PROPERTY_HINT_GLOBAL_FILE, "*.exe"));
|
||||
|
@ -28,4 +28,9 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef WINDOWS_EXPORT_H
|
||||
#define WINDOWS_EXPORT_H
|
||||
|
||||
void register_windows_exporter();
|
||||
|
||||
#endif
|
||||
|
323
platform/windows/export/export_plugin.cpp
Normal file
323
platform/windows/export/export_plugin.cpp
Normal file
@ -0,0 +1,323 @@
|
||||
/*************************************************************************/
|
||||
/* export_plugin.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "export_plugin.h"
|
||||
|
||||
Error EditorExportPlatformWindows::sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path) {
|
||||
if (p_preset->get("codesign/enable")) {
|
||||
return _code_sign(p_preset, p_path);
|
||||
} else {
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
Error EditorExportPlatformWindows::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
|
||||
Error err = EditorExportPlatformPC::export_project(p_preset, p_debug, p_path, p_flags);
|
||||
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
_rcedit_add_data(p_preset, p_path);
|
||||
|
||||
if (p_preset->get("codesign/enable") && err == OK) {
|
||||
err = _code_sign(p_preset, p_path);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void EditorExportPlatformWindows::get_export_options(List<ExportOption> *r_options) {
|
||||
EditorExportPlatformPC::get_export_options(r_options);
|
||||
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/enable"), false));
|
||||
#ifdef WINDOWS_ENABLED
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/identity_type", PROPERTY_HINT_ENUM, "Select automatically,Use PKCS12 file (specify *.PFX/*.P12 file),Use certificate store (specify SHA1 hash)"), 0));
|
||||
#endif
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity", PROPERTY_HINT_GLOBAL_FILE, "*.pfx,*.p12"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/password"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/timestamp"), true));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/timestamp_server_url"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/digest_algorithm", PROPERTY_HINT_ENUM, "SHA1,SHA256"), 1));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/description"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "codesign/custom_options"), PackedStringArray()));
|
||||
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.ico"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "1.0.0"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "1.0.0"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/company_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Company Name"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_description"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/trademarks"), ""));
|
||||
}
|
||||
|
||||
void EditorExportPlatformWindows::_rcedit_add_data(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
|
||||
String rcedit_path = EditorSettings::get_singleton()->get("export/windows/rcedit");
|
||||
|
||||
if (rcedit_path == String()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!FileAccess::exists(rcedit_path)) {
|
||||
ERR_PRINT("Could not find rcedit executable at " + rcedit_path + ", no icon or app information data will be included.");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef WINDOWS_ENABLED
|
||||
// On non-Windows we need WINE to run rcedit
|
||||
String wine_path = EditorSettings::get_singleton()->get("export/windows/wine");
|
||||
|
||||
if (wine_path != String() && !FileAccess::exists(wine_path)) {
|
||||
ERR_PRINT("Could not find wine executable at " + wine_path + ", no icon or app information data will be included.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (wine_path == String()) {
|
||||
wine_path = "wine"; // try to run wine from PATH
|
||||
}
|
||||
#endif
|
||||
|
||||
String icon_path = ProjectSettings::get_singleton()->globalize_path(p_preset->get("application/icon"));
|
||||
String file_verion = p_preset->get("application/file_version");
|
||||
String product_version = p_preset->get("application/product_version");
|
||||
String company_name = p_preset->get("application/company_name");
|
||||
String product_name = p_preset->get("application/product_name");
|
||||
String file_description = p_preset->get("application/file_description");
|
||||
String copyright = p_preset->get("application/copyright");
|
||||
String trademarks = p_preset->get("application/trademarks");
|
||||
String comments = p_preset->get("application/comments");
|
||||
|
||||
List<String> args;
|
||||
args.push_back(p_path);
|
||||
if (icon_path != String()) {
|
||||
args.push_back("--set-icon");
|
||||
args.push_back(icon_path);
|
||||
}
|
||||
if (file_verion != String()) {
|
||||
args.push_back("--set-file-version");
|
||||
args.push_back(file_verion);
|
||||
}
|
||||
if (product_version != String()) {
|
||||
args.push_back("--set-product-version");
|
||||
args.push_back(product_version);
|
||||
}
|
||||
if (company_name != String()) {
|
||||
args.push_back("--set-version-string");
|
||||
args.push_back("CompanyName");
|
||||
args.push_back(company_name);
|
||||
}
|
||||
if (product_name != String()) {
|
||||
args.push_back("--set-version-string");
|
||||
args.push_back("ProductName");
|
||||
args.push_back(product_name);
|
||||
}
|
||||
if (file_description != String()) {
|
||||
args.push_back("--set-version-string");
|
||||
args.push_back("FileDescription");
|
||||
args.push_back(file_description);
|
||||
}
|
||||
if (copyright != String()) {
|
||||
args.push_back("--set-version-string");
|
||||
args.push_back("LegalCopyright");
|
||||
args.push_back(copyright);
|
||||
}
|
||||
if (trademarks != String()) {
|
||||
args.push_back("--set-version-string");
|
||||
args.push_back("LegalTrademarks");
|
||||
args.push_back(trademarks);
|
||||
}
|
||||
|
||||
#ifdef WINDOWS_ENABLED
|
||||
OS::get_singleton()->execute(rcedit_path, args);
|
||||
#else
|
||||
// On non-Windows we need WINE to run rcedit
|
||||
args.push_front(rcedit_path);
|
||||
OS::get_singleton()->execute(wine_path, args);
|
||||
#endif
|
||||
}
|
||||
|
||||
Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
|
||||
List<String> args;
|
||||
|
||||
#ifdef WINDOWS_ENABLED
|
||||
String signtool_path = EditorSettings::get_singleton()->get("export/windows/signtool");
|
||||
if (signtool_path != String() && !FileAccess::exists(signtool_path)) {
|
||||
ERR_PRINT("Could not find signtool executable at " + signtool_path + ", aborting.");
|
||||
return ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
if (signtool_path == String()) {
|
||||
signtool_path = "signtool"; // try to run signtool from PATH
|
||||
}
|
||||
#else
|
||||
String signtool_path = EditorSettings::get_singleton()->get("export/windows/osslsigncode");
|
||||
if (signtool_path != String() && !FileAccess::exists(signtool_path)) {
|
||||
ERR_PRINT("Could not find osslsigncode executable at " + signtool_path + ", aborting.");
|
||||
return ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
if (signtool_path == String()) {
|
||||
signtool_path = "osslsigncode"; // try to run signtool from PATH
|
||||
}
|
||||
#endif
|
||||
|
||||
args.push_back("sign");
|
||||
|
||||
//identity
|
||||
#ifdef WINDOWS_ENABLED
|
||||
int id_type = p_preset->get("codesign/identity_type");
|
||||
if (id_type == 0) { //auto select
|
||||
args.push_back("/a");
|
||||
} else if (id_type == 1) { //pkcs12
|
||||
if (p_preset->get("codesign/identity") != "") {
|
||||
args.push_back("/f");
|
||||
args.push_back(p_preset->get("codesign/identity"));
|
||||
} else {
|
||||
EditorNode::add_io_error("codesign: no identity found");
|
||||
return FAILED;
|
||||
}
|
||||
} else if (id_type == 2) { //Windows certificate store
|
||||
if (p_preset->get("codesign/identity") != "") {
|
||||
args.push_back("/sha1");
|
||||
args.push_back(p_preset->get("codesign/identity"));
|
||||
} else {
|
||||
EditorNode::add_io_error("codesign: no identity found");
|
||||
return FAILED;
|
||||
}
|
||||
} else {
|
||||
EditorNode::add_io_error("codesign: invalid identity type");
|
||||
return FAILED;
|
||||
}
|
||||
#else
|
||||
if (p_preset->get("codesign/identity") != "") {
|
||||
args.push_back("-pkcs12");
|
||||
args.push_back(p_preset->get("codesign/identity"));
|
||||
} else {
|
||||
EditorNode::add_io_error("codesign: no identity found");
|
||||
return FAILED;
|
||||
}
|
||||
#endif
|
||||
|
||||
//password
|
||||
if (p_preset->get("codesign/password") != "") {
|
||||
#ifdef WINDOWS_ENABLED
|
||||
args.push_back("/p");
|
||||
#else
|
||||
args.push_back("-pass");
|
||||
#endif
|
||||
args.push_back(p_preset->get("codesign/password"));
|
||||
}
|
||||
|
||||
//timestamp
|
||||
if (p_preset->get("codesign/timestamp")) {
|
||||
if (p_preset->get("codesign/timestamp_server") != "") {
|
||||
#ifdef WINDOWS_ENABLED
|
||||
args.push_back("/tr");
|
||||
args.push_back(p_preset->get("codesign/timestamp_server_url"));
|
||||
args.push_back("/td");
|
||||
if ((int)p_preset->get("codesign/digest_algorithm") == 0) {
|
||||
args.push_back("sha1");
|
||||
} else {
|
||||
args.push_back("sha256");
|
||||
}
|
||||
#else
|
||||
args.push_back("-ts");
|
||||
args.push_back(p_preset->get("codesign/timestamp_server_url"));
|
||||
#endif
|
||||
} else {
|
||||
EditorNode::add_io_error("codesign: invalid timestamp server");
|
||||
return FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
//digest
|
||||
#ifdef WINDOWS_ENABLED
|
||||
args.push_back("/fd");
|
||||
#else
|
||||
args.push_back("-h");
|
||||
#endif
|
||||
if ((int)p_preset->get("codesign/digest_algorithm") == 0) {
|
||||
args.push_back("sha1");
|
||||
} else {
|
||||
args.push_back("sha256");
|
||||
}
|
||||
|
||||
//description
|
||||
if (p_preset->get("codesign/description") != "") {
|
||||
#ifdef WINDOWS_ENABLED
|
||||
args.push_back("/d");
|
||||
#else
|
||||
args.push_back("-n");
|
||||
#endif
|
||||
args.push_back(p_preset->get("codesign/description"));
|
||||
}
|
||||
|
||||
//user options
|
||||
PackedStringArray user_args = p_preset->get("codesign/custom_options");
|
||||
for (int i = 0; i < user_args.size(); i++) {
|
||||
String user_arg = user_args[i].strip_edges();
|
||||
if (!user_arg.is_empty()) {
|
||||
args.push_back(user_arg);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef WINDOWS_ENABLED
|
||||
args.push_back("-in");
|
||||
#endif
|
||||
args.push_back(p_path);
|
||||
#ifndef WINDOWS_ENABLED
|
||||
args.push_back("-out");
|
||||
args.push_back(p_path + "_signed");
|
||||
#endif
|
||||
|
||||
String str;
|
||||
Error err = OS::get_singleton()->execute(signtool_path, args, &str, nullptr, true);
|
||||
ERR_FAIL_COND_V(err != OK, err);
|
||||
|
||||
print_line("codesign (" + p_path + "): " + str);
|
||||
#ifndef WINDOWS_ENABLED
|
||||
if (str.find("SignTool Error") != -1) {
|
||||
#else
|
||||
if (str.find("Failed") != -1) {
|
||||
#endif
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
#ifndef WINDOWS_ENABLED
|
||||
DirAccessRef tmp_dir = DirAccess::create_for_path(p_path.get_base_dir());
|
||||
|
||||
err = tmp_dir->remove(p_path);
|
||||
ERR_FAIL_COND_V(err != OK, err);
|
||||
|
||||
err = tmp_dir->rename(p_path + "_signed", p_path);
|
||||
ERR_FAIL_COND_V(err != OK, err);
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
}
|
51
platform/windows/export/export_plugin.h
Normal file
51
platform/windows/export/export_plugin.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*************************************************************************/
|
||||
/* export_plugin.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef WINDOWS_EXPORT_PLUGIN_H
|
||||
#define WINDOWS_EXPORT_PLUGIN_H
|
||||
|
||||
#include "core/io/file_access.h"
|
||||
#include "core/os/os.h"
|
||||
#include "editor/editor_export.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "platform/windows/logo.gen.h"
|
||||
|
||||
class EditorExportPlatformWindows : public EditorExportPlatformPC {
|
||||
void _rcedit_add_data(const Ref<EditorExportPreset> &p_preset, const String &p_path);
|
||||
Error _code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path);
|
||||
|
||||
public:
|
||||
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
|
||||
virtual Error sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path);
|
||||
virtual void get_export_options(List<ExportOption> *r_options);
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user