| | 90 | |
| | 91 | Public Function GetValue(ByVal path As String, ByVal defaultValue As String) As String |
| | 92 | Dim xnode As XmlNode = Me._xrootElement.SelectSingleNode("/tween-configuration/" + path) |
| | 93 | If xnode Is Nothing Then |
| | 94 | Me.SetValue(path, defaultValue) |
| | 95 | Return defaultValue |
| | 96 | Else |
| | 97 | Return xnode.Value |
| | 98 | End If |
| | 99 | End Function |
| | 100 | |
| | 101 | Public Function GetValue(ByVal path As String, ByVal defaultValue As Integer) As Integer |
| | 102 | Dim xnode As XmlNode = Me._xrootElement.SelectSingleNode("/tween-configuration/" + path) |
| | 103 | If xnode Is Nothing Then |
| | 104 | Me.SetValue(path, defaultValue) |
| | 105 | Return defaultValue |
| | 106 | Else |
| | 107 | Return Integer.Parse(xnode.InnerXml) |
| | 108 | End If |
| | 109 | End Function |
| | 110 | |
| | 111 | Public Function GetValue(ByVal path As String, ByVal defaultValue As Boolean) As Boolean |
| | 112 | Dim xnode As XmlNode = Me._xrootElement.SelectSingleNode("/tween-configuration/" + path) |
| | 113 | If xnode Is Nothing Then |
| | 114 | Me.SetValue(path, defaultValue) |
| | 115 | Return defaultValue |
| | 116 | Else |
| | 117 | Return Boolean.Parse(xnode.InnerXml) |
| | 118 | End If |
| | 119 | End Function |
| | 120 | |
| | 121 | Public Function GetValue(ByVal path As String, ByVal defaultValue As Date) As Date |
| | 122 | Dim xnode As XmlNode = Me._xrootElement.SelectSingleNode("/tween-configuration/" + path) |
| | 123 | If xnode Is Nothing Then |
| | 124 | Me.SetValue(path, defaultValue) |
| | 125 | Return defaultValue |
| | 126 | Else |
| | 127 | Return Date.Parse(xnode.InnerXml) |
| | 128 | End If |
| | 129 | End Function |
| | 130 | |
| | 131 | Public Function GetElement(ByVal path As String) As XmlElement |
| | 132 | Dim xnode As XmlNode = Me._xrootElement.SelectSingleNode("/tween-configuration/" + path) |
| | 133 | If xnode Is Nothing Then |
| | 134 | Me.RetrievePath(path) |
| | 135 | Return Nothing |
| | 136 | Else |
| | 137 | Return DirectCast(xnode, XmlElement) |
| | 138 | End If |
| | 139 | End Function |
| | 140 | |
| | 141 | Public Sub SetValue(ByVal path As String, ByVal value As String) |
| | 142 | Me.RetrievePath(path).SetValue(value) |
| | 143 | End Sub |
| | 144 | |
| | 145 | Public Sub SetValue(ByVal path As String, ByVal value As Integer) |
| | 146 | Me.RetrievePath(path).SetValue(value.ToString()) |
| | 147 | End Sub |
| | 148 | |
| | 149 | Public Sub SetValue(ByVal path As String, ByVal value As Boolean) |
| | 150 | Me.RetrievePath(path).SetValue(value.ToString()) |
| | 151 | End Sub |
| | 152 | |
| | 153 | Public Sub SetValue(ByVal path As String, ByVal value As DateTime) |
| | 154 | Me.RetrievePath(path).SetValue(value.ToString()) |
| | 155 | End Sub |
| | 156 | |
| | 157 | Public Sub SetElement(ByVal path As String, ByVal xelement As XmlElement) |
| | 158 | Me.RetrievePath(path).ReplaceSelf(xelement.ToString()) |
| | 159 | End Sub |
| | 160 | |
| | 161 | Public Sub LoadConfiguration(ByVal fileName As String) |
| | 162 | Dim xdocument As XmlDocument = New XmlDocument() |
| | 163 | If IO.File.Exists(fileName) Then |
| | 164 | xdocument.Load(fileName) |
| | 165 | Else |
| | 166 | xdocument.AppendChild(xdocument.CreateXmlDeclaration("1.0", "utf-8", Nothing)) |
| | 167 | xdocument.AppendChild(xdocument.CreateComment("���̐ݒ��@�C����Tween �ɂ������������������B�蓮�ŕύX���Ȃ��ł��������B")) |
| | 168 | xdocument.AppendChild(xdocument.CreateElement("tween-configuration")) |
| | 169 | xdocument.Save(fileName) |
| | 170 | End If |
| | 171 | Me._xrootElement = xdocument.DocumentElement |
| | 172 | End Sub |
| | 173 | |
| | 174 | Public Sub SaveConfiguration(ByVal fileName As String) |
| | 175 | Me._xrootElement.OwnerDocument.Save(fileName) |
| | 176 | Me.LoadConfiguration(fileName) |
| | 177 | End Sub |
| | 178 | |
| | 179 | Private Function RetrievePath(ByVal path As String) As XPath.XPathNavigator |
| | 180 | Dim xnav As XPath.XPathNavigator = Me._xrootElement.OwnerDocument.CreateNavigator() |
| | 181 | xnav = xnav.SelectSingleNode("/tween-configuration") |
| | 182 | For Each fragment As String In path.Split(New Char() {"/"c}, StringSplitOptions.RemoveEmptyEntries) |
| | 183 | If (xnav.SelectSingleNode(fragment) Is Nothing) Then |
| | 184 | xnav.AppendChildElement("", fragment, Nothing, Nothing) |
| | 185 | End If |
| | 186 | xnav = xnav.SelectSingleNode(fragment) |
| | 187 | Next |
| | 188 | Return xnav |
| | 189 | End Function |