summaryrefslogtreecommitdiff
path: root/core/config
diff options
context:
space:
mode:
Diffstat (limited to 'core/config')
-rw-r--r--core/config/engine.h2
-rw-r--r--core/config/project_settings.cpp76
2 files changed, 20 insertions, 58 deletions
diff --git a/core/config/engine.h b/core/config/engine.h
index 1adab9b96f..eac96852b3 100644
--- a/core/config/engine.h
+++ b/core/config/engine.h
@@ -40,7 +40,7 @@ class Engine {
public:
struct Singleton {
StringName name;
- Object *ptr;
+ Object *ptr = nullptr;
StringName class_name; //used for binding generation hinting
bool user_created = false;
Singleton(const StringName &p_name = StringName(), Object *p_ptr = nullptr, const StringName &p_class_name = StringName());
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp
index 3a7fc828aa..79fa6a0895 100644
--- a/core/config/project_settings.cpp
+++ b/core/config/project_settings.cpp
@@ -145,7 +145,7 @@ String ProjectSettings::localize_path(const String &p_path) const {
return p_path.simplify_path();
}
- DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
String path = p_path.replace("\\", "/").simplify_path();
@@ -153,8 +153,6 @@ String ProjectSettings::localize_path(const String &p_path) const {
String cwd = dir->get_current_dir();
cwd = cwd.replace("\\", "/");
- memdelete(dir);
-
// Ensure that we end with a '/'.
// This is important to ensure that we do not wrongly localize the resource path
// in an absolute path that just happens to contain this string but points to a
@@ -173,8 +171,6 @@ String ProjectSettings::localize_path(const String &p_path) const {
return cwd.replace_first(res_path, "res://");
} else {
- memdelete(dir);
-
int sep = path.rfind("/");
if (sep == -1) {
return "res://" + path;
@@ -325,9 +321,9 @@ bool ProjectSettings::_get(const StringName &p_name, Variant &r_ret) const {
struct _VCSort {
String name;
- Variant::Type type;
- int order;
- uint32_t flags;
+ Variant::Type type = Variant::VARIANT_MAX;
+ int order = 0;
+ uint32_t flags = 0;
bool operator<(const _VCSort &p_vcs) const { return order == p_vcs.order ? name < p_vcs.name : order < p_vcs.order; }
};
@@ -541,8 +537,8 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
// Nothing was found, try to find a project file in provided path (`p_path`)
// or, if requested (`p_upwards`) in parent directories.
- DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
- ERR_FAIL_COND_V_MSG(!d, ERR_CANT_CREATE, "Cannot create DirAccess for path '" + p_path + "'.");
+ Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ ERR_FAIL_COND_V_MSG(d.is_null(), ERR_CANT_CREATE, "Cannot create DirAccess for path '" + p_path + "'.");
d->change_dir(p_path);
String current_dir = d->get_current_dir();
@@ -573,8 +569,6 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
}
}
- memdelete(d);
-
if (!found) {
return err;
}
@@ -614,26 +608,19 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bo
bool ProjectSettings::has_setting(String p_var) const {
_THREAD_SAFE_METHOD_
- StringName name = p_var;
- if (!disable_feature_overrides && feature_overrides.has(name)) {
- name = feature_overrides[name];
- }
- return props.has(name);
+ return props.has(p_var);
}
Error ProjectSettings::_load_settings_binary(const String &p_path) {
Error err;
- FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
+ Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err);
if (err != OK) {
return err;
}
uint8_t hdr[4];
f->get_buffer(hdr, 4);
- if (hdr[0] != 'E' || hdr[1] != 'C' || hdr[2] != 'F' || hdr[3] != 'G') {
- memdelete(f);
- ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Corrupted header in binary project.binary (not ECFG).");
- }
+ ERR_FAIL_COND_V_MSG((hdr[0] != 'E' || hdr[1] != 'C' || hdr[2] != 'F' || hdr[3] != 'G'), ERR_FILE_CORRUPT, "Corrupted header in binary project.binary (not ECFG).");
uint32_t count = f->get_32();
@@ -656,16 +643,14 @@ Error ProjectSettings::_load_settings_binary(const String &p_path) {
set(key, value);
}
- f->close();
- memdelete(f);
return OK;
}
Error ProjectSettings::_load_settings_text(const String &p_path) {
Error err;
- FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
+ Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err);
- if (!f) {
+ if (f.is_null()) {
// FIXME: Above 'err' error code is ERR_FILE_CANT_OPEN if the file is missing
// This needs to be streamlined if we want decent error reporting
return ERR_FILE_NOT_FOUND;
@@ -690,25 +675,18 @@ Error ProjectSettings::_load_settings_text(const String &p_path) {
err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, nullptr, true);
if (err == ERR_FILE_EOF) {
- memdelete(f);
// If we're loading a project.godot from source code, we can operate some
// ProjectSettings conversions if need be.
_convert_to_last_version(config_version);
last_save_time = FileAccess::get_modified_time(get_resource_path().plus_file("project.godot"));
return OK;
- } else if (err != OK) {
- ERR_PRINT("Error parsing " + p_path + " at line " + itos(lines) + ": " + error_text + " File might be corrupted.");
- memdelete(f);
- return err;
}
+ ERR_FAIL_COND_V_MSG(err != OK, err, "Error parsing " + p_path + " at line " + itos(lines) + ": " + error_text + " File might be corrupted.");
if (!assign.is_empty()) {
if (section.is_empty() && assign == "config_version") {
config_version = value;
- if (config_version > CONFIG_VERSION) {
- memdelete(f);
- ERR_FAIL_V_MSG(ERR_FILE_CANT_OPEN, vformat("Can't open project at '%s', its `config_version` (%d) is from a more recent and incompatible version of the engine. Expected config version: %d.", p_path, config_version, CONFIG_VERSION));
- }
+ ERR_FAIL_COND_V_MSG(config_version > CONFIG_VERSION, ERR_FILE_CANT_OPEN, vformat("Can't open project at '%s', its `config_version` (%d) is from a more recent and incompatible version of the engine. Expected config version: %d.", p_path, config_version, CONFIG_VERSION));
} else {
if (section.is_empty()) {
set(assign, value);
@@ -788,7 +766,7 @@ Error ProjectSettings::save() {
Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {
Error err;
- FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
+ Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err);
ERR_FAIL_COND_V_MSG(err != OK, err, "Couldn't save project.binary at " + p_file + ".");
uint8_t hdr[4] = { 'E', 'C', 'F', 'G' };
@@ -808,19 +786,13 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<Str
int len;
err = encode_variant(p_custom_features, nullptr, len, false);
- if (err != OK) {
- memdelete(file);
- ERR_FAIL_V(err);
- }
+ ERR_FAIL_COND_V(err != OK, err);
Vector<uint8_t> buff;
buff.resize(len);
err = encode_variant(p_custom_features, buff.ptrw(), len, false);
- if (err != OK) {
- memdelete(file);
- ERR_FAIL_V(err);
- }
+ ERR_FAIL_COND_V(err != OK, err);
file->store_32(len);
file->store_buffer(buff.ptr(), buff.size());
@@ -844,33 +816,24 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<Str
int len;
err = encode_variant(value, nullptr, len, true);
- if (err != OK) {
- memdelete(file);
- }
ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
Vector<uint8_t> buff;
buff.resize(len);
err = encode_variant(value, buff.ptrw(), len, true);
- if (err != OK) {
- memdelete(file);
- }
ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
file->store_32(len);
file->store_buffer(buff.ptr(), buff.size());
}
}
- file->close();
- memdelete(file);
-
return OK;
}
Error ProjectSettings::_save_settings_text(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {
Error err;
- FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
+ Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err);
ERR_FAIL_COND_V_MSG(err != OK, err, "Couldn't save project.godot - " + p_file + ".");
@@ -915,9 +878,6 @@ Error ProjectSettings::_save_settings_text(const String &p_file, const Map<Strin
}
}
- file->close();
- memdelete(file);
-
return OK;
}
@@ -1203,6 +1163,8 @@ ProjectSettings::ProjectSettings() {
singleton = this;
GLOBAL_DEF_BASIC("application/config/name", "");
+ GLOBAL_DEF_BASIC("application/config/name_localized", Dictionary());
+ custom_prop_info["application/config/name_localized"] = PropertyInfo(Variant::DICTIONARY, "application/config/name_localized", PROPERTY_HINT_LOCALIZABLE_STRING);
GLOBAL_DEF_BASIC("application/config/description", "");
custom_prop_info["application/config/description"] = PropertyInfo(Variant::STRING, "application/config/description", PROPERTY_HINT_MULTILINE_TEXT);
GLOBAL_DEF_BASIC("application/run/main_scene", "");