X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FSettings.cc;h=5e19ed599ee511b0abef7306fa9fade271135fd2;hp=9f0538b3b827c56e4d6037a79edd2f659e62eaba;hb=987971a961454d97082c6448fdc0bbeb540281bb;hpb=be9ebc1104574e5e81e19c5caba0c23b54df826d diff --git a/src/Moof/Settings.cc b/src/Moof/Settings.cc index 9f0538b..5e19ed5 100644 --- a/src/Moof/Settings.cc +++ b/src/Moof/Settings.cc @@ -26,7 +26,6 @@ *******************************************************************************/ -#include #include // getenv #include "Settings.hh" @@ -40,11 +39,11 @@ Settings::~Settings() save(); } -Settings& Settings::getInstance() -{ - static Settings settings; - return settings; -} +//Settings& Settings::getInstance() +//{ + //static Settings settings; + //return settings; +//} void Settings::parseArgs(int argc, char* argv[]) @@ -56,35 +55,42 @@ 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 = path; + //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); @@ -101,9 +107,9 @@ void Settings::clear() } -void Settings::saveAs(const std::string& filePath) +void Settings::saveAs(const std::string& path) { - mUserFile = filePath; + mUserFile = path; save(); } @@ -112,6 +118,9 @@ void Settings::save() const } +Settings settings; + + } // namepsace Mf /** vim: set ts=4 sw=4 tw=80: *************************************************/