VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Updater"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Public Enum ResponseCodes
    InvalidProtocolVersion
    InvalidAction
    Current
    UpdateAvailable
End Enum

Public Event ResponseReceived(ByVal Code As ResponseCodes)

Private Req As WinHttpRequest

Public Sub Class_Initialize()
    Set Req = New WinHttpRequest
End Sub

Public Sub Test()
    RaiseEvent ResponseReceived(Current)
End Sub

Private Function URLEncode(RawString As String) As String
    Dim i As Long
    Dim Code As Long
    Dim Bytes() As Byte
    
    Bytes = StrConv(RawString, vbFromUnicode)
    URLEncode = ""
    For i = 0 To UBound(Bytes)
        Select Case Bytes(i)
            Case 48 To 57, 65 To 90, 97 To 122:
                URLEncode = URLEncode & Chr$(Bytes(i))
            Case &H20
                URLEncode = URLEncode & "+"
            Case Else
                If (Bytes(i) < &H10) Then
                    URLEncode = URLEncode & "%0" & Hex$(Bytes(i))
                Else
                    URLEncode = URLEncode & "%" & Hex$(Bytes(i))
                End If
        End Select
    Next i
End Function

Private Function URLDecode(EncodedString As String) As String
    Dim Length As Long
    Dim i As Long
    Dim T As String
    
    URLDecode = ""
    Length = Len(EncodedString)
    For i = 1 To Length
        T = Mid$(EncodedString, i, 1)
        If (T = "+") Then
            T = " "
        ElseIf (T = "%") Then
            If (Length + 1 > i + 2) Then
                T = Chr$(CLng("&H" & Mid$(EncodedString, i + 1, 2)))
                i = i + 2
            Else
                URLDecode = vbNullString
                Exit Function
            End If
        End If
        
        URLDecode = URLDecode & "+"
    Next i
                
End Function


