summaryrefslogtreecommitdiff
path: root/editor/editor_export.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_export.cpp')
-rw-r--r--editor/editor_export.cpp159
1 files changed, 154 insertions, 5 deletions
diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp
index 8623b9acdb..ad9bc4a662 100644
--- a/editor/editor_export.cpp
+++ b/editor/editor_export.cpp
@@ -476,19 +476,77 @@ void EditorExportPlatform::_edit_filter_list(Set<String> &r_list, const String &
memdelete(da);
}
-Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &p_preset, EditorExportSaveFunction p_func, void *p_udata) {
+void EditorExportPlugin::add_file(const String &p_path, const Vector<uint8_t> &p_file, bool p_remap) {
+
+ ExtraFile ef;
+ ef.data = p_file;
+ ef.path = p_path;
+ ef.remap = p_remap;
+ extra_files.push_back(ef);
+}
+
+void EditorExportPlugin::add_shared_object(const String &p_path) {
+
+ shared_objects.push_back(p_path);
+}
+
+void EditorExportPlugin::_export_file_script(const String &p_path, const String &p_type, const PoolVector<String> &p_features) {
+
+ if (get_script_instance()) {
+ get_script_instance()->call("_export_file", p_path, p_type, p_features);
+ }
+}
+
+void EditorExportPlugin::_export_begin_script(const PoolVector<String> &p_features) {
+
+ if (get_script_instance()) {
+ get_script_instance()->call("_export_begin", p_features);
+ }
+}
+
+void EditorExportPlugin::_export_file(const String &p_path, const String &p_type, const Set<String> &p_features) {
+}
+
+void EditorExportPlugin::_export_begin(const Set<String> &p_features) {
+}
+
+void EditorExportPlugin::skip() {
+
+ skipped = true;
+}
+
+void EditorExportPlugin::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("add_shared_object", "path"), &EditorExportPlugin::add_shared_object);
+ ClassDB::bind_method(D_METHOD("add_file", "path", "file", "remap"), &EditorExportPlugin::add_file);
+ ClassDB::bind_method(D_METHOD("skip"), &EditorExportPlugin::skip);
+
+ BIND_VMETHOD(MethodInfo("_export_file", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "type"), PropertyInfo(Variant::POOL_STRING_ARRAY, "features")));
+ BIND_VMETHOD(MethodInfo("_export_begin", PropertyInfo(Variant::POOL_STRING_ARRAY, "features")));
+}
+
+EditorExportPlugin::EditorExportPlugin() {
+ skipped = false;
+}
+
+Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &p_preset, EditorExportSaveFunction p_func, void *p_udata, EditorExportSaveSharedObject p_so_func) {
Ref<EditorExportPlatform> platform = p_preset->get_platform();
List<String> feature_list;
platform->get_preset_features(p_preset, &feature_list);
//figure out features
Set<String> features;
+ PoolVector<String> features_pv;
for (List<String>::Element *E = feature_list.front(); E; E = E->next()) {
features.insert(E->get());
+ features_pv.push_back(E->get());
}
+ Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins();
+
//figure out paths of files that will be exported
Set<String> paths;
+ Vector<String> path_remaps;
if (p_preset->get_export_filter() == EditorExportPreset::EXPORT_ALL_RESOURCES) {
//find stuff
@@ -508,6 +566,25 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
_edit_filter_list(paths, p_preset->get_include_filter(), false);
_edit_filter_list(paths, p_preset->get_exclude_filter(), true);
+ //initial export plugin callback
+ for (int i = 0; i < export_plugins.size(); i++) {
+ if (export_plugins[i]->get_script_instance()) { //script based
+ export_plugins[i]->_export_begin_script(features_pv);
+ } else {
+ export_plugins[i]->_export_begin(features);
+ }
+ if (p_so_func) {
+ for (int j = 0; j < export_plugins[i]->shared_objects.size(); j++) {
+ p_so_func(p_udata, export_plugins[i]->shared_objects[j]);
+ }
+ }
+ for (int j = 0; j < export_plugins[i]->extra_files.size(); j++) {
+ p_func(p_udata, export_plugins[i]->extra_files[j].path, export_plugins[i]->extra_files[j].data, 0, paths.size());
+ }
+
+ export_plugins[i]->_clear();
+ }
+
//store everything in the export medium
int idx = 0;
int total = paths.size();
@@ -515,6 +592,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
for (Set<String>::Element *E = paths.front(); E; E = E->next()) {
String path = E->get();
+ String type = ResourceLoader::get_resource_type(path);
if (FileAccess::exists(path + ".import")) {
//file is imported, replace by what it imports
@@ -551,9 +629,42 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
p_func(p_udata, path + ".import", array, idx, total);
} else {
+
+ bool do_export = true;
+ for (int i = 0; i < export_plugins.size(); i++) {
+ if (export_plugins[i]->get_script_instance()) { //script based
+ export_plugins[i]->_export_file_script(path, type, features_pv);
+ } else {
+ export_plugins[i]->_export_file(path, type, features);
+ }
+ if (p_so_func) {
+ for (int j = 0; j < export_plugins[i]->shared_objects.size(); j++) {
+ p_so_func(p_udata, export_plugins[i]->shared_objects[j]);
+ }
+ }
+
+ for (int j = 0; j < export_plugins[i]->extra_files.size(); j++) {
+ p_func(p_udata, export_plugins[i]->extra_files[j].path, export_plugins[i]->extra_files[j].data, idx, total);
+ if (export_plugins[i]->extra_files[j].remap) {
+ do_export = false; //if remap, do not
+ path_remaps.push_back(path);
+ path_remaps.push_back(export_plugins[i]->extra_files[j].path);
+ }
+ }
+
+ if (export_plugins[i]->skipped) {
+ do_export = false;
+ }
+ export_plugins[i]->_clear();
+
+ if (!do_export)
+ break; //apologies, not exporting
+ }
//just store it as it comes
- Vector<uint8_t> array = FileAccess::get_file_as_array(path);
- p_func(p_udata, path, array, idx, total);
+ if (do_export) {
+ Vector<uint8_t> array = FileAccess::get_file_as_array(path);
+ p_func(p_udata, path, array, idx, total);
+ }
}
idx++;
@@ -575,9 +686,14 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
}
}
+ ProjectSettings::CustomMap custom_map;
+ if (path_remaps.size()) {
+ custom_map["path_remap/remapped_paths"] = path_remaps;
+ }
+
String config_file = "project.binary";
String engine_cfb = EditorSettings::get_singleton()->get_settings_path() + "/tmp/tmp" + config_file;
- ProjectSettings::get_singleton()->save_custom(engine_cfb, ProjectSettings::CustomMap(), custom_list);
+ ProjectSettings::get_singleton()->save_custom(engine_cfb, custom_map, custom_list);
Vector<uint8_t> data = FileAccess::get_file_as_array(engine_cfb);
p_func(p_udata, "res://" + config_file, data, idx, total);
@@ -867,6 +983,23 @@ void EditorExport::remove_export_preset(int p_idx) {
export_presets.remove(p_idx);
}
+void EditorExport::add_export_plugin(const Ref<EditorExportPlugin> &p_plugin) {
+
+ if (export_plugins.find(p_plugin) == 1) {
+ export_plugins.push_back(p_plugin);
+ }
+}
+
+void EditorExport::remove_export_plugin(const Ref<EditorExportPlugin> &p_plugin) {
+
+ export_plugins.erase(p_plugin);
+}
+
+Vector<Ref<EditorExportPlugin> > EditorExport::get_export_plugins() {
+
+ return export_plugins;
+}
+
void EditorExport::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
@@ -1113,9 +1246,13 @@ Error EditorExportPlatformPC::export_project(const Ref<EditorExportPreset> &p_pr
}
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
- da->copy(template_path, p_path);
+ Error err = da->copy(template_path, p_path, get_chmod_flags());
memdelete(da);
+ if (err != OK) {
+ return err;
+ }
+
String pck_path = p_path.get_basename() + ".pck";
return save_pack(p_preset, pck_path);
@@ -1169,5 +1306,17 @@ void EditorExportPlatformPC::get_platform_features(List<String> *r_features) {
}
}
+int EditorExportPlatformPC::get_chmod_flags() const {
+
+ return chmod_flags;
+}
+
+void EditorExportPlatformPC::set_chmod_flags(int p_flags) {
+
+ chmod_flags = p_flags;
+}
+
EditorExportPlatformPC::EditorExportPlatformPC() {
+
+ chmod_flags = -1;
}