root/lang/vb2005/TenageM/trunk/TenageM/Setting/SettingBase.vb @ 32813

Revision 32813, 1.4 kB (checked in by kiri_feather, 4 years ago)
Line 
1<Serializable()> _
2Public Class SettingBase
3    Private Shared _instance As SettingBase
4
5    Protected Shared Function LoadSettings(ByVal Path As String, ByVal Type As Type) As Object
6        Using fs As New IO.FileStream(Path, IO.FileMode.Open, IO.FileAccess.Read)
7            Dim xs As New Xml.Serialization.XmlSerializer(Type)
8            Return xs.Deserialize(fs)
9        End Using
10    End Function
11
12    Protected Shared Sub SaveSettings(ByVal Path As String, ByVal Instance As Object, ByVal Type As Type)
13        Using fs As New IO.FileStream(Path, IO.FileMode.Create, IO.FileAccess.Write)
14            Dim xs As New Xml.Serialization.XmlSerializer(Type)
15            xs.Serialize(fs, Instance)
16        End Using
17    End Sub
18
19    Protected Shared Function GetSettingFilePath() As String
20        Return IO.Path.Combine(Environment.GetFolderPath( _
21                                    Environment.SpecialFolder.ApplicationData), _
22                                "TenageM\TenageM.config")
23    End Function
24
25    <Xml.Serialization.XmlIgnore()> _
26    Public Shared Property Instance() As SettingBase
27        Get
28            If _instance Is Nothing Then
29                _instance = New AccountSettings
30            End If
31            Return _instance
32        End Get
33        Set(ByVal value As SettingBase)
34            _instance = value
35        End Set
36    End Property
37End Class
Note: See TracBrowser for help on using the browser.