示例#1
0
        /// <summary>
        /// Adds the included files as ini configuration files
        /// </summary>
        /// <param name="sources">List of URL strings or filename strings</param>
        /// <param name="cntr">Where should we start inserting sources into the list?</param>
        private void AddIncludes(List <string> sources, ref int cntr)
        {
            int cn = cntr;

            //Where should we insert the sources into the list?
            //loop over config sources
            foreach (IConfig config in m_config.Configs)
            {
                // Look for Include-* in the key name
                string[] keys = config.GetKeys();
                foreach (string k in keys)
                {
                    if (k.StartsWith("Include-"))
                    {
                        // read the config file to be included.
                        string file = config.GetString(k);
                        if (IsUri(file))
                        {
                            if (!sources.Contains(file))
                            {
                                cn++;
                                sources.Insert(cn, file);
                            }
                        }
                        else
                        {
                            string basepath = Util.BasePathCombine("");
                            // Resolve relative paths with wildcards
                            string chunkWithoutWildcards = file;
                            string chunkWithWildcards    = string.Empty;
                            int    wildcardIndex         = file.IndexOfAny(new char[] { '*', '?' });
                            if (wildcardIndex != -1)
                            {
                                chunkWithoutWildcards = file.Substring(0, wildcardIndex);
                                chunkWithWildcards    = file.Substring(wildcardIndex);
                            }
                            string   path  = Path.Combine(basepath, chunkWithoutWildcards + chunkWithWildcards);
                            string[] paths = Util.Glob(path);
                            foreach (string p in paths)
                            {
                                if (!sources.Contains(p))
                                {
                                    cn++;
                                    sources.Insert(cn, p);
                                }
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Provide same ini loader functionality for standard ini and master ini - file system or XML over http
        /// </summary>
        /// <param name="iniPath">Full path to the ini</param>
        /// <returns></returns>
        private bool ReadConfig(string iniPath, int i)
        {
            bool success = false;

            if (!IsUri(iniPath))
            {
                if (showIniLoading)
                {
                    m_log.InfoFormat("[CONFIG]: Reading configuration file {0}", Util.BasePathCombine(iniPath));
                }

                m_config.Merge(new IniConfigSource(iniPath, Nini.Ini.IniFileType.AuroraStyle));
                if (inidbg)
                {
                    WriteConfigFile(i, m_config);
                }
                success = true;
            }
            else
            {
                m_log.InfoFormat("[CONFIG]: {0} is a http:// URI, fetching ...", iniPath);

                // The ini file path is a http URI
                // Try to read it
                try
                {
                    XmlReader       r  = XmlReader.Create(iniPath);
                    XmlConfigSource cs = new XmlConfigSource(r);
                    m_config.Merge(cs);

                    success = true;
                }
                catch (Exception e)
                {
                    m_log.FatalFormat("[CONFIG]: Exception reading config from URI {0}\n" + e.ToString(), iniPath);
                    Environment.Exit(1);
                }
            }
            return(success);
        }
示例#3
0
        /// <summary>
        /// Loads the region configuration
        /// </summary>
        /// <param name="argvSource">Parameters passed into the process when started</param>
        /// <returns>A configuration that gets passed to modules</returns>
        public IConfigSource LoadConfigSettings(IConfigSource argvSource)
        {
            iniFilePath = "";
            bool iniFileExists = false;

            IConfig startupConfig = argvSource.Configs["Startup"];

            List <string> sources = new List <string>();

            inidbg =
                startupConfig.GetBoolean("inidbg", inidbg);

            showIniLoading =
                startupConfig.GetBoolean("inishowfileloading", showIniLoading);

            string masterFileName =
                startupConfig.GetString("inimaster", String.Empty);

            string iniGridName =
                startupConfig.GetString("inigrid", String.Empty);

            if (iniGridName == string.Empty) //Read the old name then
            {
                iniGridName =
                    startupConfig.GetString("inifile", String.Empty);
            }

            string iniSimName =
                startupConfig.GetString("inisim", defaultIniFile);

            //Be mindful of these when modifying...
            //1) When file A includes file B, if the same directive is found in both, that the value in file B wins.
            //2) That inifile may be used with or without inimaster being used.
            //3) That any values for directives pulled in via inifile (Config Set 2) override directives of the same name found in the directive set (Config Set 1) created by reading in bin/Aurora.ini and its subsequently included files or that created by reading in whatever file inimaster points to and its subsequently included files.

            if (IsUri(masterFileName))
            {
                if (!sources.Contains(masterFileName))
                {
                    sources.Add(masterFileName);
                }
            }
            else
            {
                string masterFilePath = Util.BasePathCombine(masterFileName);

                if (masterFileName != String.Empty &&
                    File.Exists(masterFilePath) &&
                    (!sources.Contains(masterFilePath)))
                {
                    sources.Add(masterFilePath);
                }
                if (iniGridName == "") //Then it doesn't exist and we need to set this
                {
                    iniFilePath = masterFilePath;
                }
                if (iniSimName == "") //Then it doesn't exist and we need to set this
                {
                    iniFilePath = masterFilePath;
                }
            }

            if (iniGridName != "")
            {
                if (IsUri(iniGridName))
                {
                    if (!sources.Contains(iniGridName))
                    {
                        sources.Add(iniGridName);
                    }
                    iniFilePath = iniGridName;
                }
                else
                {
                    iniFilePath = Util.BasePathCombine(iniGridName);

                    if (File.Exists(iniFilePath))
                    {
                        if (!sources.Contains(iniFilePath))
                        {
                            sources.Add(iniFilePath);
                        }
                    }
                }
            }

            if (iniSimName != "")
            {
                if (IsUri(iniSimName))
                {
                    if (!sources.Contains(iniSimName))
                    {
                        sources.Add(iniSimName);
                    }
                    iniFilePath = iniSimName;
                }
                else
                {
                    iniFilePath = Util.BasePathCombine(iniSimName);

                    if (File.Exists(iniFilePath))
                    {
                        if (!sources.Contains(iniFilePath))
                        {
                            sources.Add(iniFilePath);
                        }
                    }
                }
            }

            string iniDirName =
                startupConfig.GetString("inidirectory", "");
            string iniDirPath =
                Util.BasePathCombine(iniDirName);

            if (Directory.Exists(iniDirPath) && iniDirName != "")
            {
                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(Util.BasePathCombine(filePath)))
                        {
                            sources.Add(Util.BasePathCombine(filePath));
                        }
                    }
                }
            }


            m_config = new IniConfigSource();

            m_log.Info("[Config]: Reading configuration settings");

            if (sources.Count == 0)
            {
                m_log.FatalFormat("[CONFIG]: Could not load any configuration");
                m_log.FatalFormat("[CONFIG]: Did you copy the " + defaultIniFile + ".example file to " + defaultIniFile + "?");
                throw new NotSupportedException();
            }

            for (int i = 0; i < sources.Count; i++)
            {
                if (ReadConfig(sources[i], i))
                {
                    iniFileExists = true;
                }
                AddIncludes(sources, ref i);
            }

            if (!iniFileExists)
            {
                m_log.FatalFormat("[CONFIG]: Could not load any configuration");
                m_log.FatalFormat("[CONFIG]: Configuration exists, but there was an error loading it!");
                throw new NotSupportedException();
            }
            // Make sure command line options take precedence
            m_config.Merge(argvSource);

            return(m_config);
        }