summaryrefslogtreecommitdiff
path: root/editor/editor_file_system.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_file_system.cpp')
-rw-r--r--editor/editor_file_system.cpp121
1 files changed, 105 insertions, 16 deletions
diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp
index 2f4ac02703..c175886d14 100644
--- a/editor/editor_file_system.cpp
+++ b/editor/editor_file_system.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -118,6 +118,12 @@ Vector<String> EditorFileSystemDirectory::get_file_deps(int p_idx) const {
return files[p_idx]->deps;
}
+bool EditorFileSystemDirectory::get_file_import_is_valid(int p_idx) const {
+
+ ERR_FAIL_INDEX_V(p_idx, files.size(), false);
+ return files[p_idx]->import_valid;
+}
+
StringName EditorFileSystemDirectory::get_file_type(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, files.size(), "");
@@ -142,6 +148,7 @@ void EditorFileSystemDirectory::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_file", "idx"), &EditorFileSystemDirectory::get_file);
ClassDB::bind_method(D_METHOD("get_file_path", "idx"), &EditorFileSystemDirectory::get_file_path);
ClassDB::bind_method(D_METHOD("get_file_type", "idx"), &EditorFileSystemDirectory::get_file_type);
+ ClassDB::bind_method(D_METHOD("get_file_import_is_valid", "idx"), &EditorFileSystemDirectory::get_file_import_is_valid);
ClassDB::bind_method(D_METHOD("get_name"), &EditorFileSystemDirectory::get_name);
ClassDB::bind_method(D_METHOD("get_path"), &EditorFileSystemDirectory::get_path);
ClassDB::bind_method(D_METHOD("get_parent"), &EditorFileSystemDirectory::get_parent);
@@ -181,7 +188,7 @@ void EditorFileSystem::_scan_filesystem() {
String project = ProjectSettings::get_singleton()->get_resource_path();
- String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_cache2");
+ String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_cache3");
FileAccess *f = FileAccess::open(fscache, FileAccess::READ);
if (f) {
@@ -201,7 +208,7 @@ void EditorFileSystem::_scan_filesystem() {
} else {
Vector<String> split = l.split("::");
- ERR_CONTINUE(split.size() != 5);
+ ERR_CONTINUE(split.size() != 6);
String name = split[0];
String file;
@@ -212,8 +219,9 @@ void EditorFileSystem::_scan_filesystem() {
fc.type = split[1];
fc.modification_time = split[2].to_int64();
fc.import_modification_time = split[3].to_int64();
+ fc.import_valid = split[4].to_int64() != 0;
- String deps = split[4].strip_edges();
+ String deps = split[5].strip_edges();
if (deps.length()) {
Vector<String> dp = deps.split("<>");
for (int i = 0; i < dp.size(); i++) {
@@ -230,6 +238,28 @@ void EditorFileSystem::_scan_filesystem() {
memdelete(f);
}
+ String update_cache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_update3");
+
+ print_line("try to see fs update2");
+ if (FileAccess::exists(update_cache)) {
+
+ print_line("it exists");
+
+ {
+ FileAccessRef f = FileAccess::open(update_cache, FileAccess::READ);
+ String l = f->get_line().strip_edges();
+ while (l != String()) {
+
+ print_line("erased cache for: " + l + " " + itos(file_cache.has(l)));
+ file_cache.erase(l); //erase cache for this, so it gets updated
+ l = f->get_line().strip_edges();
+ }
+ }
+
+ DirAccessRef d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ d->remove(update_cache); //bye bye update cache
+ }
+
EditorProgressBG scan_progress("efs", "ScanFS", 1000);
ScanProgress sp;
@@ -260,7 +290,7 @@ void EditorFileSystem::_scan_filesystem() {
}
void EditorFileSystem::_save_filesystem_cache() {
- String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_cache2");
+ String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_cache3");
FileAccess *f = FileAccess::open(fscache, FileAccess::WRITE);
_save_filesystem_cache(filesystem, f);
@@ -597,11 +627,14 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess
if (fc && fc->modification_time == mt && fc->import_modification_time == import_mt && _check_missing_imported_files(path)) {
fi->type = fc->type;
+ fi->deps = fc->deps;
fi->modified_time = fc->modification_time;
fi->import_modified_time = fc->import_modification_time;
+ fi->import_valid = fc->import_valid;
if (fc->type == String()) {
fi->type = ResourceLoader::get_resource_type(path);
//there is also the chance that file type changed due to reimport, must probably check this somehow here (or kind of note it for next time in another file?)
+ //note: I think this should not happen any longer..
}
} else {
@@ -620,9 +653,11 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess
}
fi->type = ResourceFormatImporter::get_singleton()->get_resource_type(path);
+ //fi->deps = ResourceLoader::get_dependencies(path); pointless because it will be reimported, but..
print_line("import extension tried resource type for " + path + " and its " + fi->type);
fi->modified_time = 0;
fi->import_modified_time = 0;
+ fi->import_valid = ResourceLoader::is_import_valid(path);
ItemAction ia;
ia.action = ItemAction::ACTION_FILE_REIMPORT;
@@ -631,17 +666,22 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess
scan_actions.push_back(ia);
}
} else {
- //not imported, so just update type if changed
- if (fc && fc->modification_time == mt) {
+ if (fc && fc->modification_time == mt) {
+ //not imported, so just update type if changed
fi->type = fc->type;
fi->modified_time = fc->modification_time;
+ fi->deps = fc->deps;
fi->import_modified_time = 0;
+ fi->import_valid = true;
} else {
+ //new or modified time
fi->type = ResourceLoader::get_resource_type(path);
+ fi->deps = _get_dependencies(path);
print_line("regular import tried resource type for " + path + " and its " + fi->type);
fi->modified_time = mt;
fi->import_modified_time = 0;
+ fi->import_valid = true;
}
}
@@ -738,6 +778,7 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const
fi->modified_time = FileAccess::get_modified_time(path);
fi->import_modified_time = 0;
fi->type = ResourceLoader::get_resource_type(path);
+ fi->import_valid = ResourceLoader::is_import_valid(path);
{
ItemAction ia;
@@ -1008,7 +1049,7 @@ void EditorFileSystem::_save_filesystem_cache(EditorFileSystemDirectory *p_dir,
for (int i = 0; i < p_dir->files.size(); i++) {
- String s = p_dir->files[i]->file + "::" + p_dir->files[i]->type + "::" + itos(p_dir->files[i]->modified_time) + "::" + itos(p_dir->files[i]->import_modified_time);
+ String s = p_dir->files[i]->file + "::" + p_dir->files[i]->type + "::" + itos(p_dir->files[i]->modified_time) + "::" + itos(p_dir->files[i]->import_modified_time) + "::" + itos(p_dir->files[i]->import_valid);
s += "::";
for (int j = 0; j < p_dir->files[i]->deps.size(); j++) {
@@ -1187,12 +1228,34 @@ EditorFileSystemDirectory *EditorFileSystem::get_filesystem_path(const String &p
return fs;
}
+void EditorFileSystem::_save_late_updated_files() {
+ //files that already existed, and were modified, need re-scanning for dependencies upon project restart. This is done via saving this special file
+ String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_update3");
+ FileAccessRef f = FileAccess::open(fscache, FileAccess::WRITE);
+ for (Set<String>::Element *E = late_update_files.front(); E; E = E->next()) {
+ f->store_line(E->get());
+ }
+}
+
void EditorFileSystem::_resource_saved(const String &p_path) {
//print_line("resource saved: "+p_path);
EditorFileSystem::get_singleton()->update_file(p_path);
}
+Vector<String> EditorFileSystem::_get_dependencies(const String &p_path) {
+
+ List<String> deps;
+ ResourceLoader::get_dependencies(p_path, &deps);
+
+ Vector<String> ret;
+ for (List<String>::Element *E = deps.front(); E; E = E->next()) {
+ ret.push_back(E->get());
+ }
+
+ return ret;
+}
+
void EditorFileSystem::update_file(const String &p_file) {
EditorFileSystemDirectory *fs = NULL;
@@ -1217,6 +1280,9 @@ void EditorFileSystem::update_file(const String &p_file) {
if (cpos == -1) {
+ //the file did not exist, it was added
+
+ late_added_files.insert(p_file); //remember that it was added. This mean it will be scanned and imported on editor restart
int idx = 0;
for (int i = 0; i < fs->files.size(); i++) {
@@ -1228,6 +1294,7 @@ void EditorFileSystem::update_file(const String &p_file) {
EditorFileSystemDirectory::FileInfo *fi = memnew(EditorFileSystemDirectory::FileInfo);
fi->file = p_file.get_file();
fi->import_modified_time = 0;
+ fi->import_valid = ResourceLoader::is_import_valid(p_file);
if (idx == fs->files.size()) {
fs->files.push_back(fi);
@@ -1236,11 +1303,19 @@ void EditorFileSystem::update_file(const String &p_file) {
fs->files.insert(idx, fi);
}
cpos = idx;
+ } else {
+
+ //the file exists and it was updated, and was not added in this step.
+ //this means we must force upon next restart to scan it again, to get proper type and dependencies
+ late_update_files.insert(p_file);
+ _save_late_updated_files(); //files need to be updated in the re-scan
}
//print_line("UPDATING: "+p_file);
fs->files[cpos]->type = type;
fs->files[cpos]->modified_time = FileAccess::get_modified_time(p_file);
+ fs->files[cpos]->deps = _get_dependencies(p_file);
+ fs->files[cpos]->import_valid = ResourceLoader::is_import_valid(p_file);
//if (FileAccess::exists(p_file+".import")) {
// fs->files[cpos]->import_modified_time=FileAccess::get_modified_time(p_file+".import");
//}
@@ -1276,6 +1351,9 @@ void EditorFileSystem::_reimport_file(const String &p_file) {
}
importer_name = cf->get_value("remap", "importer");
}
+
+ } else {
+ late_added_files.insert(p_file); //imported files do not call update_file(), but just in case..
}
Ref<ResourceImporter> importer;
@@ -1341,22 +1419,30 @@ void EditorFileSystem::_reimport_file(const String &p_file) {
f->store_line("type=\"" + importer->get_resource_type() + "\"");
}
- if (importer->get_save_extension() == "") {
- //no path
- } else if (import_variants.size()) {
- //import with variants
- for (List<String>::Element *E = import_variants.front(); E; E = E->next()) {
+ if (err == OK) {
+
+ if (importer->get_save_extension() == "") {
+ //no path
+ } else if (import_variants.size()) {
+ //import with variants
+ for (List<String>::Element *E = import_variants.front(); E; E = E->next()) {
+
+ String path = base_path.c_escape() + "." + E->get() + "." + importer->get_save_extension();
- String path = base_path.c_escape() + "." + E->get() + "." + importer->get_save_extension();
+ f->store_line("path." + E->get() + "=\"" + path + "\"");
+ }
+ } else {
- f->store_line("path." + E->get() + "=\"" + path + "\"");
+ f->store_line("path=\"" + base_path + "." + importer->get_save_extension() + "\"");
}
+
} else {
- f->store_line("path=\"" + base_path + "." + importer->get_save_extension() + "\"");
+ f->store_line("valid=false");
}
f->store_line("");
+
if (gen_files.size()) {
f->store_line("[gen]");
Array genf;
@@ -1389,6 +1475,9 @@ void EditorFileSystem::_reimport_file(const String &p_file) {
//update modified times, to avoid reimport
fs->files[cpos]->modified_time = FileAccess::get_modified_time(p_file);
fs->files[cpos]->import_modified_time = FileAccess::get_modified_time(p_file + ".import");
+ fs->files[cpos]->deps = _get_dependencies(p_file);
+ fs->files[cpos]->type = importer->get_resource_type();
+ fs->files[cpos]->import_valid = ResourceLoader::is_import_valid(p_file);
//if file is currently up, maybe the source it was loaded from changed, so import math must be updated for it
//to reload properly