Load project metadata file only when needed
(cherry picked from commit 3dc47b0b84
)
This commit is contained in:
parent
a47a07d13b
commit
06a94ecc14
|
@ -884,6 +884,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() {
|
||||
|
@ -1171,24 +1175,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) {
|
||||
|
|
|
@ -79,6 +79,7 @@ private:
|
|||
|
||||
HashSet<String> changed_settings;
|
||||
|
||||
mutable Ref<ConfigFile> project_metadata;
|
||||
HashMap<String, PropertyInfo> hints;
|
||||
HashMap<String, VariantContainer> props;
|
||||
int last_order;
|
||||
|
@ -106,6 +107,7 @@ private:
|
|||
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();
|
||||
|
|
Loading…
Reference in New Issue