Merge pull request #52711 from m4gr3d/provide_getter_for_project_data_dir_master
This commit is contained in:
commit
a7ba227631
|
@ -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.is_empty() || p_path.begins_with("res://") || p_path.begins_with("user://") ||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -62,7 +62,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();
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
@ -135,12 +139,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;
|
||||
}
|
||||
|
@ -164,7 +169,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;
|
||||
}
|
||||
|
@ -206,7 +211,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;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
INVALID_ID = -1
|
||||
};
|
||||
|
||||
static const char *CACHE_FILE;
|
||||
static String get_cache_file();
|
||||
|
||||
private:
|
||||
mutable Ref<Crypto> crypto;
|
||||
|
|
|
@ -1046,17 +1046,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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -2163,6 +2163,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;
|
||||
|
@ -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) {
|
||||
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;
|
||||
}
|
||||
|
@ -2286,17 +2290,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -2123,8 +2123,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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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, "") + "/";
|
||||
|
|
Loading…
Reference in New Issue