From 53c8318124b7750f2d8a6e6b67ba447a0b99c2cf Mon Sep 17 00:00:00 2001
From: Diva Canto
Date: Sat, 3 Jan 2015 21:53:18 -0800
Subject: Added utility function that simplifies configuration loading of all
addins.
---
OpenSim/Framework/Util.cs | 57 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
(limited to 'OpenSim/Framework')
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
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)
--
cgit v1.1