Fix implicit bool casts in CSettings

master
Piotr Dziwinski 2015-08-15 18:26:27 +02:00
parent a082d21f95
commit f773d5714d
3 changed files with 105 additions and 104 deletions

View File

@ -155,12 +155,12 @@ bool CConfigFile::SetStringProperty(std::string section, std::string key, std::s
return true; return true;
} }
bool CConfigFile::GetStringProperty(std::string section, std::string key, std::string &value)
bool CConfigFile::GetStringProperty(std::string section, std::string key, std::string &buffer)
{ {
try try
{ {
buffer = m_propertyTree.get<std::string>(section + "." + key); std::string readValue = m_propertyTree.get<std::string>(section + "." + key);
value = std::move(readValue);
} }
catch (std::exception & e) catch (std::exception & e)
{ {
@ -177,7 +177,6 @@ bool CConfigFile::GetStringProperty(std::string section, std::string key, std::s
return true; return true;
} }
bool CConfigFile::SetIntProperty(std::string section, std::string key, int value) bool CConfigFile::SetIntProperty(std::string section, std::string key, int value)
{ {
try try
@ -193,12 +192,12 @@ bool CConfigFile::SetIntProperty(std::string section, std::string key, int value
return true; return true;
} }
bool CConfigFile::GetIntProperty(std::string section, std::string key, int &value) bool CConfigFile::GetIntProperty(std::string section, std::string key, int &value)
{ {
try try
{ {
value = m_propertyTree.get<int>(section + "." + key); int readValue = m_propertyTree.get<int>(section + "." + key);
value = readValue;
} }
catch (std::exception & e) catch (std::exception & e)
{ {
@ -215,6 +214,21 @@ bool CConfigFile::GetIntProperty(std::string section, std::string key, int &valu
return true; return true;
} }
bool CConfigFile::SetBoolProperty(std::string section, std::string key, bool value)
{
return SetIntProperty(section, key, value ? 1 : 0);
}
bool CConfigFile::GetBoolProperty(std::string section, std::string key, bool& value)
{
int intValue = 0;
bool result = GetIntProperty(section, key, intValue);
if (result)
{
value = intValue == 1;
}
return result;
}
bool CConfigFile::SetFloatProperty(std::string section, std::string key, float value) bool CConfigFile::SetFloatProperty(std::string section, std::string key, float value)
{ {
@ -231,12 +245,12 @@ bool CConfigFile::SetFloatProperty(std::string section, std::string key, float v
return true; return true;
} }
bool CConfigFile::GetFloatProperty(std::string section, std::string key, float &value) bool CConfigFile::GetFloatProperty(std::string section, std::string key, float &value)
{ {
try try
{ {
value = m_propertyTree.get<float>(section + "." + key); float readValue = m_propertyTree.get<float>(section + "." + key);
value = readValue;
} }
catch (std::exception & e) catch (std::exception & e)
{ {

View File

@ -57,53 +57,49 @@ public:
bool Save(); bool Save();
/** Sets string value in section under specified key /** Sets string value in section under specified key
* \param section
* \param key
* \param value
* \return return true on success * \return return true on success
*/ */
bool SetStringProperty(std::string section, std::string key, std::string value); bool SetStringProperty(std::string section, std::string key, std::string value);
/** Gets string value in section under specified key /** Gets string value in section under specified key
* \param section
* \param key
* \param buffer
* \return return true on success * \return return true on success
*/ */
bool GetStringProperty(std::string section, std::string key, std::string& buffer); bool GetStringProperty(std::string section, std::string key, std::string& value);
/** Sets int value in section under specified key /** Sets int value in section under specified key
* \param section
* \param key
* \param value
* \return return true on success * \return return true on success
*/ */
bool SetIntProperty(std::string section, std::string key, int value); bool SetIntProperty(std::string section, std::string key, int value);
/** Sets bool value in section under specified key
* \return return true on success
*/
bool SetBoolProperty(std::string section, std::string key, bool value);
/** Gets int value in section under specified key /** Gets int value in section under specified key
* \param section * \a value will only be changed if key exists
* \param key
* \param value
* \return return true on success * \return return true on success
*/ */
bool GetIntProperty(std::string section, std::string key, int &value); bool GetIntProperty(std::string section, std::string key, int &value);
/** Sets float value in section under specified key /** Sets float value in section under specified key
* \param section * \a value will only be changed if key exists
* \param key
* \param value
* \return return true on success * \return return true on success
*/ */
bool SetFloatProperty(std::string section, std::string key, float value); bool SetFloatProperty(std::string section, std::string key, float value);
/** Gets float value in section under specified key /** Gets float value in section under specified key
* \param section * \a value will only be changed if key exists
* \param key
* \param value
* \return return true on success * \return return true on success
*/ */
bool GetFloatProperty(std::string section, std::string key, float &value); bool GetFloatProperty(std::string section, std::string key, float &value);
/** Gets bool value in section under specified key
* \a value will only be changed if key exists
* \return return true on success
*/
bool GetBoolProperty(std::string section, std::string key, bool &value);
private: private:
boost::property_tree::ptree m_propertyTree; boost::property_tree::ptree m_propertyTree;
bool m_needsSave; bool m_needsSave;

View File

@ -56,7 +56,7 @@ void CSettings::SaveResolutionSettings(const Gfx::DeviceConfig& config)
std::ostringstream ss; std::ostringstream ss;
ss << config.size.x << "x" << config.size.y; ss << config.size.x << "x" << config.size.y;
GetConfigFile().SetStringProperty("Setup", "Resolution", ss.str()); GetConfigFile().SetStringProperty("Setup", "Resolution", ss.str());
GetConfigFile().SetIntProperty("Setup", "Fullscreen", config.fullScreen); GetConfigFile().SetBoolProperty("Setup", "Fullscreen", config.fullScreen);
GetConfigFile().Save(); GetConfigFile().Save();
} }
@ -68,30 +68,30 @@ void CSettings::SaveSettings()
Gfx::CCamera* camera = main->GetCamera(); Gfx::CCamera* camera = main->GetCamera();
CSoundInterface* sound = app->GetSound(); CSoundInterface* sound = app->GetSound();
GetConfigFile().SetIntProperty("Setup", "Tooltips", m_tooltips); GetConfigFile().SetBoolProperty("Setup", "Tooltips", m_tooltips);
GetConfigFile().SetIntProperty("Setup", "InterfaceGlint", m_interfaceGlint); GetConfigFile().SetBoolProperty("Setup", "InterfaceGlint", m_interfaceGlint);
GetConfigFile().SetIntProperty("Setup", "InterfaceRain", m_interfaceRain); GetConfigFile().SetBoolProperty("Setup", "InterfaceRain", m_interfaceRain);
GetConfigFile().SetIntProperty("Setup", "Soluce4", m_soluce4); GetConfigFile().SetBoolProperty("Setup", "Soluce4", m_soluce4);
GetConfigFile().SetIntProperty("Setup", "Movies", m_movies); GetConfigFile().SetBoolProperty("Setup", "Movies", m_movies);
GetConfigFile().SetIntProperty("Setup", "CameraScroll", camera->GetCameraScroll()); GetConfigFile().SetBoolProperty("Setup", "CameraScroll", camera->GetCameraScroll());
GetConfigFile().SetIntProperty("Setup", "CameraInvertX", camera->GetCameraInvertX()); GetConfigFile().SetBoolProperty("Setup", "CameraInvertX", camera->GetCameraInvertX());
GetConfigFile().SetIntProperty("Setup", "CameraInvertY", camera->GetCameraInvertY()); GetConfigFile().SetBoolProperty("Setup", "CameraInvertY", camera->GetCameraInvertY());
GetConfigFile().SetIntProperty("Setup", "InterfaceEffect", camera->GetEffect()); GetConfigFile().SetBoolProperty("Setup", "InterfaceEffect", camera->GetEffect());
GetConfigFile().SetIntProperty("Setup", "Blood", camera->GetBlood()); GetConfigFile().SetBoolProperty("Setup", "Blood", camera->GetBlood());
GetConfigFile().SetIntProperty("Setup", "Autosave", main->GetAutosave()); GetConfigFile().SetBoolProperty("Setup", "Autosave", main->GetAutosave());
GetConfigFile().SetIntProperty("Setup", "AutosaveInterval", main->GetAutosaveInterval()); GetConfigFile().SetIntProperty("Setup", "AutosaveInterval", main->GetAutosaveInterval());
GetConfigFile().SetIntProperty("Setup", "AutosaveSlots", main->GetAutosaveSlots()); GetConfigFile().SetIntProperty("Setup", "AutosaveSlots", main->GetAutosaveSlots());
GetConfigFile().SetIntProperty("Setup", "ObjectDirty", engine->GetDirty()); GetConfigFile().SetBoolProperty("Setup", "ObjectDirty", engine->GetDirty());
GetConfigFile().SetIntProperty("Setup", "FogMode", engine->GetFog()); GetConfigFile().SetBoolProperty("Setup", "FogMode", engine->GetFog());
GetConfigFile().SetIntProperty("Setup", "LightMode", engine->GetLightMode()); GetConfigFile().SetBoolProperty("Setup", "LightMode", engine->GetLightMode());
GetConfigFile().SetIntProperty("Setup", "UseJoystick", app->GetJoystickEnabled() ? app->GetJoystick().index : -1); GetConfigFile().SetIntProperty("Setup", "UseJoystick", app->GetJoystickEnabled() ? app->GetJoystick().index : -1);
GetConfigFile().SetFloatProperty("Setup", "ParticleDensity", engine->GetParticleDensity()); GetConfigFile().SetFloatProperty("Setup", "ParticleDensity", engine->GetParticleDensity());
GetConfigFile().SetFloatProperty("Setup", "ClippingDistance", engine->GetClippingDistance()); GetConfigFile().SetFloatProperty("Setup", "ClippingDistance", engine->GetClippingDistance());
GetConfigFile().SetIntProperty("Setup", "AudioVolume", sound->GetAudioVolume()); GetConfigFile().SetIntProperty("Setup", "AudioVolume", sound->GetAudioVolume());
GetConfigFile().SetIntProperty("Setup", "MusicVolume", sound->GetMusicVolume()); GetConfigFile().SetIntProperty("Setup", "MusicVolume", sound->GetMusicVolume());
GetConfigFile().SetIntProperty("Setup", "EditIndentMode", engine->GetEditIndentMode()); GetConfigFile().SetBoolProperty("Setup", "EditIndentMode", engine->GetEditIndentMode());
GetConfigFile().SetIntProperty("Setup", "EditIndentValue", engine->GetEditIndentValue()); GetConfigFile().SetIntProperty("Setup", "EditIndentValue", engine->GetEditIndentValue());
GetConfigFile().SetIntProperty("Setup", "SystemMouse", m_systemMouse); GetConfigFile().SetBoolProperty("Setup", "SystemMouse", m_systemMouse);
GetConfigFile().SetIntProperty("Setup", "MipmapLevel", engine->GetTextureMipmapLevel()); GetConfigFile().SetIntProperty("Setup", "MipmapLevel", engine->GetTextureMipmapLevel());
GetConfigFile().SetIntProperty("Setup", "Anisotropy", engine->GetTextureAnisotropyLevel()); GetConfigFile().SetIntProperty("Setup", "Anisotropy", engine->GetTextureAnisotropyLevel());
@ -99,9 +99,10 @@ void CSettings::SaveSettings()
GetConfigFile().SetFloatProperty("Setup", "ShadowRange", engine->GetShadowRange()); GetConfigFile().SetFloatProperty("Setup", "ShadowRange", engine->GetShadowRange());
GetConfigFile().SetIntProperty("Setup", "MSAA", engine->GetMultiSample()); GetConfigFile().SetIntProperty("Setup", "MSAA", engine->GetMultiSample());
GetConfigFile().SetIntProperty("Setup", "FilterMode", engine->GetTextureFilterMode()); GetConfigFile().SetIntProperty("Setup", "FilterMode", engine->GetTextureFilterMode());
GetConfigFile().SetIntProperty("Setup", "ShadowMapping", engine->GetShadowMapping()); GetConfigFile().SetBoolProperty("Setup", "ShadowMapping", engine->GetShadowMapping());
GetConfigFile().SetIntProperty("Setup", "ShadowMappingQuality", engine->GetShadowMappingQuality()); GetConfigFile().SetBoolProperty("Setup", "ShadowMappingQuality", engine->GetShadowMappingQuality());
GetConfigFile().SetIntProperty("Setup", "ShadowMappingResolution", engine->GetShadowMappingOffscreen() ? engine->GetShadowMappingOffscreenResolution() : 0); GetConfigFile().SetIntProperty("Setup", "ShadowMappingResolution",
engine->GetShadowMappingOffscreen() ? engine->GetShadowMappingOffscreenResolution() : 0);
CInput::GetInstancePointer()->SaveKeyBindings(); CInput::GetInstancePointer()->SaveKeyBindings();
@ -112,7 +113,7 @@ void CSettings::SaveSettings()
GetConfigFile().SetFloatProperty("Edit", "WindowPosY", m_windowPos.y); GetConfigFile().SetFloatProperty("Edit", "WindowPosY", m_windowPos.y);
GetConfigFile().SetFloatProperty("Edit", "WindowDimX", m_windowDim.x); GetConfigFile().SetFloatProperty("Edit", "WindowDimX", m_windowDim.x);
GetConfigFile().SetFloatProperty("Edit", "WindowDimY", m_windowDim.y); GetConfigFile().SetFloatProperty("Edit", "WindowDimY", m_windowDim.y);
GetConfigFile().SetIntProperty("Edit", "IOPublic", m_IOPublic); GetConfigFile().SetBoolProperty("Edit", "IOPublic", m_IOPublic);
GetConfigFile().SetFloatProperty("Edit", "IOPosX", m_IOPos.x); GetConfigFile().SetFloatProperty("Edit", "IOPosX", m_IOPos.x);
GetConfigFile().SetFloatProperty("Edit", "IOPosY", m_IOPos.y); GetConfigFile().SetFloatProperty("Edit", "IOPosY", m_IOPos.y);
GetConfigFile().SetFloatProperty("Edit", "IODimX", m_IODim.x); GetConfigFile().SetFloatProperty("Edit", "IODimX", m_IODim.x);
@ -130,42 +131,33 @@ void CSettings::LoadSettings()
Gfx::CCamera* camera = main->GetCamera(); Gfx::CCamera* camera = main->GetCamera();
CSoundInterface* sound = app->GetSound(); CSoundInterface* sound = app->GetSound();
float fValue; int iValue = 0;
int iValue; float fValue = 0.0f;
std::string key; bool bValue = false;
if (GetConfigFile().GetIntProperty("Setup", "Tooltips", iValue)) GetConfigFile().GetBoolProperty("Setup", "Tooltips", m_tooltips);
m_tooltips = iValue; GetConfigFile().GetBoolProperty("Setup", "InterfaceGlint", m_interfaceGlint);
GetConfigFile().GetBoolProperty("Setup", "InterfaceRain", m_interfaceRain);
GetConfigFile().GetBoolProperty("Setup", "Soluce4", m_soluce4);
GetConfigFile().GetBoolProperty("Setup", "Movies", m_movies);
if (GetConfigFile().GetIntProperty("Setup", "InterfaceGlint", iValue)) if (GetConfigFile().GetBoolProperty("Setup", "CameraScroll", bValue))
m_interfaceGlint = iValue; camera->SetCameraScroll(bValue);
if (GetConfigFile().GetIntProperty("Setup", "InterfaceRain", iValue)) if (GetConfigFile().GetBoolProperty("Setup", "CameraInvertX", bValue))
m_interfaceRain = iValue; camera->SetCameraInvertX(bValue);
if (GetConfigFile().GetIntProperty("Setup", "Soluce4", iValue)) if (GetConfigFile().GetBoolProperty("Setup", "CameraInvertY", bValue))
m_soluce4 = iValue; camera->SetCameraInvertY(bValue);
if (GetConfigFile().GetIntProperty("Setup", "Movies", iValue)) if (GetConfigFile().GetBoolProperty("Setup", "InterfaceEffect", bValue))
m_movies = iValue; camera->SetEffect(bValue);
if (GetConfigFile().GetIntProperty("Setup", "CameraScroll", iValue)) if (GetConfigFile().GetBoolProperty("Setup", "Blood", bValue))
camera->SetCameraScroll(iValue); camera->SetBlood(bValue);
if (GetConfigFile().GetIntProperty("Setup", "CameraInvertX", iValue)) if (GetConfigFile().GetBoolProperty("Setup", "Autosave", bValue))
camera->SetCameraInvertX(iValue); main->SetAutosave(bValue);
if (GetConfigFile().GetIntProperty("Setup", "CameraInvertY", iValue))
camera->SetCameraInvertY(iValue);
if (GetConfigFile().GetIntProperty("Setup", "InterfaceEffect", iValue))
camera->SetEffect(iValue);
if (GetConfigFile().GetIntProperty("Setup", "Blood", iValue))
camera->SetBlood(iValue);
if (GetConfigFile().GetIntProperty("Setup", "Autosave", iValue))
main->SetAutosave(iValue);
if (GetConfigFile().GetIntProperty("Setup", "AutosaveInterval", iValue)) if (GetConfigFile().GetIntProperty("Setup", "AutosaveInterval", iValue))
main->SetAutosaveInterval(iValue); main->SetAutosaveInterval(iValue);
@ -173,17 +165,17 @@ void CSettings::LoadSettings()
if (GetConfigFile().GetIntProperty("Setup", "AutosaveSlots", iValue)) if (GetConfigFile().GetIntProperty("Setup", "AutosaveSlots", iValue))
main->SetAutosaveSlots(iValue); main->SetAutosaveSlots(iValue);
if (GetConfigFile().GetIntProperty("Setup", "ObjectDirty", iValue)) if (GetConfigFile().GetBoolProperty("Setup", "ObjectDirty", bValue))
engine->SetDirty(iValue); engine->SetDirty(bValue);
if (GetConfigFile().GetIntProperty("Setup", "FogMode", iValue)) if (GetConfigFile().GetBoolProperty("Setup", "FogMode", bValue))
{ {
engine->SetFog(iValue); engine->SetFog(bValue);
camera->SetOverBaseColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)); // TODO: color ok? camera->SetOverBaseColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)); // TODO: color ok?
} }
if (GetConfigFile().GetIntProperty("Setup", "LightMode", iValue)) if (GetConfigFile().GetBoolProperty("Setup", "LightMode", bValue))
engine->SetLightMode(iValue); engine->SetLightMode(bValue);
if (GetConfigFile().GetIntProperty("Setup", "UseJoystick", iValue)) if (GetConfigFile().GetIntProperty("Setup", "UseJoystick", iValue))
{ {
@ -217,15 +209,14 @@ void CSettings::LoadSettings()
if (GetConfigFile().GetIntProperty("Setup", "MusicVolume", iValue)) if (GetConfigFile().GetIntProperty("Setup", "MusicVolume", iValue))
sound->SetMusicVolume(iValue); sound->SetMusicVolume(iValue);
if (GetConfigFile().GetIntProperty("Setup", "EditIndentMode", iValue)) if (GetConfigFile().GetBoolProperty("Setup", "EditIndentMode", bValue))
engine->SetEditIndentMode(iValue); engine->SetEditIndentMode(bValue);
if (GetConfigFile().GetIntProperty("Setup", "EditIndentValue", iValue)) if (GetConfigFile().GetIntProperty("Setup", "EditIndentValue", iValue))
engine->SetEditIndentValue(iValue); engine->SetEditIndentValue(iValue);
if (GetConfigFile().GetIntProperty("Setup", "SystemMouse", iValue)) if (GetConfigFile().GetBoolProperty("Setup", "SystemMouse", m_systemMouse))
{ {
m_systemMouse = iValue;
app->SetMouseMode(m_systemMouse ? MOUSE_SYSTEM : MOUSE_ENGINE); app->SetMouseMode(m_systemMouse ? MOUSE_SYSTEM : MOUSE_ENGINE);
} }
@ -248,11 +239,11 @@ void CSettings::LoadSettings()
if (GetConfigFile().GetIntProperty("Setup", "FilterMode", iValue)) if (GetConfigFile().GetIntProperty("Setup", "FilterMode", iValue))
engine->SetTextureFilterMode(static_cast<Gfx::TexFilter>(iValue)); engine->SetTextureFilterMode(static_cast<Gfx::TexFilter>(iValue));
if (GetConfigFile().GetIntProperty("Setup", "ShadowMapping", iValue)) if (GetConfigFile().GetBoolProperty("Setup", "ShadowMapping", bValue))
engine->SetShadowMapping(iValue); engine->SetShadowMapping(bValue);
if (GetConfigFile().GetIntProperty("Setup", "ShadowMappingQuality", iValue)) if (GetConfigFile().GetBoolProperty("Setup", "ShadowMappingQuality", bValue))
engine->SetShadowMappingQuality(iValue); engine->SetShadowMappingQuality(bValue);
if (GetConfigFile().GetIntProperty("Setup", "ShadowMappingResolution", iValue)) if (GetConfigFile().GetIntProperty("Setup", "ShadowMappingResolution", iValue))
{ {
@ -271,17 +262,17 @@ void CSettings::LoadSettings()
if (GetConfigFile().GetFloatProperty("Edit", "FontSize", fValue)) m_fontSize = fValue; GetConfigFile().GetFloatProperty("Edit", "FontSize", m_fontSize);
if (GetConfigFile().GetFloatProperty("Edit", "WindowPosX", fValue)) m_windowPos.x = fValue; GetConfigFile().GetFloatProperty("Edit", "WindowPosX", m_windowPos.x);
if (GetConfigFile().GetFloatProperty("Edit", "WindowPosY", fValue)) m_windowPos.y = fValue; GetConfigFile().GetFloatProperty("Edit", "WindowPosY", m_windowPos.y);
if (GetConfigFile().GetFloatProperty("Edit", "WindowDimX", fValue)) m_windowDim.x = fValue; GetConfigFile().GetFloatProperty("Edit", "WindowDimX", m_windowDim.x);
if (GetConfigFile().GetFloatProperty("Edit", "WindowDimY", fValue)) m_windowDim.y = fValue; GetConfigFile().GetFloatProperty("Edit", "WindowDimY", m_windowDim.y);
if (GetConfigFile().GetIntProperty ("Edit", "IOPublic", iValue)) m_IOPublic = iValue; GetConfigFile().GetBoolProperty ("Edit", "IOPublic", m_IOPublic);
if (GetConfigFile().GetFloatProperty("Edit", "IOPosX", fValue)) m_IOPos.x = fValue; GetConfigFile().GetFloatProperty("Edit", "IOPosX", m_IOPos.x);
if (GetConfigFile().GetFloatProperty("Edit", "IOPosY", fValue)) m_IOPos.y = fValue; GetConfigFile().GetFloatProperty("Edit", "IOPosY", m_IOPos.y);
if (GetConfigFile().GetFloatProperty("Edit", "IODimX", fValue)) m_IODim.x = fValue; GetConfigFile().GetFloatProperty("Edit", "IODimX", m_IODim.x);
if (GetConfigFile().GetFloatProperty("Edit", "IODimY", fValue)) m_IODim.y = fValue; GetConfigFile().GetFloatProperty("Edit", "IODimY", m_IODim.y);
} }
void CSettings::SetTooltips(bool tooltips) void CSettings::SetTooltips(bool tooltips)
@ -380,7 +371,7 @@ Math::Point CSettings::GetWindowDim()
void CSettings::SetIOPublic(bool mode) void CSettings::SetIOPublic(bool mode)
{ {
m_IOPublic = mode; m_IOPublic = mode;
GetConfigFile().SetIntProperty("Edit", "IOPublic", m_IOPublic); GetConfigFile().SetBoolProperty("Edit", "IOPublic", m_IOPublic);
GetConfigFile().Save(); GetConfigFile().Save();
} }