mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 15:09:39 +00:00
Revert to 0.45.0 comments-in-the-middle settings behavior
This commit is contained in:
parent
9f039fac87
commit
f7d2cdb782
2 changed files with 22 additions and 49 deletions
|
@ -1,8 +1,8 @@
|
||||||
#include "fallback.hpp"
|
#include "fallback.hpp"
|
||||||
|
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <sstream>
|
||||||
|
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <components/debug/debuglog.hpp>
|
||||||
|
|
||||||
namespace Fallback
|
namespace Fallback
|
||||||
{
|
{
|
||||||
|
@ -28,16 +28,10 @@ namespace Fallback
|
||||||
const std::string& fallback = getString(fall);
|
const std::string& fallback = getString(fall);
|
||||||
if (!fallback.empty())
|
if (!fallback.empty())
|
||||||
{
|
{
|
||||||
try
|
std::stringstream stream(fallback);
|
||||||
{
|
float number = 0.f;
|
||||||
// We have to rely on Boost because std::stof from C++11 uses the current locale
|
stream >> number;
|
||||||
// for separators (which is undesired) and it often silently ignores parsing errors.
|
return number;
|
||||||
return boost::lexical_cast<float>(fallback);
|
|
||||||
}
|
|
||||||
catch (boost::bad_lexical_cast&)
|
|
||||||
{
|
|
||||||
Log(Debug::Error) << "Error: '" << fall << "' setting value (" << fallback << ") is not a valid number, using 0 as a fallback";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -48,18 +42,10 @@ namespace Fallback
|
||||||
const std::string& fallback = getString(fall);
|
const std::string& fallback = getString(fall);
|
||||||
if (!fallback.empty())
|
if (!fallback.empty())
|
||||||
{
|
{
|
||||||
try
|
std::stringstream stream(fallback);
|
||||||
{
|
int number = 0;
|
||||||
return std::stoi(fallback);
|
stream >> number;
|
||||||
}
|
return number;
|
||||||
catch (const std::invalid_argument&)
|
|
||||||
{
|
|
||||||
Log(Debug::Error) << "Error: '" << fall << "' setting value (" << fallback << ") is not a valid number, using 0 as a fallback";
|
|
||||||
}
|
|
||||||
catch (const std::out_of_range&)
|
|
||||||
{
|
|
||||||
Log(Debug::Error) << "Error: '" << fall << "' setting value (" << fallback << ") is out of range, using 0 as a fallback";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
#include "settings.hpp"
|
#include "settings.hpp"
|
||||||
#include "parser.hpp"
|
#include "parser.hpp"
|
||||||
|
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <sstream>
|
||||||
#include <components/misc/stringops.hpp>
|
|
||||||
|
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <components/misc/stringops.hpp>
|
||||||
|
|
||||||
namespace Settings
|
namespace Settings
|
||||||
{
|
{
|
||||||
|
@ -55,32 +54,20 @@ std::string Manager::getString(const std::string &setting, const std::string &ca
|
||||||
|
|
||||||
float Manager::getFloat (const std::string& setting, const std::string& category)
|
float Manager::getFloat (const std::string& setting, const std::string& category)
|
||||||
{
|
{
|
||||||
const std::string value = getString(setting, category);
|
const std::string& value = getString(setting, category);
|
||||||
try
|
std::stringstream stream(value);
|
||||||
{
|
float number = 0.f;
|
||||||
// We have to rely on Boost because std::stof from C++11 uses the current locale
|
stream >> number;
|
||||||
// for separators (which is undesired) and it often silently ignores parsing errors.
|
return number;
|
||||||
return boost::lexical_cast<float>(value);
|
|
||||||
}
|
|
||||||
catch (boost::bad_lexical_cast&)
|
|
||||||
{
|
|
||||||
Log(Debug::Warning) << "Cannot parse setting '" << setting << "' (invalid setting value: " << value << ").";
|
|
||||||
return 0.f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Manager::getInt (const std::string& setting, const std::string& category)
|
int Manager::getInt (const std::string& setting, const std::string& category)
|
||||||
{
|
{
|
||||||
const std::string value = getString(setting, category);
|
const std::string& value = getString(setting, category);
|
||||||
try
|
std::stringstream stream(value);
|
||||||
{
|
int number = 0;
|
||||||
return std::stoi(value);
|
stream >> number;
|
||||||
}
|
return number;
|
||||||
catch(const std::exception& e)
|
|
||||||
{
|
|
||||||
Log(Debug::Warning) << "Cannot parse setting '" << setting << "' (invalid setting value: " << value << ").";
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::getBool (const std::string& setting, const std::string& category)
|
bool Manager::getBool (const std::string& setting, const std::string& category)
|
||||||
|
|
Loading…
Reference in a new issue