// Converts from a legacy GameINI section-key tuple to a ConfigLocation.
// Also supports the following format:
// [System.Section]
// Key = Value
static ConfigLocation MapINIToRealLocation(const std::string& section, const std::string& key)
{
  static const INIToLocationMap& ini_to_location = GetINIToLocationMap();
  const auto it = ini_to_location.find({section, key});
  if (it != ini_to_location.end())
    return it->second;

  static const INIToSectionMap& ini_to_section = GetINIToSectionMap();
  const auto it2 = ini_to_section.find(section);
  if (it2 != ini_to_section.end())
    return {it2->second.first, it2->second.second, key};

  // Attempt to load it as a configuration option
  // It will be in the format of '<System>.<Section>'
  std::istringstream buffer(section);
  std::string system_str, config_section;

  bool fail = false;
  std::getline(buffer, system_str, '.');
  fail |= buffer.fail();
  std::getline(buffer, config_section, '.');
  fail |= buffer.fail();

  const std::optional<Config::System> system = Config::GetSystemFromName(system_str);
  if (!fail && system)
    return {*system, config_section, key};

  WARN_LOG(CORE, "Unknown game INI option in section %s: %s", section.c_str(), key.c_str());
  return {Config::System::Main, "", ""};
}
示例#2
0
// Converts from a legacy GameINI section-key tuple to a ConfigLocation.
// Also supports the following format:
// [System.Section]
// Key = Value
static ConfigLocation MapINIToRealLocation(const std::string& section, const std::string& key)
{
  static const INIToLocationMap& ini_to_location = GetINIToLocationMap();

  auto it = ini_to_location.find({section, key});
  if (it == ini_to_location.end())
  {
    // 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
    // It will be in the format of '<System>.<Section>'
    std::istringstream buffer(section);
    std::string system_str, config_section;

    bool fail = false;
    std::getline(buffer, system_str, '.');
    fail |= buffer.fail();
    std::getline(buffer, config_section, '.');
    fail |= buffer.fail();

    if (!fail)
      return {Config::GetSystemFromName(system_str), config_section, key};

    WARN_LOG(CORE, "Unknown game INI option in section %s: %s", section.c_str(), key.c_str());
    return {Config::System::Main, "", ""};
  }

  return ini_to_location.at({section, key});
}
static std::pair<std::string, std::string> GetINILocationFromConfig(const ConfigLocation& location)
{
  static const INIToLocationMap& ini_to_location = GetINIToLocationMap();
  const auto it = std::find_if(ini_to_location.begin(), ini_to_location.end(),
                               [&location](const auto& entry) { return entry.second == location; });
  if (it != ini_to_location.end())
    return it->first;

  static const INIToSectionMap& ini_to_section = GetINIToSectionMap();
  const auto it2 =
      std::find_if(ini_to_section.begin(), ini_to_section.end(), [&location](const auto& entry) {
        return entry.second.first == location.system && entry.second.second == location.section;
      });
  if (it2 != ini_to_section.end())
    return {it2->first, location.key};

  return {Config::GetSystemName(location.system) + "." + location.section, location.key};
}
示例#4
0
static std::pair<std::string, std::string> GetINILocationFromConfig(const ConfigLocation& location)
{
  static const INIToLocationMap& ini_to_location = GetINIToLocationMap();

  auto it = std::find_if(ini_to_location.begin(), ini_to_location.end(),
                         [&location](const auto& entry) { return entry.second == location; });

  if (it != ini_to_location.end())
    return it->first;

  // Try again, but this time with an empty key
  // Certain sections like 'Speedhacks' have keys that are variable
  it = std::find_if(ini_to_location.begin(), ini_to_location.end(), [&location](const auto& entry) {
    return std::tie(entry.second.system, entry.second.section) ==
           std::tie(location.system, location.section);
  });
  if (it != ini_to_location.end())
    return {it->first.first, location.key};

  return {Config::GetSystemName(location.system) + "." + location.section, location.key};
}