Merge pull request #100086 from erodozer/multipart-ext-import
Support multi dot extensions in import plugins
This commit is contained in:
commit
c67b9a43e3
@ -262,7 +262,7 @@ Error ResourceFormatImporter::get_import_order_threads_and_importer(const String
|
||||
importer = get_importer_by_name(pat.importer);
|
||||
}
|
||||
} else {
|
||||
importer = get_importer_by_extension(p_path.get_extension().to_lower());
|
||||
importer = get_importer_by_file(p_path);
|
||||
}
|
||||
|
||||
if (importer.is_valid()) {
|
||||
@ -286,7 +286,7 @@ int ResourceFormatImporter::get_import_order(const String &p_path) const {
|
||||
importer = get_importer_by_name(pat.importer);
|
||||
}
|
||||
} else {
|
||||
importer = get_importer_by_extension(p_path.get_extension().to_lower());
|
||||
importer = get_importer_by_file(p_path);
|
||||
}
|
||||
|
||||
if (importer.is_valid()) {
|
||||
@ -471,12 +471,12 @@ void ResourceFormatImporter::add_importer(const Ref<ResourceImporter> &p_importe
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceFormatImporter::get_importers_for_extension(const String &p_extension, List<Ref<ResourceImporter>> *r_importers) {
|
||||
void ResourceFormatImporter::get_importers_for_file(const String &p_file, List<Ref<ResourceImporter>> *r_importers) {
|
||||
for (int i = 0; i < importers.size(); i++) {
|
||||
List<String> local_exts;
|
||||
importers[i]->get_recognized_extensions(&local_exts);
|
||||
for (const String &F : local_exts) {
|
||||
if (p_extension.to_lower() == F) {
|
||||
if (p_file.right(F.length()).nocasecmp_to(F) == 0) {
|
||||
r_importers->push_back(importers[i]);
|
||||
break;
|
||||
}
|
||||
@ -490,7 +490,7 @@ void ResourceFormatImporter::get_importers(List<Ref<ResourceImporter>> *r_import
|
||||
}
|
||||
}
|
||||
|
||||
Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const String &p_extension) const {
|
||||
Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_file(const String &p_file) const {
|
||||
Ref<ResourceImporter> importer;
|
||||
float priority = 0;
|
||||
|
||||
@ -498,9 +498,10 @@ Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const St
|
||||
List<String> local_exts;
|
||||
importers[i]->get_recognized_extensions(&local_exts);
|
||||
for (const String &F : local_exts) {
|
||||
if (p_extension.to_lower() == F && importers[i]->get_priority() > priority) {
|
||||
if (p_file.right(F.length()).nocasecmp_to(F) == 0 && importers[i]->get_priority() > priority) {
|
||||
importer = importers[i];
|
||||
priority = importers[i]->get_priority();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,8 +89,8 @@ public:
|
||||
|
||||
void remove_importer(const Ref<ResourceImporter> &p_importer) { importers.erase(p_importer); }
|
||||
Ref<ResourceImporter> get_importer_by_name(const String &p_name) const;
|
||||
Ref<ResourceImporter> get_importer_by_extension(const String &p_extension) const;
|
||||
void get_importers_for_extension(const String &p_extension, List<Ref<ResourceImporter>> *r_importers);
|
||||
Ref<ResourceImporter> get_importer_by_file(const String &p_file) const;
|
||||
void get_importers_for_file(const String &p_file, List<Ref<ResourceImporter>> *r_importers);
|
||||
void get_importers(List<Ref<ResourceImporter>> *r_importers);
|
||||
|
||||
bool are_import_settings_valid(const String &p_path) const;
|
||||
|
@ -61,8 +61,6 @@ bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_
|
||||
return ret;
|
||||
}
|
||||
|
||||
String extension = p_path.get_extension();
|
||||
|
||||
List<String> extensions;
|
||||
if (p_for_type.is_empty()) {
|
||||
get_recognized_extensions(&extensions);
|
||||
@ -71,7 +69,8 @@ bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_
|
||||
}
|
||||
|
||||
for (const String &E : extensions) {
|
||||
if (E.nocasecmp_to(extension) == 0) {
|
||||
const String ext = !E.begins_with(".") ? "." + E : E;
|
||||
if (p_path.right(ext.length()).nocasecmp_to(ext) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -330,7 +329,7 @@ Ref<Resource> ResourceLoader::_load(const String &p_path, const String &p_origin
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
if (ResourceFormatImporter::get_singleton()->get_importer_by_extension(p_path.get_extension()).is_valid()) {
|
||||
if (ResourceFormatImporter::get_singleton()->get_importer_by_file(p_path).is_valid()) {
|
||||
// The format is known to the editor, but the file hasn't been imported
|
||||
// (otherwise, ResourceFormatImporter would have been found as a suitable loader).
|
||||
found = true;
|
||||
|
@ -970,7 +970,7 @@ bool EditorFileSystem::_update_scan_actions() {
|
||||
Vector<String> dependencies = _get_dependencies(full_path);
|
||||
for (const String &dep : dependencies) {
|
||||
const String &dependency_path = dep.contains("::") ? dep.get_slice("::", 0) : dep;
|
||||
if (import_extensions.has(dep.get_extension())) {
|
||||
if (_can_import_file(dep)) {
|
||||
reimports.push_back(dependency_path);
|
||||
}
|
||||
}
|
||||
@ -1224,7 +1224,7 @@ void EditorFileSystem::_process_file_system(const ScannedDirectory *p_scan_dir,
|
||||
FileCache *fc = file_cache.getptr(path);
|
||||
uint64_t mt = FileAccess::get_modified_time(path);
|
||||
|
||||
if (import_extensions.has(ext)) {
|
||||
if (_can_import_file(scan_file)) {
|
||||
//is imported
|
||||
uint64_t import_mt = FileAccess::get_modified_time(path + ".import");
|
||||
|
||||
@ -1514,7 +1514,7 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, ScanPr
|
||||
scan_actions.push_back(ia);
|
||||
}
|
||||
|
||||
if (import_extensions.has(ext)) {
|
||||
if (_can_import_file(f)) {
|
||||
//if it can be imported, and it was added, it needs to be reimported
|
||||
ItemAction ia;
|
||||
ia.action = ItemAction::ACTION_FILE_TEST_REIMPORT;
|
||||
@ -1546,7 +1546,7 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, ScanPr
|
||||
|
||||
String path = cd.path_join(p_dir->files[i]->file);
|
||||
|
||||
if (import_extensions.has(p_dir->files[i]->file.get_extension().to_lower())) {
|
||||
if (_can_import_file(p_dir->files[i]->file)) {
|
||||
// Check here if file must be imported or not.
|
||||
// Same logic as in _process_file_system, the last modifications dates
|
||||
// needs to be trusted to prevent reading all the .import files and the md5
|
||||
@ -2820,7 +2820,7 @@ Error EditorFileSystem::_reimport_file(const String &p_file, const HashMap<Strin
|
||||
|
||||
if (importer.is_null()) {
|
||||
//not found by name, find by extension
|
||||
importer = ResourceFormatImporter::get_singleton()->get_importer_by_extension(p_file.get_extension());
|
||||
importer = ResourceFormatImporter::get_singleton()->get_importer_by_file(p_file);
|
||||
load_default = true;
|
||||
if (importer.is_null()) {
|
||||
ERR_FAIL_V_MSG(ERR_FILE_CANT_OPEN, "BUG: File queued for import, but can't be imported, importer for type '" + importer_name + "' not found.");
|
||||
@ -3626,10 +3626,20 @@ void EditorFileSystem::_update_extensions() {
|
||||
extensionsl.clear();
|
||||
ResourceFormatImporter::get_singleton()->get_recognized_extensions(&extensionsl);
|
||||
for (const String &E : extensionsl) {
|
||||
import_extensions.insert(E);
|
||||
import_extensions.insert(!E.begins_with(".") ? "." + E : E);
|
||||
}
|
||||
}
|
||||
|
||||
bool EditorFileSystem::_can_import_file(const String &p_file) {
|
||||
for (const String &F : import_extensions) {
|
||||
if (p_file.right(F.length()).nocasecmp_to(F) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void EditorFileSystem::add_import_format_support_query(Ref<EditorFileSystemImportFormatSupportQuery> p_query) {
|
||||
ERR_FAIL_COND(import_support_queries.has(p_query));
|
||||
import_support_queries.push_back(p_query);
|
||||
|
@ -279,6 +279,7 @@ class EditorFileSystem : public Node {
|
||||
|
||||
bool _test_for_reimport(const String &p_path, const String &p_expected_import_md5);
|
||||
bool _is_test_for_reimport_needed(const String &p_path, uint64_t p_last_modification_time, uint64_t p_modification_time, uint64_t p_last_import_modification_time, uint64_t p_import_modification_time, const Vector<String> &p_import_dest_paths);
|
||||
bool _can_import_file(const String &p_path);
|
||||
Vector<String> _get_import_dest_paths(const String &p_path);
|
||||
|
||||
bool reimport_on_missing_imported_files;
|
||||
|
@ -124,7 +124,7 @@ void ImportDock::set_edit_path(const String &p_path) {
|
||||
_update_options(p_path, config);
|
||||
|
||||
List<Ref<ResourceImporter>> importers;
|
||||
ResourceFormatImporter::get_singleton()->get_importers_for_extension(p_path.get_extension(), &importers);
|
||||
ResourceFormatImporter::get_singleton()->get_importers_for_file(p_path, &importers);
|
||||
List<Pair<String, String>> importer_names;
|
||||
|
||||
for (const Ref<ResourceImporter> &E : importers) {
|
||||
@ -314,7 +314,7 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) {
|
||||
params->update();
|
||||
|
||||
List<Ref<ResourceImporter>> importers;
|
||||
ResourceFormatImporter::get_singleton()->get_importers_for_extension(p_paths[0].get_extension(), &importers);
|
||||
ResourceFormatImporter::get_singleton()->get_importers_for_file(p_paths[0], &importers);
|
||||
List<Pair<String, String>> importer_names;
|
||||
|
||||
for (const Ref<ResourceImporter> &E : importers) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user