diff options
Diffstat (limited to 'editor/editor_file_system.cpp')
-rw-r--r-- | editor/editor_file_system.cpp | 114 |
1 files changed, 71 insertions, 43 deletions
diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index 8523833d52..d515b58e37 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -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?) @@ -862,6 +862,9 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess } else { //new or modified time fi->type = ResourceLoader::get_resource_type(path); + if (fi->type == "" && textfile_extensions.has(ext)) { + fi->type = "TextFile"; + } fi->uid = ResourceLoader::get_resource_uid(path); fi->script_class_name = _get_global_script_class(fi->type, path, &fi->script_class_extends, &fi->script_class_icon_path); fi->deps = _get_dependencies(path); @@ -929,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; } @@ -984,6 +987,9 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const fi->modified_time = FileAccess::get_modified_time(path); fi->import_modified_time = 0; fi->type = ResourceLoader::get_resource_type(path); + if (fi->type == "" && textfile_extensions.has(ext)) { + fi->type = "TextFile"; + } fi->script_class_name = _get_global_script_class(fi->type, path, &fi->script_class_extends, &fi->script_class_icon_path); fi->import_valid = ResourceLoader::is_import_valid(path); fi->import_group_file = ResourceLoader::get_import_group_file(path); @@ -1072,8 +1078,8 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const } for (int i = 0; i < p_dir->subdirs.size(); i++) { - if (updated_dir && !p_dir->subdirs[i]->verified) { - //this directory was removed, add action to remove it + if ((updated_dir && !p_dir->subdirs[i]->verified) || _should_skip_directory(p_dir->subdirs[i]->get_path())) { + //this directory was removed or ignored, add action to remove it ItemAction ia; ia.action = ItemAction::ACTION_DIR_REMOVE; ia.dir = p_dir->subdirs[i]; @@ -1240,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; @@ -1380,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; } @@ -1459,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; } @@ -1530,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 @@ -1539,6 +1545,9 @@ void EditorFileSystem::update_file(const String &p_file) { } String type = ResourceLoader::get_resource_type(p_file); + if (type.is_empty() && textfile_extensions.has(p_file.get_extension())) { + type = "TextFile"; + } ResourceUID::ID uid = ResourceLoader::get_resource_uid(p_file); if (cpos == -1) { @@ -1556,7 +1565,7 @@ void EditorFileSystem::update_file(const String &p_file) { EditorFileSystemDirectory::FileInfo *fi = memnew(EditorFileSystemDirectory::FileInfo); fi->file = file_name; fi->import_modified_time = 0; - fi->import_valid = ResourceLoader::is_import_valid(p_file); + fi->import_valid = type == "TextFile" ? true : ResourceLoader::is_import_valid(p_file); if (idx == fs->files.size()) { fs->files.push_back(fi); @@ -1577,7 +1586,7 @@ void EditorFileSystem::update_file(const String &p_file) { fs->files[cpos]->import_group_file = ResourceLoader::get_import_group_file(p_file); fs->files[cpos]->modified_time = FileAccess::get_modified_time(p_file); fs->files[cpos]->deps = _get_dependencies(p_file); - fs->files[cpos]->import_valid = ResourceLoader::is_import_valid(p_file); + fs->files[cpos]->import_valid = type == "TextFile" ? true : ResourceLoader::is_import_valid(p_file); if (uid != ResourceUID::INVALID_ID) { if (ResourceUID::get_singleton()->has_id(uid)) { @@ -1607,9 +1616,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); } @@ -1624,7 +1633,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; @@ -1647,15 +1656,15 @@ 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); Error err = importer->import_group_file(p_group_file, source_file_options, base_paths); //all went well, overwrite config files with proper remaps and md5s - for (Map<String, Map<StringName, Variant>>::Element *E = source_file_options.front(); E; E = E->next()) { - const String &file = E->key(); + for (const KeyValue<String, Map<StringName, Variant>> &E : source_file_options) { + const String &file = E.key; String base_path = ResourceFormatImporter::get_singleton()->get_import_base_path(file); FileAccessRef f = FileAccess::open(file + ".import", FileAccess::WRITE); ERR_FAIL_COND_V_MSG(!f, ERR_FILE_CANT_OPEN, "Cannot open import file '" + file + ".import'."); @@ -1668,7 +1677,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() + "\""); } @@ -1705,7 +1714,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; @@ -1740,6 +1749,9 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector fs->files[cpos]->import_modified_time = FileAccess::get_modified_time(file + ".import"); fs->files[cpos]->deps = _get_dependencies(file); fs->files[cpos]->type = importer->get_resource_type(); + if (fs->files[cpos]->type == "" && textfile_extensions.has(file.get_extension())) { + fs->files[cpos]->type = "TextFile"; + } fs->files[cpos]->import_valid = err == OK; //if file is currently up, maybe the source it was loaded from changed, so import math must be updated for it @@ -1747,7 +1759,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); @@ -1771,7 +1783,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) { @@ -1796,7 +1808,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"); } @@ -1822,7 +1834,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); } @@ -1839,7 +1851,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; @@ -1882,7 +1894,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() + "\""); } @@ -1895,7 +1907,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 @@ -1991,7 +2003,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); @@ -2050,7 +2062,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 { @@ -2121,10 +2133,10 @@ void EditorFileSystem::reimport_files(const Vector<String> &p_files) { if (groups_to_reimport.size()) { Map<String, Vector<String>> group_files; _find_group_files(filesystem, group_files, groups_to_reimport); - for (Map<String, Vector<String>>::Element *E = group_files.front(); E; E = E->next()) { - Error err = _reimport_group(E->key(), E->get()); + for (const KeyValue<String, Vector<String>> &E : group_files) { + Error err = _reimport_group(E.key, E.value); if (err == OK) { - _reimport_file(E->key()); + _reimport_file(E.key); } } } @@ -2151,6 +2163,11 @@ Error EditorFileSystem::_resource_import(const String &p_path) { } 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 + "/")) { + return true; + } + if (FileAccess::exists(p_path.plus_file("project.godot"))) { // skip if another project inside this return true; @@ -2216,7 +2233,7 @@ void EditorFileSystem::move_group_file(const String &p_path, const String &p_new } ResourceUID::ID EditorFileSystem::_resource_saver_get_resource_id_for_path(const String &p_path, bool p_generate) { - if (!p_path.is_resource_file() || p_path.begins_with("res://.godot")) { + if (!p_path.is_resource_file() || p_path.begins_with(ProjectSettings::get_singleton()->get_project_data_path())) { //saved externally (configuration file) or internal file, do not assign an ID. return ResourceUID::INVALID_ID; } @@ -2274,17 +2291,18 @@ bool EditorFileSystem::_scan_extensions() { } } + String extension_list_config_file = NativeExtension::get_extension_list_config_file(); if (extensions.size()) { if (extensions_added.size() || extensions_removed.size()) { //extensions were added or removed - FileAccessRef f = FileAccess::open(NativeExtension::EXTENSION_LIST_CONFIG_FILE, FileAccess::WRITE); + FileAccessRef f = FileAccess::open(extension_list_config_file, FileAccess::WRITE); for (const String &E : extensions) { f->store_line(E); } } } else { - if (loaded_extensions.size() || FileAccess::exists(NativeExtension::EXTENSION_LIST_CONFIG_FILE)) { //extensions were removed + if (loaded_extensions.size() || FileAccess::exists(extension_list_config_file)) { //extensions were removed DirAccessRef da = DirAccess::create(DirAccess::ACCESS_RESOURCES); - da->remove(NativeExtension::EXTENSION_LIST_CONFIG_FILE); + da->remove(extension_list_config_file); } } @@ -2329,6 +2347,7 @@ void EditorFileSystem::_bind_methods() { void EditorFileSystem::_update_extensions() { valid_extensions.clear(); import_extensions.clear(); + textfile_extensions.clear(); List<String> extensionsl; ResourceLoader::get_recognized_extensions_for_type("", &extensionsl); @@ -2336,6 +2355,15 @@ void EditorFileSystem::_update_extensions() { valid_extensions.insert(E); } + const Vector<String> textfile_ext = ((String)(EditorSettings::get_singleton()->get("docks/filesystem/textfile_extensions"))).split(",", false); + for (const String &E : textfile_ext) { + if (valid_extensions.has(E)) { + continue; + } + valid_extensions.insert(E); + textfile_extensions.insert(E); + } + extensionsl.clear(); ResourceFormatImporter::get_singleton()->get_recognized_extensions(&extensionsl); for (const String &E : extensionsl) { |