diff options
author | Justin Clarke Casey | 2009-02-17 17:12:10 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2009-02-17 17:12:10 +0000 |
commit | af57937760ed2be917e0920ac0def6a83e00efe3 (patch) | |
tree | e0df02145fa75ac2f9ac911ae1549f202bda6a31 /OpenSim/Region/Application | |
parent | * switch to pulsing monitors to perform test sync instead of events, since th... (diff) | |
download | opensim-SC_OLD-af57937760ed2be917e0920ac0def6a83e00efe3.zip opensim-SC_OLD-af57937760ed2be917e0920ac0def6a83e00efe3.tar.gz opensim-SC_OLD-af57937760ed2be917e0920ac0def6a83e00efe3.tar.bz2 opensim-SC_OLD-af57937760ed2be917e0920ac0def6a83e00efe3.tar.xz |
* Apply http://opensimulator.org/mantis/view.php?id=3068
* This enables parsing of xml files and files obtained via http for the -inimaster option as well as -inifile
* Thanks StrawberryFride!
Diffstat (limited to 'OpenSim/Region/Application')
-rw-r--r-- | OpenSim/Region/Application/ConfigurationLoader.cs | 132 |
1 files changed, 68 insertions, 64 deletions
diff --git a/OpenSim/Region/Application/ConfigurationLoader.cs b/OpenSim/Region/Application/ConfigurationLoader.cs index 638125c..f0c57e0 100644 --- a/OpenSim/Region/Application/ConfigurationLoader.cs +++ b/OpenSim/Region/Application/ConfigurationLoader.cs | |||
@@ -66,105 +66,109 @@ namespace OpenSim | |||
66 | m_config.Source = new IniConfigSource(); | 66 | m_config.Source = new IniConfigSource(); |
67 | m_config.Source.Merge(DefaultConfig()); | 67 | m_config.Source.Merge(DefaultConfig()); |
68 | 68 | ||
69 | m_log.Info("Reading in config files now"); | 69 | m_log.Info("[CONFIG] Reading configuration settings"); |
70 | |||
71 | Uri configUri; | ||
72 | String xmlPath = Path.Combine(Util.configDir(), "OpenSim.xml"); | ||
70 | 73 | ||
71 | //check for master .INI file (name passed in command line, no default) | 74 | //check for master .INI file (name passed in command line, no default), or XML over http |
72 | if (masterFileName.Length != 0) // If a master file name is given ... | 75 | if (masterFileName.Length > 0) // If a master file name is given ... |
73 | { | 76 | { |
74 | m_log.InfoFormat("[CONFIG] Reading config master file {0}", Path.GetFullPath(masterfilePath)); | 77 | m_log.InfoFormat("[CONFIG] Reading config master file {0}", masterfilePath); |
75 | if (File.Exists(masterfilePath)) | 78 | |
76 | { | 79 | bool isMasterUri = Uri.TryCreate(masterFileName, UriKind.Absolute, out configUri) && configUri.Scheme == Uri.UriSchemeHttp; |
77 | m_config.Source.Merge(new IniConfigSource(masterfilePath)); | 80 | |
78 | } | 81 | if (!ReadConfig(masterFileName, masterfilePath, m_config, isMasterUri)) |
79 | else | ||
80 | { | 82 | { |
81 | // IF(!) a master file is given it must exist, be readable, ...... | ||
82 | // Otherwise the application will hickup | ||
83 | m_log.FatalFormat("[CONFIG] Could not open master config file {0}", masterfilePath); | 83 | m_log.FatalFormat("[CONFIG] Could not open master config file {0}", masterfilePath); |
84 | Environment.Exit(1); | ||
85 | } | 84 | } |
86 | } | 85 | } |
87 | 86 | ||
88 | // Check for .INI file (either default or name passed on command | 87 | // Check for .INI file (either default or name passed on command |
89 | // line) or XML config source | 88 | // line) or XML config source over http |
90 | // | 89 | bool isIniUri = Uri.TryCreate(iniFileName, UriKind.Absolute, out configUri) && configUri.Scheme == Uri.UriSchemeHttp; |
91 | String xmlPath = Path.Combine(Util.configDir(), "OpenSim.xml"); | 90 | iniFileExists = ReadConfig(iniFileName, Application.iniFilePath, m_config, isIniUri); |
92 | bool isUri = false; | ||
93 | Uri configUri; | ||
94 | 91 | ||
95 | if (Uri.TryCreate(startupConfig.GetString("inifile", "OpenSim.ini"), UriKind.Absolute, out configUri) && configUri.Scheme == Uri.UriSchemeHttp) | 92 | if (!iniFileExists) |
96 | { | 93 | { |
97 | isUri = true; | 94 | // check for a xml config file |
98 | } | 95 | if (File.Exists(xmlPath)) |
96 | { | ||
97 | Application.iniFilePath = xmlPath; | ||
98 | |||
99 | m_log.InfoFormat("Reading XML configuration from {0}", Path.GetFullPath(xmlPath)); | ||
100 | iniFileExists = true; | ||
101 | |||
102 | m_config.Source = new XmlConfigSource(); | ||
103 | m_config.Source.Merge(new XmlConfigSource(Application.iniFilePath)); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | m_config.Source.Merge(configSource); | ||
99 | 108 | ||
100 | if (!isUri && File.Exists(Application.iniFilePath)) | 109 | if (!iniFileExists) |
101 | { | 110 | { |
102 | m_log.InfoFormat("[CONFIG] Reading configuration file {0}", Path.GetFullPath(Application.iniFilePath)); | 111 | m_log.FatalFormat("[CONFIG] Could not load any configuration"); |
112 | if (!isIniUri) | ||
113 | m_log.FatalFormat("[CONFIG] Tried to load {0}, ", Path.GetFullPath(Application.iniFilePath)); | ||
114 | else | ||
115 | m_log.FatalFormat("[CONFIG] Tried to load from URI {0}, ", iniFileName); | ||
116 | m_log.FatalFormat("[CONFIG] and XML source {0}", Path.GetFullPath(xmlPath)); | ||
103 | 117 | ||
104 | iniFileExists = true; | 118 | m_log.FatalFormat("[CONFIG] Did you copy the OpenSim.ini.example file to OpenSim.ini?"); |
119 | Environment.Exit(1); | ||
120 | } | ||
121 | |||
122 | ReadConfigSettings(); | ||
123 | |||
124 | return m_config; | ||
125 | } | ||
126 | |||
127 | /// <summary> | ||
128 | /// Provide same ini loader functionality for standard ini and master ini - file system or XML over http | ||
129 | /// </summary> | ||
130 | /// <param name="iniName">The name of the ini to load</param> | ||
131 | /// <param name="iniPath">Full path to the ini</param> | ||
132 | /// <param name="m_config">The current configuration source</param> | ||
133 | /// <param name="isUri">Boolean representing whether the ini source is a URI path over http or a file on the system</param> | ||
134 | /// <returns></returns> | ||
135 | private bool ReadConfig(string iniName, string iniPath, OpenSimConfigSource m_config, bool isUri) | ||
136 | { | ||
137 | bool success = false; | ||
138 | |||
139 | if (!isUri && File.Exists(iniPath)) | ||
140 | { | ||
141 | m_log.InfoFormat("[CONFIG] Reading configuration file {0}", Path.GetFullPath(iniPath)); | ||
105 | 142 | ||
106 | // From reading Nini's code, it seems that later merged keys replace earlier ones. | 143 | // From reading Nini's code, it seems that later merged keys replace earlier ones. |
107 | m_config.Source.Merge(new IniConfigSource(Application.iniFilePath)); | 144 | m_config.Source.Merge(new IniConfigSource(iniPath)); |
145 | success = true; | ||
108 | } | 146 | } |
109 | else | 147 | else |
110 | { | 148 | { |
111 | if (isUri) | 149 | if (isUri) |
112 | { | 150 | { |
113 | m_log.InfoFormat("[CONFIG] {0} is a http:// URI, fetching ...", startupConfig.GetString("inifile", "OpenSim.ini")); | 151 | m_log.InfoFormat("[CONFIG] {0} is a http:// URI, fetching ...", iniName); |
114 | 152 | ||
115 | // The ini file path is a http URI | 153 | // The ini file path is a http URI |
116 | // Try to read it | 154 | // Try to read it |
117 | // | ||
118 | try | 155 | try |
119 | { | 156 | { |
120 | XmlReader r = XmlReader.Create(startupConfig.GetString("inifile", "OpenSim.ini")); | 157 | XmlReader r = XmlReader.Create(iniName); |
121 | XmlConfigSource cs = new XmlConfigSource(r); | 158 | XmlConfigSource cs = new XmlConfigSource(r); |
122 | m_config.Source.Merge(cs); | 159 | m_config.Source.Merge(cs); |
123 | 160 | ||
124 | iniFileExists = true; | 161 | success = true; |
125 | m_log.InfoFormat("[CONFIG] Loaded config from {0}", startupConfig.GetString("inifile", "OpenSim.ini")); | 162 | m_log.InfoFormat("[CONFIG] Loaded config from {0}", iniName); |
126 | } | 163 | } |
127 | catch (Exception e) | 164 | catch (Exception e) |
128 | { | 165 | { |
129 | m_log.FatalFormat("[CONFIG] Exception reading config from URI {0}\n" + e.ToString(), startupConfig.GetString("inifile", "OpenSim.ini")); | 166 | m_log.FatalFormat("[CONFIG] Exception reading config from URI {0}\n" + e.ToString(), iniName); |
130 | Environment.Exit(1); | 167 | Environment.Exit(1); |
131 | } | 168 | } |
132 | } | 169 | } |
133 | else | ||
134 | { | ||
135 | // check for a xml config file | ||
136 | |||
137 | if (File.Exists(xmlPath)) | ||
138 | { | ||
139 | Application.iniFilePath = xmlPath; | ||
140 | |||
141 | m_log.InfoFormat("Reading XML configuration from {0}", Path.GetFullPath(xmlPath)); | ||
142 | iniFileExists = true; | ||
143 | |||
144 | m_config.Source = new XmlConfigSource(); | ||
145 | m_config.Source.Merge(new XmlConfigSource(Application.iniFilePath)); | ||
146 | } | ||
147 | } | ||
148 | } | 170 | } |
149 | 171 | return success; | |
150 | m_config.Source.Merge(configSource); | ||
151 | |||
152 | if (!iniFileExists) | ||
153 | { | ||
154 | m_log.FatalFormat("[CONFIG] Could not load any configuration"); | ||
155 | if (!isUri) | ||
156 | m_log.FatalFormat("[CONFIG] Tried to load {0}, ", Path.GetFullPath(Application.iniFilePath)); | ||
157 | else | ||
158 | m_log.FatalFormat("[CONFIG] Tried to load from URI {0}, ", startupConfig.GetString("inifile", "OpenSim.ini")); | ||
159 | m_log.FatalFormat("[CONFIG] and XML source {0}", Path.GetFullPath(xmlPath)); | ||
160 | |||
161 | m_log.FatalFormat("[CONFIG] Did you copy the OpenSim.ini.example file to OpenSim.ini?"); | ||
162 | Environment.Exit(1); | ||
163 | } | ||
164 | |||
165 | ReadConfigSettings(); | ||
166 | |||
167 | return m_config; | ||
168 | } | 172 | } |
169 | 173 | ||
170 | /// <summary> | 174 | /// <summary> |