diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 97c958a0f3..6f2e7c3e24 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -1191,6 +1191,63 @@ namespace OpenSim.Framework
return settingsClass;
}
+ ///
+ /// Reads a configuration file, configFile, merging it with the main configuration, config.
+ /// If the file doesn't exist, it copies a given exampleConfigFile onto configFile, and then
+ /// merges it.
+ ///
+ /// The main configuration data
+ /// The name of a configuration file in ConfigDirectory variable, no path
+ /// Full path to an example configuration file
+ /// Full path ConfigDirectory/configFileName
+ /// True if the file was created in ConfigDirectory, false if it existed
+ /// True if success
+ public static bool MergeConfigurationFile(IConfigSource config, string configFileName, string exampleConfigFile, out string configFilePath, out bool created)
+ {
+ created = false;
+ configFilePath = string.Empty;
+
+ IConfig cnf = config.Configs["Startup"];
+ if (cnf == null)
+ {
+ m_log.WarnFormat("[UTILS]: Startup section doesn't exist");
+ return false;
+ }
+
+ string configDirectory = cnf.GetString("ConfigDirectory", ".");
+ string configFile = Path.Combine(configDirectory, configFileName);
+
+ if (!File.Exists(configFile) && !string.IsNullOrEmpty(exampleConfigFile))
+ {
+ // We need to copy the example onto it
+
+ if (!Directory.Exists(configDirectory))
+ Directory.CreateDirectory(configDirectory);
+
+ try
+ {
+ File.Copy(exampleConfigFile, configFile);
+ created = true;
+ }
+ catch (Exception e)
+ {
+ m_log.WarnFormat("[UTILS]: Exception copying configuration file {0} to {1}: {2}", configFile, exampleConfigFile, e.Message);
+ return false;
+ }
+ }
+
+ if (File.Exists(configFile))
+ {
+ // Merge
+ config.Merge(new IniConfigSource(configFile));
+ config.ExpandKeyValues();
+ configFilePath = configFile;
+ return true;
+ }
+ else
+ return false;
+ }
+
#endregion
public static float Clip(float x, float min, float max)