*******************************************************************************/
-#include <sstream>
#include <cstdlib> // getenv
#include "Settings.hh"
namespace Mf {
-Settings& Settings::getInstance()
+Settings::~Settings()
{
- static Settings settings;
- return settings;
+ save();
}
+//Settings& Settings::getInstance()
+//{
+ //static Settings settings;
+ //return settings;
+//}
+
void Settings::parseArgs(int argc, char* argv[])
{
for (int i = 1; i < argc; ++i)
{
- script_.doString(argv[i]);
+ mScript.doString(argv[i]);
}
}
-void Settings::loadFromFile(const std::string& filePath)
+void Settings::loadFromFiles(const std::string& path)
{
std::vector<std::string> paths;
- boost::split(paths, filePath, boost::is_any_of(":"));
+ boost::split(paths, path, boost::is_any_of(":"));
loadFromFiles(paths);
}
-void Settings::loadFromFiles(const std::vector<std::string>& filePaths)
+void Settings::loadFromFiles(const std::vector<std::string>& path)
{
- std::vector<std::string>::const_iterator it;
-
- char* home = getenv("HOME");
-
- for (it = filePaths.begin(); it != filePaths.end(); ++it)
+ std::vector<std::string> copy(path);
+ std::vector<std::string>::iterator it;
+
+#if defined(_WIN32) || defined(__WIN32__)
+ char* homeDrive = getenv("HOMEDRIVE");
+ char* homePath = getenv("HOMEPATH");
+ std::string home(homeDrive ? homeDrive : "");
+ if (homePath) home += homePath;
+#else
+ char *homePath = getenv("HOME");
+ std::string home(homePath ? homePath : "");
+#endif
+
+ for (it = copy.begin(); it != copy.end(); ++it)
{
- std::string path = *it;
-
- if (home)
+ if (!home.empty())
{
- boost::replace_all(path, "$HOME", home);
+ boost::replace_all(*it, "$HOME", home);
+
+ //Mf::logDebug("Copying global settings...");
+ //mUserFile = *it;
+ //mGlobals.pushCopy();
+ //mScript.set("globals", Script::REGISTRY);
}
- if (script_.doFile(path) != Script::SUCCESS)
+ if (mScript.doFile(*it) != Script::SUCCESS)
{
std::string str;
- script_[-1].get(str);
- logScript("%s", str.c_str());
- script_.clear();
+ mScript[-1].get(str);
+ logWarning(str);
+ mScript.clear();
}
}
}
+void Settings::clear()
+{
+ mScript.reset();
+}
+
+
+void Settings::saveAs(const std::string& path)
+{
+ mUserFile = path;
+ save();
+}
+
+void Settings::save() const
+{
+}
+
+
+Settings settings;
+
+
} // namepsace Mf
/** vim: set ts=4 sw=4 tw=80: *************************************************/