|
@@ -33,8 +33,6 @@
|
|
|
#include "core/config/project_settings.h"
|
|
|
#include "core/extension/gdextension_manager.h"
|
|
|
#include "core/io/file_access.h"
|
|
|
-#include "core/io/resource_importer.h"
|
|
|
-#include "core/io/resource_loader.h"
|
|
|
#include "core/io/resource_saver.h"
|
|
|
#include "core/object/worker_thread_pool.h"
|
|
|
#include "core/os/os.h"
|
|
@@ -903,6 +901,7 @@ void EditorFileSystem::scan() {
|
|
|
// Set first_scan to false before the signals so the function doing_first_scan can return false
|
|
|
// in editor_node to start the export if needed.
|
|
|
first_scan = false;
|
|
|
+ ResourceImporter::load_on_startup = nullptr;
|
|
|
emit_signal(SNAME("filesystem_changed"));
|
|
|
emit_signal(SNAME("sources_changed"), sources_changed.size() > 0);
|
|
|
} else {
|
|
@@ -1513,6 +1512,7 @@ void EditorFileSystem::_notification(int p_what) {
|
|
|
// Set first_scan to false before the signals so the function doing_first_scan can return false
|
|
|
// in editor_node to start the export if needed.
|
|
|
first_scan = false;
|
|
|
+ ResourceImporter::load_on_startup = nullptr;
|
|
|
if (changed) {
|
|
|
emit_signal(SNAME("filesystem_changed"));
|
|
|
}
|
|
@@ -1535,6 +1535,7 @@ void EditorFileSystem::_notification(int p_what) {
|
|
|
// Set first_scan to false before the signals so the function doing_first_scan can return false
|
|
|
// in editor_node to start the export if needed.
|
|
|
first_scan = false;
|
|
|
+ ResourceImporter::load_on_startup = nullptr;
|
|
|
emit_signal(SNAME("filesystem_changed"));
|
|
|
emit_signal(SNAME("sources_changed"), sources_changed.size() > 0);
|
|
|
}
|
|
@@ -2410,14 +2411,16 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
-Error EditorFileSystem::_reimport_file(const String &p_file, const HashMap<StringName, Variant> &p_custom_options, const String &p_custom_importer, Variant *p_generator_parameters) {
|
|
|
+Error EditorFileSystem::_reimport_file(const String &p_file, const HashMap<StringName, Variant> &p_custom_options, const String &p_custom_importer, Variant *p_generator_parameters, bool p_update_file_system) {
|
|
|
print_verbose(vformat("EditorFileSystem: Importing file: %s", p_file));
|
|
|
uint64_t start_time = OS::get_singleton()->get_ticks_msec();
|
|
|
|
|
|
EditorFileSystemDirectory *fs = nullptr;
|
|
|
int cpos = -1;
|
|
|
- bool found = _find_file(p_file, &fs, cpos);
|
|
|
- ERR_FAIL_COND_V_MSG(!found, ERR_FILE_NOT_FOUND, "Can't find file '" + p_file + "'.");
|
|
|
+ if (p_update_file_system) {
|
|
|
+ bool found = _find_file(p_file, &fs, cpos);
|
|
|
+ ERR_FAIL_COND_V_MSG(!found, ERR_FILE_NOT_FOUND, "Can't find file '" + p_file + "'.");
|
|
|
+ }
|
|
|
|
|
|
//try to obtain existing params
|
|
|
|
|
@@ -2471,11 +2474,13 @@ Error EditorFileSystem::_reimport_file(const String &p_file, const HashMap<Strin
|
|
|
|
|
|
if (importer_name == "keep" || importer_name == "skip") {
|
|
|
//keep files, do nothing.
|
|
|
- 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.clear();
|
|
|
- fs->files[cpos]->type = "";
|
|
|
- fs->files[cpos]->import_valid = false;
|
|
|
+ if (p_update_file_system) {
|
|
|
+ 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.clear();
|
|
|
+ fs->files[cpos]->type = "";
|
|
|
+ fs->files[cpos]->import_valid = false;
|
|
|
+ }
|
|
|
EditorResourcePreview::get_singleton()->check_for_invalidation(p_file);
|
|
|
return OK;
|
|
|
}
|
|
@@ -2635,16 +2640,18 @@ Error EditorFileSystem::_reimport_file(const String &p_file, const HashMap<Strin
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Update cpos, newly created files could've changed the index of the reimported p_file.
|
|
|
- _find_file(p_file, &fs, cpos);
|
|
|
+ if (p_update_file_system) {
|
|
|
+ // Update cpos, newly created files could've changed the index of the reimported p_file.
|
|
|
+ _find_file(p_file, &fs, cpos);
|
|
|
|
|
|
- // 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]->uid = uid;
|
|
|
- fs->files[cpos]->import_valid = fs->files[cpos]->type == "TextFile" ? true : ResourceLoader::is_import_valid(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]->uid = uid;
|
|
|
+ fs->files[cpos]->import_valid = fs->files[cpos]->type == "TextFile" ? true : ResourceLoader::is_import_valid(p_file);
|
|
|
+ }
|
|
|
|
|
|
if (ResourceUID::get_singleton()->has_id(uid)) {
|
|
|
ResourceUID::get_singleton()->set_id(uid, p_file);
|
|
@@ -2904,6 +2911,33 @@ Error EditorFileSystem::_resource_import(const String &p_path) {
|
|
|
return OK;
|
|
|
}
|
|
|
|
|
|
+Ref<Resource> EditorFileSystem::_load_resource_on_startup(ResourceFormatImporter *p_importer, const String &p_path, Error *r_error, bool p_use_sub_threads, float *r_progress, ResourceFormatLoader::CacheMode p_cache_mode) {
|
|
|
+ ERR_FAIL_NULL_V(p_importer, Ref<Resource>());
|
|
|
+
|
|
|
+ if (!FileAccess::exists(p_path)) {
|
|
|
+ ERR_FAIL_V_MSG(Ref<Resource>(), vformat("Failed loading resource: %s. The file doesn't seem to exist.", p_path));
|
|
|
+ }
|
|
|
+
|
|
|
+ Ref<Resource> res;
|
|
|
+ bool can_retry = true;
|
|
|
+ bool retry = true;
|
|
|
+ while (retry) {
|
|
|
+ retry = false;
|
|
|
+
|
|
|
+ res = p_importer->load_internal(p_path, r_error, p_use_sub_threads, r_progress, p_cache_mode, can_retry);
|
|
|
+
|
|
|
+ if (res.is_null() && can_retry) {
|
|
|
+ can_retry = false;
|
|
|
+ Error err = singleton->_reimport_file(p_path, HashMap<StringName, Variant>(), "", nullptr, false);
|
|
|
+ if (err == OK) {
|
|
|
+ retry = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return res;
|
|
|
+}
|
|
|
+
|
|
|
bool EditorFileSystem::_should_skip_directory(const String &p_path) {
|
|
|
String project_data_path = ProjectSettings::get_singleton()->get_project_data_path();
|
|
|
if (p_path == project_data_path || p_path.begins_with(project_data_path + "/")) {
|
|
@@ -3101,6 +3135,10 @@ EditorFileSystem::EditorFileSystem() {
|
|
|
|
|
|
scan_total = 0;
|
|
|
ResourceSaver::set_get_resource_id_for_path(_resource_saver_get_resource_id_for_path);
|
|
|
+
|
|
|
+ // Set the callback method that the ResourceFormatImporter will use
|
|
|
+ // if resources are loaded during the first scan.
|
|
|
+ ResourceImporter::load_on_startup = _load_resource_on_startup;
|
|
|
}
|
|
|
|
|
|
EditorFileSystem::~EditorFileSystem() {
|