Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Provide a getter for the project data directory. #52714

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/io/resource_importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResourceImporter> &p_a, const Ref<ResourceImporter> &p_b) const {
Expand Down Expand Up @@ -380,7 +381,7 @@ Ref<ResourceImporter> 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 {
Expand Down
9 changes: 9 additions & 0 deletions core/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
2 changes: 2 additions & 0 deletions core/project_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class ProjectSettings : public Object {
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();
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
18 changes: 12 additions & 6 deletions editor/editor_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1888,13 +1888,14 @@ void EditorFileSystem::_find_group_files(EditorFileSystemDirectory *efd, Map<Str
}

void EditorFileSystem::reimport_files(const Vector<String> &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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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");
Expand Down
5 changes: 3 additions & 2 deletions editor/find_in_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
3 changes: 2 additions & 1 deletion editor/project_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion platform/javascript/api/javascript_tools_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, "") + "/";
Expand Down