Imports System.IO

Public Class cUserSettings

    Shared settings As New List(Of cListUserSettings)
    Public Shared Sub setProperty(name, value)
        settings = New List(Of cListUserSettings)
        loadPropertys()
        setNewProperty(name, value)
        writesettings()
    End Sub
  
    Public Shared Function getProperty(name) As String
        settings = New List(Of cListUserSettings)
        loadPropertys()
        For Each a In settings
            If a.name = name Then Return a.value
        Next
        Return ""
    End Function


    Shared Sub setNewProperty(name, value)
        For Each a In settings
            If a.name = name Then
                a.value = value
                Exit Sub
            End If
        Next
        'settings.Add(New Dictionary(name, value))

        settings.Add(New cListUserSettings(name, value))
    End Sub
    Shared Sub loadPropertys()
        Try
            Using sr As New StreamReader(AppDomain.CurrentDomain.BaseDirectory & "settings.txt")
                Dim line As String = ""
                Do While sr.Peek() >= 0
                    line = CStr(sr.ReadLine())
                    If line.Contains(Chr(29)) Then
                        Dim s = line.Split(Chr(29)) 'nach GroupSeperator splitten   
                        'If s(0) = name Then Return True
                        settings.Add(New cListUserSettings(s(0), s(1)))
                    End If
                Loop
            End Using
        Catch ex As Exception
            'MsgBox("FEHLER beim Einlesen der UserSettings.")
        End Try
    End Sub
    Shared Sub writesettings()
        Try
            Using sr As New StreamWriter(AppDomain.CurrentDomain.BaseDirectory & "settings.txt", False)
                For Each a In settings
                    sr.WriteLine(a.name & Chr(29) & a.value)
                Next
            End Using
        Catch ex As Exception
        End Try
    End Sub


End Class

Public Class cListUserSettings
    Property name As String
    Property value As String
    Sub New(ByVal n As String, v As String)
        name = n
        value = v
    End Sub
End Class