;#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;The parameters set the app behaviour as follows: ; -q : quiet mode (this will only show errors and warnings) ; -d : set the "MustDeclareVars" option to True ; -w 1 : give a warning if an include file is included more than once ; -w 2 : give a warning if #comments-end (or #ce) is missing ; -w 3 : give a warning if variables are already declared ; -w 4 : give a warning if local variables are used in the global scope ; -w 5 : give a warning if a local variable is declared but not used ; -w 6 : give a warning when using Dim ; -w 7 : give a warning if ByRef parameters are incorrect #include-once ; #INDEX# ===================================================================================================================== ; Title .........: G0GCD_Library.au3 ; AutoIt Version : 3.3.14.5 ; Language ......: en-GB (English) ; Description ...: Collection of useful procedures. ; Author(s) .....: John Powers 2000-2022 ; Modifiers .....: ; Forum link ....: N/A ; Exe(s) ........: N/A ; ============================================================================================================================= ; #CURRENT# =================================================================================================================== ; ==(File Manipulation) ; _g0gcd_FileInUse($sFilename) ; _g0gcd_Get_FQPN_Name($sFQPN, $Delim = "\") ; _g0gcd_Get_FQPN_Path($sFQPN, $Delim = "\", $IncludeTrailingSlash = True) ; ; ==(Machine Specific Tools) ; _g0gcd_Get_HW_SNo() ; _g0gcd_Get_WindowsVersionInfo() ; ==(PUK Suite) ; _g0gcd_Decrypt($skey, $sencrypt) ; _g0gcd_Encrypt($sKey, $sSubject, $iResultLength = 253) ; ; ==(File Content Manipulation) ; _g0gcd_FetchConfig($Tag, $dlftValue = "", $NewIniSection = "", $NewIniFilename = "") ; _g0gcd_FileDeleteEmptyLines($sFile) ; _g0gcd_IniClearSection($SectionName, $In, $Filename) ;TBA ; _g0gcd_IniCreateNewSection($SectionName, $Into, $Filename, $After="footer", $Section="") ; _g0gcd_IniFile($Tag, $dfltValue = "", $NewIniSection = "", $NewIniFilename = "") ; _g0gcd_IniSectionExists($Filename, $Section) ; _g0gcd_IniTidy($Filename) ; _g0gcd_InsertLineInFile($InsertText, $Into, $FilePath, $After = "Footer", $TargetText = "") ; _g0gcd_InsertLineToFile($FilePath, $TargetText, $InsertText, $After = True) ; _g0gcd_Log($Message, $Write2Log = True, $Separator = ">", $LogFilename = "") ; _g0gcd_ReadConfig($Value, $Key, $Section = "", $File = "") ; DEPRECATED ; _g0gcd_WriteConfig($Value, $Key, $Section = "", $File = "") ; DEPRECATED ; ; ==(String Manipulation) ; _g0gcd_DateTimeTextToDateTime($DateTimeText) ; _g0gcd_DateTimeToIndex($InputString, $Type = 0) ; _g0gcd_Hash($sMessage = "") ; _g0gcd_HexFill($sSubject = "", $iStringLength = l) [*to be deprecated*] ; _g0gcd_HexPad($sSubject = "", $iStringLength = l) ; _g0gcd_HexSum($sSubject) ; _g0gcd_Minify_HTML($Input) ; _g0gcd_Ordinalise($Number) ; _g0gcd_Terminate($sText, $sTerminator = "\") ; _g0gcd_Text2Lines($sText, $iMaxLen=100, $sDelim="|") ; _g0gcd_Trim($sMessage) ; _g0gcd_UnXMLTag($n = "", $flag = True, $Para = " ") ; ; =={Array Manipulation} ; _g0gcd_ArrayDeleteEmptyColumns($aArray) ; _g0gcd_ArrayDeleteEmptyRows($aArray) ; _g0gcd_ArrayTrim($aArray) ; ============================================================================================================================= ; #INTERNAL_USE_ONLY#========================================================================================================== ; __EncodePlink ; ============================================================================================================================= ;============================================================================================================================== #Region Include ;============================================================================================================================== ;Include supplementary function blocks, bundled with AutoIT 3.3.14.5 unless otherwise attributed #include ;#include ;#Include ;#include #include ;#include ;#include ; Jos (https://www.autoitscript.com/forum/profile/19-jos/) #include ;#include ;#include ;#include ;#include ;#include ; Ward (https://www.autoitscript.com/forum/profile/10768-ward/) ;#include ; g0gcd (https://www.autoitscript.com/forum/profile/67254-g0gcd/) ;#include ;#include ;#include ;#include <_pop3.au3> ; Apzo (https://www.autoitscript.com/forum/profile/4782-apzo/) ;#include ; PSaltyDS (https://www.autoitscript.com/forum/topic/70538-_processlistproperties/ ;#include ; JiBe (https://www.autoitscript.com/forum/profile/36446-jibe/) ;#Include ;#include ;#include ;#include ; Realm (https://www.autoitscript.com/forum/profile/35742-realm/) ;#Include ; DanySys (https://www.autoitscript.com/forum/profile/71248-danyfirex/) ;DanySys 30/05/22 ;#Include ;#include ;#include ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #EndRegion Include ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Global Variables ; None ;------------------------------------------------------------------------------------------------------------------------------ ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_ArrayDeleteEmptyColumns ; Description ...: Takes the empty columns out of a supplied 2D array ; Syntax.........: _g0gcd_ArrayDeleteEmptyColumns($aArray) ; Parameters ....: $aArray ; Return values .: Array with content of $aArray but all completely empty columns removed ; Author ........: John Powers (g0gcd) ; Modified.......: 22/06/2022 ; Remarks .......: ; Related .......: _g0gcd_ArrayDeleteEmptyRows() ; Link ..........: (derived from _g0gcd_ArrayDeleteEmptyRows()) ; Example .......: $Array = _g0gcd_ArrayDeleteEmptyColumns($Array) ; ============================================================================================================================= Func _g0gcd_ArrayDeleteEmptyColumns($aArray) ;Notes ;_Log($LogTab & "_g0gcd_ArrayDeleteEmptyColumns: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables Local $not_empty ;Populate local configurable variables ;Initialise local variables Local $Rows = Ubound($aArray,1) Local $Cols = Ubound($aArray,2) Local $aTemp[$Rows][$Cols] Local $Count = 0 ;Procedure ................................................................................................................ For $X = 0 to $Cols - 1 ;Loop through columns $not_empty = 0 For $Y = 0 to $Rows - 1 ;Loop through rows ;Copy all rows to temp array even if they are all empty $aTemp[$Y][$Count] = $aArray[$Y][$X] ;If even one row contains data, make sure it doesn't get deleted If $aArray[$Y][$X] <> "" Then $not_empty = BitOr($not_empty, 1) Next ;If the column has any data, increment, else keep overwriting last column until it contains something If $not_empty Then $Count += 1 Next Redim $aTemp[$Rows][$Count] Return $aTemp ;_Log($LogTab & "_g0gcd_ArrayDeleteEmptyColumns: Completed.", $dBugLog) EndFunc ;==>_g0gcd_ArrayDeleteEmptyColumns ;------------------------------------------------------------------------------------------------------------------------------ ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_ArrayDeleteEmptyRows ; Description ...: Takes the empty rows out of a supplied 2D array ; Syntax.........: _g0gcd_ArrayDeleteEmptyRows($aArray) ; Parameters ....: $aArray ; Return values .: Array with content of $aArray but all completely empty rows removed ; Author ........: https://www.autoitscript.com/forum/profile/7530-weaponx/ (mofified by g0gcd) ; Modified.......: 22/06/2022 ; Remarks .......: ; Related .......: _g0gcd_ArrayDeleteEmptyColumns() ; Link ..........: https://www.autoitscript.com/forum/topic/97637-remove-empty-rows-in-2d-array/ ; Example .......: $aArray = _g0gcd_ArrayDeleteEmptyRows($aArray) ; ============================================================================================================================= Func _g0gcd_ArrayDeleteEmptyRows($aArray) ;Notes ;_Log($LogTab & "_g0gcd_ArrayDeleteEmptyRows: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables Local $not_empty ;Populate local configurable variables ;Initialise local variables Local $Rows = Ubound($aArray,1) Local $Cols = Ubound($aArray,2) Local $aTemp[$Rows][$Cols] Local $Count = 0 ;Procedure ................................................................................................................ For $Y = 0 to $Rows - 1 ;Loop through rows $not_empty = 0 For $X = 0 to $Cols - 1 ;Loop through columns ;Copy all columns to temp array even if they are all empty $aTemp[$Count][$X] = $aArray[$Y][$X] ;If even one column contains data, make sure it doesn't get deleted If $aArray[$Y][$X] <> "" Then $not_empty = BitOr($not_empty, 1) Next ;If the row has any data, increment, else keep overwriting last row until it contains something If $not_empty Then $Count += 1 Next Redim $aTemp[$Count][$Cols] Return $aTemp ;_Log($LogTab & "_g0gcd_ArrayDeleteEmptyRows: Completed.", $dBugLog) EndFunc ;==>_g0gcd_ArrayDeleteEmptyRows ;------------------------------------------------------------------------------------------------------------------------------ ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_ArrayTrim ; Description ...: Takes the empty columns and rows out of a supplied 2D array ; Syntax.........: _g0gcd_ArrayTrim($aArray) ; Parameters ....: $aArray ; Return values .: Array with content of $aArray but all completely empty columns and rows removed ; Author ........: John Powers (g0gcd) ; Modified.......: 22/06/2022 ; Remarks .......: ; Related .......: _g0gcd_ArrayDeleteEmptyColumns(), _g0gcd_ArrayDeleteEmptyRows() ; Link ..........: https://www.autoitscript.com/forum/topic/97637-remove-empty-rows-in-2d-array/ ; Example .......: $aArray = _g0gcd_ArrayTrim($aArray) ; ============================================================================================================================= Func _g0gcd_ArrayTrim($aArray) ;Notes ;_Log($LogTab & "_g0gcd_ArrayTrim: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables ;Populate local configurable variables ;Initialise local variables ;Procedure ................................................................................................................ Return _g0gcd_ArrayDeleteEmptyColumns(_g0gcd_ArrayDeleteEmptyRows($aArray)) ;_Log($LogTab & "_g0gcd_ArrayTrim: Completed.", $dBugLog) EndFunc ;==>_g0gcd_ArrayTrim ;------------------------------------------------------------------------------------------------------------------------------ ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_DateTimeTextToDateTime ; Description ...: Converts a verbose time/date string to sortable format ; Syntax.........: _g0gcd_DateTimeTextToDateTime($DateTimeText) ; Parameters ....: $sText = Verbose time/date string ; Return values .: Success = Coded Time/Date String ; Failure = Empty String ; Author ........: John Powers (g0gcd) ; Modified.......: 26/09/2021 ; Remarks .......: Inital purpose for converting Weather Warning From/To/Updated strings for NN14System.au3 ; Assumes current year, unless 2000 to 2059 appears in the string. ; Related .......: ; Link ..........: ; Example .......: _g0gcd_DateTimeTextToDateTime("10:00 BST on Sun 4 July") returns "04/07/21 10:00" ; ============================================================================================================================= Func _g0gcd_DateTimeTextToDateTime($DateTimeText, $Mode = 0) ;Notes ;_Log($LogTab & "_g0gcd_DateTimeTextToDateTime: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables Local $aArray, $sYear, $sMonth, $sDay, $sHour, $sMinute ;Populate local configurable variables ;Initialise local variables Local $aDateParts = StringSplit($DateTimeText," ",2) ; Flag is $STR_NOCOUNT (2) = disable the return count in the first element Static $sLookup = " ,January ,February ,March ,April ,May ,June ,July ,August ,September,October ,November ,December ," ;Procedure ................................................................................................................ Switch $Mode Case 0 ;Mode = 0 > '06:00 BST on Sat 3 July[ 2021]' >> '03/07/21 22:50' $aArray = StringRegExp($DateTimeText,"20[0-5][0-9]", 3) ; Flag is $STR_REGEXPARRAYGLOBALMATCH (3) = return array of matches If UBound($aArray) = 0 Then $sYear = @YEAR ; Default Else $sYear = $aArray[0] EndIf $sMonth = StringRight("00" & Int(StringInStr($sLookup, _g0gcd_Trim($aDateParts[5]))/10),2) $sDay = StringRight("00" & _g0gcd_Trim($aDateParts[4]),2) $sHour = StringMid($aDateParts[0],1,2) $sMinute = StringMid($aDateParts[0],4,2) Return $sDay & "/" & $sMonth & "/" & StringRight($sYear,2) & " " & $sHour & ":" & $sMinute Case 1 ;Mode = 1 > '21 July[ 2021] at 11:06 BST' >> '21/07/21 11:06' $aArray = StringRegExp($DateTimeText,"20[0-5][0-9]", 3) ; Flag is $STR_REGEXPARRAYGLOBALMATCH (3) = return array of matches If UBound($aArray) = 0 Then $sYear = @YEAR ; Default $sMonth = StringRight("00" & Int(StringInStr($sLookup, _g0gcd_Trim($aDateParts[1]))/10),2) $sDay = StringRight("00" & _g0gcd_Trim($aDateParts[0]),2) $sHour = StringMid($aDateParts[3],1,2) $sMinute = StringMid($aDateParts[3],4,2) Else $sYear = $aArray[0] $sMonth = StringRight("00" & Int(StringInStr($sLookup, _g0gcd_Trim($aDateParts[1]))/10),2) $sDay = StringRight("00" & _g0gcd_Trim($aDateParts[0]),2) $sHour = StringMid($aDateParts[4],1,2) $sMinute = StringMid($aDateParts[4],4,2) EndIf Return $sDay & "/" & $sMonth & "/" & StringRight($sYear,2) & " " & $sHour & ":" & $sMinute EndSwitch ;_Log($LogTab & "_g0gcd_DateTimeTextToDateTime: Completed.", $dBugLog) EndFunc ;==>_g0gcd_DateTimeTextToDateTime ;------------------------------------------------------------------------------------------------------------------------------ ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_DateTimeToIndex ; Description ...: ; Syntax.........: _g0gcd_DateTimeToIndex($InputString, $Type = 0) ; Parameters ....: $sKey = Text of key to be used for decryption ; $sSubject = Text of encrypt ; Return values .: Success = Decrypted string of material contained in the encrypt ; Failure = (No error handling) ; Failure = Returns zero and sets the @error flag: {TBA} ; |1 - The $avAnArray is invalid. {example} ; Author ........: John Powers (g0gcd) ; Modified.......: 24/09/2021 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: _g0gcd_DateTimeToIndex('21/07/20 11:06', 0) returns '2007211106' ; ============================================================================================================================= Func _g0gcd_DateTimeToIndex($InputString, $Type = 0) ;Notes ;_Log($LogTab & "_g0gcd_DateTimeToIndex: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables ;Populate local configurable variables ;Initialise local variables ;Procedure ................................................................................................................ If $Type = 0 Then ; '01/02/03 05:06' >> '0302010506' Return StringMid($InputString, 7, 2) & StringMid($InputString, 4, 2) & StringMid($InputString, 1, 2) _ & StringMid($InputString, 10, 2) & StringMid($InputString, 13, 2) Else ; '2003/02/01 05:06' >> '0302010506' Return StringMid($InputString, 3, 2) & StringMid($InputString, 6, 2) & StringMid($InputString, 9, 2) _ & StringMid($InputString, 12, 2) & StringMid($InputString, 15, 2) EndIf ;_Log($LogTab & "_g0gcd_DateTimeToIndex: Completed.", $dBugLog) EndFunc ;==>_g0gcd_DateTimeToIndex ;------------------------------------------------------------------------------------------------------------------------------ ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_Decrypt ; Description ...: Part of the Program Unlock Key (PUK) encryption suite, decrypts encrypt string using key ; Syntax.........: _g0gcd_Decrypt($sKey, $sEncrypt) ; Parameters ....: $sKey = Text of key to be used for decryption ; $sSubject = Text of encrypt ; Return values .: Success = Decrypted string of material contained in the encrypt ; Failure = (No error handling) ; Failure = Returns zero and sets the @error flag: {TBA} ; |1 - The $avAnArray is invalid. {example} ; Author ........: John Powers (g0gcd) ; Modified.......: 03/07/2021 ; Remarks .......: ; Related .......: _g0gcd_Encrypt ; Link ..........: ; Example .......: None ; ============================================================================================================================= Func _g0gcd_Decrypt($sKey, $sEncrypt) ;Notes ;_Log($LogTab & "_g0gcd_Decrypt: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables Local $q1 Local $n1 ;Populate local configurable variables ;Initialise local variables Local $k1 = $sKey Local $t1 = $sEncrypt Local $r2 = "" ;Procedure ................................................................................................................ ;Replicate the key until it matches the encrypt length While StringLen($t1) > StringLen($k1) $k1 = $k1 & $sKey WEnd ;Extract the length of relevant data within the encrypt $n1 = Dec(StringRight($t1, 2)) ;Subtract the key value from each character to restore original text For $p1 = 1 To $n1 $q1 = Dec(StringMid($t1, ($p1 * 2) - 1, 2)) - Asc(StringMid($k1, $p1, 1)) If $q1 < 0 Then $q1 = $q1 + 256 $r2 = $r2 & Chr($q1) Next ;Return resulting decrypt Return ($r2) ;_Log($LogTab & "_g0gcd_Decrypt: Completed.", $dBugLog) EndFunc ;==>_g0gcd_Decrypt ;------------------------------------------------------------------------------------------------------------------------------ ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_Encrypt ; Description ...: Part of the Program Unlock Key (PUK) encryption suite, encrypts subject string using key ; Syntax.........: _g0gcd_Encrypt($sKey, $sSubject, $iResultLength) ; Parameters ....: $sKey = Text of key to be used for decryption ; $sSubject = Text of encrypt ; $iResultLength = Minimum length of resulting encrypt ; Return values .: Success = Encrypted string of subject material ; Failure = (No error handling) ; Author ........: John Powers (g0gcd) ; Modified.......: 03/07/2021 ; Remarks .......: ; Related .......: _g0gcd_Decrypt, uses _g0gcd_HexPad ; Link ..........: ; Example .......: None ; ============================================================================================================================= Func _g0gcd_Encrypt($sKey, $sSubject, $iResultLength = 253) ;Notes ;_Log($LogTab & "_g0gcd_Encrypt: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables Local $r1 = "" Local $q1 ;Populate local configurable variables ;Initialise local variables Local $k1 = $sKey Local $t1 = $sSubject ;Procedure ................................................................................................................ ;Replicate the key until it matches the encrypt length While StringLen($t1) > StringLen($k1) $k1 = $k1 & $sKey WEnd ;Add the key value from each character and convert to hex to determine encrypt For $p1 = 1 To StringLen($t1) $q1 = Asc(StringMid($k1, $p1, 1)) + Asc(StringMid($t1, $p1, 1)) If $q1 > 255 Then $q1 = $q1 - 256 $r1 = $r1 & StringRight("00" & Hex($q1), 2) Next ;Pad out encrypt to minimum length $r1 = _g0gcd_HexPad($r1, $iResultLength) ;Attach subject length to tail of encrypt $r1 = $r1 & StringRight("00" & Hex(StringLen($t1)), 2) ;Return resulting encrypt Return ($r1) ;_Log($LogTab & "_g0gcd_Encrypt: Completed.", $dBugLog) EndFunc ;==>_g0gcd_Encrypt ;#ce ;------------------------------------------------------------------------------------------------------------------------------ ;#cs DEPRECATED ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_FetchConfig() ; Description ...: Returns the value of a tag in an inifile, writing the default value if it's not present. ; Syntax.........: _g0gcd_FetchConfig($Tag, $dlftValue = "", $NewIniSection = "", $NewIniFilename = "") ; Parameters ....: $Tag, the tag specifiying the value to be returned/written ; $dlftValue, the value to be written if the tag, section or file are missing ; $NewIniSection, the section of the inifile to use (if not sepcified, uses last call ; $NNIniFilename the path\name of the inifile to use (if not sepcified, uses last call ; Return values .: String containing found config value, or $dlftValue if no tag, section or file. ; Author ........: John Powers (g0gcd) ; Modified.......: 03/09/22 ; Remarks .......: Used to extract configuration within function scope, to save unneccesary Global variable usage ; Related .......: ; Link ..........: ; Example .......: $Value = _g0gcd_FetchConfig("Tag", "DefaultValue", "Section", "C:\IniFilename.ini") returns "FoundValue" ; ============================================================================================================================= Func _g0gcd_FetchConfig($Tag, $dfltValue = "NotFound", $NewIniSection = "", $NewIniFilename = "") ;Notes ; IniFilename is sticky.. so first call will set that up for the program run ; IniSection is sticky, so only need to specify it when changing functions... ; If $dlftValue is not supplied, then "NotFound" is created/returned ; If $Tag ends in '$' then the inifile entry is re/written and previous value ignored ; If $Tag is '=' then return current setting of $IniFilename ;_Log($LogTab & "_FetchConfig: Started.", $dBugLog) ;Global variables used ;$dBugLog ;Declare local variables Local Static $IniFilename Local Static $IniSection Local $Value ;Populate local configurable variables ;Initialise local variables ;Procedure ................................................................................................................ If $NewIniFilename <> "" Then $IniFilename = $NewIniFilename If $NewIniSection <> "" Then $IniSection = $NewIniSection If NOT FileExists($IniFilename) Then DirCreate(_g0gcd_Get_FQPN_Path($IniFilename)) If $Tag = "=" Then ;Configuration of $IniFilename only expected $Value = $IniFilename Else If StringRight($Tag,1) = "$" Then $Value = $dfltValue ; _Log($LogTab & "_FetchConfig: " & "Write [" & $IniSection & "] " & $Tag & "=" & $Value, $dBugLog) Else $Value = IniRead($IniFilename, $IniSection, $Tag, $dfltValue) ; If $Value = $dfltValue Then ;; _Log($LogTab & "_FetchConfig: " & "Unchanged/Default [" & $IniSection & "] " & $Tag & "=" & $Value, $dBugLog) ; Else ;; _Log($LogTab & "_FetchConfig: " & "Updated/Read [" & $IniSection & "] " & $Tag & "=" & $Value, $dBugLog) ; EndIf EndIf IniWrite($IniFilename, $IniSection, $Tag, $Value) EndIf Return $Value ;_Log($LogTab & "_FetchConfig: Completed.", $dBugLog) EndFunc ;==>_g0gcd_FetchConfig ;#ce ;------------------------------------------------------------------------------------------------------------------------------ ;#cs ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_FileDeleteEmptyLines ; Description ...: Extract filename from fully qualified path name (FQPN) ; Syntax.........: _g0gcd_FileDeleteEmptyLines($sFile) ; Parameters ....: $sFile = Fully Qualified Path Name to file ; Return values .: ; Author ........: John Powers (g0gcd) ; Modified.......: 10/10/2021 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; ============================================================================================================================= Func _g0gcd_FileDeleteEmptyLines($sFile) ;Notes ;_Log($LogTab & "_g0gcd_FileDeleteEmptyLines: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables Local $hFOpen ;Populate local configurable variables ;Initialise local variables Local $sFileContent = StringRegExpReplace(FileRead($sFile), "(\r\n){1,}", "\1") ;Procedure ................................................................................................................ $hFOpen = FileOpen($sFile, 2) FileWrite($hFOpen, StringStripWS($sFileContent, 3)) FileClose($hFOpen) ;_Log($LogTab & "_g0gcd_FileDeleteEmptyLines: Completed.", $dBugLog) EndFunc ;==>_g0gcd_FileDeleteEmptyLines ;------------------------------------------------------------------------------------------------------------------------------ ;#cs ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_FileInUse() ; Description ...: Checks if file is in use ; Syntax.........: _g0gcd_FileInUse($sFilename) ; Parameters ....: $sFilename = Fully Qualified PathFilename to check ; Return values .: 1 - file in use (@error contains system error code) ; 0 - file not in use ; Author ........: Siao https://www.autoitscript.com/forum/profile/23675-siao/ ; Formatted by John Powers (g0gcd) ; Modified.......: 04/09/2022 ; Remarks .......: ; Related .......: ; Link ..........: https://www.autoitscript.com/forum/topic/53994-need-help-with-copy-verification/?tab=comments 02/09/22 ; Example .......: $file = "FileInUseTestfile.txt" ; $h = FileOpen($file, 1) ; $x = _FileInUse($file) ; MsgBox(0, "_FileInUse() example", "File "& $file & @CRLF & "Return= " & $x & " (Error = " & @error & ")") ; FileClose($h) ; $x = _FileInUse($file) ; MsgBox(0, "_FileInUse() example", "File "& $file & @CRLF & "Return= " & $x & " (Error = " & @error & ")") ; ============================================================================================================================= Func _g0gcd_FileInUse($sFilename) ;Notes ;_Log($LogTab & "_g0gcd_FileInUse: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables Local $aRet, $hFile ;Populate local configurable variables ;Initialise local variables ;Procedure ................................................................................................................ $aRet = DllCall("Kernel32.dll", "hwnd", "CreateFile", _ "str", $sFilename, _ ;lpFileName "dword", 0x80000000, _ ;dwDesiredAccess = GENERIC_READ "dword", 0, _ ;dwShareMode = DO NOT SHARE "dword", 0, _ ;lpSecurityAttributes = NULL "dword", 3, _ ;dwCreationDisposition = OPEN_EXISTING "dword", 128, _ ;dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL "hwnd", 0) ;hTemplateFile = NULL $hFile = $aRet[0] If $hFile = -1 Then ;INVALID_HANDLE_VALUE = -1 $aRet = DllCall("Kernel32.dll", "int", "GetLastError") SetError($aRet[0]) Return 1 Else ;close file handle DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Return 0 EndIf ;_Log($LogTab & "_g0gcd_FileInUse: Completed.", $dBugLog) EndFunc ;==>_g0gcd_FileInUse ;#ce ;------------------------------------------------------------------------------------------------------------------------------ ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_Get_FQPN_Name ; Description ...: Extract filename from fully qualified path name (FQPN) ; Syntax.........: _g0gcd_Get_FQPN_Name($sFQPN, $Delim = "\") ; Parameters ....: $sFQPN = Fully Qualified Path Name to file ; $Delim = Delimiter character used to differentiate folder hierarchy (e.g. \ for windows, / for URLs) ; Return values .: Success = String containing filename.ext portion of FQPN ; Failure = String containing FQPN as supplied ; Author ........: John Powers (g0gcd) ; Modified.......: 03/07/2021 ; Remarks .......: Uses _g0gcd_Get_FQPN_Path(). Supersedes _FindFilename(). Option needed to select whether file.ext is captured. ; Related .......: ; Link ..........: ; Example .......: _g0gcd_Get_FQPN_Name("C:\test\document.txt") returns "document.txt" ; ============================================================================================================================= Func _g0gcd_Get_FQPN_Name($sFQPN, $Delim = "\") ;Notes ;_Log($LogTab & "_g0gcd_Get_FQPN_Name: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables Local $lngPointer ;Populate local configurable variables ;Initialise local variables ;Procedure ................................................................................................................ ;Use function to find the end of the path, including delimiter, and set pointer. $lngPointer = StringLen(_g0gcd_Get_FQPN_Path($sFQPN, $Delim)) ;If successful, If $lngPointer > 0 Then ; lop filename off and return value Return StringMid($sFQPN, $lngPointer + 1) Else ; Otherwise, just return FQPN as supplied Return $sFQPN EndIf ;_Log($LogTab & "_g0gcd_Get_FQPN_Name: Completed.", $dBugLog) EndFunc ;==>_g0gcd_Get_FQPN_Name ;------------------------------------------------------------------------------------------------------------------------------ ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_Get_FQPN_Path ; Description ...: Extract path only from fully qualified path name (FQPN) ; Syntax.........: _g0gcd_Get_FQPN_Path($sFQPN, $Delim = "\", $IncludeTrailingSlash = True) ; Parameters ....: $sFQPN = Fully Qualified Path Name to file ; $Delim = Delimiter character used to differentiate folder hierarchy (e.g. \ for windows, / for URLs) ; $IncludeTrailingSlash = If true, return path string with trailine delimiter ; Return values .: Success = String containing filename.ext portion of FQPN ; Failure = Empty string ; Author ........: John Powers (g0gcd) ; Modified.......: 03/07/2021 ; Remarks .......: Supersedes _FindPath(). ; Related .......: ; Link ..........: ; Example .......: _g0gcd_Get_FQPN_Path("C:\test\document.txt") returns "C:\test\" ; _g0gcd_Get_FQPN_Path("C:\test\document.txt", "\", False) returns "C:\test" ; ============================================================================================================================= Func _g0gcd_Get_FQPN_Path($sFQPN, $Delim = "\", $IncludeTrailingSlash = True) ;Notes ;_Log($LogTab & "_g0gcd_Get_FQPN_Path: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables Local $lngPointer, $sTemp ;Populate local configurable variables ;Initialise local variables ;Procedure ................................................................................................................ ;If there's no delimiter in the FQPN .. If StringInStr($sFQPN, $Delim, 0) = 0 Then ; Return an empty string Return "" Else ; Find the last instance of the delimiter (use StringInStr searching from right?) and set pointer $lngPointer = 1 While $lngPointer > 0 $sTemp = StringLeft($sFQPN, $lngPointer) $lngPointer = StringInStr($sFQPN, $Delim, 0, 1, $lngPointer + 1) WEnd If $IncludeTrailingSlash = True Then ; Return lopped off path including trailing delimiter Return $sTemp Else ; Return lopped off path less trailing delimiter Return StringLeft($sTemp, StringLen($sTemp) - 1) EndIf EndIf ;_Log($LogTab & "_g0gcd_Get_FQPN_Path: Completed.", $dBugLog) EndFunc ;==>_g0gcd_Get_FQPN_Path ;------------------------------------------------------------------------------------------------------------------------------ ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_Get_HW_SNo ; Description ...: Finds and returns the serial number of the hardware. ; Syntax.........: _g0gcd_Get_HW_SNo() ; Parameters ....: None ; Return values .: Success = String containing the serial number reported by the machine BIOS ; Failure = (No error handling) ; Failure = Returns zero and sets the @error flag: {TBA} ; |1 - The $avAnArray is invalid. {example} ; Author ........: INET ; Modified.......: 03/07/2021 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: None ; ============================================================================================================================= Func _g0gcd_Get_HW_SNo() ;Notes ;_Log($LogTab & "_g0gcd_Get_HW_SNo: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables Local $element, $sSerialNo ;Populate local configurable variables ;Initialise local variables ;Procedure ................................................................................................................ ;Query BIOS Local $WMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2") Local $aBIOS = $WMI.ExecQuery("Select * from Win32_BIOS") ;Extract SerialNo element For $element In $aBIOS $sSerialNo = $element.SerialNumber Next ;Return extracted information Return $sSerialNo ;_Log($LogTab & "_g0gcd_Get_HW_SNo: Completed.", $dBugLog) EndFunc ;==>_g0gcd_Get_HW_SNo ;------------------------------------------------------------------------------------------------------------------------------ ;#cs ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_Get_WindowsVersionInfo ; Description ...: ; Syntax.........: _g0gcd_Get_WindowsVersionInfo ; Parameters ....: ; Return values .: A zero based array containing: ; [0] Product Name, e.g. "Windows 10 Home" ; [1] Display Version, e.g. "22H2" ; [2] Current Version, e.g. "6.3" ; [3] Current Build Number, e.g. "19045" ; Requires ......: ; Author ........: John Powers (g0gcd) ; Modified.......: 09/12/2022 ; Remarks .......: ONLY TESTED ON WINDOWS 10 ; Related .......: ; Link ..........: ; Example .......: _g0gcd_Get_WindowsVersionInfo ; ============================================================================================================================= Func _g0gcd_Get_WindowsVersionInfo() ;Notes ;Uses Registry Key Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\... ;CurrentBuild, CurrentBuildNumber = 19045 ;CurrentVersion = 6.3 ;ProductName = Windows 10 Home ;DisplayVersion = 22H2 ;_Log($LogTab & "_g0gcd_Get_WindowsVersionInfo: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables Local $Results[4] ;Populate local configurable variables ;Initialise local variables ;Procedure ................................................................................................................ $Results[0] = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName") $Results[1] = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DisplayVersion") $Results[2] = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentVersion") $Results[3] = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuild") ;_Log($LogTab & "_g0gcd_Get_WindowsVersionInfo: Completed.", $dBugLog) Return $Results EndFunc ;==>_g0gcd_Get_WindowsVersionInfo ;#ce ;------------------------------------------------------------------------------------------------------------------------------ ;#cs ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_Hash ; Description ...: Returns a MD5 128bit hash signature for the given input string ; Syntax.........: _g0gcd_Hash($sMessage = "") ; Parameters ....: $sMessage = Text string to be hashed ; Return values .: Success = Hashed string ; Failure = (not defined) ; Requires ......: Crypt.au3 ; Author ........: John Powers (g0gcd) ; Modified.......: 30/06/2022 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: None ; ============================================================================================================================= #Include Func _g0gcd_Hash($sMessage = "") ;Notes ;_Log($LogTab & "_g0gcd_Hash: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables ;Populate local configurable variables ;Initialise local variables Local $g_iAlgorithm = 0x00008003 ;MD5 128bit ;Procedure ................................................................................................................ ;Return hashed string Return (_Crypt_HashData($sMessage, $g_iAlgorithm)) ;_Log($LogTab & "_g0gcd_Hash: Completed.", $dBugLog) EndFunc ;==>_g0gcd_Hash ;------------------------------------------------------------------------------------------------------------------------------ ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_HexFill ; Description ...: Adds random hex characters to the end of a supplied string, to the length given ; Syntax.........: _g0gcd_HexFill($sSubject = "", $iStringLength = l) ; Parameters ....: $sSubject = Text string to be extended ; $iStringLength = Number of characters in output ; Return values .: Success = Extended string ; Failure = (No error handling) ; Failure = Returns zero and sets the @error flag: {TBA} ; |1 - The $avAnArray is invalid. {example} ; Author ........: John Powers (g0gcd) ; Modified.......: 03/07/2021 ; Remarks .......: Note that the hex characters are added as digit pairs, so resurlt string may be longer than $iStringLength ; To be superseded by _g0gcd_HexPad, same parameters/results, and deprecated. ; Related .......: ; Link ..........: ; Example .......: None ; ============================================================================================================================= Func _g0gcd_HexFill($sSubject = "", $iStringLength = 1) ;Notes ;_Log($LogTab & "_g0gcd_HexFill: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables ;Populate local configurable variables ;Initialise local variables Local $r3 = $sSubject Local $l = $iStringLength ;Procedure ................................................................................................................ ;Pad/Fill to length given by $l While StringLen($r3) < $l $r3 = $r3 & Hex(Random(0, 255, 1), 2) WEnd ;Return padded string Return ($r3) ;_Log($LogTab & "_g0gcd_HexFill: Completed.", $dBugLog) EndFunc ;==>_g0gcd_HexFill ;------------------------------------------------------------------------------------------------------------------------------ ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_HexPad ; Description ...: Adds random hex characters to the end of a supplied string, to the length given ; Syntax.........: _g0gcd_HexPad($sSubject = "", $iStringLength = l) ; Parameters ....: $sSubject = Text string to be extended ; $iStringLength = Number of characters in output ; Return values .: Success = Extended string ; Failure = (No error handling) ; Failure = Returns zero and sets the @error flag: {TBA} ; |1 - The $avAnArray is invalid. {example} ; Author ........: John Powers (g0gcd) ; Modified.......: 03/07/2021 ; Remarks .......: Note that the hex characters are added as digit pairs, so resurlt string may be longer than $iStringLength ; Supersedes _g0gcd_HexFill, same parameters/results ; Related .......: ; Link ..........: ; Example .......: None ; ============================================================================================================================= Func _g0gcd_HexPad($sSubject = "", $iStringLength = 1) ;Notes ;_Log($LogTab & "_g0gcd_HexPad: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables ;Populate local configurable variables ;Initialise local variables Local $r3 = $sSubject Local $l = $iStringLength ;Procedure ................................................................................................................ ;Pad/Fill to length given by $l While StringLen($r3) < $l $r3 = $r3 & Hex(Random(0, 255, 1), 2) WEnd ;Return padded string Return ($r3) ;_Log($LogTab & "_g0gcd_HexPad: Completed.", $dBugLog) EndFunc ;==>_g0gcd_HexPad ;------------------------------------------------------------------------------------------------------------------------------ ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_HexSum ; Description ...: Provides a simple checksum of the supplied string ; Syntax.........: _g0gcd_HexSum($sSubject = "") ; Parameters ....: $sSubject = Text string to be enumerated ; Return values .: Success = Returns the Hex string format of the checksum (e.g. 0x1234) ; Failure = (No error handling) ; Failure = Returns zero and sets the @error flag: {TBA} ; |1 - The $avAnArray is invalid. {example} ; Author ........: John Powers (g0gcd) ; Modified.......: 03/07/2021 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: None ; ============================================================================================================================= Func _g0gcd_HexSum($sSubject) ;Notes ;_Log($LogTab & "_g0gcd_HexSum: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables Local $aChars Local $i ;Populate local configurable variables ;Initialise local variables Local $iChecksum = 0 ;Procedure ................................................................................................................ ;Split the string into individual characters in an array $aChars = StringSplit($sSubject, "") For $i = 1 To $aChars[0] $iChecksum += Asc($aChars[$i]) Next ;Return formatted sum Return (StringFormat("0x%X", $iChecksum, $iChecksum)) ;& @CRLF) ;WHy two instances of the variable????? ;_Log($LogTab & "_g0gcd_HexSum: Completed.", $dBugLog) EndFunc ;==>_g0gcd_HexSum ;------------------------------------------------------------------------------------------------------------------------------ ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_IniClearSection($SectionName, $In, $Filename) ;; Description ...: Inserts a section into a .ini file, based on a target section. ; Syntax.........: _g0gcd_IniClearSection($SectionName, $In, $Filename) ;; Parameters ....: ($SectionName, $Into, $Filename, $After="footer", $Section="") ;; Parameters ....: ($SectionName, $Into, $Filename, $After="footer", $Section="") ; Return values .: Success tba ; Failure tba ; Author ........: John Powers (g0gcd) ; Modified.......: 15/10/2021 ;; Remarks .......: Format is "Function ({New Section} into {file} {header/before/after/footer} {target})" ;; Target is only required for efore/fter modes ;; Takes no action if section already present ; Link ..........: ; Example .......: _g0gcd_IniClearSection($SectionName, $In, $Filename) ;; _g0gcd_IniCreateNewSection("New Section", "into", $NNIniFilename, "before", "Section3") ;Before [Section3] ; ============================================================================================================================= Func _g0gcd_IniClearSection($SectionName, $From, $Filename) ;Notes ;IniRenameSection($Filename,$SectionName,$SectionName,1) ;Deletes Section name too! ;_Log($LogTab & "_g0gcd_IniClearSection: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables Local $keys, $index ;Populate local configurable variables ;Initialise local variables ;Local configuration ;Procedure ................................................................................................................ If $From Then $From = $From ; avoids compile time error as $From is padding and unused $keys = IniReadSection($Filename,$SectionName) If @error Then ;Problem with the section/file Else If $keys[0][0] == 0 Then ;Nothing in the section to delete Else For $index = 1 to $keys[0][0] IniDelete($Filename,$SectionName,$keys[$index][0]) Next EndIf EndIf ;_Log($LogTab & "_g0gcd_IniClearSection: Completed.", $dBugLog) EndFunc ;==>_g0gcd_IniClearSection ;------------------------------------------------------------------------------------------------------------------------------ ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_IniCreateNewSection($SectionName, $Into, $Filename, $After="footer", $Section="") ; Parameters ....: ($SectionName, $Into, $Filename, $After="footer", $Section="") ; Return values .: Success tba ; Failure tba ; Author ........: John Powers (g0gcd) ; Modified.......: 15/10/2021 ; Remarks .......: Format is "Function ({New Section} into {file} {header/before/after/footer} {target})" ; Target is only required for efore/fter modes ; Takes no action if section already present ; Related .......: ; Link ..........: ; Example .......: _g0gcd_IniCreateNewSection("New Section", "into", $NNIniFilename, "header") ;At start of file ; _g0gcd_IniCreateNewSection("New Section", "into", $NNIniFilename, "before", "Section3") ;Before [Section3] ; _g0gcd_IniCreateNewSection("New Section", "into", $NNIniFilename, "after", "Section3") ;After [Section3] ; _g0gcd_IniCreateNewSection("New Section", "into", $NNIniFilename, "footer") ;At end of file ; ============================================================================================================================= Func _g0gcd_IniCreateNewSection($SectionName, $Into, $Filename, $After="footer", $Section="") ;Notes ;_Log($LogTab & "_g0gcd_IniCreateNewSection: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables Local $headers, $index ;Populate local configurable variables ;Initialise local variables ;Procedure ................................................................................................................ If $Into Then $Into = $Into ; avoids compile time error as $Into is padding and unused $headers = IniReadSectionNames($Filename) If _ArraySearch($headers, $SectionName, 1, 0, 0) == -1 Then ;$sectionName does not exist Switch StringLeft(StringUpper($After),1) Case "H" ; Start of file _g0gcd_InsertLineInFile("", "into", $Filename, "header") _g0gcd_InsertLineInFile("[" & $SectionName & "]", "into", $Filename, "header") Case "B" ; Within file, before target If StringLeft($Section,1) <> "[" Then $Section = "[" & $Section If StringRight($Section,1) <> "]" Then $Section &= "]" _g0gcd_InsertLineInFile("[" & $SectionName & "]", "into", $Filename, "before", $Section) _g0gcd_InsertLineInFile("", "into", $Filename, "before", $Section) Case "A" ; Within file, after target If StringLeft($Section,1) <> "[" Then $Section = "[" & $Section If StringRight($Section,1) <> "]" Then $Section &= "]" For $index = 1 to $headers[0] If "[" & $headers[$index] & "]" = $Section Then ExitLoop Next if $index == $headers[0] Then _g0gcd_InsertLineInFile("", "into", $Filename, "footer") _g0gcd_InsertLineInFile("[" & $SectionName & "]", "into", $Filename, "footer") Else _g0gcd_InsertLineInFile("[" & $SectionName & "]", "into", $Filename, "before", "[" & $headers[$index + 1] & "]") _g0gcd_InsertLineInFile("", "into", $Filename, "before", "[" & $headers[$index + 1] & "]") EndIf Case "F" ; End of file _g0gcd_InsertLineInFile("", "into", $Filename, "footer") _g0gcd_InsertLineInFile("[" & $SectionName & "]", "into", $Filename, "footer") Case Else EndSwitch Else ;No action - flag section exists ; msgbox(0,"Test","Section already exists") ; (what about using this to clear all keys from an existing section? - in same position if $anchor is blank) Endif ;_Log($LogTab & "_g0gcd_IniCreateNewSection: Completed.", $dBugLog) EndFunc ;==>g0gcd_IniCreateNewSection ;------------------------------------------------------------------------------------------------------------------------------ ;#cs ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_IniFile() ; Description ...: Returns the value of a tag in an inifile, writing the default value if it's not present. ; Syntax.........: _g0gcd_IniFile($Tag, $dfltValue = "", $NewIniSection = "", $NewIniFilename = "") ; Parameters ....: $Tag, the tag specifiying the value to be returned/written. Note Optional control field. ; $dfltValue, the value to be written if the tag, section or file are missing ; $NewIniSection, the section of the inifile to use (if not sepcified, uses last call ; $NNIniFilename the path\name of the inifile to use (if not sepcified, uses last call ; Return values .: String containing found config value, or $dfltValue if no tag, section or file. ; Author ........: John Powers (g0gcd) ; Modified.......: 24/06/23 Added option [O]verwrite, as [W] but returns sent value, for debugging use ; 26/05/23 Added coding for '=' in _g0gcd_IniFile value handling ; 01/05/23 Added coding for CR and LF in _g0gcd_IniFile value handling ; 02/01/23 Added [D] for delete mode ; Remarks .......: $dfltValue which contain @CRLF and/or = are a problem, as .inifile lines cannot be broken and still recognised. ; @CR is replaced by |c|, @LF by |l| and = by |e| on write and swapped back on read. ; Note max resulting line must be less than 4000 characters - long strings need to be handled with multiple tags ; Related .......: ; Link ..........: ; Example .......: $Value = _g0gcd_IniFile("Tag", "DefaultValue", "Section", "C:\IniFilename.ini") returns "FoundValue" ; ============================================================================================================================= Func _g0gcd_IniFile($Tag, $dfltValue = "NotFound", $NewIniSection = "", $NewIniFilename = "") ;Notes ; IniFilename is sticky.. so first call will set that up for the program run ; IniSection is sticky, so only need to specify it when changing functions... ; See table for specific actions when $dfltValue is not supplied, depends on mode ; If $Tag is '=' then procedure returns current setting of [$IniSection]$IniFilename, taking no action on the file. ; Need to add a recognition of empty tag is the same as missing tag... but check in case empty tag is a valid value... ;Control field in tag, as in "[W]Tag$": ;[R]ead - used to read the .ini file, making no changes to the .ini file entry ;[W]rite - used to write/update the .ini file, returning the previous value but updating the file to match the supplied new value ;[C]onfig - (default) used to overwrite default values with those FROM the .ini file, returning the file value, changes value in file only if missing ;If no control is defined on the tag, then a tag name with a trailing '$' is treated as [W]Tag$ (for compatibilty with older code) ;+Read a tag+++++++++++++ ;If tag's there with a value ;Return the tag value ;If tag's there with no value ;Return blank (which is the value!) ;If tag's missing ;Return supplied value ;+Write a tag++++++++++++ ;If tag's there with a value ;Overwrite tag value with supplied value ;Return the previous value ;If tag's there with no value ;Overwrite tag value with supplied value ;Return blank (which is the previous value!) ;If tag's missing ;Create tag value with supplied value ;Return blank (which is the previous value!) ;+Configure from tag+++++ ;If tag's there with a value ;Return the tag value ;If tag's there with no value ?Is this valid? ;Return blank (which is the value!) ;If tag's missing ;Create tag value with supplied value ;Return supplied value ;File Entry | Default | Returns | File Action "Write" | File Action "Read" | File Action "Config" ;Missing | Not given | A "NotFound" | 1 Create Empty Tag | 5 Unchanged | 9 Unchanged ;Missing | Given | B Default | 2 Create with default | 6 Unchanged | 10 Create with default ;Present | Not given | C File Entry | 3 No action | 7 Unchanged | 11 Unchanged ;Present | Given | C File Entry | 4 Change to default | 8 Unchanged | 12 Unchanged ;_Log($LogTab & "_g0gcd_IniFile: Started.", $dBugLog) ;Global variables used ;$dBugLog ;Declare local variables Local Static $IniFilename Local Static $IniSection Local $Value Local $WriteValue Local $Mode ;Populate local configurable variables ;Initialise local variables Local $DftExists = False Local $TagExists = False Local $AltCR = "|c|"; substitutes have to be within ASCII 32-127 to avoid errors in prettify/minify functions Local $AltLF = "|l|" Local $AltEQ = "|e|" ;Procedure ................................................................................................................ ;Separate $Mode from $Tag $Mode = "C"; Default mode If StringLen($Tag) > 3 Then If StringMid($Tag,1,1) = "[" AND StringMid($Tag,3,1) = "]" Then ;Mode control exists If StringUpper(StringMid($Tag,2,1)) = "D" Then $Mode = "D" If StringUpper(StringMid($Tag,2,1)) = "R" Then $Mode = "R" If StringUpper(StringMid($Tag,2,1)) = "O" Then $Mode = "O" If StringUpper(StringMid($Tag,2,1)) = "W" Then $Mode = "W" $Tag = StringMid($Tag,4); Strip mode control from tag Endif Else ;Mode control can't exist, use default If StringRight($Tag,1) = "$" Then $Mode = "W"; This can't be right.. it overrides the explicit mode EndIf ;Set 'sticky' values If String($NewIniFilename) <> "" Then $IniFilename = $NewIniFilename ; String() to prevent 0== "" If String($NewIniSection) <> "" Then $IniSection = $NewIniSection If NOT FileExists($IniFilename) Then DirCreate(_g0gcd_Get_FQPN_Path($IniFilename)) If $Tag = "=" Then ; Configuration of $IniFilename only expected $Value = "[" & $IniSection & "]" & $IniFilename Else ; Proper config if String($dfltValue) <> "" Then $DftExists = True If IniRead($IniFilename, $IniSection, $Tag, "[[NotFound]]") <> "[[NotFound]]" Then $TagExists = True ;READ MODE ================================================================================================================================================================ ;File Entry | Default | Returns | File Action "Read" ;Missing | Not given | A "NotFound" | 5 Unchanged ;Missing | Given | B Default | 6 Unchanged ;Present | Not given | C File Entry | 7 Unchanged ;Present | Given | C File Entry | 8 Unchanged ;+Read a tag+++++++++++++ ;If tag's there with a value ;Return the tag value ;If tag's there with no value ;Return blank (which is the value!) ;If tag's missing ;Return supplied value If $Mode = "R" Then If $TagExists Then $Value = IniRead($IniFilename, $IniSection, $Tag, $dfltValue) $Value = StringReplace($Value, $AltEQ, "=") $Value = StringReplace($Value, $AltLF, @LF) $Value = StringReplace($Value, $AltCR, @CR) Else If $DftExists Then $Value = $dfltValue Else $Value = "NotFound" EndIf Endif EndIf ;DELETE MODE ============================================================================================================================================================== ;? ;File Entry | Default | Returns | File Action "Read" ;? ;Missing | Not given | A "NotFound" | 5 Unchanged ;? ;Missing | Given | B Default | 6 Unchanged ;? ;Present | Not given | C File Entry | 7 Unchanged ;? ;Present | Given | C File Entry | 8 Unchanged ;+Delete a tag+++++++++++++ ;If tag's there with a value ;Return the tag value, then delete the key and value ;If tag's there with no value ;Return blank (which is the value!), then delete the key ;If tag's missing ;Return 'NotFound' If $Mode = "D" Then If $TagExists Then $Value = IniRead($IniFilename, $IniSection, $Tag, $dfltValue) IniDelete($IniFilename,$IniSection,$Tag) $Value = StringReplace($Value, $AltEQ, "=") $Value = StringReplace($Value, $AltLF, @LF) $Value = StringReplace($Value, $AltCR, @CR) Else $Value = "NotFound" Endif EndIf ;WRITE MODE =============================================================================================================================================================== ;File Entry | Default | Returns | File Action "Write" ;Missing | Not given | A "NotFound" | 1 Create Empty Tag ;Missing | Given | B Default | 2 Create with default ;Present | Not given | C File Entry | 3 No action ;Present | Given | C File Entry | 4 Change to default ;+Write a tag++++++++++++ ;If tag's there with a value ;Overwrite tag value with supplied value ;Return the previous value ;If tag's there with no value ;Overwrite tag value with supplied value ;Return blank (which is the previous value!) ;If tag's missing ;Create tag value with supplied value ;Return blank (which is the previous value!) If $Mode = "W" Then If $TagExists Then If $DftExists Then $Value = IniRead($IniFilename, $IniSection, $Tag, $dfltValue) $Value = StringReplace($Value, $AltEQ, "=") $Value = StringReplace($Value, $AltLF, @LF) $Value = StringReplace($Value, $AltCR, @CR) $WriteValue = StringReplace($dfltValue, @CR, $AltCR) $WriteValue = StringReplace($WriteValue, @LF, $AltLF) $WriteValue = StringReplace($WriteValue, "=", $AltEQ) IniWrite($IniFilename, $IniSection, $Tag, $WriteValue) Else $Value = IniRead($IniFilename, $IniSection, $Tag, $dfltValue) $Value = StringReplace($Value, $AltEQ, "=") $Value = StringReplace($Value, $AltLF, @LF) $Value = StringReplace($Value, $AltCR, @CR) EndIf Else If $DftExists Then $Value = "";$dfltValue $WriteValue = StringReplace($dfltValue, @CR, $AltCR) $WriteValue = StringReplace($WriteValue, @LF, $AltLF) $WriteValue = StringReplace($WriteValue, "=", $AltEQ) IniWrite($IniFilename, $IniSection, $Tag, $WriteValue) Else $Value = "NotFound" IniWrite($IniFilename, $IniSection, $Tag, "") EndIf Endif Endif If $Mode = "O" Then If $TagExists Then If $DftExists Then ;$Value = IniRead($IniFilename, $IniSection, $Tag, $dfltValue) ;$Value = StringReplace($Value, $AltEQ, "=") ;$Value = StringReplace($Value, $AltLF, @LF) ;$Value = StringReplace($Value, $AltCR, @CR) $Value = $dfltValue $WriteValue = StringReplace($dfltValue, @CR, $AltCR) $WriteValue = StringReplace($WriteValue, @LF, $AltLF) $WriteValue = StringReplace($WriteValue, "=", $AltEQ) IniWrite($IniFilename, $IniSection, $Tag, $WriteValue) Else $Value = "" ;$Value = IniRead($IniFilename, $IniSection, $Tag, $dfltValue) ;$Value = StringReplace($Value, $AltEQ, "=") ;$Value = StringReplace($Value, $AltLF, @LF) ;$Value = StringReplace($Value, $AltCR, @CR) EndIf Else If $DftExists Then $Value = $dfltValue $WriteValue = StringReplace($dfltValue, @CR, $AltCR) $WriteValue = StringReplace($WriteValue, @LF, $AltLF) $WriteValue = StringReplace($WriteValue, "=", $AltEQ) IniWrite($IniFilename, $IniSection, $Tag, $WriteValue) Else $Value = "";"NotFound" IniWrite($IniFilename, $IniSection, $Tag, "") EndIf Endif Endif ;CONFIG MODE ============================================================================================================================================================== ;File Entry | Default | Returns | File Action "Config" ;Missing | Not given | A "NotFound" | 9 Unchanged ;Missing | Given | B Default | 10 Create with default ;Present | Not given | C File Entry | 11 Unchanged ;Present | Given | C File Entry | 12 Unchanged ;+Configure from tag+++++ ;If tag's there with a value ;Return the tag value ;If tag's there with no value ?Is this valid? ;Return blank (which is the value!) ;If tag's missing ;Create tag value with supplied value ;Return supplied value If $Mode = "C" Then If $TagExists Then $Value = IniRead($IniFilename, $IniSection, $Tag, $dfltValue) $Value = StringReplace($Value, $AltEQ, "=") $Value = StringReplace($Value, $AltCR, @CR) $Value = StringReplace($Value, $AltLF, @LF) Else If $DftExists Then $Value = $dfltValue $WriteValue = StringReplace($dfltValue, @CR, $AltCR) $WriteValue = StringReplace($WriteValue, @LF, $AltLF) $WriteValue = StringReplace($WriteValue, "=", $AltEQ) IniWrite($IniFilename, $IniSection, $Tag, $WriteValue) Else $Value = "NotFound" EndIf Endif Endif EndIf Return $Value ;_Log($LogTab & "_g0gcd_IniFile: Completed.", $dBugLog) EndFunc ;==>_g0gcd_IniFile ;#ce ;------------------------------------------------------------------------------------------------------------------------------ ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_IniSectionExists() ; Description ...: Reports whether a section name exists within an .ini file (even if it contains no keys) ; Syntax.........: _g0gcd_IniSectionExists($IniFilename, $IniSection) ; Parameters ....: $IniFilename = File name of the .Ini file ; $IniSection = Section name to be searched for (case sensitive) ; Return values .: True if found, False if not, or file does not exist ; Author ........: John Powers (g0gcd) ; Modified.......: 29/01/2021 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; ============================================================================================================================= Func _g0gcd_IniSectionExists($IniFilename, $IniSection) ;Notes ;_Log($LogTab & "_g0gcd_IniSectionExists: Started.", $dBugLog) ;Required support ;Global variables used ;$dBugLog, $NNIniFile, $NNDebugStore, $NNDataStore, ;Declare local variables ;Populate local configurable variables ;Initialise local variables Local $SectionNames = IniReadSectionNames($IniFilename) ;Procedure ................................................................................................................ if @error Then ;No file/sections exist! ;Return False Else For $ptr = 1 to $SectionNames[0] If $SectionNames[$ptr] == $IniSection Then Return True EndIf Next Endif Return False ;_Log($LogTab & "_g0gcd_IniSectionExists: Completed.", $dBugLog) EndFunc ;==_g0gcd_IniSectionExists ;#ce ;------------------------------------------------------------------------------------------------------------------------------ ;#cs ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_IniTidy ; Description ...: To insert single blank rows between each section in the specified .ini file ; Syntax.........: _g0gcd_IniTidy($Filename) ; Parameters ....: $Filename ; Return values .: Success tba ; Failure tba ; Author ........: John Powers (g0gcd) ; Modified.......: 05/01/2023 ; Remarks .......: Added Mode functionality (which is s l o w ) ; Related .......: ; Link ..........: ; Example .......: ; ============================================================================================================================= #include Func _g0gcd_IniTidy($Filename, $Mode = 0) ;Notes ;Func _IniTidy($Filename, $Mode = 0) ;or "simple", "section", "key", "all" ;Mode 0 = Remove empty lines, insert blank spaces in front of each section, except the first (default/quickest) ;Mode 1 = As Mode 0 but sort sections into alphabetic order ;Mode 2 = As Mode 0 but sort keys into alphabetic order within each section ;Mode 3 = As Mode 0 but sorts sections into alphabetic order and keys within each section into alphabetic order ;Currently only does Mode 0 ("simple"). WARNING Mode 1 crops big values ;_Log($LogTab & "_g0gcd_IniTidy: Started.", $dBugLog) ;Required support ;#include ;Global variables used ;None ;Declare local variables Local $headers, $KVPairs, $index ;Populate local configurable variables ;Initialise local variables ;Procedure ................................................................................................................ _g0gcd_FileDeleteEmptyLines($Filename) $headers = IniReadSectionNames($Filename) If Not @error Then Switch $Mode Case 0 ; Simple (reformat whitespace only), done after Switch section ;No action Case 1 ;= As Mode 0 but sort sections into alphabetic order _ArraySort($headers,0,2) For $index = 2 to $headers[0] $KVPairs = IniReadSection($Filename,$headers[$index]) ;_ArraySort($KVPairs,0,1) ; doesn't do 'numeric' sort correctly, i.e. result is 1,10,100,2,25,3, etc IniDelete($Filename,$headers[$index]) IniWriteSection($Filename,$headers[$index],$KVPairs) Next Case 2 ;= As Mode 0 but sort keys into alphabetic order within each section ; _ArraySort($headers,0,2) For $index = 2 to $headers[0] $KVPairs = IniReadSection($Filename,$headers[$index]) _ArraySort($KVPairs,0,1) ; doesn't do 'numeric' sort correctly, i.e. result is 1,10,100,2,25,3, etc IniDelete($Filename,$headers[$index]) IniWriteSection($Filename,$headers[$index],$KVPairs) Next Case 3 ;= As Mode 0 but sorts sections into alphabetic order and keys within each section into alphabetic order _ArraySort($headers,0,2) For $index = 2 to $headers[0] $KVPairs = IniReadSection($Filename,$headers[$index]) _ArraySort($KVPairs,0,1) ; doesn't do 'numeric' sort correctly, i.e. result is 1,10,100,2,25,3, etc IniDelete($Filename,$headers[$index]) IniWriteSection($Filename,$headers[$index],$KVPairs) Next EndSwitch ;Case "Any" ; Simple (reformat whitespace only) For $index = 1 to $headers[0] if $index == 1 Then ;Except first section Else _g0gcd_InsertLineInFile("", "into", $Filename, "before", "[" & $headers[$index] & "]") EndIf Next Else ;No action - flag section exists ; msgbox(0,"Test","Section already exists") ; (what about using this to clear all keys from an existing section? - in same position if $anchor is blank) Endif ;_Log($LogTab & "_g0gcd_IniTidy: Completed.", $dBugLog) EndFunc ;==>g0gcd_IniTidy ;#ce ;------------------------------------------------------------------------------------------------------------------------------ ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_InsertLineInFile ; Description ...: Inserts a line into a text file based on a target phrase. ; Syntax.........: _g0gcd_InsertLineInFile($InsertText, $Into, $FilePath, $After = "Footer", $TargetText = "") ; Parameters ....: ; Parameters ....: ; Return values .: Success tba ; Failure tba ; Author ........: John ; Modified.......: 09/10/2021 ; Remarks .......: Special instances of $TargetText for beginning/end of file ; ^B (02H STX - Start of TeXt) - insert at beginning of file ; ^C (03H ETX - End of TeXt) - insert at end of file ; Related .......: ; Link ..........: ; Example .......: _g0gcd_InsertLineInFile("New Line", "into", $NNIniFilename, "header") ;At start of file ; _g0gcd_InsertLineInFile("New Line", "into", $NNIniFilename, "before", "target") ;Before "*target*" ; _g0gcd_InsertLineInFile("New Line", "into", $NNIniFilename, "after", "target") ;After "*target*" ; _g0gcd_InsertLineInFile("New Line", "into", $NNIniFilename, "footer") ;At end of file ; ============================================================================================================================= Func _g0gcd_InsertLineInFile($InsertText, $Into, $FilePath, $After = "Footer", $TargetText = "") ;Notes ;_Log($LogTab & "_g0gcd_InsertLineInFile: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables Local $Lines ;Populate local configurable variables ;Initialise local variables ;Procedure ................................................................................................................ If $Into Then $Into = $Into ; avoids compile time error as $Into is padding and unused ;Load file to array If Not _FileReadToArray($FilePath, $Lines) Then Return -1 ;Manipulate array Switch StringLeft(StringUpper($After),1) Case "H" ; Start of file _ArrayInsert($Lines, 1,$InsertText) Case "B" ; Within file, before target _ArrayInsert($Lines, _ArraySearch($Lines, $TargetText, 1, 0, 0), $InsertText) Case "A" ; Within file, after target _ArrayInsert($Lines, _ArraySearch($Lines, $TargetText, 1, 0, 0) + 1, $InsertText) Case "F" ; End of file _ArrayAdd($Lines, $InsertText) Case Else EndSwitch ;Write array back to file If _FileWriteFromArray($FilePath, $Lines, 1) Then Return 1 Return -2 ;_Log($LogTab & "_g0gcd_InsertLineInFile: Completed.", $dBugLog) EndFunc ;==>_g0gcd_InsertLineToFile ;------------------------------------------------------------------------------------------------------------------------------ ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_InsertLineToFile ; Description ...: Inserts a line into a text file based on a target phrase. ; Syntax.........: _g0gcd_InsertLineToFile($FilePath, $TargetText, $InsertText, $After = True) ; Parameters ....: ; Parameters ....: ; Return values .: Success tba ; Failure tba ; Author ........: John Powers (g0gcd) ; Modified.......: 09/10/2021 ; Remarks .......: DEPRECATED - See _g0gcd_InsertLineInFile. For legacy compatibility only ; Related .......: ; Link ..........: ; Example .......: ; ============================================================================================================================= Func _g0gcd_InsertLineToFile($FilePath, $TargetText, $InsertText, $After = True) ;Notes ;_Log($LogTab & "_g0gcd_InsertLineToFile: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables Local $Lines ;Populate local configurable variables ;Initialise local variables ;Procedure ................................................................................................................ ;Load file to array If Not _FileReadToArray($FilePath, $Lines) Then Return -1 ;Manipulate array Switch $TargetText Case Chr(2) ; Start of file - NOT USED _ArrayInsert($Lines, 1,$InsertText) Case Chr(3) ; End of file - NOT USED _ArrayAdd($Lines, $InsertText) Case Else ; Within the file If $After == True Then _ArrayInsert($Lines, _ArraySearch($Lines, $TargetText, 1, 0, 0) + 1, $InsertText) Else _ArrayInsert($Lines, _ArraySearch($Lines, $TargetText, 1, 0, 0), $InsertText) EndIf EndSwitch ;Write array back to file If _FileWriteFromArray($FilePath, $Lines, 1) Then Return 1 Return -2 ;_Log($LogTab & "_g0gcd_InsertLineToFile: Completed.", $dBugLog) EndFunc ;==>_g0gcd_InsertLineToFile ;------------------------------------------------------------------------------------------------------------------------------ ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_Log ; Description ...: Create a timed entry into a specific text file ; Syntax.........: _g0gcd_Log($Message, $Write2Log = True, $Separator = ">", $LogFilename = "") ; Parameters ....: $Message - Text to be recorded ; $Write2Log - used to control whether there is any logging action (in conjunction with debugging controls) ; $Separator - specifies the character/s to be used between timestamp and message ; $LogFilename - specifies the file to be used for logging, must be fully qualified (see Remarks) ; Return values .: None ; Author ........: John Powers (g0gcd) ; Modified.......: 12/12/21 ; Remarks .......: If $LogFilename is missing, then last one used. If no file specified, then messages are stored in a string ; and added when the file is first specified, before the recent message is processed ; Related .......: ; Link ..........: ; Example .......: _g0gcd_Log("Record This") ; ============================================================================================================================= Func _g0gcd_Log($Message, $Write2Log = True, $Separator = ">", $LogFilename = "") ;Notes ;_Log($LogTab & "_g0gcd_Log: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables Local $LogLine ;Populate local configurable variables ;Initialise local variables Static $HoldMessages = "" Static $LastLogFilename = "" ;Procedure ................................................................................................................ ;Process a new $LogFilename whether a log entry is called for or not If $LogFilename <>"" Then $LastLogFilename = $LogFilename ;Only process message if $Write2Log is True If $Write2Log Then $LogLine = @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & $Separator & " " & $Message If $LastLogFilename <> "" Then If $HoldMessages <> "" Then FileWriteLine($LastLogFilename, $HoldMessages) $HoldMessages = "" FileWriteLine($LastLogFilename, $LogLine) Else If $HoldMessages <> "" Then $HoldMessages &= @CRLF & @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & $Separator & " " & $Message Else $HoldMessages = @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & $Separator & " " & $Message Endif Endif EndIf ;_Log($LogTab & "_g0gcd_Log: Completed.", $dBugLog) EndFunc ;==>_g0gcd_Log ;#ce ;------------------------------------------------------------------------------------------------------------------------------ ;#cs ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_Minify_HTML() ; Description ...: Extract Pollen conditions and 5d forecast from website ; Syntax.........: _g0gcd_Minify_HTML($Input) ; Parameters ....: $Input = to be converted ; Return values .: String based on $Input ; Author ........: John Powers (g0gcd) ; Modified.......: 03/12/22 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; ============================================================================================================================= Func _g0gcd_Minify_HTML($Input = "") ;Notes #cs #include ; to declare the Constants of MsgBox Local $sRegex = "(?m)|\s\B" Local $sString = "" & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ "" Local $sSubst = "" Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst) MsgBox($MB_SYSTEMMODAL, "Result", $sResult) #ce ;_Log($LogTab & "_g0gcd_Minify_HTML: Started.", $dBugLog) ;Required support ;Global variables used ;$dBugLog, $NNIniFile, $NNDebugStore, $NNDataStore, ;Declare local variables ;Populate local configurable variables ;Initialise local variables Local $sRegex = "(?m)|\s\B" ;Local $sString = "Test string" Local $sSubst = "" ;Procedure ................................................................................................................ ;#cs Minify HTML ;#include ; to declare the Constants of MsgBox ;Local $sRegex = "(?m)|\s\B" ;Local $sString = "Test string" ;Local $sSubst = "" ;#ce Local $sResult = StringRegExpReplace($Input, $sRegex, $sSubst) #cs MsgBox($MB_SYSTEMMODAL, "Result", $sResult) #ce Return $sResult ;_Log($LogTab & "_g0gcd_Minify_HTML: Completed.", $dBugLog) EndFunc ;==>_g0gcd_Minify_HTML ;#ce ;------------------------------------------------------------------------------------------------------------------------------ ;#cs ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_Ordinalise ; Description ...: Extract Pollen conditions and 5d forecast from website ; Syntax.........: _g0gcd_Ordinalise($Text) ; Parameters ....: $Input = to be converted ; Return values .: String based on $Input, non-zero positive numbers converted to ordinal. Otherwise returns string of input. ; Author ........: John Powers (g0gcd) ; Modified.......: 24/06/22 ; Remarks .......: Takes numeric or string input of a positive non-zero number. Text or blank treated as zero. ; Related .......: ; Link ..........: ; Example .......: ;msgbox(0,"Out",_g0gcd_Ordinalise("101")) -> ="101st" ; ============================================================================================================================= Func _g0gcd_Ordinalise($Input = "") ;Notes ;_Log($LogTab & "_g0gcd_Ordinalise: Started.", $dBugLog) ;Required support ;Global variables used ;$dBugLog, $NNIniFile, $NNDebugStore, $NNDataStore, ;Declare local variables ;Populate local configurable variables ;Initialise local variables Local $N = Number($Input) Local $S = String($N) ;Procedure ................................................................................................................ If $N > 0 Then $N = $N - (Int($N/100) * 100);$H Switch $N Case 1,21,31,41,51,61,71,81,91 $S &= "st" Case 2,22,32,42,52,62,72,82,92 $S &= "nd" Case 3,23,33,43,53,63,73,83,93 $S &= "rd" Case Else $S &= "th" EndSwitch EndIf Return $S ;_Log($LogTab & "_g0gcd_Ordinalise: Completed.", $dBugLog) EndFunc ;==>_g0gcd_Ordinalise ;#ce ;------------------------------------------------------------------------------------------------------------------------------ ;#cs ;#cs ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_Prettify_HTML($Input, $Output = "", $nTabWidth = -1, $CRAltChar = "") ; Description ...: Extract Pollen conditions and 5d forecast from website ; Syntax.........: _g0gcd_Prettify_HTML($Input) ; Parameters ....: $Input = to be converted ; $Output ; $Mode; redundant ; $nTabWidth = -1 ; $CRAltChar = "" ; Return values .: String based on $Input ; Author ........: John Powers (g0gcd) ; Modified.......: 06/05/23 Extracted and enhanced ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: $Result = _g0gcd_Prettify_HTML() ; ============================================================================================================================= ;Func _g0gcd_Prettify_HTML($sFile, $nTabWidth = -1) Func _g0gcd_Prettify_HTML($Input, $Output = "", $nTabWidth = -1, $CRAltChar = "") ;Notes ; Based on: ; Func _Tidy($sFile, $nTabWidth = -1), "Mat Diesels HTML tidier" ; Source: https://www.autoitscript.com/forum/topic/103417-html-tidier-possessing-beauty/ ; Author: https://www.autoitscript.com/forum/profile/46719-mat/ ; Downloaded: 25/04/2023 ; Modified to make into a module ;Mode: ; 0 = File Input, File Output to same file ; 1 = File Input, String Output with @CR line delimiters ; 2 = File Input, String Output with $CRAltChar delimiters ; 3 = String Input, File Output to same file ; 4 = String Input, String Output with @CR line delimiters ; 5 = String Input, String Output with $CRAltChar delimiters ; $Input describes an existing, non-zero length fully qualified filename > File Input, else String Input ; $Output is non-zero length (filename) > File Output, else String Output ; $nTabWidth = number of spaces to indent each level, -1 means @TAB ; $CRAltChar = character to use instead of @CRLF for line endings, use @CRLF if empty ;Need to add: ;Receive from a string (instead of a file) ;Write to a string (instead of a file) ;Output a single line with alternative to @CR (for use in .ini files) ;_Log($LogTab & "_g0gcd_Prettify_HTML: Started.", $dBugLog) ;Global variables used ;Declare local variables ;Local $__g0gcd_Prettify_HTML ;Populate local configurable variables ;Local $NAM = _g0gcd_IniFile("[R]Name", "AccuWeather Forecast", "ACCU_Control", $NNIniFilename); Used to set default .inifile access ;Local $URL = _g0gcd_IniFile("[C]URL", "") ; Not used ;Local $PRD = _g0gcd_IniFile("[C]PRD", "") ; Not used ;Local $KEY = _g0gcd_IniFile("[C]API", "") ; Not used ;Local $dBugSubFolder = _g0gcd_IniFile("[C]DebugSubFolder", "") ; Not used ;Local $dBugFilename = _g0gcd_IniFile("[C]DebugFilename", "ACCU_Debug.txt") ; Not used ;Local $ImageFilename = _g0gcd_IniFile("[C]ImageFilename", "ACCU_RawWebPage.txt") ; Not used ;Local $WebFilename = _g0gcd_IniFile("[C]WebFilename", "NN14Info-ACCU.js") ; Not used ;#forceref $NAM ;Initialise local variables ;Local $dBugFQFolder = $NNDebugStore & $dBugSubFolder ; Not used ;Local $dBugFQFilename = $DBugFQFolder & $dBugFilename ; Not used ;Local $ImageFQFilename = $dBugFQFolder & $ImageFilename ; Not used ;Local $WebFQFilename = $NNDataStore & $WebFilename ; Not used Local $hFile Local $sTab = "" Local $i = 0 Local $sData = "" Local $sInd = "" Local $aData = 0 Local $iExt = 0 Local $aReg Local $Mode = 0 Local $Credit = "" #forceref $iExt, $Mode, $CRAltChar ;Procedure ................................................................................................................ ; deal with input variables For $i = 1 To $nTabWidth $sTab &= " " Next If $nTabWidth = -1 Then $sTab = @TAB ; If Not FileExists($sFile) Then ;Return 0; * ConsoleWrite("ERROR:1#" & @error & @CRLF) If FileExists($Input) Then ;Return 0; * ConsoleWrite("ERROR:1#" & @error & @CRLF) ;File INPUT mode ; Open File + Get data ;ConsoleWrite("Opening File." & @CRLF) $hFile = FileOpen($Input, 0) If $hFile = -1 Then Return 0; * ConsoleWrite("ERROR:2#0" & @CRLF) ;ConsoleWrite("Reading file." & @CRLF) $sData = FileRead($hFile) If @error > 0 Then Return 0; * ConsoleWrite("ERROR:3#" & @error & @CRLF) FileClose($hFile) ;ConsoleWrite("File Data read. 0 Errors" & @CRLF) Else ;String INPUT mode $sData = $Input Endif $sData = StringReplace($sData, $Credit, "") ; Remove unnecessary whitespace ;ConsoleWrite("Removing Unneccessary whitespace" & @CRLF) $sData = StringReplace($sData, @CRLF, "") $sData = StringReplace($sData, @LF, "") $sData = StringReplace($sData, @CR, "") $sData = StringRegExpReplace($sData, ">\s*?<", "><") $sData = StringRegExpReplace($sData, "(\s)\1*", "\1") ; HTML does this any way. ;ConsoleWrite("Unnecessary whitespace removed" & @CRLF) ; Correct tags ;ConsoleWrite("Correcting tags." & @CRLF) $sData = StringRegExpReplace($sData, "(<[br;img;base;area;basefont;meta;wbr;hr;param;isindex;input;link;embed].*?)([^/])>", "\1\2 />") ;ConsoleWrite(@extended & " closing remarks added." & @CRLF) ; Lower case tags ;ConsoleWrite("Lowercasing tags" & @CRLF) $iExt = 0 $aReg = StringRegExp($sData, "<.*?[\s;>]", 3) ; If @error + 0 * ConsoleWrite(@extended & " tags found.") < 1 Then If @error < 1 Then For $i = 0 To UBound($aReg) - 1 If StringRegExp($aReg[$i], "[^a-z]", 0) Then $iExt += 1 $sData = StringReplace($sData, $aReg[$i], StringLower($aReg[$i]), 1) EndIf Next EndIf ; Re-line ;ConsoleWrite("Re-lining data" & @CRLF) $sData = StringRegExpReplace($sData, "(<(/)?[^a;/a].*?>)", @CR & "\1" & @CR) $sData = StringReplace($sData, @CR & @CR, @CR) ;ConsoleWrite("Data Re-Lined" & @CRLF) ; Indent ;ConsoleWrite("indenting data" & @CRLF) $aData = StringSplit($sData, @CR) $sData = $Credit;"";"" For $i = 1 To $aData[0] $aData[$i] = StringStripWS($aData[$i], 3) If (StringLeft(StringStripWS($aData[$i], 8), 2) = " "<") Then $aData[$i] = $sInd & $aData[$i] ElseIf Not StringRegExp($aData[$i], "<(a|br|img|base|area|basefont|meta|wbr|hr|param|isindex|input|link|embed)[\s;>]", 0) Then $aData[$i] = $sInd & $aData[$i] $sInd &= $sTab ; +1 to tab! Else $aData[$i] = $sInd & $aData[$i] EndIf $sData &= @CRLF & $aData[$i] Next $aData = 0 ;ConsoleWrite("data indented" & @CRLF) ; $sData = StringReplace($sData, $Credit, "") ; $sData = $Credit & $sData If $CRAltChar <> "" Then $sData = StringReplace($sData, @CRLF, $CRAltChar) $sData = StringReplace($sData, @LF, $CRAltChar) $sData = StringReplace($sData, @CR, $CRAltChar) EndIf If $Output = "" Then ;String OUTPUT mode Else ;File OUTPUT mode ; re write file ; ConsoleWrite("Writing to file." & @CRLF) ; $hFile = FileOpen($sFile & ".txt", 2) $hFile = FileOpen($Output, 2) FileWrite($hFile, $sData) ; ConsoleWrite("File Written" & @CRLF & "Closing File" & @CRLF) FileClose($hFile) ; ConsoleWrite("File closed." & @CRLF) $sData = $Output EndIf ;_Log($LogTab & "_g0gcd_Prettify_HTML: Completed.", $dBugLog) Return $sData ; g0gcd modification EndFunc ;==>_g0gcd_Prettify_HTML ;#ce ;------------------------------------------------------------------------------------------------------------------------------ ;#cs ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_ReadConfig($Value, $Key, $Section = "", $File = "") ; Description ...: ; Syntax.........: _g0gcd_ReadConfig($Value, $Key, $Section = "", $File = "") ; Parameters ....: ; Return values .: ; Author ........: John Powers (g0gcd) ; Modified.......: 04/10/22 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: _g0gcd_ReadConfig($Value, $Key, $Section = "", $File = "") ; ============================================================================================================================= Func _g0gcd_ReadConfig($Value, $Key, $Section = "", $File = "") ;Notes ;DEPRECATED, Use _g0gcd_IniFile($Tag, $dfltValue = "", $NewIniSection = "", $NewIniFilename = "") ;Required support ;Global variables used ;Declare local variables Static $LastSection, $LastFile ;Populate local configurable variables ;Initialise local variables ;Procedure ................................................................................................................ If $File == "" Then $File = $LastFile Else $LastFile = $File EndIf If $Section == "" Then $Section = $LastSection Else $LastSection = $Section EndIf ;First run MUST be seeded - no error checking for this condition! $Value = IniRead($File, $Section, $Key, $Value) ;IniDelete($File, $Section, $Key); Force new write to bottom of section IniWrite($File, $Section, $Key, $Value) Return $Value EndFunc ;==>_g0gcd_ReadConfig ;#ce ;------------------------------------------------------------------------------------------------------------------------------ ;#cs ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_Terminate ; Description ...: Breaks a long text line into delimited sections of about $iMaxLen, based on spaces in original string ; Syntax.........: _g0gcd_Terminate($sText, $sTerminator = "\") ; Parameters ....: $sText = String to be formatted ; Parameters ....: $sTerminator = Character to terminate $sText with ; Return values .: Success = Terminated String ; Failure tba ; Author ........: John Powers (g0gcd) ; Modified.......: 29/08/2022 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; ============================================================================================================================= Func _g0gcd_Terminate($sText, $sTerminator = "\") ;Notes ;_Log($LogTab & "_g0gcd_Terminate: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables ;Populate local configurable variables ;Initialise local variables ;Procedure ................................................................................................................ If StringRight($sText,1) <> $sTerminator Then $sText &= $sTerminator Endif Return $sText ;_Log($LogTab & "_g0gcd_Terminate: Completed.", $dBugLog) EndFunc ;==>_g0gcd_Terminate ;#ce ;------------------------------------------------------------------------------------------------------------------------------ ;#cs ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_Text2Lines ; Description ...: Breaks a long text line into delimited sections of about $iMaxLen, based on spaces in original string ; Syntax.........: _g0gcd_Text2Lines($sText, $iMaxLen=100) ; Parameters ....: $sText = String to be formatted ; Parameters ....: $iMaxLen = Maximum number of characters per line (may be longer if no space in first $iMaxLen chars) ; Return values .: Success = String of delimited lines ; Failure tba ; Author ........: John Powers (g0gcd) ; Modified.......: 06/07/2021 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; ============================================================================================================================= Func _g0gcd_Text2Lines($sText, $iMaxLen=100, $sDelim="|") ;Notes ;Process Delim ; if contains escape char \+1\ then insert line number with offset ; e.g. Delim = "|Text\+3\=" will begin each line with Text3=, |Text4=, |Text5= etc.. ; Note that first character of the delimiter is missing from start of output string ;_Log($LogTab & "_g0gcd_Text2Lines: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables ;Populate local configurable variables ;Initialise local variables Local $SOut = "" Local $TextLineCounter = 1 Local $TextPointer = 0 Local $TextLineTemp = "" Local $CR = Chr(13) & Chr(10) Local $Dlm = $sDelim ;Procedure ................................................................................................................ $TextLineTemp = StringReplace($sText, $CR, " ") While StringLen($TextLineTemp) > $iMaxLen $Dlm = StringReplace($sDelim,"\+1\",$TextLineCounter) $TextPointer = StringInStr($TextLineTemp, " ", 0, -1, $iMaxLen) ; points at last space before TextLenOut If $TextPointer = 0 Then $TextPointer = StringInStr($TextLineTemp & " ", " ", 0, 1, $iMaxLen + 1) ; searches for next space after TextLenOut (big word, e.g. URL) $sOut &= $Dlm & StringStripWS(StringLeft($TextLineTemp, $TextPointer), 3) $TextLineTemp = StringStripWS(StringMid($TextLineTemp, $TextPointer + 1), 3) $TextLineCounter += 1 WEnd If StringLen($TextLineTemp) > 0 Then $sOut &= $Dlm & StringStripWS($TextLineTemp, 3) Return $sOut ;_Log($LogTab & "_g0gcd_Text2Lines: Completed.", $dBugLog) EndFunc ;==>_g0gcd_Text2Lines ;#ce ;------------------------------------------------------------------------------------------------------------------------------ ;#cs ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_Trim ; Description ...: Simulates the VBA Trim($input) function ; Syntax.........: _g0gcd_Trim($sMessage) ; Parameters ....: $sMessage = String to be trimmed ; Return values .: Success = Trimmed String ; Failure = Original String ; Author ........: John Powers (g0gcd) ; Modified.......: 03/07/2021 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; ============================================================================================================================= Func _g0gcd_Trim($sMessage) ;Notes ;_Log($LogTab & "_g0gcd_Trim: Started.", $dBugLog) ;Required support ;Global variables used ;$dBugLog, $NNIniFile, $NNDebugStore, $NNDataStore, ;Declare local variables ;Populate local configurable variables ;Initialise local variables ;Procedure ................................................................................................................ Return StringStripWS($sMessage, 3) ; Return Trimmed string ;_Log($LogTab & "_g0gcd_Trim: Completed.", $dBugLog) EndFunc ;==>_g0gcd_Trim ;------------------------------------------------------------------------------------------------------------------------------ ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_UnXMLTag($n = "", $flag = True, $Para = " ") ; Description ...: Simulates the VBA Trim($input) function ; Syntax.........: _g0gcd_UnXMLTag($n = "", $flag = True, $Para = " ") ; Parameters ....: $sMessage = String to be trimmed ; Return values .: Success = Trimmed String ; Failure = Original String ; Author ........: John Powers (g0gcd) ; Modified.......: 03/07/2021 ; Remarks .......: Supersedes _FindPath(). ; Related .......: ; Link ..........: ; Example .......: _g0gcd_Trim(" Test Words ") returns "Test Words" ; ============================================================================================================================= Func _g0gcd_UnXMLTag($n = "", $flag = True, $Para = " ") ;Notes ;_Log($LogTab & "_g0gcd_UnXMLTag: Started.", $dBugLog) ;Required support ;Global variables used ;None ;Declare local variables ;Populate local configurable variables ;Initialise local variables Local $o = "" Local $p = "" Local $c = 0 ;Procedure ................................................................................................................ For $c = 1 To StringLen($n) $p = StringMid($n, $c, 1) If $p = "<" Then $flag = False If $flag = True Then $o = $o & $p If $p = ">" Then ;and Stringright($o,stringlen($Para)) <> $Para then $o = $o & $Para $flag = True EndIf Next Return $o ;_Log($LogTab & "_g0gcd_UnXMLTag: Completed.", $dBugLog) EndFunc ;==>_g0gcd_UnXMLTag ;ce ;------------------------------------------------------------------------------------------------------------------------------ ;#cs ; #FUNCTION# ================================================================================================================== ; Name...........: _g0gcd_WriteConfig($Value, $Key, $Section = "", $File = "") ; Description ...: ; Syntax.........: _g0gcd_WriteConfig($Value, $Key, $Section = "", $File = "") ; Parameters ....: ; Return values .: ; Author ........: John Powers (g0gcd) ; Modified.......: 04/10/2 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: _g0gcd_WriteConfig($Value, $Key, $Section = "", $File = "") ; ============================================================================================================================= Func _g0gcd_WriteConfig($Value, $Key, $Section = "", $File = "") ;Notes ;DEPRECATED, Use _g0gcd_IniFile($Tag, $dfltValue = "", $NewIniSection = "", $NewIniFilename = "") ;Required support ;#Include ;Global variables used ;Declare local variables Static $LastSection, $LastFile ;Populate local configurable variables ;Initialise local variables ;Procedure ................................................................................................................ If $File == "" Then $File = $LastFile Else $LastFile = $File EndIf If $Section == "" Then $Section = $LastSection Else $LastSection = $Section EndIf ;First run MUST be seeded - no error checking for this condition! ;$Value = IniRead($File,$Section,$Key,$Value) ;IniDelete($File, $Section, $Key); Force new write to bottom of section IniWrite($File, $Section, $Key, $Value) Return $Value EndFunc ;==>_g0gcd_WriteConfig ;#ce ;------------------------------------------------------------------------------------------------------------------------------ #cs Notes Find OS https://www.autoitscript.com/forum/topic/130736-how-do-i-get-os-version/ https://www.autoitscript.com/forum/profile/56360-taietel/ 04/08/2022 $colItems = "" $Output="" $objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", 0x30) If IsObj($colItems) then For $objItem In $colItems $Output = $objItem.Caption & " " & $objItem.Version & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_OperatingSystem" ) Endif #ce #cs Minify HTML #include ; to declare the Constants of MsgBox Local $sRegex = "(?m)|\s\B" Local $sString = "Test string" Local $sSubst = "" Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst) MsgBox($MB_SYSTEMMODAL, "Result", $sResult) #ce