MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / encode_cfg_to_text

Function encode_cfg_to_text

utility/import_info.cpp:987–1041  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

985}
986
987String encode_cfg_to_text(const Ref<ConfigFileCompat> &cf, int ver_major, int ver_minor, bool gdext = false) {
988 StringBuilder sb;
989 bool first = true;
990 static const String null_replacement = String("\"") + ImportInfo::NULL_REPLACEMENT + "\"";
991 for (const String &section : cf->get_sections()) {
992 if (first) {
993 first = false;
994 } else {
995 sb.append("\n");
996 }
997 if (!section.is_empty()) {
998 sb.append("[" + section + "]\n");
999 if (!gdext) {
1000 sb.append("\n");
1001 }
1002 }
1003
1004 for (const String &key : cf->get_section_keys(section)) {
1005 String vstr;
1006 Variant value = cf->get_value(section, key);
1007 if (gdext && value.get_type() == Variant::DICTIONARY) {
1008 Dictionary dict = value;
1009 LocalVector<Variant> keys = dict.get_key_list();
1010 vstr = "{";
1011 String temp_vstr;
1012 for (size_t i = 0; i < keys.size(); i++) {
1013 const Variant &E = keys[i];
1014 temp_vstr.clear();
1015 VariantWriterCompat::write_to_string(E, temp_vstr, ver_major, ver_minor);
1016 vstr += temp_vstr;
1017 vstr += ": ";
1018 temp_vstr.clear();
1019 VariantWriterCompat::write_to_string(dict[E], temp_vstr, ver_major, ver_minor);
1020 vstr += temp_vstr;
1021 if (i < keys.size() - 1) {
1022 vstr += ", ";
1023 }
1024 }
1025 vstr += "}";
1026 } else {
1027 VariantWriterCompat::write_to_string(value, vstr, ver_major, ver_minor);
1028 }
1029 // ConfigFile interprets setting a key to null as erasing the key, so we have to use a special value that'll get replaced when saving.
1030 if (vstr == null_replacement) {
1031 vstr = "null";
1032 }
1033 sb.append(key.property_name_encode() + (gdext ? " = " : "=") + vstr + "\n");
1034 if (section == "deps" && key == "files") {
1035 // extra newline for some reason
1036 sb.append("\n");
1037 }
1038 }
1039 }
1040 return sb.as_string();
1041}
1042
1043Error ImportInfoModern::save_to(const String &new_import_file) {
1044 Error err = gdre::ensure_dir(new_import_file.get_base_dir());

Callers 2

save_toMethod · 0.85
_get_jsonMethod · 0.85

Calls 6

get_sectionsMethod · 0.80
get_section_keysMethod · 0.80
get_valueMethod · 0.45
get_typeMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected