Exemple #1
0
        public bool GetValueBool(string name, bool defaultValue)
        {
            var valuePath = getValuePath(name);

            if (XMLUtil.NodeExists(root, valuePath) == false)
            {
                valuePath = getValuePath("Util_" + name);
                if (XMLUtil.NodeExists(root, valuePath) == false)
                {
                    return(defaultValue);
                }
            }
            var  v = XMLUtil.GetNodeValue(root, valuePath);
            bool bret;

            if (string.IsNullOrEmpty(v) || bool.TryParse(v, out bret) == false)
            {
                return(defaultValue);
            }
            else
            {
                return(bret);
            }
        }
Exemple #2
0
        public string GetDefaultSettingValue(string name)
        {
            var valuePath = getValuePath(name);

            return(XMLUtil.GetNodeValue(defaultroot, valuePath));
        }
Exemple #3
0
 public bool HasSetting(string name)
 {
     return(XMLUtil.NodeExists(root, name));
 }
Exemple #4
0
        public void LoadSettings()
        {
            if (xml == null)
            {
                xml = new XmlDocument();
            }
            if (defaultxml == null)
            {
                defaultxml = new XmlDocument();

                if (File.Exists(DefaultSettingFilePath))
                {
                    try
                    {
                        defaultxml.Load(DefaultSettingFilePath);
                        defaultroot = XMLUtil.GetNode(defaultxml, "root");
                    }
                    catch
                    {
                        defaultroot = null;
                    }

                    if (defaultroot == null)
                    {
                        defaultxml  = new XmlDocument();
                        defaultroot = XMLUtil.AddNode(defaultxml, "root");
                    }
                }
                else
                {
                    defaultroot = XMLUtil.AddNode(defaultxml, "root");
                }
            }



            try
            {
                if (SettingFilePath == DefaultSettingFilePath)
                {
                    xml  = defaultxml;
                    root = defaultroot;

                    if (loadSaved)
                    {
                        var lastFile = GetDefaultSettingValue("lastSettingFile");
                        if (!string.IsNullOrEmpty(lastFile) &&
                            File.Exists(lastFile) &&
                            lastFile != DefaultSettingFilePath)
                        {
                            SettingFilePath = lastFile;
                            if (File.Exists(SettingFilePath))
                            {
                                try
                                {
                                    XmlDocument doc = new XmlDocument();
                                    doc.Load(SettingFilePath);
                                    this.xml = doc;
                                    root     = XMLUtil.GetNode(xml, "root");
                                    if (root == null)
                                    {
                                        xml = null;
                                    }
                                }
                                catch { }
                            }
                        }

                        loadSaved = false;
                    }
                }
                else
                {
                    if (root == null)
                    {
                        if (File.Exists(SettingFilePath))
                        {
                            try
                            {
                                XmlDocument x = new XmlDocument();
                                x.Load(SettingFilePath);
                                this.xml = x;
                                root     = XMLUtil.GetNode(xml, "root");
                                if (root == null)
                                {
                                    xml = null;
                                }
                            }
                            catch { }
                        }
                    }
                }
            }
            catch
            {
                xml  = defaultxml;
                root = defaultroot;
            }
        }
 public static XmlNode AddNode(this XmlNode node, string name)
 {
     return(XMLUtil.AddNode(node, name));
 }
 public static XmlAttribute AddAttribute(this XmlNode node, string name, string value)
 {
     return(XMLUtil.AddAttribute(node, name, value));
 }
 public static XmlNode SetValue(this XmlNode node, string value)
 {
     XMLUtil.SetNodeValue(node, value);
     return(node);
 }
 public static XmlNode GetNode(this XmlDocument doc, string xpath)
 {
     return(XMLUtil.GetNode(doc, xpath));
 }