Skip to content

Commit

Permalink
Load project metadata file only when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
KoBeWi committed Jul 23, 2023
1 parent 6588a4a commit 3dc47b0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
39 changes: 25 additions & 14 deletions editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,10 @@ bool EditorSettings::_is_default_text_editor_theme(String p_theme_name) {
return p_theme_name == "default" || p_theme_name == "godot 2" || p_theme_name == "custom";
}

const String EditorSettings::_get_project_metadata_path() const {
return EditorPaths::get_singleton()->get_project_settings_dir().path_join("project_metadata.cfg");
}

// PUBLIC METHODS

EditorSettings *EditorSettings::get_singleton() {
Expand Down Expand Up @@ -1160,24 +1164,31 @@ void EditorSettings::add_property_hint(const PropertyInfo &p_hint) {
// Metadata

void EditorSettings::set_project_metadata(const String &p_section, const String &p_key, Variant p_data) {
Ref<ConfigFile> cf = memnew(ConfigFile);
String path = EditorPaths::get_singleton()->get_project_settings_dir().path_join("project_metadata.cfg");
Error err;
err = cf->load(path);
ERR_FAIL_COND_MSG(err != OK && err != ERR_FILE_NOT_FOUND, "Cannot load editor settings from file '" + path + "'.");
cf->set_value(p_section, p_key, p_data);
err = cf->save(path);
ERR_FAIL_COND_MSG(err != OK, "Cannot save editor settings to file '" + path + "'.");
const String path = _get_project_metadata_path();

if (project_metadata.is_null()) {
project_metadata.instantiate();

Error err = project_metadata->load(path);
if (err != OK && err != ERR_FILE_NOT_FOUND) {
ERR_PRINT("Cannot load project metadata from file '" + path + "'.");
}
}
project_metadata->set_value(p_section, p_key, p_data);

Error err = project_metadata->save(path);
ERR_FAIL_COND_MSG(err != OK, "Cannot save project metadata to file '" + path + "'.");
}

Variant EditorSettings::get_project_metadata(const String &p_section, const String &p_key, Variant p_default) const {
Ref<ConfigFile> cf = memnew(ConfigFile);
String path = EditorPaths::get_singleton()->get_project_settings_dir().path_join("project_metadata.cfg");
Error err = cf->load(path);
if (err != OK) {
return p_default;
if (project_metadata.is_null()) {
project_metadata.instantiate();

const String path = _get_project_metadata_path();
Error err = project_metadata->load(path);
ERR_FAIL_COND_V_MSG(err != OK && err != ERR_FILE_NOT_FOUND, p_default, "Cannot load project metadata from file '" + path + "'.");
}
return cf->get_value(p_section, p_key, p_default);
return project_metadata->get_value(p_section, p_key, p_default);
}

void EditorSettings::set_favorites(const Vector<String> &p_favorites) {
Expand Down
2 changes: 2 additions & 0 deletions editor/editor_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class EditorSettings : public Resource {

HashSet<String> changed_settings;

mutable Ref<ConfigFile> project_metadata;
HashMap<String, PropertyInfo> hints;
HashMap<String, VariantContainer> props;
int last_order;
Expand Down Expand Up @@ -106,6 +107,7 @@ class EditorSettings : public Resource {
void _load_godot2_text_editor_theme();
bool _save_text_editor_theme(String p_file);
bool _is_default_text_editor_theme(String p_theme_name);
const String _get_project_metadata_path() const;

protected:
static void _bind_methods();
Expand Down

0 comments on commit 3dc47b0

Please sign in to comment.