Leaderboard
Popular Content
Showing content with the highest reputation on 05/01/2021 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
-
WebDriver UDF - Help & Support (III)
seadoggie01 reacted to CodeWriter for a topic
@seadoggie01Thank you. I guess that "current" tab in the WebDriver notes doesn't mean currently active on screen, but just the last handle that WebDriver was using.1 point -
Autoit convert to exe, the executable works only once - (Moved)
seadoggie01 reacted to Musashi for a topic
https://www.autoitscript.com/forum/topic/34658-are-my-autoit-exes-really-infected/?do=findComment&comment=14729061 point -
Autoit convert to exe, the executable works only once - (Moved)
Musashi reacted to seadoggie01 for a topic
Maybe don't compile it to an executable (exe) then. Try using: #AutoIt3Wrapper_OutFile_Type=a3x at the top of your script. Then associate the a3x file format with the AutoIt3 executable. I've successfully avoided the antivirus in a locked down corporate environment for two years like this Edit: See Musashi's link below for a much more detailed explanation1 point -
Autoit convert to exe, the executable works only once - (Moved)
argumentum reacted to 4891gesp for a topic
@argumentum Thank you for your answer. @Nine Can you give an example of WebDriver UDF? Thank you1 point -
Instead of beating a MsgBox, use a Gui ListBox that you can fill during the loop, and lines will show all along the way.1 point
-
Virtual listviews for huge number of rows
Lion66 reacted to pixelsearch for a topic
@Lion66 In case it may help you, here is a script that combines a virtual listview with incremental search & sorting on all columns : Opt( "MustDeclareVars", 1 ) #include <EditConstants.au3> #include <GuiListView.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include "RandomArray.au3" ; LarsJ Global $g_iRows = 1000, $g_iCols = 6, $g_aArray, $g_aSubArray, $g_aIndex[$g_iRows], $g_aSubIndex[$g_iRows] Global $g_hListView, $g_hEdit, $g_idEditSearch, $g_iSortDir, $g_iSearch = $g_iRows Example() Func Example() ; Generate Array & one index _Generate_All($g_aArray, $g_aIndex) $g_aSubArray = $g_aArray $g_aSubIndex = $g_aIndex ; Create GUI Local $hGui = GUICreate( "Virtual ListView + Sort + Incremental search (2d)", 630+20, 788+30+20 ) ; Create Edit control GUICtrlCreateLabel( "Search", 10, 10, 50, 20 , BitOr($SS_CENTERIMAGE, $SS_CENTER) ) Local $idEdit = GUICtrlCreateEdit( "", 70, 10, 170, 20, BitXOR( $GUI_SS_DEFAULT_EDIT, $WS_HSCROLL, $WS_VSCROLL ) ) $g_hEdit = GUICtrlGetHandle( $idEdit ) $g_idEditSearch = GUICtrlCreateDummy() ; Create ListView Local $idListView = GUICtrlCreateListView( "", 10, 40, 630, 788, $LVS_OWNERDATA, $WS_EX_CLIENTEDGE ) _GUICtrlListView_SetExtendedListViewStyle( $idListView, $LVS_EX_DOUBLEBUFFER + $LVS_EX_FULLROWSELECT ) $g_hListView = GUICtrlGetHandle( $idListView ) Local $hHeader = _GUICtrlListView_GetHeader( $idListView ) Local $aCols = [ "Strings", "Integers", "Floats", "Dates", "Times", "R/C" ] Local $aWidths = [ 230, 60, 120, 70, 60, 60 ] For $i = 0 To $g_iCols - 1 _GUICtrlListView_AddColumn( $idListView, $aCols[$i], $aWidths[$i] ) Next ; Sorting information $g_iSortDir = 0x0400 ; $HDF_SORTUP Local $iColumn = -1, $iColumnPrev = -1 GUIRegisterMsg( $WM_COMMAND, "WM_COMMAND" ) GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" ) GUICtrlSendMsg( $idListView, $LVM_SETITEMCOUNT, $g_iRows, 0 ) ; Show GUI GUISetState( @SW_SHOW ) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $g_idEditSearch Local $sSearch = GUICtrlRead( $idEdit ) If $sSearch = "" Then ; Empty search string, display all rows $g_aSubArray = $g_aArray $g_aSubIndex = $g_aIndex $g_iSearch = $g_iRows Else ; Find rows matching the search string $g_iSearch = 0 For $i = 0 To $g_iRows - 1 ; If StringInStr( $g_aArray[$i][0], $sSearch ) Then ; Normal search If StringRegExp( $g_aArray[$i][0], $sSearch ) Then ; Reg. exp. search For $j = 0 To $g_iCols - 1 $g_aSubArray[$g_iSearch][$j] = $g_aArray[$i][$j] Next $g_aSubIndex[$g_iSearch] = $g_iSearch $g_iSearch += 1 EndIf Next EndIf ConsoleWrite( StringFormat( "%4d", $g_iSearch ) & " rows matching """ & $sSearch & """" & @CRLF ) GUICtrlSendMsg( $idListView, $LVM_SETITEMCOUNT, $g_iSearch, 0 ) Case $idListView ; Sort $iColumn = GUICtrlGetState( $idListView ) If $iColumn <> $iColumnPrev Then _GUICtrlHeader_SetItemFormat( $hHeader, $iColumnPrev, $HDF_STRING ) EndIf Local $tIndex = _SortArrayStruct($g_aSubArray, $iColumn, $g_iSearch) For $i = 0 To $g_iSearch - 1 $g_aSubIndex[$i] = DllStructGetData($tIndex, 1, $i + 1) Next $g_iSortDir = (($iColumn = $iColumnPrev) ? ($g_iSortDir = $HDF_SORTUP ? $HDF_SORTDOWN : $HDF_SORTUP) : ($HDF_SORTUP)) _GUICtrlHeader_SetItemFormat( $hHeader, $iColumn, $HDF_STRING + $g_iSortDir ) GUICtrlSendMsg( $idListView, $LVM_SETSELECTEDCOLUMN, $iColumn, 0 ) GUICtrlSendMsg( $idListView, $LVM_SETITEMCOUNT, $g_iSearch, 0 ) $iColumnPrev = $iColumn EndSwitch WEnd ; Cleanup GUIDelete( $hGui ) EndFunc ;======================================================================== Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam ) Local $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ) Switch HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) ) Case $g_hListView Switch DllStructGetData( $tNMHDR, "Code" ) Case $LVN_GETDISPINFOW Local $tNMLVDISPINFO = DllStructCreate( $tagNMLVDISPINFO, $lParam ) Local Static $tText = DllStructCreate( "wchar[50]" ), $pText = DllStructGetPtr( $tText ) If $g_iSortDir = 0x0400 Then ; 0x0400 = $HDF_SORTUP DllStructSetData($tText, 1, $g_aSubArray[$g_aSubIndex[$tNMLVDISPINFO.Item]][$tNMLVDISPINFO.SubItem]) Else DllStructSetData($tText, 1, $g_aSubArray[$g_aSubIndex[$g_iSearch -1 -$tNMLVDISPINFO.Item]][$tNMLVDISPINFO.SubItem]) EndIf DllStructSetData( $tNMLVDISPINFO, "Text", $pText ) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;======================================================================== Func WM_COMMAND( $hWnd, $iMsg, $wParam, $lParam ) Local $hWndFrom = $lParam Local $iCode = BitShift( $wParam, 16 ) ; High word Switch $hWndFrom Case $g_hEdit Switch $iCode Case $EN_CHANGE GUICtrlSendToDummy( $g_idEditSearch ) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;======================================================================== Func _Generate_All(ByRef $g_aArray, ByRef $g_aIndex) ConsoleWrite( "$g_iRows = " & $g_iRows & " $g_iCols = " & $g_iCols & @CRLF ) Local $hTimer = TimerInit() $g_aArray = FAS_Random2DArrayAu3( $g_iRows, "sifdtr", "abcdefghijklmnopqrstuvwxyz" ) For $i = 0 To $g_iRows - 1 $g_aIndex[$i] = $i Next ConsoleWrite( "Generating array & one index = " & TimerDiff( $hTimer ) & @CRLF & @CRLF) EndFunc ;======================================================================== Func _SortArrayStruct(Const ByRef $aArray, $iCol, $iRows) Local $tIndex = DllStructCreate("uint[" & $iRows & "]") Local $pIndex = DllStructGetPtr($tIndex) Local Static $hDll = DllOpen("kernel32.dll") Local Static $hDllComp = DllOpen("shlwapi.dll") Local $lo, $hi, $mi, $r ; Sorting by one column For $i = 1 To $iRows - 1 $lo = 0 $hi = $i - 1 Do $mi = Int(($lo + $hi) / 2) $r = DllCall($hDllComp, 'int', 'StrCmpLogicalW', 'wstr', $aArray[$i][$iCol], 'wstr', $aArray[DllStructGetData($tIndex, 1, $mi + 1)][$iCol])[0] Switch $r Case -1 $hi = $mi - 1 Case 1 $lo = $mi + 1 Case 0 ExitLoop EndSwitch Until $lo > $hi DllCall($hDll, "none", "RtlMoveMemory", "struct*", $pIndex + ($mi + 1) * 4, "struct*", $pIndex + $mi * 4, "ulong_ptr", ($i - $mi) * 4) DllStructSetData($tIndex, 1, $i, $mi + 1 + ($lo = $mi + 1)) Next Return $tIndex EndFunc Thanks to @LarsJ and @jpm for their scripts that helped me a lot to combine it all. The script requires "RandomArray.au3" from LarsJ. You can find this file into one of his attachment, named "ArrayDisplay.7z" and found at this link Good luck1 point -
Read text file line by line problem after for loop
Danp2 reacted to JockoDundee for a topic
Let me take another tack: @youtuber, so you have this file, TxtFile.txt, right? 1) How many lines are in it? 2) How many times do you want msgbox to display by the time the program exits? 3) Give a example of a msgbox you EXPECT to receive when the program is working - USE REAL DATA, not variable names 4) If possible, post your TxtFile.txt If you do all these things, either you will figure it out then, or somebody will right after.1 point -
Read text file line by line problem after for loop
Musashi reacted to JockoDundee for a topic
You’re the one “collecting” them, with your &= $ReadLines &= FileReadLine($OpenFileTxt, $i) & @CRLF I think you owe “her” an apology1 point -
TxtFile.txt its content Line1 Line2 Line3 Line4 ...0 points