aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools/Configger/ConfigurationLoader.cs
diff options
context:
space:
mode:
authorMelanie2010-02-08 15:53:20 +0000
committerMelanie2010-02-08 15:53:38 +0000
commitbaaf660511214e52ea4ed20b8e80ec8e1ff06a3a (patch)
tree1e90c7a22ea3354d6bfd5d2b3f8f64f199dbd477 /OpenSim/Tools/Configger/ConfigurationLoader.cs
parentAdded missing configs to Standalone.ini (diff)
parentAdding the Careminster "Configger" tool to OpenSim. The tool will, when launched (diff)
downloadopensim-SC_OLD-baaf660511214e52ea4ed20b8e80ec8e1ff06a3a.zip
opensim-SC_OLD-baaf660511214e52ea4ed20b8e80ec8e1ff06a3a.tar.gz
opensim-SC_OLD-baaf660511214e52ea4ed20b8e80ec8e1ff06a3a.tar.bz2
opensim-SC_OLD-baaf660511214e52ea4ed20b8e80ec8e1ff06a3a.tar.xz
Merge branch 'master' into presence-refactor
This was a large, heavily conflicted merge and things MAY have got broken. Please check!
Diffstat (limited to 'OpenSim/Tools/Configger/ConfigurationLoader.cs')
-rw-r--r--OpenSim/Tools/Configger/ConfigurationLoader.cs251
1 files changed, 251 insertions, 0 deletions
diff --git a/OpenSim/Tools/Configger/ConfigurationLoader.cs b/OpenSim/Tools/Configger/ConfigurationLoader.cs
new file mode 100644
index 0000000..49af417
--- /dev/null
+++ b/OpenSim/Tools/Configger/ConfigurationLoader.cs
@@ -0,0 +1,251 @@
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Reflection;
5using System.Threading;
6using System.Xml;
7using log4net;
8using Nini.Config;
9
10namespace Careminster
11{
12 /// <summary>
13 /// Loads the Configuration files into nIni
14 /// </summary>
15 public class ConfigurationLoader
16 {
17 /// <summary>
18 /// A source of Configuration data
19 /// </summary>
20 protected IConfigSource m_config;
21
22 /// <summary>
23 /// Console logger
24 /// </summary>
25 private static readonly ILog m_log =
26 LogManager.GetLogger(
27 MethodBase.GetCurrentMethod().DeclaringType);
28
29 public ConfigurationLoader()
30 {
31 }
32
33 /// <summary>
34 /// Loads the region configuration
35 /// </summary>
36 /// <param name="argvSource">Parameters passed into the process when started</param>
37 /// <param name="configSettings"></param>
38 /// <param name="networkInfo"></param>
39 /// <returns>A configuration that gets passed to modules</returns>
40 public IConfigSource LoadConfigSettings()
41 {
42 bool iniFileExists = false;
43
44 List<string> sources = new List<string>();
45
46 string iniFileName = "OpenSim.ini";
47 string iniFilePath = Path.Combine(".", iniFileName);
48
49 if (IsUri(iniFileName))
50 {
51 if (!sources.Contains(iniFileName))
52 sources.Add(iniFileName);
53 }
54 else
55 {
56 if (File.Exists(iniFilePath))
57 {
58 if (!sources.Contains(iniFilePath))
59 sources.Add(iniFilePath);
60 }
61 }
62
63 m_config = new IniConfigSource();
64 m_config.Merge(DefaultConfig());
65
66 m_log.Info("[CONFIG] Reading configuration settings");
67
68 if (sources.Count == 0)
69 {
70 m_log.FatalFormat("[CONFIG] Could not load any configuration");
71 m_log.FatalFormat("[CONFIG] Did you copy the OpenSim.ini.example file to OpenSim.ini?");
72 Environment.Exit(1);
73 }
74
75 for (int i = 0 ; i < sources.Count ; i++)
76 {
77 if (ReadConfig(sources[i]))
78 iniFileExists = true;
79 AddIncludes(sources);
80 }
81
82 if (!iniFileExists)
83 {
84 m_log.FatalFormat("[CONFIG] Could not load any configuration");
85 m_log.FatalFormat("[CONFIG] Configuration exists, but there was an error loading it!");
86 Environment.Exit(1);
87 }
88
89 return m_config;
90 }
91
92 /// <summary>
93 /// Adds the included files as ini configuration files
94 /// </summary>
95 /// <param name="sources">List of URL strings or filename strings</param>
96 private void AddIncludes(List<string> sources)
97 {
98 //loop over config sources
99 foreach (IConfig config in m_config.Configs)
100 {
101 // Look for Include-* in the key name
102 string[] keys = config.GetKeys();
103 foreach (string k in keys)
104 {
105 if (k.StartsWith("Include-"))
106 {
107 // read the config file to be included.
108 string file = config.GetString(k);
109 if (IsUri(file))
110 {
111 if (!sources.Contains(file))
112 sources.Add(file);
113 }
114 else
115 {
116 string basepath = Path.GetFullPath(".");
117 string path = Path.Combine(basepath, file);
118 string[] paths = Util.Glob(path);
119 foreach (string p in paths)
120 {
121 if (!sources.Contains(p))
122 sources.Add(p);
123 }
124 }
125 }
126 }
127 }
128 }
129 /// <summary>
130 /// Check if we can convert the string to a URI
131 /// </summary>
132 /// <param name="file">String uri to the remote resource</param>
133 /// <returns>true if we can convert the string to a Uri object</returns>
134 bool IsUri(string file)
135 {
136 Uri configUri;
137
138 return Uri.TryCreate(file, UriKind.Absolute,
139 out configUri) && configUri.Scheme == Uri.UriSchemeHttp;
140 }
141
142 /// <summary>
143 /// Provide same ini loader functionality for standard ini and master ini - file system or XML over http
144 /// </summary>
145 /// <param name="iniPath">Full path to the ini</param>
146 /// <returns></returns>
147 private bool ReadConfig(string iniPath)
148 {
149 bool success = false;
150
151 if (!IsUri(iniPath))
152 {
153 m_log.InfoFormat("[CONFIG] Reading configuration file {0}",
154 Path.GetFullPath(iniPath));
155
156 m_config.Merge(new IniConfigSource(iniPath));
157 success = true;
158 }
159 else
160 {
161 m_log.InfoFormat("[CONFIG] {0} is a http:// URI, fetching ...",
162 iniPath);
163
164 // The ini file path is a http URI
165 // Try to read it
166 //
167 try
168 {
169 XmlReader r = XmlReader.Create(iniPath);
170 XmlConfigSource cs = new XmlConfigSource(r);
171 m_config.Merge(cs);
172
173 success = true;
174 }
175 catch (Exception e)
176 {
177 m_log.FatalFormat("[CONFIG] Exception reading config from URI {0}\n" + e.ToString(), iniPath);
178 Environment.Exit(1);
179 }
180 }
181 return success;
182 }
183
184 /// <summary>
185 /// Setup a default config values in case they aren't present in the ini file
186 /// </summary>
187 /// <returns>A Configuration source containing the default configuration</returns>
188 private static IConfigSource DefaultConfig()
189 {
190 IConfigSource defaultConfig = new IniConfigSource();
191
192 {
193 IConfig config = defaultConfig.Configs["Startup"];
194
195 if (null == config)
196 config = defaultConfig.AddConfig("Startup");
197
198 config.Set("region_info_source", "filesystem");
199
200 config.Set("gridmode", false);
201 config.Set("physics", "OpenDynamicsEngine");
202 config.Set("meshing", "Meshmerizer");
203 config.Set("physical_prim", true);
204 config.Set("see_into_this_sim_from_neighbor", true);
205 config.Set("serverside_object_permissions", false);
206 config.Set("storage_plugin", "OpenSim.Data.SQLite.dll");
207 config.Set("storage_connection_string", "URI=file:OpenSim.db,version=3");
208 config.Set("storage_prim_inventories", true);
209 config.Set("startup_console_commands_file", String.Empty);
210 config.Set("shutdown_console_commands_file", String.Empty);
211 config.Set("DefaultScriptEngine", "XEngine");
212 config.Set("clientstack_plugin", "OpenSim.Region.ClientStack.LindenUDP.dll");
213 // life doesn't really work without this
214 config.Set("EventQueue", true);
215 }
216
217 {
218 IConfig config = defaultConfig.Configs["StandAlone"];
219
220 if (null == config)
221 config = defaultConfig.AddConfig("StandAlone");
222
223 config.Set("accounts_authenticate", true);
224 config.Set("welcome_message", "Welcome to OpenSimulator");
225 config.Set("inventory_plugin", "OpenSim.Data.SQLite.dll");
226 config.Set("inventory_source", "");
227 config.Set("userDatabase_plugin", "OpenSim.Data.SQLite.dll");
228 config.Set("user_source", "");
229 config.Set("LibrariesXMLFile", string.Format(".{0}inventory{0}Libraries.xml", Path.DirectorySeparatorChar));
230 }
231
232 {
233 IConfig config = defaultConfig.Configs["Network"];
234
235 if (null == config)
236 config = defaultConfig.AddConfig("Network");
237
238 config.Set("default_location_x", 1000);
239 config.Set("default_location_y", 1000);
240 config.Set("grid_send_key", "null");
241 config.Set("grid_recv_key", "null");
242 config.Set("user_send_key", "null");
243 config.Set("user_recv_key", "null");
244 config.Set("secure_inventory_server", "true");
245 }
246
247 return defaultConfig;
248 }
249
250 }
251}