diff options
Diffstat (limited to 'editor/editor_file_system.cpp')
-rw-r--r-- | editor/editor_file_system.cpp | 198 |
1 files changed, 114 insertions, 84 deletions
diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index a6fc8dcddf..d462cce908 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -188,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_cache3"); + String fscache = EditorSettings::get_singleton()->get_project_settings_dir().plus_file("filesystem_cache3"); FileAccess *f = FileAccess::open(fscache, FileAccess::READ); if (f) { @@ -238,7 +238,7 @@ void EditorFileSystem::_scan_filesystem() { memdelete(f); } - String update_cache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_update3"); + String update_cache = EditorSettings::get_singleton()->get_project_settings_dir().plus_file("filesystem_update3"); if (FileAccess::exists(update_cache)) { { @@ -282,7 +282,7 @@ void EditorFileSystem::_scan_filesystem() { } void EditorFileSystem::_save_filesystem_cache() { - String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_cache3"); + String fscache = EditorSettings::get_singleton()->get_project_settings_dir().plus_file("filesystem_cache3"); FileAccess *f = FileAccess::open(fscache, FileAccess::WRITE); _save_filesystem_cache(filesystem, f); @@ -296,6 +296,89 @@ void EditorFileSystem::_thread_func(void *_userdata) { sd->_scan_filesystem(); } +bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_imported_files) { + + if (!reimport_on_missing_imported_files && p_only_imported_files) + return false; + + Error err; + FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err); + + if (!f) { //no import file, do reimport + return true; + } + + VariantParser::StreamFile stream; + stream.f = f; + + String assign; + Variant value; + VariantParser::Tag next_tag; + + int lines = 0; + String error_text; + + List<String> to_check; + + String source_md5; + + while (true) { + + assign = Variant(); + next_tag.fields.clear(); + next_tag.name = String(); + + err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true); + if (err == ERR_FILE_EOF) { + memdelete(f); + break; + } else if (err != OK) { + ERR_PRINTS("ResourceFormatImporter::load - " + p_path + ".import:" + itos(lines) + " error: " + error_text); + memdelete(f); + return false; //parse error, try reimport manually (Avoid reimport loop on broken file) + } + + if (assign != String()) { + if (assign.begins_with("path")) { + to_check.push_back(value); + } else if (assign == "files") { + Array fa = value; + for (int i = 0; i < fa.size(); i++) { + to_check.push_back(fa[i]); + } + } else if (!p_only_imported_files && assign == "source_md5") { + source_md5 = value; + } + + } else if (next_tag.name != "remap" && next_tag.name != "deps") { + break; + } + } + + memdelete(f); + + //imported files are gone, reimport + for (List<String>::Element *E = to_check.front(); E; E = E->next()) { + if (!FileAccess::exists(E->get())) { + return true; + } + } + + //check source md5 matching + if (!p_only_imported_files) { + if (source_md5 == String()) { + return true; //lacks md5, so just reimport + } + + String md5 = FileAccess::get_md5(p_path); + if (md5 != source_md5) { + return true; + } + } + + return false; //nothing changed +} + bool EditorFileSystem::_update_scan_actions() { sources_changed.clear(); @@ -365,12 +448,20 @@ bool EditorFileSystem::_update_scan_actions() { fs_changed = true; } break; - case ItemAction::ACTION_FILE_REIMPORT: { + case ItemAction::ACTION_FILE_TEST_REIMPORT: { int idx = ia.dir->find_file_index(ia.file); ERR_CONTINUE(idx == -1); String full_path = ia.dir->get_file_path(idx); - reimports.push_back(full_path); + if (_test_for_reimport(full_path, false)) { + //must reimport + reimports.push_back(full_path); + } else { + //must not reimport, all was good + //update modified times, to avoid reimport + ia.dir->files[idx]->modified_time = FileAccess::get_modified_time(full_path); + ia.dir->files[idx]->import_modified_time = FileAccess::get_modified_time(full_path + ".import"); + } fs_changed = true; } break; @@ -440,72 +531,6 @@ EditorFileSystem::ScanProgress EditorFileSystem::ScanProgress::get_sub(int p_cur return sp; } -bool EditorFileSystem::_check_missing_imported_files(const String &p_path) { - - if (!reimport_on_missing_imported_files) - return true; - - Error err; - FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err); - - if (!f) { - print_line("could not open import for " + p_path); - return false; - } - - VariantParser::StreamFile stream; - stream.f = f; - - String assign; - Variant value; - VariantParser::Tag next_tag; - - int lines = 0; - String error_text; - - List<String> to_check; - - while (true) { - - assign = Variant(); - next_tag.fields.clear(); - next_tag.name = String(); - - err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true); - if (err == ERR_FILE_EOF) { - memdelete(f); - return OK; - } else if (err != OK) { - ERR_PRINTS("ResourceFormatImporter::load - " + p_path + ".import:" + itos(lines) + " error: " + error_text); - memdelete(f); - return false; - } - - if (assign != String()) { - if (assign.begins_with("path")) { - to_check.push_back(value); - } else if (assign == "files") { - Array fa = value; - for (int i = 0; i < fa.size(); i++) { - to_check.push_back(fa[i]); - } - } - - } else if (next_tag.name != "remap" && next_tag.name != "deps") { - break; - } - } - - memdelete(f); - - for (List<String>::Element *E = to_check.front(); E; E = E->next()) { - if (!FileAccess::exists(E->get())) { - return false; - } - } - return true; -} - void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess *da, const ScanProgress &p_progress) { List<String> dirs; @@ -611,7 +636,7 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess import_mt = FileAccess::get_modified_time(path + ".import"); } - if (fc && fc->modification_time == mt && fc->import_modification_time == import_mt && _check_missing_imported_files(path)) { + if (fc && fc->modification_time == mt && fc->import_modification_time == import_mt && !_test_for_reimport(path, true)) { fi->type = fc->type; fi->deps = fc->deps; @@ -632,7 +657,7 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess fi->import_valid = ResourceLoader::is_import_valid(path); ItemAction ia; - ia.action = ItemAction::ACTION_FILE_REIMPORT; + ia.action = ItemAction::ACTION_FILE_TEST_REIMPORT; ia.dir = p_dir; ia.file = E->get(); scan_actions.push_back(ia); @@ -761,7 +786,7 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const if (import_extensions.has(ext)) { //if it can be imported, and it was added, it needs to be reimported ItemAction ia; - ia.action = ItemAction::ACTION_FILE_REIMPORT; + ia.action = ItemAction::ACTION_FILE_TEST_REIMPORT; ia.dir = p_dir; ia.file = f; scan_actions.push_back(ia); @@ -807,7 +832,7 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const uint64_t import_mt = FileAccess::get_modified_time(path + ".import"); if (import_mt != p_dir->files[i]->import_modified_time) { reimport = true; - } else if (!_check_missing_imported_files(path)) { + } else if (_test_for_reimport(path, true)) { reimport = true; } } @@ -815,14 +840,12 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const if (reimport) { ItemAction ia; - ia.action = ItemAction::ACTION_FILE_REIMPORT; + ia.action = ItemAction::ACTION_FILE_TEST_REIMPORT; ia.dir = p_dir; ia.file = p_dir->files[i]->file; scan_actions.push_back(ia); } } - - EditorResourcePreview::get_singleton()->check_for_invalidation(p_dir->get_file_path(i)); } for (int i = 0; i < p_dir->subdirs.size(); i++) { @@ -915,7 +938,8 @@ void EditorFileSystem::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { - scan(); + call_deferred("scan"); //this should happen after every editor node entered the tree + } break; case NOTIFICATION_EXIT_TREE: { if (use_threads && thread) { @@ -1181,7 +1205,7 @@ EditorFileSystemDirectory *EditorFileSystem::get_filesystem_path(const String &p 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"); + String fscache = EditorSettings::get_singleton()->get_project_settings_dir().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()); @@ -1220,8 +1244,10 @@ void EditorFileSystem::update_file(const String &p_file) { if (!FileAccess::exists(p_file)) { //was removed _delete_internal_files(p_file); - memdelete(fs->files[cpos]); - fs->files.remove(cpos); + if (cpos != -1) { // Might've never been part of the editor file system (*.* files deleted in Open dialog). + memdelete(fs->files[cpos]); + fs->files.remove(cpos); + } call_deferred("emit_signal", "filesystem_changed"); //update later return; } @@ -1266,7 +1292,6 @@ void EditorFileSystem::update_file(const String &p_file) { fs->files[cpos]->deps = _get_dependencies(p_file); fs->files[cpos]->import_valid = ResourceLoader::is_import_valid(p_file); - EditorResourcePreview::get_singleton()->call_deferred("check_for_invalidation", p_file); call_deferred("emit_signal", "filesystem_changed"); //update later } @@ -1387,8 +1412,9 @@ void EditorFileSystem::_reimport_file(const String &p_file) { f->store_line(""); + f->store_line("[deps]\n"); + if (gen_files.size()) { - f->store_line("[gen]"); Array genf; for (List<String>::Element *E = gen_files.front(); E; E = E->next()) { genf.push_back(E->get()); @@ -1400,6 +1426,8 @@ void EditorFileSystem::_reimport_file(const String &p_file) { f->store_line(""); } + f->store_line("source_md5=\"" + FileAccess::get_md5(p_file) + "\"\n"); + f->store_line("[params]"); f->store_line(""); @@ -1436,6 +1464,8 @@ void EditorFileSystem::_reimport_file(const String &p_file) { r->set_import_last_modified_time(0); } } + + EditorResourcePreview::get_singleton()->check_for_invalidation(p_file); } void EditorFileSystem::reimport_files(const Vector<String> &p_files) { |