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

Function LoadFromConfig

src/settings.cpp:1375–1466  ·  view source on GitHub ↗

* Load the values from the configuration files * @param startup Load the minimal amount of the configuration to "bootstrap" the blitter and such. */

Source from the content-addressed store, hash-verified

1373 * @param startup Load the minimal amount of the configuration to "bootstrap" the blitter and such.
1374 */
1375void LoadFromConfig(bool startup)
1376{
1377 ConfigIniFile generic_ini(_config_file);
1378 ConfigIniFile private_ini(_private_file);
1379 ConfigIniFile secrets_ini(_secrets_file);
1380 ConfigIniFile favs_ini(_favs_file);
1381
1382 if (!startup) ResetCurrencies(false); // Initialize the array of currencies, without preserving the custom one
1383
1384 IniFileVersion generic_version = LoadVersionFromConfig(generic_ini);
1385
1386 if (startup) {
1387 GraphicsSetLoadConfig(generic_ini);
1388 }
1389
1390 /* Before the split of private/secrets, we have to look in the generic for these settings. */
1391 if (generic_version < IFV_PRIVATE_SECRETS) {
1392 HandleSettingDescs(generic_ini, generic_ini, generic_ini, IniLoadSettings, IniLoadSettingList, startup);
1393 } else {
1394 HandleSettingDescs(generic_ini, private_ini, secrets_ini, IniLoadSettings, IniLoadSettingList, startup);
1395 }
1396
1397 /* Load basic settings only during bootstrap, load other settings not during bootstrap */
1398 if (!startup) {
1399 if (generic_version < IFV_LINKGRAPH_SECONDS) {
1400 _settings_newgame.linkgraph.recalc_interval *= CalendarTime::SECONDS_PER_DAY;
1401 _settings_newgame.linkgraph.recalc_time *= CalendarTime::SECONDS_PER_DAY;
1402 }
1403
1404 /* Move use_relay_service from generic_ini to private_ini. */
1405 if (generic_version < IFV_NETWORK_PRIVATE_SETTINGS) {
1406 const IniGroup *network = generic_ini.GetGroup("network");
1407 if (network != nullptr) {
1408 const IniItem *use_relay_service = network->GetItem("use_relay_service");
1409 if (use_relay_service != nullptr) {
1410 if (use_relay_service->value == "never") {
1411 _settings_client.network.use_relay_service = UseRelayService::URS_NEVER;
1412 } else if (use_relay_service->value == "ask") {
1413 _settings_client.network.use_relay_service = UseRelayService::URS_ASK;
1414 } else if (use_relay_service->value == "allow") {
1415 _settings_client.network.use_relay_service = UseRelayService::URS_ALLOW;
1416 }
1417 }
1418 }
1419 }
1420
1421 const IniItem *old_item;
1422
1423 if (generic_version < IFV_GAME_TYPE && IsConversionNeeded(generic_ini, "network", "server_advertise", "server_game_type", &old_item)) {
1424 auto old_value = BoolSettingDesc::ParseSingleValue(*old_item->value);
1425 _settings_client.network.server_game_type = old_value.value_or(false) ? SERVER_GAME_TYPE_PUBLIC : SERVER_GAME_TYPE_LOCAL;
1426 }
1427
1428 if (generic_version < IFV_AUTOSAVE_RENAME && IsConversionNeeded(generic_ini, "gui", "autosave", "autosave_interval", &old_item)) {
1429 static constexpr std::initializer_list<std::string_view> _old_autosave_interval{"off"sv, "monthly"sv, "quarterly"sv, "half year"sv, "yearly"sv};
1430 auto old_value = OneOfManySettingDesc::ParseSingleValue(*old_item->value, _old_autosave_interval).value_or(-1);
1431
1432 switch (old_value) {

Callers 3

OnNewGRFsScannedMethod · 0.85
openttd_mainFunction · 0.85
SwitchToModeFunction · 0.85

Calls 15

ResetCurrenciesFunction · 0.85
LoadVersionFromConfigFunction · 0.85
GraphicsSetLoadConfigFunction · 0.85
HandleSettingDescsFunction · 0.85
IsConversionNeededFunction · 0.85
GRFLoadConfigFunction · 0.85
AILoadConfigFunction · 0.85
GameLoadConfigFunction · 0.85
PickerLoadConfigFunction · 0.85
BadgeClassLoadConfigFunction · 0.85
PrepareOldDiffCustomFunction · 0.85
IniLoadSettingsFunction · 0.85

Tested by

no test coverage detected