浏览代码

Merge pull request #52711 from m4gr3d/provide_getter_for_project_data_dir_master

Rémi Verschelde 3 年之前
父节点
当前提交
a7ba227631

+ 12 - 1
core/config/project_settings.cpp

@@ -48,11 +48,22 @@ ProjectSettings *ProjectSettings::get_singleton() {
 	return singleton;
 	return singleton;
 }
 }
 
 
+String ProjectSettings::get_project_data_dir_name() const {
+	return ".godot";
+}
+
+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 {
 String ProjectSettings::get_resource_path() const {
 	return resource_path;
 	return resource_path;
 }
 }
 
 
-const String ProjectSettings::IMPORTED_FILES_PATH("res://.godot/imported");
+String ProjectSettings::get_imported_files_path() const {
+	return get_project_data_path().plus_file("imported");
+}
 
 
 String ProjectSettings::localize_path(const String &p_path) const {
 String ProjectSettings::localize_path(const String &p_path) const {
 	if (resource_path.is_empty() || p_path.begins_with("res://") || p_path.begins_with("user://") ||
 	if (resource_path.is_empty() || p_path.begins_with("res://") || p_path.begins_with("user://") ||

+ 3 - 1
core/config/project_settings.h

@@ -42,7 +42,6 @@ class ProjectSettings : public Object {
 
 
 public:
 public:
 	typedef Map<String, Variant> CustomMap;
 	typedef Map<String, Variant> CustomMap;
-	static const String IMPORTED_FILES_PATH;
 
 
 	enum {
 	enum {
 		//properties that are not for built in values begin from this value, so builtin ones are displayed first
 		//properties that are not for built in values begin from this value, so builtin ones are displayed first
@@ -141,7 +140,10 @@ public:
 	bool property_can_revert(const String &p_name);
 	bool property_can_revert(const String &p_name);
 	Variant property_get_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;
 	String get_resource_path() const;
+	String get_imported_files_path() const;
 
 
 	static ProjectSettings *get_singleton();
 	static ProjectSettings *get_singleton();
 
 

+ 3 - 1
core/extension/native_extension.cpp

@@ -35,7 +35,9 @@
 #include "core/object/method_bind.h"
 #include "core/object/method_bind.h"
 #include "core/os/os.h"
 #include "core/os/os.h"
 
 
-const char *NativeExtension::EXTENSION_LIST_CONFIG_FILE = "res://.godot/extension_list.cfg";
+String NativeExtension::get_extension_list_config_file() {
+	return ProjectSettings::get_singleton()->get_project_data_path().plus_file("extension_list.cfg");
+}
 
 
 class NativeExtensionMethodBind : public MethodBind {
 class NativeExtensionMethodBind : public MethodBind {
 	GDNativeExtensionClassMethodCall call_func;
 	GDNativeExtensionClassMethodCall call_func;

+ 1 - 1
core/extension/native_extension.h

@@ -62,7 +62,7 @@ protected:
 	static void _bind_methods();
 	static void _bind_methods();
 
 
 public:
 public:
-	static const char *EXTENSION_LIST_CONFIG_FILE;
+	static String get_extension_list_config_file();
 
 
 	Error open_library(const String &p_path, const String &p_entry_symbol);
 	Error open_library(const String &p_path, const String &p_entry_symbol);
 	void close_library();
 	void close_library();

+ 1 - 1
core/extension/native_extension_manager.cpp

@@ -112,7 +112,7 @@ void NativeExtensionManager::deinitialize_extensions(NativeExtension::Initializa
 }
 }
 
 
 void NativeExtensionManager::load_extensions() {
 void NativeExtensionManager::load_extensions() {
-	FileAccessRef f = FileAccess::open(NativeExtension::EXTENSION_LIST_CONFIG_FILE, FileAccess::READ);
+	FileAccessRef f = FileAccess::open(NativeExtension::get_extension_list_config_file(), FileAccess::READ);
 	while (f && !f->eof_reached()) {
 	while (f && !f->eof_reached()) {
 		String s = f->get_line().strip_edges();
 		String s = f->get_line().strip_edges();
 		if (s != String()) {
 		if (s != String()) {

+ 1 - 1
core/io/resource_importer.cpp

@@ -418,7 +418,7 @@ Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const St
 }
 }
 
 
 String ResourceFormatImporter::get_import_base_path(const String &p_for_file) const {
 String ResourceFormatImporter::get_import_base_path(const String &p_for_file) const {
-	return ProjectSettings::IMPORTED_FILES_PATH.plus_file(p_for_file.get_file() + "-" + p_for_file.md5_text());
+	return ProjectSettings::get_singleton()->get_imported_files_path().plus_file(p_for_file.get_file() + "-" + p_for_file.md5_text());
 }
 }
 
 
 bool ResourceFormatImporter::are_import_settings_valid(const String &p_path) const {
 bool ResourceFormatImporter::are_import_settings_valid(const String &p_path) const {

+ 11 - 6
core/io/resource_uid.cpp

@@ -29,6 +29,8 @@
 /*************************************************************************/
 /*************************************************************************/
 
 
 #include "resource_uid.h"
 #include "resource_uid.h"
+
+#include "core/config/project_settings.h"
 #include "core/crypto/crypto.h"
 #include "core/crypto/crypto.h"
 #include "core/io/dir_access.h"
 #include "core/io/dir_access.h"
 #include "core/io/file_access.h"
 #include "core/io/file_access.h"
@@ -36,7 +38,9 @@
 static constexpr uint32_t char_count = ('z' - 'a');
 static constexpr uint32_t char_count = ('z' - 'a');
 static constexpr uint32_t base = char_count + ('9' - '0');
 static constexpr uint32_t base = char_count + ('9' - '0');
 
 
-const char *ResourceUID::CACHE_FILE = "res://.godot/uid_cache.bin";
+String ResourceUID::get_cache_file() {
+	return ProjectSettings::get_singleton()->get_project_data_path().plus_file("uid_cache.bin");
+}
 
 
 String ResourceUID::id_to_text(ID p_id) const {
 String ResourceUID::id_to_text(ID p_id) const {
 	if (p_id < 0) {
 	if (p_id < 0) {
@@ -135,12 +139,13 @@ void ResourceUID::remove_id(ID p_id) {
 }
 }
 
 
 Error ResourceUID::save_to_cache() {
 Error ResourceUID::save_to_cache() {
-	if (!FileAccess::exists(CACHE_FILE)) {
+	String cache_file = get_cache_file();
+	if (!FileAccess::exists(cache_file)) {
 		DirAccessRef d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
 		DirAccessRef d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
-		d->make_dir_recursive(String(CACHE_FILE).get_base_dir()); //ensure base dir exists
+		d->make_dir_recursive(String(cache_file).get_base_dir()); //ensure base dir exists
 	}
 	}
 
 
-	FileAccessRef f = FileAccess::open(CACHE_FILE, FileAccess::WRITE);
+	FileAccessRef f = FileAccess::open(cache_file, FileAccess::WRITE);
 	if (!f) {
 	if (!f) {
 		return ERR_CANT_OPEN;
 		return ERR_CANT_OPEN;
 	}
 	}
@@ -164,7 +169,7 @@ Error ResourceUID::save_to_cache() {
 }
 }
 
 
 Error ResourceUID::load_from_cache() {
 Error ResourceUID::load_from_cache() {
-	FileAccessRef f = FileAccess::open(CACHE_FILE, FileAccess::READ);
+	FileAccessRef f = FileAccess::open(get_cache_file(), FileAccess::READ);
 	if (!f) {
 	if (!f) {
 		return ERR_CANT_OPEN;
 		return ERR_CANT_OPEN;
 	}
 	}
@@ -206,7 +211,7 @@ Error ResourceUID::update_cache() {
 	for (OrderedHashMap<ID, Cache>::Element E = unique_ids.front(); E; E = E.next()) {
 	for (OrderedHashMap<ID, Cache>::Element E = unique_ids.front(); E; E = E.next()) {
 		if (!E.get().saved_to_cache) {
 		if (!E.get().saved_to_cache) {
 			if (f == nullptr) {
 			if (f == nullptr) {
-				f = FileAccess::open(CACHE_FILE, FileAccess::READ_WRITE); //append
+				f = FileAccess::open(get_cache_file(), FileAccess::READ_WRITE); //append
 				if (!f) {
 				if (!f) {
 					return ERR_CANT_OPEN;
 					return ERR_CANT_OPEN;
 				}
 				}

+ 1 - 1
core/io/resource_uid.h

@@ -44,7 +44,7 @@ public:
 		INVALID_ID = -1
 		INVALID_ID = -1
 	};
 	};
 
 
-	static const char *CACHE_FILE;
+	static String get_cache_file();
 
 
 private:
 private:
 	mutable Ref<Crypto> crypto;
 	mutable Ref<Crypto> crypto;

+ 8 - 6
editor/editor_export.cpp

@@ -1046,17 +1046,19 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
 			return err;
 			return err;
 		}
 		}
 	}
 	}
-	if (FileAccess::exists(ResourceUID::CACHE_FILE)) {
-		Vector<uint8_t> array = FileAccess::get_file_as_array(ResourceUID::CACHE_FILE);
-		err = p_func(p_udata, ResourceUID::CACHE_FILE, array, idx, total, enc_in_filters, enc_ex_filters, key);
+	String resource_cache_file = ResourceUID::get_cache_file();
+	if (FileAccess::exists(resource_cache_file)) {
+		Vector<uint8_t> array = FileAccess::get_file_as_array(resource_cache_file);
+		err = p_func(p_udata, resource_cache_file, array, idx, total, enc_in_filters, enc_ex_filters, key);
 		if (err != OK) {
 		if (err != OK) {
 			return err;
 			return err;
 		}
 		}
 	}
 	}
 
 
-	if (FileAccess::exists(NativeExtension::EXTENSION_LIST_CONFIG_FILE)) {
-		Vector<uint8_t> array = FileAccess::get_file_as_array(NativeExtension::EXTENSION_LIST_CONFIG_FILE);
-		err = p_func(p_udata, NativeExtension::EXTENSION_LIST_CONFIG_FILE, array, idx, total, enc_in_filters, enc_ex_filters, key);
+	String extension_list_config_file = NativeExtension::get_extension_list_config_file();
+	if (FileAccess::exists(extension_list_config_file)) {
+		Vector<uint8_t> array = FileAccess::get_file_as_array(extension_list_config_file);
+		err = p_func(p_udata, extension_list_config_file, array, idx, total, enc_in_filters, enc_ex_filters, key);
 		if (err != OK) {
 		if (err != OK) {
 			return err;
 			return err;
 		}
 		}

+ 1 - 1
editor/editor_file_dialog.cpp

@@ -588,7 +588,7 @@ void EditorFileDialog::_item_list_item_rmb_selected(int p_item, const Vector2 &p
 			continue;
 			continue;
 		}
 		}
 		Dictionary item_meta = item_list->get_item_metadata(i);
 		Dictionary item_meta = item_list->get_item_metadata(i);
-		if (String(item_meta["path"]).begins_with("res://.godot")) {
+		if (String(item_meta["path"]).begins_with(ProjectSettings::get_singleton()->get_project_data_path())) {
 			allow_delete = false;
 			allow_delete = false;
 			break;
 			break;
 		}
 		}

+ 9 - 4
editor/editor_file_system.cpp

@@ -2163,6 +2163,10 @@ Error EditorFileSystem::_resource_import(const String &p_path) {
 }
 }
 
 
 bool EditorFileSystem::_should_skip_directory(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"))) {
 	if (FileAccess::exists(p_path.plus_file("project.godot"))) {
 		// skip if another project inside this
 		// skip if another project inside this
 		return true;
 		return true;
@@ -2228,7 +2232,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) {
 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.
 		//saved externally (configuration file) or internal file, do not assign an ID.
 		return ResourceUID::INVALID_ID;
 		return ResourceUID::INVALID_ID;
 	}
 	}
@@ -2286,17 +2290,18 @@ bool EditorFileSystem::_scan_extensions() {
 		}
 		}
 	}
 	}
 
 
+	String extension_list_config_file = NativeExtension::get_extension_list_config_file();
 	if (extensions.size()) {
 	if (extensions.size()) {
 		if (extensions_added.size() || extensions_removed.size()) { //extensions were added or removed
 		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) {
 			for (const String &E : extensions) {
 				f->store_line(E);
 				f->store_line(E);
 			}
 			}
 		}
 		}
 	} else {
 	} 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);
 			DirAccessRef da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
-			da->remove(NativeExtension::EXTENSION_LIST_CONFIG_FILE);
+			da->remove(extension_list_config_file);
 		}
 		}
 	}
 	}
 
 

+ 6 - 3
editor/editor_paths.cpp

@@ -87,6 +87,8 @@ void EditorPaths::_bind_methods() {
 EditorPaths::EditorPaths() {
 EditorPaths::EditorPaths() {
 	singleton = this;
 	singleton = this;
 
 
+	project_data_dir = ProjectSettings::get_singleton()->get_project_data_path();
+
 	// Self-contained mode if a `._sc_` or `_sc_` file is present in executable dir.
 	// Self-contained mode if a `._sc_` or `_sc_` file is present in executable dir.
 	String exe_path = OS::get_singleton()->get_executable_path().get_base_dir();
 	String exe_path = OS::get_singleton()->get_executable_path().get_base_dir();
 	{
 	{
@@ -183,7 +185,7 @@ EditorPaths::EditorPaths() {
 		}
 		}
 	}
 	}
 
 
-	// Validate or create project-specific editor data dir (`res://.godot`),
+	// Validate or create project-specific editor data dir,
 	// including shader cache subdir.
 	// including shader cache subdir.
 
 
 	if (Main::is_project_manager() || Main::is_cmdline_tool()) {
 	if (Main::is_project_manager() || Main::is_cmdline_tool()) {
@@ -205,8 +207,9 @@ EditorPaths::EditorPaths() {
 			dir_res->make_dir("editor");
 			dir_res->make_dir("editor");
 		}
 		}
 		// Imported assets dir.
 		// Imported assets dir.
-		if (!dir_res->dir_exists(ProjectSettings::IMPORTED_FILES_PATH)) {
-			dir_res->make_dir(ProjectSettings::IMPORTED_FILES_PATH);
+		String imported_files_path = ProjectSettings::get_singleton()->get_imported_files_path();
+		if (!dir_res->dir_exists(imported_files_path)) {
+			dir_res->make_dir(imported_files_path);
 		}
 		}
 	}
 	}
 }
 }

+ 1 - 1
editor/editor_paths.h

@@ -41,7 +41,7 @@ class EditorPaths : public Object {
 	String data_dir; // Editor data (templates, shader cache, etc.).
 	String data_dir; // Editor data (templates, shader cache, etc.).
 	String config_dir; // Editor config (settings, profiles, themes, etc.).
 	String config_dir; // Editor config (settings, profiles, themes, etc.).
 	String cache_dir; // Editor cache (thumbnails, tmp generated files).
 	String cache_dir; // Editor cache (thumbnails, tmp generated files).
-	String project_data_dir = "res://.godot"; // Project-specific data (metadata, shader cache, etc.).
+	String project_data_dir; // Project-specific data (metadata, shader cache, etc.).
 	bool self_contained = false; // Self-contained means everything goes to `editor_data` dir.
 	bool self_contained = false; // Self-contained means everything goes to `editor_data` dir.
 	String self_contained_file; // Self-contained file with configuration.
 	String self_contained_file; // Self-contained file with configuration.
 
 

+ 3 - 2
editor/find_in_files.cpp

@@ -233,8 +233,9 @@ void FindInFiles::_scan_dir(String path, PackedStringArray &out_folders) {
 			break;
 			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;
 			continue;
 		}
 		}
 		if (dir->current_is_hidden()) {
 		if (dir->current_is_hidden()) {

+ 2 - 2
editor/project_manager.cpp

@@ -2123,8 +2123,8 @@ void ProjectManager::_run_project_confirm() {
 		const String &selected = selected_list[i].project_key;
 		const String &selected = selected_list[i].project_key;
 		String path = EditorSettings::get_singleton()->get("projects/" + selected);
 		String path = EditorSettings::get_singleton()->get("projects/" + selected);
 
 
-		// `.substr(6)` on `IMPORTED_FILES_PATH` strips away the leading "res://".
-		if (!DirAccess::exists(path.plus_file(ProjectSettings::IMPORTED_FILES_PATH.substr(6)))) {
+		// `.substr(6)` on `ProjectSettings::get_singleton()->get_imported_files_path()` strips away the leading "res://".
+		if (!DirAccess::exists(path.plus_file(ProjectSettings::get_singleton()->get_imported_files_path().substr(6)))) {
 			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->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();
 			run_error_diag->popup_centered();
 			continue;
 			continue;

+ 1 - 0
modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Client.cs

@@ -121,6 +121,7 @@ namespace GodotTools.IdeMessaging
             this.messageHandler = messageHandler;
             this.messageHandler = messageHandler;
             this.logger = logger;
             this.logger = logger;
 
 
+            // TODO: Need to fetch the project data dir name from ProjectSettings instead of defaulting to ".godot"
             string projectMetadataDir = Path.Combine(godotProjectDir, ".godot", "mono", "metadata");
             string projectMetadataDir = Path.Combine(godotProjectDir, ".godot", "mono", "metadata");
 
 
             MetaFilePath = Path.Combine(projectMetadataDir, GodotIdeMetadata.DefaultFileName);
             MetaFilePath = Path.Combine(projectMetadataDir, GodotIdeMetadata.DefaultFileName);

+ 1 - 1
modules/mono/godotsharp_dirs.cpp

@@ -122,7 +122,7 @@ public:
 
 
 private:
 private:
 	_GodotSharpDirs() {
 	_GodotSharpDirs() {
-		res_data_dir = "res://.godot/mono";
+		res_data_dir = ProjectSettings::get_singleton()->get_project_data_path().plus_file("mono");
 		res_metadata_dir = res_data_dir.plus_file("metadata");
 		res_metadata_dir = res_data_dir.plus_file("metadata");
 		res_assemblies_base_dir = res_data_dir.plus_file("assemblies");
 		res_assemblies_base_dir = res_data_dir.plus_file("assemblies");
 		res_assemblies_dir = res_assemblies_base_dir.plus_file(GDMono::get_expected_api_build_config());
 		res_assemblies_dir = res_assemblies_base_dir.plus_file(GDMono::get_expected_api_build_config());

+ 2 - 1
platform/javascript/api/javascript_tools_editor_plugin.cpp

@@ -131,9 +131,10 @@ void JavaScriptToolsEditorPlugin::_zip_recursive(String p_path, String p_base_pa
 	}
 	}
 	dir->list_dir_begin();
 	dir->list_dir_begin();
 	String cur = dir->get_next();
 	String cur = dir->get_next();
+	String project_data_dir_name = ProjectSettings::get_singleton()->get_project_data_dir_name();
 	while (!cur.is_empty()) {
 	while (!cur.is_empty()) {
 		String cs = p_path.plus_file(cur);
 		String cs = p_path.plus_file(cur);
-		if (cur == "." || cur == ".." || cur == ".import") {
+		if (cur == "." || cur == ".." || cur == project_data_dir_name) {
 			// Skip
 			// Skip
 		} else if (dir->current_is_dir()) {
 		} else if (dir->current_is_dir()) {
 			String path = cs.replace_first(p_base_path, "") + "/";
 			String path = cs.replace_first(p_base_path, "") + "/";