diff options
Diffstat (limited to 'editor/editor_export.cpp')
-rw-r--r-- | editor/editor_export.cpp | 560 |
1 files changed, 262 insertions, 298 deletions
diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index f5840d00fb..7ac299974c 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -27,20 +27,20 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_export.h" -#include "version.h" -#include "script_language.h" -#include "global_config.h" -#include "os/file_access.h" -#include "os/dir_access.h" #include "editor/editor_file_system.h" -#include "io/resource_loader.h" +#include "editor/plugins/script_editor_plugin.h" #include "editor_node.h" #include "editor_settings.h" +#include "global_config.h" #include "io/config_file.h" -#include "io/resource_saver.h" #include "io/md5.h" -#include "editor/plugins/script_editor_plugin.h" +#include "io/resource_loader.h" +#include "io/resource_saver.h" #include "io/zip_io.h" +#include "os/dir_access.h" +#include "os/file_access.h" +#include "script_language.h" +#include "version.h" static int _get_pad(int p_alignment, int p_n) { @@ -55,10 +55,10 @@ static int _get_pad(int p_alignment, int p_n) { #define PCK_PADDING 16 -bool EditorExportPreset::_set(const StringName& p_name, const Variant& p_value) { +bool EditorExportPreset::_set(const StringName &p_name, const Variant &p_value) { - if (values.has(p_name)) { - values[p_name]=p_value; + if (values.has(p_name)) { + values[p_name] = p_value; EditorExport::singleton->save_presets(); return true; } @@ -66,18 +66,18 @@ bool EditorExportPreset::_set(const StringName& p_name, const Variant& p_value) return false; } -bool EditorExportPreset::_get(const StringName& p_name,Variant &r_ret) const{ +bool EditorExportPreset::_get(const StringName &p_name, Variant &r_ret) const { if (values.has(p_name)) { - r_ret=values[p_name]; + r_ret = values[p_name]; return true; } return false; } -void EditorExportPreset::_get_property_list( List<PropertyInfo> *p_list) const{ +void EditorExportPreset::_get_property_list(List<PropertyInfo> *p_list) const { - for (const List<PropertyInfo>::Element *E=properties.front();E;E=E->next()) { + for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { p_list->push_back(E->get()); } @@ -91,26 +91,24 @@ Ref<EditorExportPlatform> EditorExportPreset::get_platform() const { Vector<String> EditorExportPreset::get_files_to_export() const { Vector<String> files; - for(Set<String>::Element *E=selected_files.front();E;E=E->next()) { + for (Set<String>::Element *E = selected_files.front(); E; E = E->next()) { files.push_back(E->get()); } return files; } -void EditorExportPreset::set_name(const String& p_name) { - name=p_name; +void EditorExportPreset::set_name(const String &p_name) { + name = p_name; EditorExport::singleton->save_presets(); - } String EditorExportPreset::get_name() const { return name; - } void EditorExportPreset::set_runnable(bool p_enable) { - runnable=p_enable; + runnable = p_enable; EditorExport::singleton->save_presets(); } @@ -121,20 +119,18 @@ bool EditorExportPreset::is_runnable() const { void EditorExportPreset::set_export_filter(ExportFilter p_filter) { - export_filter=p_filter; + export_filter = p_filter; EditorExport::singleton->save_presets(); - } EditorExportPreset::ExportFilter EditorExportPreset::get_export_filter() const { return export_filter; } -void EditorExportPreset::set_include_filter(const String& p_include) { +void EditorExportPreset::set_include_filter(const String &p_include) { - include_filter=p_include; + include_filter = p_include; EditorExport::singleton->save_presets(); - } String EditorExportPreset::get_include_filter() const { @@ -142,9 +138,9 @@ String EditorExportPreset::get_include_filter() const { return include_filter; } -void EditorExportPreset::set_exclude_filter(const String& p_exclude) { +void EditorExportPreset::set_exclude_filter(const String &p_exclude) { - exclude_filter=p_exclude; + exclude_filter = p_exclude; EditorExport::singleton->save_presets(); } @@ -153,28 +149,28 @@ String EditorExportPreset::get_exclude_filter() const { return exclude_filter; } -void EditorExportPreset::add_export_file(const String& p_path) { +void EditorExportPreset::add_export_file(const String &p_path) { selected_files.insert(p_path); EditorExport::singleton->save_presets(); } -void EditorExportPreset::remove_export_file(const String& p_path) { +void EditorExportPreset::remove_export_file(const String &p_path) { selected_files.erase(p_path); EditorExport::singleton->save_presets(); } -bool EditorExportPreset::has_export_file(const String& p_path) { +bool EditorExportPreset::has_export_file(const String &p_path) { return selected_files.has(p_path); } -void EditorExportPreset::add_patch(const String& p_path,int p_at_pos) { +void EditorExportPreset::add_patch(const String &p_path, int p_at_pos) { - if (p_at_pos<0) + if (p_at_pos < 0) patches.push_back(p_path); else - patches.insert(p_at_pos,p_path); + patches.insert(p_at_pos, p_path); EditorExport::singleton->save_presets(); } @@ -183,14 +179,14 @@ void EditorExportPreset::remove_patch(int p_idx) { EditorExport::singleton->save_presets(); } -void EditorExportPreset::set_patch(int p_index,const String& p_path) { - ERR_FAIL_INDEX(p_index,patches.size()); - patches[p_index]=p_path; +void EditorExportPreset::set_patch(int p_index, const String &p_path) { + ERR_FAIL_INDEX(p_index, patches.size()); + patches[p_index] = p_path; EditorExport::singleton->save_presets(); } String EditorExportPreset::get_patch(int p_index) { - ERR_FAIL_INDEX_V(p_index,patches.size(),String()); + ERR_FAIL_INDEX_V(p_index, patches.size(), String()); return patches[p_index]; } @@ -200,136 +196,131 @@ Vector<String> EditorExportPreset::get_patches() const { EditorExportPreset::EditorExportPreset() { - export_filter=EXPORT_ALL_RESOURCES; - runnable=false; + export_filter = EXPORT_ALL_RESOURCES; + runnable = false; } - /////////////////////////////////// void EditorExportPlatform::gen_debug_flags(Vector<String> &r_flags, int p_flags) { String host = EditorSettings::get_singleton()->get("network/debug_host"); - if (p_flags&DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) - host="localhost"; + if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) + host = "localhost"; - if (p_flags&DEBUG_FLAG_DUMB_CLIENT) { + if (p_flags & DEBUG_FLAG_DUMB_CLIENT) { int port = EditorSettings::get_singleton()->get("filesystem/file_server/port"); String passwd = EditorSettings::get_singleton()->get("filesystem/file_server/password"); r_flags.push_back("-rfs"); - r_flags.push_back(host+":"+itos(port)); - if (passwd!="") { + r_flags.push_back(host + ":" + itos(port)); + if (passwd != "") { r_flags.push_back("-rfs_pass"); r_flags.push_back(passwd); } } - if (p_flags&DEBUG_FLAG_REMOTE_DEBUG) { + if (p_flags & DEBUG_FLAG_REMOTE_DEBUG) { r_flags.push_back("-rdebug"); - r_flags.push_back(host+":"+String::num(GLOBAL_DEF("network/debug/remote_port", 6007))); + r_flags.push_back(host + ":" + String::num(GLOBAL_DEF("network/debug/remote_port", 6007))); List<String> breakpoints; ScriptEditor::get_singleton()->get_breakpoints(&breakpoints); - if (breakpoints.size()) { r_flags.push_back("-bp"); String bpoints; - for(const List<String>::Element *E=breakpoints.front();E;E=E->next()) { + for (const List<String>::Element *E = breakpoints.front(); E; E = E->next()) { - bpoints+=E->get().replace(" ","%20"); + bpoints += E->get().replace(" ", "%20"); if (E->next()) - bpoints+=","; + bpoints += ","; } r_flags.push_back(bpoints); } - } - if (p_flags&DEBUG_FLAG_VIEW_COLLISONS) { + if (p_flags & DEBUG_FLAG_VIEW_COLLISONS) { r_flags.push_back("-debugcol"); } - if (p_flags&DEBUG_FLAG_VIEW_NAVIGATION) { + if (p_flags & DEBUG_FLAG_VIEW_NAVIGATION) { r_flags.push_back("-debugnav"); } } -Error EditorExportPlatform::_save_pack_file(void *p_userdata,const String& p_path, const Vector<uint8_t>& p_data,int p_file,int p_total) { +Error EditorExportPlatform::_save_pack_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total) { - PackData *pd = (PackData*)p_userdata; + PackData *pd = (PackData *)p_userdata; SavedData sd; - sd.path_utf8=p_path.utf8(); + sd.path_utf8 = p_path.utf8(); sd.ofs = pd->f->get_pos(); sd.size = p_data.size(); - pd->f->store_buffer(p_data.ptr(),p_data.size()); - int pad = _get_pad(PCK_PADDING,sd.size); - for(int i=0;i<pad;i++) { + pd->f->store_buffer(p_data.ptr(), p_data.size()); + int pad = _get_pad(PCK_PADDING, sd.size); + for (int i = 0; i < pad; i++) { pd->f->store_8(0); } { MD5_CTX ctx; MD5Init(&ctx); - MD5Update(&ctx,(unsigned char*)p_data.ptr(),p_data.size()); + MD5Update(&ctx, (unsigned char *)p_data.ptr(), p_data.size()); MD5Final(&ctx); sd.md5.resize(16); - for(int i=0;i<16;i++) { - sd.md5[i]=ctx.digest[i]; + for (int i = 0; i < 16; i++) { + sd.md5[i] = ctx.digest[i]; } } pd->file_ofs.push_back(sd); - pd->ep->step(TTR("Storing File:")+" "+p_path,2+p_file*100/p_total,false); + pd->ep->step(TTR("Storing File:") + " " + p_path, 2 + p_file * 100 / p_total, false); return OK; } -Error EditorExportPlatform::_save_zip_file(void *p_userdata,const String& p_path, const Vector<uint8_t>& p_data,int p_file,int p_total) { - +Error EditorExportPlatform::_save_zip_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total) { - String path=p_path.replace_first("res://",""); + String path = p_path.replace_first("res://", ""); - ZipData *zd = (ZipData*)p_userdata; + ZipData *zd = (ZipData *)p_userdata; - zipFile zip=(zipFile)zd->zip; + zipFile zip = (zipFile)zd->zip; zipOpenNewFileInZip(zip, - path.utf8().get_data(), - NULL, - NULL, - 0, - NULL, - 0, - NULL, - Z_DEFLATED, - Z_DEFAULT_COMPRESSION); - - zipWriteInFileInZip(zip,p_data.ptr(),p_data.size()); + path.utf8().get_data(), + NULL, + NULL, + 0, + NULL, + 0, + NULL, + Z_DEFLATED, + Z_DEFAULT_COMPRESSION); + + zipWriteInFileInZip(zip, p_data.ptr(), p_data.size()); zipCloseFileInZip(zip); - zd->ep->step(TTR("Storing File:")+" "+p_path,2+p_file*100/p_total,false); + zd->ep->step(TTR("Storing File:") + " " + p_path, 2 + p_file * 100 / p_total, false); return OK; } String EditorExportPlatform::find_export_template(String template_file_name, String *err) const { - String user_file = EditorSettings::get_singleton()->get_settings_path() - +"/templates/"+itos(VERSION_MAJOR)+"."+itos(VERSION_MINOR)+"."+_MKSTR(VERSION_STATUS)+"/"+template_file_name; - String system_file=OS::get_singleton()->get_installed_templates_path(); - bool has_system_path=(system_file!=""); - system_file+=template_file_name; + String user_file = EditorSettings::get_singleton()->get_settings_path() + "/templates/" + itos(VERSION_MAJOR) + "." + itos(VERSION_MINOR) + "." + _MKSTR(VERSION_STATUS) + "/" + 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)) { @@ -345,11 +336,11 @@ String EditorExportPlatform::find_export_template(String template_file_name, Str // Not found if (err) { - *err+="No export template found at \""+user_file+"\""; + *err += "No export template found at \"" + user_file + "\""; if (has_system_path) - *err+="\n or \""+system_file+"\"."; + *err += "\n or \"" + system_file + "\"."; else - *err+="."; + *err += "."; } return ""; } @@ -358,34 +349,32 @@ Ref<EditorExportPreset> EditorExportPlatform::create_preset() { Ref<EditorExportPreset> preset; preset.instance(); - preset->platform=Ref<EditorExportPlatform>(this); + preset->platform = Ref<EditorExportPlatform>(this); List<ExportOption> options; get_export_options(&options); - for (List<ExportOption>::Element *E=options.front();E;E=E->next()) { + for (List<ExportOption>::Element *E = options.front(); E; E = E->next()) { preset->properties.push_back(E->get().option); - preset->values[E->get().option.name]=E->get().default_value; + preset->values[E->get().option.name] = E->get().default_value; } return preset; - } -void EditorExportPlatform::_export_find_resources(EditorFileSystemDirectory *p_dir,Set<String>& p_paths) { +void EditorExportPlatform::_export_find_resources(EditorFileSystemDirectory *p_dir, Set<String> &p_paths) { - for(int i=0;i<p_dir->get_subdir_count();i++) { - _export_find_resources(p_dir->get_subdir(i),p_paths); + for (int i = 0; i < p_dir->get_subdir_count(); i++) { + _export_find_resources(p_dir->get_subdir(i), p_paths); } - for(int i=0;i<p_dir->get_file_count();i++) { + for (int i = 0; i < p_dir->get_file_count(); i++) { p_paths.insert(p_dir->get_file_path(i)); } } - -void EditorExportPlatform::_export_find_dependencies(const String& p_path,Set<String>& p_paths) { +void EditorExportPlatform::_export_find_dependencies(const String &p_path, Set<String> &p_paths) { if (p_paths.has(p_path)) return; @@ -394,94 +383,93 @@ void EditorExportPlatform::_export_find_dependencies(const String& p_path,Set<St EditorFileSystemDirectory *dir; int file_idx; - dir = EditorFileSystem::get_singleton()->find_file(p_path,&file_idx); + dir = EditorFileSystem::get_singleton()->find_file(p_path, &file_idx); if (!dir) return; Vector<String> deps = dir->get_file_deps(file_idx); - for(int i=0;i<deps.size();i++) { + for (int i = 0; i < deps.size(); i++) { - _export_find_dependencies(deps[i],p_paths); + _export_find_dependencies(deps[i], p_paths); } } - -Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset>& p_preset,EditorExportSaveFunction p_func, void* p_udata) { +Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &p_preset, EditorExportSaveFunction p_func, void *p_udata) { Ref<EditorExportPlatform> platform = p_preset->get_platform(); List<String> feature_list; - platform->get_preset_features(p_preset,&feature_list); + platform->get_preset_features(p_preset, &feature_list); //figure out features Set<String> features; - for (List<String>::Element *E=feature_list.front();E;E=E->next()) { + for (List<String>::Element *E = feature_list.front(); E; E = E->next()) { features.insert(E->get()); } //figure out paths of files that will be exported Set<String> paths; - if (p_preset->get_export_filter()==EditorExportPreset::EXPORT_ALL_RESOURCES) { + if (p_preset->get_export_filter() == EditorExportPreset::EXPORT_ALL_RESOURCES) { //find stuff - _export_find_resources(EditorFileSystem::get_singleton()->get_filesystem(),paths); + _export_find_resources(EditorFileSystem::get_singleton()->get_filesystem(), paths); } else { - bool scenes_only = p_preset->get_export_filter()==EditorExportPreset::EXPORT_SELECTED_SCENES; + bool scenes_only = p_preset->get_export_filter() == EditorExportPreset::EXPORT_SELECTED_SCENES; Vector<String> files = p_preset->get_files_to_export(); - for(int i=0;i<files.size();i++) { - if (scenes_only && ResourceLoader::get_resource_type(files[i])!="PackedScene") + for (int i = 0; i < files.size(); i++) { + if (scenes_only && ResourceLoader::get_resource_type(files[i]) != "PackedScene") continue; - _export_find_dependencies(files[i],paths); + _export_find_dependencies(files[i], paths); } } //store everything in the export medium int idx = 0; - int total=paths.size(); + int total = paths.size(); - for(Set<String>::Element *E=paths.front();E;E=E->next()) { + for (Set<String>::Element *E = paths.front(); E; E = E->next()) { String path = E->get(); - if (FileAccess::exists(path+".import")) { + if (FileAccess::exists(path + ".import")) { //file is imported, replace by what it imports Ref<ConfigFile> config; config.instance(); - Error err = config->load(path+".import"); - if (err!=OK) { - ERR_PRINTS("Could not parse: '"+path+"', not exported."); + Error err = config->load(path + ".import"); + if (err != OK) { + ERR_PRINTS("Could not parse: '" + path + "', not exported."); continue; } List<String> remaps; - config->get_section_keys("remap",&remaps); + config->get_section_keys("remap", &remaps); - for(List<String>::Element *F=remaps.front();F;F=F->next()) { + for (List<String>::Element *F = remaps.front(); F; F = F->next()) { - String remap=F->get(); - if (remap=="path") { - String remapped_path=config->get_value("remap",remap); + String remap = F->get(); + if (remap == "path") { + String remapped_path = config->get_value("remap", remap); Vector<uint8_t> array = FileAccess::get_file_as_array(remapped_path); - p_func(p_udata,remapped_path,array,idx,total); + p_func(p_udata, remapped_path, array, idx, total); } else if (remap.begins_with("path.")) { - String feature = remap.get_slice(".",1); + String feature = remap.get_slice(".", 1); if (features.has(feature)) { - String remapped_path=config->get_value("remap",remap); + String remapped_path = config->get_value("remap", remap); Vector<uint8_t> array = FileAccess::get_file_as_array(remapped_path); - p_func(p_udata,remapped_path,array,idx,total); + p_func(p_udata, remapped_path, array, idx, total); } } } //also save the .import file - Vector<uint8_t> array = FileAccess::get_file_as_array(path+".import"); - p_func(p_udata,path+".import",array,idx,total); + Vector<uint8_t> array = FileAccess::get_file_as_array(path + ".import"); + p_func(p_udata, path + ".import", array, idx, total); } else { //just store it as it comes Vector<uint8_t> array = FileAccess::get_file_as_array(path); - p_func(p_udata,path,array,idx,total); + p_func(p_udata, path, array, idx, total); } idx++; @@ -489,29 +477,29 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset>& //save config! - String config_file="godot.cfb"; - String engine_cfb =EditorSettings::get_singleton()->get_settings_path()+"/tmp/tmp"+config_file; + String config_file = "godot.cfb"; + String engine_cfb = EditorSettings::get_singleton()->get_settings_path() + "/tmp/tmp" + config_file; GlobalConfig::get_singleton()->save_custom(engine_cfb); Vector<uint8_t> data = FileAccess::get_file_as_array(engine_cfb); - p_func(p_udata,"res://"+config_file,data,idx,total); + p_func(p_udata, "res://" + config_file, data, idx, total); return OK; } -Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset>& p_preset,const String& p_path) { +Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, const String &p_path) { - EditorProgress ep("savepack",TTR("Packing"),102); + EditorProgress ep("savepack", TTR("Packing"), 102); - String tmppath = EditorSettings::get_singleton()->get_settings_path()+"/tmp/packtmp"; - FileAccess *ftmp = FileAccess::open(tmppath,FileAccess::WRITE); - ERR_FAIL_COND_V(!ftmp,ERR_CANT_CREATE) + String tmppath = EditorSettings::get_singleton()->get_settings_path() + "/tmp/packtmp"; + FileAccess *ftmp = FileAccess::open(tmppath, FileAccess::WRITE); + ERR_FAIL_COND_V(!ftmp, ERR_CANT_CREATE) PackData pd; - pd.ep=&ep; - pd.f=ftmp; + pd.ep = &ep; + pd.f = ftmp; - Error err = export_project_files(p_preset,_save_pack_file,&pd); + Error err = export_project_files(p_preset, _save_pack_file, &pd); memdelete(ftmp); //close tmp file @@ -520,15 +508,14 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset>& p_preset,co pd.file_ofs.sort(); //do sort, so we can do binary search later - - FileAccess *f = FileAccess::open(p_path,FileAccess::WRITE); - ERR_FAIL_COND_V(!f,ERR_CANT_CREATE) + FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE); + ERR_FAIL_COND_V(!f, ERR_CANT_CREATE) f->store_32(0x43504447); //GDPK f->store_32(1); //pack version f->store_32(VERSION_MAJOR); f->store_32(VERSION_MINOR); f->store_32(0); //hmph - for(int i=0;i<16;i++) { + for (int i = 0; i < 16; i++) { //reserved f->store_32(0); } @@ -539,55 +526,54 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset>& p_preset,co //precalculate header size - for(int i=0;i<pd.file_ofs.size();i++) { + for (int i = 0; i < pd.file_ofs.size(); i++) { header_size += 4; // size of path string (32 bits is enough) uint32_t string_len = pd.file_ofs[i].path_utf8.length(); - header_size += string_len + _get_pad(4,string_len); ///size of path string + header_size += string_len + _get_pad(4, string_len); ///size of path string header_size += 8; // offset to file _with_ header size included header_size += 8; // size of file - header_size +=16; // md5 - + header_size += 16; // md5 } - size_t header_padding = _get_pad(PCK_PADDING,header_size); + size_t header_padding = _get_pad(PCK_PADDING, header_size); - - for(int i=0;i<pd.file_ofs.size();i++) { + for (int i = 0; i < pd.file_ofs.size(); i++) { uint32_t string_len = pd.file_ofs[i].path_utf8.length(); - uint32_t pad = _get_pad(4,string_len);; - f->store_32(string_len+pad); - f->store_buffer((const uint8_t*)pd.file_ofs[i].path_utf8.get_data(),string_len); - for(uint32_t j=0;j<pad;j++) { + uint32_t pad = _get_pad(4, string_len); + ; + f->store_32(string_len + pad); + f->store_buffer((const uint8_t *)pd.file_ofs[i].path_utf8.get_data(), string_len); + for (uint32_t j = 0; j < pad; j++) { f->store_8(0); } f->store_64(pd.file_ofs[i].ofs + header_padding + header_size); f->store_64(pd.file_ofs[i].size); // pay attention here, this is where file is - f->store_buffer(pd.file_ofs[i].md5.ptr(),16); //also save md5 for file + f->store_buffer(pd.file_ofs[i].md5.ptr(), 16); //also save md5 for file } - for(uint32_t j=0;j<header_padding;j++) { + for (uint32_t j = 0; j < header_padding; j++) { f->store_8(0); } //save the rest of the data - ftmp = FileAccess::open(tmppath,FileAccess::READ); + ftmp = FileAccess::open(tmppath, FileAccess::READ); if (!ftmp) { memdelete(f); - ERR_FAIL_COND_V(!ftmp,ERR_CANT_CREATE) + ERR_FAIL_COND_V(!ftmp, ERR_CANT_CREATE) } - const int bufsize=16384; + const int bufsize = 16384; uint8_t buf[bufsize]; - while(true) { + while (true) { - int got = ftmp->get_buffer(buf,bufsize); - if (got<=0) + int got = ftmp->get_buffer(buf, bufsize); + if (got <= 0) break; - f->store_buffer(buf,got); + f->store_buffer(buf, got); } memdelete(ftmp); @@ -598,91 +584,81 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset>& p_preset,co return OK; } -Error EditorExportPlatform::save_zip(const Ref<EditorExportPreset>& p_preset,const String& p_path) { +Error EditorExportPlatform::save_zip(const Ref<EditorExportPreset> &p_preset, const String &p_path) { - EditorProgress ep("savezip",TTR("Packing"),102); + EditorProgress ep("savezip", TTR("Packing"), 102); //FileAccess *tmp = FileAccess::open(tmppath,FileAccess::WRITE); FileAccess *src_f; zlib_filefunc_def io = zipio_create_io_from_file(&src_f); - zipFile zip=zipOpen2(p_path.utf8().get_data(),APPEND_STATUS_CREATE,NULL,&io); + zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io); ZipData zd; - zd.ep=&ep; - zd.zip=zip; - + zd.ep = &ep; + zd.zip = zip; - Error err = export_project_files(p_preset,_save_zip_file,&zd); + Error err = export_project_files(p_preset, _save_zip_file, &zd); - zipClose(zip,NULL); + zipClose(zip, NULL); return OK; } EditorExportPlatform::EditorExportPlatform() { - - } - //// -EditorExport *EditorExport::singleton=NULL; - +EditorExport *EditorExport::singleton = NULL; void EditorExport::_save() { - Ref<ConfigFile> config; config.instance(); - for(int i=0;i<export_presets.size();i++) { + for (int i = 0; i < export_presets.size(); i++) { Ref<EditorExportPreset> preset = export_presets[i]; - String section="preset."+itos(i); + String section = "preset." + itos(i); - config->set_value(section,"name",preset->get_name()); - config->set_value(section,"platform",preset->get_platform()->get_name()); - config->set_value(section,"runnable",preset->is_runnable()); - bool save_files=false; - switch(preset->get_export_filter()) { + config->set_value(section, "name", preset->get_name()); + config->set_value(section, "platform", preset->get_platform()->get_name()); + config->set_value(section, "runnable", preset->is_runnable()); + bool save_files = false; + switch (preset->get_export_filter()) { case EditorExportPreset::EXPORT_ALL_RESOURCES: { - config->set_value(section,"export_filter","all_resources"); + config->set_value(section, "export_filter", "all_resources"); } break; case EditorExportPreset::EXPORT_SELECTED_SCENES: { - config->set_value(section,"export_filter","scenes"); - save_files=true; + config->set_value(section, "export_filter", "scenes"); + save_files = true; } break; case EditorExportPreset::EXPORT_SELECTED_RESOURCES: { - config->set_value(section,"export_filter","resources"); - save_files=true; + config->set_value(section, "export_filter", "resources"); + save_files = true; } break; - - } if (save_files) { Vector<String> export_files = preset->get_files_to_export(); - config->set_value(section,"export_files",export_files); + config->set_value(section, "export_files", export_files); } - config->set_value(section,"include_filter",preset->get_include_filter()); - config->set_value(section,"exclude_filter",preset->get_exclude_filter()); - config->set_value(section,"patch_list",preset->get_patches()); + config->set_value(section, "include_filter", preset->get_include_filter()); + config->set_value(section, "exclude_filter", preset->get_exclude_filter()); + config->set_value(section, "patch_list", preset->get_patches()); - String option_section="preset."+itos(i)+".options"; + String option_section = "preset." + itos(i) + ".options"; - for (const List<PropertyInfo>::Element *E=preset->get_properties().front();E;E=E->next()) { - config->set_value(option_section,E->get().name,preset->get(E->get().name)); + for (const List<PropertyInfo>::Element *E = preset->get_properties().front(); E; E = E->next()) { + config->set_value(option_section, E->get().name, preset->get(E->get().name)); } } config->save("res://export_presets.cfg"); print_line("saved ok"); - } - void EditorExport::save_presets() { print_line("save presets"); @@ -693,10 +669,10 @@ void EditorExport::save_presets() { void EditorExport::_bind_methods() { - ClassDB::bind_method("_save",&EditorExport::_save); + ClassDB::bind_method("_save", &EditorExport::_save); } -void EditorExport::add_export_platform(const Ref<EditorExportPlatform>& p_platform) { +void EditorExport::add_export_platform(const Ref<EditorExportPlatform> &p_platform) { export_platforms.push_back(p_platform); } @@ -708,20 +684,17 @@ int EditorExport::get_export_platform_count() { Ref<EditorExportPlatform> EditorExport::get_export_platform(int p_idx) { - ERR_FAIL_INDEX_V(p_idx,export_platforms.size(),Ref<EditorExportPlatform>()); + ERR_FAIL_INDEX_V(p_idx, export_platforms.size(), Ref<EditorExportPlatform>()); return export_platforms[p_idx]; } +void EditorExport::add_export_preset(const Ref<EditorExportPreset> &p_preset, int p_at_pos) { -void EditorExport::add_export_preset(const Ref<EditorExportPreset>& p_preset,int p_at_pos) { - - if (p_at_pos<0) + if (p_at_pos < 0) export_presets.push_back(p_preset); else - export_presets.insert(p_at_pos,p_preset); - - + export_presets.insert(p_at_pos, p_preset); } int EditorExport::get_export_preset_count() const { @@ -731,7 +704,7 @@ int EditorExport::get_export_preset_count() const { Ref<EditorExportPreset> EditorExport::get_export_preset(int p_idx) { - ERR_FAIL_INDEX_V( p_idx, export_presets.size(),Ref<EditorExportPreset>() ); + ERR_FAIL_INDEX_V(p_idx, export_presets.size(), Ref<EditorExportPreset>()); return export_presets[p_idx]; } @@ -742,7 +715,7 @@ void EditorExport::remove_export_preset(int p_idx) { void EditorExport::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_TREE) { + if (p_what == NOTIFICATION_ENTER_TREE) { load_config(); } } @@ -752,24 +725,24 @@ void EditorExport::load_config() { Ref<ConfigFile> config; config.instance(); Error err = config->load("res://export_presets.cfg"); - if (err!=OK) + if (err != OK) return; - block_save=true; + block_save = true; - int index=0; - while(true) { + int index = 0; + while (true) { - String section = "preset."+itos(index); + String section = "preset." + itos(index); if (!config->has_section(section)) break; - String platform=config->get_value(section,"platform"); + String platform = config->get_value(section, "platform"); Ref<EditorExportPreset> preset; - for(int i=0;i<export_platforms.size();i++) { - if (export_platforms[i]->get_name()==platform) { + for (int i = 0; i < export_platforms.size(); i++) { + if (export_platforms[i]->get_name() == platform) { preset = export_platforms[i]->create_preset(); break; } @@ -780,86 +753,79 @@ void EditorExport::load_config() { ERR_CONTINUE(!preset.is_valid()); } - preset->set_name( config->get_value(section,"name") ); - preset->set_runnable( config->get_value(section,"runnable") ); + preset->set_name(config->get_value(section, "name")); + preset->set_runnable(config->get_value(section, "runnable")); - String export_filter = config->get_value(section,"export_filter"); + String export_filter = config->get_value(section, "export_filter"); - bool get_files=false; + bool get_files = false; - if (export_filter=="all_resources") { + if (export_filter == "all_resources") { preset->set_export_filter(EditorExportPreset::EXPORT_ALL_RESOURCES); - } else if (export_filter=="scenes") { + } else if (export_filter == "scenes") { preset->set_export_filter(EditorExportPreset::EXPORT_SELECTED_SCENES); - get_files=true; - } else if (export_filter=="resources") { + get_files = true; + } else if (export_filter == "resources") { preset->set_export_filter(EditorExportPreset::EXPORT_SELECTED_RESOURCES); - get_files=true; + get_files = true; } if (get_files) { - Vector<String> files = config->get_value(section,"export_files"); + Vector<String> files = config->get_value(section, "export_files"); - for(int i=0;i<files.size();i++) { + for (int i = 0; i < files.size(); i++) { preset->add_export_file(files[i]); } } - preset->set_include_filter( config->get_value(section,"include_filter") ); - preset->set_exclude_filter( config->get_value(section,"exclude_filter") ); + preset->set_include_filter(config->get_value(section, "include_filter")); + preset->set_exclude_filter(config->get_value(section, "exclude_filter")); + Vector<String> patch_list = config->get_value(section, "patch_list"); - Vector<String> patch_list = config->get_value(section,"patch_list"); - - for(int i=0;i<patch_list.size();i++) { + for (int i = 0; i < patch_list.size(); i++) { preset->add_patch(patch_list[i]); } - String option_section="preset."+itos(index)+".options"; + String option_section = "preset." + itos(index) + ".options"; List<String> options; - config->get_section_keys(option_section,&options); + config->get_section_keys(option_section, &options); - for (List<String>::Element *E=options.front();E;E=E->next()) { + for (List<String>::Element *E = options.front(); E; E = E->next()) { - Variant value = config->get_value(option_section,E->get()); + Variant value = config->get_value(option_section, E->get()); - preset->set(E->get(),value); + preset->set(E->get(), value); } add_export_preset(preset); index++; } - block_save=false; - + block_save = false; } - - EditorExport::EditorExport() { - save_timer = memnew( Timer ); + save_timer = memnew(Timer); add_child(save_timer); save_timer->set_wait_time(0.8); save_timer->set_one_shot(true); - save_timer->connect("timeout",this,"_save"); - block_save=false; + save_timer->connect("timeout", this, "_save"); + block_save = false; - singleton=this; + singleton = this; } EditorExport::~EditorExport() { - - } - ////////// -void EditorExportPlatformPC::get_preset_features(const Ref<EditorExportPreset>& p_preset,List<String>* r_features) { +void EditorExportPlatformPC::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) { if (p_preset->get("texture_format/s3tc")) { r_features->push_back("s3tc"); @@ -874,35 +840,35 @@ void EditorExportPlatformPC::get_preset_features(const Ref<EditorExportPreset>& void EditorExportPlatformPC::get_export_options(List<ExportOption> *r_options) { - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL,"texture_format/s3tc"),true)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL,"texture_format/etc"),false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL,"texture_format/etc2"),false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL,"binary_format/64_bits"),true)); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING,"custom_template/release",PROPERTY_HINT_GLOBAL_FILE),"")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING,"custom_template/debug",PROPERTY_HINT_GLOBAL_FILE),"")); + r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), true)); + r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), false)); + r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), false)); + r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "binary_format/64_bits"), true)); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE), "")); } String EditorExportPlatformPC::get_name() const { return name; } -Ref<Texture> EditorExportPlatformPC::get_logo() const { +Ref<Texture> EditorExportPlatformPC::get_logo() const { return logo; } -bool EditorExportPlatformPC::can_export(const Ref<EditorExportPreset>& p_preset,String &r_error, bool &r_missing_templates) const { +bool EditorExportPlatformPC::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const { - r_missing_templates=false; + r_missing_templates = false; - if (find_export_template(release_file_32)==String()) { - r_missing_templates=true; - } else if (find_export_template(debug_file_32)==String()) { - r_missing_templates=true; - } else if (find_export_template(release_file_64)==String()) { - r_missing_templates=true; - } else if (find_export_template(debug_file_64)==String()) { - r_missing_templates=true; + if (find_export_template(release_file_32) == String()) { + r_missing_templates = true; + } else if (find_export_template(debug_file_32) == String()) { + r_missing_templates = true; + } else if (find_export_template(release_file_64) == String()) { + r_missing_templates = true; + } else if (find_export_template(debug_file_64) == String()) { + r_missing_templates = true; } return !r_missing_templates; } @@ -911,64 +877,62 @@ String EditorExportPlatformPC::get_binary_extension() const { return extension; } -Error EditorExportPlatformPC::export_project(const Ref<EditorExportPreset>& p_preset, bool p_debug, const String& p_path, int p_flags) { +Error EditorExportPlatformPC::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) { return OK; } -void EditorExportPlatformPC::set_extension(const String& p_extension) { - extension=p_extension; +void EditorExportPlatformPC::set_extension(const String &p_extension) { + extension = p_extension; } -void EditorExportPlatformPC::set_name(const String& p_name) { - name=p_name; +void EditorExportPlatformPC::set_name(const String &p_name) { + name = p_name; } -void EditorExportPlatformPC::set_logo(const Ref<Texture>& p_logo) { - logo=p_logo; +void EditorExportPlatformPC::set_logo(const Ref<Texture> &p_logo) { + logo = p_logo; } -void EditorExportPlatformPC::set_release_64(const String& p_file) { +void EditorExportPlatformPC::set_release_64(const String &p_file) { - release_file_64=p_file; + release_file_64 = p_file; } -void EditorExportPlatformPC::set_release_32(const String& p_file){ +void EditorExportPlatformPC::set_release_32(const String &p_file) { - release_file_32=p_file; + release_file_32 = p_file; } -void EditorExportPlatformPC::set_debug_64(const String& p_file){ +void EditorExportPlatformPC::set_debug_64(const String &p_file) { - debug_file_64=p_file; + debug_file_64 = p_file; } -void EditorExportPlatformPC::set_debug_32(const String& p_file){ - - debug_file_32=p_file; +void EditorExportPlatformPC::set_debug_32(const String &p_file) { + debug_file_32 = p_file; } EditorExportPlatformPC::EditorExportPlatformPC() { - } //////// #if 0 -#include "version.h" -#include "script_language.h" -#include "global_config.h" -#include "os/file_access.h" -#include "os/dir_access.h" #include "editor/editor_file_system.h" -#include "io/resource_loader.h" +#include "editor/plugins/script_editor_plugin.h" #include "editor_node.h" #include "editor_settings.h" +#include "global_config.h" #include "io/config_file.h" -#include "io/resource_saver.h" #include "io/md5.h" -#include "io_plugins/editor_texture_import_plugin.h" -#include "editor/plugins/script_editor_plugin.h" +#include "io/resource_loader.h" +#include "io/resource_saver.h" #include "io/zip_io.h" +#include "io_plugins/editor_texture_import_plugin.h" +#include "os/dir_access.h" +#include "os/file_access.h" +#include "script_language.h" +#include "version.h" String EditorImportPlugin::validate_source_path(const String& p_path) { |