
'*************************************************************************
'
'      Author       : Esben Laursen (hyber@hyber.dk)
'      
'      Webpage      : http://www.hyber.dk or http://netsmsgw.sf.net
'
'      Notes        :
'
'      License      : This program is free software; you can redistribute
'                     it and/or modify it under the terms of the GNU
'                     General Public License as published by the Free
'                     Software Foundation version 2 of the License.
'
'*************************************************************************

Public Class Utils


    Public Structure netSMSgwVersionCheck
        Dim CurrentVer As String
        Dim NewestVer As String
        Dim NewerAvailable As Boolean
    End Structure





    Public Function CheckForNewVersion() As netSMSgwVersionCheck
        Dim strURL As String = "http://netsmsgw.hyber.dk/netsmsgwver.txt"
        Dim client As New System.Net.WebClient
        Dim data As IO.Stream
        Dim reader As IO.StreamReader
        Dim strVersion As String
        Dim file As FileVersionInfo = FileVersionInfo.GetVersionInfo(GetType(netSMSgw.netSMSgwd.clsSettings).Assembly.CodeBase.ToString.Remove(0, 8))
        Dim strct As New netSMSgwVersionCheck

        Try
            client.Headers.Add("User-Agent", "netSMSgw_v" & file.FileVersion.ToString)
            data = client.OpenRead(strURL)
            reader = New IO.StreamReader(data)

            strVersion = reader.ReadLine

            If strVersion = "Current version:" Then
                strVersion = reader.ReadLine

                strct.CurrentVer = file.FileVersion
                strct.NewestVer = strVersion

                If strct.CurrentVer < strVersion Then
                    strct.NewerAvailable = True
                Else
                    strct.NewerAvailable = False
                End If

            End If
            Return strct

        Catch ex As System.Net.WebException
            Call AddToLog(gstrCriticalErrUtil & ex.Message.ToString, logUtils.LogLevels.Critical)
            Return strct
        End Try
    End Function


End Class
