Merge pull request #94357 from KoBeWi/your_file_is_broken._just_saying

Don't attempt to re-import broken files if they didn't change
This commit is contained in:
Rémi Verschelde 2024-07-17 15:45:07 +02:00
commit 4d97269e11
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 10 additions and 15 deletions

View File

@ -435,11 +435,6 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo
return true;
}
if (!ResourceFormatImporter::get_singleton()->are_import_settings_valid(p_path)) {
//reimport settings are not valid, reimport
return true;
}
Error err;
Ref<FileAccess> f = FileAccess::open(p_path + ".import", FileAccess::READ, &err);
@ -2448,16 +2443,14 @@ Error EditorFileSystem::_reimport_file(const String &p_file, const HashMap<Strin
Variant meta;
Error err = importer->import(p_file, base_path, params, &import_variants, &gen_files, &meta);
ERR_FAIL_COND_V_MSG(err != OK, ERR_FILE_UNRECOGNIZED, "Error importing '" + p_file + "'.");
//as import is complete, save the .import file
// As import is complete, save the .import file.
Vector<String> dest_paths;
{
Ref<FileAccess> f = FileAccess::open(p_file + ".import", FileAccess::WRITE);
ERR_FAIL_COND_V_MSG(f.is_null(), ERR_FILE_CANT_OPEN, "Cannot open file from path '" + p_file + ".import'.");
//write manually, as order matters ([remap] has to go first for performance).
// Write manually, as order matters ([remap] has to go first for performance).
f->store_line("[remap]");
f->store_line("");
f->store_line("importer=\"" + importer->get_importer_name() + "\"");
@ -2473,7 +2466,7 @@ Error EditorFileSystem::_reimport_file(const String &p_file, const HashMap<Strin
uid = ResourceUID::get_singleton()->create_id();
}
f->store_line("uid=\"" + ResourceUID::get_singleton()->id_to_text(uid) + "\""); //store in readable format
f->store_line("uid=\"" + ResourceUID::get_singleton()->id_to_text(uid) + "\""); // Store in readable format.
if (err == OK) {
if (importer->get_save_extension().is_empty()) {
@ -2528,13 +2521,14 @@ Error EditorFileSystem::_reimport_file(const String &p_file, const HashMap<Strin
for (int i = 0; i < dest_paths.size(); i++) {
dp.push_back(dest_paths[i]);
}
f->store_line("dest_files=" + Variant(dp).get_construct_string() + "\n");
f->store_line("dest_files=" + Variant(dp).get_construct_string());
}
f->store_line("");
f->store_line("[params]");
f->store_line("");
//store options in provided order, to avoid file changing. Order is also important because first match is accepted first.
// Store options in provided order, to avoid file changing. Order is also important because first match is accepted first.
for (const ResourceImporter::ImportOption &E : opts) {
String base = E.option.name;
@ -2558,7 +2552,7 @@ 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);
//update modified times, to avoid reimport
// 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);
@ -2572,8 +2566,8 @@ Error EditorFileSystem::_reimport_file(const String &p_file, const HashMap<Strin
ResourceUID::get_singleton()->add_id(uid, 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
// If file is currently up, maybe the source it was loaded from changed, so import math must be updated for it
// to reload properly.
Ref<Resource> r = ResourceCache::get_ref(p_file);
if (r.is_valid()) {
if (!r->get_import_path().is_empty()) {
@ -2587,6 +2581,7 @@ Error EditorFileSystem::_reimport_file(const String &p_file, const HashMap<Strin
print_verbose(vformat("EditorFileSystem: \"%s\" import took %d ms.", p_file, OS::get_singleton()->get_ticks_msec() - start_time));
ERR_FAIL_COND_V_MSG(err != OK, ERR_FILE_UNRECOGNIZED, "Error importing '" + p_file + "'.");
return OK;
}