From c8b022c165e79dddd0882744d957ecd4a0da3a5f Mon Sep 17 00:00:00 2001 From: Fredia Huya-Kouadio Date: Fri, 10 Sep 2021 10:52:41 -0700 Subject: [PATCH] Provide a getter for the project data directory. --- core/io/resource_importer.cpp | 3 ++- core/project_settings.cpp | 9 +++++++++ core/project_settings.h | 2 ++ editor/editor_file_dialog.cpp | 2 +- editor/editor_file_system.cpp | 18 ++++++++++++------ editor/find_in_files.cpp | 5 +++-- editor/project_manager.cpp | 3 ++- .../api/javascript_tools_editor_plugin.cpp | 3 ++- 8 files changed, 33 insertions(+), 12 deletions(-) diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp index 2511c89678f..5b48a0d127e 100644 --- a/core/io/resource_importer.cpp +++ b/core/io/resource_importer.cpp @@ -31,6 +31,7 @@ #include "resource_importer.h" #include "core/os/os.h" +#include "core/project_settings.h" #include "core/variant_parser.h" bool ResourceFormatImporter::SortImporterByName::operator()(const Ref &p_a, const Ref &p_b) const { @@ -380,7 +381,7 @@ Ref ResourceFormatImporter::get_importer_by_extension(const St } String ResourceFormatImporter::get_import_base_path(const String &p_for_file) const { - return "res://.import/" + p_for_file.get_file() + "-" + p_for_file.md5_text(); + return ProjectSettings::get_singleton()->get_project_data_path().plus_file(p_for_file.get_file() + "-" + p_for_file.md5_text()); } bool ResourceFormatImporter::are_import_settings_valid(const String &p_path) const { diff --git a/core/project_settings.cpp b/core/project_settings.cpp index 540157d6e1f..e4c95a4a4b5 100644 --- a/core/project_settings.cpp +++ b/core/project_settings.cpp @@ -49,6 +49,15 @@ ProjectSettings *ProjectSettings::get_singleton() { return singleton; } +String ProjectSettings::get_project_data_dir_name() const { + return ".import"; +} + +String ProjectSettings::get_project_data_path() const { + String project_data_dir_name = get_project_data_dir_name(); + return "res://" + project_data_dir_name; +} + String ProjectSettings::get_resource_path() const { return resource_path; }; diff --git a/core/project_settings.h b/core/project_settings.h index db99c8c7ed0..c650c8ce408 100644 --- a/core/project_settings.h +++ b/core/project_settings.h @@ -127,6 +127,8 @@ public: bool property_can_revert(const String &p_name); Variant property_get_revert(const String &p_name); + String get_project_data_dir_name() const; + String get_project_data_path() const; String get_resource_path() const; static ProjectSettings *get_singleton(); diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index 871da84eec0..217ea790d02 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -568,7 +568,7 @@ void EditorFileDialog::_item_list_item_rmb_selected(int p_item, const Vector2 &p continue; } Dictionary item_meta = item_list->get_item_metadata(i); - if (item_meta["path"] == "res://.import") { + if (item_meta["path"] == ProjectSettings::get_singleton()->get_project_data_path()) { allow_delete = false; break; } diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index 236b6906fd9..b3f46b830ba 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -1888,13 +1888,14 @@ void EditorFileSystem::_find_group_files(EditorFileSystemDirectory *efd, Map &p_files) { - { //check that .import folder exists + { //check that the project data folder exists + String project_data_dir_name = ProjectSettings::get_singleton()->get_project_data_dir_name(); DirAccess *da = DirAccess::open("res://"); - if (da->change_dir(".import") != OK) { - Error err = da->make_dir(".import"); + if (da->change_dir(project_data_dir_name) != OK) { + Error err = da->make_dir(project_data_dir_name); if (err) { memdelete(da); - ERR_FAIL_MSG("Failed to create 'res://.import' folder."); + ERR_FAIL_MSG("Failed to create folder res://" + project_data_dir_name); } } memdelete(da); @@ -1973,6 +1974,10 @@ Error EditorFileSystem::_resource_import(const String &p_path) { } bool EditorFileSystem::_should_skip_directory(const String &p_path) { + if (p_path == ProjectSettings::get_singleton()->get_project_data_path()) { + return true; + } + if (FileAccess::exists(p_path.plus_file("project.godot"))) { // skip if another project inside this return true; } @@ -2088,8 +2093,9 @@ EditorFileSystem::EditorFileSystem() { scanning_changes_done = false; DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); - if (da->change_dir("res://.import") != OK) { - da->make_dir("res://.import"); + String project_data_path = ProjectSettings::get_singleton()->get_project_data_path(); + if (da->change_dir(project_data_path) != OK) { + da->make_dir(project_data_path); } // This should probably also work on Unix and use the string it returns for FAT32 or exFAT using_fat32_or_exfat = (da->get_filesystem_type() == "FAT32" || da->get_filesystem_type() == "exFAT"); diff --git a/editor/find_in_files.cpp b/editor/find_in_files.cpp index 22d4cf04504..c30dc435182 100644 --- a/editor/find_in_files.cpp +++ b/editor/find_in_files.cpp @@ -238,8 +238,9 @@ void FindInFiles::_scan_dir(String path, PoolStringArray &out_folders) { break; } - // Ignore special dirs (such as .git and .import) - if (file == "." || file == ".." || file.begins_with(".")) { + // Ignore special dirs (such as .git and project data directory) + String project_data_dir_name = ProjectSettings::get_singleton()->get_project_data_dir_name(); + if (file.begins_with(".") || file == project_data_dir_name) { continue; } if (dir->current_is_hidden()) { diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index 25444566be8..763a9be538e 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -2080,7 +2080,8 @@ void ProjectManager::_run_project_confirm() { const String &selected = selected_list[i].project_key; String path = EditorSettings::get_singleton()->get("projects/" + selected); - if (!DirAccess::exists(path + "/.import")) { + String project_data_dir_name = ProjectSettings::get_singleton()->get_project_data_dir_name(); + if (!DirAccess::exists(path + "/" + project_data_dir_name)) { run_error_diag->set_text(TTR("Can't run project: Assets need to be imported.\nPlease edit the project to trigger the initial import.")); run_error_diag->popup_centered(); continue; diff --git a/platform/javascript/api/javascript_tools_editor_plugin.cpp b/platform/javascript/api/javascript_tools_editor_plugin.cpp index 364fda02098..7813b0d8b8c 100644 --- a/platform/javascript/api/javascript_tools_editor_plugin.cpp +++ b/platform/javascript/api/javascript_tools_editor_plugin.cpp @@ -118,9 +118,10 @@ void JavaScriptToolsEditorPlugin::_zip_recursive(String p_path, String p_base_pa } dir->list_dir_begin(); String cur = dir->get_next(); + String project_data_dir_name = ProjectSettings::get_singleton()->get_project_data_dir_name(); while (!cur.empty()) { String cs = p_path.plus_file(cur); - if (cur == "." || cur == ".." || cur == ".import") { + if (cur == "." || cur == ".." || cur == project_data_dir_name) { // Skip } else if (dir->current_is_dir()) { String path = cs.replace_first(p_base_path, "") + "/";