aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/Util.cs57
1 files changed, 57 insertions, 0 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 97c958a..6f2e7c3 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -1191,6 +1191,63 @@ namespace OpenSim.Framework
1191 return settingsClass; 1191 return settingsClass;
1192 } 1192 }
1193 1193
1194 /// <summary>
1195 /// Reads a configuration file, configFile, merging it with the main configuration, config.
1196 /// If the file doesn't exist, it copies a given exampleConfigFile onto configFile, and then
1197 /// merges it.
1198 /// </summary>
1199 /// <param name="config">The main configuration data</param>
1200 /// <param name="configFileName">The name of a configuration file in ConfigDirectory variable, no path</param>
1201 /// <param name="exampleConfigFile">Full path to an example configuration file</param>
1202 /// <param name="configFilePath">Full path ConfigDirectory/configFileName</param>
1203 /// <param name="created">True if the file was created in ConfigDirectory, false if it existed</param>
1204 /// <returns>True if success</returns>
1205 public static bool MergeConfigurationFile(IConfigSource config, string configFileName, string exampleConfigFile, out string configFilePath, out bool created)
1206 {
1207 created = false;
1208 configFilePath = string.Empty;
1209
1210 IConfig cnf = config.Configs["Startup"];
1211 if (cnf == null)
1212 {
1213 m_log.WarnFormat("[UTILS]: Startup section doesn't exist");
1214 return false;
1215 }
1216
1217 string configDirectory = cnf.GetString("ConfigDirectory", ".");
1218 string configFile = Path.Combine(configDirectory, configFileName);
1219
1220 if (!File.Exists(configFile) && !string.IsNullOrEmpty(exampleConfigFile))
1221 {
1222 // We need to copy the example onto it
1223
1224 if (!Directory.Exists(configDirectory))
1225 Directory.CreateDirectory(configDirectory);
1226
1227 try
1228 {
1229 File.Copy(exampleConfigFile, configFile);
1230 created = true;
1231 }
1232 catch (Exception e)
1233 {
1234 m_log.WarnFormat("[UTILS]: Exception copying configuration file {0} to {1}: {2}", configFile, exampleConfigFile, e.Message);
1235 return false;
1236 }
1237 }
1238
1239 if (File.Exists(configFile))
1240 {
1241 // Merge
1242 config.Merge(new IniConfigSource(configFile));
1243 config.ExpandKeyValues();
1244 configFilePath = configFile;
1245 return true;
1246 }
1247 else
1248 return false;
1249 }
1250
1194 #endregion 1251 #endregion
1195 1252
1196 public static float Clip(float x, float min, float max) 1253 public static float Clip(float x, float min, float max)