]> Dogcows Code - chaz/yoink/blob - src/Moof/Settings.cc
94845c2b1380962352d6a86e80b034837efb1ad4
[chaz/yoink] / src / Moof / Settings.cc
1
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
4 *
5 * vi:ts=4 sw=4 tw=75
6 *
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
9 *
10 **************************************************************************/
11
12 #include <cstdlib> // getenv
13
14 #include "Settings.hh"
15
16
17 namespace Mf {
18
19
20 Settings::~Settings()
21 {
22 save();
23 }
24
25
26 void Settings::parseArgs(int argc, char* argv[])
27 {
28 for (int i = 1; i < argc; ++i)
29 {
30 mScript.doString(argv[i]);
31 }
32 }
33
34
35 void Settings::loadFromFiles(const std::string& path)
36 {
37 std::vector<std::string> paths;
38 boost::split(paths, path, boost::is_any_of(":"));
39
40 loadFromFiles(paths);
41 }
42
43 void Settings::loadFromFiles(const std::vector<std::string>& path)
44 {
45 std::vector<std::string> copy(path);
46 std::vector<std::string>::iterator it;
47
48 #if defined(_WIN32) || defined(__WIN32__)
49 char* homeDrive = getenv("HOMEDRIVE");
50 char* homePath = getenv("HOMEPATH");
51 std::string home(homeDrive ? homeDrive : "");
52 if (homePath) home += homePath;
53 #else
54 char *homePath = getenv("HOME");
55 std::string home(homePath ? homePath : "");
56 #endif
57
58 for (it = copy.begin(); it != copy.end(); ++it)
59 {
60 if (!home.empty())
61 {
62 boost::replace_all(*it, "$HOME", home);
63
64 //Mf::logDebug("Copying global settings...");
65 //mUserFile = *it;
66 //mGlobals.pushCopy();
67 //mScript.set("globals", Script::REGISTRY);
68 }
69
70 if (mScript.doFile(*it) != Script::SUCCESS)
71 {
72 std::string str;
73 mScript[-1].get(str);
74 logWarning(str);
75 mScript.clear();
76 }
77 }
78 }
79
80
81 void Settings::clear()
82 {
83 mScript.reset();
84 }
85
86
87 void Settings::saveAs(const std::string& path)
88 {
89 mUserFile = path;
90 save();
91 }
92
93 void Settings::save() const
94 {
95 // TODO saving settings not yet implemented
96 }
97
98
99 Settings settings; // global instance
100
101
102 } // namepsace Mf
103
This page took 0.03836 seconds and 3 git commands to generate.