diff options
Diffstat (limited to 'OpenSim/Tools/OpenSim.GridLaunch/Settings.cs')
-rw-r--r-- | OpenSim/Tools/OpenSim.GridLaunch/Settings.cs | 181 |
1 files changed, 181 insertions, 0 deletions
diff --git a/OpenSim/Tools/OpenSim.GridLaunch/Settings.cs b/OpenSim/Tools/OpenSim.GridLaunch/Settings.cs new file mode 100644 index 0000000..91353d8 --- /dev/null +++ b/OpenSim/Tools/OpenSim.GridLaunch/Settings.cs | |||
@@ -0,0 +1,181 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Reflection; | ||
30 | using System.Text; | ||
31 | using log4net; | ||
32 | |||
33 | namespace OpenSim.GridLaunch | ||
34 | { | ||
35 | internal class Settings | ||
36 | { | ||
37 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
38 | private Dictionary<string, string> Config = new Dictionary<string, string>(); | ||
39 | public Dictionary<string, bool> Components = new Dictionary<string, bool>(); | ||
40 | |||
41 | public static string[] defaultComponents = new string[] | ||
42 | { | ||
43 | "OpenSim.Grid.UserServer.exe", | ||
44 | "OpenSim.Grid.GridServer.exe", | ||
45 | "OpenSim.Grid.AssetServer.exe", | ||
46 | "OpenSim.Grid.InventoryServer.exe", | ||
47 | "OpenSim.Grid.MessagingServer.exe", | ||
48 | "OpenSim.32BitLaunch.exe" | ||
49 | }; | ||
50 | |||
51 | |||
52 | private static readonly char[] confSplit = new char[] { '=' }; | ||
53 | private static readonly char[] comaSplit = new char[] { ',' }; | ||
54 | private static readonly char[] colonSplit = new char[] { ';' }; | ||
55 | |||
56 | private string configFile = ""; | ||
57 | |||
58 | public Settings() | ||
59 | { | ||
60 | } | ||
61 | public Settings(string ConfigFile) | ||
62 | { | ||
63 | LoadConfig(ConfigFile); | ||
64 | } | ||
65 | |||
66 | |||
67 | public void LoadConfig(string ConfigFile) | ||
68 | { | ||
69 | configFile = ConfigFile; | ||
70 | m_log.Info("Reading config file: " + ConfigFile); | ||
71 | try | ||
72 | { | ||
73 | // Read config file | ||
74 | foreach (string line in System.IO.File.ReadAllLines(ConfigFile)) | ||
75 | { | ||
76 | string[] s = line.Split(confSplit, 2); | ||
77 | if (s.Length >= 2) | ||
78 | Config.Add(s[0], s[1]); | ||
79 | } | ||
80 | |||
81 | // Process Components section | ||
82 | string cmp = Config["Components"]; | ||
83 | Config.Remove("Components"); | ||
84 | foreach (string c in cmp.Split(comaSplit)) | ||
85 | { | ||
86 | string[] cs = c.Split(colonSplit); | ||
87 | if (cs.Length >= 2) | ||
88 | { | ||
89 | bool status = false; | ||
90 | bool.TryParse(cs[1], out status); | ||
91 | Components.Add(cs[0], status); | ||
92 | } | ||
93 | } | ||
94 | } | ||
95 | catch (Exception ex) | ||
96 | { | ||
97 | m_log.Error("Exception reading config file: " + ex.ToString()); | ||
98 | } | ||
99 | // No components? Add default components | ||
100 | if (Components.Count == 0) | ||
101 | foreach (string c in defaultComponents) | ||
102 | { | ||
103 | Components.Add(c, true); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | public void SaveConfig(string ConfigFile) | ||
108 | { | ||
109 | configFile = ConfigFile; | ||
110 | SaveConfig(); | ||
111 | } | ||
112 | |||
113 | public void SaveConfig() | ||
114 | { | ||
115 | m_log.Info("Writing config file: " + configFile); | ||
116 | try | ||
117 | { | ||
118 | System.IO.File.WriteAllText(configFile, ToString()); | ||
119 | } | ||
120 | catch (Exception ex) | ||
121 | { | ||
122 | m_log.Error("Exception writing config file: " + ex.ToString()); | ||
123 | } | ||
124 | |||
125 | } | ||
126 | |||
127 | public new string ToString() | ||
128 | { | ||
129 | StringBuilder ret = new StringBuilder(); | ||
130 | |||
131 | Dictionary<string, string> config = new Dictionary<string, string>(Config); | ||
132 | |||
133 | // Add Components key | ||
134 | StringBuilder _Components = new StringBuilder(); | ||
135 | foreach (string c in Components.Keys) | ||
136 | { | ||
137 | if (_Components.Length > 0) | ||
138 | _Components.Append(","); | ||
139 | _Components.Append(c + ";" + Components[c].ToString()); | ||
140 | } | ||
141 | config["Components"] = _Components.ToString(); | ||
142 | |||
143 | // Make return string | ||
144 | foreach (string key in config.Keys) | ||
145 | { | ||
146 | ret.AppendLine(key + "=" + config[key]); | ||
147 | } | ||
148 | |||
149 | // Return it | ||
150 | return ret.ToString(); | ||
151 | } | ||
152 | |||
153 | public string this[string Key] | ||
154 | { | ||
155 | get | ||
156 | { | ||
157 | if (Config.ContainsKey(Key)) | ||
158 | return Config[Key]; | ||
159 | return ""; | ||
160 | } | ||
161 | set { Config[Key] = value; } | ||
162 | } | ||
163 | |||
164 | public void ParseCommandArguments(string[] args) | ||
165 | { | ||
166 | string key = null; | ||
167 | foreach (string a in args) | ||
168 | { | ||
169 | if (a.StartsWith("--")) | ||
170 | key = a.Remove(0, 2); | ||
171 | else | ||
172 | { | ||
173 | if (key != null) | ||
174 | Config[key] = a; | ||
175 | key = null; | ||
176 | } | ||
177 | } | ||
178 | |||
179 | } | ||
180 | } | ||
181 | } | ||