diff --git a/apps/openmw/mwinput/bindingsmanager.cpp b/apps/openmw/mwinput/bindingsmanager.cpp index a6bab19673..bad6744c0f 100644 --- a/apps/openmw/mwinput/bindingsmanager.cpp +++ b/apps/openmw/mwinput/bindingsmanager.cpp @@ -1,5 +1,7 @@ #include "bindingsmanager.hpp" +#include + #include #include @@ -209,13 +211,22 @@ namespace MWInput BindingsManager::~BindingsManager() { + const std::string newFileName = Files::pathToUnicodeString(mUserFile) + ".new"; 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(); } } diff --git a/extern/oics/ICSInputControlSystem.cpp b/extern/oics/ICSInputControlSystem.cpp index 7d92d9ee07..e64fef0fc6 100644 --- a/extern/oics/ICSInputControlSystem.cpp +++ b/extern/oics/ICSInputControlSystem.cpp @@ -357,14 +357,9 @@ namespace ICS return file.substr(0, file.find_last_of(".")); } - bool InputControlSystem::save(std::string fileName) + bool InputControlSystem::save(const std::string& fileName) { - if(fileName != "") - { - mFileName = fileName; - } - - TiXmlDocument doc( mFileName.c_str() ); + TiXmlDocument doc(fileName.c_str()); TiXmlDeclaration dec; dec.Parse( "", 0, TIXML_ENCODING_UNKNOWN ); diff --git a/extern/oics/ICSInputControlSystem.h b/extern/oics/ICSInputControlSystem.h index 97ab8d2edf..aa37c4a124 100644 --- a/extern/oics/ICSInputControlSystem.h +++ b/extern/oics/ICSInputControlSystem.h @@ -144,7 +144,7 @@ namespace ICS void cancelDetectingBindingState(); bool detectingBindingState(); - bool save(std::string fileName = ""); + bool save(const std::string& fileName); void adjustMouseRegion (Uint16 width, Uint16 height);