Skip to content

Commit

Permalink
Merge pull request #94357 from KoBeWi/your_file_is_broken._just_saying
Browse files Browse the repository at this point in the history
Don't attempt to re-import broken files if they didn't change
  • Loading branch information
akien-mga committed Jul 17, 2024
2 parents c4806ed + a5d86c1 commit 4d97269
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions editor/editor_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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() + "\"");
Expand All @@ -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()) {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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()) {
Expand All @@ -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;
}

Expand Down

0 comments on commit 4d97269

Please sign in to comment.