summaryrefslogtreecommitdiff
path: root/editor/editor_file_system.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_file_system.cpp')
-rw-r--r--editor/editor_file_system.cpp72
1 files changed, 38 insertions, 34 deletions
diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp
index 3d6b523733..5beed352a6 100644
--- a/editor/editor_file_system.cpp
+++ b/editor/editor_file_system.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -241,7 +241,7 @@ void EditorFileSystem::_scan_filesystem() {
first = false;
continue;
}
- if (l == String()) {
+ if (l.is_empty()) {
continue;
}
@@ -295,7 +295,7 @@ void EditorFileSystem::_scan_filesystem() {
{
FileAccessRef f2 = FileAccess::open(update_cache, FileAccess::READ);
String l = f2->get_line().strip_edges();
- while (l != String()) {
+ while (!l.is_empty()) {
file_cache.erase(l); //erase cache for this, so it gets updated
l = f2->get_line().strip_edges();
}
@@ -405,7 +405,7 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo
return false; //parse error, try reimport manually (Avoid reimport loop on broken file)
}
- if (assign != String()) {
+ if (!assign.is_empty()) {
if (assign.begins_with("path")) {
to_check.push_back(value);
} else if (assign == "files") {
@@ -476,7 +476,7 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo
memdelete(md5s);
return false; // parse error
}
- if (assign != String()) {
+ if (!assign.is_empty()) {
if (!p_only_imported_files) {
if (assign == "source_md5") {
source_md5 = value;
@@ -497,11 +497,11 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo
//check source md5 matching
if (!p_only_imported_files) {
- if (source_file != String() && source_file != p_path) {
+ if (!source_file.is_empty() && source_file != p_path) {
return true; //file was moved, reimport
}
- if (source_md5 == String()) {
+ if (source_md5.is_empty()) {
return true; //lacks md5, so just reimport
}
@@ -510,7 +510,7 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo
return true;
}
- if (dest_files.size() && dest_md5 != String()) {
+ if (dest_files.size() && !dest_md5.is_empty()) {
md5 = FileAccess::get_multiple_md5(dest_files);
if (md5 != dest_md5) {
return true;
@@ -577,7 +577,7 @@ bool EditorFileSystem::_update_scan_actions() {
ERR_CONTINUE(idx == -1);
_delete_internal_files(ia.dir->files[idx]->file);
memdelete(ia.dir->files[idx]);
- ia.dir->files.remove(idx);
+ ia.dir->files.remove_at(idx);
fs_changed = true;
@@ -710,7 +710,7 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess
da->list_dir_begin();
while (true) {
String f = da->get_next();
- if (f == "") {
+ if (f.is_empty()) {
break;
}
@@ -820,7 +820,7 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess
scan_actions.push_back(ia);
}
- if (fc->type == String()) {
+ if (fc->type.is_empty()) {
fi->type = ResourceLoader::get_resource_type(path);
fi->import_group_file = ResourceLoader::get_import_group_file(path);
//there is also the chance that file type changed due to reimport, must probably check this somehow here (or kind of note it for next time in another file?)
@@ -932,7 +932,7 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const
da->list_dir_begin();
while (true) {
String f = da->get_next();
- if (f == "") {
+ if (f.is_empty()) {
break;
}
@@ -1246,7 +1246,7 @@ void EditorFileSystem::_save_filesystem_cache(EditorFileSystemDirectory *p_dir,
p_file->store_line("::" + p_dir->get_path() + "::" + String::num(p_dir->modified_time));
for (int i = 0; i < p_dir->files.size(); i++) {
- if (p_dir->files[i]->import_group_file != String()) {
+ if (!p_dir->files[i]->import_group_file.is_empty()) {
group_file_cache.insert(p_dir->files[i]->import_group_file);
}
String s = p_dir->files[i]->file + "::" + p_dir->files[i]->type + "::" + itos(p_dir->files[i]->uid) + "::" + itos(p_dir->files[i]->modified_time) + "::" + itos(p_dir->files[i]->import_modified_time) + "::" + itos(p_dir->files[i]->import_valid) + "::" + p_dir->files[i]->import_group_file + "::" + p_dir->files[i]->script_class_name + "<>" + p_dir->files[i]->script_class_extends + "<>" + p_dir->files[i]->script_class_icon_path;
@@ -1386,7 +1386,7 @@ EditorFileSystemDirectory *EditorFileSystem::get_filesystem_path(const String &p
f = f.substr(6, f.length());
f = f.replace("\\", "/");
- if (f == String()) {
+ if (f.is_empty()) {
return filesystem;
}
@@ -1465,7 +1465,7 @@ void EditorFileSystem::_scan_script_classes(EditorFileSystemDirectory *p_dir) {
int filecount = p_dir->files.size();
const EditorFileSystemDirectory::FileInfo *const *files = p_dir->files.ptr();
for (int i = 0; i < filecount; i++) {
- if (files[i]->script_class_name == String()) {
+ if (files[i]->script_class_name.is_empty()) {
continue;
}
@@ -1536,7 +1536,7 @@ void EditorFileSystem::update_file(const String &p_file) {
}
}
memdelete(fs->files[cpos]);
- fs->files.remove(cpos);
+ fs->files.remove_at(cpos);
}
call_deferred(SNAME("emit_signal"), "filesystem_changed"); //update later
@@ -1545,7 +1545,7 @@ void EditorFileSystem::update_file(const String &p_file) {
}
String type = ResourceLoader::get_resource_type(p_file);
- if (type == "" && textfile_extensions.has(p_file.get_extension())) {
+ if (type.is_empty() && textfile_extensions.has(p_file.get_extension())) {
type = "TextFile";
}
ResourceUID::ID uid = ResourceLoader::get_resource_uid(p_file);
@@ -1604,6 +1604,10 @@ void EditorFileSystem::update_file(const String &p_file) {
_queue_update_script_classes();
}
+Set<String> EditorFileSystem::get_valid_extensions() const {
+ return valid_extensions;
+}
+
Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector<String> &p_files) {
String importer_name;
@@ -1616,9 +1620,9 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
ERR_CONTINUE(err != OK);
ERR_CONTINUE(!config->has_section_key("remap", "importer"));
String file_importer_name = config->get_value("remap", "importer");
- ERR_CONTINUE(file_importer_name == String());
+ ERR_CONTINUE(file_importer_name.is_empty());
- if (importer_name != String() && importer_name != file_importer_name) {
+ if (!importer_name.is_empty() && importer_name != file_importer_name) {
EditorNode::get_singleton()->show_warning(vformat(TTR("There are multiple importers for different types pointing to file %s, import aborted"), p_group_file));
ERR_FAIL_V(ERR_FILE_CORRUPT);
}
@@ -1633,7 +1637,7 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
Ref<ResourceImporter> importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(importer_name);
ERR_FAIL_COND_V(!importer.is_valid(), ERR_FILE_CORRUPT);
List<ResourceImporter::ImportOption> options;
- importer->get_import_options(&options);
+ importer->get_import_options(p_files[i], &options);
//set default values
for (const ResourceImporter::ImportOption &E : options) {
source_file_options[p_files[i]][E.option.name] = E.default_value;
@@ -1644,7 +1648,7 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
config->get_section_keys("params", &sk);
for (const String &param : sk) {
Variant value = config->get_value("params", param);
- //override with whathever is in file
+ //override with whatever is in file
source_file_options[p_files[i]][param] = value;
}
}
@@ -1656,7 +1660,7 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
return OK; // (do nothing)
}
- ERR_FAIL_COND_V(importer_name == String(), ERR_UNCONFIGURED);
+ ERR_FAIL_COND_V(importer_name.is_empty(), ERR_UNCONFIGURED);
Ref<ResourceImporter> importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(importer_name);
@@ -1677,7 +1681,7 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
if (version > 0) {
f->store_line("importer_version=" + itos(version));
}
- if (importer->get_resource_type() != "") {
+ if (!importer->get_resource_type().is_empty()) {
f->store_line("type=\"" + importer->get_resource_type() + "\"");
}
@@ -1714,7 +1718,7 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
//store options in provided order, to avoid file changing. Order is also important because first match is accepted first.
List<ResourceImporter::ImportOption> options;
- importer->get_import_options(&options);
+ importer->get_import_options(file, &options);
//set default values
for (const ResourceImporter::ImportOption &F : options) {
String base = F.option.name;
@@ -1759,7 +1763,7 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
if (ResourceCache::has(file)) {
Resource *r = ResourceCache::get(file);
- if (r->get_import_path() != String()) {
+ if (!r->get_import_path().is_empty()) {
String dst_path = ResourceFormatImporter::get_singleton()->get_internal_resource_path(file);
r->set_import_path(dst_path);
r->set_import_last_modified_time(0);
@@ -1783,7 +1787,7 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName
Map<StringName, Variant> params;
String importer_name; //empty by default though
- if (p_custom_importer != String()) {
+ if (!p_custom_importer.is_empty()) {
importer_name = p_custom_importer;
}
if (p_custom_options != nullptr) {
@@ -1808,7 +1812,7 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName
}
if (cf->has_section("remap")) {
- if (p_custom_importer == String()) {
+ if (p_custom_importer.is_empty()) {
importer_name = cf->get_value("remap", "importer");
}
@@ -1834,7 +1838,7 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName
Ref<ResourceImporter> importer;
bool load_default = false;
//find the importer
- if (importer_name != "") {
+ if (!importer_name.is_empty()) {
importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(importer_name);
}
@@ -1851,7 +1855,7 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName
//mix with default params, in case a parameter is missing
List<ResourceImporter::ImportOption> opts;
- importer->get_import_options(&opts);
+ importer->get_import_options(p_file, &opts);
for (const ResourceImporter::ImportOption &E : opts) {
if (!params.has(E.option.name)) { //this one is not present
params[E.option.name] = E.default_value;
@@ -1894,7 +1898,7 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName
if (version > 0) {
f->store_line("importer_version=" + itos(version));
}
- if (importer->get_resource_type() != "") {
+ if (!importer->get_resource_type().is_empty()) {
f->store_line("type=\"" + importer->get_resource_type() + "\"");
}
@@ -1907,7 +1911,7 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName
Vector<String> dest_paths;
if (err == OK) {
- if (importer->get_save_extension() == "") {
+ if (importer->get_save_extension().is_empty()) {
//no path
} else if (import_variants.size()) {
//import with variants
@@ -2003,7 +2007,7 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName
if (ResourceCache::has(p_file)) {
Resource *r = ResourceCache::get(p_file);
- if (r->get_import_path() != String()) {
+ if (!r->get_import_path().is_empty()) {
String dst_path = ResourceFormatImporter::get_singleton()->get_internal_resource_path(p_file);
r->set_import_path(dst_path);
r->set_import_last_modified_time(0);
@@ -2062,7 +2066,7 @@ void EditorFileSystem::reimport_files(const Vector<String> &p_files) {
groups_to_reimport.insert(file);
//groups do not belong to grups
group_file = String();
- } else if (group_file != String()) {
+ } else if (!group_file.is_empty()) {
//it's a group file, add group to import and skip this file
groups_to_reimport.insert(group_file);
} else {