Fixed huge lag on closing settings
Introduced in 02c24fbf27
, this was supposed to make it more resistant to crashes but turned out to generate huge lag on closing settings
Instead, I added manual .Save() after every value change
master
parent
d3c3f47b19
commit
8c87eedd28
|
@ -38,7 +38,8 @@ template<> CConfigFile* CSingleton<CConfigFile>::m_instance = nullptr;
|
|||
namespace bp = boost::property_tree;
|
||||
|
||||
CConfigFile::CConfigFile()
|
||||
: m_useCurrentDirectory(false)
|
||||
: m_needsSave(false)
|
||||
, m_useCurrentDirectory(false)
|
||||
, m_loaded(false)
|
||||
{
|
||||
}
|
||||
|
@ -46,6 +47,11 @@ CConfigFile::CConfigFile()
|
|||
|
||||
CConfigFile::~CConfigFile()
|
||||
{
|
||||
if (m_needsSave)
|
||||
{
|
||||
GetLogger()->Warn("Config file was not properly saved! Saving now...\n");
|
||||
Save();
|
||||
}
|
||||
}
|
||||
|
||||
void CConfigFile::SetUseCurrentDirectory(bool useCurrentDirectory)
|
||||
|
@ -79,13 +85,13 @@ bool CConfigFile::Init()
|
|||
}
|
||||
else
|
||||
{
|
||||
GetLogger()->Error("Error on parsing profile: failed to open file\n");
|
||||
GetLogger()->Error("Error on parsing config file: failed to open file\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
GetLogger()->Error("Error on parsing profile: %s\n", e.what());
|
||||
GetLogger()->Error("Error on parsing config file: %s\n", e.what());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -93,38 +99,42 @@ bool CConfigFile::Init()
|
|||
|
||||
bool CConfigFile::Save()
|
||||
{
|
||||
try
|
||||
if (m_needsSave)
|
||||
{
|
||||
std::unique_ptr<std::ostream> stream;
|
||||
bool good;
|
||||
if (m_useCurrentDirectory)
|
||||
try
|
||||
{
|
||||
std::ofstream* outputStream = new std::ofstream("./colobot.ini");
|
||||
stream = std::unique_ptr<std::ostream>(outputStream);
|
||||
good = outputStream->good();
|
||||
}
|
||||
else
|
||||
{
|
||||
COutputStream* outputStream = new COutputStream("colobot.ini");
|
||||
stream = std::unique_ptr<std::ostream>(outputStream);
|
||||
good = outputStream->is_open();
|
||||
}
|
||||
std::unique_ptr<std::ostream> stream;
|
||||
bool good;
|
||||
if (m_useCurrentDirectory)
|
||||
{
|
||||
std::ofstream* outputStream = new std::ofstream("./colobot.ini");
|
||||
stream = std::unique_ptr<std::ostream>(outputStream);
|
||||
good = outputStream->good();
|
||||
}
|
||||
else
|
||||
{
|
||||
COutputStream* outputStream = new COutputStream("colobot.ini");
|
||||
stream = std::unique_ptr<std::ostream>(outputStream);
|
||||
good = outputStream->is_open();
|
||||
}
|
||||
|
||||
if (good)
|
||||
{
|
||||
bp::ini_parser::write_ini(*stream, m_propertyTree);
|
||||
if (good)
|
||||
{
|
||||
bp::ini_parser::write_ini(*stream, m_propertyTree);
|
||||
m_needsSave = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
GetLogger()->Error("Error on storing config file: failed to open file\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (std::exception & e)
|
||||
{
|
||||
GetLogger()->Error("Error on storing profile: failed to open file\n");
|
||||
GetLogger()->Error("Error on storing config file: %s\n", e.what());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
GetLogger()->Error("Error on storing profile: %s\n", e.what());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -133,11 +143,11 @@ bool CConfigFile::SetStringProperty(std::string section, std::string key, std::s
|
|||
try
|
||||
{
|
||||
m_propertyTree.put(section + "." + key, value);
|
||||
Save();
|
||||
m_needsSave = true;
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
GetLogger()->Info("Error on editing config file: %s\n", e.what());
|
||||
GetLogger()->Error("Error on editing config file: %s\n", e.what());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -171,11 +181,11 @@ bool CConfigFile::SetIntProperty(std::string section, std::string key, int value
|
|||
try
|
||||
{
|
||||
m_propertyTree.put(section + "." + key, value);
|
||||
Save();
|
||||
m_needsSave = true;
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
GetLogger()->Info("Error on editing config file: %s\n", e.what());
|
||||
GetLogger()->Error("Error on editing config file: %s\n", e.what());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -209,11 +219,11 @@ bool CConfigFile::SetFloatProperty(std::string section, std::string key, float v
|
|||
try
|
||||
{
|
||||
m_propertyTree.put(section + "." + key, value);
|
||||
Save();
|
||||
m_needsSave = true;
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
GetLogger()->Info("Error on editing config file: %s\n", e.what());
|
||||
GetLogger()->Error("Error on editing config file: %s\n", e.what());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -56,6 +56,11 @@ public:
|
|||
*/
|
||||
bool Init();
|
||||
|
||||
/** Saves colobot.ini
|
||||
* \return return true on success
|
||||
*/
|
||||
bool Save();
|
||||
|
||||
/** Sets string value in section under specified key
|
||||
* \param section
|
||||
* \param key
|
||||
|
@ -104,14 +109,9 @@ public:
|
|||
*/
|
||||
bool GetFloatProperty(std::string section, std::string key, float &value);
|
||||
|
||||
private:
|
||||
/** Saves colobot.ini
|
||||
* \return return true on success
|
||||
*/
|
||||
bool Save();
|
||||
|
||||
private:
|
||||
boost::property_tree::ptree m_propertyTree;
|
||||
bool m_needsSave;
|
||||
bool m_useCurrentDirectory;
|
||||
bool m_loaded;
|
||||
};
|
||||
|
|
|
@ -76,6 +76,7 @@ CPlayerProfile::CPlayerProfile(std::string playerName)
|
|||
{
|
||||
m_playerName = playerName;
|
||||
GetConfigFile().SetStringProperty("Gamer", "LastName", m_playerName);
|
||||
GetConfigFile().Save();
|
||||
|
||||
if (!CResourceManager::DirectoryExists(GetSaveDir()))
|
||||
{
|
||||
|
|
|
@ -410,6 +410,7 @@ void CRobotMain::CreateConfigFile()
|
|||
GetConfigFile().SetFloatProperty("Edit", "IOPosY", m_IOPos.y);
|
||||
GetConfigFile().SetFloatProperty("Edit", "IODimX", m_IODim.x);
|
||||
GetConfigFile().SetFloatProperty("Edit", "IODimY", m_IODim.y);
|
||||
GetConfigFile().Save();
|
||||
}
|
||||
|
||||
void CRobotMain::LoadConfigFile()
|
||||
|
@ -1549,6 +1550,7 @@ void CRobotMain::SetFontSize(float size)
|
|||
{
|
||||
m_fontSize = size;
|
||||
GetConfigFile().SetFloatProperty("Edit", "FontSize", m_fontSize);
|
||||
GetConfigFile().Save();
|
||||
}
|
||||
|
||||
float CRobotMain::GetFontSize()
|
||||
|
@ -1562,6 +1564,7 @@ void CRobotMain::SetWindowPos(Math::Point pos)
|
|||
m_windowPos = pos;
|
||||
GetConfigFile().SetFloatProperty("Edit", "WindowPosX", m_windowPos.x);
|
||||
GetConfigFile().SetFloatProperty("Edit", "WindowPosY", m_windowPos.y);
|
||||
GetConfigFile().Save();
|
||||
}
|
||||
|
||||
Math::Point CRobotMain::GetWindowPos()
|
||||
|
@ -1574,6 +1577,7 @@ void CRobotMain::SetWindowDim(Math::Point dim)
|
|||
m_windowDim = dim;
|
||||
GetConfigFile().SetFloatProperty("Edit", "WindowDimX", m_windowDim.x);
|
||||
GetConfigFile().SetFloatProperty("Edit", "WindowDimY", m_windowDim.y);
|
||||
GetConfigFile().Save();
|
||||
}
|
||||
|
||||
Math::Point CRobotMain::GetWindowDim()
|
||||
|
@ -1587,6 +1591,7 @@ void CRobotMain::SetIOPublic(bool mode)
|
|||
{
|
||||
m_IOPublic = mode;
|
||||
GetConfigFile().SetIntProperty("Edit", "IOPublic", m_IOPublic);
|
||||
GetConfigFile().Save();
|
||||
}
|
||||
|
||||
bool CRobotMain::GetIOPublic()
|
||||
|
@ -1599,6 +1604,7 @@ void CRobotMain::SetIOPos(Math::Point pos)
|
|||
m_IOPos = pos;
|
||||
GetConfigFile().SetFloatProperty("Edit", "IOPosX", m_IOPos.x);
|
||||
GetConfigFile().SetFloatProperty("Edit", "IOPosY", m_IOPos.y);
|
||||
GetConfigFile().Save();
|
||||
}
|
||||
|
||||
Math::Point CRobotMain::GetIOPos()
|
||||
|
@ -1611,6 +1617,7 @@ void CRobotMain::SetIODim(Math::Point dim)
|
|||
m_IODim = dim;
|
||||
GetConfigFile().SetFloatProperty("Edit", "IODimX", m_IODim.x);
|
||||
GetConfigFile().SetFloatProperty("Edit", "IODimY", m_IODim.y);
|
||||
GetConfigFile().Save();
|
||||
}
|
||||
|
||||
Math::Point CRobotMain::GetIODim()
|
||||
|
|
|
@ -4911,6 +4911,8 @@ void CMainDialog::SetupMemorize()
|
|||
CInput::GetInstancePointer()->SaveKeyBindings();
|
||||
|
||||
GetConfigFile().SetIntProperty("Setup", "DeleteGamer", m_bDeleteGamer);
|
||||
|
||||
GetConfigFile().Save();
|
||||
}
|
||||
|
||||
// Remember all the settings.
|
||||
|
|
Loading…
Reference in New Issue