]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/settings.h
Fix MinGW build
[dragonfireclient.git] / src / settings.h
index e7b49b6d7798497cc3d25f8bda08a596abe4acf9..e19f83e3fe8e4ede19d0a543c4dd6e385c259896 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
 {
@@ -59,7 +60,6 @@ class Settings
 public:
        Settings()
        {
-               m_mutex.Init();
        }
 
        void writeLines(std::ostream &os)
@@ -76,7 +76,7 @@ class Settings
                }
        }
   
-       // return all keys used 
+       // return all keys used
        std::vector<std::string> getNames(){
                std::vector<std::string> names;
                for(std::map<std::string, std::string>::iterator
@@ -85,7 +85,7 @@ class Settings
                {
                        names.push_back(i->first);
                }
-               return names;  
+               return names;
        }
 
        // remove a setting
@@ -308,14 +308,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 +317,7 @@ class Settings
                                        i = objects.begin();
                                        i != objects.end(); ++i)
                        {
-                               os<<(*i);
+                               ss<<(*i);
                        }
 
                        /*
@@ -340,7 +333,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;
                        }
                }