summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
Diffstat (limited to 'platform')
-rw-r--r--platform/android/export/export.cpp90
-rw-r--r--platform/javascript/export/export.cpp13
-rw-r--r--platform/osx/export/export.cpp21
-rw-r--r--platform/uwp/export/export.cpp57
-rw-r--r--platform/x11/os_x11.cpp9
5 files changed, 109 insertions, 81 deletions
diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp
index dc0a63d171..16e49e8a38 100644
--- a/platform/android/export/export.cpp
+++ b/platform/android/export/export.cpp
@@ -32,6 +32,7 @@
#include "core/io/marshalls.h"
#include "core/io/zip_io.h"
+#include "core/os/dir_access.h"
#include "core/os/file_access.h"
#include "core/os/os.h"
#include "core/project_settings.h"
@@ -1398,8 +1399,9 @@ public:
return ERR_UNCONFIGURED;
}
- //export_temp
+ // Export_temp APK.
if (ep.step("Exporting APK", 0)) {
+ device_lock->unlock();
return ERR_SKIP;
}
@@ -1409,11 +1411,20 @@ public:
if (use_reverse)
p_debug_flags |= DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST;
- String export_to = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport.apk");
- Error err = export_project(p_preset, true, export_to, p_debug_flags);
- if (err) {
- device_lock->unlock();
- return err;
+ String tmp_export_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport.apk");
+
+#define CLEANUP_AND_RETURN(m_err) \
+ { \
+ DirAccess::remove_file_or_error(tmp_export_path); \
+ device_lock->unlock(); \
+ return m_err; \
+ }
+
+ // Export to temporary APK before sending to device.
+ Error err = export_project(p_preset, true, tmp_export_path, p_debug_flags);
+
+ if (err != OK) {
+ CLEANUP_AND_RETURN(err);
}
List<String> args;
@@ -1425,7 +1436,7 @@ public:
if (remove_prev) {
if (ep.step("Uninstalling...", 1)) {
- return ERR_SKIP;
+ CLEANUP_AND_RETURN(ERR_SKIP);
}
print_line("Uninstalling previous version: " + devices[p_device].name);
@@ -1440,7 +1451,7 @@ public:
print_line("Installing to device (please wait...): " + devices[p_device].name);
if (ep.step("Installing to device (please wait...)", 2)) {
- return ERR_SKIP;
+ CLEANUP_AND_RETURN(ERR_SKIP);
}
args.clear();
@@ -1448,13 +1459,12 @@ public:
args.push_back(devices[p_device].id);
args.push_back("install");
args.push_back("-r");
- args.push_back(export_to);
+ args.push_back(tmp_export_path);
err = OS::get_singleton()->execute(adb, args, true, NULL, NULL, &rv);
if (err || rv != 0) {
EditorNode::add_io_error("Could not install to device.");
- device_lock->unlock();
- return ERR_CANT_CREATE;
+ CLEANUP_AND_RETURN(ERR_CANT_CREATE);
}
if (use_remote) {
@@ -1508,7 +1518,7 @@ public:
}
if (ep.step("Running on Device...", 3)) {
- return ERR_SKIP;
+ CLEANUP_AND_RETURN(ERR_SKIP);
}
args.clear();
args.push_back("-s");
@@ -1528,11 +1538,11 @@ public:
err = OS::get_singleton()->execute(adb, args, true, NULL, NULL, &rv);
if (err || rv != 0) {
EditorNode::add_io_error("Could not execute on device.");
- device_lock->unlock();
- return ERR_CANT_CREATE;
+ CLEANUP_AND_RETURN(ERR_CANT_CREATE);
}
- device_lock->unlock();
- return OK;
+
+ CLEANUP_AND_RETURN(OK);
+#undef CLEANUP_AND_RETURN
}
virtual Ref<Texture> get_run_icon() const {
@@ -2023,8 +2033,16 @@ public:
zlib_filefunc_def io2 = io;
FileAccess *dst_f = NULL;
io2.opaque = &dst_f;
- String unaligned_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport-unaligned.apk");
- zipFile unaligned_apk = zipOpen2(unaligned_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io2);
+
+ String tmp_unaligned_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport-unaligned.apk");
+
+#define CLEANUP_AND_RETURN(m_err) \
+ { \
+ DirAccess::remove_file_or_error(tmp_unaligned_path); \
+ return m_err; \
+ }
+
+ zipFile unaligned_apk = zipOpen2(tmp_unaligned_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io2);
bool use_32_fb = p_preset->get("graphics/32_bits_framebuffer");
bool immersive = p_preset->get("screen/immersive_mode");
@@ -2152,7 +2170,7 @@ public:
}
if (ep.step("Adding Files...", 1)) {
- return ERR_SKIP;
+ CLEANUP_AND_RETURN(ERR_SKIP);
}
Error err = OK;
Vector<String> cl = cmdline.strip_edges().split(" ");
@@ -2184,7 +2202,7 @@ public:
unzClose(pkg);
EditorNode::add_io_error("Could not write expansion package file: " + apkfname);
- return OK;
+ CLEANUP_AND_RETURN(ERR_SKIP);
}
cl.push_back("--use_apk_expansion");
@@ -2271,8 +2289,8 @@ public:
zipClose(unaligned_apk, NULL);
unzClose(pkg);
- if (err) {
- return err;
+ if (err != OK) {
+ CLEANUP_AND_RETURN(err);
}
if (_signed) {
@@ -2280,7 +2298,7 @@ public:
String jarsigner = EditorSettings::get_singleton()->get("export/android/jarsigner");
if (!FileAccess::exists(jarsigner)) {
EditorNode::add_io_error("'jarsigner' could not be found.\nPlease supply a path in the Editor Settings.\nThe resulting APK is unsigned.");
- return OK;
+ CLEANUP_AND_RETURN(OK);
}
String keystore;
@@ -2300,7 +2318,7 @@ public:
}
if (ep.step("Signing debug APK...", 103)) {
- return ERR_SKIP;
+ CLEANUP_AND_RETURN(ERR_SKIP);
}
} else {
@@ -2309,13 +2327,13 @@ public:
user = release_username;
if (ep.step("Signing release APK...", 103)) {
- return ERR_SKIP;
+ CLEANUP_AND_RETURN(ERR_SKIP);
}
}
if (!FileAccess::exists(keystore)) {
EditorNode::add_io_error("Could not find keystore, unable to export.");
- return ERR_FILE_CANT_OPEN;
+ CLEANUP_AND_RETURN(ERR_FILE_CANT_OPEN);
}
List<String> args;
@@ -2333,30 +2351,30 @@ public:
args.push_back(keystore);
args.push_back("-storepass");
args.push_back(password);
- args.push_back(unaligned_path);
+ args.push_back(tmp_unaligned_path);
args.push_back(user);
int retval;
OS::get_singleton()->execute(jarsigner, args, true, NULL, NULL, &retval);
if (retval) {
EditorNode::add_io_error("'jarsigner' returned with error #" + itos(retval));
- return ERR_CANT_CREATE;
+ CLEANUP_AND_RETURN(ERR_CANT_CREATE);
}
if (ep.step("Verifying APK...", 104)) {
- return ERR_SKIP;
+ CLEANUP_AND_RETURN(ERR_SKIP);
}
args.clear();
args.push_back("-verify");
args.push_back("-keystore");
args.push_back(keystore);
- args.push_back(unaligned_path);
+ args.push_back(tmp_unaligned_path);
args.push_back("-verbose");
OS::get_singleton()->execute(jarsigner, args, true, NULL, NULL, &retval);
if (retval) {
EditorNode::add_io_error("'jarsigner' verification of APK failed. Make sure to use a jarsigner from OpenJDK 8.");
- return ERR_CANT_CREATE;
+ CLEANUP_AND_RETURN(ERR_CANT_CREATE);
}
}
@@ -2365,14 +2383,14 @@ public:
static const int ZIP_ALIGNMENT = 4;
if (ep.step("Aligning APK...", 105)) {
- return ERR_SKIP;
+ CLEANUP_AND_RETURN(ERR_SKIP);
}
- unzFile tmp_unaligned = unzOpen2(unaligned_path.utf8().get_data(), &io);
+ unzFile tmp_unaligned = unzOpen2(tmp_unaligned_path.utf8().get_data(), &io);
if (!tmp_unaligned) {
- EditorNode::add_io_error("Could not find temp unaligned APK.");
- return ERR_FILE_NOT_FOUND;
+ EditorNode::add_io_error("Could not unzip temporary unaligned APK.");
+ CLEANUP_AND_RETURN(ERR_FILE_NOT_FOUND);
}
ret = unzGoToFirstFile(tmp_unaligned);
@@ -2442,7 +2460,7 @@ public:
zipClose(final_apk, NULL);
unzClose(tmp_unaligned);
- return OK;
+ CLEANUP_AND_RETURN(OK);
}
virtual void get_platform_features(List<String> *r_features) {
diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp
index c68b420c61..69dd038709 100644
--- a/platform/javascript/export/export.cpp
+++ b/platform/javascript/export/export.cpp
@@ -362,12 +362,21 @@ int EditorExportPlatformJavaScript::get_device_count() const {
Error EditorExportPlatformJavaScript::run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) {
- String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_export.html");
+ String basepath = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_js_export");
+ String path = basepath + ".html";
Error err = export_project(p_preset, true, path, p_debug_flags);
- if (err) {
+ 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 + ".js");
+ DirAccess::remove_file_or_error(basepath + ".pck");
+ DirAccess::remove_file_or_error(basepath + ".png");
+ DirAccess::remove_file_or_error(basepath + ".wasm");
return err;
}
OS::get_singleton()->shell_open(String("file://") + path);
+ // FIXME: Find out how to clean up export files after running the successfully
+ // exported game. Might not be trivial.
return OK;
}
diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp
index 8cabc45250..56b0a44dbc 100644
--- a/platform/osx/export/export.cpp
+++ b/platform/osx/export/export.cpp
@@ -29,9 +29,11 @@
/*************************************************************************/
#include "export.h"
+
#include "core/io/marshalls.h"
#include "core/io/resource_saver.h"
#include "core/io/zip_io.h"
+#include "core/os/dir_access.h"
#include "core/os/file_access.h"
#include "core/os/os.h"
#include "core/project_settings.h"
@@ -244,13 +246,17 @@ void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_
copy->resize(icon_infos[i].size, icon_infos[i].size);
if (icon_infos[i].is_png) {
- //encode png icon
+ // Encode PNG icon.
it->create_from_image(copy);
String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("icon.png");
ResourceSaver::save(path, it);
FileAccess *f = FileAccess::open(path, FileAccess::READ);
- ERR_FAIL_COND(!f);
+ if (!f) {
+ // Clean up generated file.
+ DirAccess::remove_file_or_error(path);
+ ERR_FAIL();
+ }
int ofs = data.size();
uint32_t len = f->get_len();
@@ -261,6 +267,10 @@ void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_
len = BSWAP32(len);
copymem(&data.write[ofs], icon_infos[i].name, 4);
encode_uint32(len, &data.write[ofs + 4]);
+
+ // Clean up generated file.
+ DirAccess::remove_file_or_error(path);
+
} else {
PoolVector<uint8_t> src_data = copy->get_data();
@@ -561,7 +571,6 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
}
}
}
- //bleh?
}
if (data.size() > 0) {
@@ -687,7 +696,8 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
// Clean up temporary .app dir
OS::get_singleton()->move_to_trash(tmp_app_path_name);
- } else {
+
+ } else { // pck
String pack_path = EditorSettings::get_singleton()->get_cache_dir().plus_file(pkg_name + ".pck");
@@ -747,6 +757,9 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
zipCloseFileInZip(dst_pkg_zip);
}
}
+
+ // Clean up generated file.
+ DirAccess::remove_file_or_error(pack_path);
}
}
diff --git a/platform/uwp/export/export.cpp b/platform/uwp/export/export.cpp
index 024e7f1916..662ee49935 100644
--- a/platform/uwp/export/export.cpp
+++ b/platform/uwp/export/export.cpp
@@ -34,6 +34,7 @@
#include "core/io/zip_io.h"
#include "core/math/crypto_core.h"
#include "core/object.h"
+#include "core/os/dir_access.h"
#include "core/os/file_access.h"
#include "core/project_settings.h"
#include "core/version.h"
@@ -133,8 +134,6 @@ class AppxPackager {
String progress_task;
FileAccess *package;
- String tmp_blockmap_file_path;
- String tmp_content_types_file_path;
Set<String> mime_types;
@@ -146,8 +145,8 @@ class AppxPackager {
String hash_block(const uint8_t *p_block_data, size_t p_block_len);
- void make_block_map();
- void make_content_types();
+ 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++) {
@@ -208,9 +207,9 @@ String AppxPackager::hash_block(const uint8_t *p_block_data, size_t p_block_len)
return String(base64);
}
-void AppxPackager::make_block_map() {
+void AppxPackager::make_block_map(const String &p_path) {
- FileAccess *tmp_file = FileAccess::open(tmp_blockmap_file_path, FileAccess::WRITE);
+ 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\">");
@@ -253,9 +252,9 @@ String AppxPackager::content_type(String p_extension) {
return "application/octet-stream";
}
-void AppxPackager::make_content_types() {
+void AppxPackager::make_content_types(const String &p_path) {
- FileAccess *tmp_file = FileAccess::open(tmp_content_types_file_path, FileAccess::WRITE);
+ 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\">");
@@ -458,8 +457,6 @@ void AppxPackager::init(FileAccess *p_fa) {
package = p_fa;
central_dir_offset = 0;
end_of_central_dir_offset = 0;
- tmp_blockmap_file_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpblockmap.xml");
- tmp_content_types_file_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpcontenttypes.xml");
}
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) {
@@ -591,7 +588,9 @@ void AppxPackager::finish() {
// Create and add block map file
EditorNode::progress_task_step("export", "Creating block map...", 4);
- make_block_map();
+ const String &tmp_blockmap_file_path = EditorSettings::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_len());
@@ -604,8 +603,11 @@ void AppxPackager::finish() {
memdelete(blockmap_file);
// Add content types
+
EditorNode::progress_task_step("export", "Setting content types...", 5);
- make_content_types();
+
+ const String &tmp_content_types_file_path = EditorSettings::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;
@@ -618,6 +620,10 @@ void AppxPackager::finish() {
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]);
@@ -909,7 +915,8 @@ class EditorExportPlatformUWP : public EditorExportPlatform {
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);
}
@@ -919,29 +926,7 @@ class EditorExportPlatformUWP : public EditorExportPlatform {
f->close();
memdelete(f);
-
- // Delete temp file
- DirAccess *dir = DirAccess::open(tmp_path.get_base_dir(), &err);
-
- if (err != OK) {
-
- String err_string = "Couldn't open temp path to remove temp logo file.";
-
- EditorNode::add_io_error(err_string);
- ERR_FAIL_V_MSG(data, err_string);
- }
-
- err = dir->remove(tmp_path);
-
- memdelete(dir);
-
- if (err != OK) {
-
- String err_string = "Couldn't remove temp logo file.";
-
- EditorNode::add_io_error(err_string);
- ERR_FAIL_V_MSG(data, err_string);
- }
+ DirAccess::remove_file_or_error(tmp_path);
return data;
}
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 0d1e702d04..ca72393e43 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -1518,9 +1518,12 @@ void OS_X11::set_window_maximized(bool p_enabled) {
XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
- if (is_window_maximize_allowed()) {
- while (p_enabled && !is_window_maximized()) {
- // Wait for effective resizing (so the GLX context is too).
+ if (p_enabled && is_window_maximize_allowed()) {
+ // Wait for effective resizing (so the GLX context is too).
+ // Give up after 0.5s, it's not going to happen on this WM.
+ // https://github.com/godotengine/godot/issues/19978
+ for (int attempt = 0; !is_window_maximized() && attempt < 50; attempt++) {
+ usleep(10000);
}
}