MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / SaveToConfig

Function SaveToConfig

src/settings.cpp:1469–1538  ·  view source on GitHub ↗

Save the values to the configuration file */

Source from the content-addressed store, hash-verified

1467
1468/** Save the values to the configuration file */
1469void SaveToConfig()
1470{
1471 ConfigIniFile generic_ini(_config_file);
1472 ConfigIniFile private_ini(_private_file);
1473 ConfigIniFile secrets_ini(_secrets_file);
1474 ConfigIniFile favs_ini(_favs_file);
1475
1476 IniFileVersion generic_version = LoadVersionFromConfig(generic_ini);
1477
1478 /* If we newly create the private/secrets file, add a dummy group on top
1479 * just so we can add a comment before it (that is how IniFile works).
1480 * This to explain what the file is about. After doing it once, never touch
1481 * it again, as otherwise we might be reverting user changes. */
1482 if (IniGroup *group = private_ini.GetGroup("private"); group != nullptr) group->comment = "; This file possibly contains private information which can identify you as person.\n";
1483 if (IniGroup *group = secrets_ini.GetGroup("secrets"); group != nullptr) group->comment = "; Do not share this file with others, not even if they claim to be technical support.\n; This file contains saved passwords and other secrets that should remain private to you!\n";
1484
1485 if (generic_version == IFV_0) {
1486 /* Remove some obsolete groups. These have all been loaded into other groups. */
1487 generic_ini.RemoveGroup("patches");
1488 generic_ini.RemoveGroup("yapf");
1489 generic_ini.RemoveGroup("gameopt");
1490
1491 /* Remove all settings from the generic ini that are now in the private ini. */
1492 generic_ini.RemoveGroup("server_bind_addresses");
1493 generic_ini.RemoveGroup("servers");
1494 generic_ini.RemoveGroup("bans");
1495 for (auto &table : PrivateSettingTables()) {
1496 RemoveEntriesFromIni(generic_ini, table);
1497 }
1498
1499 /* Remove all settings from the generic ini that are now in the secrets ini. */
1500 for (auto &table : SecretSettingTables()) {
1501 RemoveEntriesFromIni(generic_ini, table);
1502 }
1503 }
1504
1505 if (generic_version < IFV_REMOVE_GENERATION_SEED) {
1506 IniGroup *game_creation = generic_ini.GetGroup("game_creation");
1507 if (game_creation != nullptr) {
1508 game_creation->RemoveItem("generation_seed");
1509 }
1510 }
1511
1512 /* These variables are migrated from generic ini to private ini now. */
1513 if (generic_version < IFV_NETWORK_PRIVATE_SETTINGS) {
1514 IniGroup *network = generic_ini.GetGroup("network");
1515 if (network != nullptr) {
1516 network->RemoveItem("use_relay_service");
1517 }
1518 }
1519
1520 HandleSettingDescs(generic_ini, private_ini, secrets_ini, IniSaveSettings, IniSaveSettingList);
1521 GraphicsSetSaveConfig(generic_ini);
1522 GRFSaveConfig(generic_ini, "newgrf", _grfconfig_newgame);
1523 GRFSaveConfig(generic_ini, "newgrf-static", _grfconfig_static);
1524 AISaveConfig(generic_ini, "ai_players");
1525 GameSaveConfig(generic_ini, "game_scripts");
1526 PickerSaveConfig(favs_ini);

Callers 4

ChangeValueMethod · 0.85
PostMainLoopFunction · 0.85
SetFontFunction · 0.85
ConSaveConfigFunction · 0.85

Calls 14

LoadVersionFromConfigFunction · 0.85
RemoveEntriesFromIniFunction · 0.85
HandleSettingDescsFunction · 0.85
GraphicsSetSaveConfigFunction · 0.85
GRFSaveConfigFunction · 0.85
AISaveConfigFunction · 0.85
GameSaveConfigFunction · 0.85
PickerSaveConfigFunction · 0.85
BadgeClassSaveConfigFunction · 0.85
SaveVersionInConfigFunction · 0.85
GetGroupMethod · 0.80
RemoveGroupMethod · 0.80

Tested by

no test coverage detected