30 #include <boost/filesystem/fstream.hpp>
31 #include <boost/algorithm/string/replace.hpp>
32 #include <boost/filesystem/path.hpp>
33 #include <boost/filesystem/operations.hpp>
42 using namespace boost;
43 namespace po = boost::program_options;
47 Settings::Settings(
const std::string i_path)
50 m_SettingsFileName = i_path +
"\\.creaImageIO\\share\\creaImageIO\\app.config";
52 if(!boost::filesystem::exists(m_SettingsFileName) )
56 std::ifstream ifs(m_SettingsFileName.c_str());
68 std::vector<std::string> Keys;
76 readSettings(Keys, sets);
91 void Settings::createFile()
97 m_SettingsMap[
SETTINGS_COPY_PATH] = m_SettingsFileName.substr(0,m_SettingsFileName.find_last_of(
'\\')+1)+
"Copied files";
110 void Settings::readSettings(std::vector<std::string> &i_Keys,
const std::string &i_file)
112 std::vector<std::string>::iterator it_key = i_Keys.begin();
113 for(; it_key< i_Keys.end(); ++it_key)
115 size_t fpos = i_file.find(it_key->c_str());
116 size_t lpos = i_file.rfind(it_key->c_str());
117 if(fpos != std::string::npos && lpos != std::string::npos)
119 m_SettingsMap[it_key->c_str()] = i_file.substr(fpos + it_key->size(),lpos-fpos - it_key->size());
130 void Settings::updateSetting(
const std::string& key,
const std::string &val)
132 m_SettingsMap[key.c_str()] = val;
140 void Settings::addDB(
const std::string &i_path)
154 void Settings::removeDB(
const std::string &i_path)
156 boost::algorithm::replace_all(m_SettingsMap[
SETTINGS_DBPATH],i_path +
";",
"");
165 void Settings::writeSettings(std::ofstream &o_file)
167 std::map<std::string, std::string>::iterator it_map = m_SettingsMap.begin();
168 std::stringstream st;
169 for(; it_map != m_SettingsMap.end(); ++it_map)
171 o_file << it_map->first.c_str();
172 o_file << it_map->second.c_str();
173 o_file << it_map->first.c_str();
183 void Settings::writeSettingsFile()
185 std::ofstream ofs(m_SettingsFileName.c_str());