Ejemplo n.º 1
0
        /// <summary>
        /// On error: Show message box.
        /// </summary>
        public static void SaveScriptConfig(string configName)
        {
            string configFilePath = CalcScriptConfigFilePath(configName);

            try
            {
                ConfigNode rootNode = new ConfigNode();

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

                using (StreamWriter streamWriter = new StreamWriter(configFilePath, false, Encoding.UTF8))
                {
                    ConfigWriter configWriter = new ConfigWriter(streamWriter);
                    configWriter.Process(rootNode);
                }
            }
            catch (Exception ex)
            {
                ShowError(
                    string.Format("Cannot save script configuration to \"{0}\".", configFilePath),
                    ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// On error: Show message box.
        /// </summary>
        private void SaveGlobalConfig()
        {
            string configFilePath = CalcGlobalConfigFilePath();

            try
            {
                if (m_ScriptsListView.SelectedItems.Count == 1)
                    Lib.GlobalConfig.SetValue(CONFIG_SELECTED_SCRIPT, m_ScriptsListView.SelectedItems[0].Text);

                using (StreamWriter streamWriter = new StreamWriter(configFilePath, false, Encoding.UTF8))
                {
                    ConfigWriter configWriter = new ConfigWriter(streamWriter);
                    configWriter.Process(Lib.GlobalConfig);
                }
            }
            catch (Exception ex)
            {
                Lib.ShowError(
                    string.Format("Cannot save global configuration to \"{0}\".", configFilePath),
                    ex);
            }
        }