コード例 #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);
            }
        }
コード例 #2
0
        public string GetDefaultSettingValue(string name)
        {
            var valuePath = getValuePath(name);

            return(XMLUtil.GetNodeValue(defaultroot, valuePath));
        }
コード例 #3
0
 public bool HasSetting(string name)
 {
     return(XMLUtil.NodeExists(root, name));
 }
コード例 #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;
            }
        }
コード例 #5
0
 public static XmlNode AddNode(this XmlNode node, string name)
 {
     return(XMLUtil.AddNode(node, name));
 }
コード例 #6
0
 public static XmlAttribute AddAttribute(this XmlNode node, string name, string value)
 {
     return(XMLUtil.AddAttribute(node, name, value));
 }
コード例 #7
0
 public static XmlNode SetValue(this XmlNode node, string value)
 {
     XMLUtil.SetNodeValue(node, value);
     return(node);
 }
コード例 #8
0
 public static XmlNode GetNode(this XmlDocument doc, string xpath)
 {
     return(XMLUtil.GetNode(doc, xpath));
 }