
user4157124
Active Members-
Posts
57 -
Joined
Content Type
Forums
Downloads
Forum Articles
Events
Everything posted by user4157124
-
Means IniReadSection() failed. Happens (from documentation) : So: If you're sure mp3.txt exists (containing non-empty [files_links] -section) and is in same directory as script file, try (everyone in this topic already said this) : _Download(@ScriptDir & '\mp3.txt', 'files_links', @DesktopDir & '\') Most likely your script is run in a way that changes its working directory; it looks for mp3.txt in altered working directory when provided relative- instead of absolute (full) file path. P.S.: Use [Alt] + [Prt Scr] for screenshots of a window without having to manually crop it.
-
GUICtrlSetData($progressbar1, $prc) in your code seems an attempt at GUI creation. I get no errors, only successfully downloaded files. What's the full error message (line number)? Make sure _Download()'s parameters are correct (provide full path to .txt if not in same directory as script file, also check section name).
-
See here. Does sir want fries a GUI with that? #include <AutoItConstants.au3> #include <InetConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> _Download('mp3.txt', 'files_links', @DesktopDir & '\') Func _Download(Const $sFileIni, Const $sSection, Const $sDest) Local Const $aFile = IniReadSection($sFileIni, $sSection) Local $aDownload[$aFile[0][0] + 1] $aDownload[0] = $aFile[0][0] For $i1 = 1 To $aFile[0][0] $aDownload[$i1] = InetGet($aFile[$i1][1], $sDest & StringTrimLeft($aFile[$i1][1], StringInStr($aFile[$i1][1], '/', 0, -1)), $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) Next Local Const $iWidth = 400, _ $iHeight = 20 Local $hWnd = GUICreate(@ScriptName, $iWidth, $iHeight * $aDownload[0]) Local $aHnd[$aDownload[0] + 1] For $i1 = 1 To $aDownload[0] $aHnd[$i1] = GUICtrlCreateProgress(0, ($i1 - 1) * $iHeight, $iWidth, $iHeight) GUICtrlSetTip($aHnd[$i1], $aFile[$i1][1]) Next GUISetState(@SW_SHOW, $hWnd) Local $aInfo While Not (GUIGetMsg() = $GUI_EVENT_CLOSE) For $i1 = 1 To $aDownload[0] $aInfo = InetGetInfo($aDownload[$i1]) GUICtrlSetData($aHnd[$i1], ($aInfo[$INET_DOWNLOADCOMPLETE] Or $aInfo[$INET_DOWNLOADSUCCESS]) ? 100 : $aInfo[$INET_DOWNLOADSIZE] / $aInfo[$INET_DOWNLOADREAD]) Next If InetGetInfo() Then ContinueLoop MsgBox($MB_OK, @ScriptName, 'No more running downloads.', 0, $hWnd) ExitLoop WEnd For $i1 = 1 To $aDownload[0] InetClose($aDownload[$i1]) Next EndFunc
-
AutoIt error logger (AUERLO) UDF
user4157124 commented on user4157124's file in Scripting and Development
-
ConsoleWrite('>Message here.' & @CRLF) outputs colored text (per + > - ! characters). ConsoleWrite('warning' & @TAB & '38' & @TAB & 'more text ...' & @CRLF) enables jump to line 38 on doubleclick. Using "jump to line" format, only red and pink text coloring seems possible (simply prefixing color directives to output-text disables jump to line functionality). Is it possible to combine the two (define custom color while keeping "jump to line" functionality)?
- 2 replies
-
- color
- ConsoleWrite()
-
(and 1 more)
Tagged with:
-
AutoIt error logger (AUERLO) UDF
user4157124 replied to user4157124's topic in AutoIt Example Scripts
Thank you. Yes easy error logging to assist debugging is what it aims for. -
[UDF] Rollbar Error Reporting v0.2
user4157124 replied to EmilyLove's topic in AutoIt Example Scripts
No need to rename (it's a UDF, good one too). And serves a purpose. @WorkingDir was not a suggestion; line 48 describes @ScriptDir as "Working Directory". The predefined path isn't a problem (non asking function available too) but illustrates limitations introduced by a solution implemented on different level/scope than it affects. @mLipok Could do something like : #AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include "auerlo.au3" #include "RollbarSDK.au3" Main() Func Main() Local $aArray _AUERLO_Set($AUERLO_OPT_LOGSTD, True) _AUERLO_Set($AUERLO_OPT_LVLSTD, $AUERLO_LVL_ALL) _AUERLO_Set($AUERLO_OPT_LOGCUSTOM, True) _AUERLO_Set($AUERLO_OPT_LVLCUSTOM, $AUERLO_LVL_WARNING) _AUERLO_Set($AUERLO_OPT_FUNCCUSTOM, __AUERLO_OutputRollbar) _AUERLO_Set($AUERLO_OPT_FUNCEXIT, Default) _AUERLO_Set($AUERLO_OPT_FUNCCOM, Default) _AUERLO_Set($AUERLO_OPT_TIMEUTC, True); Consistency on collective deployment. _Rollbar_Init('RollbarAPIkeyhere') _AUERLO_Log() For $i1 = $AUERLO_LVL_TRACE To $AUERLO_LVL_FATAL _AUERLO_Log('Message #' & $i1 + 1, $i1) Next _AUERLO_Read($aArray) _AUERLO_View($aArray) ; Exit EndFunc Volatile Func __AUERLO_OutputRollbar($aData) Local $aLvl[$AUERLO_LVL__ENUM] $aLvl[$AUERLO_LVL_TRACE] = 'Debug' $aLvl[$AUERLO_LVL_DEBUG] = 'Debug' $aLvl[$AUERLO_LVL_INFO] = 'Info' $aLvl[$AUERLO_LVL_WARNING] = 'Warning' $aLvl[$AUERLO_LVL_ERROR] = 'Error' $aLvl[$AUERLO_LVL_FATAL] = 'Critical' Local Const $sLvl = $aLvl[ $aData[$AUERLO_ATR_LEVEL] ], _ $sMsg = $aData[$AUERLO_ATR_DATETIME] & ($__g_aAUERLO_OptCur[$AUERLO_OPT_TIMEUTC] ? 'UTC' : 'loc') _ & $aData[$AUERLO_ATR_MESSAGE] ? ' - ' : '' _ & $aData[$AUERLO_ATR_MESSAGE], _ $sCat = __AUERLO_GetTxtLevel($aData[$AUERLO_ATR_LEVEL]); Or other category -determining function. Local Const $iRet = _Rollbar_CreateItem($sLvl, $sMsg, $sCat) ; _AUERLO_Log('_AUERLO_AuerloToRollbar()'); Infinite regress on _Rollbar_CreateItem() @error? Return SetError(@error, @extended, $iRet) EndFunc -
File- and stdout/-err (console) output of messages, regular- and COM Object errors, exit method and -code, etc. Just call _AUERLO_Log() after to be logged functions (no parameters required if preceding function returns @error on failure). Or replace ConsoleWrite() (and SciTE trace lines) by _AUERLO_Log() for existing scripts. _AUERLO_FileRead() and _AUERLO_View() to display error log file contents (or import as CSV file to Microsoft Excel for example). Register custom functions to adjust date/time format and replace or add output functionality (no UDF source code modifications required). Output to: file console (stdout and stderr) non-blocking notification (Beep(), SoundPlay(), etc.) prompt (GUI dialog; script-halting notification) Microsoft Windows Event Log custom (register function) Download: AUERLO v2.0.0 Remarks: AutoIt v3.3.14.3+ required. @ScriptLineNumber = 0 if from callback (like $AUERLO_OPT_FUNCEXIT, except for $AUERLO_OPT_FUNCCOM = Default), -1 if @compiled. Generates Au3Stripper warnings (to be ignored without consequence; #AutoIt3Wrapper_Au3stripper_OnError=ForceUse -safe). agpl-3.0 auerlo.au3 : _AUERLO_Set() _AUERLO_Log() _AUERLO_LogAlt() _AUERLO_LogWinAPI() _AUERLO_LogEnv() _AUERLO_Assert() _AUERLO_FileClear() _AUERLO_FileRead() _AUERLO_View() auerloConstants.au3 : $AUERLO_LVL__ENUM - debug levels, $AUERLO_OPT__ENUM - _AUERLO_Set() options, $AUERLO_RET__ENUM - Return codes, $AUERLO_ERR__ENUM - @error codes, and $AUERLO_ATR__ENUM - error item attributes. Usage explanation: If @error signifies failure (implicit logging) : _ArrayDisplay($sNotAnArray); Returns @error = 1. _AUERLO_Log() ; Logs as $AUERLO_LVL_TRACE, $AUERLO_LVL_ERROR on @error, $AUERLO_LVL_DEBUG on @extended. If @error Then ... ; _AUERLO_Log() transparently passes @error and @extended from _ArrayDisplay(). If return value signifies failure (explicit logging) : If FileExists('invalid path') = 0 Then _AUERLO_Log('', $AUERLO_LVL_ERROR) Global $g_hFile = FileOpen('invalid path') If $g_hFile = -1 Then _AUERLO_Log('', $AUERLO_LVL_ERROR) If (return) value or expression result signifies failure (implicit logging): Global $g_hFile = FileOpen('invalid path') _AUERLO_Assert(Not ($g_hFile = -1)) ; $AUERLO_LVL_DEBUG if True (success), $AUERLO_LVL_WARNING if False. _AUERLO_Assert(FileWrite($g_hFile, 'data')); Successfull return value (1) evaluates to True; failure (0) to False. _AUERLO_Assert(IsArray($g_sNotAnArray)) Import error log file contents: Global $g_aArray2D = _AUERLO_FileRead(); Reads from current error log file. _AUERLO_View($g_aArray2D) Configuration ($AUERLO_OPT__ENUM in auerloConstants.au3 for description of all options) : _AUERLO_Set($AUERLO_OPT_LOGFILE, False) ; Disables output to error log file. _AUERLO_Set($AUERLO_OPT_LOGSTD, True) ; Enables output to stdout/stderr (console). _AUERLO_Set($AUERLO_OPT_FNCEXIT, Default) ; Registers default exit handler (no script exit logging without). _AUERLO_Set($AUERLO_OPT_FNCEXIT, Null) ; Deregisters default exit handler. _AUERLO_Set($AUERLO_OPT_FNCCOM, Default) ; Registers default COM Object error handler (no COM error logging without). _AUERLO_Set($AUERLO_OPT_FNCCOM, Null) ; Deregisters COM Object error handler. _AUERLO_Set($AUERLO_OPT_FNCCOM, YourFunc); Registers custom COM Object error handler YourFunc().
-
[UDF] Rollbar Error Reporting v0.2
user4157124 replied to EmilyLove's topic in AutoIt Example Scripts
I meant my design suggestion is opinion based (function level name vs. level parameter). Seeing different settings (onoff/debug -state, file path, API key) I suggested formalization (set -function could do what _Init, _Init_Ask, $__G_Rollbar_bDebug and hard coded .ini file path do). Availability throughout runtime has no particular advantage to that specific option no. MsgBox() -choice and IniRead() is nice to have, but generally including script's responsibility. The .ini file is referenced relative to @ScriptDir, so when C:\Program Files\MBP\MyBigProgram.exe (compiled AutoIt script having #include "RollbarSDK.au3") wants to let RollbarSDK do its IniWrite(), then MyBigProgram.exe needs admin rights (because @ScriptDir is a folder in C:\Program Files). That is the hard coded path (despite @ScriptDir being relative). It is distinct from @WorkingDir additionally (line 48). I am not aware of documented localization best-practices for AutoIt (but wouldn't differ from other languages). Simply returning @error (not generating messages) enables including script to relate as required. May be as simple as $sError = $aError[@error][$iLang] (if @error from _Rollbar_SendItem() is of Enum instead of HTTP code). Or as formal as separate text files (so changes require restart/reload rather than recompile). Also, StringFormat('HTTP Status %i - %s', $iCode, $sMsg) may save a few constants. Error loggers : https://www.autoitscript.com/forum/topic/195862-loga-a-logging-library/ https://www.autoitscript.com/forum/topic/195882-errorlogau3-udf-a-logging-library/ I use another (not sure how it compares, may release if anyone cares). -
[UDF] Rollbar Error Reporting v0.2
user4157124 replied to EmilyLove's topic in AutoIt Example Scripts
"Do you have a specific use case in mind?" UDF settings in general (the individual global vars). Including script should decide how to configure UDF (and where to get settings from). File path is hard-coded currently (location requires administrative rights to modify if used in compiled script installed to \Program Files\). Array enables setting options like: Func Rollbar_Set($iAttr, $nValue) $__g_aRollbar_Opt[$iAttr] = $nValue ... EndFunc "Can you please be a bit clearer so I can better understand what you are requesting?" UDF accepts user choices and outputs information, but including script should control presentation (MsgBox(), GUI, etc.). Including this UDF to scripts compiled as console for example, forces display of GUI elements (mixes logic and presentation; scripts can't control its behavior). "This is too jumbled for me to understand. Can you please be a bit clearer so ..." Too concise probably. Error loggers require quite some functionality to be considered useful (but most of that seems out of scope for this UDF). Some users posted dedicated error logging UDF's; yours could take their output as input. "This allows devs to be more flexible." Design choice being (opinion based, current way is fine too): Rollbar_SendWarning('Msg') Rollbar_SendError('Msg') or: Rollbar_Send($ROLLBAR_LVL_WARNING, 'Msg') Rollbar_Send($ROLLBAR_LVL_ERROR, 'Msg') "... Rollbar REST API expects a string." That's what UDF's are for (to make sure what gets input is output as required). Example (no out of bounds -check): Func Rollbar_Send($iLevel, $sMsg = '') Local $aLevel = ['trace', 'debug', 'info', 'warning', 'error', 'fatal'] Local $sLevel = $aLevel[$iLevel] ... EndFunc 2D arrays are ideal for localization: Enum $ROLLBAR_LANG_EN, $ROLLBAR_LANG_DE, ..., $ROLLBAR_LANG__ENUM Enum $ROLLBAR_TEXT_TEST, ..., $ROLLBAR_TEXT__ENUM Global $__g_aRollbar_Txt[$ROLLBAR_TEXT__ENUM][$ROLLBAR_LANG__ENUM] $__g_aRollbar_Txt[$ROLLBAR_TEXT_TEST][$ROLLBAR_LANG_EN] = 'Example text.' $__g_aRollbar_Txt[$ROLLBAR_TEXT_TEST][$ROLLBAR_LANG_DE] = 'Beispieltext.' $g_iLang = $ROLLBAR_LANG_EN MsgBox($MB_OK, @ScriptName, $__g_aRollbar_Txt[$ROLLBAR_TEXT_TEST][$g_iLang]) -
[solved] Tcp send and receive question.
user4157124 replied to Borje's topic in AutoIt General Help and Support
The GitHub copy&paste (what "try and try" didn't work?) streams binary over TCP; create a protocol for client and server to agree on interpretation of (meta-) data. In this case just display $Destination somewhere (it's all in there already). -
[UDF] Rollbar Error Reporting v0.2
user4157124 replied to EmilyLove's topic in AutoIt Example Scripts
Some suggestions: - https://www.autoitscript.com/wiki/Best_coding_practices - https://www.autoitscript.com/wiki/UDF-spec - Remove AutoIt3Wrapper directives from UDF (even if just AU3Check; remove on release or add to RollbarTest.au3 instead). - Replace .ini operations by a 2D array (set from function like _Rollbar_Set($iAttr, $nValue) ). - Remove MsgBox() -calls and saving as .ini or move to separate function (so main script controls MsgBox(), .ini file path and choice to load or not; configuration, permission and GUI-notification being calling/including script's responsibility, UDF itself to be concerned with maintaining valid internal state only). - Accept output from dedicated error logger function/UDF instead (or split into separate UDF's). Error loggers ideally enable registering custom functions on Exit, for COM Object errors, for custom date/time format and item output (console, file, Beep(), etc.), and auto-elevate level if @error (level error), if @extended (level debug), or if @exitCode (level critical/fatal), inclusion of @ScriptLineNumber, transparently passing @error/@extended, etc.; which (along with other error-logger's functionality) although necessary, seems out of scope for a Rollbar transmission UDF specifically. - Rollbar_Send...() et al. seem redundant; single function could accept level parameter as int (using Enum instead of quoted str has SciTE suggest auto-completion too). Generally error level depends on outcome logged; naming functions after parameters introduces hard coded specificity as (unless used with Call() ) it's valid within pre-defined (foreseen) context only (specific If/Else branch for example). - Hard coded text messages don't sit well with German, French, Russian, etc. AutoIt communities (of consideration if widespread adoption is a goal). -
Not ideal but expected (consistent behavior). Manual conversion (StringLower) isn't required however: ConsoleWrite(('False' = 'false') & @CRLF) Empty str evaluates to False, so could just do: $vValue = String(False) $vValue = $vValue = 'false' ? '' : $vValue If $vValue Then ConsoleWrite('True' & @CRLF) Else ConsoleWrite('False' & @CRLF) EndIf
-
Multiple controls with same class
user4157124 replied to MrKris1224's topic in AutoIt GUI Help and Support
Possible workaround: ControlClick($hWnd, '', '[CLASS:TPageControl; INSTANCE:1]', 'primary', 1, $g_aGuiLoc[$LOC_TAB_2][$COORD_X], $g_aGuiLoc[$LOC_TAB_2][$COORD_Y]) Where $g_aGuiLoc contains coordinates to (somewhere inside) concerning tab header (relative to TPageControl's location). Address controls by INSTANCE. First activation of each tab changes INSTANCE number of controls (cycle through all tabs first for INSTANCE to consistently relate to same control). Now it should be possible to address controls by for example [CLASS:TEdit; INSTANCE:25] (even if another tab than containing one is visible). Not all GUICtrl...() functions work for Delphi controls (most cases solvable using workarounds however). -
TCPStartUp() in a UDF - best practice?
user4157124 replied to orbs's topic in AutoIt Technical Discussion
For a UDF, TCPStartUp() is the including script's responsibility (like caling _GDIPlus_Startup() or _SQLite_Startup() prior to using functions from a UDF that depend on these libraries). Check in each function helps debugging (uninitialized use will error eventually, a check at least identifies the cause), but TCP functions return @error WSANOTINITIALISED (10093) if called prior to TCPStartup() already. Generally speaking, anything of global effect is the script's (not UDF's) responsibility (code becomes inflexible/unmanageable otherwise). Of course you can do as you please (it's a convenience vs. flexibility trade off eventually). -
what's it called when you have \n instead of @CRLF?
user4157124 replied to orbs's topic in AutoIt General Help and Support
Possibly just: ConsoleWrite(StringFormat('\r\n@CRLF before this\t@TAB before this\n')) Called escape sequence. -
Possibly: https://www.autoitscript.com/autoit3/docs/functions/InputBox.htm
-
Some possibilities: https://stackoverflow.com/a/50539184/4157124