
'*************************************************************************
'
'      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.
'
'*************************************************************************

Module basPublic

    Public gSettings As New clsSettings
    Public gstrSettingsPath As String = System.IO.Path.GetDirectoryName(GetType(netSMSgw.netSMSgwd.clsSettings).Assembly.CodeBase.ToString.Remove(0, 8)) & "\netSMSgwd_settings.xml"

    Public Const gstrStart As String = "Starting netSMSgw service now"
    Public Const gstrStop As String = "Stopping netSMSgw service now"
    Public Const gstrLoadSet As String = "Loaded settings from: "
    Public Const gstrLoadStats As String = "Loaded stats from: "
    Public Const gstrCriticalErr As String = "Critical Error happened in netSMSgwd: "
    Public Const gstrCriticalErrUtil As String = "Critical error happend in netsmsgwd.utils: "
    Public Const gstrReturnNew As String = "Returning new settings"
    Public Const gstrCurVer As String = "Running on version: "
    Public Const gstrNewerVer As String = "Newest version is: "
    Public Const gstrGotoWeb As String = "There is a newer version available, goto http://netsmsgw.hyber.dk for a updated version"
    Public Const gstrCustomCmd As String = "Custom command was not found... WTF?"
    Public Const gstrPhoneHome As String = "Phonehome was successfull (true/false): "
    Public Const gstrPHSocketErr As String = "There was a communication problem with netSMSgw Statistics Collector, error was: "
    Public Const gstrPHCritical As String = "A critical error has happened in PhoneHome, error was: "
    Public Const gstrHttpdNotSupported As String = "Sorry but HTTPd is not supported on this platform, you need at least Windows XP with ServicePack 2, Httpd is disabled...."


    Public Sub AddToLog(ByVal pstrString As String, ByVal penuLogLevel As netSMSgw.logUtils.LogLevels)
        Dim strLog As String

        If gSettings.SaveLogToFile Then

            Select Case penuLogLevel
                Case netSMSgw.logUtils.LogLevels.Debug
                    strLog = Now.ToShortDateString & " " & Now.ToLongTimeString & "[DEBUG]: "
                Case netSMSgw.logUtils.LogLevels.Info
                    strLog = Now.ToShortDateString & " " & Now.ToLongTimeString & "[INFO]: "
                Case netSMSgw.logUtils.LogLevels.Notice
                    strLog = Now.ToShortDateString & " " & Now.ToLongTimeString & "[Notice]: "
                Case netSMSgw.logUtils.LogLevels.Warnings
                    strLog = Now.ToShortDateString & " " & Now.ToLongTimeString & "[WARNING!]: "
                Case netSMSgw.logUtils.LogLevels.Critical
                    strLog = Now.ToShortDateString & " " & Now.ToLongTimeString & "[CRITICAL!!]: "
                Case netSMSgw.logUtils.LogLevels.None
                    Exit Sub
                Case Else
                    strLog = ""
                    Exit Sub
            End Select

            If gSettings.LogLevel >= penuLogLevel Then
                FileOpen(1, gSettings.LogFile, OpenMode.Append)
                WriteLine(1, strLog & pstrString)
                FileClose(1)
            End If
        End If
    End Sub

    Public Function MyVersion() As String
        Try

            Dim strVersion As String
            Dim file As FileVersionInfo = FileVersionInfo.GetVersionInfo(GetType(netSMSgw.netSMSgwd.clsSettings).Assembly.CodeBase.ToString.Remove(0, 8))

            strVersion = file.FileVersion
            Return strVersion

        Catch ex As Exception
            Return ""
            Call AddToLog(gstrCriticalErr & " - MyVersion - " & ex.Message.ToString, logUtils.LogLevels.Critical)
        End Try

    End Function
 
End Module
