;Coded by UEZ Build 2010-06-30
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <File.au3>
#Include <GuiEdit.au3>
Opt("GUIOnEventMode", 1)

Global $iMemo, $new_line
$width = 1024
$height = 600
$hGUI = GUICreate("Realtime Log Reader by UEZ 2010", $width, $height, -1, -1, Default, $WS_EX_TOPMOST)
$iMemo = GUICtrlCreateEdit("", 0, 0, $width, $height, $ES_AUTOVSCROLL + $WS_VSCROLL + $WS_HSCROLL + $ES_READONLY)
GUICtrlSetLimit(-1, 0x7FFFFFFF)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
GUISetState()
If $CmdLine[0] > 0 And FileExists($CmdLine[1]) Then
	$file = $CmdLine[1]
Else
	$file = @WindowsDir & "\WindowsUpdate.log"
EndIf
$hFile = FileOpen($file)
$txt = FileRead($hFile)

GUICtrlSetData($iMemo, $txt, 1)
_GUICtrlEdit_LineScroll($iMemo, 1, 0xfffffff)
$cl = _FileCountLines($File)
$fs = FileGetSize($file)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

While Sleep(1000)
	$fs_new = FileGetSize($file)
    If $fs < $fs_new Then
		$cl_new = _FileCountLines($file)
		For $i = $cl + 1 To $cl_new
			$new_line &= FileReadLine($hFile, $i) & @CRLF
		Next
		GUICtrlSetData($iMemo, $new_line, 1)
;~ 		_GUICtrlEdit_LineScroll($iMemo, 0, 0xfffffff)
		$cl = $cl_new
		$fs = $fs_new
		$new_line = ""
	EndIf
Wend

Func _Exit()
	FileClose($hFile)
	GUIDelete($hGUI)
	Exit
EndFunc