* Check whether a conversion should be done, and based on what old setting information. * * To prevent errors when switching back and forth between older and newer * version of OpenTTD, the type of a setting is never changed. Instead, the * setting is renamed, and this function is used to check whether a conversion * between the old and new setting is required. * * This checks if the new se
| 1345 | * @return Whether upgrading should happen; if false, old_item is a nullptr. |
| 1346 | */ |
| 1347 | bool IsConversionNeeded(const ConfigIniFile &ini, const std::string &group, const std::string &old_var, const std::string &new_var, const IniItem **old_item) |
| 1348 | { |
| 1349 | *old_item = nullptr; |
| 1350 | |
| 1351 | const IniGroup *igroup = ini.GetGroup(group); |
| 1352 | /* If the group doesn't exist, there is nothing to convert. */ |
| 1353 | if (igroup == nullptr) return false; |
| 1354 | |
| 1355 | const IniItem *tmp_old_item = igroup->GetItem(old_var); |
| 1356 | const IniItem *new_item = igroup->GetItem(new_var); |
| 1357 | |
| 1358 | /* If the old item doesn't exist, there is nothing to convert. */ |
| 1359 | if (tmp_old_item == nullptr) return false; |
| 1360 | |
| 1361 | /* If the new item exists, it means conversion was already done. We only |
| 1362 | * do the conversion the first time, and after that these settings are |
| 1363 | * independent. This allows users to freely change between older and |
| 1364 | * newer clients without breaking anything. */ |
| 1365 | if (new_item != nullptr) return false; |
| 1366 | |
| 1367 | *old_item = tmp_old_item; |
| 1368 | return true; |
| 1369 | } |
| 1370 | |
| 1371 | /** |
| 1372 | * Load the values from the configuration files |
no test coverage detected