﻿B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=StaticCode
Version=7.8
@EndOfDesignText@
'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.

	Public  IsInitialize	As Boolean = False
	
	Private gShowLog		As Boolean = True
	Private gWriteLog		As Boolean = False
	
	Private gLogPath		As String  
	Public  gLogName		As String  = "LogMsgs.txt"
End Sub

Public  Sub Initialize
			IsInitialize = True
			
			gLogPath  	 = File.DirRootExternal &"/" &cMDBGlobals.gDirectoryDataFiles
End Sub

Public  Sub DeleteLog
			If  IsInitialize = False Then 
				Initialize
			End If
			
			If  File.Exists(gLogPath, gLogName) Then
				File.Delete(gLogPath, gLogName)
			End If	
End Sub

Public	Sub IsShowing As Boolean
			Return gShowLog
End Sub
Public  Sub SetShowLog(xShowLog As Boolean)
			gShowLog = xShowLog
End Sub

Public  Sub IsWritting As Boolean
			Return gWriteLog
End Sub

Public  Sub SetWriteLog(xWriteLog As Boolean)
			gWriteLog = xWriteLog	
End Sub

Public  Sub LogMsg(Msg As String)

			If  IsInitialize = False Then 
				Initialize
			End If
				
			Dim msgOut			As String 		= DateTime.Time(DateTime.Now) &"  " &Msg

			If  gWriteLog Then
				Try
					Dim AppendTo  As Boolean	= File.Exists(gLogPath, gLogName)
				
					If  AppendTo Then
						Dim Today 		 As String = DateTime.Date(DateTime.Now)
						Dim LastUsed	 As String = DateTime.Date(File.LastModified(gLogPath, gLogName))
						
						'-------------------------------------------------------------------------------------------------------------------	
						'  Overright the file if it is a different day	  -  Could be a problem doing work over midnight
						'-------------------------------------------------------------------------------------------------------------------
						AppendTo = Today.EqualsIgnoreCase(LastUsed)       '  If NOT equal then will be false and Append will be Overwrite
					End If
					
  					Dim out 		As OutputStream = File.OpenOutput(gLogPath, gLogName, AppendTo) 'True - Append mode
   					Dim tw 			As TextWriter

   					tw.Initialize(out)
   					tw.WriteLine(msgOut &Chr(13))
   					tw.Close			
				Catch        			
					Log("LogMsg - CatchException:" &LastException.Message)				 
				End Try			
			End If
			
			If  gShowLog Then
				Log(msgOut)			
			End If
End Sub

Public  Sub GetLogFile As List
			Dim LogFile As List
			
			LogFile.Initialize
			
			If  File.Exists(gLogPath, gLogName) Then
				LogFile = File.ReadList(gLogPath, gLogName)
			End If
			
			Return LogFile
End Sub