]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Settings.cc
refactoring needed for win32 crash
[chaz/yoink] / src / Moof / Settings.cc
index 9f0538b3b827c56e4d6037a79edd2f659e62eaba..5e19ed599ee511b0abef7306fa9fade271135fd2 100644 (file)
@@ -26,7 +26,6 @@
 
 *******************************************************************************/
 
-#include <sstream>
 #include <cstdlib>             // 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<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 = 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: *************************************************/
This page took 0.019749 seconds and 4 git commands to generate.