Leaderboard
Popular Content
Showing content with the highest reputation on 09/15/2020 in all areas
-
Here is a small application made for my own need. It allows you to follow the tail of a log file (or other txt file) in real time. To avoid some memory issues, it loads about 10MB from the end of the file, so you can follow your huge log files in real-time with it. Here is the code : #include <FileConstants.au3> #include <GUIConstantsEx.au3> #include <GuiEdit.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $sAppTitle = "RT-LogFileViewer" Global $iSizeToLoad = 10 * 1024 * 1024 Global $iBlockSize = 1024, $iPause = False Global $sLastDirectory = RegRead("HKEY_CURRENT_USER\Software\" & $sAppTitle, "LastDirectory") Global $iFileChange = 0, $sFileDate, $sLogFile, $iFileSize, $hGui Global $idEdit, $idPause, $idSearch, $idFileName, $idProgress If Not StringLen($sLastDirectory) Or Not FileExists($sLastDirectory) Then $sLastDirectory = @MyDocumentsDir Opt("GUIOnEventMode", 1) Opt("MustDeclareVars", 1) _LoadGui() If $CmdLine[0] Then _FileOpen($CmdLine[1]) ProcessWaitClose(@AutoItPID) Func _LoadGui() Local $idOpen, $idAbout $hGui = GUICreate($sAppTitle, 800, 600, -1, -1, BitOR($WS_SYSMENU, $WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX) ) $idEdit = GUICtrlCreateEdit("" , 10 , 50 , 780, 490, BitOr($ES_READONLY, $ES_AUTOVSCROLL, $WS_VSCROLL, $WS_HSCROLL, $ES_NOHIDESEL)) $idOpen = GUICtrlCreateButton(ChrW(0x2f) , 10 , 10 , 30 , 30) $idPause = GUICtrlCreateButton(ChrW(0x3b) , 760, 10 , 30 , 30) $idSearch = GUICtrlCreateButton(ChrW(0x2315), 720, 10 , 30 , 30) $idFileName = GUICtrlCreateLabel ("" , 10 , 550, 680, 25) $idAbout = GUICtrlCreateLabel ("About" , 690, 550, 100, 25, $SS_RIGHT) $idProgress = GUICtrlCreateProgress(10, 540, 780, 5) Local $aAccelKeys = [["^o", $idOpen], ["^p", $idPause], ["^f", $idSearch]] GUICtrlSetFont($idOpen , 12, 400, 0, "Wingdings 2") GUICtrlSetFont($idPause , 12, 400, 0, "Webdings") GUICtrlSetFont($idSearch , 19, 800, 0, "Arial") GUICtrlSetFont($idEdit , 10, 400, 0, "Courier") GUICtrlSetFont($idFileName, 9 , 400, 0, "Verdana") GUICtrlSetFont($idAbout , 9 , 400, 4, "Verdana") GUICtrlSetTip($idOpen , "Open file (CTRL + O)") GUICtrlSetTip($idSearch, "Search... (CTRL + F)") GUICtrlSetTip($idPause , "Pause monitoring (CTRL + P)") GUICtrlSendMsg($idEdit, $EM_LIMITTEXT, -1, 0) GUICtrlSetColor($idAbout, 0x0000ff) GUISetOnEvent ($GUI_EVENT_CLOSE, "_Exit") GUICtrlSetOnEvent($idPause , "_Pause") GUICtrlSetOnEvent($idSearch , "_Search") GUICtrlSetOnEvent($idOpen , "_FileOpenGUI") GUICtrlSetOnEvent($idAbout , "_About") GUICtrlSetResizing($idOpen, $GUI_DOCKALL) GUICtrlSetResizing($idPause, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKSIZE) GUICtrlSetResizing($idSearch, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKSIZE) GUICtrlSetResizing($idEdit, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM) GUICtrlSetResizing($idFileName, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM + $GUI_DOCKHEIGHT) GUICtrlSetResizing($idAbout, $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM + $GUI_DOCKSIZE) GUICtrlSetResizing($idProgress, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM + $GUI_DOCKHEIGHT) GUICtrlSetState($idSearch, $GUI_DISABLE) GUICtrlSetState($idPause, $GUI_DISABLE) GUICtrlSetState($idProgress, $GUI_HIDE) GUISetAccelerators($aAccelKeys, $hGui) GUISetIcon(@SystemDir & "\SHELL32.dll", -25) GUISetState(@SW_SHOW) EndFunc Func _LoadTail($sLogFile) Local $sLines, $iPercent $iFileSize = FileGetSize($sLogFile) Local $hFile = FileOpen($sLogFile, $FO_READ) If @error Then Return 0 $sFileDate = FileGetTime($sLogFile, 0, 1) Local $iStartPos =($iSizeToLoad > $iFileSize ? 0 : $iFileSize - $iSizeToLoad) GUICtrlSetData($idProgress, 0) GUICtrlSetState($idProgress, $GUI_SHOW) For $i = $iStartPos To $iFileSize - $iBlockSize Step $iBlockSize $iPercent = Int( $i * 100 / $iFileSize) GUICtrlSetData($idProgress, $iPercent) FileSetPos($hFile, $i, 0) $sLines &= FileRead($hFile, $iBlockSize) If $i = $iStartPos Then $sLines = StringRegExpReplace($sLines, "^\V*\R", "", 1) Next $sLines &= FileRead($hFile) GUICtrlSetData($idProgress, 100) Sleep(100) GUICtrlSetState($idProgress, $GUI_HIDE) _GUICtrlEdit_AppendText($idEdit, $sLines) FileClose($hFile) Return 1 EndFunc Func _Search() _GUICtrlEdit_Find($idEdit) EndFunc Func _FileOpenGUI() _FileOpen() EndFunc Func _FileOpen($sFileToOpen = "") If Not FileExists($sFileToOpen) Then $sFileToOpen = FileOpenDialog("Select a file", $sLastDirectory, "Log File (*.log)|All (*.*)", 1, "", $hGui) If @error Then Return If $sFileToOpen = $sLogFile Then If not $iFileChange Then Return $iFileChange = 0 EndIf GUICtrlSetData($idEdit, "") GUICtrlSetState($idPause, $GUI_ENABLE) If Not $iPause Then _Pause() If _LoadTail($sFileToOpen) Then $sLogFile = $sFileToOpen GUICtrlSetData($idFileName, $sLogFile) $sLastDirectory = StringRegExpReplace($sLogFile, "\\[^\\]+$", "") RegWrite("HKEY_CURRENT_USER\Software\" & $sAppTitle, "LastDirectory", "REG_SZ", $sLastDirectory) Else MsgBox(16, $sAppTitle & " - Error", "Unable to load the specified file.") EndIf _Pause() EndFunc Func _Refresh() Local $sLines, $hFile Local $iNewSize = FileGetSize($sLogFile) Local $sNewFileDate = FileGetTime($sLogFile, 0, 1) If $sNewFileDate = $sFileDate Then Return $sFileDate = $sNewFileDate If $iNewSize > $iFileSize Then $hFile = FileOpen($sLogFile, $FO_READ) FileSetPos($hFile, $iFileSize, 0) $sLines = FileRead($hFile, $iNewSize - $iFileSize) FileClose($hFile) $iFileSize = $iNewSize _GUICtrlEdit_AppendText($idEdit, $sLines) Else $iFileChange = 1 _FileOpen($sLogFile) Return EndIf EndFunc Func _Pause() $iPause = Not $iPause If $iPause Then GUICtrlSetData($idPause, ChrW(0x34)) GUICtrlSetState($idSearch, $GUI_ENABLE) AdlibUnRegister("_Refresh") Else GUICtrlSetData($idPause, ChrW(0x3b)) GUICtrlSetState($idSearch, $GUI_DISABLE) AdlibRegister("_Refresh") EndIf EndFunc Func _About() Local $sAboutText = $sAppTitle & " is a real-time log file viewer. It allows you to monitor huge files by showing you the end of the file (not the whole file)." & @CRLF & _ "Thanks to use it !" & @CRLF & @CRLF & _ "Made with AutoIt version " & @AutoItVersion & " by JGUINCH." MsgBox(0, $sAppTitle, $sAboutText, 0, $hGui) EndFunc Func _Exit() Exit EndFunc1 point
-
Autoit-Events
oHenry reacted to tarretarretarre for a topic
About AutoIt-Events AutoIt-Events is an event Observer and is a core dependency for Autoit-Socket-IO but can be used for any Autoit project. Example #include "Event.au3" ; Subscribe listeners _Event_Listen(UserCreatedEvent, SendWelcomeMail) _Event_Listen(UserCreatedEvent, RegisterNewsLetter) ; Fire event _Event(UserCreatedEvent, @UserName, "tarre.islam@gmail.com") Func UserCreatedEvent(Const ByRef $oEvent, $name, $email) ; via $oEvent you can pass data to its listeners $oEvent.add("name", $name) $oEvent.add("email", $email) $oEvent.add("id", 1) EndFunc Func SendWelcomeMail(Const $oEvent) MsgBox(64, "Welcome mail sent", "Welcome mail sent to " & $oEvent.item("name") & " with email " & $oEvent.item("email")) EndFunc Func RegisterNewsLetter(Const $oEvent) MsgBox(64, "News letter registred", "News letter bound to user id " & $oEvent.item("id")) EndFunc The code is also available at Github Autoit-Events-1.0.0.zip1 point -
cleanIt('C:\windows\Temp\mat-debug-5288.log') cleanIt('C:\windows\Temp\officeclicktorun.exe_streamserver(2020080309013714A8).log') Func cleanIt($file) ConsoleWrite($file & @CRLF) ConsoleWrite(FileGetAttrib($file) & @CRLF) If Not FileDelete($file) Then ConsoleWrite("! >>> File not deleted" & @CRLF) EndIf EndFunc ;==>cleanIt EDIT : You are mixing up the return value of the function (1=Success, 0=Failure) with the error macro. The error macro(@error) is always 0 (here).1 point
-
maniootek, Sorry for the delay in replying - the real world got rather busy. #include <GUIConstantsEx.au3> ;for $GUI_EVENT_CLOSE #include <GuiListViewEx.au3> ; for $iExListViewStyle #include <Array.au3> Example() Func Example() GUICreate("listview items", 220, 250, 100, 200, -1) Local $idListview = GUICtrlCreateListView("col1|col2|col3 ", 10, 10, 200, 150) Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER) _GUICtrlListView_SetExtendedListViewStyle($idListview, $iExListViewStyle) Local $aArray[6] for $i=0 to 5 $aArray[$i] = $i & "|name|1" GUICtrlCreateListViewItem($i & "|name|1" , $idListview) Next $cButton = GUICtrlCreateButton("Read ListView", 10, 200, 80, 30) GUISetState(@SW_SHOW) $iLV_Index = _GUIListViewEx_Init($idListview, $aArray, 0, 0, True, 2) ; Use correct number of parameters here <<<<<<<<<<<<< _GUIListViewEx_SetEditStatus($iLV_Index, "2") ; Set editable column here <<<<<<<<<<<<<<<<<< _GUIListViewEx_MsgRegister(True, False, False) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $cButton $aRead = _GUIListViewEx_ReturnArray($iLV_Index) _ArrayDisplay($aRead, "Content", Default, 8) $aRead = _GUIListViewEx_ReturnArray($iLV_Index, 1) _ArrayDisplay($aRead, "Checkboxes", Default, 8) EndSwitch _GUIListViewEx_EventMonitor() ; Use correct monitor function here <<<<<<<<<<<<<<<<<<< WEnd EndFunc That should do you! M231 point
-
If you want to end the running autoit script with a hotkey, then you can do it like this, use ctrl q to quit: If HotKeySet("^q", "exitapp") = 0 Then MsgBox(0, "Hotkey", "Err: Could not set. ") local $oldsec=@sec While 1 if $oldsec<>@sec then ConsoleWrite(@hour & ":" & @MIN & ":" & @sec & @crlf) $oldsec=@sec EndIf WEnd Func exitapp() exit EndFunc Btw, you can remove the two lines: because they are after the exit, they never get executed.1 point