mirror of
https://github.com/godotengine/godot.git
synced 2025-01-30 21:33:18 +08:00
Load project metadata file only when needed
This commit is contained in:
parent
6588a4a29a
commit
3dc47b0b84
@ -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";
|
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
|
// PUBLIC METHODS
|
||||||
|
|
||||||
EditorSettings *EditorSettings::get_singleton() {
|
EditorSettings *EditorSettings::get_singleton() {
|
||||||
@ -1160,24 +1164,31 @@ void EditorSettings::add_property_hint(const PropertyInfo &p_hint) {
|
|||||||
// Metadata
|
// Metadata
|
||||||
|
|
||||||
void EditorSettings::set_project_metadata(const String &p_section, const String &p_key, Variant p_data) {
|
void EditorSettings::set_project_metadata(const String &p_section, const String &p_key, Variant p_data) {
|
||||||
Ref<ConfigFile> cf = memnew(ConfigFile);
|
const String path = _get_project_metadata_path();
|
||||||
String path = EditorPaths::get_singleton()->get_project_settings_dir().path_join("project_metadata.cfg");
|
|
||||||
Error err;
|
if (project_metadata.is_null()) {
|
||||||
err = cf->load(path);
|
project_metadata.instantiate();
|
||||||
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);
|
Error err = project_metadata->load(path);
|
||||||
err = cf->save(path);
|
if (err != OK && err != ERR_FILE_NOT_FOUND) {
|
||||||
ERR_FAIL_COND_MSG(err != OK, "Cannot save editor settings to file '" + path + "'.");
|
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 {
|
Variant EditorSettings::get_project_metadata(const String &p_section, const String &p_key, Variant p_default) const {
|
||||||
Ref<ConfigFile> cf = memnew(ConfigFile);
|
if (project_metadata.is_null()) {
|
||||||
String path = EditorPaths::get_singleton()->get_project_settings_dir().path_join("project_metadata.cfg");
|
project_metadata.instantiate();
|
||||||
Error err = cf->load(path);
|
|
||||||
if (err != OK) {
|
const String path = _get_project_metadata_path();
|
||||||
return p_default;
|
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) {
|
void EditorSettings::set_favorites(const Vector<String> &p_favorites) {
|
||||||
|
@ -79,6 +79,7 @@ private:
|
|||||||
|
|
||||||
HashSet<String> changed_settings;
|
HashSet<String> changed_settings;
|
||||||
|
|
||||||
|
mutable Ref<ConfigFile> project_metadata;
|
||||||
HashMap<String, PropertyInfo> hints;
|
HashMap<String, PropertyInfo> hints;
|
||||||
HashMap<String, VariantContainer> props;
|
HashMap<String, VariantContainer> props;
|
||||||
int last_order;
|
int last_order;
|
||||||
@ -106,6 +107,7 @@ private:
|
|||||||
void _load_godot2_text_editor_theme();
|
void _load_godot2_text_editor_theme();
|
||||||
bool _save_text_editor_theme(String p_file);
|
bool _save_text_editor_theme(String p_file);
|
||||||
bool _is_default_text_editor_theme(String p_theme_name);
|
bool _is_default_text_editor_theme(String p_theme_name);
|
||||||
|
const String _get_project_metadata_path() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
Loading…
Reference in New Issue
Block a user