commit 1e85464dea7e85b72dd25f175dea2774b044a643 Author: r0n1n7an Date: Thu Aug 21 16:55:17 2025 +0800 init commit diff --git a/BigChar.au3 b/BigChar.au3 new file mode 100644 index 0000000..f91879a --- /dev/null +++ b/BigChar.au3 @@ -0,0 +1,234 @@ +#NoTrayIcon +#Region ;**** Directives created by AutoIt3Wrapper_GUI **** +#AutoIt3Wrapper_Change2CUI=y +#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** + +Global $Row0 = " # # " +Global $Row1 = " # # # ## ## ### ### # # # # # # # # # # # # " +Global $Row2 = " # #### #### #### ##### ##### ### ## ####### ######## ##### ## ## ## ### ### #### ### #### #### ##### ## #### ### # # ## ## ## ## ##### ## ## ### ## # # ## ### ### # ### ### # ##### ### ##### ### ### # ### # # #### # # # # # # # # # # # # # # # ### # ## # # # # " +Global $Row3 = " # # # # # # # # # # # # # # # # # # # # ## ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ## # # # # ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # " +Global $Row4 = " ## # # # # # # # # # # # # # # # # # ## ## ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ## ####### # # ## # # # # # ##### # # # # # # # # # # # # # # # " +Global $Row5 = " # # ### # # # ### ### # #### # # ## # ## ## ## # # # ### # # ### ## # # # # # ### # # # ## ### ### ### ## #### #### ### ## ## # ### # #### #### ## #### ### ## ## #### ### ## ## ### ### # # ## ## ### ## #### # # # # ## # # #### #### # ### # # # # # # # # ## # # ### # # ##### ##### # # # # # # # # # # #### # " +Global $Row6 = " # # # # # # # # # # # # ### # # # # # # # # # # # ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ## # # # # # # # # # # # # # # # # # # # # # # # # # # # #### # # # # # # ## # # ### # # # # # # # # # # # # # # # # " +Global $Row7 = " #### # # # # # # # # # # # # # # # # # # # # ## # # # ### # # # # # # # ## # # # # # # ### # # # # # #### # ## # # # # ### # # # # # # # # # # # # # ## # # # # # ### # # # # # # # # # #### # # # # # # # # # ### ###### # # ## ## # # # # ##### # # # # # # # # # # # # # # " +Global $Row8 = " # # # # # # # # # # # # # # # # # # # # ## # # # # # # # # ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ## # # # # ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # " +Global $Row9 = "## ###### ### #### ##### ### ## ## ####### # # ### ######### # # ### # ### ### ### ### ###### ### ## # # # ## ## ### ##### #### ### ### #### ### #### #### ### ## ### # ### ####### # # # ### ## ## ### ### ### #### ## #### # # # ## ## # #### ### ### ##### ### ## ### ### # ### ### # #### # # #### # # # # # # # # # # # # # # # # # ## ## # " +Global $Row10 = " ### ## # # # # # # # # # ## ## ### ### # # # # " +Global $Row11 = " ### ### ### ### ## ###### # # " + +;Global $Row0 = " " +;Global $Row1 = " # # ### # ## ## # ### # # ### # ### # # # # ## ## ### ### # # # # ## # ### # " +;Global $Row2 = " # #### ### #### #### #### #### # # ##### #### # # # # # # # #### #### ### ### #### ##### # # # ## ## # # # ##### # # # # # # # ### ## ### ### ## #### ### ##### ### ### # # ## # # ### # # # # # # # # # # # # # # # # ## # # # # # " +;Global $Row3 = " # # # # ## # ## # # # # # # # # # # # # ## # ## ## # ### # # # # # # # # ## # # # # # # ### #### ### #### ### # ######### ### #### # # # ##### #### ### #### #### #### ### ##### # # # ## ### ## # # #### # # # # # # # # # # ## # # # # # # # # # # # # #### ### # # # # # # # ## ## # # # # # # # # # # # # # " +;Global $Row4 = " # # # # # # # # # # # # # # # # # # ## # ## # # # # ## # # # # # # # # ## # ## # # # # ## # ## # # # ###### # # # # # # # # # # # # # # # # ## # # # # # # # # # # ## # # # # # # # # ## # # # # # # # # ## # # # # # # ####### # # # # # # # # # # # # # ## ## # # # # # # # ## # " +;Global $Row5 = " # # #### # # # #### #### # ## #### # # ## # # ## # ## # # # #### # # ### ### # # # # # # ## # ## # # #### # # # # # ##### # # # # # # # ## # # # # # # # # # # # # # ## # # # # ## # # ## # # # # # # # # ## # # ### #### # ### #### # # ## # # # ### # # # # ##### ####### ## # # # # # ## # ### # ### # # " +;Global $Row6 = "##### # # # # # # # # # # # # # # # # # # # ## # # # # # # # # # # # # # #### ## # # # # # # # # # # # #### # # # # ## # # # # # # # # # # # # # ## # # # # # # ### ## # # # ## # # # # ###### # # # # # ## # # # ## ####### # # # ### # # ### # # # # # # # # # # # ### # ## # " +;Global $Row7 = "# # # # ## # ## # # ## # # # # # # # # # # # ## ## ## # # ## # # # # # # # # # ## # # # # # ## # # # # ## ## # # # # # # # # # # # # # # # # # # # ## # # # # # # # ## ## # # ## # # # # # # # # # # # # # # # ### # # # # # # # # # ##### # # # # # ## ## # # # ## ## # # # # " +;Global $Row8 = "# # #### ### #### #### # #### # # ##### ### # # #### # # # # #### # ### # # #### # ### # # # ## ## # #### #### #### ### ## # #### # ##### # # #### # # # #### # # # # # ### #### ## # # ### ### #### # # # ## ## # #### ### ##### ##### ### # ### ### # ### ### # # # # #### # ### # # # # # # ## ## # # # ## ## # # ##### # " +;Global $Row9 = " # # # # # # # # # # # # # # # ## # ## # # " +;Global $Row10 = " ## #### ### # # ### #### # # ###### ## ## ### ### ## ## # " +;Global $Row11 = " " + +Func _Big_CHR($String, $Ins = "#") + If @NumParams < 1 Then + Return 0 + ElseIf @NumParams = 1 Then + Local $InsX = "#" + Else + Local $InsX = $Ins + $InsX = StringLeft($InsX, 1) + EndIf + + Local $SrcString = $String + Local $SrcStringLenth = StringLen($SrcString) + + Local $Big_Type_Str0 + Local $Big_Type_Str1 + Local $Big_Type_Str2 + Local $Big_Type_Str3 + Local $Big_Type_Str4 + Local $Big_Type_Str5 + Local $Big_Type_Str6 + Local $Big_Type_Str7 + Local $Big_Type_Str8 + Local $Big_Type_Str9 + Local $Big_Type_Str10 + Local $Big_Type_Str11 + + For $j = 1 To $SrcStringLenth Step 1 + Local $Src_Head = StringLeft($SrcString, 1) + $SrcString = StringTrimLeft($SrcString, 1) + Local $Big_Type_Num = _SringNum($Src_Head) + If $Big_Type_Num = 0 Then + ConsoleWrite(@CRLF & "Error: Character(s) Not Supported." & @CRLF) + Return 1 + EndIf + + Local $Big_Type_Pos + + $Big_Type_Pos = ($Big_Type_Num-1)*6 + For $k = 1 To 6 Step 1 + $Big_Type_Pos += 1 + $Big_Type_Str0 &= StringMid($Row0, $Big_Type_Pos, 1) + Next + + $Big_Type_Pos = ($Big_Type_Num-1)*6 + For $k = 1 To 6 Step 1 + $Big_Type_Pos += 1 + $Big_Type_Str1 &= StringMid($Row1, $Big_Type_Pos, 1) + Next + + $Big_Type_Pos = ($Big_Type_Num-1)*6 + For $k = 1 To 6 Step 1 + $Big_Type_Pos += 1 + $Big_Type_Str2 &= StringMid($Row2, $Big_Type_Pos, 1) + Next + + $Big_Type_Pos = ($Big_Type_Num-1)*6 + For $k = 1 To 6 Step 1 + $Big_Type_Pos += 1 + $Big_Type_Str3 &= StringMid($Row3, $Big_Type_Pos, 1) + Next + + $Big_Type_Pos = ($Big_Type_Num-1)*6 + For $k = 1 To 6 Step 1 + $Big_Type_Pos += 1 + $Big_Type_Str4 &= StringMid($Row4, $Big_Type_Pos, 1) + Next + + $Big_Type_Pos = ($Big_Type_Num-1)*6 + For $k = 1 To 6 Step 1 + $Big_Type_Pos += 1 + $Big_Type_Str5 &= StringMid($Row5, $Big_Type_Pos, 1) + Next + + $Big_Type_Pos = ($Big_Type_Num-1)*6 + For $k = 1 To 6 Step 1 + $Big_Type_Pos += 1 + $Big_Type_Str6 &= StringMid($Row6, $Big_Type_Pos, 1) + Next + + $Big_Type_Pos = ($Big_Type_Num-1)*6 + For $k = 1 To 6 Step 1 + $Big_Type_Pos += 1 + $Big_Type_Str7 &= StringMid($Row7, $Big_Type_Pos, 1) + Next + + $Big_Type_Pos = ($Big_Type_Num-1)*6 + For $k = 1 To 6 Step 1 + $Big_Type_Pos += 1 + $Big_Type_Str8 &= StringMid($Row8, $Big_Type_Pos, 1) + Next + + $Big_Type_Pos = ($Big_Type_Num-1)*6 + For $k = 1 To 6 Step 1 + $Big_Type_Pos += 1 + $Big_Type_Str9 &= StringMid($Row9, $Big_Type_Pos, 1) + Next + + $Big_Type_Pos = ($Big_Type_Num-1)*6 + For $k = 1 To 6 Step 1 + $Big_Type_Pos += 1 + $Big_Type_Str10 &= StringMid($Row10, $Big_Type_Pos, 1) + Next + + $Big_Type_Pos = ($Big_Type_Num-1)*6 + For $k = 1 To 6 Step 1 + $Big_Type_Pos += 1 + $Big_Type_Str11 &= StringMid($Row11, $Big_Type_Pos, 1) + Next + + Next + + Local $Big_Type_Str = $Big_Type_Str0 & @CRLF _ + & $Big_Type_Str1 & @CRLF _ + & $Big_Type_Str2 & @CRLF _ + & $Big_Type_Str3 & @CRLF _ + & $Big_Type_Str4 & @CRLF _ + & $Big_Type_Str5 & @CRLF _ + & $Big_Type_Str6 & @CRLF _ + & $Big_Type_Str7 & @CRLF _ + & $Big_Type_Str8 & @CRLF _ + & $Big_Type_Str9 & @CRLF _ + & $Big_Type_Str10 & @CRLF _ + & $Big_Type_Str11 & @CRLF + $Big_Type_Str = StringReplace($Big_Type_Str, "#", $InsX) + ConsoleWrite($Big_Type_Str) + +EndFunc + + + +Func _SringNum($String) +Local $Big_Type_String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" +Local $Big_Type_Num = _SringNumPlus($String) +If $Big_Type_Num = 0 Then + $Big_Type_Num = StringInStr($Big_Type_String, $String, 1) + If $Big_Type_Num = 0 Then + Return 0 + Else + Return $Big_Type_Num + EndIf +Else + Return $Big_Type_Num +EndIf +EndFunc + + + +Func _SringNumPlus($String) + Local $Big_Type_Num = 0 + ;Switch $String + If $String == "!" Then $Big_Type_Num = 63 + If $String == "@" Then $Big_Type_Num = 64 + If $String == "#" Then $Big_Type_Num = 65 + If $String == "$" Then $Big_Type_Num = 66 + If $String == "%" Then $Big_Type_Num = 67 + If $String == "*" Then $Big_Type_Num = 68 + If $String == "(" Then $Big_Type_Num = 69 + If $String == ")" Then $Big_Type_Num = 70 + If $String == "-" Then $Big_Type_Num = 71 + If $String == "_" Then $Big_Type_Num = 72 + If $String == "=" Then $Big_Type_Num = 73 + If $String == "+" Then $Big_Type_Num = 74 + If $String == "{" Then $Big_Type_Num = 75 + If $String == "}" Then $Big_Type_Num = 76 + If $String == "[" Then $Big_Type_Num = 77 + If $String == "]" Then $Big_Type_Num = 78 + If $String == ":" Then $Big_Type_Num = 79 + If $String == ";" Then $Big_Type_Num = 80 + If $String == '"' Then $Big_Type_Num = 81 + If $String == "'" Then $Big_Type_Num = 82 + If $String == "\" Then $Big_Type_Num = 83 + If $String == "<" Then $Big_Type_Num = 84 + If $String == ">" Then $Big_Type_Num = 85 + If $String == "," Then $Big_Type_Num = 86 + If $String == "." Then $Big_Type_Num = 87 + If $String == "?" Then $Big_Type_Num = 88 + If $String == "/" Then $Big_Type_Num = 89 + If $String == "~" Then $Big_Type_Num = 90 + If $String == "^" Then $Big_Type_Num = 91 + If $String == "&" Then $Big_Type_Num = 92 + If $String == "|" Then $Big_Type_Num = 93 + If $String == " " Then $Big_Type_Num = 94 + Return $Big_Type_Num +EndFunc + + +Func _Big_Char() + Local $Tips = @CRLF & "CMD:" & @TAB & "/CHR String [Instead=#]" & @CRLF _ + & "Usage:" & @TAB & "Print a string with big font by a specified character." & @CRLF & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + ElseIf $CMDLINE[0] = 2 Then + Local $String = $CMDLINE[2] + _Big_CHR($String, "#") + Exit 0 + Else + Local $String = $CMDLINE[2] + Local $Ins = $CMDLINE[3] + _Big_CHR($String, $Ins) + Exit + EndIf +EndFunc diff --git a/ChgRes.au3 b/ChgRes.au3 new file mode 100644 index 0000000..87c6c43 --- /dev/null +++ b/ChgRes.au3 @@ -0,0 +1,75 @@ +#Include-Once +#NoTrayIcon +;=============================================================================== +; +; Func Name: _ChangeScreenRes() +; Infomation: Change screen resolution and refresh rate. +; Version: 1.0.0.1 +; Parameters: $i_Width - Desktop Width (1024X768-->1024) +; $i_Height - Desktop Height (1024X768-->768) +; $i_BitsPP - Screen Color Deepth (Ext: 32Bit) +; $i_RefreshRate - Screen Refresh Rate (Ext: 75 MHZ). +; ReturnCode: Succees, @ERROR = 0 +; Fail, @ERROR = 1 +; Author: Original code - psandu.ro +; Modifications - PartyPooper +; http://www.autoitscript.com/forum/index.php?showtopic=20121 +;=============================================================================== + +;Func _ChangeScreenRes($i_Width = @DesktopWidth, $i_Height = @DesktopHeight, $i_BitsPP = @DesktopDepth, $i_RefreshRate = @DesktopRefresh) +Func _ChangeScreenRes($i_Width, $i_Height, $i_BitsPP, $i_RefreshRate) +Local Const $DM_PELSWIDTH = 0x00080000 +Local Const $DM_PELSHEIGHT = 0x00100000 +Local Const $DM_BITSPERPEL = 0x00040000 +Local Const $DM_DISPLAYFREQUENCY = 0x00400000 +Local Const $CDS_TEST = 0x00000002 +Local Const $CDS_UPDATEREGISTRY = 0x00000001 +Local Const $DISP_CHANGE_RESTART = 1 +Local Const $DISP_CHANGE_SUCCESSFUL = 0 +Local Const $HWND_BROADCAST = 0xffff +Local Const $WM_DISPLAYCHANGE = 0x007E +If $i_Width = "" Or $i_Width = -1 Then $i_Width = @DesktopWidth ; default to current setting +If $i_Height = "" Or $i_Height = -1 Then $i_Height = @DesktopHeight ; default to current setting +If $i_BitsPP = "" Or $i_BitsPP = -1 Then $i_BitsPP = @DesktopDepth ; default to current setting +If $i_RefreshRate = "" Or $i_RefreshRate = -1 Then $i_RefreshRate = @DesktopRefresh ; default to current setting +Local $DEVMODE = DllStructCreate("byte[32];int[10];byte[32];int[6]") +Local $B = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "long", 0, "ptr", DllStructGetPtr($DEVMODE)) + +If @error Then + $B = 0 + SetError(1) + Return $B +Else + $B = $B[0] +EndIf + +If $B <> 0 Then + DllStructSetData($DEVMODE, 2, BitOR($DM_PELSWIDTH, $DM_PELSHEIGHT, $DM_BITSPERPEL, $DM_DISPLAYFREQUENCY), 5) + DllStructSetData($DEVMODE, 4, $i_Width, 2) + DllStructSetData($DEVMODE, 4, $i_Height, 3) + DllStructSetData($DEVMODE, 4, $i_BitsPP, 1) + DllStructSetData($DEVMODE, 4, $i_RefreshRate, 5) + $B = DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DllStructGetPtr($DEVMODE), "int", $CDS_TEST) + If @error Then + $B = -1 + Else + $B = $B[0] + EndIf + Select + Case $B = $DISP_CHANGE_RESTART + $DEVMODE = "" + Return 2 + Case $B = $DISP_CHANGE_SUCCESSFUL + DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DllStructGetPtr($DEVMODE), "int", $CDS_UPDATEREGISTRY) + DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_DISPLAYCHANGE, _ + "int", $i_BitsPP, "int", $i_Height * 2 ^ 16 + $i_Width) + $DEVMODE = "" + Return 1 + Case Else + $DEVMODE = "" + SetError(1) + Return $B + EndSelect +EndIf + +EndFunc ;==>_ChangeScreenRes diff --git a/CmdUtil.au3 b/CmdUtil.au3 new file mode 100644 index 0000000..f21ea0c --- /dev/null +++ b/CmdUtil.au3 @@ -0,0 +1,246 @@ +#NoTrayIcon +#Region ;**** Directives created by AutoIt3Wrapper_GUI **** +#AutoIt3Wrapper_Outfile=CmdUtil32.exe +#AutoIt3Wrapper_Outfile_x64=CmdUtil64.exe +#AutoIt3Wrapper_Compile_Both=y +#AutoIt3Wrapper_UseX64=y +#AutoIt3Wrapper_Change2CUI=y +#AutoIt3Wrapper_Res_Comment=CmdUtil.exe +#AutoIt3Wrapper_Res_Description=r0n1n7an's Commandline Utility +#AutoIt3Wrapper_Res_Fileversion=2.1.0.0 +#AutoIt3Wrapper_Res_ProductVersion=2.1.0.0 +#AutoIt3Wrapper_Res_LegalCopyright=r0n1n7an +#AutoIt3Wrapper_Res_Language=1033 +#AutoIt3Wrapper_Res_Field=ProductName|CmdUtil.exe +#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** + +;Modification +; 2016.06.22 Add Misc Item (/SLP /BEP /MON /DSI /RES) +; 2016.06.27 Modify /NUM function output format(Added ----------String: $String) +; 2016.06.28 Modify /FRL function (Add "-" to get line form then end of the file or from line_strat to line_end) +; 2016.08.02 Add /MD5 /UPR /LWR /CHR Function. +; 2016.08.08 Add /CMD Function. +; 2016.08.09 Add More Operation Of /CMD Function. +; 2016.09.10 Add /EXT Function(Utils.au3). +; 2016.09.14 Fix A Bug Of /MID Function $CMDLINE[4]. +; 2016/12/08 Add /H2S & /S2H Function @ Str.au3 +; 2020/05/13 Fix console outputs of some functions. + +#Include +#Include +#Include +#Include +#Include +#Include + + +If $CMDLINE[0] < 1 Then + _Usage() + Exit 0 +EndIf + +Switch $CMDLINE[1] + Case "/LOG" + _WriteLog() + Case "/DEL" + _DeleteLine() + Case "/INS" + _WriteLine() + Case "/REP" + _ReplaceString() + Case "/NUM" + _LineNum() + Case "/FRL" + _GetLine() + Case "/FCL" + _CountLine() + Case "/FGA" + _GetAttrib() + Case "/FSA" + _SetAttrib() + Case "/ENC" + _GetEncoding() + Case "/RED" + _Read() + Case "/SIZ" + _GetSize() + Case "/FGT" + _GetTime() + Case "/FST" + _FileSetTime() + Case "/VER" + _GetVersion() + Case "/SRE" + _FileSRER2Line() + Case "/BTW" + _StrBetween() + Case "/CMP" + _StrCompare() + Case "/FMT" + _StringFormat() + Case "/SIS" + _StringInStr() + Case "/DIV" + _StrExplode() + Case "/PAR" + _StrSplit() + Case "/ISR" + _StrInsert() + Case "/IAN" + _StrIsAlNum() + Case "/ALP" + _StrIsAlpha() + Case "/ASC" + _StrIsASCII() + Case "/DIG" + _StrIsDigit() + Case "/SIL" + _StrIsLower() + Case "/SIU" + _StrIsUpper() + Case "/BLK" + _StrIsSpace() + Case "/HEX" + _StrIsHEX() + Case "/LEN" + _StrLength() + Case "/LFT" + _StrLeft() + Case "/RIT" + _StrRight() + Case "/STL" + _StrTrimLeft() + Case "/STR" + _StrTrimRight() + Case "/MID" + _StrMid() + Case "/SRP" + _StrReplace() + Case "/REV" + _StrReverse() + Case "/SWS" + _StrStripWS() + Case "/S2H" + _Str2Hex() + Case "/H2S" + _Hex2Str() + Case "/MD5" + _StringMD5() + Case "/UPR" + _StringUpper() + Case "/LWR" + _StringLower() + Case "/MON" + _MonitorOnOff() + Case "/RES" + _ChgRes() + Case "/DSI" + _Enum() + Case "/SLP" + _Sleep() + Case "/BEP" + _Beep() + Case "/RND" + _Random() + Case "/CHR" + _Big_Char() + Case "/CMD" + _CMD() + Case "/EXT" + _Execute() + Case Else + _Usage() +EndSwitch + + + +Func _Usage() + Local $Info_Head = @CRLF & "CmdUtil.exe V2.1 Build: 2020.05.15" & @CRLF _ + & "Commandline Utility." & @CRLF _ + & "Usage: CmdUtil.exe Command Parameter(s) " & @CRLF & @CRLF _ + + Local $Info_String = "---------- String Operations ----------" & @CRLF _ + & "/BTW: Find strings between two string delimiters." & @CRLF _ + & "/CMP: Compare two strings with options." & @CRLF _ + & "/SIS: Check if a string contains a given substring." & @CRLF _ + & "/DIV: Split up a string into substrings depending on the given delimiters." & @CRLF _ + & "/PAR: Split up a string into substrings depending on the given delimiters." & @CRLF _ + & "/ISR: Insert a string within another string." & @CRLF _ + & "/UPR: Convert a string to uppercase." & @CRLF _ + & "/LWR: Convert a string to lowercase." & @CRLF _ + & "/IAN: Check if a string contains only alphanumeric characters." & @CRLF _ + & "/ALP: Check if a string contains only alphabetic characters." & @CRLF _ + & "/ASC: Check if a string contains only ASCII characters(0x00 - 0x7f)." & @CRLF _ + & "/DIG: Check if a string contains only digit (0-9) characters." & @CRLF _ + & "/SIL: Check if a string contains only lowercase characters." & @CRLF _ + & "/SIU: Check if a string contains only uppercase characters." & @CRLF _ + & "/BLK: Check if a string contains only whitespace characters." & @CRLF _ + & "/HEX: Check if a string are hexadecimal digit (0-9, A-F) characters." & @CRLF _ + & "/LEN: Return the number of characters in a string." & @CRLF _ + & "/LFT: Return a number of characters from the left side of a string." & @CRLF _ + & "/RIT: Return a number of characters from the right side of a string." & @CRLF _ + & "/STL: Trim a number of characters from the left side of a string." & @CRLF _ + & "/STR: Trim a number of characters from the right side of a string." & @CRLF _ + & "/MID: Extract a number of characters from a string." & @CRLF _ + & "/SRP: Replace substrings in a string." & @CRLF _ + & "/REV: Reverse the contents of the specified string." & @CRLF _ + & "/SWS: Strip the white space in a string." & @CRLF _ + & "/S2H: Convert a string to a hex string." & @CRLF _ + & "/H2S: Convert a hex string to a string." & @CRLF _ + & "/MD5: Return the MD5 value of a specified string." & @CRLF &@CRLF + + Local $Info_Text = "---------- Text File Operations ----------" & @CRLF _ + & "/INS: Insert text to a specific line in a file." & @CRLF _ + & "/DEL: Delete the specified line in a file." & @CRLF _ + & "/REP: Replace a substring in a file." & @CRLF _ + & "/NUM: Return the number of lines (with specified sting) of a specified file." & @CRLF _ + & "/FRL: Return the text of the specified line in a specified text file." & @CRLF _ + & "/FCL: Return the count of lines in the specified file." & @CRLF _ + & "/RED: Read a number of characters from a file." & @CRLF _ + & "/SRE: Delete(or replace) the lines by the specified string.(RegExp)" & @CRLF _ + & "/LOG: Write current date, time and the specified text to a log file." & @CRLF & @CRLF + + Local $Info_Att = "---------- File Attribute Operations ----------" & @CRLF _ + & "/FGA: Return a code string representing a file's attributes." & @CRLF _ + & "/FSA: Set the attributes of one or more files/directories." & @CRLF _ + & "/FGT: Return the time and date information for a file." & @CRLF _ + & "/FST: Set the timestamp of one of more files." & @CRLF _ + & "/ENC: Determine the text encoding used in a file." & @CRLF _ + & "/SIZ: Return the size of a file." & @CRLF _ + & "/VER: Return version information stored in a file." & @CRLF & @CRLF + + Local $Info_Misc = "-------------------- Misc Item --------------------" & @CRLF _ + & "/CHR: Type a string in big font with a specified character." & @CRLF _ + & "/RND: Generate a pseudo-random integer-type number." & @CRLF _ + & "/SLP: Pause execution for a while." & @CRLF _ + & "/BEP: Play back a beep to the user." & @CRLF _ + & "/MON: Turn the display monitor on/off." & @CRLF _ + & "/DSI: Retrieve display settings information." & @CRLF _ + & "/RES: Change desktop resolution." & @CRLF _ + & "/EXT: Execute an expression." & @CRLF _ + & "/CMD: Change state of current console window." & @CRLF & @CRLF + + Local $Info_Trail = "Type CmdUtil.exe 'Command' to see the detailed info." & @CRLF + + If $CMDLINE[0] < 2 Then + ConsoleWrite($Info_Head & $Info_String & $Info_Text & $Info_Att & $Info_Misc & $Info_Trail) + Exit 0 + ElseIf $CMDLINE[2] = "STR" Then + ConsoleWrite($Info_Head & $Info_String & $Info_Trail) + Exit 0 + ElseIf $CMDLINE[2] = "TXT" Then + ConsoleWrite($Info_Head & $Info_Text & $Info_Trail) + Exit 0 + ElseIf $CMDLINE[2] = "ATT" Then + ConsoleWrite($Info_Head & $Info_Att & $Info_Trail) + Exit 0 + ElseIf $CMDLINE[2] = "MISC" Then + ConsoleWrite($Info_Head & $Info_Misc & $Info_Trail) + Exit 0 + Else + ConsoleWrite($Info_Head & $Info_String & $Info_Text & $Info_Att & $Info_Trail) + Exit 0 + EndIf +EndFunc + + diff --git a/CmdUtil32.exe b/CmdUtil32.exe new file mode 100644 index 0000000..4771e46 Binary files /dev/null and b/CmdUtil32.exe differ diff --git a/CmdUtil64.exe b/CmdUtil64.exe new file mode 100644 index 0000000..d9c84cf Binary files /dev/null and b/CmdUtil64.exe differ diff --git a/Monitor.au3 b/Monitor.au3 new file mode 100644 index 0000000..6892b54 --- /dev/null +++ b/Monitor.au3 @@ -0,0 +1,216 @@ +#NoTrayIcon +#CS ==================================================================================================== +#Region ;**** Directives created by AutoIt3Wrapper_GUI **** +#AutoIt3Wrapper_Outfile=Monitor32.exe +#AutoIt3Wrapper_Outfile_x64=Monitor64.exe +#AutoIt3Wrapper_UseUpx=Y +#AutoIt3Wrapper_Compile_Both=Y +#AutoIt3Wrapper_UseX64=Y +#AutoIt3Wrapper_Change2CUI=Y +#AutoIt3Wrapper_Res_Comment=Monitor On/Off +#AutoIt3Wrapper_Res_Description=Monitor On/Off +#AutoIt3Wrapper_Res_Fileversion=1.0.0.0 +#AutoIt3Wrapper_Res_ProductVersion=1.0.0.0 +#AutoIt3Wrapper_Res_LegalCopyright=Wayne Tan +#AutoIt3Wrapper_Res_Field=ProductName|Monitor.exe +#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** + +If $CMDLINE[0] < 1 Then + _Enum() + Exit 0 +Else + Switch $CMDLINE[1] + Case "/RES" + _ChgRes() + Case "/ON" + _Monitor_ON() + Exit 0 + Case "/OFF" + _Monitor_OFF() + Exit 0 + Case "/?" + _Usage() + Exit 0 + Case Else + _Usage() + Exit 0 + EndSwitch +EndIf + +Exit 0 + +#CE ==================================================================================================== + +#Include +#Include +#Include +#Include +#Include + +Global Const $lciWM_SYSCommand = 274 +Global Const $lciSC_MonitorPower = 61808 +Global Const $lciPower_Off = 2 +Global Const $lciPower_On = -1 +Global $MonitorIsOff = False + + +Func _MonitorOnOff() + Local $Tips = @CRLF & "CMD:" & @TAB & "/MON ON|OFF" & @CRLF _ + & "Usage:" & @TAB & "Turn on/off the display monitor." & @CRLF _ + & "Parameters:" & @CRLF _ + & "ON:" & @TAB & "Turn on the monitor." & @CRLF _ + & "OFF:" & @TAB & "Turn off the monitor." & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + EndIf + Local $SW = $CMDLINE[2] + Switch $SW + Case "ON" + _Monitor_ON() + Exit + Case "OFF" + _Monitor_OFF() + Exit + Case Else + ConsoleWrite($Tips) + Exit 0 + EndSwitch + Exit 0 +EndFunc + + + +Func _Monitor_ON() +$MonitorIsOff = False +Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]') +DllCall('user32.dll', 'int', 'SendMessage', _ +'hwnd', $Progman_hwnd, _ +'int', $lciWM_SYSCommand, _ +'int', $lciSC_MonitorPower, _ +'int', $lciPower_On) +Send("{Capslock}") +EndFunc + + +Func _Monitor_OFF() +$MonitorIsOff = True +Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]') +;While $MonitorIsOff = True +DllCall('user32.dll', 'int', 'SendMessage', _ +'hwnd', $Progman_hwnd, _ +'int', $lciWM_SYSCommand, _ +'int', $lciSC_MonitorPower, _ +'int', $lciPower_Off) +;_IdleWaitCommit(0) +;Sleep(20) +;WEnd +EndFunc + + +Func _IdleWaitCommit($idlesec) +Local $iSave, $LastInputInfo = DllStructCreate ("uint;dword") +DllStructSetData ($LastInputInfo, 1, DllStructGetSize ($LastInputInfo)) +DllCall ("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr ($LastInputInfo)) +Do +$iSave = DllStructGetData ($LastInputInfo, 2) +Sleep(60) +DllCall ("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr ($LastInputInfo)) +Until (DllStructGetData ($LastInputInfo, 2)-$iSave) > $idlesec or $MonitorIsOff = False +Return DllStructGetData ($LastInputInfo, 2)-$iSave +EndFunc + +Func _Enum() + Local $Data, $i = 0 + ConsoleWrite(@CRLF & "--- Desktop Monitor Information ---" & @CRLF) + ConsoleWrite(@CRLF & "Supported Modes:" & @CRLF) + While 1 + $Data = _WinAPI_EnumDisplaySettings('', $i) + If IsArray($Data) Then + ConsoleWrite($Data[0] & " X " & $Data[1] & @TAB & $Data[2] & 'Bit' & @TAB & $Data[3] & "Hz" & @TAB & "Mode:" & $Data[4] & @CRLF) + Else + ExitLoop + EndIf + $i += 3 + WEnd + $Current = _WinAPI_EnumDisplaySettings('',$ENUM_CURRENT_SETTINGS) + ;_ArrayUnique($Current) + Local $CurrInfo = @CRLF & 'Current Settings: ' & @CRLF _ + & 'Resolution:' & @TAB & $Current[0] & ' X ' & $Current[1] & @CRLF _ + & 'Deepth:' & @TAB & @TAB & $Current[2] & 'Bit' & @CRLF _ + & 'Frequency:' & @TAB & $Current[3] & 'HZ' & @CRLF _ + & 'Mode:' & @TAB & @TAB & $Current[4] & @CRLF + ConsoleWrite($CurrInfo) + Exit 0 +EndFunc + + +Func _ChgRes() + Switch $CMDLINE[0] + Case 1 + $i_Width = @DesktopWidth + $i_Height = @DesktopHeight + $i_BitsPP = @DesktopDepth + $i_RefreshRate = @DesktopRefresh + Case 2 + $i_Width = $CMDLINE[2] + $i_Height = @DesktopHeight + $i_BitsPP = @DesktopDepth + $i_RefreshRate = @DesktopRefresh + Case 3 + $i_Width = $CMDLINE[2] + $i_Height = $CMDLINE[3] + $i_BitsPP = @DesktopDepth + $i_RefreshRate = @DesktopRefresh + Case 4 + $i_Width = $CMDLINE[2] + $i_Height = $CMDLINE[3] + $i_BitsPP = $CMDLINE[4] + $i_RefreshRate = @DesktopRefresh + Case 5 + $i_Width = $CMDLINE[2] + $i_Height = $CMDLINE[3] + $i_BitsPP = $CMDLINE[4] + $i_RefreshRate = $CMDLINE[5] + Case Else + $i_Width = $CMDLINE[2] + $i_Height = $CMDLINE[3] + $i_BitsPP = $CMDLINE[4] + $i_RefreshRate = $CMDLINE[5] + EndSwitch + If $CMDLINE[0] >= 2 Then + If $CMDLINE[2] = "/?" Then + ConsoleWrite(@CRLF & "CMD:" & @TAB & "/RES [Width] [Height] [ColorDeepth] [RefreshRate]" & @CRLF) + Exit 0 + EndIf + EndIf + Local $RET = _ChangeScreenRes($i_Width, $i_Height, $i_BitsPP, $i_RefreshRate) + If @Error = 0 Then + ConsoleWrite("Return Code: " & @Error & @CRLF & "Set Screen Resolution Successed." & @CRLF) + Exit 0 + Else + ConsoleWrite("Return Code: " & @Error & @CRLF & "Set Screen Resolution Failed." & @CRLF) + Exit 1 + EndIf + Exit +EndFunc + + + +#CS ==================================================================================================== +Func _Usage() +Local $MSG = @CRLF & "Monitor.exe V1.0 Build 20160614" & @CRLF & @CRLF _ + & "Usage:" & @TAB & "Set Screren Resoluton / Turn Monitor On/Off." & @CRLF & @CRLF _ + & "Command:" & @CRLF _ + & "Monitor.exe /ON " & @TAB & "Turn on the monitor." & @CRLF _ + & "Monitor.exe /OFF " & @TAB & "Turn off the monitor." & @CRLF _ + & "Monitor.exe /RES [Width] [Height] [ColorDeepth] [RefreshRate]" & @CRLF & @CRLF +ConsoleWrite($MSG) +Exit 0 +EndFunc +#CE ==================================================================================================== + +Func _Quit() +_Monitor_ON() +Exit +EndFunc diff --git a/StringMD5.au3 b/StringMD5.au3 new file mode 100644 index 0000000..05456ee --- /dev/null +++ b/StringMD5.au3 @@ -0,0 +1,436 @@ +Const $BITS_TO_A_BYTE = 8 +Const $BYTES_TO_A_WORD = 4 +Const $BITS_TO_A_WORD = $BYTES_TO_A_WORD * $BITS_TO_A_BYTE + +Dim $m_lOnBits[31] +Dim $m_l2Power[31] + + +Func Class_Initialize() + + $m_lOnBits[0] = 1 ; 00000000000000000000000000000001 + $m_lOnBits[1] = 3 ; 00000000000000000000000000000011 + $m_lOnBits[2] = 7 ; 00000000000000000000000000000111 + $m_lOnBits[3] = 15 ; 00000000000000000000000000001111 + $m_lOnBits[4] = 31 ; 00000000000000000000000000011111 + $m_lOnBits[5] = 63 ; 00000000000000000000000000111111 + $m_lOnBits[6] = 127 ; 00000000000000000000000001111111 + $m_lOnBits[7] = 255 ; 00000000000000000000000011111111 + $m_lOnBits[8] = 511 ; 00000000000000000000000111111111 + $m_lOnBits[9] = 1023 ; 00000000000000000000001111111111 + $m_lOnBits[10] = 2047 ; 00000000000000000000011111111111 + $m_lOnBits[11] = 4095 ; 00000000000000000000111111111111 + $m_lOnBits[12] = 8191 ; 00000000000000000001111111111111 + $m_lOnBits[13] = 16383 ; 00000000000000000011111111111111 + $m_lOnBits[14] = 32767 ; 00000000000000000111111111111111 + $m_lOnBits[15] = 65535 ; 00000000000000001111111111111111 + $m_lOnBits[16] = 131071 ; 00000000000000011111111111111111 + $m_lOnBits[17] = 262143 ; 00000000000000111111111111111111 + $m_lOnBits[18] = 524287 ; 00000000000001111111111111111111 + $m_lOnBits[19] = 1048575 ; 00000000000011111111111111111111 + $m_lOnBits[20] = 2097151 ; 00000000000111111111111111111111 + $m_lOnBits[21] = 4194303 ; 00000000001111111111111111111111 + $m_lOnBits[22] = 8388607 ; 00000000011111111111111111111111 + $m_lOnBits[23] = 16777215 ; 00000000111111111111111111111111 + $m_lOnBits[24] = 33554431 ; 00000001111111111111111111111111 + $m_lOnBits[25] = 67108863 ; 00000011111111111111111111111111 + $m_lOnBits[26] = 134217727 ; 00000111111111111111111111111111 + $m_lOnBits[27] = 268435455 ; 00001111111111111111111111111111 + $m_lOnBits[28] = 536870911 ; 00011111111111111111111111111111 + $m_lOnBits[29] = 1073741823 ; 00111111111111111111111111111111 + $m_lOnBits[30] = 2147483647 ; 01111111111111111111111111111111 + + + $m_l2Power[0] = 1 ; 00000000000000000000000000000001 + $m_l2Power[1] = 2 ; 00000000000000000000000000000010 + $m_l2Power[2] = 4 ; 00000000000000000000000000000100 + $m_l2Power[3] = 8 ; 00000000000000000000000000001000 + $m_l2Power[4] = 16 ; 00000000000000000000000000010000 + $m_l2Power[5] = 32 ; 00000000000000000000000000100000 + $m_l2Power[6] = 64 ; 00000000000000000000000001000000 + $m_l2Power[7] = 128 ; 00000000000000000000000010000000 + $m_l2Power[8] = 256 ; 00000000000000000000000100000000 + $m_l2Power[9] = 512 ; 00000000000000000000001000000000 + $m_l2Power[10] = 1024 ; 00000000000000000000010000000000 + $m_l2Power[11] = 2048 ; 00000000000000000000100000000000 + $m_l2Power[12] = 4096 ; 00000000000000000001000000000000 + $m_l2Power[13] = 8192 ; 00000000000000000010000000000000 + $m_l2Power[14] = 16384 ; 00000000000000000100000000000000 + $m_l2Power[15] = 32768 ; 00000000000000001000000000000000 + $m_l2Power[16] = 65536 ; 00000000000000010000000000000000 + $m_l2Power[17] = 131072 ; 00000000000000100000000000000000 + $m_l2Power[18] = 262144 ; 00000000000001000000000000000000 + $m_l2Power[19] = 524288 ; 00000000000010000000000000000000 + $m_l2Power[20] = 1048576 ; 00000000000100000000000000000000 + $m_l2Power[21] = 2097152 ; 00000000001000000000000000000000 + $m_l2Power[22] = 4194304 ; 00000000010000000000000000000000 + $m_l2Power[23] = 8388608 ; 00000000100000000000000000000000 + $m_l2Power[24] = 16777216 ; 00000001000000000000000000000000 + $m_l2Power[25] = 33554432 ; 00000010000000000000000000000000 + $m_l2Power[26] = 67108864 ; 00000100000000000000000000000000 + $m_l2Power[27] = 134217728 ; 00001000000000000000000000000000 + $m_l2Power[28] = 268435456 ; 00010000000000000000000000000000 + $m_l2Power[29] = 536870912 ; 00100000000000000000000000000000 + $m_l2Power[30] = 1073741824 ; 01000000000000000000000000000000 +EndFunc + + +Func LShift($lValue, $iShiftBits) + + If $iShiftBits = 0 Then + Return $lValue + + + ElseIf $iShiftBits = 31 Then + If BitAND($lValue, 1) Then + Return 0x80000000 + Else + Return 0 + Endif + + + + ElseIf $iShiftBits < 0 Or $iShiftBits > 31 Then + SetError(6) + Endif + + + If BitAND($lValue, $m_l2Power[31 - $iShiftBits]) Then + + + Return BitOR((BitAND($lValue, $m_lOnBits[31 - ($iShiftBits + 1)]) * _ + $m_l2Power[$iShiftBits]) , 0x80000000) + + Else + + Return (BitAND($lValue, $m_lOnBits[31 - $iShiftBits]) * _ + $m_l2Power[$iShiftBits]) + + Endif +EndFunc + + +Func RShift($lValue, $iShiftBits) + + Local $RShift + + + If $iShiftBits = 0 Then + Return $lValue + + + ElseIf $iShiftBits = 31 Then + If BitAND($lValue, 0x80000000) Then + Return 1 + Else + Return 0 + Endif + + + ElseIf $iShiftBits < 0 Or $iShiftBits > 31 Then + SetError(6) + Endif + + + $RShift = int(BitAND($lValue, 0x7FFFFFFE) / $m_l2Power[$iShiftBits]) + + + If BitAND($lValue, 0x80000000) Then + + $RShift = int(BitOR($RShift, (0x40000000 / $m_l2Power[$iShiftBits - 1]))) + Endif + + Return $RShift + +EndFunc + + +Func RShiftSigned($lValue , $iShiftBits) + + + If $iShiftBits = 0 Then + Return $lValue + + ElseIf $iShiftBits = 31 Then + + If BitAND($lValue, 0x80000000) Then + Return -1 + Else + Return 0 + Endif + + + ElseIf $iShiftBits < 0 Or $iShiftBits > 31 Then + SetError(6) + Endif + + Return Int($lValue / $m_l2Power[$iShiftBits]) +EndFunc + + +Func RotateLeft($lValue , $iShiftBits) + Return BitOR(LShift($lValue, $iShiftBits), RShift($lValue, (32 - $iShiftBits))) +EndFunc + + +Func AddUnsigned($lX , $lY ) + + $lX8 = BitAND($lX, 0x80000000) + $lY8 = BitAND($lY, 0x80000000) + $lX4 = BitAND($lX, 0x40000000) + $lY4 = BitAND($lY, 0x40000000) + + $lResult = BitAND($lX, 0x3FFFFFFF) + BitAND($lY, 0x3FFFFFFF) + + If BitAND($lX4, $lY4) Then + $lResult = BitXOR($lResult, 0x80000000, $lX8, $lY8) + ElseIf BitOR($lX4 , $lY4) Then + If BitAND($lResult, 0x40000000) Then + $lResult = BitXOR($lResult, 0xC0000000, $lX8, $lY8) + Else + $lResult = BitXOR($lResult, 0x40000000, $lX8, $lY8) + Endif + Else + $lResult = BitXOR($lResult, $lX8, $lY8) + Endif + + Return $lResult +EndFunc + + +Func F($x , $y , $z ) + Return BitOR(BitAND($x, $y) , BitAND((BitNOT($x)), $z)) +EndFunc + + +Func G($x , $y , $z ) + Return BitOR(BitAND($x, $z) , BitAND($y , (BitNOT($z)))) +EndFunc + + +Func H($x , $y , $z ) + Return BitXOR($x , $y , $z) +EndFunc + + +Func I($x , $y , $z ) + Return BitXOR($y , BitOR($x , (BitNOT($z)))) +EndFunc + + +Func FF(ByRef $a , $b , $c , $d , $x , $s , $ac ) + $a = AddUnsigned($a, AddUnsigned(AddUnsigned(F($b, $c, $d), $x), $ac)) + $a = RotateLeft($a, $s) + $a = AddUnsigned($a, $b) +EndFunc + + +Func GG(ByRef $a , $b , $c , $d , $x , $s , $ac ) + $a = AddUnsigned($a, AddUnsigned(AddUnsigned(G($b, $c, $d), $x), $ac)) + $a = RotateLeft($a, $s) + $a = AddUnsigned($a, $b) +EndFunc + + +Func HH(ByRef $a , $b , $c , $d , $x , $s , $ac ) + $a = AddUnsigned($a, AddUnsigned(AddUnsigned(H($b, $c, $d), $x), $ac)) + $a = RotateLeft($a, $s) + $a = AddUnsigned($a, $b) +EndFunc + + +Func II(ByRef $a , $b , $c , $d , $x , $s , $ac ) + $a = AddUnsigned($a, AddUnsigned(AddUnsigned(I($b, $c, $d), $x), $ac)) + $a = RotateLeft($a, $s) + $a = AddUnsigned($a, $b) +EndFunc + + +Func ConvertToWordArray($sMessage ) + Dim $lWordArray[1] + + Const $MODULUS_BITS = 512 + Const $CONGRUENT_BITS = 448 + + $lMessageLength = StringLen($sMessage) + + $lNumberOfWords = (int(($lMessageLength + _ + int(($MODULUS_BITS - $CONGRUENT_BITS) / $BITS_TO_A_BYTE)) / _ + int($MODULUS_BITS / $BITS_TO_A_BYTE)) + 1) * _ + int($MODULUS_BITS / $BITS_TO_A_WORD) + ReDim $lWordArray[$lNumberOfWords] + + $lBytePosition = 0 + $lByteCount = 0 + Do + + $lWordCount = int($lByteCount / $BYTES_TO_A_WORD) + + + $lBytePosition = (Mod($lByteCount , $BYTES_TO_A_WORD)) * $BITS_TO_A_BYTE + $lWordArray[$lWordCount] = BitOR($lWordArray[$lWordCount] , _ + LShift(Asc(StringMid($sMessage, $lByteCount + 1, 1)), $lBytePosition)) + $lByteCount = $lByteCount + 1 + Until $lByteCount >= $lMessageLength + + + $lWordCount = int($lByteCount / $BYTES_TO_A_WORD) + $lBytePosition = (Mod($lByteCount , $BYTES_TO_A_WORD)) * $BITS_TO_A_BYTE + + + $lWordArray[$lWordCount] = BitOR($lWordArray[$lWordCount] , _ + LShift(0x80, $lBytePosition)) + + + $lWordArray[$lNumberOfWords - 2] = LShift($lMessageLength, 3) + $lWordArray[$lNumberOfWords - 1] = RShift($lMessageLength, 29) + + Return $lWordArray +EndFunc + + +Func WordToHex($lValue) + + $WordToHex="" + + For $lCount = 0 To 3 + $lByte = BitAND(RShift($lValue, $lCount * $BITS_TO_A_BYTE) , _ + $m_lOnBits[$BITS_TO_A_BYTE - 1]) + $WordToHex = $WordToHex & StringRight("0" & Hex($lByte,2), 2) + Next + Return $WordToHex +EndFunc + + + +Func MD5($sMessage) + + Const $S11 = 7 + Const $S12 = 12 + Const $S13 = 17 + Const $S14 = 22 + Const $S21 = 5 + Const $S22 = 9 + Const $S23 = 14 + Const $S24 = 20 + Const $S31 = 4 + Const $S32 = 11 + Const $S33 = 16 + Const $S34 = 23 + Const $S41 = 6 + Const $S42 = 10 + Const $S43 = 15 + Const $S44 = 21 + + Class_Initialize() + + + $x = ConvertToWordArray($sMessage) + + + $a = 0x67452301 + $b = 0xEFCDAB89 + $c = 0x98BADCFE + $d = 0x10325476 + + + For $k = 0 To UBound($x)-1 Step 16 + $AA = $a + $BB = $b + $CC = $c + $DD = $d + + + FF( $a, $b, $c, $d, $x[$k + 0], $S11, 0xD76AA478 ) + FF( $d, $a, $b, $c, $x[$k + 1], $S12, 0xE8C7B756 ) + FF( $c, $d, $a, $b, $x[$k + 2], $S13, 0x242070DB ) + FF( $b, $c, $d, $a, $x[$k + 3], $S14, 0xC1BDCEEE ) + FF( $a, $b, $c, $d, $x[$k + 4], $S11, 0xF57C0FAF ) + FF( $d, $a, $b, $c, $x[$k + 5], $S12, 0x4787C62A ) + FF( $c, $d, $a, $b, $x[$k + 6], $S13, 0xA8304613 ) + FF( $b, $c, $d, $a, $x[$k + 7], $S14, 0xFD469501 ) + FF( $a, $b, $c, $d, $x[$k + 8], $S11, 0x698098D8 ) + FF( $d, $a, $b, $c, $x[$k + 9], $S12, 0x8B44F7AF ) + FF( $c, $d, $a, $b, $x[$k + 10], $S13, 0xFFFF5BB1) + FF( $b, $c, $d, $a, $x[$k + 11], $S14, 0x895CD7BE) + FF( $a, $b, $c, $d, $x[$k + 12], $S11, 0x6B901122) + FF( $d, $a, $b, $c, $x[$k + 13], $S12, 0xFD987193) + FF( $c, $d, $a, $b, $x[$k + 14], $S13, 0xA679438E) + FF( $b, $c, $d, $a, $x[$k + 15], $S14, 0x49B40821) + + GG( $a, $b, $c, $d, $x[$k + 1], $S21, 0xF61E2562 ) + GG( $d, $a, $b, $c, $x[$k + 6], $S22, 0xC040B340 ) + GG( $c, $d, $a, $b, $x[$k + 11], $S23, 0x265E5A51) + GG( $b, $c, $d, $a, $x[$k + 0], $S24, 0xE9B6C7AA ) + GG( $a, $b, $c, $d, $x[$k + 5], $S21, 0xD62F105D ) + GG( $d, $a, $b, $c, $x[$k + 10], $S22, 0x2441453 ) + GG( $c, $d, $a, $b, $x[$k + 15], $S23, 0xD8A1E681) + GG( $b, $c, $d, $a, $x[$k + 4], $S24, 0xE7D3FBC8 ) + GG( $a, $b, $c, $d, $x[$k + 9], $S21, 0x21E1CDE6 ) + GG( $d, $a, $b, $c, $x[$k + 14], $S22, 0xC33707D6) + GG( $c, $d, $a, $b, $x[$k + 3], $S23, 0xF4D50D87 ) + GG( $b, $c, $d, $a, $x[$k + 8], $S24, 0x455A14ED ) + GG( $a, $b, $c, $d, $x[$k + 13], $S21, 0xA9E3E905) + GG( $d, $a, $b, $c, $x[$k + 2], $S22, 0xFCEFA3F8 ) + GG( $c, $d, $a, $b, $x[$k + 7], $S23, 0x676F02D9 ) + GG( $b, $c, $d, $a, $x[$k + 12], $S24, 0x8D2A4C8A) + + HH( $a, $b, $c, $d, $x[$k + 5], $S31, 0xFFFA3942 ) + HH( $d, $a, $b, $c, $x[$k + 8], $S32, 0x8771F681 ) + HH( $c, $d, $a, $b, $x[$k + 11], $S33, 0x6D9D6122) + HH( $b, $c, $d, $a, $x[$k + 14], $S34, 0xFDE5380C) + HH( $a, $b, $c, $d, $x[$k + 1], $S31, 0xA4BEEA44 ) + HH( $d, $a, $b, $c, $x[$k + 4], $S32, 0x4BDECFA9 ) + HH( $c, $d, $a, $b, $x[$k + 7], $S33, 0xF6BB4B60 ) + HH( $b, $c, $d, $a, $x[$k + 10], $S34, 0xBEBFBC70) + HH( $a, $b, $c, $d, $x[$k + 13], $S31, 0x289B7EC6) + HH( $d, $a, $b, $c, $x[$k + 0], $S32, 0xEAA127FA ) + HH( $c, $d, $a, $b, $x[$k + 3], $S33, 0xD4EF3085 ) + HH( $b, $c, $d, $a, $x[$k + 6], $S34, 0x4881D05 ) + HH( $a, $b, $c, $d, $x[$k + 9], $S31, 0xD9D4D039 ) + HH( $d, $a, $b, $c, $x[$k + 12], $S32, 0xE6DB99E5) + HH( $c, $d, $a, $b, $x[$k + 15], $S33, 0x1FA27CF8) + HH( $b, $c, $d, $a, $x[$k + 2], $S34, 0xC4AC5665 ) + + II( $a, $b, $c, $d, $x[$k + 0], $S41, 0xF4292244 ) + II( $d, $a, $b, $c, $x[$k + 7], $S42, 0x432AFF97 ) + II( $c, $d, $a, $b, $x[$k + 14], $S43, 0xAB9423A7) + II( $b, $c, $d, $a, $x[$k + 5], $S44, 0xFC93A039 ) + II( $a, $b, $c, $d, $x[$k + 12], $S41, 0x655B59C3) + II( $d, $a, $b, $c, $x[$k + 3], $S42, 0x8F0CCC92 ) + II( $c, $d, $a, $b, $x[$k + 10], $S43, 0xFFEFF47D) + II( $b, $c, $d, $a, $x[$k + 1], $S44, 0x85845DD1 ) + II( $a, $b, $c, $d, $x[$k + 8], $S41, 0x6FA87E4F ) + II( $d, $a, $b, $c, $x[$k + 15], $S42, 0xFE2CE6E0) + II( $c, $d, $a, $b, $x[$k + 6], $S43, 0xA3014314 ) + II( $b, $c, $d, $a, $x[$k + 13], $S44, 0x4E0811A1) + II( $a, $b, $c, $d, $x[$k + 4], $S41, 0xF7537E82 ) + II( $d, $a, $b, $c, $x[$k + 11], $S42, 0xBD3AF235) + II( $c, $d, $a, $b, $x[$k + 2], $S43, 0x2AD7D2BB ) + II( $b, $c, $d, $a, $x[$k + 9], $S44, 0xEB86D391 ) + + $a = AddUnsigned($a, $AA) + $b = AddUnsigned($b, $BB) + $c = AddUnsigned($c, $CC) + $d = AddUnsigned($d, $DD) + Next + + + Return StringLower(WordToHex($a) & WordToHex($b) & WordToHex($c) & WordToHex($d)) +EndFunc + + +Func _StringMD5() + Local $Tips = @CRLF & "CMD:" & @TAB & "/MD5 String" & @CRLF _ + & "Usage:" & @TAB & "Return the MD5 value of a specified string." & @CRLF & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $RET = MD5($CMDLINE[2]) + ;ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "Result: " & $RET & @CRLF) + ConsoleWrite(StringUpper($RET)) + Exit 0 + EndIf +EndFunc + diff --git a/StringX.au3 b/StringX.au3 new file mode 100644 index 0000000..124b9e8 --- /dev/null +++ b/StringX.au3 @@ -0,0 +1,832 @@ +#NoTrayIcon +#Include +#Include +#Include + +; 2016/12/08 Add /H2S & /S2H Function + +#CS ---------------------------------------------------------------------------- +If $CMDLINE[0] < 1 Then _Usage() +Switch $CMDLINE[1] + Case "/?" + _Usage() + Case "/BTW" + _StrBetween() + Case "/CMP" + _StrCompare() + Case "/FMT" + _StringFormat() + Case "/SIS" + _StringInStr() + Case "/DIV" + _StrDivision() + Case "/PAR" + _StrSplit() + Case "/ISR" + _StrInsert() + Case "/IAN" + _StrIsAlNum() + Case "/ALP" + _StrIsAlpha() + Case "/ASC" + _StrIsASCII() + Case "/DIG" + _StrIsDigit() + Case "/SIL" + _StrIsLower() + Case "/SIU" + _StrIsUpper() + Case "/BLK" + _StrIsSpace() + Case "/HEX" + _StrIsHEX() + Case "/LEN" + _StrLenth() + Case "/LFT" + _StrLeft() + Case "/RIT" + _StrRight() + Case "/STL" + _StrTrimLeft() + Case "/STR" + _StrTrimRight() + Case "/MID" + _StrMid() + Case "/SRP" + _StrReplace() + Case "/REV" + _StrReverse() + Case "/SWS" + _StrStripWS() + Case Else + _Usage() +EndSwitch +#CE ---------------------------------------------------------------------------- + + + +Func _StrBetween() + Local $Tips = @CRLF & "CMD:" & @TAB & "/BTW ""String"" ""Start"" ""End"" [Mode=0] [Case=0]" & @CRLF _ + & "Usage:" & @TAB & "Find strings between two string delimiters." & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "String:" & @TAB & "The string to search." & @CRLF _ + & "Start:" & @TAB & "The beginning of the string to find." & @CRLF _ + & @TAB & "(If empty, starts at the beginning.)" & @CRLF _ + & "End:" & @TAB & "The end of the string to find." & @CRLF _ + & @TAB & "(If empty, searches from ""Start"" to end of string.)" & @CRLF _ + & "Mode: (Optional)" & @CRLF _ + & @TAB & "0: The ""End"" string at the end of a match starts the next possible match." & @CRLF _ + & @TAB & "1: A further instance of the ""Start"" starts the next match." & @CRLF _ + & "Case: (Optional)" & @CRLF _ + & @TAB & "0: Case-Insensitive." & @CRLF _ + & @TAB & "1: Case-Sensitive." & @CRLF _ + & "Return Code:" & @CRLF _ + & @TAB & "Success: The first found strings." & @CRLF _ + & @TAB & "Fail: Error." & @CRLF & @CRLF _ + & "Use /F:FileName to set ""String"" as the contents of the specified file." & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + If $CMDLINE[2] = "/?" Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $sString = $CMDLINE[2] + Local $sStart = '' + Local $sEnd = '' + Local $iMode = 0 + Local $iCase = 0 + If $CMDLINE[0] >= 3 Then Local $sStart = $CMDLINE[3] + If $CMDLINE[0] >= 4 Then Local $sEnd = $CMDLINE[4] + If $CMDLINE[0] >= 5 Then + If $CMDLINE[5] = 0 Then + Local $iMode = 0 + Else + Local $iMode = 1 + EndIf + EndIf + EndIf + EndIf + If $CMDLINE[0] >= 6 Then Local $iCase = $CMDLINE[6] + $sString = StringReplace($sString, "@CRLF", @CRLF) + $sString = StringReplace($sString, "@CR", @CR) + $sString = StringReplace($sString, "@LF", @LF) + If StringLeft($sString, 3) = "/F:" Then + Local $sFile = StringTrimLeft( $sString, 3 ) + Local $File = FileOpen($sFile) + Local $sString = FileRead($File) + FileClose($File) + EndIf + + $RET = _StringBetween( $sString, $sStart, $sEnd, $iMode, $iCase) + If IsArray($RET) Then + ConsoleWrite("--> Total SubStrings: " & UBound($RET) &@CRLF) + For $i = 0 To UBound($RET) - 1 + ConsoleWrite("#"&$i&":"&@TAB&$RET[$i] &@CRLF) + Next + Exit 0 + Else + ConsoleWrite(">>> Errors Occurred." &@CRLF) + Exit 0 + EndIf +EndFunc + + +Func _StrCompare() + Local $Tips = @CRLF & "CMD:" & @TAB & "/CMP ""String1"" ""String2"" [CaseSense=0/1]" & @CRLF _ + & "Usage:" & @TAB & "Compare two strings with options." & @CRLF _ + & "Return Code:" & @CRLF _ + & " 0: String1 and String2 are equal." & @CRLF _ + & " 1: String1 is greater than String2." & @CRLF _ + & " -1: String1 is less than String2." & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite("Parameters Format Error." & @CRLF & $Tips) + Exit + ElseIf $CMDLINE[0] = 2 Then + If $CMDLINE[2] = "/?" Then + ConsoleWrite($Tips) + Exit + Else + ConsoleWrite("Parameters Format Error." & @CRLF & $Tips) + Exit + EndIf + ElseIf $CMDLINE[0] = 3 Then + Local $Case = 0 + ElseIf $CMDLINE[0] = 4 Then + Local $Case = $CMDLINE[4] + Else + Local $Case = $CMDLINE[4] + EndIf + Local $RET = StringCompare($CMDLINE[2],$CMDLINE[3],$Case) + ConsoleWrite($RET &@CRLF) + Exit 0 +EndFunc + + +Func _StringFormat() + Local $Tips = @CRLF & "CMD:" & @TAB & "/FMT String" & @CRLF _ + & "Usage:" & @TAB & "Return a C sprintf() style string." & @CRLF + Local $sParam = StringTrimLeft($CMDLINERAW, StringLen($CMDLINE[1])) + Local $RET = StringFormat($CMDLINE[2], $sParam) + ConsoleWrite($RET&@CRLF) + Exit 0 +EndFunc + + +Func _StringInStr() + Local $Tips = @CRLF & "CMD:" & @TAB & "/SIS String Substring [Case] [Occurrence] [Start] [Count]" & @CRLF _ + & "Usage:" & @TAB & "Check if a string contains a given substring." & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "String:" & @TAB & @TAB & "The string to evaluate. " & @CRLF _ + & "Substring:" & @TAB & "The substring to search for. " & @CRLF _ + & "Case:" & @TAB & @TAB & "Indicate if the operation should be case sensitive(0/1)." & @CRLF _ + & "Occurrence:" & @TAB & "Occurrence of the substring to find in the string.(Def=1)" & @CRLF _ + & "Start:" & @TAB & @TAB & "The starting position of the search.(Def=1)" & @CRLF _ + & "Count:" & @TAB & @TAB & "Number of char to search, must be longer than the substring." & @CRLF & @CRLF _ + & "Return Code: " & @CRLF _ + & "Success: The position of the substring." & @CRLF _ + & "Failure: Return 0 if substring not found." & @CRLF + + If $CMDLINE[0] < 3 Then + ConsoleWrite("Parameters Format Error." & @CRLF & $Tips) + Exit 0 + EndIf + + If StringLeft($CMDLINE[2],3) = "/F:" Then + Local $FileName = StringTrimLeft($CMDLINE[2],3) + Local $File = FileOpen($FileName,0) + Local $Str = FileRead($File) + Else + Local $Str = $CMDLINE[2] + $Str = StringReplace($Str, "@CRLF", @CRLF) + $Str = StringReplace($Str, "@CR", @CR) + $Str = StringReplace($Str, "@LF", @LF) + EndIf + + If StringLeft($CMDLINE[3],3) = "/F:" Then + Local $FileName = StringTrimLeft($CMDLINE[3],3) + Local $File = FileOpen($FileName,0) + Local $SubStr = FileRead($File) + Else + Local $SubStr = $CMDLINE[3] + $SubStr = StringReplace($SubStr, "@CRLF", @CRLF) + $SubStr = StringReplace($SubStr, "@CR", @CR) + $SubStr = StringReplace($SubStr, "@LF", @LF) + EndIf + + Local $iCase = 0 + Local $iOccur = 1 + Local $iStart = 1 + Local $iCount = "" + If $CMDLINE[0] >= 4 Then Local $iCase = $CMDLINE[4] + If $CMDLINE[0] >= 5 Then Local $iOccur = $CMDLINE[5] + If $CMDLINE[0] >= 6 Then Local $iStart = $CMDLINE[6] + If $CMDLINE[0] >= 7 Then + Local $iCount = $CMDLINE[7] + If $iCount < StringLen($CMDLINE[3]) Then + Local $Err = @CRLF & "Parameters Error." & @CRLF _ + & "The ""Count"" parameter must be longer than the substring." & @CRLF + ConsoleWrite($Err) + Exit + EndIf + EndIf + + If $CMDLINE[0] >= 7 Then + Local $RET = StringInStr($Str, $SubStr, $iCase, $iOccur, $iStart, $iCount) + ConsoleWrite($RET &@CRLF) + Exit 0 + Else + Local $RET = StringInStr($Str, $SubStr, $iCase, $iOccur, $iStart) + ConsoleWrite($RET &@CRLF) + Exit 0 + EndIf + +EndFunc + + + +Func _StrExplode() + Local $Tips = @CRLF & "CMD:" & @TAB & "/DIV String Delimiter [Limit=0]" & @CRLF _ + & "Usage:" & @TAB & "Split up a string into substrings depending on the given delimiters." & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "String:" & @TAB & @TAB & "String to be split." & @CRLF _ + & "Delimiter:" & @TAB & "Delimiter to split on." & @CRLF _ + & "Limit:" & @TAB & @TAB & "(Optional) Maximum elements to be returned." & @CRLF _ + & @TAB & @TAB & "=0: (Default) Split on every instance of the delimiter." & @CRLF _ + & @TAB & @TAB & ">0: Split until limit, last element will contain remaining portion." & @CRLF _ + & @TAB & @TAB & "<0: Split on every instance, removing limit count from end of the array." & @CRLF & @CRLF _ + & "Return Value:" & @TAB & "Return an array containing the exploded strings." & @CRLF & @CRLF _ + & "Use /F:FileName to set ""String"" as the contents of the specified file." & @CRLF + + If $CMDLINE[0] < 3 Then + ConsoleWrite($Tips) + Exit 0 + ElseIf $CMDLINE[0] = 3 Then + Local $iLimit = 0 + Else + Local $iLimit = $CMDLINE[4] + EndIf + + Local $sString = $CMDLINE[2] + $sString = StringReplace($sString, "@CRLF", @CRLF) + $sString = StringReplace($sString, "@CR", @CR) + $sString = StringReplace($sString, "@LF", @LF) + If StringLeft($sString, 3) = "/F:" Then + Local $sFile = StringTrimLeft( $sString, 3 ) + Local $File = FileOpen($sFile) + Local $sString = FileRead($File) + FileClose($File) + EndIf + + Local $RET = _StringExplode($sString, $CMDLINE[3], $iLimit) + If IsArray($RET) Then + ConsoleWrite("--> Matching SubStrings: " & UBound($RET) & @CRLF) + For $i = 0 To UBound($RET) - 1 + ConsoleWrite("#"&$i&":"&@TAB&$RET[$i] &@CRLF) + Next + Exit 0 + Else + ConsoleWrite(">>> Errors Occurred." & @CRLF) + Exit 0 + EndIf +EndFunc + + +Func _StrSplit() + Local $Tips = @CRLF & "CMD:" & @TAB & "/PAR String Delimiter [Flag=0]" & @CRLF _ + & "Usage:" & @TAB & "Split up a string into substrings depending on the given delimiters." & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "String:" & @TAB & @TAB & "String to be split." & @CRLF _ + & "Delimiter:" & @TAB & "Delimiter to split on." & @CRLF _ + & "Flag:" & @TAB & @TAB & "(Optional) Changes how the string split works." & @CRLF _ + & @TAB & @TAB & "=0: Each character of the delimiter will mark the split." & @CRLF _ + & @TAB & @TAB & "=1: Entire delimiter string is needed to mark the split." & @CRLF & @CRLF _ + & "Return Value:" & @TAB & "Return an array containing the exploded strings." & @CRLF & @CRLF _ + & "Use /F:FileName to set ""String"" as the contents of the specified file." & @CRLF + + If $CMDLINE[0] < 3 Then + ConsoleWrite($Tips) + Exit 0 + ElseIf $CMDLINE[0] = 3 Then + Local $iFlag = $STR_CHRSPLIT + Else + Local $iFlag = $CMDLINE[4] + If $iFlag = 0 Then $iFlag = $STR_CHRSPLIT + If $iFlag = 1 Then $iFlag = $STR_ENTIRESPLIT + If $iFlag <> 1 And $iFlag <> 0 Then $iFlag = $STR_NOCOUNT + EndIf + + Local $sString = $CMDLINE[2] + $sString = StringReplace($sString, "@CRLF", @CRLF) + $sString = StringReplace($sString, "@CR", @CR) + $sString = StringReplace($sString, "@LF", @LF) + If StringLeft($sString, 3) = "/F:" Then + Local $sFile = StringTrimLeft( $sString, 3 ) + Local $File = FileOpen($sFile) + Local $sString = FileRead($File) + FileClose($File) + EndIf + + Local $RET = StringSplit($sString, $CMDLINE[3], $iFlag) + If IsArray($RET) Then + ConsoleWrite("--> Matching SubStrings: " & $RET[0] & @CRLF) + For $i = 1 To $RET[0] + ConsoleWrite("#"&$i&":"&@TAB&$RET[$i] & @CRLF) + Next + Exit 0 + Else + ConsoleWrite(">>> Errors Occurred." &@CRLF) + Exit 0 + EndIf +EndFunc + + +Func _StrInsert() + Local $Tips = @CRLF & "CMD:" & @TAB & "/ISR String InsertStr Position" & @CRLF _ + & "Usage:" & @TAB & "Insert a string within another string." & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "String:" & @TAB & @TAB & "Original string." & @CRLF _ + & "InsertStr:" & @TAB & "String to be inserted." & @CRLF _ + & "Position:" & @TAB & "Position to insert string." & @CRLF _ + & @TAB & @TAB & "(Negatives values count from right hand side)." & @CRLF & @CRLF _ + & "Return Value:" & @CRLF _ + & @TAB & "Success: The modified string." & @CRLF _ + & @TAB & "Failure: The original string." & @CRLF + If $CMDLINE[0] < 4 Then + ConsoleWrite($Tips) + Exit 0 + EndIf + Local $RET = _StringInsert($CMDLINE[2], $CMDLINE[3], $CMDLINE[4]) + ConsoleWrite($RET&@CRLF) + Exit 0 +EndFunc + + +Func _StrIsAlNum() + Local $Tips = @CRLF & "CMD:" & @TAB & "/IAN String" & @CRLF _ + & "Usage:" & @TAB & "Check if a string contains only alphanumeric characters." & @CRLF & @CRLF _ + & "Error Code:" & @CRLF _ + & " 0: String contains only alphanumeric characters." & @CRLF _ + & " 1: String contains non-alphanumeric characters." & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $RET = StringIsAlNum($CMDLINE[2]) + If $RET = 1 Then + ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 0" & @CRLF) + Exit 0 + Else + ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 1" & @CRLF) + Exit 1 + EndIf + EndIf +EndFunc + + +Func _StrIsAlpha() + Local $Tips = @CRLF & "CMD:" & @TAB & "/ALP String" & @CRLF _ + & "Usage:" & @TAB & "Check if a string contains only alphabetic characters." & @CRLF & @CRLF _ + & "Error Code:" & @CRLF _ + & " 0: String contains only alphabetic characters." & @CRLF _ + & " 1: String contains non-alphabetic characters." & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $RET = StringIsAlpha($CMDLINE[2]) + If $RET = 1 Then + ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 0" & @CRLF) + Exit 0 + Else + ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 1" & @CRLF) + Exit 1 + EndIf + EndIf +EndFunc + + +Func _StrIsASCII() + Local $Tips = @CRLF & "CMD:" & @TAB & "/ASC String" & @CRLF _ + & "Usage:" & @TAB & "Check if a string contains only ASCII characters(0x00 - 0x7f)." & @CRLF & @CRLF _ + & "Error Code:" & @CRLF _ + & " 0: String contains only ASCII characters." & @CRLF _ + & " 1: String contains extended ASCII characters." & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $RET = StringIsASCII($CMDLINE[2]) + If $RET = 1 Then + ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 0" & @CRLF) + Exit 0 + Else + ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 1" & @CRLF) + Exit 1 + EndIf + EndIf +EndFunc + + +Func _StrIsDigit() + Local $Tips = @CRLF & "CMD:" & @TAB & "/DIG String" & @CRLF _ + & "Usage:" & @TAB & "Check if a string contains only digit (0-9) characters." & @CRLF & @CRLF _ + & "Error Code:" & @CRLF _ + & " 0: String contains only digit characters." & @CRLF _ + & " 1: String contains non-digits characters." & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $RET = StringIsDigit($CMDLINE[2]) + If $RET = 1 Then + ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 0" & @CRLF) + Exit 0 + Else + ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 1" & @CRLF) + Exit 1 + EndIf + EndIf +EndFunc + + +Func _StrIsLower() + Local $Tips = @CRLF & "CMD:" & @TAB & "/LOW String" & @CRLF _ + & "Usage:" & @TAB & "Check if a string contains only lowercase characters." & @CRLF & @CRLF _ + & "Error Code:" & @CRLF _ + & " 0: String contains only lowercase characters." & @CRLF _ + & " 1: String contains non-lowercase characters." & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $RET = StringIsLower($CMDLINE[2]) + If $RET = 1 Then + ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 0" & @CRLF) + Exit 0 + Else + ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 1" & @CRLF) + Exit 1 + EndIf + EndIf +EndFunc + + +Func _StrIsUpper() + Local $Tips = @CRLF & "CMD:" & @TAB & "/UPR String" & @CRLF _ + & "Usage:" & @TAB & "Check if a string contains only lowercase characters." & @CRLF & @CRLF _ + & "Error Code:" & @CRLF _ + & " 0: String contains only uppercase characters." & @CRLF _ + & " 1: String contains non-uppercase characters." & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $RET = StringIsUpper($CMDLINE[2]) + If $RET = 1 Then + ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 0" & @CRLF) + Exit 0 + Else + ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 1" & @CRLF) + Exit 1 + EndIf + EndIf +EndFunc + + +Func _StrIsSpace() + Local $Tips = @CRLF & "CMD:" & @TAB & "/BLK String" & @CRLF _ + & "Usage:" & @TAB & "Check if a string contains only whitespace characters." & @CRLF & @CRLF _ + & "Error Code:" & @CRLF _ + & " 0: String contains only whitespace characters." & @CRLF _ + & " 1: String contains non-whitespace characters." & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $RET = StringIsSpace($CMDLINE[2]) + If $RET = 1 Then + ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 0" & @CRLF) + Exit 0 + Else + ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 1" & @CRLF) + Exit 1 + EndIf + EndIf +EndFunc + + +Func _StrIsHEX() + Local $Tips = @CRLF & "CMD:" & @TAB & "/HEX String" & @CRLF _ + & "Usage:" & @TAB & "Check if a string are hexadecimal digit (0-9, A-F) characters." & @CRLF & @CRLF _ + & "Error Code:" & @CRLF _ + & " 0: String contains only hexadecimal characters." & @CRLF _ + & " 1: String contains non-hexadecimal characters." & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $RET = StringIsXDigit($CMDLINE[2]) + If $RET = 1 Then + ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 0" & @CRLF) + Exit 0 + Else + ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 1" & @CRLF) + Exit 1 + EndIf + EndIf +EndFunc + + +Func _StrLength() + Local $Tips = @CRLF & "CMD:" & @TAB & "/LEN String" & @CRLF _ + & "Usage:" & @TAB & "Return the number of characters in a string." & @CRLF & @CRLF _ + & "Return Value: The length of the string." & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $RET = StringLen($CMDLINE[2]) + ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "Length: " & $RET & @CRLF) + Exit 0 + EndIf +EndFunc + + + +Func _StrLeft() + Local $Tips = @CRLF & "CMD:" & @TAB & "/LFT String Count" & @CRLF _ + & "Usage:" & @TAB & "Return a number of characters from the left side of a string." & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "String:" & @TAB & "The string to evaluate." & @CRLF _ + & "Count:" & @TAB & "The number of characters to get." & @CRLF + If $CMDLINE[0] < 3 Then + ConsoleWrite($Tips) + Exit 0 + Else + If $CMDLINE[2] = "/?" Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $RET = StringLeft($CMDLINE[2], $CMDLINE[3]) + ConsoleWrite($RET&@CRLF) + Exit 0 + EndIf + EndIf +EndFunc + + +Func _StrRight() + Local $Tips = @CRLF & "CMD:" & @TAB & "/RIT String Count" & @CRLF _ + & "Usage:" & @TAB & "Return a number of characters from the right side of a string." & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "String:" & @TAB & "The string to evaluate." & @CRLF _ + & "Count:" & @TAB & "The number of characters to get." & @CRLF + If $CMDLINE[0] < 3 Then + ConsoleWrite($Tips) + Exit 0 + Else + If $CMDLINE[2] = "/?" Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $RET = StringRight($CMDLINE[2], $CMDLINE[3]) + ConsoleWrite($RET&@CRLF) + Exit 0 + EndIf + EndIf +EndFunc + + +Func _StrTrimLeft() + Local $Tips = @CRLF & "CMD:" & @TAB & "/STL String Count" & @CRLF _ + & "Usage:" & @TAB & "Trim a number of characters from the left side of a string." & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "String:" & @TAB & "The string to evaluate." & @CRLF _ + & "Count:" & @TAB & "The number of characters to trim." & @CRLF + If $CMDLINE[0] < 3 Then + ConsoleWrite($Tips) + Exit 0 + Else + If $CMDLINE[2] = "/?" Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $RET = StringTrimLeft($CMDLINE[2], $CMDLINE[3]) + ConsoleWrite($RET&@CRLF) + Exit 0 + EndIf + EndIf +EndFunc + + +Func _StrTrimRight() + Local $Tips = @CRLF & "CMD:" & @TAB & "/STR String Count" & @CRLF _ + & "Usage:" & @TAB & "Trim a number of characters from the right side of a string." & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "String:" & @TAB & "The string to evaluate." & @CRLF _ + & "Count:" & @TAB & "The number of characters to trim." & @CRLF + If $CMDLINE[0] < 3 Then + ConsoleWrite($Tips) + Exit 0 + Else + If $CMDLINE[2] = "/?" Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $RET = StringTrimRight($CMDLINE[2], $CMDLINE[3]) + ConsoleWrite($RET&@CRLF) + Exit 0 + EndIf + EndIf +EndFunc + + +Func _StrMid() + Local $Tips = @CRLF & "CMD:" & @TAB & "/MID String Start [Count]" & @CRLF _ + & "Usage:" & @TAB & "Extract a number of characters from a string." & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "String:" & @TAB & "The string to evaluate." & @CRLF _ + & "Start:" & @TAB & "The character position to start." & @CRLF _ + & "Count:" & @TAB & "(Optional) The number of characters to extract." & @CRLF _ + & @TAB & "(By default the entire remainder of the string.)" & @CRLF + + If $CMDLINE[0] < 3 Then + ConsoleWrite($Tips) + Exit 0 + Else + If $CMDLINE[2] = "/?" Then + ConsoleWrite($Tips) + Exit 0 + EndIf + EndIf + + Local $iCount = -1 + If $CMDLINE[0] >=4 Then $iCount = $CMDLINE[4] + + Local $RET = StringMid($CMDLINE[2], $CMDLINE[3], $iCount) + ConsoleWrite($RET&@CRLF) + Exit 0 +EndFunc + + + +Func _StrReplace() + Local $Tips = @CRLF & "CMD:" & @TAB & "/SRP String SearchStr ReplaceStr [Count=0] [Case=0]" & @CRLF _ + & "Usage:" & @TAB & "Replace substrings in a string." & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "String:" & @TAB & @TAB & "The string to evaluate." & @CRLF _ + & "SearchStr:" & @TAB & "The substring to search for." & @CRLF _ + & "ReplaceStr:" & @TAB & "The replacement string." & @CRLF _ + & "Count:" & @TAB & @TAB & "The number of times to replace the searchstring." & @CRLF _ + & @TAB & @TAB & "All searchstrings will be replaced.(Default=0)" & @CRLF _ + & @TAB & @TAB & "Use a negative number to replace from the right side." & @CRLF _ + & "Case:" & @TAB & @TAB & "Flag to indicate if the operations should be case sensitive." & @CRLF _ + & @TAB & @TAB & "0: Not case sensitive.(Default)" & @CRLF _ + & @TAB & @TAB & "1: Case sensitive." & @CRLF & @CRLF _ + & "Returen Value: The new string." & @CRLF + + If $CMDLINE[0] < 4 Then + ConsoleWrite($Tips) + Exit 0 + EndIf + + Local $iCount = 0 + Local $iCase = 0 + If $CMDLINE[0] >= 5 Then $iCount = $CMDLINE[5] + If $CMDLINE[0] >= 6 Then $iCase = $CMDLINE[6] + + Local $RET = StringReplace($CMDLINE[2], $CMDLINE[3], $CMDLINE[4], $iCount, $iCase) + ConsoleWrite("--> Occurrence: " & @Extended & @CRLF & $RET & @CRLF) + Exit 0 +EndFunc + + +Func _StrReverse() + Local $Tips = @CRLF & "CMD:" & @TAB & "/REV String" & @CRLF _ + & "Usage:" & @TAB & "Reverse the contents of the specified string." & @CRLF & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $RET = StringReverse($CMDLINE[2]) + ;ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "Result: " & $RET & @CRLF) + ConsoleWrite($RET&@CRLF) + Exit 0 + EndIf +EndFunc + + +Func _StrStripWS() + Local $Tips = @CRLF & "CMD:" & @TAB & "/SWS String Flag" & @CRLF _ + & "Usage:" & @TAB & "Strip the white space in a string." & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "String:" & @TAB & "The string to strip." & @CRLF _ + & "Flag:" & @TAB & "Flag to indicate the type of stripping." & @CRLF _ + & @TAB & "Add the flags together for multiple operations." & @CRLF _ + & @TAB & "1: Strip leading white space." & @CRLF _ + & @TAB & "2: Strip trailing white space." & @CRLF _ + & @TAB & "4: Strip double (or more) spaces between words." & @CRLF _ + & @TAB & "8: Strip all spaces (over-rides all other flags)." & @CRLF + If $CMDLINE[0] < 3 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $sString = $CMDLINE[2] + Local $iFlag = $CMDLINE[3] + EndIf + Local $RET = StringStripWS($sString, $iFlag) + ConsoleWrite($RET&@CRLF) + Exit 0 +EndFunc + + +Func _StringLower() + Local $Tips = @CRLF & "CMD:" & @TAB & "/LWR String" & @CRLF _ + & "Usage:" & @TAB & "Convert a string to lowercase." & @CRLF & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $RET = StringLower($CMDLINE[2]) + ;ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "Result: " & $RET & @CRLF) + ConsoleWrite($RET&@CRLF) + Exit 0 + EndIf +EndFunc + + +Func _StringUpper() + Local $Tips = @CRLF & "CMD:" & @TAB & "/UPR String" & @CRLF _ + & "Usage:" & @TAB & "Convert a string to uppercase." & @CRLF & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $RET = StringUpper($CMDLINE[2]) + ;ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "Result: " & $RET & @CRLF) + ConsoleWrite($RET&@CRLF) + Exit 0 + EndIf +EndFunc + + +Func _Str2Hex() + Local $Tips = @CRLF & "CMD:" & @TAB & "/S2H String" & @CRLF _ + & "Usage:" & @TAB & "Convert a string to a hex string." & @CRLF & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $RET = _StringToHex($CMDLINE[2]) + ;ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "Result: " & $RET & @CRLF) + ConsoleWrite($RET&@CRLF) + Exit 0 + EndIf +EndFunc + + +Func _Hex2Str() + Local $Tips = @CRLF & "CMD:" & @TAB & "/H2S String" & @CRLF _ + & "Usage:" & @TAB & "Convert a hex string to a string." & @CRLF & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $RET = _HexToString($CMDLINE[2]) + ;ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "Result: " & $RET & @CRLF) + ConsoleWrite($RET&@CRLF) + Exit 0 + EndIf +EndFunc + + +;#CS ---------------------------------------- +; Switch $iFlag +; Case '/L' +; $iFlag = $STR_STRIPLEADING (1) +; Case '/R' +; $iFlag = $STR_STRIPLEADING (2) +; Case '/S' +; $iFlag = $STR_STRIPLEADING (4) +; Case '/A' +; $iFlag = $STR_STRIPLEADING (8) +; Case Else +; $iFlag = $STR_STRIPLEADING (8) +; EndSwitch +;#CE ---------------------------------------- +#CS +Func _Usage() + Global $HelpInfo = @CRLF & "-- String Manage Utility." & @CRLF _ + & "Ver 1.0 Build Jun.21 2016." & @CRLF & @CRLF _ + & "Command Line: [/Command] ... " & @CRLF & @CRLF _ + & "Commands:" & @CRLF _ + & "/CMP" & @TAB & "Compares two strings with options." & @CRLF _ + & "/SIS" & @TAB & "Checks if a string contains a given substring." & @CRLF _ + ConsoleWrite($HelpInfo) + Exit 0 +EndFunc +#CE + + diff --git a/Utils.au3 b/Utils.au3 new file mode 100644 index 0000000..f218448 --- /dev/null +++ b/Utils.au3 @@ -0,0 +1,886 @@ +#NoTrayIcon +#Include +#Include +#Include + +;Modification: +; 2016/06/19 Change /SRE Function Description. +; 2016/09/10 Add _Execute Function. +; 2016/10/27 ADD ATT/ACT operation to _CMD Function. + + +Func _WriteLog() + If $CMDLINE[0] < 3 Then + Local $Tips = @CRLF & "Parameters Format Error !" & @CRLF & @CRLF _ + & "CMD:" & @TAB & "/LOG LogPath LogMsg [Flag = -1]" & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "LogPath:" & @TAB & "Path of the file to write to." & @CRLF _ + & "LogMsg:" & @TAB & @TAB & "Message to be written to the log file." & @CRLF _ + & "Flag(Optional):" & @CRLF _ + & @TAB & "Flag = -1 (Default) LogMsg will be written to the end of file." & @CRLF _ + & @TAB & "Otherwise LogMsg will be written to beginning of file." & @CRLF & @CRLF _ + & "Use /F:FileName to set the ""LogMsg"" as the contents of a file." & @CRLF & @CRLF + ConsoleWrite($Tips) + Exit 0 + ElseIf $CMDLINE[0] = 3 Then + Local $LogPath = $CMDLINE[2] + Local $LogMsg = $CMDLINE[3] + Local $Flag = -1 + If StringLeft($LogMsg,3) = "/F:" Then + Local $SrcName = StringTrimLeft($LogMsg, 3) + Local $SrcFile = FileOpen($SrcName) + $LogMsg = FileRead($SrcFile) + FileClose($SrcFile) + EndIf + Else + Local $LogPath = $CMDLINE[2] + Local $LogMsg = $CMDLINE[3] + Local $Flag = $CMDLINE[4] + If StringLeft($LogMsg,3) = "/F:" Then + Local $SrcName = StringTrimLeft($LogMsg, 3) + Local $SrcFile = FileOpen($SrcName) + $LogMsg = FileRead($SrcFile) + FileClose($SrcFile) + EndIf + EndIf + Local $RET = _FileWriteLog($LogPath, $LogMsg, $Flag) + FileOpen($LogPath, 1) + FileClose($LogPath) + Exit $RET +EndFunc + + + +Func _DeleteLine() + Local $Tips = @CRLF & "CMD:" & @TAB & "/DEL FileName LineNum" & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "FileName:" & @TAB & "File name." & @CRLF _ + & "LineNum:" & @TAB & "Line number." & @CRLF & @CRLF + If $CMDLINE[0] < 3 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $File = $CMDLINE[2] + Local $Line = $CMDLINE[3] + _FileWriteToLine($File, $Line, "", True) + Exit 0 + EndIf + Exit 0 +EndFunc + + + +Func _WriteLine() + If $CMDLINE[0] < 4 Then + Local $Tips = @CRLF & "Parameters Format Error !" & @CRLF & @CRLF _ + & "CMD:" & @TAB & "/INS FilePath LineNum Text [OverWrite = False]" & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "FilePath:" & @TAB & "Path of the file to write to." & @CRLF _ + & "LineNum:" & @TAB & "The line number to write to." & @CRLF _ + & "Text:" & @TAB & @TAB & "The text to write." & @CRLF _ + & "OverWrite(Optional):" & @CRLF _ + & @TAB & "True - Will overwrite the old line." & @CRLF _ + & @TAB & "False - (Default) Will not overwrite." & @CRLF & @CRLF _ + & "Use /F:FileName.txt to set the ""Text"" as the contents of a file." & @CRLF & @CRLF + ConsoleWrite($Tips) + Exit 0 + ElseIf $CMDLINE[0] = 4 Then + Local $FilePath = $CMDLINE[2] + Local $Line = $CMDLINE[3] + Local $Text = $CMDLINE[4] + Local $OverWrite = False + If StringLeft($Text,3) = "/F:" Then + Local $SrcName = StringTrimLeft($Text, 3) + Local $SrcFile = FileOpen($SrcName) + $Text = FileRead($SrcFile) + FileClose($SrcFile) + EndIf + Else + Local $FilePath = $CMDLINE[2] + Local $Line = $CMDLINE[3] + Local $Text = $CMDLINE[4] + $OverWrite = $CMDLINE[5] + If StringLeft($Text,3) = "/F:" Then + Local $SrcName = StringTrimLeft($Text, 3) + Local $SrcFile = FileOpen($SrcName) + $Text = FileRead($SrcFile) + FileClose($SrcFile) + EndIf + EndIf + Local $RET = _FileWriteToLine ( $FilePath, $Line, $Text, $OverWrite ) + Exit $RET +EndFunc + + + +Func _ReplaceString() + If $CMDLINE[0] < 4 Then + Local $Tips = @CRLF & "Parameters Format Error !" & @CRLF & @CRLF _ + & "CMD:" & @TAB & "/REP FileName SrcString DstString [Case = 0] [Occurance = 1]" & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "FileName:" & @TAB & "Full path of the file." & @CRLF _ + & "SrcString:" & @TAB & "The string to evaluate." & @CRLF _ + & "DstString:" & @TAB & "The text to write." & @CRLF _ + & "Case(Optional):" & @CRLF _ + & @TAB & "0 -- (Default) Not case sensitive." & @CRLF _ + & @TAB & "1 -- Case sensitive." & @CRLF _ + & "Occurance(Optional):" & @CRLF _ + & @TAB & "0 -- Only the first occurrence is replaced." & @CRLF _ + & @TAB & "1 -- (Default) All occurrences are replaced." & @CRLF & @CRLF _ + & "Use /F:FileName to set ""SrcString"" and ""DstString"" as the contents of a file." & @CRLF & @CRLF + ConsoleWrite($Tips) + Exit 0 + ElseIf $CMDLINE[0] = 4 Then + Local $Path = $CMDLINE[2] + Local $SrcStr = $CMDLINE[3] + Local $DstStr = $CMDLINE[4] + Local $Case = 0 + Local $Occur = 1 + If StringLeft($SrcStr, 3) = "/F:" Then + Local $SrcName = StringTrimLeft($SrcStr, 3) + Local $SrcFile = FileOpen($SrcName) + $SrcStr = FileRead($SrcFile) + FileClose($SrcFile) + EndIf + If StringLeft($DstStr, 3) = "/F:" Then + Local $SrcName1 = StringTrimLeft($DstStr, 3) + Local $SrcFile1 = FileOpen($SrcName1) + $DstStr = FileRead($SrcFile1) + FileClose($SrcFile1) + EndIf + ElseIf $CMDLINE[0] = 5 Then + Local $Path = $CMDLINE[2] + Local $SrcStr = $CMDLINE[3] + Local $DstStr = $CMDLINE[4] + Local $Case = $CMDLINE[5] + Local $Occur = 1 + If StringLeft($SrcStr, 3) = "/F:" Then + Local $SrcName = StringTrimLeft($SrcStr, 3) + Local $SrcFile = FileOpen($SrcName) + $SrcStr = FileRead($SrcFile) + FileClose($SrcFile) + EndIf + If StringLeft($DstStr, 3) = "/F:" Then + Local $SrcName1 = StringTrimLeft($DstStr, 3) + Local $SrcFile1 = FileOpen($SrcName1) + $DstStr = FileRead($SrcFile1) + FileClose($SrcFile1) + EndIf + Else + Local $Path = $CMDLINE[2] + Local $SrcStr = $CMDLINE[3] + Local $DstStr = $CMDLINE[4] + Local $Case = $CMDLINE[5] + Local $Occur = $CMDLINE[6] + If StringLeft($SrcStr, 3) = "/F:" Then + Local $SrcName = StringTrimLeft($SrcStr, 3) + Local $SrcFile = FileOpen($SrcName) + $SrcStr = FileRead($SrcFile) + FileClose($SrcFile) + EndIf + If StringLeft($DstStr, 3) = "/F:" Then + Local $SrcName1 = StringTrimLeft($DstStr, 3) + Local $SrcFile1 = FileOpen($SrcName1) + $DstStr = FileRead($SrcFile1) + FileClose($SrcFile1) + EndIf + EndIf + Local $RET = _ReplaceStringInFile ( $Path, $SrcStr, $DstStr, $Case, $Occur ) + ConsoleWrite("Return Code: " & $RET & @CRLF) + Exit 0 +EndFunc + + + +Func _LineNum() + Global $Tips_Lin = @CRLF & "CMD:" & @TAB & "/NUM FileName [String] [Case=N]" & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "FileName:" & @TAB & "Path and filename of the file to search for." & @CRLF _ + & "String:" & @TAB & @TAB & "[Optional] The string to search in the file." & @CRLF _ + & @TAB & @TAB & "If not define ""String"", return the count of lines of the file" & @CRLF _ + & "Case:" & @TAB & @TAB & "Flag to indicate if the operations should be case sensitive. Y/N." & @CRLF & @CRLF + + Switch $CMDLINE[0] + Case 1 + ConsoleWrite($Tips_Lin) + Exit 0 + Case 2 + If $CMDLINE[2] = "/?" Then + ConsoleWrite($Tips_Lin) + Exit 0 + Else + Local $File = $CMDLINE[2] + ;Local $String = '' + Local $CaseSense = 0 + EndIf + Case 3 + Local $File = $CMDLINE[2] + Local $String = $CMDLINE[3] + Local $CaseSense = 0 + Case Else + Local $File = $CMDLINE[2] + Local $String = $CMDLINE[3] + Local $CaseSense = $CMDLINE[4] + If $CaseSense = "Y" Then + $CaseSense = 1 + ElseIf $CaseSense = "N" Then + $CaseSense = 0 + Else + $CaseSense = 0 + EndIf + EndSwitch + If Not IsDeclared("String") Then + Local $RET = _FileCountLines ($File) + ConsoleWrite($RET&@CRLF) + Exit $RET + Else + ;Local $Array = "" + ;_FileReadToArray($File, $Array) + ;Local $Index = _ArrayFindAll($Array, $String, 0, 0, 0, 1) + ;Local $Count = StringLen(_ArrayToString($Index, '')) + Local $Ocurrences = 0 + Local $fOpen = FileOpen($File,0) + Local $Lines = _FileCountLines($File) + $Lines = $Lines + 1 + Local $LineArray[$Lines] + Local $StringArray[$Lines] + ConsoleWrite("-->File: " & $File & @CRLF) + ConsoleWrite("-->String: " & $String & @CRLF) + For $Loop1 = 1 To $Lines Step 1 + Local $fString = FileReadLine($fOpen, $Loop1) + If StringInStr($fString, $String, $CaseSense) > 0 Then + $Ocurrences += 1 + $LineArray[$Ocurrences] = $Loop1 + $StringArray[$Ocurrences] = $fString + EndIf + Next + ConsoleWrite("-->Ocurrence: " & $Ocurrences & @CRLF) + For $Loop2 = 1 To $Ocurrences Step 1 + ConsoleWrite($LineArray[$Loop2] & @TAB & $StringArray[$Loop2] & @CRLF) + Next + FileClose($fOpen) + Exit 0 + EndIf +EndFunc + + + +Func _GetLine() + Local $Tips = @CRLF & "CMD:" & @TAB & "/FRL FileName LineNum" & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "FileName:" & @TAB & "Path and filename." & @CRLF _ + & "LineNum:" & @TAB & "Number of line to read." & @CRLF _ + & @TAB & "Use -[Number] to read the file from the end, etc -8" & @CRLF _ + & @TAB & "Use [Number1]-[Number2] to read line Number1 to line Number2, etc 2-5" & @CRLF + Switch $CMDLINE[0] + Case 1 To 2 + ConsoleWrite($Tips) + Exit 0 + Case 3 + Local $File = $CMDLINE[2] + Local $Line = $CMDLINE[3] + Case Else + Local $File = $CMDLINE[2] + Local $Line = $CMDLINE[3] + EndSwitch + Local $Lines = _FileCountLines($File) + If $Line > $Lines Then + ConsoleWrite("Error: Parameter ""Line"" out of range." & @CRLF) + Exit 255 + ElseIf StringLeft($Line, 1) = "-" Then + $Line = Int(StringTrimLeft($Line, 1)) + $Line = $Lines - $Line + 1 + Local $fOpen = FileOpen($File) + Local $RET = FileReadLine($fOpen, $Line) + ConsoleWrite($RET&@CRLF) + Exit 0 + ElseIf StringInStr($Line, "-") <> 0 And StringLeft($Line, 1) <> "-" Then + $Line = StringSplit($Line, "-") + If IsArray($Line) Then + Local $Line_Start = $Line[1] + Local $Line_End = $Line[2] + For $i = $Line_Start To $Line_End Step 1 + Local $fOpen = FileOpen($File) + Local $RET = FileReadLine($fOpen, $i) + ConsoleWrite($RET&@CRLF) + If $i <> $Line_End Then ConsoleWrite(@CRLF) + Next + Exit 0 + EndIf + Else + Local $fOpen = FileOpen($File) + Local $RET = FileReadLine($fOpen, $Line) + ConsoleWrite($RET&@CRLF) + Exit 0 + EndIf + Exit 0 +EndFunc + + +Func _CountLine() + Local $Tips = @CRLF & "CMD:" & @TAB & "/FCL FileName" & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "FileName:" & @TAB & "Path and filename." & @CRLF & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $sFilePath = $CMDLINE[2] + Local $RET = _FileCountLines( $sFilePath ) + ConsoleWrite($RET &@CRLF) + Exit 0 + EndIf +EndFunc + + +Func _GetAttrib() + Local $Tips = @CRLF & "CMD:" & @TAB & "/FGA FileName" & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "FileName:" & @TAB & "Path and filename." & @CRLF & @CRLF _ + & "Return Code:" & @CRLF _ + & "A code string representing a file's attributes." & @CRLF _ + & " R = READONLY" & @CRLF _ + & " A = ARCHIVE" & @CRLF _ + & " S = SYSTEM" & @CRLF _ + & " H = HIDDEN" & @CRLF _ + & " N = NORMAL" & @CRLF _ + & " D = DIRECTORY" & @CRLF _ + & " O = OFFLINE" & @CRLF _ + & " C = COMPRESSED (NTFS Compression, Not ZIP Compression)" & @CRLF _ + & " T = TEMPORARY" & @CRLF _ + & " X = EFS ENCRYPTION" & @CRLF & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $sFilePath = $CMDLINE[2] + Local $RET = FileGetAttrib( $sFilePath ) + ConsoleWrite($RET&@CRLF) + Exit 0 + EndIf +EndFunc + + +Func _SetAttrib() + Local $Tips = @CRLF & "CMD:" & @TAB & "/FSA FileName ""+-RASHNOT"" " & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "FileName:" & @TAB & "The path of the file(s) to set, (* and ? wildcards accepted)" & @CRLF _ + & "+-RASHNOT:" & @TAB & "Attribute(s) to set/clear. e.g. ""+A"", ""+RA-SH"""& @CRLF _ + & " A = ARCHIVE" & @CRLF _ + & " S = SYSTEM" & @CRLF _ + & " H = HIDDEN" & @CRLF _ + & " N = NORMAL" & @CRLF _ + & " O = OFFLINE" & @CRLF _ + & " R = READONLY" & @CRLF _ + & " T = TEMPORARY" & @CRLF & @CRLF + If $CMDLINE[0] < 3 Then + ConsoleWrite( $Tips ) + Exit 0 + Else + Local $FileSet = $CMDLINE[2] + Local $Att = $CMDLINE[3] + Local $RET = FileSetAttrib( $FileSet, $Att ) + If $RET = 1 Then + ConsoleWrite("Success") + Exit 0 + Else + ConsoleWrite("Error") + Exit 0 + EndIf + EndIf +EndFunc + + +Func _GetEncoding() + Local $Tips = @CRLF & "CMD:" & @TAB & "/ENC FileName" & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "FileName:" & @TAB & "Path and filename." & @CRLF & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $sFilePath = $CMDLINE[2] + Local $ENC = FileGetEncoding( $sFilePath ) + Switch $ENC + Case $FO_UTF16_LE + Local $RET = "UTF16 Little Endian" + Case $FO_UTF16_BE + Local $RET = "UTF16 Big Endian" + Case $FO_UTF8 + Local $RET = "UTF8 With BOM" + Case $FO_UTF8_NOBOM + Local $RET = "UTF8 Without BOM" + Case $FO_ANSI + Local $RET = "ANSI" + Case Else + Local $RET = "ERROR" + EndSwitch + ConsoleWrite($RET&@CRLF) + Exit 0 + EndIf +EndFunc + + +Func _GetSize() + Local $Tips = @CRLF & "CMD:" & @TAB & "/SIZ FileName" & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "FileName:" & @TAB & "Path and filename." & @CRLF & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $sFilePath = $CMDLINE[2] + Local $Size = FileGetSize( $sFilePath ) + If $Size <= 1024 Then + ConsoleWrite($Size & " Bytes") + Exit 0 + ElseIf $Size <= 1048576 Then + Local $RET = Int($Size/1024) + ConsoleWrite($RET & " KB") + Exit 0 + Else + Local $RET = Int($Size/1048576) + ConsoleWrite($RET & " MB") + Exit 0 + EndIf + EndIf +EndFunc + + +Func _GetTime() + Local $Tips = @CRLF & "CMD:" & @TAB & "/FGT FileName" & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "FileName:" & @TAB & "Path and filename." & @CRLF & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $sFilePath = $CMDLINE[2] + Local $ModifiedTime = FileGetTime( $sFilePath, $FT_MODIFIED, $FT_STRING ) + Local $CreatedTime = FileGetTime( $sFilePath, $FT_CREATED, $FT_STRING ) + Local $AccessedTime = FileGetTime( $sFilePath, $FT_ACCESSED, $FT_STRING ) + Local $RET = "CreatedTime: " & @TAB & $CreatedTime & @CRLF _ + & "LastModified: " & @TAB & $ModifiedTime & @CRLF _ + & "LastAccessed: " & @TAB & $AccessedTime & @CRLF + ConsoleWrite($RET&@CRLF) + Exit 0 + EndIf +EndFunc + + +Func _FileSetTime() + Local $Tips = @CRLF & "CMD:" & @TAB & "/FST FileName Time Type" & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "FileName:" & @TAB & "Path and filename." & @CRLF _ + & "Time:" & @TAB & @TAB & "The new time to set in the format ""YYYYMMDDHHMMSS""" & @CRLF _ + & @TAB & @TAB & "If the time is blank then the current time is used." & @CRLF _ + & "Type:" & @TAB & @TAB & "MODIFIED, CREATED, ACCESSED." & @CRLF & @CRLF + If $CMDLINE[0] < 4 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $FileSet = $CMDLINE[2] + Local $Time = $CMDLINE[3] + Local $Type = $CMDLINE[4] + Switch $Type + Case "MODIFIED" + $Type = $FT_MODIFIED + Case "CREATED" + $Type = $FT_CREATED + Case "ACCESSED" + $Type = $FT_ACCESSED + Case Else + ConsoleWrite("Parameters Error." & @CRLF) + Exit 0 + EndSwitch + Local $RET = FileSetTime( $FileSet, $Time, $Type ) + If $RET = 1 Then + ConsoleWrite("Successed" &@CRLF) + Exit 0 + Else + ConsoleWrite("Failed" &@CRLF) + Exit 0 + EndIf + EndIf +EndFunc + + +Func _GetVersion() + Local $Tips = @CRLF & "CMD:" & @TAB & "/VER FileName" & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "FileName:" & @TAB & "Path and filename." & @CRLF & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + Local $sFilePath = $CMDLINE[2] + + Local $FILEVERSION = FileGetVersion( $sFilePath, $FV_FILEVERSION ) + Local $FILEDESCRIPTION = FileGetVersion( $sFilePath, $FV_FILEDESCRIPTION ) + Local $COMMENTS = FileGetVersion( $sFilePath, $FV_COMMENTS ) + Local $INTERNALNAME = FileGetVersion( $sFilePath, $FV_INTERNALNAME ) + Local $COMPANYNAME = FileGetVersion( $sFilePath, $FV_COMPANYNAME ) + Local $LEGALCOPYRIGHT = FileGetVersion( $sFilePath, $FV_LEGALCOPYRIGHT ) + Local $LEGALTRADEMARKS = FileGetVersion( $sFilePath, $FV_LEGALTRADEMARKS ) + Local $ORIGINALFILENAME = FileGetVersion( $sFilePath, $FV_ORIGINALFILENAME ) + Local $PRODUCTNAME = FileGetVersion( $sFilePath, $FV_PRODUCTNAME ) + Local $PRODUCTVERSION = FileGetVersion( $sFilePath, $FV_PRODUCTVERSION ) + + Local $RET = "FileName: " & $sFilePath & @CRLF _ + & "----- Version Information -----" & @CRLF _ + & "File_Version:" & @TAB & @TAB & $FILEVERSION & @CRLF _ + & "File_Description:" & @TAB & $FILEDESCRIPTION & @CRLF _ + & "Comments:" & @TAB & @TAB & $COMMENTS & @CRLF _ + & "Internal_Name:" & @TAB & @TAB & $INTERNALNAME & @CRLF _ + & "Company_Name:" & @TAB & @TAB & $COMPANYNAME & @CRLF _ + & "Legal_Copyright:" & @TAB & $LEGALCOPYRIGHT & @CRLF _ + & "Legal_Trademarks:" & @TAB & $LEGALTRADEMARKS & @CRLF _ + & "Original_File_Name:" & @TAB & $ORIGINALFILENAME & @CRLF _ + & "Product_Name:" & @TAB & @TAB & $PRODUCTNAME & @CRLF _ + & "Product_Version:" & @TAB & $PRODUCTVERSION & @CRLF + ConsoleWrite($RET&@CRLF) + Exit 0 + EndIf +EndFunc + + +Func _Read() + Local $Tips = @CRLF & "CMD:" & @TAB & "/RED FileName [Count]" & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "FileName:" & @TAB & "Path and filename." & @CRLF _ + & "Count:" &@TAB&@TAB& "A number of characters to read in the file." & @CRLF & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite( $Tips ) + Exit 0 + ElseIf $CMDLINE[0] = 2 Then + Local $sFilePath = $CMDLINE[2] + Local $RET = FileRead( $sFilePath ) + ConsoleWrite( $RET ) + Exit 0 + Else + Local $sFilePath = $CMDLINE[2] + Local $Count = $CMDLINE[3] + Local $RET = FileRead( $sFilePath, $Count ) + ConsoleWrite( $RET ) + Exit 0 + EndIf +EndFunc + + + + +;Func _FileSRER2Line($File, $pattern = '', $replace = '', $flag = 1, $SRE = 0, $CR = 1, $Write = '') +Func _FileSRER2Line() + Global $Tips_SRE = @CRLF & "CMD:" & @TAB & "/SRE FileName Pattern Replace Flag=1 SRE=1 CR=1 Write" & @CRLF & @CRLF _ + & "Parameters:" & @CRLF _ + & "FileName:" & @TAB & "Path and filename of the file to modify." & @CRLF _ + & "Pattern:" & @TAB & "String to search for. If NULL, delete all blank lines." & @CRLF _ + & "Replace:" & @TAB & "String to write. If NULL, delete the lines contain ""Pattern""." & @CRLF _ + & "Flag:" _ + & @TAB & @TAB & "Flag=1: Line must meet the ""Pattern""." & @CRLF _ + & @TAB & @TAB & "Flag=0: Line contain the ""Pattern""." & @CRLF _ + & "SRE:" _ + & @TAB & @TAB & "SRE=1: Use regular expressions." & @CRLF _ + & @TAB & @TAB & "SRE=0: Not use regular expressions." & @CRLF _ + & "CR:" _ + & @TAB & @TAB & "CR=1: Recognition @CRLF(Default)." & @CRLF _ + & @TAB & @TAB & "CR=0: Recognition @LF." & @CRLF _ + & "Write:" _ + & @TAB & @TAB & "NULL: Write the source file." & @CRLF _ + & @TAB & @TAB & "Not NULL: Write the specified file." & @CRLF & @CRLF + ; & @TAB & @TAB & "0: Echo only, not write." & @CRLF _ + Switch $CMDLINE[0] + Case 1 + ConsoleWrite($Tips_SRE) + Exit 0 + Case 2 + If $CMDLINE[2] = "/?" Then + ConsoleWrite($Tips_SRE) + Exit 0 + Else + Local $File = $CMDLINE[2] + Local $pattern = '' + Local $replace = '' + Local $flag = 1 + Local $SRE = 0 + Local $CR = 1 + Local $Write = '' + EndIf + Case 3 + Local $File = $CMDLINE[2] + Local $pattern = $CMDLINE[3] + Local $replace = '' + Local $flag = 1 + Local $SRE = 0 + Local $CR = 1 + Local $Write = '' + Case 4 + Local $File = $CMDLINE[2] + Local $pattern = $CMDLINE[3] + Local $replace = $CMDLINE[4] + Local $flag = 1 + Local $SRE = 0 + Local $CR = 1 + Local $Write = '' + Case 5 + Local $File = $CMDLINE[2] + Local $pattern = $CMDLINE[3] + Local $replace = $CMDLINE[4] + Local $flag = $CMDLINE[5] + Local $SRE = 0 + Local $CR = 1 + Local $Write = '' + Case 6 + Local $File = $CMDLINE[2] + Local $pattern = $CMDLINE[3] + Local $replace = $CMDLINE[4] + Local $flag = $CMDLINE[5] + Local $SRE = $CMDLINE[6] + Local $CR = 1 + Local $Write = '' + Case 7 + Local $File = $CMDLINE[2] + Local $pattern = $CMDLINE[3] + Local $replace = $CMDLINE[4] + Local $flag = $CMDLINE[5] + Local $SRE = $CMDLINE[6] + Local $CR = $CMDLINE[7] + Local $Write = '' + Case 8 + Local $File = $CMDLINE[2] + Local $pattern = $CMDLINE[3] + Local $replace = $CMDLINE[4] + Local $flag = $CMDLINE[5] + Local $SRE = $CMDLINE[6] + Local $CR = $CMDLINE[7] + Local $Write = $CMDLINE[8] + Case Else + Local $File = $CMDLINE[2] + Local $pattern = $CMDLINE[3] + Local $replace = $CMDLINE[4] + Local $flag = $CMDLINE[5] + Local $SRE = $CMDLINE[6] + Local $CR = $CMDLINE[7] + Local $Write = $CMDLINE[8] + EndSwitch + Local $sFile = String(FileRead($File)), $strqhz = '', $extended = 0, $sRER, $strZY, $CRF = '' + If $CR = 0 Then $CRF = '?' + If $pattern = '' Then + $sRER = StringRegExpReplace(@CRLF & $sFile, '\r' & $CRF & '\n(?=\r' & $CRF & '\n)|\r' & $CRF & '\n$', '') + Else + If $SRE = 0 Then + $strZY = '(\.|\||\*|\?|\+|\(|\)|\{|\}|\[|\]|\^|\$|\\)' + $pattern = StringRegExpReplace($pattern, $strZY, '\\$1') + $replace = StringRegExpReplace($replace, $strZY, '\\$1') + EndIf + If $flag = 0 Then $strqhz = '\V*' + Local $patternWZ = $strqhz & $pattern & $strqhz + $pattern = '(\r' & $CRF & '\n)' & $patternWZ & '(?=\r' & $CRF & '\n)|\r' & $CRF & '\n' & $patternWZ & '$' + If $replace <> '' Then + $sRER = StringRegExpReplace(@CRLF & $sFile, $pattern, '${1}' & $replace) + Else + $sRER = StringRegExpReplace(@CRLF & $sFile, $pattern, '') + EndIf + EndIf + $extended = $extended + @extended + $sRER = StringRegExpReplace($sRER, '^\r' & $CRF & '\n', '') + If $Write = '' And $Write <> '0' Then + $sTmp = FileOpen($File, 2) + FileWrite($sTmp, $sRER) + FileClose($sTmp) + ElseIf $Write <> '' Then + $sTmp = FileOpen($Write, 2) + FileWrite($sTmp, $sRER) + FileClose($sTmp) + EndIf + SetExtended($extended) + ConsoleWrite("Return Code: " & @extended & @CRLF) + Return $sRER + Exit 0 +EndFunc ;==>_FileSRER2Line + + +;============================== Misc Item ============================== + + +Func _Sleep() + Local $Tips = @CRLF & "CMD:" & @TAB & "/SLP Delay" & @CRLF _ + & "Usage:" & @TAB & "Pause execution for a while." & @CRLF _ + & "Parameters:" & @CRLF _ + & "Delay: Amount of time to pause (in milliseconds)." & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + EndIf + Sleep($CMDLINE[2]) + Exit 0 +EndFunc + + +Func _Beep() + Local $Tips = @CRLF & "CMD:" & @TAB & "/BEP [Frequency=500] [Duration=1000]" & @CRLF _ + & "Usage:" & @TAB & "Play back a beep to the user." & @CRLF _ + & "Parameters:" & @CRLF _ + & "Frequency:" & @TAB & "The frequency of the beep in hertz. 37~32767 (0x25~0x7FFF)." & @CRLF _ + & "Duration:" & @TAB & "The length of the beep in milliseconds." & @CRLF + Local $Frequency = 500 + Local $Duration = 1000 + If $CMDLINE[0] >= 2 Then + If $CMDLINE[2] = "/?" Then + ConsoleWrite($Tips) + Exit 0 + Else + $Frequency = $CMDLINE[2] + EndIf + EndIf + If $CMDLINE[0] >= 3 Then $Duration = $CMDLINE[3] + Beep($Frequency, $Duration) + Exit 0 +EndFunc + + +Func _Random() + Local $Tips = @CRLF & "CMD:" & @TAB & "/RND Min Max" & @CRLF _ + & "Usage:" & @TAB & "Generate a pseudo-random integer-type number." & @CRLF _ + & "Parameters:" & @CRLF _ + & "Min The smallest number to be generated. (Default=0.)" & @CRLF _ + & "Max The largest number to be generated. (Default=1.)" & @CRLF + Local $Min = 0 + Local $Max = 1 + Local $Flag = 1 + If $CMDLINE[0] >= 2 Then + If $CMDLINE[2] = "/?" Then + ConsoleWrite($Tips) + Exit 0 + Else + $Min = $CMDLINE[2] + EndIf + EndIf + If $CMDLINE[0] >= 3 Then $Max = $CMDLINE[3] + Local $RET = Random($Min, $Max, $Flag) + ConsoleWrite($RET&@CRLF) + Exit($RET) +EndFunc + + +Func _CMD() + Local $Tips = @CRLF & "CMD:" & @TAB & "/CMD State" & @CRLF _ + & "Usage:" & @TAB & "Change state of current console window." & @CRLF & @CRLF _ + & "State:" & @CRLF _ + & @TAB & "ATT: Activate console window." & @CRLF _ + & @TAB & "ACT: Check if console window is actived." & @CRLF _ + & @TAB & "DIS: Disable console window." & @CRLF _ + & @TAB & "ENA: Enable console window." & @CRLF _ + & @TAB & "MIN: Minimize console window." & @CRLF _ + & @TAB & "MAX: Maximize console window." & @CRLF _ + & @TAB & "RES: Restore console window.(Undo MIN/MAX)" & @CRLF _ + & @TAB & "NOR: Activate and display console window." & @CRLF _ + & @TAB & "HIDE: Hide console window." & @CRLF _ + & @TAB & "SHOW: Show console window." & @CRLF _ + & @TAB & "TOP 1: Set console windows always on top." & @CRLF _ + & @TAB & "TOP 0: Set console windows NOT always on top." & @CRLF + +; & @TAB & "LOCK: Lock Console Window." & @CRLF _ +; & @TAB & "FREE: Unlock Console Window." & @CRLF + + Local $hWnd = DllCall("kernel32", "ptr", "GetConsoleWindow") + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + EndIf + Local $iState + Switch $CMDLINE[2] + Case "/?" + ConsoleWrite($Tips) + Exit 0 + Case "MIN" + $iState = @SW_MINIMIZE + Case "MAX" + $iState = @SW_MAXIMIZE + Case "RES" + $iState = @SW_RESTORE + Case "HIDE" + $iState = @SW_HIDE + Case "SHOW" + $iState = @SW_SHOW + Case "DIS" + $iState = @SW_DISABLE + Case "ENA" + $iState = @SW_ENABLE + Case "LOCK" + $iState = @SW_LOCK + Case "FREE" + $iState = @SW_UNLOCK + Case "NOR" + $iState = @SW_SHOWNORMAL + Case "ATT" + WinActivate($hWnd[0]) + Exit 0 + Case "ACT" + Local $RET = WinActive($hWnd[0]) + ConsoleWrite("Result: " & $RET & @CRLF) + Exit 0 + Case "TOP" + Local $Flag = 0 + If $CMDLINE[0] >= 3 Then $Flag = $CMDLINE[3] + WinActivate($hWnd[0]) + WinSetOnTop($hWnd[0], "", $Flag) + Exit 0 + Case Else + ConsoleWrite("Parameters Error." & @CRLF) + Exit 0 + EndSwitch + WinSetState($hWnd[0], "", $iState) + Exit 0 +EndFunc + + +Func _Execute() + Local $Tips = @CRLF & "CMD:" & @TAB & "/EXT Expression" & @CRLF _ + & "Usage:" & @TAB & "Execute an expression." & @CRLF & @CRLF + If $CMDLINE[0] < 2 Then + ConsoleWrite($Tips) + Exit 0 + Else + If $CMDLINE[2] = "/?" Then + ConsoleWrite($Tips) + Exit 0 + EndIf + EndIf + Local $EXP = $CMDLINE[2] + Local $RET = Execute($EXP) + ConsoleWrite($RET & @CRLF) + Exit 0 +EndFunc + + + +;============================== Misc Item ============================== + + +#CS ------------------------------ +Func _Usage() + Local $Info = @CRLF & "V1.1 By Wayne Tan (2016.06.18)" & @CRLF & @CRLF _ + & "Command:" & @CRLF _ + & "/INS: Insert text to a specific line in a file." & @CRLF _ + & "/DEL: Delete the specified line in a file." & @CRLF _ + & "/REP: Replace a substring in a file." & @CRLF _ + & "/NUM: Return the number of lines (with specified sting) of a specified file." & @CRLF _ + & "/FRL: Return the text of the specified line in a specified text file." & @CRLF _ + & "/FCL: Return the count of lines in the specified file." & @CRLF _ + & "/FGA: Return a code string representing a file's attributes." & @CRLF _ + & "/FSA: Set the attributes of one or more files/directories." & @CRLF _ + & "/FGT: Return the time and date information for a file." & @CRLF _ + & "/FST: Set the timestamp of one of more files." & @CRLF _ + & "/ENC: Determine the text encoding used in a file." & @CRLF _ + & "/RED: Read a number of characters from a file." & @CRLF _ + & "/SIZ: Return the size of a file." & @CRLF _ + & "/VER: Return version information stored in a file." & @CRLF _ + & "/SRE: Delete(or replace) the lines by the specified string.(RegExp)" & @CRLF _ + & "/LOG: Write current date, time and the specified text to a log file." & @CRLF & @CRLF _ + & "Type Command to see the detail information." & @CRLF & @CRLF + ConsoleWrite($Info) + Exit 0 +EndFunc +#CE ------------------------------ +