summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorkubecz3k <kubecz3k@gmail.com>2017-08-15 23:41:46 +0200
committerGitHub <noreply@github.com>2017-08-15 23:41:46 +0200
commit41d8ddf7c4d226cf98119a9fe65debdcfdef2599 (patch)
tree6980caa0d1fe0a16ed9e5f11a1b5d44b3e13cd52 /editor
parenta6c4e0105c687d99819219de56e1b6cf8b715075 (diff)
parent571a3a2dcdb4f43b5c58b048874cbdf6b67253de (diff)
Merge pull request #10336 from endragor/export-filters
Use include/exclude export filters. Fixes #9860
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_export.cpp61
-rw-r--r--editor/editor_export.h4
2 files changed, 64 insertions, 1 deletions
diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp
index 36fd86d88f..fe1dfa281c 100644
--- a/editor/editor_export.cpp
+++ b/editor/editor_export.cpp
@@ -37,7 +37,6 @@
#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 "project_settings.h"
#include "script_language.h"
@@ -420,6 +419,63 @@ void EditorExportPlatform::_export_find_dependencies(const String &p_path, Set<S
}
}
+void EditorExportPlatform::_edit_files_with_filter(DirAccess *da, const Vector<String> &p_filters, Set<String> &r_list, bool exclude) {
+
+ da->list_dir_begin();
+ String cur_dir = da->get_current_dir().replace("\\", "/");
+ if (!cur_dir.ends_with("/"))
+ cur_dir += "/";
+
+ Vector<String> dirs;
+ String f;
+ while ((f = da->get_next()) != "") {
+ if (da->current_is_dir())
+ dirs.push_back(f);
+ else {
+ String fullpath = cur_dir + f;
+ for (int i = 0; i < p_filters.size(); ++i) {
+ if (fullpath.matchn(p_filters[i])) {
+ if (!exclude) {
+ r_list.insert(fullpath);
+ } else {
+ r_list.erase(fullpath);
+ }
+ }
+ }
+ }
+ }
+
+ da->list_dir_end();
+
+ for (int i = 0; i < dirs.size(); ++i) {
+ String dir = dirs[i];
+ if (dir.begins_with("."))
+ continue;
+ da->change_dir(dir);
+ _edit_files_with_filter(da, p_filters, r_list, exclude);
+ da->change_dir("..");
+ }
+}
+
+void EditorExportPlatform::_edit_filter_list(Set<String> &r_list, const String &p_filter, bool exclude) {
+
+ if (p_filter == "")
+ return;
+ Vector<String> split = p_filter.split(",");
+ Vector<String> filters;
+ for (int i = 0; i < split.size(); i++) {
+ String f = split[i].strip_edges();
+ if (f.empty())
+ continue;
+ filters.push_back(f);
+ }
+
+ DirAccess *da = DirAccess::open("res://");
+ ERR_FAIL_NULL(da);
+ _edit_files_with_filter(da, filters, r_list, exclude);
+ memdelete(da);
+}
+
Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &p_preset, EditorExportSaveFunction p_func, void *p_udata) {
Ref<EditorExportPlatform> platform = p_preset->get_platform();
@@ -449,6 +505,9 @@ 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);
+
//store everything in the export medium
int idx = 0;
int total = paths.size();
diff --git a/editor/editor_export.h b/editor/editor_export.h
index dc4b198575..91e012d945 100644
--- a/editor/editor_export.h
+++ b/editor/editor_export.h
@@ -30,6 +30,7 @@
#ifndef EDITOR_EXPORT_H
#define EDITOR_EXPORT_H
+#include "os/dir_access.h"
#include "resource.h"
#include "scene/main/node.h"
#include "scene/main/timer.h"
@@ -157,6 +158,9 @@ private:
static Error _save_pack_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total);
static Error _save_zip_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total);
+ void _edit_files_with_filter(DirAccess *da, const Vector<String> &p_filters, Set<String> &r_list, bool exclude);
+ void _edit_filter_list(Set<String> &r_list, const String &p_filter, bool exclude);
+
protected:
bool exists_export_template(String template_file_name, String *err) const;
String find_export_template(String template_file_name, String *err = NULL) const;