3131/* *************************************************************************/
3232
3333#include " config_file.h"
34+ #include " config_file.compat.inc"
3435
3536#include " core/io/file_access_encrypted.h"
3637#include " core/os/keyboard.h"
@@ -133,7 +134,7 @@ void ConfigFile::erase_section_key(const String &p_section, const String &p_key)
133134 }
134135}
135136
136- String ConfigFile::encode_to_text () const {
137+ String ConfigFile::encode_to_text (bool p_full_objects ) const {
137138 StringBuilder sb;
138139 bool first = true ;
139140 for (const KeyValue<String, HashMap<String, Variant>> &E : values) {
@@ -148,25 +149,25 @@ String ConfigFile::encode_to_text() const {
148149
149150 for (const KeyValue<String, Variant> &F : E.value ) {
150151 String vstr;
151- VariantWriter::write_to_string (F.value , vstr);
152+ VariantWriter::write_to_string (F.value , vstr, nullptr , nullptr , true , p_full_objects );
152153 sb.append (F.key .property_name_encode () + " =" + vstr + " \n " );
153154 }
154155 }
155156 return sb.as_string ();
156157}
157158
158- Error ConfigFile::save (const String &p_path) {
159+ Error ConfigFile::save (const String &p_path, bool p_full_objects ) {
159160 Error err;
160161 Ref<FileAccess> file = FileAccess::open (p_path, FileAccess::WRITE, &err);
161162
162163 if (err) {
163164 return err;
164165 }
165166
166- return _internal_save (file);
167+ return _internal_save (file, p_full_objects );
167168}
168169
169- Error ConfigFile::save_encrypted (const String &p_path, const Vector<uint8_t > &p_key) {
170+ Error ConfigFile::save_encrypted (const String &p_path, const Vector<uint8_t > &p_key, bool p_full_objects ) {
170171 Error err;
171172 Ref<FileAccess> f = FileAccess::open (p_path, FileAccess::WRITE, &err);
172173
@@ -180,10 +181,10 @@ Error ConfigFile::save_encrypted(const String &p_path, const Vector<uint8_t> &p_
180181 if (err) {
181182 return err;
182183 }
183- return _internal_save (fae);
184+ return _internal_save (fae, p_full_objects );
184185}
185186
186- Error ConfigFile::save_encrypted_pass (const String &p_path, const String &p_pass) {
187+ Error ConfigFile::save_encrypted_pass (const String &p_path, const String &p_pass, bool p_full_objects ) {
187188 Error err;
188189 Ref<FileAccess> f = FileAccess::open (p_path, FileAccess::WRITE, &err);
189190
@@ -198,10 +199,10 @@ Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass
198199 return err;
199200 }
200201
201- return _internal_save (fae);
202+ return _internal_save (fae, p_full_objects );
202203}
203204
204- Error ConfigFile::_internal_save (Ref<FileAccess> file) {
205+ Error ConfigFile::_internal_save (Ref<FileAccess> file, bool p_full_objects ) {
205206 bool first = true ;
206207 for (const KeyValue<String, HashMap<String, Variant>> &E : values) {
207208 if (first) {
@@ -215,26 +216,26 @@ Error ConfigFile::_internal_save(Ref<FileAccess> file) {
215216
216217 for (const KeyValue<String, Variant> &F : E.value ) {
217218 String vstr;
218- VariantWriter::write_to_string (F.value , vstr);
219+ VariantWriter::write_to_string (F.value , vstr, nullptr , nullptr , true , p_full_objects );
219220 file->store_string (F.key .property_name_encode () + " =" + vstr + " \n " );
220221 }
221222 }
222223
223224 return OK;
224225}
225226
226- Error ConfigFile::load (const String &p_path) {
227+ Error ConfigFile::load (const String &p_path, bool p_allow_objects ) {
227228 Error err;
228229 Ref<FileAccess> f = FileAccess::open (p_path, FileAccess::READ, &err);
229230
230231 if (f.is_null ()) {
231232 return err;
232233 }
233234
234- return _internal_load (p_path, f);
235+ return _internal_load (p_path, f, p_allow_objects );
235236}
236237
237- Error ConfigFile::load_encrypted (const String &p_path, const Vector<uint8_t > &p_key) {
238+ Error ConfigFile::load_encrypted (const String &p_path, const Vector<uint8_t > &p_key, bool p_allow_objects ) {
238239 Error err;
239240 Ref<FileAccess> f = FileAccess::open (p_path, FileAccess::READ, &err);
240241
@@ -248,10 +249,10 @@ Error ConfigFile::load_encrypted(const String &p_path, const Vector<uint8_t> &p_
248249 if (err) {
249250 return err;
250251 }
251- return _internal_load (p_path, fae);
252+ return _internal_load (p_path, fae, p_allow_objects );
252253}
253254
254- Error ConfigFile::load_encrypted_pass (const String &p_path, const String &p_pass) {
255+ Error ConfigFile::load_encrypted_pass (const String &p_path, const String &p_pass, bool p_allow_objects ) {
255256 Error err;
256257 Ref<FileAccess> f = FileAccess::open (p_path, FileAccess::READ, &err);
257258
@@ -266,25 +267,25 @@ Error ConfigFile::load_encrypted_pass(const String &p_path, const String &p_pass
266267 return err;
267268 }
268269
269- return _internal_load (p_path, fae);
270+ return _internal_load (p_path, fae, p_allow_objects );
270271}
271272
272- Error ConfigFile::_internal_load (const String &p_path, Ref<FileAccess> f) {
273+ Error ConfigFile::_internal_load (const String &p_path, Ref<FileAccess> f, bool p_allow_objects ) {
273274 VariantParser::StreamFile stream;
274275 stream.f = f;
275276
276- Error err = _parse (p_path, &stream);
277+ Error err = _parse (p_path, &stream, p_allow_objects );
277278
278279 return err;
279280}
280281
281- Error ConfigFile::parse (const String &p_data) {
282+ Error ConfigFile::parse (const String &p_data, bool p_allow_objects ) {
282283 VariantParser::StreamString stream;
283284 stream.s = p_data;
284- return _parse (" <string>" , &stream);
285+ return _parse (" <string>" , &stream, p_allow_objects );
285286}
286287
287- Error ConfigFile::_parse (const String &p_path, VariantParser::Stream *p_stream) {
288+ Error ConfigFile::_parse (const String &p_path, VariantParser::Stream *p_stream, bool p_allow_objects ) {
288289 String assign;
289290 Variant value;
290291 VariantParser::Tag next_tag;
@@ -295,11 +296,12 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream)
295296 String section;
296297
297298 while (true ) {
298- assign = Variant ();
299+ assign = String ();
300+ value = Variant ();
299301 next_tag.fields .clear ();
300302 next_tag.name = String ();
301303
302- Error err = VariantParser::parse_tag_assign_eof (p_stream, lines, error_text, next_tag, assign, value, nullptr , true );
304+ Error err = VariantParser::parse_tag_assign_eof (p_stream, lines, error_text, next_tag, assign, value, nullptr , true , p_allow_objects );
303305 if (err == ERR_FILE_EOF) {
304306 return OK;
305307 } else if (err != OK) {
@@ -334,19 +336,19 @@ void ConfigFile::_bind_methods() {
334336 ClassDB::bind_method (D_METHOD (" erase_section" , " section" ), &ConfigFile::erase_section);
335337 ClassDB::bind_method (D_METHOD (" erase_section_key" , " section" , " key" ), &ConfigFile::erase_section_key);
336338
337- ClassDB::bind_method (D_METHOD (" load" , " path" ), &ConfigFile::load);
338- ClassDB::bind_method (D_METHOD (" parse" , " data" ), &ConfigFile::parse);
339- ClassDB::bind_method (D_METHOD (" save" , " path" ), &ConfigFile::save);
339+ ClassDB::bind_method (D_METHOD (" load" , " path" , " allow_objects " ), &ConfigFile::load, DEFVAL ( false ) );
340+ ClassDB::bind_method (D_METHOD (" parse" , " data" , " allow_objects " ), &ConfigFile::parse, DEFVAL ( false ) );
341+ ClassDB::bind_method (D_METHOD (" save" , " path" , " full_objects " ), &ConfigFile::save, DEFVAL ( false ) );
340342
341- ClassDB::bind_method (D_METHOD (" encode_to_text" ), &ConfigFile::encode_to_text);
343+ ClassDB::bind_method (D_METHOD (" encode_to_text" , " full_objects " ), &ConfigFile::encode_to_text, DEFVAL ( false ) );
342344
343345 BIND_METHOD_ERR_RETURN_DOC (" load" , ERR_FILE_CANT_OPEN);
344346
345- ClassDB::bind_method (D_METHOD (" load_encrypted" , " path" , " key" ), &ConfigFile::load_encrypted);
346- ClassDB::bind_method (D_METHOD (" load_encrypted_pass" , " path" , " password" ), &ConfigFile::load_encrypted_pass);
347+ ClassDB::bind_method (D_METHOD (" load_encrypted" , " path" , " key" , " allow_objects " ), &ConfigFile::load_encrypted, DEFVAL ( false ) );
348+ ClassDB::bind_method (D_METHOD (" load_encrypted_pass" , " path" , " password" , " allow_objects " ), &ConfigFile::load_encrypted_pass, DEFVAL ( false ) );
347349
348- ClassDB::bind_method (D_METHOD (" save_encrypted" , " path" , " key" ), &ConfigFile::save_encrypted);
349- ClassDB::bind_method (D_METHOD (" save_encrypted_pass" , " path" , " password" ), &ConfigFile::save_encrypted_pass);
350+ ClassDB::bind_method (D_METHOD (" save_encrypted" , " path" , " key" , " full_objects " ), &ConfigFile::save_encrypted, DEFVAL ( false ) );
351+ ClassDB::bind_method (D_METHOD (" save_encrypted_pass" , " path" , " password" , " full_objects " ), &ConfigFile::save_encrypted_pass, DEFVAL ( false ) );
350352
351353 ClassDB::bind_method (D_METHOD (" clear" ), &ConfigFile::clear);
352354}
0 commit comments