示例#1
0
        /// <summary>
        /// On error: Show message box.
        /// </summary>
        public static void LoadScriptConfig(string configName)
        {
            string configFilePath = CalcScriptConfigFilePath(configName);

            if (!File.Exists(configFilePath))
                return;

            try
            {
                ConfigNode rootNode = new ConfigNode();

                using (StreamReader streamReader = new StreamReader(configFilePath, Encoding.UTF8, true))
                {
                    ConfigReader configReader = new ConfigReader(streamReader);
                    configReader.Process(rootNode);
                }

                foreach (ISerializable s in m_Serializables)
                {
                    string sId = s.GetId();
                    if (!string.IsNullOrEmpty(sId))
                    {
                        ConfigNode sNode = rootNode.FindFirstChild(sId);
                        if (sNode != null)
                            s.LoadFromConfig(sNode);
                    }

                }
            }
            catch (Exception ex)
            {
                ShowError(
                    string.Format("Cannot load script configuration from \"{0}\".", configFilePath),
                    ex);
            }
        }
示例#2
0
        private void LoadGlobalConfig()
        {
            string configFilePath = CalcGlobalConfigFilePath();

            try
            {
                if (File.Exists(configFilePath))
                {
                    using (StreamReader streamReader = new StreamReader(configFilePath, Encoding.UTF8, true))
                    {
                        ConfigReader configReader = new ConfigReader(streamReader);
                        configReader.Process(Lib.GlobalConfig);
                    }

                    PreselectScript();
                }
            }
            catch (Exception ex)
            {
                Lib.ShowError(
                    string.Format("Cannot load global configuration from \"{0}\".", configFilePath),
                    ex);
            }
        }