-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessagebox.au3
64 lines (55 loc) · 1.68 KB
/
messagebox.au3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#NoTrayIcon
#include <MsgBoxConstants.au3>
_Main()
;~ Main script loop
Func _Main()
_InitialChecks()
_ShowMessageBox()
EndFunc
;~ Initial checks
Func _InitialChecks()
Local $iCmdArgsCurrent = Int($CmdLine[0]) ; Get total amount of args
Local $iCmdArgsNeeded = 3
If $iCmdArgsCurrent <> $iCmdArgsNeeded Then
Local $sMessageArgsMissing = StringFormat("%s needs %s arguments to run (hostname, userfield and password), %s were provided.", @ScriptName, $iCmdArgsNeeded, $iCmdArgsCurrent)
_DebugQuit($sMessageArgsMissing)
EndIf
EndFunc
;~ Show a message box
Func _ShowMessageBox()
Local $sTitle = String($CmdLine[1])
Local $sText = String($CmdLine[2])
Local $isError = _ParseBoolean($CmdLine[3])
Local $iMsgboxTimeout = 30
Local $iFlag = $MB_ICONNONE
If $isError = True Then $iFlag = $MB_ICONERROR
MsgBox($iFlag, $sTitle, $sText, $iMsgboxTimeout)
EndFunc
;~ Parse boolean value from string
Func _ParseBoolean($sInput)
Local $sSanitizedInput = _SanitizeBooleanInput($sInput)
Local $vTrueValues = BitOR("true", "1", "yes", "on")
Local $vFalseValues = BitOR("false", "0", "no", "off")
Switch $sSanitizedInput
Case $vTrueValues
Return True
Case $vFalseValues
Return False
Case Else
Return False
EndSwitch
EndFunc
;~ Sanitize boolean parse input
Func _SanitizeBooleanInput($sInput)
Local $sCharSpace = " "
Local $sEmptyChar = ""
Local $sSanitizedInput = StringReplace(StringLower(String($sInput)), $sCharSpace, $sEmptyChar)
Return $sSanitizedInput
EndFunc
;~ Handle debug and script quitting
Func _DebugQuit($sMessage)
ConsoleWrite($sMessage & @CRLF)
Local $sTitle = "Error"
MsgBox($MB_ICONERROR, $sTitle, $sMessage)
Exit
EndFunc