X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FSettings.cc;h=5e19ed599ee511b0abef7306fa9fade271135fd2;hp=81b5c50fd62d7b6d34ec740b15b7eb23f09a6800;hb=3f6e44698c38b74bb622ad81ea9d2daa636981d2;hpb=e495074443d9fd7bc16137084cf9de3d031b75c4 diff --git a/src/Moof/Settings.cc b/src/Moof/Settings.cc index 81b5c50..5e19ed5 100644 --- a/src/Moof/Settings.cc +++ b/src/Moof/Settings.cc @@ -26,7 +26,6 @@ *******************************************************************************/ -#include #include // getenv #include "Settings.hh" @@ -35,12 +34,17 @@ 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[]) { @@ -51,34 +55,46 @@ void Settings::parseArgs(int argc, char* argv[]) } -void Settings::loadFromFile(const std::string& filePath) +void Settings::loadFromFiles(const std::string& path) { std::vector 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& filePaths) +void Settings::loadFromFiles(const std::vector& path) { - std::vector::const_iterator it; - - char* home = getenv("HOME"); - - for (it = filePaths.begin(); it != filePaths.end(); ++it) + std::vector copy(path); + std::vector::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 (mScript.doFile(path) != Script::SUCCESS) + if (mScript.doFile(*it) != Script::SUCCESS) { std::string str; mScript[-1].get(str); - logScript("%s", str.c_str()); + logWarning(str); mScript.clear(); } } @@ -91,6 +107,20 @@ void Settings::clear() } +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: *************************************************/