cmd-util/CmdUtil.au3
2025-08-21 16:55:17 +08:00

247 lines
7.8 KiB
AutoIt

#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 <BigChar.au3>
#Include <StringX.au3>
#Include <StringMD5.au3>
#Include <Utils.au3>
#Include <ChgRes.au3>
#Include <Monitor.au3>
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