Reduce the indentation level of MapINIToRealLocation

This commit is contained in:
JosJuice 2017-12-23 18:23:31 +01:00
parent 3eeab02ee2
commit 5296ee6d3d

View File

@ -138,34 +138,32 @@ static ConfigLocation MapINIToRealLocation(const std::string& section, const std
static const INIToLocationMap& ini_to_location = GetINIToLocationMap(); static const INIToLocationMap& ini_to_location = GetINIToLocationMap();
auto it = ini_to_location.find({section, key}); auto it = ini_to_location.find({section, key});
if (it == ini_to_location.end()) if (it != ini_to_location.end())
{ return it->second;
// Try again, but this time with an empty key
// Certain sections like 'Speedhacks' has keys that are variable
it = ini_to_location.find({section, ""});
if (it != ini_to_location.end())
return {it->second.system, it->second.section, key};
// Attempt to load it as a configuration option // Try again, but this time with an empty key
// It will be in the format of '<System>.<Section>' // Certain sections like 'Speedhacks' has keys that are variable
std::istringstream buffer(section); it = ini_to_location.find({section, ""});
std::string system_str, config_section; if (it != ini_to_location.end())
return {it->second.system, it->second.section, key};
bool fail = false; // Attempt to load it as a configuration option
std::getline(buffer, system_str, '.'); // It will be in the format of '<System>.<Section>'
fail |= buffer.fail(); std::istringstream buffer(section);
std::getline(buffer, config_section, '.'); std::string system_str, config_section;
fail |= buffer.fail();
const std::optional<Config::System> system = Config::GetSystemFromName(system_str); bool fail = false;
if (!fail && system) std::getline(buffer, system_str, '.');
return {*system, config_section, key}; fail |= buffer.fail();
std::getline(buffer, config_section, '.');
fail |= buffer.fail();
WARN_LOG(CORE, "Unknown game INI option in section %s: %s", section.c_str(), key.c_str()); const std::optional<Config::System> system = Config::GetSystemFromName(system_str);
return {Config::System::Main, "", ""}; if (!fail && system)
} return {*system, config_section, key};
return ini_to_location.at({section, key}); WARN_LOG(CORE, "Unknown game INI option in section %s: %s", section.c_str(), key.c_str());
return {Config::System::Main, "", ""};
} }
static std::pair<std::string, std::string> GetINILocationFromConfig(const ConfigLocation& location) static std::pair<std::string, std::string> GetINILocationFromConfig(const ConfigLocation& location)