]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/settings.h
Fix spaces float islands code
[dragonfireclient.git] / src / settings.h
index e7b49b6d7798497cc3d25f8bda08a596abe4acf9..4ee5b591322a9070f6bf7b685f034cd823b1e54c 100644 (file)
@@ -21,10 +21,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #define SETTINGS_HEADER
 
 #include "irrlichttypes_bloated.h"
+#include "exceptions.h"
 #include <string>
-#include <jthread.h>
-#include <jmutex.h>
-#include <jmutexautolock.h>
+#include "jthread/jmutex.h"
+#include "jthread/jmutexautolock.h"
 #include "strfnd.h"
 #include <iostream>
 #include <fstream>
@@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <list>
 #include <map>
 #include <set>
+#include "filesys.h"
 
 enum ValueType
 {
@@ -308,14 +309,7 @@ class Settings
 
                // Write stuff back
                {
-                       std::ofstream os(filename);
-                       if(os.good() == false)
-                       {
-                               errorstream<<"Error opening configuration file"
-                                               " for writing: \""
-                                               <<filename<<"\""<<std::endl;
-                               return false;
-                       }
+                       std::ostringstream ss(std::ios_base::binary);
 
                        /*
                                Write updated stuff
@@ -324,7 +318,7 @@ class Settings
                                        i = objects.begin();
                                        i != objects.end(); ++i)
                        {
-                               os<<(*i);
+                               ss<<(*i);
                        }
 
                        /*
@@ -340,7 +334,14 @@ class Settings
                                std::string value = i->second;
                                infostream<<"Adding \""<<name<<"\" = \""<<value<<"\""
                                                <<std::endl;
-                               os<<name<<" = "<<value<<"\n";
+                               ss<<name<<" = "<<value<<"\n";
+                       }
+
+                       if(!fs::safeWriteToFile(filename, ss.str()))
+                       {
+                               errorstream<<"Error writing configuration file: \""
+                                               <<filename<<"\""<<std::endl;
+                               return false;
                        }
                }