Attribute VB_Name = "modSettings"
'By the BWW-IRC Team. Distributed under the GPL.

'Declears Varibles
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

Public Function WriteValue(key As String, value As String)
'Writes value from INI file
    Call WritePrivateProfileString("BWW-IRC", key, value, App.Path + "\Settings\" + "BWWIRC.ini")
End Function

Public Function GetValue(key As String)
    'Gets values from INI file
    Dim RetStr As String, NC As Long
    RetStr = String(255, 0)
    NC = GetPrivateProfileString("BWW-IRC", key, "", RetStr, 222, App.Path + "\Settings\BWWIRC.ini")
    If NC <> 0 Then RetStr = Left(RetStr, NC)
    GetValue = Trim(RetStr)
End Function


Public Sub WriteOptions()
    'Writes Values
    With frmmain
        WriteValue "nickname", .txtNick
        WriteValue "alternative", .txtNick
        WriteValue "user", .txtUser
        WriteValue "password", .txtPass
        WriteValue "SenderBold", .chksenderBold
        WriteValue "Server", .cboServer.text
        WriteValue "BlockWords", .chkBlock.value
        WriteValue "AutoPrivate", .chkAutoPriv.value
        WriteValue "ChannelInfo", .chkChannelInfo.value
        WriteValue "Userstatus", .chkUserstaus
        WriteValue "Awaymessages", .chkAway
    End With
End Sub


Public Sub SetOptions()
    'Updates Values
    With frmmain
        .txtNick = GetValue("nickname")
        .txtPass = GetValue("password")
        .txtUser = GetValue("user")
        .chksenderBold = GetValue("SenderBold")
        .cboServer.text = GetValue("server")
        .chkBlock = GetValue("blockwords")
        .chkAutoPriv = GetValue("AutoPrivate")
        .chkChannelInfo = GetValue("ChannelInfo")
        .chkUserstaus = GetValue("Userstatus")
        .chkAway = GetValue("Awaymessages")
    End With

End Sub

'********************
'Server list functions below
'********************

Public Sub UpdateServerList()
    'temp varible to hold data from text file
    Dim tempServer As String
    'Opens file
    Open App.Path + "\" + "\Settings\Servers.txt" For Input As #3
    'do will the end of file is not reached
    Do While Not EOF(3)
        'get data
        Line Input #3, tempServer
        'If server is within "  and "
        If Mid(tempServer, 1, 1) = """" Then tempServer = Mid(tempServer, 2, Len(tempServer) - 2)
        'add data to server combo box is tempserver=""
        If tempServer <> "" Then frmmain.cboServer.AddItem Trim(tempServer)
    Loop
    'close file
    Close #3
End Sub


Public Sub AddServer(ServerAddress As String)
    'Write New Server to server text file
    Open App.Path + "\" + "Servers.txt" For Append As #5
    Write #5, ServerAddress
    Close #5
    'Add server to Server combo box
    frmmain.cboServer.AddItem ServerAddress
End Sub

Public Sub RemoveServer(ServerAddress As String)
    'open servers.txt for write
    Open App.Path + "\" + "Servers.txt" For Output As #4
    
    'loops though server combo box
    For Count = 0 To frmmain.cboServer.ListCount - 1
    
    If frmmain.cboServer.List(Count) <> ServerAddress Then
    'write server to file if it is not to be removed
    Write #4, frmmain.cboServer.List(Count)
    Else
    'if it equal removedserver then remove it from combo box
    frmmain.cboServer.RemoveItem (Count)
    End If
    Next Count
    
    'closes file
    Close #4
    'Sets text to server at the top of the list
    frmmain.cboServer.text = frmmain.cboServer.List(0)
End Sub



Public Sub GetFriendlyContacts()
'open

End Sub