1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 03:29:55 +00:00

Save and rename input bindings file

To reduce the chance of corrupting the file.
This commit is contained in:
elsid 2024-08-20 23:12:02 +02:00
parent 527fa053c5
commit 6a5bc9f992
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625
3 changed files with 17 additions and 11 deletions

View file

@ -1,5 +1,7 @@
#include "bindingsmanager.hpp" #include "bindingsmanager.hpp"
#include <filesystem>
#include <MyGUI_EditBox.h> #include <MyGUI_EditBox.h>
#include <extern/oics/ICSChannelListener.h> #include <extern/oics/ICSChannelListener.h>
@ -209,13 +211,22 @@ namespace MWInput
BindingsManager::~BindingsManager() BindingsManager::~BindingsManager()
{ {
const std::string newFileName = Files::pathToUnicodeString(mUserFile) + ".new";
try try
{ {
mInputBinder->save(Files::pathToUnicodeString(mUserFile)); if (mInputBinder->save(newFileName))
{
std::filesystem::rename(Files::pathFromUnicodeString(newFileName), mUserFile);
Log(Debug::Info) << "Saved input bindings: " << mUserFile;
}
else
{
Log(Debug::Error) << "Failed to save input bindings to " << newFileName;
}
} }
catch (std::exception& e) catch (const std::exception& e)
{ {
Log(Debug::Error) << "Failed to save input bindings: " << e.what(); Log(Debug::Error) << "Failed to save input bindings to " << newFileName << ": " << e.what();
} }
} }

View file

@ -357,14 +357,9 @@ namespace ICS
return file.substr(0, file.find_last_of(".")); return file.substr(0, file.find_last_of("."));
} }
bool InputControlSystem::save(std::string fileName) bool InputControlSystem::save(const std::string& fileName)
{ {
if(fileName != "") TiXmlDocument doc(fileName.c_str());
{
mFileName = fileName;
}
TiXmlDocument doc( mFileName.c_str() );
TiXmlDeclaration dec; TiXmlDeclaration dec;
dec.Parse( "<?xml version='1.0' encoding='utf-8'?>", 0, TIXML_ENCODING_UNKNOWN ); dec.Parse( "<?xml version='1.0' encoding='utf-8'?>", 0, TIXML_ENCODING_UNKNOWN );

View file

@ -144,7 +144,7 @@ namespace ICS
void cancelDetectingBindingState(); void cancelDetectingBindingState();
bool detectingBindingState(); bool detectingBindingState();
bool save(std::string fileName = ""); bool save(const std::string& fileName);
void adjustMouseRegion (Uint16 width, Uint16 height); void adjustMouseRegion (Uint16 width, Uint16 height);