Merge pull request #2956 from est31/add_system_wide_export_path

Add way to look for templates at system wide level too
This commit is contained in:
Juan Linietsky 2015-12-08 17:04:24 -03:00
commit eff81965af
13 changed files with 139 additions and 54 deletions

1
.gitignore vendored
View File

@ -15,6 +15,7 @@ core/method_bind.inc
core/method_bind_ext.inc
core/script_encryption_key.cpp
core/global_defaults.cpp
drivers/unix/os_unix_global_settings_path.cpp
tools/editor/register_exporters.cpp
tools/editor/doc_data_compressed.h
tools/editor/editor_icons.cpp

View File

@ -127,6 +127,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('unix_global_settings_path', 'unix-specific 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')

View File

@ -184,6 +184,7 @@ public:
virtual void set_low_processor_usage_mode(bool p_enabled);
virtual bool is_in_low_processor_usage_mode() const;
virtual String get_installed_templates_path() const { return ""; };
virtual String get_executable_path() const;
virtual Error execute(const String& p_path, const List<String>& p_arguments,bool p_blocking,ProcessID *r_child_id=NULL,String* r_pipe=NULL,int *r_exitcode=NULL)=0;
virtual Error kill(const ProcessID& p_pid)=0;

View File

@ -1,5 +1,13 @@
Import('env')
ed_gl_set='#include "os_unix.h"\n'
ed_gl_set+='String OS_Unix::get_global_settings_path() const {\n'
ed_gl_set+='\treturn "' + env["unix_global_settings_path"]+'";\n'
ed_gl_set+='}\n'
f = open("os_unix_global_settings_path.cpp","wb")
f.write(ed_gl_set)
f.close()
env.add_source_files(env.drivers_sources,"*.cpp")
Export('env')

View File

@ -477,6 +477,14 @@ String OS_Unix::get_data_dir() const {
}
String OS_Unix::get_installed_templates_path() const {
String p=get_global_settings_path();
if (p!="")
return p+"/templates/";
else
return "";
}
String OS_Unix::get_executable_path() const {
#ifdef __linux__

View File

@ -64,6 +64,8 @@ protected:
String stdin_buf;
String get_global_settings_path() const;
public:
@ -111,6 +113,7 @@ public:
virtual void debug_break();
virtual String get_installed_templates_path() const;
virtual String get_executable_path() const;
virtual String get_data_dir() const;

View File

@ -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";
}

View File

@ -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";
}

View File

@ -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";
}

View File

@ -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";
}

View File

@ -399,6 +399,40 @@ Vector<StringName> 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=OS::get_singleton()->get_installed_templates_path();
bool has_system_path=(system_file!="");
system_file+=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";
}

View File

@ -86,6 +86,8 @@ protected:
Vector<uint8_t> get_exported_file_default(String& p_fname) const;
virtual Vector<uint8_t> get_exported_file(String& p_fname) const;
virtual Vector<StringName> 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 {

View File

@ -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<String,Plugin>& get_plugins() const { return plugins; }