From 15f6d3cebf9e8c9288132454816f1152e16dde36 Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 30 Nov 2015 01:26:51 +0100 Subject: [PATCH] Add way to look for templates at system wide level too Useful for everybody wanting to package godot. Fixes #1026. -> Retain the old behaviour: path in error msg only when exporting. -> User templates override system templates --- .gitignore | 1 + SConstruct | 1 + platform/android/export/export.cpp | 29 ++++++----- platform/bb10/export/export.cpp | 16 +++--- platform/javascript/export/export.cpp | 27 ++++++---- platform/osx/export/export.cpp | 21 ++++---- tools/editor/SCsub | 9 ++++ tools/editor/editor_import_export.cpp | 75 +++++++++++++++++++++------ tools/editor/editor_import_export.h | 2 + tools/editor/editor_settings.h | 1 + 10 files changed, 128 insertions(+), 54 deletions(-) diff --git a/.gitignore b/.gitignore index f24d91a7ee0..cfdb0af68a6 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ core/global_defaults.cpp tools/editor/register_exporters.cpp tools/editor/doc_data_compressed.h tools/editor/editor_icons.cpp +tools/editor/editor_global_settings.cpp -fpic .fscache make.bat diff --git a/SConstruct b/SConstruct index 46edf06a42c..e44091d7833 100644 --- a/SConstruct +++ b/SConstruct @@ -126,6 +126,7 @@ opts.Add("CXX", "Compiler"); opts.Add("CCFLAGS", "Custom flags for the C++ compiler"); opts.Add("CFLAGS", "Custom flags for the C compiler"); opts.Add("LINKFLAGS", "Custom flags for the linker"); +opts.Add('global_settings_path', 'Path to system-wide settings. Currently only used by templates.','') opts.Add('disable_3d', 'Disable 3D nodes for smaller executable (yes/no)', "no") opts.Add('disable_advanced_gui', 'Disable advance 3D gui nodes and behaviors (yes/no)', "no") opts.Add('colored', 'Enable colored output for the compilation (yes/no)', 'no') diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 1deeb3457a8..7d550f4fa05 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -1020,18 +1020,24 @@ Error EditorExportPlatformAndroid::export_project(const String& p_path, bool p_d EditorProgress ep("export","Exporting for Android",104); - String apk_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; - - if (p_debug) { - - src_apk=custom_debug_package!=""?custom_debug_package:apk_path+"android_debug.apk"; - } else { - - src_apk=custom_release_package!=""?custom_release_package:apk_path+"android_release.apk"; + if (p_debug) + src_apk=custom_debug_package; + else + src_apk=custom_release_package; + if (src_apk=="") { + String err; + if (p_debug) { + src_apk=find_export_template("android_debug.apk", &err); + } else { + src_apk=find_export_template("android_release.apk", &err); + } + if (src_apk=="") { + EditorNode::add_io_error(err); + return ERR_FILE_NOT_FOUND; + } } - FileAccess *src_f=NULL; zlib_filefunc_def io = zipio_create_io_from_file(&src_f); @@ -1659,10 +1665,7 @@ bool EditorExportPlatformAndroid::can_export(String *r_error) const { err+="Debug Keystore not configured in editor settings.\n"; } - - String exe_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; - - if (!FileAccess::exists(exe_path+"android_debug.apk") || !FileAccess::exists(exe_path+"android_release.apk")) { + if (!exists_export_template("android_debug.apk") || !exists_export_template("android_release.apk")) { valid=false; err+="No export templates found.\nDownload and install export templates.\n"; } diff --git a/platform/bb10/export/export.cpp b/platform/bb10/export/export.cpp index 434aaff4147..2acd920f316 100644 --- a/platform/bb10/export/export.cpp +++ b/platform/bb10/export/export.cpp @@ -275,10 +275,16 @@ Error EditorExportPlatformBB10::export_project(const String& p_path, bool p_debu EditorProgress ep("export","Exporting for BlackBerry 10",104); - String template_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; - - String src_template=custom_package!=""?custom_package:template_path.plus_file("bb10.zip"); + String src_template=custom_package; + if (src_template=="") { + String err; + src_template = find_export_template("bb10.zip", &err); + if (src_template=="") { + EditorNode::add_io_error(err); + return ERR_FILE_NOT_FOUND; + } + } FileAccess *src_f=NULL; zlib_filefunc_def io = zipio_create_io_from_file(&src_f); @@ -733,9 +739,7 @@ bool EditorExportPlatformBB10::can_export(String *r_error) const { err+="Blackberry host tools not configured in editor settings.\n"; } - String exe_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; - - if (!FileAccess::exists(exe_path+"bb10.zip")) { + if (!exists_export_template("bb10.zip")) { valid=false; err+="No export template found.\nDownload and install export templates.\n"; } diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index 9e2595f4a16..acbcbb46524 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -205,18 +205,24 @@ Error EditorExportPlatformJavaScript::export_project(const String& p_path, bool EditorProgress ep("export","Exporting for javascript",104); - String template_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; - - if (p_debug) { - - src_template=custom_debug_package!=""?custom_debug_package:template_path+"javascript_debug.zip"; - } else { - - src_template=custom_release_package!=""?custom_release_package:template_path+"javascript_release.zip"; + if (p_debug) + src_template=custom_debug_package; + else + src_template=custom_release_package; + if (src_template=="") { + String err; + if (p_debug) { + src_template=find_export_template("javascript_debug.zip", &err); + } else { + src_template=find_export_template("javascript_release.zip", &err); + } + if (src_template=="") { + EditorNode::add_io_error(err); + return ERR_FILE_NOT_FOUND; + } } - FileAccess *src_f=NULL; zlib_filefunc_def io = zipio_create_io_from_file(&src_f); @@ -337,9 +343,8 @@ bool EditorExportPlatformJavaScript::can_export(String *r_error) const { bool valid=true; String err; - String exe_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; - if (!FileAccess::exists(exe_path+"javascript_debug.zip") || !FileAccess::exists(exe_path+"javascript_release.zip")) { + if (!exists_export_template("javascript_debug.zip") || !exists_export_template("javascript_release.zip")) { valid=false; err+="No export templates found.\nDownload and install export templates.\n"; } diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp index 79ee91bc61b..0bece6ec760 100644 --- a/platform/osx/export/export.cpp +++ b/platform/osx/export/export.cpp @@ -251,15 +251,19 @@ Error EditorExportPlatformOSX::export_project(const String& p_path, bool p_debug EditorProgress ep("export","Exporting for OSX",104); - String pkg_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/osx.zip"; - if (p_debug) { - - src_pkg=custom_debug_package!=""?custom_debug_package:pkg_path; - } else { - - src_pkg=custom_release_package!=""?custom_release_package:pkg_path; + if (p_debug) + src_pkg=custom_debug_package; + else + src_pkg=custom_release_package; + if (src_pkg=="") { + String err; + src_pkg=find_export_template("osx.zip", &err); + if (src_pkg=="") { + EditorNode::add_io_error(err); + return ERR_FILE_NOT_FOUND; + } } @@ -464,9 +468,8 @@ bool EditorExportPlatformOSX::can_export(String *r_error) const { bool valid=true; String err; - String exe_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; - if (!FileAccess::exists(exe_path+"osx.zip")) { + if (!exists_export_template("osx.zip")) { valid=false; err+="No export templates found.\nDownload and install export templates.\n"; } diff --git a/tools/editor/SCsub b/tools/editor/SCsub index cd46ff83533..c96386fb18d 100644 --- a/tools/editor/SCsub +++ b/tools/editor/SCsub @@ -44,6 +44,15 @@ if (env["tools"]=="yes"): f.write(reg_exporters) f.close() + ed_gl_set='#include "editor_settings.h"\n' + ed_gl_set+='String EditorSettings::get_global_settings_path() const {\n' + ed_gl_set+='\treturn "' + env["global_settings_path"]+'";\n' + ed_gl_set+='}\n' + reg_exporters+='}\n' + f = open("editor_global_settings.cpp","wb") + f.write(ed_gl_set) + f.close() + env.Depends("#tools/editor/doc_data_compressed.h","#doc/base/classes.xml") env.Command("#tools/editor/doc_data_compressed.h","#doc/base/classes.xml",make_doc_header) diff --git a/tools/editor/editor_import_export.cpp b/tools/editor/editor_import_export.cpp index f52c6e67a26..5ecc6f67042 100644 --- a/tools/editor/editor_import_export.cpp +++ b/tools/editor/editor_import_export.cpp @@ -399,6 +399,40 @@ Vector EditorExportPlatform::get_dependencies(bool p_bundles) const } +String EditorExportPlatform::find_export_template(String template_file_name, String *err) const { + String user_file = EditorSettings::get_singleton()->get_settings_path() + +"/templates/"+template_file_name; + String system_file=EditorSettings::get_singleton()->get_global_settings_path(); + bool has_system_path=(system_file!=""); + system_file+="/templates/"+template_file_name; + + // Prefer user file + if (FileAccess::exists(user_file)) { + return user_file; + } + + // Now check system file + if (has_system_path) { + if (FileAccess::exists(system_file)) { + return system_file; + } + } + + // Not found + if (err) { + *err+="No export template found at \""+user_file+"\""; + if (has_system_path) + *err+="\n or \""+system_file+"\"."; + else + *err+="."; + } + return ""; +} + +bool EditorExportPlatform::exists_export_template(String template_file_name, String *err) const { + return find_export_template(template_file_name,err)!=""; +} + /////////////////////////////////////// @@ -1131,19 +1165,32 @@ Error EditorExportPlatformPC::export_project(const String& p_path, bool p_debug, ep.step("Setting Up..",0); - String exe_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; - if (use64) { - if (p_debug) - exe_path=custom_debug_binary!=""?custom_debug_binary:exe_path+debug_binary64; - else - exe_path=custom_release_binary!=""?custom_release_binary:exe_path+release_binary64; - } else { + String exe_path=""; - if (p_debug) - exe_path=custom_debug_binary!=""?custom_debug_binary:exe_path+debug_binary32; - else - exe_path=custom_release_binary!=""?custom_release_binary:exe_path+release_binary32; + if (p_debug) + exe_path=custom_debug_binary; + else + exe_path=custom_release_binary; + if (exe_path=="") { + String fname; + if (use64) { + if (p_debug) + fname=debug_binary64; + else + fname=release_binary64; + } else { + if (p_debug) + fname=debug_binary32; + else + fname=release_binary32; + } + String err=""; + exe_path=find_export_template(fname,&err); + if (exe_path=="") { + EditorNode::add_io_error(err); + return ERR_FILE_CANT_READ; + } } FileAccess *src_exe=FileAccess::open(exe_path,FileAccess::READ); @@ -1207,14 +1254,12 @@ bool EditorExportPlatformPC::can_export(String *r_error) const { String err; bool valid=true; - String exe_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; - - if (use64 && (!FileAccess::exists(exe_path+debug_binary64) || !FileAccess::exists(exe_path+release_binary64))) { + if (use64 && (!exists_export_template(debug_binary64)) || !exists_export_template(release_binary64)) { valid=false; err="No 64 bits export templates found.\nDownload and install export templates.\n"; } - if (!use64 && (!FileAccess::exists(exe_path+debug_binary32) || !FileAccess::exists(exe_path+release_binary32))) { + if (!use64 && (!exists_export_template(debug_binary32) || !exists_export_template(release_binary32))) { valid=false; err="No 32 bits export templates found.\nDownload and install export templates.\n"; } diff --git a/tools/editor/editor_import_export.h b/tools/editor/editor_import_export.h index 1a3171e66ba..1147a3abf5b 100644 --- a/tools/editor/editor_import_export.h +++ b/tools/editor/editor_import_export.h @@ -86,6 +86,8 @@ protected: Vector get_exported_file_default(String& p_fname) const; virtual Vector get_exported_file(String& p_fname) const; virtual Vector get_dependencies(bool p_bundles) const; + virtual String find_export_template(String template_file_name, String *err=NULL) const; + virtual bool exists_export_template(String template_file_name, String *err=NULL) const; struct TempData { diff --git a/tools/editor/editor_settings.h b/tools/editor/editor_settings.h index 4ba940cd1c9..bdfa5160d6f 100644 --- a/tools/editor/editor_settings.h +++ b/tools/editor/editor_settings.h @@ -107,6 +107,7 @@ public: static EditorSettings *get_singleton(); void erase(String p_var); String get_settings_path() const; + String get_global_settings_path() const; String get_project_settings_path() const; const Map& get_plugins() const { return plugins; }