summaryrefslogtreecommitdiff
path: root/core/io/config_file.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/io/config_file.cpp')
-rw-r--r--core/io/config_file.cpp26
1 files changed, 0 insertions, 26 deletions
diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp
index 73230e3a3c..902d3cde9f 100644
--- a/core/io/config_file.cpp
+++ b/core/io/config_file.cpp
@@ -35,14 +35,12 @@
#include "core/variant_parser.h"
PackedStringArray ConfigFile::_get_sections() const {
-
List<String> s;
get_sections(&s);
PackedStringArray arr;
arr.resize(s.size());
int idx = 0;
for (const List<String>::Element *E = s.front(); E; E = E->next()) {
-
arr.set(idx++, E->get());
}
@@ -50,14 +48,12 @@ PackedStringArray ConfigFile::_get_sections() const {
}
PackedStringArray ConfigFile::_get_section_keys(const String &p_section) const {
-
List<String> s;
get_section_keys(p_section, &s);
PackedStringArray arr;
arr.resize(s.size());
int idx = 0;
for (const List<String>::Element *E = s.front(); E; E = E->next()) {
-
arr.set(idx++, E->get());
}
@@ -65,7 +61,6 @@ PackedStringArray ConfigFile::_get_section_keys(const String &p_section) const {
}
void ConfigFile::set_value(const String &p_section, const String &p_key, const Variant &p_value) {
-
if (p_value.get_type() == Variant::NIL) {
//erase
if (!values.has(p_section))
@@ -84,7 +79,6 @@ void ConfigFile::set_value(const String &p_section, const String &p_key, const V
}
}
Variant ConfigFile::get_value(const String &p_section, const String &p_key, Variant p_default) const {
-
if (!values.has(p_section) || !values[p_section].has(p_key)) {
ERR_FAIL_COND_V_MSG(p_default.get_type() == Variant::NIL, Variant(),
vformat("Couldn't find the given section \"%s\" and key \"%s\", and no default was given.", p_section, p_key));
@@ -95,24 +89,20 @@ Variant ConfigFile::get_value(const String &p_section, const String &p_key, Vari
}
bool ConfigFile::has_section(const String &p_section) const {
-
return values.has(p_section);
}
bool ConfigFile::has_section_key(const String &p_section, const String &p_key) const {
-
if (!values.has(p_section))
return false;
return values[p_section].has(p_key);
}
void ConfigFile::get_sections(List<String> *r_sections) const {
-
for (OrderedHashMap<String, OrderedHashMap<String, Variant>>::ConstElement E = values.front(); E; E = E.next()) {
r_sections->push_back(E.key());
}
}
void ConfigFile::get_section_keys(const String &p_section, List<String> *r_keys) const {
-
ERR_FAIL_COND_MSG(!values.has(p_section), vformat("Cannot get keys from nonexistent section \"%s\".", p_section));
for (OrderedHashMap<String, Variant>::ConstElement E = values[p_section].front(); E; E = E.next()) {
@@ -121,13 +111,11 @@ void ConfigFile::get_section_keys(const String &p_section, List<String> *r_keys)
}
void ConfigFile::erase_section(const String &p_section) {
-
ERR_FAIL_COND_MSG(!values.has(p_section), vformat("Cannot erase nonexistent section \"%s\".", p_section));
values.erase(p_section);
}
void ConfigFile::erase_section_key(const String &p_section, const String &p_key) {
-
ERR_FAIL_COND_MSG(!values.has(p_section), vformat("Cannot erase key \"%s\" from nonexistent section \"%s\".", p_key, p_section));
ERR_FAIL_COND_MSG(!values[p_section].has(p_key), vformat("Cannot erase nonexistent key \"%s\" from section \"%s\".", p_key, p_section));
@@ -135,7 +123,6 @@ void ConfigFile::erase_section_key(const String &p_section, const String &p_key)
}
Error ConfigFile::save(const String &p_path) {
-
Error err;
FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err);
@@ -149,7 +136,6 @@ Error ConfigFile::save(const String &p_path) {
}
Error ConfigFile::save_encrypted(const String &p_path, const Vector<uint8_t> &p_key) {
-
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err);
@@ -167,7 +153,6 @@ Error ConfigFile::save_encrypted(const String &p_path, const Vector<uint8_t> &p_
}
Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass) {
-
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err);
@@ -186,15 +171,12 @@ Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass
}
Error ConfigFile::_internal_save(FileAccess *file) {
-
for (OrderedHashMap<String, OrderedHashMap<String, Variant>>::Element E = values.front(); E; E = E.next()) {
-
if (E != values.front())
file->store_string("\n");
file->store_string("[" + E.key() + "]\n\n");
for (OrderedHashMap<String, Variant>::Element F = E.get().front(); F; F = F.next()) {
-
String vstr;
VariantWriter::write_to_string(F.get(), vstr);
file->store_string(F.key() + "=" + vstr + "\n");
@@ -207,7 +189,6 @@ Error ConfigFile::_internal_save(FileAccess *file) {
}
Error ConfigFile::load(const String &p_path) {
-
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
@@ -218,7 +199,6 @@ Error ConfigFile::load(const String &p_path) {
}
Error ConfigFile::load_encrypted(const String &p_path, const Vector<uint8_t> &p_key) {
-
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
@@ -236,7 +216,6 @@ Error ConfigFile::load_encrypted(const String &p_path, const Vector<uint8_t> &p_
}
Error ConfigFile::load_encrypted_pass(const String &p_path, const String &p_pass) {
-
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
@@ -255,7 +234,6 @@ Error ConfigFile::load_encrypted_pass(const String &p_path, const String &p_pass
}
Error ConfigFile::_internal_load(const String &p_path, FileAccess *f) {
-
VariantParser::StreamFile stream;
stream.f = f;
@@ -267,14 +245,12 @@ Error ConfigFile::_internal_load(const String &p_path, FileAccess *f) {
}
Error ConfigFile::parse(const String &p_data) {
-
VariantParser::StreamString stream;
stream.s = p_data;
return _parse("<string>", &stream);
}
Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream) {
-
String assign;
Variant value;
VariantParser::Tag next_tag;
@@ -285,7 +261,6 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream)
String section;
while (true) {
-
assign = Variant();
next_tag.fields.clear();
next_tag.name = String();
@@ -309,7 +284,6 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream)
}
void ConfigFile::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_value", "section", "key", "value"), &ConfigFile::set_value);
ClassDB::bind_method(D_METHOD("get_value", "section", "key", "default"), &ConfigFile::get_value, DEFVAL(Variant()));