Implement .ini file includes. Anything that begins with "Include-" will be
treated as another ini source to load. For example: Include-Asset = AssetSetup.ini will load AssetSetup.ini after all other ini files are done. This works recursively, too0.6.6-post-fixes
							parent
							
								
									a85f496f4d
								
							
						
					
					
						commit
						e5f3337c3f
					
				|  | @ -66,7 +66,7 @@ namespace OpenSim.Framework.Console | |||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     System.Console.WriteLine(loggingMessage); | ||||
|                     System.Console.Write(loggingMessage); | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception e) | ||||
|  |  | |||
|  | @ -49,6 +49,7 @@ namespace OpenSim.Framework.Console | |||
|         private List<string> m_Scrollback = new List<string>(); | ||||
|         private ManualResetEvent m_DataEvent = new ManualResetEvent(false); | ||||
|         private List<string> m_InputData = new List<string>(); | ||||
|         private uint m_LineNumber = 1; | ||||
| 
 | ||||
|         public RemoteConsole(string defaultPrompt) : base(defaultPrompt) | ||||
|         { | ||||
|  | @ -70,7 +71,8 @@ namespace OpenSim.Framework.Console | |||
|             { | ||||
|                 while (m_Scrollback.Count >= 1000) | ||||
|                     m_Scrollback.RemoveAt(0); | ||||
|                 m_Scrollback.Add(level+":"+text); | ||||
|                 m_Scrollback.Add(String.Format("{0}", m_LineNumber)+":"+level+":"+text); | ||||
|                 m_LineNumber++; | ||||
|             } | ||||
|             System.Console.Write(text); | ||||
|         } | ||||
|  |  | |||
|  | @ -26,6 +26,7 @@ | |||
|  */ | ||||
| 
 | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.IO; | ||||
| using System.Reflection; | ||||
| using System.Threading; | ||||
|  | @ -42,29 +43,95 @@ namespace OpenSim | |||
|         protected OpenSimConfigSource m_config; | ||||
|         protected NetworkServersInfo m_networkServersInfo; | ||||
| 
 | ||||
|         private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||||
|         private static readonly ILog m_log = | ||||
|                 LogManager.GetLogger( | ||||
|                 MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         public ConfigurationLoader() | ||||
|         { | ||||
|         } | ||||
| 
 | ||||
|         public OpenSimConfigSource LoadConfigSettings(IConfigSource configSource, out ConfigSettings configSettings, | ||||
|                                                       out NetworkServersInfo networkInfo) | ||||
|         public OpenSimConfigSource LoadConfigSettings( | ||||
|                 IConfigSource argvSource, out ConfigSettings configSettings, | ||||
|                 out NetworkServersInfo networkInfo) | ||||
|         { | ||||
|             m_configSettings = configSettings = new ConfigSettings(); | ||||
|             m_networkServersInfo = networkInfo = new NetworkServersInfo(); | ||||
| 
 | ||||
|             bool iniFileExists = false; | ||||
| 
 | ||||
|             IConfig startupConfig = configSource.Configs["Startup"]; | ||||
|             IConfig startupConfig = argvSource.Configs["Startup"]; | ||||
| 
 | ||||
|             string iniFileName = startupConfig.GetString("inifile", "OpenSim.ini"); | ||||
|             Application.iniFilePath = Path.Combine(Util.configDir(), iniFileName); | ||||
|             List<string> sources = new List<string>(); | ||||
| 
 | ||||
|             string masterFileName = startupConfig.GetString("inimaster", ""); | ||||
|             string masterfilePath = Path.Combine(Util.configDir(), masterFileName); | ||||
|             string masterFileName = | ||||
|                     startupConfig.GetString("inimaster", String.Empty); | ||||
| 
 | ||||
|             string iniDirName = startupConfig.GetString("inidirectory", "config"); | ||||
|             //string iniDirPath = Path.Combine(Util.configDir(), iniDirName); | ||||
|             if (IsUri(masterFileName)) | ||||
|             { | ||||
|                 if (!sources.Contains(masterFileName)) | ||||
|                     sources.Add(masterFileName); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 string masterFilePath = Path.GetFullPath( | ||||
|                         Path.Combine(Util.configDir(), masterFileName)); | ||||
| 
 | ||||
|                 if (masterFileName != String.Empty && | ||||
|                         File.Exists(masterFilePath) && | ||||
|                         (!sources.Contains(masterFilePath))) | ||||
|                     sources.Add(masterFilePath); | ||||
|             } | ||||
| 
 | ||||
| 
 | ||||
|             string iniFileName = | ||||
|                     startupConfig.GetString("inifile", "OpenSim.ini"); | ||||
| 
 | ||||
|             if (IsUri(iniFileName)) | ||||
|             { | ||||
|                 if (!sources.Contains(iniFileName)) | ||||
|                     sources.Add(iniFileName); | ||||
|                 Application.iniFilePath = iniFileName; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 Application.iniFilePath = Path.GetFullPath( | ||||
|                         Path.Combine(Util.configDir(), iniFileName)); | ||||
| 
 | ||||
|                 if (!File.Exists(Application.iniFilePath)) | ||||
|                 { | ||||
|                     iniFileName = "OpenSim.xml"; | ||||
|                     Application.iniFilePath = Path.GetFullPath( | ||||
|                             Path.Combine(Util.configDir(), iniFileName)); | ||||
|                 } | ||||
| 
 | ||||
|                 if (File.Exists(Application.iniFilePath)) | ||||
|                 { | ||||
|                     if (!sources.Contains(Application.iniFilePath)) | ||||
|                         sources.Add(Application.iniFilePath); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             string iniDirName = | ||||
|                     startupConfig.GetString("inidirectory", "config"); | ||||
|             string iniDirPath = | ||||
|                     Path.Combine(Util.configDir(), iniDirName); | ||||
| 
 | ||||
|             if (Directory.Exists(iniDirPath)) | ||||
|             { | ||||
|                 m_log.InfoFormat("Searching folder {0} for config ini files", | ||||
|                         iniDirPath); | ||||
| 
 | ||||
|                 string[] fileEntries = Directory.GetFiles(iniDirName); | ||||
|                 foreach (string filePath in fileEntries) | ||||
|                 { | ||||
|                     if (Path.GetExtension(filePath).ToLower() == ".ini") | ||||
|                     { | ||||
|                         if (!sources.Contains(Path.GetFullPath(filePath))) | ||||
|                             sources.Add(Path.GetFullPath(filePath)); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             m_config = new OpenSimConfigSource(); | ||||
|             m_config.Source = new IniConfigSource(); | ||||
|  | @ -72,70 +139,24 @@ namespace OpenSim | |||
| 
 | ||||
|             m_log.Info("[CONFIG] Reading configuration settings"); | ||||
| 
 | ||||
|             Uri configUri; | ||||
|             String xmlPath = Path.Combine(Util.configDir(), "OpenSim.xml"); | ||||
| 
 | ||||
|             //check for master .INI file (name passed in command line, no default), or XML over http | ||||
|             if (masterFileName.Length > 0) // If a master file name is given ... | ||||
|             if (sources.Count == 0) | ||||
|             { | ||||
|                 m_log.InfoFormat("[CONFIG] Reading config master file {0}", masterfilePath); | ||||
| 
 | ||||
|                 bool isMasterUri = Uri.TryCreate(masterFileName, UriKind.Absolute, out configUri) && | ||||
|                                    configUri.Scheme == Uri.UriSchemeHttp; | ||||
| 
 | ||||
|                 if (!ReadConfig(masterFileName, masterfilePath, m_config, isMasterUri)) | ||||
|                 { | ||||
|                     m_log.FatalFormat("[CONFIG] Could not open master config file {0}", masterfilePath); | ||||
|                 } | ||||
|                 m_log.FatalFormat("[CONFIG] Could not load any configuration"); | ||||
|                 m_log.FatalFormat("[CONFIG] Did you copy the OpenSim.ini.example file to OpenSim.ini?"); | ||||
|                 Environment.Exit(1); | ||||
|             } | ||||
| 
 | ||||
|             if (Directory.Exists(iniDirName)) | ||||
|             for (int i = 0 ; i < sources.Count ; i++) | ||||
|             { | ||||
|                 m_log.InfoFormat("Searching folder: {0} , for config ini files", iniDirName); | ||||
|                 string[] fileEntries = Directory.GetFiles(iniDirName); | ||||
|                 foreach (string filePath in fileEntries) | ||||
|                 { | ||||
|                     if (Path.GetExtension(filePath).ToLower() == ".ini") | ||||
|                     { | ||||
|                         // m_log.InfoFormat("reading ini file < {0} > from config dir", filePath); | ||||
|                         ReadConfig(Path.GetFileName(filePath), filePath, m_config, false); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             // Check for .INI file (either default or name passed on command | ||||
|             // line) or XML config source over http | ||||
|             bool isIniUri = Uri.TryCreate(iniFileName, UriKind.Absolute, out configUri) && | ||||
|                             configUri.Scheme == Uri.UriSchemeHttp; | ||||
|             iniFileExists = ReadConfig(iniFileName, Application.iniFilePath, m_config, isIniUri); | ||||
| 
 | ||||
|             if (!iniFileExists) | ||||
|             { | ||||
|                 // check for a xml config file                                 | ||||
|                 if (File.Exists(xmlPath)) | ||||
|                 { | ||||
|                     Application.iniFilePath = xmlPath; | ||||
| 
 | ||||
|                     m_log.InfoFormat("Reading XML configuration from {0}", Path.GetFullPath(xmlPath)); | ||||
|                 if (ReadConfig(sources[i])) | ||||
|                     iniFileExists = true; | ||||
| 
 | ||||
|                     m_config.Source = new XmlConfigSource(); | ||||
|                     m_config.Source.Merge(new XmlConfigSource(Application.iniFilePath)); | ||||
|                 } | ||||
|                 AddIncludes(sources); | ||||
|             } | ||||
| 
 | ||||
|             m_config.Source.Merge(configSource); | ||||
| 
 | ||||
|             if (!iniFileExists) | ||||
|             { | ||||
|                 m_log.FatalFormat("[CONFIG] Could not load any configuration"); | ||||
|                 if (!isIniUri) | ||||
|                     m_log.FatalFormat("[CONFIG] Tried to load {0}, ", Path.GetFullPath(Application.iniFilePath)); | ||||
|                 else | ||||
|                     m_log.FatalFormat("[CONFIG] Tried to load from URI {0}, ", iniFileName); | ||||
|                 m_log.FatalFormat("[CONFIG] and XML source {0}", Path.GetFullPath(xmlPath)); | ||||
| 
 | ||||
|                 m_log.FatalFormat("[CONFIG] Did you copy the OpenSim.ini.example file to OpenSim.ini?"); | ||||
|                 m_log.FatalFormat("[CONFIG] Configuration exists, but there was an error loading it!"); | ||||
|                 Environment.Exit(1); | ||||
|             } | ||||
| 
 | ||||
|  | @ -144,48 +165,81 @@ namespace OpenSim | |||
|             return m_config; | ||||
|         } | ||||
| 
 | ||||
|         private void AddIncludes(List<string> sources) | ||||
|         { | ||||
|             foreach (IConfig config in m_config.Source.Configs) | ||||
|             { | ||||
|                 string[] keys = config.GetKeys(); | ||||
|                 foreach (string k in keys) | ||||
|                 { | ||||
|                     if (k.StartsWith("Include-")) | ||||
|                     { | ||||
|                         string file = config.GetString(k); | ||||
|                         if (IsUri(file)) | ||||
|                         { | ||||
|                             if (!sources.Contains(file)) | ||||
|                                 sources.Add(file); | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                             string path = Path.GetFullPath( | ||||
|                                     Path.Combine(Util.configDir(), file)); | ||||
|                             if (File.Exists(path)) | ||||
|                             { | ||||
|                                 if (!sources.Contains(path)) | ||||
|                                     sources.Add(path); | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         bool IsUri(string file) | ||||
|         { | ||||
|             Uri configUri; | ||||
| 
 | ||||
|             return Uri.TryCreate(file, UriKind.Absolute, | ||||
|                     out configUri) && configUri.Scheme == Uri.UriSchemeHttp; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Provide same ini loader functionality for standard ini and master ini - file system or XML over http | ||||
|         /// </summary> | ||||
|         /// <param name="iniName">The name of the ini to load</param> | ||||
|         /// <param name="iniPath">Full path to the ini</param> | ||||
|         /// <param name="m_config">The current configuration source</param> | ||||
|         /// <param name="isUri">Boolean representing whether the ini source is a URI path over http or a file on the system</param> | ||||
|         /// <returns></returns> | ||||
|         private bool ReadConfig(string iniName, string iniPath, OpenSimConfigSource m_config, bool isUri) | ||||
|         private bool ReadConfig(string iniPath) | ||||
|         { | ||||
|             bool success = false; | ||||
| 
 | ||||
|             if (!isUri && File.Exists(iniPath)) | ||||
|             if (!IsUri(iniPath)) | ||||
|             { | ||||
|                 m_log.InfoFormat("[CONFIG] Reading configuration file {0}", Path.GetFullPath(iniPath)); | ||||
|                 m_log.InfoFormat("[CONFIG] Reading configuration file {0}", | ||||
|                         Path.GetFullPath(iniPath)); | ||||
| 
 | ||||
|                 // From reading Nini's code, it seems that later merged keys replace earlier ones.                 | ||||
|                 m_config.Source.Merge(new IniConfigSource(iniPath)); | ||||
|                 success = true; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 if (isUri) | ||||
|                 m_log.InfoFormat("[CONFIG] {0} is a http:// URI, fetching ...", | ||||
|                         iniPath); | ||||
| 
 | ||||
|                 // The ini file path is a http URI | ||||
|                 // Try to read it | ||||
|                 // | ||||
|                 try | ||||
|                 { | ||||
|                     m_log.InfoFormat("[CONFIG] {0} is a http:// URI, fetching ...", iniName); | ||||
|                     XmlReader r = XmlReader.Create(iniPath); | ||||
|                     XmlConfigSource cs = new XmlConfigSource(r); | ||||
|                     m_config.Source.Merge(cs); | ||||
| 
 | ||||
|                     // The ini file path is a http URI | ||||
|                     // Try to read it | ||||
|                     try | ||||
|                     { | ||||
|                         XmlReader r = XmlReader.Create(iniName); | ||||
|                         XmlConfigSource cs = new XmlConfigSource(r); | ||||
|                         m_config.Source.Merge(cs); | ||||
| 
 | ||||
|                         success = true; | ||||
|                         m_log.InfoFormat("[CONFIG] Loaded config from {0}", iniName); | ||||
|                     } | ||||
|                     catch (Exception e) | ||||
|                     { | ||||
|                         m_log.FatalFormat("[CONFIG] Exception reading config from URI {0}\n" + e.ToString(), iniName); | ||||
|                         Environment.Exit(1); | ||||
|                     } | ||||
|                     success = true; | ||||
|                 } | ||||
|                 catch (Exception e) | ||||
|                 { | ||||
|                     m_log.FatalFormat("[CONFIG] Exception reading config from URI {0}\n" + e.ToString(), iniPath); | ||||
|                     Environment.Exit(1); | ||||
|                 } | ||||
|             } | ||||
|             return success; | ||||
|  | @ -195,7 +249,7 @@ namespace OpenSim | |||
|         /// Setup a default config values in case they aren't present in the ini file | ||||
|         /// </summary> | ||||
|         /// <returns></returns> | ||||
|         public static IConfigSource DefaultConfig() | ||||
|         private static IConfigSource DefaultConfig() | ||||
|         { | ||||
|             IConfigSource defaultConfig = new IniConfigSource(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -490,9 +490,6 @@ namespace OpenSim | |||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                             // IConfig c = DefaultConfig().Configs[cmdparams[1]]; | ||||
|                             // if (c == null) | ||||
|                             //     c = DefaultConfig().AddConfig(cmdparams[1]); | ||||
|                             IConfig c; | ||||
|                             IConfigSource source = new IniConfigSource(); | ||||
|                             c = source.AddConfig(cmdparams[1]); | ||||
|  | @ -516,7 +513,7 @@ namespace OpenSim | |||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                             IConfig c = m_config.Source.Configs[cmdparams[1]]; // DefaultConfig().Configs[cmdparams[1]]; | ||||
|                             IConfig c = m_config.Source.Configs[cmdparams[1]]; | ||||
|                             if (c == null) | ||||
|                             { | ||||
|                                 m_log.Info("Section \"" + cmdparams[1] + "\" does not exist."); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 Melanie Thielker
						Melanie Thielker