31
31
/* *************************************************************************/
32
32
33
33
#include " config_file.h"
34
+ #include " config_file.compat.inc"
34
35
35
36
#include " core/io/file_access_encrypted.h"
36
37
#include " core/os/keyboard.h"
@@ -133,7 +134,7 @@ void ConfigFile::erase_section_key(const String &p_section, const String &p_key)
133
134
}
134
135
}
135
136
136
- String ConfigFile::encode_to_text () const {
137
+ String ConfigFile::encode_to_text (bool p_full_objects ) const {
137
138
StringBuilder sb;
138
139
bool first = true ;
139
140
for (const KeyValue<String, HashMap<String, Variant>> &E : values) {
@@ -148,25 +149,25 @@ String ConfigFile::encode_to_text() const {
148
149
149
150
for (const KeyValue<String, Variant> &F : E.value ) {
150
151
String vstr;
151
- VariantWriter::write_to_string (F.value , vstr);
152
+ VariantWriter::write_to_string (F.value , vstr, nullptr , nullptr , true , p_full_objects );
152
153
sb.append (F.key .property_name_encode () + " =" + vstr + " \n " );
153
154
}
154
155
}
155
156
return sb.as_string ();
156
157
}
157
158
158
- Error ConfigFile::save (const String &p_path) {
159
+ Error ConfigFile::save (const String &p_path, bool p_full_objects ) {
159
160
Error err;
160
161
Ref<FileAccess> file = FileAccess::open (p_path, FileAccess::WRITE, &err);
161
162
162
163
if (err) {
163
164
return err;
164
165
}
165
166
166
- return _internal_save (file);
167
+ return _internal_save (file, p_full_objects );
167
168
}
168
169
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 ) {
170
171
Error err;
171
172
Ref<FileAccess> f = FileAccess::open (p_path, FileAccess::WRITE, &err);
172
173
@@ -180,10 +181,10 @@ Error ConfigFile::save_encrypted(const String &p_path, const Vector<uint8_t> &p_
180
181
if (err) {
181
182
return err;
182
183
}
183
- return _internal_save (fae);
184
+ return _internal_save (fae, p_full_objects );
184
185
}
185
186
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 ) {
187
188
Error err;
188
189
Ref<FileAccess> f = FileAccess::open (p_path, FileAccess::WRITE, &err);
189
190
@@ -198,10 +199,10 @@ Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass
198
199
return err;
199
200
}
200
201
201
- return _internal_save (fae);
202
+ return _internal_save (fae, p_full_objects );
202
203
}
203
204
204
- Error ConfigFile::_internal_save (Ref<FileAccess> file) {
205
+ Error ConfigFile::_internal_save (Ref<FileAccess> file, bool p_full_objects ) {
205
206
bool first = true ;
206
207
for (const KeyValue<String, HashMap<String, Variant>> &E : values) {
207
208
if (first) {
@@ -215,26 +216,26 @@ Error ConfigFile::_internal_save(Ref<FileAccess> file) {
215
216
216
217
for (const KeyValue<String, Variant> &F : E.value ) {
217
218
String vstr;
218
- VariantWriter::write_to_string (F.value , vstr);
219
+ VariantWriter::write_to_string (F.value , vstr, nullptr , nullptr , true , p_full_objects );
219
220
file->store_string (F.key .property_name_encode () + " =" + vstr + " \n " );
220
221
}
221
222
}
222
223
223
224
return OK;
224
225
}
225
226
226
- Error ConfigFile::load (const String &p_path) {
227
+ Error ConfigFile::load (const String &p_path, bool p_allow_objects ) {
227
228
Error err;
228
229
Ref<FileAccess> f = FileAccess::open (p_path, FileAccess::READ, &err);
229
230
230
231
if (f.is_null ()) {
231
232
return err;
232
233
}
233
234
234
- return _internal_load (p_path, f);
235
+ return _internal_load (p_path, f, p_allow_objects );
235
236
}
236
237
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 ) {
238
239
Error err;
239
240
Ref<FileAccess> f = FileAccess::open (p_path, FileAccess::READ, &err);
240
241
@@ -248,10 +249,10 @@ Error ConfigFile::load_encrypted(const String &p_path, const Vector<uint8_t> &p_
248
249
if (err) {
249
250
return err;
250
251
}
251
- return _internal_load (p_path, fae);
252
+ return _internal_load (p_path, fae, p_allow_objects );
252
253
}
253
254
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 ) {
255
256
Error err;
256
257
Ref<FileAccess> f = FileAccess::open (p_path, FileAccess::READ, &err);
257
258
@@ -266,25 +267,25 @@ Error ConfigFile::load_encrypted_pass(const String &p_path, const String &p_pass
266
267
return err;
267
268
}
268
269
269
- return _internal_load (p_path, fae);
270
+ return _internal_load (p_path, fae, p_allow_objects );
270
271
}
271
272
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 ) {
273
274
VariantParser::StreamFile stream;
274
275
stream.f = f;
275
276
276
- Error err = _parse (p_path, &stream);
277
+ Error err = _parse (p_path, &stream, p_allow_objects );
277
278
278
279
return err;
279
280
}
280
281
281
- Error ConfigFile::parse (const String &p_data) {
282
+ Error ConfigFile::parse (const String &p_data, bool p_allow_objects ) {
282
283
VariantParser::StreamString stream;
283
284
stream.s = p_data;
284
- return _parse (" <string>" , &stream);
285
+ return _parse (" <string>" , &stream, p_allow_objects );
285
286
}
286
287
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 ) {
288
289
String assign;
289
290
Variant value;
290
291
VariantParser::Tag next_tag;
@@ -295,11 +296,12 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream)
295
296
String section;
296
297
297
298
while (true ) {
298
- assign = Variant ();
299
+ assign = String ();
300
+ value = Variant ();
299
301
next_tag.fields .clear ();
300
302
next_tag.name = String ();
301
303
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 );
303
305
if (err == ERR_FILE_EOF) {
304
306
return OK;
305
307
} else if (err != OK) {
@@ -334,19 +336,19 @@ void ConfigFile::_bind_methods() {
334
336
ClassDB::bind_method (D_METHOD (" erase_section" , " section" ), &ConfigFile::erase_section);
335
337
ClassDB::bind_method (D_METHOD (" erase_section_key" , " section" , " key" ), &ConfigFile::erase_section_key);
336
338
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 ) );
340
342
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 ) );
342
344
343
345
BIND_METHOD_ERR_RETURN_DOC (" load" , ERR_FILE_CANT_OPEN);
344
346
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 ) );
347
349
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 ) );
350
352
351
353
ClassDB::bind_method (D_METHOD (" clear" ), &ConfigFile::clear);
352
354
}
0 commit comments