#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>
#include <list>
#include <map>
#include <set>
+#include "filesys.h"
enum ValueType
{
public:
Settings()
{
- m_mutex.Init();
}
void writeLines(std::ostream &os)
}
}
- // 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
{
names.push_back(i->first);
}
- return names;
+ return names;
}
// remove a setting
// 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
i = objects.begin();
i != objects.end(); ++i)
{
- os<<(*i);
+ ss<<(*i);
}
/*
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;
}
}