mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-29 04:08:55 +00:00
Config: Handle unknown system strings better
Currently, a simple typo in the system name will trigger an assert message that complains about a "programming error". This is not user friendly and misleading. So this changes GetSystemFromName to return an std::optional, which allows for callers to check whether the system exists and handle failures better.
This commit is contained in:
parent
653977cec7
commit
05c8d229af
4 changed files with 14 additions and 8 deletions
|
@ -101,15 +101,14 @@ const std::string& GetSystemName(System system)
|
|||
return system_to_name.at(system);
|
||||
}
|
||||
|
||||
System GetSystemFromName(const std::string& name)
|
||||
std::optional<System> GetSystemFromName(const std::string& name)
|
||||
{
|
||||
const auto system = std::find_if(system_to_name.begin(), system_to_name.end(),
|
||||
[&name](const auto& entry) { return entry.second == name; });
|
||||
if (system != system_to_name.end())
|
||||
return system->first;
|
||||
|
||||
_assert_msg_(COMMON, false, "Programming error! Couldn't convert '%s' to system!", name.c_str());
|
||||
return System::Main;
|
||||
return {};
|
||||
}
|
||||
|
||||
const std::string& GetLayerName(LayerType layer)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue