summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorne0fhyk <fhuyakou@gmail.com>2021-09-10 08:32:29 -0700
committerne0fhyk <fhuyakou@gmail.com>2021-09-15 12:52:03 -0700
commit69f890ff11a15cc2c1aa651801a872505ab08c81 (patch)
treeba9bbb131814f460a87605d3f9fce3c578e8e06a
parent729461b2a455bd3b4afb26bb362863a68e98a9ee (diff)
Provide a getter for the project data directory.
-rw-r--r--core/config/project_settings.cpp13
-rw-r--r--core/config/project_settings.h4
-rw-r--r--core/extension/native_extension.cpp4
-rw-r--r--core/extension/native_extension.h2
-rw-r--r--core/extension/native_extension_manager.cpp2
-rw-r--r--core/io/resource_importer.cpp2
-rw-r--r--core/io/resource_uid.cpp17
-rw-r--r--core/io/resource_uid.h2
-rw-r--r--editor/editor_export.cpp14
-rw-r--r--editor/editor_file_dialog.cpp2
-rw-r--r--editor/editor_file_system.cpp13
-rw-r--r--editor/editor_paths.cpp9
-rw-r--r--editor/editor_paths.h2
-rw-r--r--editor/find_in_files.cpp5
-rw-r--r--editor/project_manager.cpp4
-rw-r--r--modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Client.cs1
-rw-r--r--modules/mono/godotsharp_dirs.cpp2
-rw-r--r--platform/javascript/api/javascript_tools_editor_plugin.cpp3
18 files changed, 67 insertions, 34 deletions
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp
index 03892d1d4f..283500d826 100644
--- a/core/config/project_settings.cpp
+++ b/core/config/project_settings.cpp
@@ -48,11 +48,22 @@ ProjectSettings *ProjectSettings::get_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 {
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 {
if (resource_path == "") {
diff --git a/core/config/project_settings.h b/core/config/project_settings.h
index 7e93f26f0d..b642051402 100644
--- a/core/config/project_settings.h
+++ b/core/config/project_settings.h
@@ -42,7 +42,6 @@ class ProjectSettings : public Object {
public:
typedef Map<String, Variant> CustomMap;
- static const String IMPORTED_FILES_PATH;
enum {
//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);
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_imported_files_path() const;
static ProjectSettings *get_singleton();
diff --git a/core/extension/native_extension.cpp b/core/extension/native_extension.cpp
index a3cd7ca14c..93b98524b7 100644
--- a/core/extension/native_extension.cpp
+++ b/core/extension/native_extension.cpp
@@ -35,7 +35,9 @@
#include "core/object/method_bind.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 {
GDNativeExtensionClassMethodCall call_func;
diff --git a/core/extension/native_extension.h b/core/extension/native_extension.h
index b661381d64..88a98d4ee9 100644
--- a/core/extension/native_extension.h
+++ b/core/extension/native_extension.h
@@ -60,7 +60,7 @@ protected:
static void _bind_methods();
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);
void close_library();
diff --git a/core/extension/native_extension_manager.cpp b/core/extension/native_extension_manager.cpp
index 8b7a9df4f1..cd72376897 100644
--- a/core/extension/native_extension_manager.cpp
+++ b/core/extension/native_extension_manager.cpp
@@ -112,7 +112,7 @@ void NativeExtensionManager::deinitialize_extensions(NativeExtension::Initializa
}
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()) {
String s = f->get_line().strip_edges();
if (s != String()) {
diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp
index 1e166015b0..cd44c537a8 100644
--- a/core/io/resource_importer.cpp
+++ b/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 {
- 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 {
diff --git a/core/io/resource_uid.cpp b/core/io/resource_uid.cpp
index 97d683f415..acb49ecece 100644
--- a/core/io/resource_uid.cpp
+++ b/core/io/resource_uid.cpp
@@ -29,6 +29,8 @@
/*************************************************************************/
#include "resource_uid.h"
+
+#include "core/config/project_settings.h"
#include "core/crypto/crypto.h"
#include "core/io/dir_access.h"
#include "core/io/file_access.h"
@@ -36,7 +38,9 @@
static constexpr uint32_t char_count = ('z' - 'a');
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 {
if (p_id < 0) {
@@ -136,12 +140,13 @@ void ResourceUID::remove_id(ID p_id) {
}
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);
- 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) {
return ERR_CANT_OPEN;
}
@@ -165,7 +170,7 @@ Error ResourceUID::save_to_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) {
return ERR_CANT_OPEN;
}
@@ -207,7 +212,7 @@ Error ResourceUID::update_cache() {
for (OrderedHashMap<ID, Cache>::Element E = unique_ids.front(); E; E = E.next()) {
if (!E.get().saved_to_cache) {
if (f == nullptr) {
- f = FileAccess::open(CACHE_FILE, FileAccess::READ_WRITE); //append
+ f = FileAccess::open(get_cache_file(), FileAccess::READ_WRITE); //append
if (!f) {
return ERR_CANT_OPEN;
}
diff --git a/core/io/resource_uid.h b/core/io/resource_uid.h
index b12138425a..2f1bfdf243 100644
--- a/core/io/resource_uid.h
+++ b/core/io/resource_uid.h
@@ -44,7 +44,7 @@ public:
INVALID_ID = -1
};
- static const char *CACHE_FILE;
+ static String get_cache_file();
private:
mutable Ref<Crypto> crypto;
diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp
index 10ed76673e..e90bb1cb53 100644
--- a/editor/editor_export.cpp
+++ b/editor/editor_export.cpp
@@ -1043,17 +1043,19 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
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) {
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) {
return err;
}
diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp
index bf95e6cf62..46a4756a97 100644
--- a/editor/editor_file_dialog.cpp
+++ b/editor/editor_file_dialog.cpp
@@ -588,7 +588,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 (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;
break;
}
diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp
index aa89a14725..5542d808d8 100644
--- a/editor/editor_file_system.cpp
+++ b/editor/editor_file_system.cpp
@@ -2147,6 +2147,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;
@@ -2212,7 +2216,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;
}
@@ -2270,17 +2274,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);
}
}
diff --git a/editor/editor_paths.cpp b/editor/editor_paths.cpp
index c9817190dd..71f13c0c2f 100644
--- a/editor/editor_paths.cpp
+++ b/editor/editor_paths.cpp
@@ -87,6 +87,8 @@ void EditorPaths::_bind_methods() {
EditorPaths::EditorPaths() {
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.
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.
if (Main::is_project_manager() || Main::is_cmdline_tool()) {
@@ -205,8 +207,9 @@ EditorPaths::EditorPaths() {
dir_res->make_dir("editor");
}
// 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);
}
}
}
diff --git a/editor/editor_paths.h b/editor/editor_paths.h
index 2c156b7c96..cf94ed797a 100644
--- a/editor/editor_paths.h
+++ b/editor/editor_paths.h
@@ -41,7 +41,7 @@ class EditorPaths : public Object {
String data_dir; // Editor data (templates, shader cache, etc.).
String config_dir; // Editor config (settings, profiles, themes, etc.).
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.
String self_contained_file; // Self-contained file with configuration.
diff --git a/editor/find_in_files.cpp b/editor/find_in_files.cpp
index 9444706fd2..fd685cf592 100644
--- a/editor/find_in_files.cpp
+++ b/editor/find_in_files.cpp
@@ -233,8 +233,9 @@ void FindInFiles::_scan_dir(String path, PackedStringArray &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 05cf3791f4..1277a4e2bd 100644
--- a/editor/project_manager.cpp
+++ b/editor/project_manager.cpp
@@ -2119,8 +2119,8 @@ void ProjectManager::_run_project_confirm() {
const String &selected = selected_list[i].project_key;
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->popup_centered();
continue;
diff --git a/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Client.cs b/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Client.cs
index 0f50c90531..1d7bfaf0a4 100644
--- a/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Client.cs
+++ b/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Client.cs
@@ -121,6 +121,7 @@ namespace GodotTools.IdeMessaging
this.messageHandler = messageHandler;
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");
MetaFilePath = Path.Combine(projectMetadataDir, GodotIdeMetadata.DefaultFileName);
diff --git a/modules/mono/godotsharp_dirs.cpp b/modules/mono/godotsharp_dirs.cpp
index 375ad413c4..24bd1ed492 100644
--- a/modules/mono/godotsharp_dirs.cpp
+++ b/modules/mono/godotsharp_dirs.cpp
@@ -122,7 +122,7 @@ public:
private:
_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_assemblies_base_dir = res_data_dir.plus_file("assemblies");
res_assemblies_dir = res_assemblies_base_dir.plus_file(GDMono::get_expected_api_build_config());
diff --git a/platform/javascript/api/javascript_tools_editor_plugin.cpp b/platform/javascript/api/javascript_tools_editor_plugin.cpp
index c50195639c..11bb7605ed 100644
--- a/platform/javascript/api/javascript_tools_editor_plugin.cpp
+++ b/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();
String cur = dir->get_next();
+ String project_data_dir_name = ProjectSettings::get_singleton()->get_project_data_dir_name();
while (!cur.is_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, "") + "/";