Jump to content

DXRW4E

Active Members
  • Posts

    387
  • Joined

  • Last visited

  • Days Won

    1

Reputation Activity

  1. Thanks
    DXRW4E got a reaction from toasterking in INI File Processing Functions   
    IniEx.au3 (INI File Processing Functions) solve many problems, such as the limits of AutoIt Default INI function, and add many other options, since all function work by reference so IniEx.au3 also use less memory, and provide a really good performance in speed
     
    #include-Once ; #INDEX# ======================================================================================================================= ; Title .........: IniEx ; AutoIt Version : v3.3.9.22++ ; Language ......: English ; Description ...: INI File Processing Functions ; Author(s) .....: DXRW4E ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_IniClearCache() ;_IniCloseFileEx() ;_IniDeleteEx() ;_IniFileWriteEx() ;_IniGetFileInformationEx() ;_IniGetFileStringData() ;_IniGetSectionNumberEx() ;_IniOpenFileEx() ;_IniOpenFile() ;_IniReadEx() ;_IniReadSectionEx() ;_IniReadSectionNamesEx() ;_IniRenameSectionEx() ;_IniWriteEx() ;_IniWriteSectionEx() ; =============================================================================================================================== ; #INTERNAL_USE_ONLY# =========================================================================================================== ;__GetSeparatorCharacter() ;__IniFileWriteEx() ;__IniGetFileStringData() ;__IniReadSectionEx() ;__IniSaveCache() ;__IniWriteSectionEx() ; =============================================================================================================================== ; #CONSTANTS# =================================================================================================================== Global Const $INI_STRIPLEADING            = 1           ; $STR_STRIPLEADING  - strip leading white space Global Const $INI_STRIPTRAILING           = 2           ; $STR_STRIPTRAILING - strip trailing white space Global Const $INI_STRIPLEADTRAILING       = 3            ; BitOR($STR_STRIPLEADING,  $STR_STRIPTRAILING) Global Const $INI_ARRAYDATA               = 4 Global Const $INI_ARRAYDATA_NOCOUNT       = 8 Global Const $INI_NOWRITEREADONLY         = 16 Global Const $INI_FO_UNICODE              = 32          ; $FO_UNICODE Global Const $INI_FO_UTF16_LE             = 32          ; $FO_UTF16_LE Global Const $INI_FO_UTF16_BE             = 64          ; $FO_UTF16_BE Global Const $INI_FO_UTF8                 = 128         ; $FO_UTF8 Global Const $INI_FO_UTF8_NOBOM           = 256         ; $FO_UTF8_NOBOM Global Const $INI_NOOCCURRENCE            = 512 Global Const $INI_MERGE                   = 1024 Global Const $INI_NOCREATE                = 2048 Global Const $INI_APPENDDATA              = 4096 Global Const $INI_REPLACEONLY             = 8192 Global Const $INI_FO_UTF8_FULL            = 16384       ; $FO_UTF8_FULL Global Const $INI_NOOVERWRITE             = 32768 Global Const $INI_OVERWRITEALL            = 65536 Global Const $INI_IGNOREDUPLICATE         = 131072 Global Const $INI_DELETE                  = 262144 Global Const $INI_RENAME                  = 524288 Global Const $INI_REMOVE                  = 1048576 ;Global Const $INI_RESERVED*               = 2097152 ;Global Const $INI_RESERVED*               = 4194304 ;Global Const $INI_RESERVED*               = 8388608 Global Const $INI_OPEN_EXISTING           = 16777216 Global Const $INI_CREATEPATH              = 33554432 Global Const $INI_REPAIR_ERROR            = 67108864 Global Const $INI_DISCARDCHANGES          = 134217728 Global Const $INI_OPEN_FILEQUEUE          = 268435456 ;Global Const $INI_RESERVED*               = 536870912 Global Const $INI_2DARRAYFIELD            = 1073741824 ;;;; THESE ARE SPECIAL FLAGS, ARE USED INTERNALLY ONLY ;;;; Global Const $INI_INTERNAL_USE_ONLY       = 2147483648 Global Const $INI_FO_STYLE                = BitOR(31, $INI_OPEN_EXISTING, $INI_CREATEPATH, $INI_REPAIR_ERROR, $INI_OPEN_FILEQUEUE) Global Const $INI_MERGE_NOOCCURRENCE      = BitOR($INI_MERGE, $INI_NOOCCURRENCE) Global Const $INI_REMOVE_RENAME           = BitOR($INI_REMOVE, $INI_RENAME) Global Const $INI_REMOVE_DELETE           = BitOR($INI_REMOVE, $INI_DELETE) Global Const $INI_NOCREATE_REMOVE_DELETE  = BitOR($INI_NOCREATE, $INI_REMOVE, $INI_DELETE) Global Const $INI_NOOCCURRENCE_IGNOREDUPLICATE = BitOr($INI_NOOCCURRENCE, $INI_IGNOREDUPLICATE) Global Const $INI_OVERWRITEALL_APPENDDATA = BitOR($INI_OVERWRITEALL, $INI_APPENDDATA) Global Const $NULL_REF = Null Global Const $sINI_OPENFILE_EX            = @LF & "[]" & @LF ;;;; DO NOT EVER USE\CHANGE\EDIT THESE VARIABLES ;;;; ;;;;  THESE VARIABLES ARE USED INTERNALLY ONLY   ;;;; Global Static $INI_NULL_REF = Null Global Static $_HINI[11][11] = [[10, 0]] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniOpenFileEx ; Description ...: The _IniOpenFileEx function opens an INI file and returns a handle to it. ; Syntax.........: _IniOpenFileEx($sFilePath[, $iFlags]]) ; Parameters ....: $sFilePath       - INI File Path ;                   $iFlags          - Optional, (add the flags together for multiple operations): ;                  This Flags will be ignored if the $INI_CREATEPATH is not set\used ;                  | A file may fail to open due to access rights or attributes. ;                  | The default mode when writing text is ANSI - use the unicode flags to change this. When writing unicode files ;                  | the Windows default mode (and the fastest in AutoIt due to the least conversion) is UTF16 Little Endian (mode 32). ;                  | $INI_FO_* Flags will be ignored if the $INI_CREATEPATH is not Set\Used ;                  |$INI_FO_UNICODE or $INI_UTF16_LE (32) - Use Unicode UTF16 Little Endian reading and writing mode. Reading does not override existing BOM. ;                  |$INI_FO_UTF16_BE (64)                 - Use Unicode UTF16 Big Endian reading and writing mode. Reading does not override existing BOM. ;                  |$INI_FO_UTF8 (128)                    - Use Unicode UTF8 (with BOM) reading and writing mode. Reading does not override existing BOM. ;                  |$INI_FO_UTF8_NOBOM (256)              - Use Unicode UTF8 (without BOM) reading and writing mode. ;                  |$INI_FO_UTF8_FULL (16384)             - When opening for reading and no BOM is present, use full file UTF8 detection. If this is not used then only the initial part of the file is checked for UTF8. ;                  ;;;;;;;;;;;; ;                  |$INI_OPEN_EXISTING (16777216)      - If the INI File (Path) is Already Open use that (Handle) (Default Always Opens a New) ;                  |$INI_CREATEPATH (33554432)         - Create INI File if does not exist (Default if file not exist Return Error) ;                  |$INI_REPAIR_ERROR (67108864)       - If exist Error when Opening the INI File Repair Error, example as this line (@CRLF & [SectionName & @CRLF) repair in (@CRLF & [SectionName] & @CRLF), Default Return Error ;                  |$INI_OPEN_FILEQUEUE (268435456)    - Open INI file from Memory\Variable, $sFilePath must contain String Text Data of INI file ; Return values .: Success - INI Handle ;                  Failure - Returns 0 or String\Text of error line (check @Extended for error line number) ;                  @Error  - 0 = No error. ;                  |1 = File cannot be opened or found. ;                  |2 = Error when Opening the INI File ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniOpenFileEx($sFilePath, $iFlags = 0)     If BitAND($iFlags, $INI_OPEN_EXISTING) Then         For $i = 1 To $_HINI[0][0]             If $_HINI[$i][2] = $sFilePath Then Return SetError(0, $i, $i)         Next     EndIf     Local $sCS, $_sCS = "\r", $hFilePath, $iFileEncoding, $aFileData, $aErrorLine, $iFO_Style = BitXOR(BitOR($iFlags, $INI_FO_STYLE), $INI_FO_STYLE)     If BitAND($iFlags, $INI_OPEN_FILEQUEUE) Then         $aFileData = StringRegExpReplace($sINI_OPENFILE_EX & $sFilePath, '\r(?!\n)', @CRLF)    ;;;;, '(?<!\r)\n', @CRLF)         $sFilePath = "FileQueue"         $iFileEncoding = $iFO_Style    ;;(StringIsASCII($aFileData) ? 0 : 32)     Else         $hFilePath = FileOpen($sFilePath)         If $hFilePath = -1 Then             If Not FileExists($sFilePath) Then                 If Not BitAND($iFlags, $INI_CREATEPATH) Then Return SetError(1, 0, 0)                 $iFO_Style += 10        ;;$iFO_Style = 42             EndIf             $hFilePath = FileOpen($sFilePath, $iFO_Style)             If $hFilePath = -1 Then Return SetError(1, 0, 0)         EndIf         $aFileData = StringRegExpReplace($sINI_OPENFILE_EX & FileRead($hFilePath), '\r(?!\n)', @CRLF)    ;;;;, '(?<!\r)\n', @CRLF)         $iFileEncoding = FileGetEncoding($hFilePath)         FileClose($hFilePath)     EndIf     $aErrorLine = StringRegExp($aFileData, '\n\K[\h\f\xb\x0]*\[[^\]\n]*(?:\n|$)', 1)     If Not @Error Then         Local $iErrorLine = @Extended - (StringLen($aErrorLine[0]) - 1)         If Not BitAND($iFlags, $INI_REPAIR_ERROR) Then Return SetError(2, StringSplit(StringLeft($aFileData, $iErrorLine), @LF)[0] - 2, $aErrorLine[0])         $aFileData = StringRegExpReplace($aFileData, '(\n[\h\f\xb\x0]*\[[^\]\r\n]*)(?=[\r\n]|$)', "$1]")     EndIf     $sCS = __GetSeparatorCharacter($aFileData)     If $sCS = @CR Then $_sCS = ""     $aFileData = StringRegExpReplace($aFileData & @CRLF & "[", "\n\K(?>[" & $_sCS & "\n\h\f\xb\x0]*\n|\x0*)(?=[\h\f\xb\x0]*\[)", $sCS & "${0}" & $sCS)     $aFileData = StringRegExp($aFileData & $sCS, $sCS & "([\h\f\xb\x0]*\[)([^\]\n]*)(\][^\n]*\n)((?>[" & $_sCS & "\n\h\f\xb\x0]*\n)*)([^" & $sCS & "]*)" & $sCS & "([^" & $sCS & "]*)", 3)     $aFileData[0] = UBound($aFileData) - 1     If $aFileData[0] < 5 Then Return SetError(1, 0, 0) ; should not happen ever     $aFileData[$aFileData[0]] = StringTrimRight($aFileData[$aFileData[0]], 2)     For $iHINI = 1 To $_HINI[0][0]         If Not $_HINI[$iHINI][0] Then ExitLoop     Next     If $iHINI > $_HINI[0][0] Then         ReDim $_HINI[$iHINI + $iHINI][11]         $_HINI[0][0] = $iHINI + $iHINI - 1     EndIf     $aFileData[2] = $iHINI     If Not $_sCS Then         $aFileData[3] = StringAddCR($aFileData[3])         $aFileData[4] = StringAddCR($aFileData[4])         $aFileData[5] = StringAddCR($aFileData[5])     EndIf     For $i = 7 To $aFileData[0] Step 6         $_HINI[$iHINI][5] &= @LF & $aFileData[$i] & @CR & $i         If Not $_sCS Then             $aFileData[$i + 1] = StringAddCR($aFileData[$i + 1])             $aFileData[$i + 2] = StringAddCR($aFileData[$i + 2])             $aFileData[$i + 3] = StringAddCR($aFileData[$i + 3])             $aFileData[$i + 4] = StringAddCR($aFileData[$i + 4])         EndIf     Next     $_HINI[0][1] += 1    ;;($_HINI[0][1] < 1) ? 1 : $_HINI[0][1] + 1     $_HINI[$iHINI][0] = $iHINI     $_HINI[$iHINI][1] = $aFileData     $_HINI[$iHINI][2] = $sFilePath     $_HINI[$iHINI][3] = $iFileEncoding     $_HINI[$iHINI][4] = ($aFileData[0] - 5) / 6     $_HINI[$iHINI][5] = StringReplace($_HINI[$iHINI][5], "\E", "\e", 0, 1)     $_HINI[$iHINI][7] = Null     Return $iHINI EndFunc   ;==>_IniOpenFileEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniOpenFile ; Description ...: The _IniOpenFile function opens an INI file and returns a handle to it. ; Parameters ....: the same as the _IniOpenFileEx(), See _IniOpenFileEx() ; Return values .: See _IniOpenFileEx() ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: _IniOpenFile() is the same as the _IniOpenFileEx(), only that _IniOpenFile()  force the check\repair of @CR or @LF in @CRLF ;                    performance\speed does not change much with _IniOpenFileEx(), _IniOpenFile() can only be about 1% or 5% or10% slower ; =============================================================================================================================== Func _IniOpenFile($sFilePath, $iFlags = 0)     If BitAND($iFlags, $INI_OPEN_EXISTING) Then         For $i = 1 To $_HINI[0][0]             If $_HINI[$i][2] = $sFilePath Then Return SetError(0, $i, $i)         Next     EndIf     Local $hFilePath, $iFileEncoding, $aFileData, $aErrorLine, $iFO_Style = BitXOR(BitOR($iFlags, $INI_FO_STYLE), $INI_FO_STYLE)     If BitAND($iFlags, $INI_OPEN_FILEQUEUE) Then         $aFileData = StringRegExpReplace($sINI_OPENFILE_EX & $sFilePath, '\r\n?', @LF)         $sFilePath = "FileQueue"         $iFileEncoding = $iFO_Style    ;;(StringIsASCII($aFileData) ? 0 : 32)     Else         $hFilePath = FileOpen($sFilePath)         If $hFilePath = -1 Then             If Not FileExists($sFilePath) Then                 If Not BitAND($iFlags, $INI_CREATEPATH) Then Return SetError(1, 0, 0)                 $iFO_Style += 10        ;;$iFO_Style = 42             EndIf             $hFilePath = FileOpen($sFilePath, $iFO_Style)             If $hFilePath = -1 Then Return SetError(1, 0, 0)         EndIf         $aFileData = StringRegExpReplace($sINI_OPENFILE_EX & FileRead($hFilePath), '\r\n?', @LF)         $iFileEncoding = FileGetEncoding($hFilePath)         FileClose($hFilePath)     EndIf     $aErrorLine = StringRegExp($aFileData, '\n\K[\h\f\xb\x0]*\[[^\]\n]*(?:\n|$)', 1)     If Not @Error Then         Local $iErrorLine = @Extended - (StringLen($aErrorLine[0]) - 1)         If Not BitAND($iFlags, $INI_REPAIR_ERROR) Then Return SetError(2, StringSplit(StringLeft($aFileData, $iErrorLine), @LF)[0] - 2, $aErrorLine[0])         $aFileData = StringRegExpReplace($aFileData, '(\n[\h\f\xb\x0]*\[[^\]\n]*)(?=\n|$)', "$1]")     EndIf     $aFileData = StringRegExpReplace($aFileData & @LF & "[", '\n\K(?>[\n\h\f\xb\x0]*\n|\x0*)(?=[\h\f\xb\x0]*\[)', @CR & "${0}" & @CR)     $aFileData = StringRegExp($aFileData & @CR, '\r([\h\f\xb\x0]*\[)([^\]\n]*)(\][^\n]*\n)((?>[\n\h\f\xb\x0]*\n)*)([^\r]*)\r([^\r]*)', 3)     $aFileData[0] = UBound($aFileData) - 1     If $aFileData[0] < 5 Then Return SetError(1, 0, 0) ; should not happen ever     $aFileData[$aFileData[0]] = StringTrimRight($aFileData[$aFileData[0]], 1)     For $iHINI = 1 To $_HINI[0][0]         If Not $_HINI[$iHINI][0] Then ExitLoop     Next     If $iHINI > $_HINI[0][0] Then         ReDim $_HINI[$iHINI + $iHINI][11]         $_HINI[0][0] = $iHINI + $iHINI - 1     EndIf     $aFileData[2] = $iHINI     $aFileData[3] = StringAddCR($aFileData[3])     $aFileData[4] = StringAddCR($aFileData[4])     $aFileData[5] = StringAddCR($aFileData[5])     For $i = 7 To $aFileData[0] Step 6         $_HINI[$iHINI][5] &= @LF & $aFileData[$i] & @CR & $i         $aFileData[$i + 1] = StringAddCR($aFileData[$i + 1])         $aFileData[$i + 2] = StringAddCR($aFileData[$i + 2])         $aFileData[$i + 3] = StringAddCR($aFileData[$i + 3])         $aFileData[$i + 4] = StringAddCR($aFileData[$i + 4])     Next     $_HINI[0][1] += 1    ;;($_HINI[0][1] < 1) ? 1 : $_HINI[0][1] + 1     $_HINI[$iHINI][0] = $iHINI     $_HINI[$iHINI][1] = $aFileData     $_HINI[$iHINI][2] = $sFilePath     $_HINI[$iHINI][3] = $iFileEncoding     $_HINI[$iHINI][4] = ($aFileData[0] - 5) / 6     $_HINI[$iHINI][5] = StringReplace($_HINI[$iHINI][5], "\E", "\e", 0, 1)     $_HINI[$iHINI][7] = Null     Return $iHINI EndFunc   ;==>_IniOpenFileEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniCloseFileEx ; Description ...: The _IniCloseFileEx function closes the INI file opened by a call to _IniOpenFileEx. ; Syntax.........: _IniCloseFileEx($hIniFile[, $iFlags]) ; Parameters ....: $hIniFile - Handle or INI Path to the INI file to be closed, This parameter can be NULL (use the $NULL_REF to set NULL this parameter) ;                    if $hIniFile is NULL Function Close All Open Handle or INI Path ;                   $iFlags  - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ;                  |Default - always Commits the changes that were made when the INI file was opened by _IniOpenFileEx() ;                  |$INI_DISCARDCHANGES (134217728) - Discards the changes that were made when the INI file was opened by _IniOpenFileEx() ; Return values .: NONE ; Author ........: DXRW4E ; Remarks .......: ; =============================================================================================================================== Func _IniCloseFileEx($hIniFile, $iFlags = 0)     If $hIniFile = $NULL_REF Then         For $i = 1 To $_HINI[0][0]             If Not BitAND($iFlags, $INI_DISCARDCHANGES) And $_HINI[$i][2] <> "FileQueue" Then _IniFileWriteEx($i, $iFlags)             For $y = 0 To 10                 $_HINI[$i][$y] = ""             Next         Next         $_HINI[0][1] = 0     Else         $hIniFile = _IniGetFileInformationEx($hIniFile)         If @Error Then Return SetError(1, 0, 0)         If Not BitAND($iFlags, $INI_DISCARDCHANGES) And $_HINI[$hIniFile][2] <> "FileQueue" Then _IniFileWriteEx($hIniFile, $iFlags)         For $i = 0 To 10             $_HINI[$hIniFile][$i] = ""         Next         $_HINI[0][1] -= 1     EndIf     Return 0 EndFunc   ;==>_IniCloseFileEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniDeleteEx ; Description ...: Delete\Remove - Section\KeyName in INI File. ; Syntax.........: _IniDeleteEx(ByRef $hIniFile, $sSectionName[, $sKeyName[, $iFlags[, $scKeyName]]]) ; Parameters ....: $hIniFile     - Handle to the INI file to query "see _IniOpenFileEx()" ;                   $sSectionName - The name of the section containing the Key\Value, This parameter can be NULL (use the $NULL_REF to set NULL this parameter) ;                    If $sSectionName is NULL, $hIniFile must be contain Section String\Key\Value\Data and $sKeyName the name of the key to delete ;                  $sKeyName     - The key name to delete, If $INI_OVERWRITEALL if set\used, $sKeyName will be writte exactly as in $sKeyName (without Edit\Formatting) ;                    This parameter can be NULL (use the $NULL_REF to set NULL this parameter), If $sKeyName is NULL, $hIniFile must be contain INI String\Text Data and $sSectionName the name of the section to delete ;                   $iFlags       - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ;                  |$INI_NOOCCURRENCE (512)       - Check only first section if there are more than one ;                  |$INI_IGNOREDUPLICATE (131072) - Proceed\Execute (Add\Delete\Replace\Edit ect ect) Once Only (Ignore all other Duplicate\Occurrences of KeyName\Value\Data) ;                  |$INI_DELETE (262144)          - Delete\Remove KeyName\Value\Data ;                  |$INI_REMOVE (1048576)         - Remove\Delete Section ;                   $scKeyName    - Optional, Key-Name separator character, Default is '=', This parameter can not be '"' or @CR or @LF ; Return values .: Returns a 0 (check @Extended for number of edit performed) ;                  @Error  - 0 = No error. ;                  |1 = Invalid IniHandle. ;                  |3 = SectionName not found ; Remarks .......: $INI_MERGE (1024) - (Join section if more than one in INI file) is always set\used by default, to disable it just use the $INI_NOOCCURRENCE ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniDeleteEx(ByRef $hIniFile, $sSectionName, $sKeyName = "", $iFlags = 0, $scKeyName = "=")     If Not $scKeyName Then $scKeyName = "="     If $sSectionName = $NULL_REF Then         Local $iOffSet = StringInStr($hIniFile, @LF, 1)         If StringRegExp(StringLeft($hIniFile, $iOffSet), '^(?i)[\h\f\xb\x0]*(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*') Then             If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $hIniFile = StringRegExpReplace($hIniFile, '\n[\h\f\xb\x0]*(?i)(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*', "")             $hIniFile = StringTrimLeft($hIniFile, $iOffSet)             SetExtended(1)         Else             $hIniFile = StringRegExpReplace($hIniFile, '\n[\h\f\xb\x0]*(?i)(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*', "", (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? 1 : 0))         EndIf     ElseIf $sKeyName = $NULL_REF Then         ;Not Recommended (NOT SAFE), if the Section (contains) String\Text Data is greater than 4.5 MB, the Section will be ignored         $hIniFile = StringTrimRight(StringRegExpReplace($hIniFile & @LF & "[", "(?is)\n[\h\f\xb\x0]*\[\Q" & StringReplace($sSectionName, "\E", "\e", 0, 1) & "\E\][^\n]*(?>\n?(?![\h\f\xb\x0]*\[))(.*?(?=\n[\h\f\xb\x0]*\[))", "", (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? 1 : 0)), 2)     Else         If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")         ;;;;If Not $sSectionName Then Return SetError(2, 0, "")    ;Invalid Section Name         If StringInStr($sSectionName, "\E", 1) Then $sSectionName = StringReplace($sSectionName, "\E", "\e", 0, 1)         If Not $sKeyName Or BitAND($iFlags, $INI_REMOVE_DELETE) = $INI_REMOVE Then             $iFlags = BitOr($iFlags, $INI_REMOVE)             __IniWriteSectionEx($hIniFile, $sSectionName, $INI_NULL_REF, $iFlags, $INI_NULL_REF, $_HINI[$hIniFile][1])         Else             $iFlags = BitOR(BitAND($iFlags, $INI_NOOCCURRENCE_IGNOREDUPLICATE), $INI_DELETE, $INI_MERGE)             If $_HINI[$hIniFile][7] <> $sSectionName Or ($_HINI[$hIniFile][8] > 1 And BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) <> BitAND($_HINI[$hIniFile][9], $INI_MERGE_NOOCCURRENCE)) Then                 __IniReadSectionEx($hIniFile, $sSectionName, $iFlags, $_HINI[$hIniFile][1])                 If @Error Then Return SetError(3, 0, "")             EndIf             Local $aKeyValue[2][3] = [[1],[$sKeyName]]             __IniWriteSectionEx($hIniFile, $sSectionName, $aKeyValue, $iFlags, $scKeyName, $_HINI[$hIniFile][1])         EndIf     EndIf     Return SetError(0, @Extended, 0) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniReadEx ; Description ...: The _IniReadEx Retrieves a string from the specified section in an Ini file ; Syntax.........: _IniReadEx($hIniFile, $sSectionName, $sKeyName[, $sDefault[, $iFlags[, $scKeyName]]]) ; Parameters ....: $hIniFile      - Handle to the INI file to query "see _IniOpenFileEx()" ;                   $sSectionName  - The name of the section containing the key name, This parameter can be NULL (use the $NULL_REF to set NULL this parameter) ;                    If $sSectionName is NULL, $hIniFile must be contain Section String\Key\Value\Data ;                   $sKeyName      - The name of the key whose associated string is to be retrieved ;                   $sDefault      - The default value to return if the requested KeyName is not found. ;                   $iFlags        - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ;                  |$INI_ARRAYDATA (4)         - Read All KeyName and Return Array of ValueString ;                  |$INI_ARRAYDATA_NOCOUNT (8) - Disable the return count in the first element, This Flags will be ignored if the $INI_ARRAYDATA is not set\used ;                  |$INI_NOOCCURRENCE (512)    - Read only first section if there are more than one ;                  |$INI_MERGE (1024)          - Join section if more than one in INI file, This Flag will be ignored if the $INI_NOOCCURRENCE is set\used ;                   $scKeyName - Optional, Key-Name separator character, Default is '=', This parameter can not be '"' or @CR or @LF ; Return values .: The first occurrence of requested key value as a string Or Array of Value String ;                  Failure - Returns $sDefault parameter ;                  @Error  - 0 = No error. ;                  |1 = Invalid IniHandle. ;                  |3 = SectionName not found ;                  |5 = Invalid KeyName ;                  |6 = KeyName not found ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniReadEx(ByRef $hIniFile, $sSectionName, $sKeyName, $sDefault = "", $iFlags = 0, $scKeyName = "=")     ;;If Not $sKeyName Then Return SetError(5, 0, "")     If StringInStr($sKeyName, "\E", 1) Then $sKeyName = StringReplace($sKeyName, "\E", "\e", 0, 1)     Local $aValueString, $sValueString, $iArray = BitAND($iFlags, $INI_ARRAYDATA)     If $sSectionName = $NULL_REF Then         $aValueString = StringRegExp(StringLeft($hIniFile, StringInStr($hIniFile, @LF, 1)), '^(?i)[\h\f\xb\x0]*(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)(?>[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*)(?|"([^\r\n]*)"|(.*?))[\h\f\xb\x0]*(?=[\r\n]|$)', 1)     Else         If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")         If StringInStr($sSectionName, "\E", 1) Then $sSectionName = StringReplace($sSectionName, "\E", "\e", 0, 1)         If $_HINI[$hIniFile][7] <> $sSectionName Or ($_HINI[$hIniFile][8] > 1 And BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) <> BitAND($_HINI[$hIniFile][9], $INI_MERGE_NOOCCURRENCE)) Then             _IniReadSectionEx($hIniFile, $sSectionName, BitOR($iFlags, $INI_STRIPLEADTRAILING))             If @Error Then Return SetError(3, 0, "")         EndIf         $aValueString = StringRegExp(StringLeft(($_HINI[$hIniFile][1])[$_HINI[$hIniFile][10]], StringInStr(($_HINI[$hIniFile][1])[$_HINI[$hIniFile][10]], @LF, 1)), '^(?i)[\h\f\xb\x0]*(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)(?>[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*)(?|"([^\r\n]*)"|(.*?))[\h\f\xb\x0]*(?=[\r\n]|$)', 1)         ;;;;$aValueString = StringRegExp(($sSectionName = $NULL_REF ? $hIniFile : ($_HINI[$hIniFile][1])[$_HINI[$hIniFile][10]]), '(?im)^[\h\f\xb\x0]*(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*(?|"([^\r\n]*)"|(.*?))[\h\f\xb\x0]*(?=[\r\n]|$)', 3)     EndIf     If Not @Error Then         If Not $iArray Then Return $aValueString[0]         $sValueString = $aValueString[0] & @LF     EndIf     $aValueString = StringRegExp(($sSectionName = $NULL_REF ? $hIniFile : ($_HINI[$hIniFile][1])[$_HINI[$hIniFile][10]]), '\n[\h\f\xb\x0]*(?i)(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)(?>[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*)(?|"([^\r\n]*)"|(.*?))[\h\f\xb\x0]*(?=[\r\n]|$)', ($iArray ? 3 : 1))     If @Error Then Return SetError(6, 0, $sDefault)     If Not $iArray Then Return $aValueString[0]     For $i = 0 To UBound($aValueString) - 1         $sValueString &= $aValueString[$i] & @LF     Next     Return StringSplit(StringTrimRight($sValueString, 1), @LF, (BitAND($iFlags, $INI_ARRAYDATA_NOCOUNT) ? 3 : 1)) EndFunc   ;==>_IniReadEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniReadSectionEx ; Description ...: The _IniReadSectionEx Retrieves all the lines for the specified section ; Syntax.........: _IniReadSectionEx(ByRef $hIniFile, $sSectionName[, $iFlags[, $scKeyName]) ; Parameters ....: $hIniFile      - Handle to the INI file to query "see _IniOpenFileEx()" ;                   $sSectionName  - The name of the section containing the Key\Value, This parameter can be NULL (use the $NULL_REF to set NULL this parameter) ;                    If $sSectionName is NULL, $hIniFile must be contain Section String\Key\Value\Data ;                   $iFlags        - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ;                    Default Return Section String\Text Data ;                  |$INI_NOOCCURRENCE (512)        - Read only first section if there are more than one ;                  |$INI_MERGE (1024)              - Join section if more than one in INI file, This Flag will be ignored if the $INI_NOOCCURRENCE is set\used ;                  |$INI_2DARRAYFIELD (1073741824) - Return 2DArray ;                     $aArray[0][0] = number of elements ;                     $aArray[0][1] = Key-Name separator character, Defaut is '=' ;                     $aArray[1][0] = "KeyName" ;                     $aArray[1][1] = "Value" ;                     $aArray[1][2] = "Unmodified contents of a line (example '    KeyName  = Value')" ;                     $aArray[n][0] = "KeyName" ;                     $aArray[n][1] = "Value" ;                     $aArray[n][2] = "Unmodified contents of a line (example ' KeyName =  Value')" ;                   $scKeyName - Optional, Key-Name separator character, Default is '=', This parameter can not be '"' or @CR or @LF ; Return values .: String\Text Data Or 2D Array ;                  @Error  - 0 = No error. ;                  |1 = Invalid IniHandle. ;                  |3 = SectionName's not found ;                  |4 = Array is invalid, Key\Value not found ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniReadSectionEx(ByRef $hIniFile, $sSectionName, $iFlags = 0, $scKeyName = "=")     If Not $scKeyName Then $scKeyName = "="     If $sSectionName = $NULL_REF Then         Local $_aSectionData = StringRegExp($hIniFile, '(?m)^((?>[\h\f\xb\x0]*)((?>"[^"\r\n]+"|(?:[^"\s' & $scKeyName & '\x0]+|(?>[\h\f\xb\x0]+)(?!' & $scKeyName & '))*))(?>[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*)(?|"([^\r\n]*)"|(.*?))[\h\f\xb\x0]*(?=[\r\n]|$))', 3)     Else         If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")         If $_HINI[$hIniFile][7] <> $sSectionName Or ($_HINI[$hIniFile][8] > 1 And BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) <> BitAND($_HINI[$hIniFile][9], $INI_MERGE_NOOCCURRENCE)) Then             $iFlags = BitOR($iFlags, $INI_NOCREATE)             __IniReadSectionEx($hIniFile, $sSectionName, $iFlags, $_HINI[$hIniFile][1])             If @Error Then Return SetError(3, 0, "")         EndIf         If Not BitAND($iFlags, $INI_2DARRAYFIELD) Then Return ($_HINI[$hIniFile][1])[$_HINI[$hIniFile][10]]         Local $_aSectionData = StringRegExp(($_HINI[$hIniFile][1])[$_HINI[$hIniFile][10]], '(?m)^((?>[\h\f\xb\x0]*)((?>"[^"\r\n]+"|(?:[^"\s' & $scKeyName & '\x0]+|(?>[\h\f\xb\x0]+)(?!' & $scKeyName & '))*))(?>[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*)(?|"([^\r\n]*)"|(.*?))[\h\f\xb\x0]*(?=[\r\n]|$))', 3)     EndIf     If @Error Then Return SetError(4, 0, "")     Local $iaSectionData = UBound($_aSectionData), $aSectionData[$iaSectionData / 3 + 1][3] = [[0,$scKeyName,$iaSectionData - 1]]     For $i = 0 To $aSectionData[0][2] Step 3         $aSectionData[0][0] += 1         $aSectionData[$aSectionData[0][0]][0] = $_aSectionData[$i + 1]         $aSectionData[$aSectionData[0][0]][1] = $_aSectionData[$i + 2]         $aSectionData[$aSectionData[0][0]][2] = $_aSectionData[$i]     Next     Return SetError(0, $aSectionData[0][0], $aSectionData) EndFunc   ;==>_IniReadSectionEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniReadSectionNamesEx ; Description ...: The _IniReadSectionNamesEx Retrieves the names of all sections in an INI file ; Syntax.........: _IniReadSectionNamesEx($hIniFile[, $iFlags]) ; Parameters ....: $hIniFile - Handle to the INI file to query "see _IniOpenFileEx()" ;                   $iFlags   - Optional, Flag to indicate the type of action that should be performed ;                  |$INI_ARRAYDATA_NOCOUNT (8) - disable the return count in the first element ;                  |$NULL_REF (NULL)           - $hIniFile must be contain INI String\Section\Key\Value\Data ; Return values .: Array of SectionNames String, and set @Extended = Number of Section's ;                  @Error  - 0 = No error. ;                  |1 = Array is invalid, Invalid IniHandle. ;                  |3 = Array is invalid, SectionName's not found ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniReadSectionNamesEx(ByRef $hIniFile, $iFlags = 0)     If $iFlags = $NULL_REF Then         Local $aSectionNames, $iANC = BitAND($iFlags, $INI_ARRAYDATA_NOCOUNT)         $aSectionNames = StringRegExp(($iANC ? @LF : @LF & "[]" & @LF) & $hIniFile, "\n[\h\f\xb\x0]*\[([^\r\n]*)\]", 3)         If @Error Then Return SetError(1, 0, "")         If $iANC Then Return SetError(0, UBound($aSectionNames), $aSectionNames)         $aSectionNames[0] = UBound($aSectionNames) - 1         Return SetError(0, $aSectionNames[0], $aSectionNames)     EndIf     If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")     If Not $_HINI[$hIniFile][4] Then Return SetError(3, 0, "")     If BitAND($iFlags, $INI_ARRAYDATA_NOCOUNT) Then Return SetError(0, $_HINI[$hIniFile][4], StringRegExp($_HINI[$hIniFile][5], "\n([^\r\n]*)", 3))     Return SetError(0, $_HINI[$hIniFile][4], StringRegExp(@LF & $_HINI[$hIniFile][4] & $_HINI[$hIniFile][5], "\n([^\r\n]*)", 3)) EndFunc   ;==>_IniReadSectionNamesEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniRenameSectionEx ; Description ...: The _IniRenameSectionEx rename the sections in an INI file ; Syntax.........: _IniRenameSectionEx($hIniFile[, $iFlags]) ; Parameters ....: $hIniFile      - Handle to the INI file to query "see _IniOpenFileEx()" ;                   $iFlags        - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ;                  |$INI_NOOCCURRENCE (512) - Rename only first section if there are more than one ;                  |$INI_MERGE (1024)       - Join section if more than one in INI\INI file, This Flag will be ignored if the $INI_NOOCCURRENCE is set\used ;                  |$NULL_REF (NULL)        - $hIniFile must be contain INI String\Section\Key\Value\Data ; Return values .: Returns a 0 (check @Extended for number of edit performed) ;                  @Error  - 0 = No error. ;                  |1 = Invalid IniHandle. ;                  |3 = SectionName's not found ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniRenameSectionEx(ByRef $hIniFile, $sSectionName, $sNewSectionName, $iFlags = 0)     ;;;;If Not $sSectionName Or Not $sNewSectionName Then Return SetError(2, 0, "")    ;Invalid Section Name     If $iFlags = $NULL_REF Then         $hIniFile = StringRegExpReplace($hIniFile, "(?mi)^[\h\f\xb\x0]*\[\K\Q" & StringReplace($sSectionName, "\E", "\e", 0, 1) & "\E(?=\])", StringReplace($sNewSectionName, "\", "\\", 0, 1), (BitAND($iFlags, $INI_NOOCCURRENCE) ? 1 : 0))     Else         If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")         If StringInStr($sSectionName, "\E", 1) Then $sSectionName = StringReplace($sSectionName, "\E", "\e", 0, 1)         $iFlags = BitXOR(BitOR($iFlags, $INI_REMOVE_RENAME), $INI_REMOVE)         If BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) = $INI_MERGE And Not __IniReadSectionEx($hIniFile, $sSectionName, $iFlags, $_HINI[$hIniFile][1]) Then Return SetError(3, 0, 0)         __IniWriteSectionEx($hIniFile, $sSectionName, $sNewSectionName, $iFlags, $INI_NULL_REF, $_HINI[$hIniFile][1])     EndIf     Return SetError(@Error, @Extended, 0) EndFunc   ;==>_IniRenameSectionEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniWriteEx ; Description ...: Write\Add\Replace\Delete\Change\Edit a KeyName\Value\Data in INI File ; Syntax.........: _IniWriteEx(ByRef $hIniFile, $sSectionName, $sKeyName, $sValue[, $iFlags[, $scKeyName]]) ; Parameters ....: $hIniFile     - Handle to the INI file to query "see _IniOpenFileEx()" ;                   $sSectionName - The name of the section containing the Key\Value, This parameter can be NULL (use the $NULL_REF to set NULL this parameter) ;                    If $sSectionName is NULL, $hIniFile must be contain Section String\Key\Value\Data ;                  $sKeyName     - The key name in the in the .ini file. ;                  $sKeyName     - The value to write/change. ;                   $iFlags       - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ;                  |$INI_STRIPLEADING (1)         - strip leading white space Section, This Flag will be ignored if the $INI_OVERWRITEALL or $INI_APPENDDATA is set\used ;                  |$INI_STRIPTRAILING (2)        - trailing white space Section, This Flag will be ignored if the $INI_OVERWRITEALL or $INI_APPENDDATA is set\used ;                  |$INI_NOOCCURRENCE (512)       - Check only first section if there are more than one ;                  |$INI_NOCREATE (2048)          - Not Create New Section If Section Not Exist ;                  |$INI_APPENDDATA (4096)        - Add KeyName\Value\Data (Append Mod) ;                  |$INI_REPLACEONLY (8192)       - Add KeyName\Value\Data Only if Exist ;                  |$INI_NOOVERWRITE (32768)      - Add KeyName\Value\Data Only if Not Exist ;                  |$INI_OVERWRITEALL (65536)     - Overwrite All data in Section (Replaces all KeyName\Value\Data in the Section) ;                  |$INI_IGNOREDUPLICATE (131072) - Proceed\Execute (Add\Delete\Replace\Edit ect ect) Once Only (Ignore all other Duplicate\Occurrences of KeyName\Value\Data) ;                  |$INI_DELETE (262144)          - Delete\Remove KeyName\Value\Data ;                   $scKeyName     - Optional, Key-Name separator character, Default is '=', This parameter can not be '"' or @CR or @LF ; Return values .: Returns a 0 (check @Extended for number of edit performed) ;                  @Error  - 0 = No error. ;                  |1 = Invalid IniHandle. ;                  |3 = SectionName's not found ;                  |5 = Invalid KeyName ; Author ........: DXRW4E ; Remarks .......: $INI_MERGE (1024) - (Join section if more than one in INI file) is always set\used by default, to disable it just use the $INI_NOOCCURRENCE ; =============================================================================================================================== Func _IniWriteEx(ByRef $hIniFile, $sSectionName, $sKeyName, $sValue, $iFlags = 0, $scKeyName = "=")     ;;If Not $sKeyName Then Return SetError(5, 0, "")     If Not $scKeyName Then $scKeyName = "="     If $sSectionName = $NULL_REF Then         If BitAND($iFlags, $INI_OVERWRITEALL_APPENDDATA) Then             If BitAND($iFlags, $INI_OVERWRITEALL) Then $hIniFile = ""             $hIniFile &= $sKeyName & $scKeyName & $sValue & @CRLF         Else             Local $asKeyValue, $sKNPattern, $iOffSet = StringInStr($hIniFile, @LF, 1)             $sKNPattern = '\n[\h\f\xb\x0]*(?i)(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*'             If StringRegExp(StringLeft($hIniFile, $iOffSet), '^(?i)[\h\f\xb\x0]*(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*') Then                 If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $hIniFile = StringRegExpReplace($hIniFile, $sKNPattern, "")                 If BitAND($iFlags, $INI_DELETE) Then                     $hIniFile = StringTrimLeft($hIniFile, $iOffSet)                 ElseIf Not BitAND($iFlags, $INI_NOOVERWRITE) Then                     $hIniFile = $sKeyName & $scKeyName & $sValue & @CRLF & StringTrimLeft($hIniFile, $iOffSet)                 EndIf             ElseIf BitAND($iFlags, $INI_DELETE) Then                 $hIniFile = StringRegExpReplace($hIniFile, $sKNPattern, "", (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? 1 : 0))             Else                 $asKeyValue = StringRegExp($hIniFile, $sKNPattern, 1)                 $iOffSet = @Extended - 1                 If Not @Error Then                     If BitAND($iFlags, $INI_NOOVERWRITE) Then                         If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $hIniFile = StringLeft($hIniFile, $iOffSet) & StringRegExpReplace(StringTrimLeft($hIniFile, $iOffSet), $sKNPattern, "")                     Else                         $hIniFile = StringLeft($hIniFile, $iOffSet + 1 - StringLen($asKeyValue[0])) & $sKeyName & $scKeyName & $sValue & @CR & (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? StringTrimLeft($hIniFile, $iOffSet) : StringRegExpReplace(StringTrimLeft($hIniFile, $iOffSet), $sKNPattern, ""))                     EndIf                 ElseIf Not BitAND($iFlags, $INI_REPLACEONLY) Then                     $hIniFile &= $sKeyName & $scKeyName & $sValue & @CRLF                 Else                     Return SetError(0, 0, 0)                 EndIf             EndIf         EndIf         Return SetError(0, 1, 0)     Else         If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")         ;;;;If Not $sSectionName Then Return SetError(2, 0, "")    ;Invalid Section Name         If StringInStr($sSectionName, "\E", 1) Then $sSectionName = StringReplace($sSectionName, "\E", "\e", 0, 1)         Local $aKeyValue[2][3] = [[1],[$sKeyName,"",$sKeyName & $scKeyName & $sValue]]         $iFlags = BitOR(BitXOR($iFlags, BitAND($iFlags, $INI_REMOVE_RENAME)), $INI_MERGE)         If $_HINI[$hIniFile][7] <> $sSectionName Or ($_HINI[$hIniFile][8] > 1 And BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) <> BitAND($_HINI[$hIniFile][9], $INI_MERGE_NOOCCURRENCE)) Then             __IniReadSectionEx($hIniFile, $sSectionName, $iFlags, $_HINI[$hIniFile][1])             If @Error Then Return SetError(3, 0, "")         EndIf         __IniWriteSectionEx($hIniFile, $sSectionName, $aKeyValue, $iFlags, $scKeyName, $_HINI[$hIniFile][1])     EndIf     Return SetError(@Error, @Extended, 0) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniWriteSectionEx ; Description ...: Add\Replace\Delete\Remove\Rename\Change\Edit a Section\KeyName\Value\Data in INI File. ; Syntax.........: _IniWriteSectionEx() ; Parameters ....: $hIniFile     - Handle to the INI file to query "see _IniOpenFileEx()" ;                   $sSectionName - The name of the section containing the Key\Value\Data ;                  $aKeyValue    - String\Text Data (example 'KeyName=Value 7 @LF & KeyName2=Value2') or an 2DArray is passed as data, the return Array of IniReadSectionEx() can be used immediately. ;                    If $aKeyValue is String\Text Data and $INI_OVERWRITEALL or $INI_APPENDDATA if Set\Used, $aKeyValue will be writte exactly as in $aKeyValue (without Edit\Formatting) ;                   $iFlags       - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ;                  |$INI_STRIPLEADING (1)         - strip leading white space Section, This Flag will be ignored if the $INI_OVERWRITEALL or $INI_APPENDDATA is set\used ;                  |$INI_STRIPTRAILING (2)        - trailing white space Section, This Flag will be ignored if the $INI_OVERWRITEALL or $INI_APPENDDATA is set\used ;                  |$INI_NOOCCURRENCE (512)       - Check only first section if there are more than one ;                  |$INI_NOCREATE (2048)          - Not Create New Section If Section Not Exist ;                  |$INI_APPENDDATA (4096)        - Add KeyName\Value\Data (Append Mod) ;                  |$INI_REPLACEONLY (8192)       - Add KeyName\Value\Data Only if Exist ;                  |$INI_NOOVERWRITE (32768)      - Add KeyName\Value\Data Only if Not Exist ;                  |$INI_OVERWRITEALL (65536)     - Overwrite All data in Section (Replaces all KeyName\Value\Data in the Section) ;                  |$INI_IGNOREDUPLICATE (131072) - Proceed\Execute (Add\Delete\Replace\Edit ect ect) Once Only (Ignore all other Duplicate\Occurrences of KeyName\Value\Data) ;                  |$INI_DELETE (262144)          - Delete\Remove KeyName\Value\Data ;                  |$INI_RENAME (524288)          - Renames a section ;                  |$INI_REMOVE (1048576)         - Remove\Delete Section ;                   $scKeyName     - Optional, Key-Name separator character, Default is '=', This parameter can not be '"' or @CR or @LF ; Return values .: Returns a 0 (check @Extended for number of edit performed) ;                  @Error  - 0 = No error. ;                  |1 = Invalid IniHandle. ;                  |3 = SectionName's not found ;                  |5 = Invalid KeyName ; Remarks .......: ; Author ........: DXRW4E ; Remarks .......: $INI_MERGE (1024) - (Join section if more than one in INI file) is always set\used by default, to disable it just use the $INI_NOOCCURRENCE ; =============================================================================================================================== Func _IniWriteSectionEx(ByRef $hIniFile, $sSectionName, $aKeyValue, $iFlags = 0, $scKeyName = "=") ;~     If $sSectionName = $NULL_REF Then ;~         If Not $scKeyName Then $scKeyName = "=" ;~         If IsArray($aKeyValue) Then ;~             Local $iCols = UBound($aKeyValue, 2) ;~             If UBound($aKeyValue, 0) <> 2 Or $iCols < 2 Then Return SetError(7, 0, "") ;~             If $iCols = 2 Then ;~                 ReDim $aKeyValue[$aKeyValue[0][0] + 1][3] ;~                 For $i = 1 To $aKeyValue[0][0] ;~                     $aKeyValue[$i][2] = $aKeyValue[$i][0] & $scKeyName & $aKeyValue[$i][1] ;~                 Next ;~             EndIf ;~         ElseIf Not BitAND($iFlags, $INI_OVERWRITEALL_APPENDDATA) Then ;~             $aKeyValue = _IniReadSectionEx($aKeyValue, Null, $INI_2DARRAYFIELD, $scKeyName) ;~             If @Error Then Return SetError(7, 0, "") ;~         EndIf ;~         If BitAND($iFlags, $INI_OVERWRITEALL_APPENDDATA) Then ;~             If BitAND($iFlags, $INI_OVERWRITEALL) Then $hIniFile = "" ;~             If IsArray($aKeyValue) Then ;~                 For $i = 1 To $aKeyValue[0][0] ;~                     $hIniFile &= $aKeyValue[$i][2] & @CRLF ;~                 Next ;~             Else ;~                 ;;    KeyName\Value\Text Data will be writte exactly as in $aKeyValue (without Edit\Formatting ect ect) ;~                 $hIniFile &= $aKeyValue & (StringRight($aKeyValue, 1) = @LF ? "" : @CRLF) ;~             EndIf ;~             Return SetError(0, 1, 0) ;~         Else ;~             Local $asKeyValue, $iKeyValue = 0, $sKNPattern, $iOffSet = StringInStr($hIniFile, @LF, 1) ;~             For $i = 1 To $aKeyValue[0][0] ;~                 $sKNPattern = '\n[\h\f\xb\x0]*(?i)(?>\Q"' & $aKeyValue[$i][0] & '"\E|\Q' & $aKeyValue[$i][0] & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*' ;~                 If StringRegExp(StringLeft($hIniFile, $iOffSet), '^(?i)[\h\f\xb\x0]*(?>\Q"' & $aKeyValue[$i][0] & '"\E|\Q' & $aKeyValue[$i][0] & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*') Then ;~                     If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $hIniFile = StringRegExpReplace($hIniFile, $sKNPattern, "") ;~                     If BitAND($iFlags, $INI_DELETE) Then ;~                         $hIniFile = StringTrimLeft($hIniFile, $iOffSet) ;~                     ElseIf Not BitAND($iFlags, $INI_NOOVERWRITE) Then ;~                         $hIniFile = $aKeyValue[$i][2] & @CRLF & StringTrimLeft($hIniFile, $iOffSet) ;~                     EndIf ;~                 ElseIf BitAND($iFlags, $INI_DELETE) Then ;~                     $hIniFile = StringRegExpReplace($hIniFile, $sKNPattern, "", (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? 1 : 0)) ;~                 Else ;~                     $asKeyValue = StringRegExp($hIniFile, $sKNPattern, 1) ;~                     $iOffSet = @Extended - 1 ;~                     If Not @Error Then ;~                         If BitAND($iFlags, $INI_NOOVERWRITE) Then ;~                             If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $hIniFile = StringLeft($hIniFile, $iOffSet) & StringRegExpReplace(StringTrimLeft($hIniFile, $iOffSet), $sKNPattern, "") ;~                         Else ;~                             $hIniFile = StringLeft($hIniFile, $iOffSet + 1 - StringLen($asKeyValue[0])) & $aKeyValue[$i][2] & @CR & (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? StringTrimLeft($hIniFile, $iOffSet) : StringRegExpReplace(StringTrimLeft($hIniFile, $iOffSet), $sKNPattern, "")) ;~                         EndIf ;~                     ElseIf Not BitAND($iFlags, $INI_REPLACEONLY) Then ;~                         $hIniFile &= $aKeyValue[$i][2] & @CRLF ;~                     Else ;~                         $iKeyValue -= 1 ;~                     EndIf ;~                 EndIf ;~                 $iKeyValue += 1 ;~             Next ;~             Return SetError(0, $iKeyValue, 0) ;~         EndIf ;~     EndIf     If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")     ;;;;If Not $sSectionName Then Return SetError(2, 0, "")    ;Invalid Section Name     If StringInStr($sSectionName, "\E", 1) Then $sSectionName = StringReplace($sSectionName, "\E", "\e", 0, 1)     If BitAND($iFlags, $INI_REMOVE) Then         __IniWriteSectionEx($hIniFile, $sSectionName, $INI_NULL_REF, $iFlags, $INI_NULL_REF, $_HINI[$hIniFile][1])     ElseIf BitAND($iFlags, $INI_RENAME) Then         ;;;;    $aKeyValue is New Section Name         ;;If Not $aKeyValue Then Return SetError(5, 0, "")         If BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) = $INI_MERGE And Not __IniReadSectionEx($hIniFile, $sSectionName, $iFlags, $_HINI[$hIniFile][1]) Then Return SetError(3, 0, 0)         __IniWriteSectionEx($hIniFile, $sSectionName, $aKeyValue, $iFlags, $INI_NULL_REF, $_HINI[$hIniFile][1])     Else         If Not $scKeyName Then $scKeyName = "="         If IsArray($aKeyValue) Then             Local $iCols = UBound($aKeyValue, 2)             If UBound($aKeyValue, 0) <> 2 Or $iCols < 2 Then Return SetError(5, 0, "")             If $iCols = 2 Then                 ReDim $aKeyValue[$aKeyValue[0][0] + 1][3]                 For $i = 1 To $aKeyValue[0][0]                     $aKeyValue[$i][2] = $aKeyValue[$i][0] & $scKeyName & $aKeyValue[$i][1]                 Next             EndIf         ElseIf Not BitAND($iFlags, $INI_OVERWRITEALL_APPENDDATA) Then             $aKeyValue = _IniReadSectionEx($aKeyValue, Null, $INI_2DARRAYFIELD, $scKeyName)             If @Error Then Return SetError(5, 0, "")         EndIf         $iFlags = BitOR($iFlags, $INI_MERGE)         If $_HINI[$hIniFile][7] <> $sSectionName Or ($_HINI[$hIniFile][8] > 1 And BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) <> BitAND($_HINI[$hIniFile][9], $INI_MERGE_NOOCCURRENCE)) Then             __IniReadSectionEx($hIniFile, $sSectionName, $iFlags, $_HINI[$hIniFile][1])             If @Error Then Return SetError(3, 0, "")         EndIf         __IniWriteSectionEx($hIniFile, $sSectionName, $aKeyValue, $iFlags, $scKeyName, $_HINI[$hIniFile][1])     EndIf     Return SetError(@Error, @Extended, 0) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniGetSectionNumberEx ; Description ...: The _IniGetSectionNumberEx Retrieves the number of all sections in an INI file ; Syntax.........: _IniGetSectionNumberEx(Byref $hIniFile) ; Parameters ....: $hIniFile      - Handle to the INI file to query "see _IniOpenFileEx()" ; Return values .: Number of Section's ;                  @Error  - 0 = No error. ;                  |1 = Invalid IniHandle. ;                  |3 = SectionName's not found ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniGetSectionNumberEx(ByRef $hIniFile)     If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then         Local $aSectionNames = StringRegExp(@LF & $hIniFile, "\n[\h\f\xb\x0]*\[[^\r\n]*\K\]", 3)    ;StringRegExp($hIniFile, "(?m)^[\h\f\xb\x0]*\[[^\r\n]*\]", 3)         Return SetError(@Error, 0, UBound($aSectionNames))     EndIf     Return SetError(($_HINI[$hIniFile][4] ? 0 : 3), 0, $_HINI[$hIniFile][4]) EndFunc   ;==>_IniGetSectionNumberEx ; #FUNCTION# =========================================================================================================== ; Name...........: _IniGetFileInformationEx ; Description ...: Returns information about an INI file ; Syntax.........: _IniGetFileInformationEx($hIniFile[, $iFlags]) ; Parameters ....: $hIniFile    - Handle of INI file previously opened by _IniOpenFileEx, see _IniOpenFileEx() ;                  $iFlags - Optional ;                  |0  - Return INI Handle (Default) ;                  |1  - Return INI File Array Data (is array of arrays) ;                  |2  - Return INI File Path ;                  |3  - Return INI Encoding ;                  |4  - Return INI Section Number ; Return values .: See Flag parameter ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: ; =============================================================================================================================== Func _IniGetFileInformationEx($hIniFile, $iFlags = 0)     If Not $hIniFile Then Return SetError(1, 0, "")     If $_HINI[0][1] < 0 Then         $_HINI[0][1] = 0         Return SetError(1, 0, "")     ElseIf IsString($hIniFile) Then         ;;If StringIsDigit($hIniFile) And StringLeft($hIniFile, 1) <> "0" Then         ;;    $hIniFile = Number($hIniFile)         ;;Else             For $i = 1 To $_HINI[0][0]                 If $_HINI[$i][2] = $hIniFile Then ExitLoop             Next             $hIniFile = $i         ;;EndIf     EndIf     If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")    ; Or $hIniFile <> $_HINI[$hIniFile][0]     If $iFlags < 1 Or $iFlags > 4 Then Return $hIniFile     Return SetError(0, $hIniFile, $_HINI[$hIniFile][$iFlags]) EndFunc   ;==>_IniGetFileInformationEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniGetFileStringData ; Description ...: The _IniGetFileStringData Retrieves all INI Lines\String\Text Data ; Syntax.........: _IniGetFileStringData(ByRef $hIniFile[, $iFlags]) ; Parameters ....: $hIniFile      - Handle to the INI file to query "see _IniOpenFileEx()" ;                   $iFlags        - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ;                  |$INI_STRIPLEADING (1)          - strip leading white space Section ;                  |$INI_STRIPTRAILING (2)         - strip trailing white space Section ; Return values .: String\Text Data ;                  @Error  - 0 = No error. ;                  |1 = Invalid IniHandle. ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniGetFileStringData(ByRef $hIniFile, $iFlags = 0)     If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")     ;;Local $sData, $iSL = BitAND($iFlags, $INI_STRIPLEADING), $iST = BitAND($iFlags, $INI_STRIPTRAILING)     ;;$sData = ($iSL ? "" : ($_HINI[$hIniFile][1])[3]) & ($_HINI[$hIniFile][1])[4] & ($iST ? "" : ($_HINI[$hIniFile][1])[5])     ;;For $i = 6 To ($_HINI[$hIniFile][1])[0] Step 6     ;;    $sData &= ($_HINI[$hIniFile][1])[$i] & ($_HINI[$hIniFile][1])[$i + 1] & ($_HINI[$hIniFile][1])[$i + 2] & ($iSL ? "" : ($_HINI[$hIniFile][1])[$i + 3]) & ($_HINI[$hIniFile][1])[$i + 4] & ($iST ? "" : ($_HINI[$hIniFile][1])[$i + 5])     ;;Next     Local $sData = __IniGetFileStringData($hIniFile, $iFlags, $_HINI[$hIniFile][1])     Return SetError(0, $_HINI[$hIniFile][3], $sData) EndFunc   ;==>_IniGetFileStringData ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniClearCache ; Description ...: Clear INI File Processing Functions Cache ; Syntax.........: _IniClearCache(ByRef $aIniFile) ; Parameters ....: $hIniFile     - Handle to the INI file to query "see _IniOpenFileEx()" ; Return values .: None ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: This function is useful to Run after _IniRea*Ex Funcion's, only in the case when in the INI file are duplicated function ;                   and if the flag $INI_MERGE or $INI_NOOCCURRENCE is not set\used, because in this case the _IniReadEx\_IniReadSectionEx saves ;                   in cache the Function's\String\Data to be fast during the loop ect ect, so only in cases when you Get\Read Occurrence Function ;                   and the flag $INI_MERGE or $INI_NOOCCURRENCE is not set\used ;                   All other function as _IniDeleteEx or _IniWrite*Ex use by Default or Force the use of $INI_MERGE flag ;                   So in 99.9% of cases you do not Need\Have to run _IniClearCache(), because the INI File Processing Functions Work's only By Reference ; =============================================================================================================================== Func _IniClearCache(ByRef $hIniFile)     If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")     $_HINI[$hIniFile][6] = ""     __IniSaveCache($hIniFile, $_HINI[$hIniFile][6], $INI_NULL_REF, $_HINI[$hIniFile][6], $_HINI[$hIniFile][6], $_HINI[$hIniFile][1])     Return 0 EndFunc   ;==>_IniClearCache ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniFileWrite ; Description ...: Write a Ini File ; Syntax.........: _IniFileWriteEx(ByRef $hIniFile[, $iFlags[, $sFilePath[, $iFileEncoding]]]) ; Parameters ....: $hIniFile      - Handle to the INI file to query "see _IniOpenFileEx()" ;                   $iFlags        - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ;                  |$INI_STRIPLEADING (1)     - strip leading white space Section ;                  |$INI_STRIPTRAILING (2)    - trailing white space Section ;                  |$INI_NOWRITEREADONLY (16) - Do not Write\Replace\Edit the ReadOnly file (Default Write\Replace\Edit the ReadOnly files) ;                   $sFilePath     - Optional, use alternative FilePath, By Default always is used (Default) PathFile ;                   $iFileEncoding - Optional, use alternative FileEncoding, By Default always is used (Default) FileEncoding ; Return values .: Returns a 0 ;                  @Error  - 0 = No error. ;                  |1  =  Invalid IniHandle. ;                  |9  =  Invalid FilePath ;                  |10 = A file may fail to open due to access rights or attributes. ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniFileWriteEx(ByRef $hIniFile, $iFlags = 0, $sFilePath = Default, $iFileEncoding = Default)     If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")     If $_HINI[$hIniFile][2] = "FileQueue" And Not $sFilePath Then Return SetError(9, 0, "")     If $sFilePath = Default Then $sFilePath = $_HINI[$hIniFile][2]     If $iFileEncoding = Default Then $iFileEncoding = $_HINI[$hIniFile][3] + 10     ;;Local $hFileOpen, $iSL = BitAND($iFlags, $INI_STRIPLEADING), $iST = BitAND($iFlags, $INI_STRIPTRAILING)     ;;$hFileOpen = FileOpen($_HINI[$hIniFile][2], $_HINI[$hIniFile][3] + 10)     ;; ;; Check if file opened for writing OK     ;;If $hFileOpen = -1 Then     ;;    Return SetError(10, 0, 0)     ;;EndIf     ;;FileWrite($hFileOpen, ($iSL ? "" : ($_HINI[$hIniFile][1])[3]) & ($_HINI[$hIniFile][1])[4] & ($iST ? "" : ($_HINI[$hIniFile][1])[5]))     ;;For $i = 6 To ($_HINI[$hIniFile][1])[0] Step 6     ;;    FileWrite($hFileOpen, ($_HINI[$hIniFile][1])[$i] & ($_HINI[$hIniFile][1])[$i + 1] & ($_HINI[$hIniFile][1])[$i + 2] & ($iSL ? "" : ($_HINI[$hIniFile][1])[$i + 3]) & ($_HINI[$hIniFile][1])[$i + 4] & ($iST ? "" : ($_HINI[$hIniFile][1])[$i + 5]))     ;;Next     ;;FileClose($hFileOpen)     __IniFileWriteEx($hIniFile, $iFlags, $sFilePath, $iFileEncoding, $_HINI[$hIniFile][1])     Return SetError(@Error, @Extended, 0) EndFunc   ;==>_IniFileWriteEx ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __IniReadSectionEx ; Description ...: Support Function for _IniReadSectionEx ; Syntax.........: __IniReadSectionEx(ByRef $aIniFile, ByRef $sSectionName, ByRef $iFlags) ; Parameters ....: See _IniReadSectionEx() ; Return values .: See _IniReadSectionEx() ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: This function is used internally by _IniReadSectionEx ; =============================================================================================================================== Func __IniReadSectionEx(ByRef $hIniFile, ByRef $sSectionName, ByRef $iFlags, ByRef $aIniFile)     ;;;;If Not $sSectionName Then Return SetError(2, 0, "")    ;Invalid Section Name     If StringInStr($sSectionName, "\E", 1) Then $sSectionName = StringReplace($sSectionName, "\E", "\e", 0, 1)     Local $sSectionData, $aSectionName, $iSectionName = 1     $aSectionName = StringRegExp($_HINI[$hIniFile][5], "\n(?is)\Q" & $sSectionName & "\E\r([^\n]+)", 3)     If @Error Then         If BitAND($iFlags, $INI_NOCREATE_REMOVE_DELETE) Then Return SetError(3, 0, "")         $aIniFile[0] += 6         Redim $aIniFile[$aIniFile[0] + 1]         $aIniFile[$aIniFile[0] - 5] = "["         $aIniFile[$aIniFile[0] - 4] = $sSectionName         $aIniFile[$aIniFile[0] - 3] = "]" & @CRLF         $_HINI[$hIniFile][4] += 1         $_HINI[$hIniFile][5] &= @LF & $sSectionName & @CR & ($aIniFile[0] - 4)         $_HINI[$hIniFile][6] = $aIniFile[0] - 1     Else         $_HINI[$hIniFile][6] = $aSectionName[0] + 3         $iSectionName = UBound($aSectionName)         ;;If BitAND($iFlags, $INI_STRIPLEADTRAILING) = $INI_STRIPLEADTRAILING Then    ;; BitOR($INI_STRIPLEADING,  $INI_STRIPTRAILING)         ;;    $sSectionData = $aIniFile[$aSectionName[0] + 3]         ;;ElseIf BitAND($iFlags, $INI_STRIPLEADING) Then         ;;    $sSectionData = $aIniFile[$aSectionName[0] + 3] & $aIniFile[$aSectionName[0] + 4]         ;;ElseIf BitAND($iFlags, $INI_STRIPTRAILING) Then         ;;    $sSectionData = $aIniFile[$aSectionName[0] + 2] & $aIniFile[$aSectionName[0] + 3]         ;;Else         ;;    $sSectionData = $aIniFile[$aSectionName[0] + 2] & $aIniFile[$aSectionName[0] + 3] & $aIniFile[$aSectionName[0] + 4]         ;;EndIf         If Not BitAND($iFlags, $INI_NOOCCURRENCE) And $iSectionName > 1 Then             $sSectionData = $aIniFile[$aSectionName[0] + 3]             For $i = 1 To $iSectionName - 1                 $sSectionData &= $aIniFile[$aSectionName[$i] + 3]                 If BitAND($iFlags, $INI_MERGE) Then                     For $y = $aSectionName[$i] - 1 To $aSectionName[$i] + 4                         $aIniFile[$y] = ""                     Next                     $_HINI[$hIniFile][5] = StringRegExpReplace($_HINI[$hIniFile][5], '\n(?is)\Q' & $sSectionName & '\E\r' & $aSectionName[$i], "")                 EndIf             Next             If BitAND($iFlags, $INI_MERGE) Then $aIniFile[$aSectionName[0] + 3] = $sSectionData         EndIf     EndIf     __IniSaveCache($hIniFile, $sSectionData, $sSectionName, $iFlags, $iSectionName, $aIniFile)     Return $iSectionName    ;SetError(Not $iSectionName, $iSectionName, $sSectionData) EndFunc   ;==>__IniReadSectionEx ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __IniWriteSectionEx ; Description ...: Support Function for _IniWriteSectionEx ; Syntax.........: __IniWriteSectionEx(ByRef $hIniFile, ByRef $sSectionName, ByRef $aKeyValue, ByRef $iFlags, ByRef $scKeyName, ByRef $aIniFile) ; Parameters ....: See _IniWriteSectionEx() ; Return values .: See _IniWriteSectionEx() ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: This function is used internally by _IniWriteSectionEx ; =============================================================================================================================== Func __IniWriteSectionEx(ByRef $hIniFile, ByRef $sSectionName, ByRef $aKeyValue, ByRef $iFlags, ByRef $scKeyName, ByRef $aIniFile)     If BitAND($iFlags, $INI_REMOVE) Then         Local $iaSectionName, $aSectionName = StringRegExp($_HINI[$hIniFile][5], '\n(?is)\Q' & $sSectionName & '\E\r([^\n]+)', 3)         If @Error Then Return SetError(3, 0, 0)         $iaSectionName = UBound($aSectionName) - 1         If BitAND($iFlags, $INI_NOOCCURRENCE) Then $iaSectionName = 0         For $i = 0 To $iaSectionName             For $y = $aSectionName[$i] - 1 To $aSectionName[$i] + 4                 $aIniFile[$y] = ""             Next         Next         $_HINI[$hIniFile][4] -= $iaSectionName + 1         $_HINI[$hIniFile][5] = StringRegExpReplace($_HINI[$hIniFile][5], '\n(?is)\Q' & $sSectionName & '\E\r[^\r\n]+', "", Int($iaSectionName = 0))         Return SetError(0, @Extended, 0)     ElseIf BitAND($iFlags, $INI_RENAME) Then         Local $iaSectionName, $aSectionName = StringRegExp($_HINI[$hIniFile][5], '\n(?is)\Q' & $sSectionName & '\E\r([^\n]+)', 3)         If @Error Then Return SetError(3, 0, 0)         $iaSectionName = UBound($aSectionName) - 1         If BitAND($iFlags, $INI_NOOCCURRENCE) Then $iaSectionName = 0         ;; $aKeyValue is New Section Name         For $i = 0 To $iaSectionName             $aIniFile[$aSectionName[$i]] = $aKeyValue         Next         $_HINI[$hIniFile][5] = StringRegExpReplace($_HINI[$hIniFile][5], '\n\K(?is)\Q' & $sSectionName & '\E(?=\r)', StringReplace(StringReplace($aKeyValue, "\", "\\", 0, 1), "\E", "\e", 0, 1), Int($iaSectionName = 0))         Return SetError(0, @Extended, 0)     Else         Local $iSN = $_HINI[$hIniFile][10]         If BitAND($iFlags, $INI_OVERWRITEALL_APPENDDATA) Then             If BitAND($iFlags, $INI_OVERWRITEALL) Then $aIniFile[$iSN] = ""             If BitAND($iFlags, $INI_STRIPLEADING) Then $aIniFile[$iSN - 1] = ""             If BitAND($iFlags, $INI_STRIPTRAILING) Then $aIniFile[$iSN + 1] = ""             If IsArray($aKeyValue) Then                 For $i = 1 To $aKeyValue[0][0]                     $aIniFile[$iSN] &= $aKeyValue[$i][2] & @CRLF                 Next             Else                 ;;    KeyName\Value\Text Data will be writte exactly as in $aKeyValue (without Edit\Formatting ect ect)                 $aIniFile[$iSN] &= $aKeyValue & (StringRight($aKeyValue, 1) = @LF ? "" : @CRLF)             EndIf             Return SetError(0, 1, 0)         Else             Local $asKeyValue, $iKeyValue = 0, $sKNPattern, $iOffSet = StringInStr($aIniFile[$iSN], @LF, 1)             For $i = 1 To $aKeyValue[0][0]                 $sKNPattern = '\n[\h\f\xb\x0]*(?i)(?>\Q"' & $aKeyValue[$i][0] & '"\E|\Q' & $aKeyValue[$i][0] & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*'                 If StringRegExp(StringLeft($aIniFile[$iSN], $iOffSet), '^(?i)[\h\f\xb\x0]*(?>\Q"' & $aKeyValue[$i][0] & '"\E|\Q' & $aKeyValue[$i][0] & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*') Then                     If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $aIniFile[$iSN] = StringRegExpReplace($aIniFile[$iSN], $sKNPattern, "")                     If BitAND($iFlags, $INI_DELETE) Then                         $aIniFile[$iSN] = StringTrimLeft($aIniFile[$iSN], $iOffSet)                     ElseIf Not BitAND($iFlags, $INI_NOOVERWRITE) Then                         $aIniFile[$iSN] = $aKeyValue[$i][2] & @CRLF & StringTrimLeft($aIniFile[$iSN], $iOffSet)                     EndIf                 ElseIf BitAND($iFlags, $INI_DELETE) Then                     $aIniFile[$iSN] = StringRegExpReplace($aIniFile[$iSN], $sKNPattern, "", (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? 1 : 0))                 Else                     $asKeyValue = StringRegExp($aIniFile[$iSN], $sKNPattern, 1)                     $iOffSet = @Extended - 1                     If Not @Error Then                         If BitAND($iFlags, $INI_NOOVERWRITE) Then                             If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $aIniFile[$iSN] = StringLeft($aIniFile[$iSN], $iOffSet) & StringRegExpReplace(StringTrimLeft($aIniFile[$iSN], $iOffSet), $sKNPattern, "")                         Else                             $aIniFile[$iSN] = StringLeft($aIniFile[$iSN], $iOffSet + 1 - StringLen($asKeyValue[0])) & $aKeyValue[$i][2] & @CR & (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? StringTrimLeft($aIniFile[$iSN], $iOffSet) : StringRegExpReplace(StringTrimLeft($aIniFile[$iSN], $iOffSet), $sKNPattern, ""))                         EndIf                     ElseIf Not BitAND($iFlags, $INI_REPLACEONLY) Then                         $aIniFile[$iSN] &= $aKeyValue[$i][2] & @CRLF                     Else                         $iKeyValue -= 1                     EndIf                 EndIf                 $iKeyValue += 1             Next             Return SetError(0, $iKeyValue, 0)         EndIf     EndIf EndFunc ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __IniFileWriteEx ; Description ...: Support Function for _IniFileWriteEx ; Syntax.........: __IniFileWriteEx(ByRef $hIniFile, ByRef $iFlags, ByRef $sFilePath, ByRef $iFileEncoding, ByRef $aIniFile) ; Parameters ....: See _IniFileWriteEx() ; Return values .: See _IniFileWriteEx() ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: This function is used internally by _IniFileWriteEx ; =============================================================================================================================== Func __IniFileWriteEx(ByRef $hIniFile, ByRef $iFlags, ByRef $sFilePath, ByRef $iFileEncoding, ByRef $aIniFile)     Local $hFileOpen, $iSL = BitAND($iFlags, $INI_STRIPLEADING), $iST = BitAND($iFlags, $INI_STRIPTRAILING), $iReadOnly = 0     $hFileOpen = FileOpen($sFilePath, $iFileEncoding)     ; Check if file opened for writing OK     If $hFileOpen = -1 Then         If Not BitAND($iFlags, $INI_NOWRITEREADONLY) And StringInStr(FileGetAttrib($sFilePath), "R") Then             FileSetAttrib($sFilePath, "-R")             $iReadOnly = 1             $hFileOpen = FileOpen($sFilePath, $iFileEncoding)             If $hFileOpen = -1 Then Return SetError(10, 0, 0)         Else             Return SetError(10, 0, 0)         EndIf     EndIf     FileWrite($hFileOpen, ($iSL ? "" : $aIniFile[3]) & $aIniFile[4] & ($iST ? "" : $aIniFile[5]))     For $i = 6 To $aIniFile[0] Step 6         FileWrite($hFileOpen, $aIniFile[$i] & $aIniFile[$i + 1] & $aIniFile[$i + 2] & ($iSL ? "" : $aIniFile[$i + 3]) & $aIniFile[$i + 4] & ($iST ? "" : $aIniFile[$i + 5]))     Next     FileClose($hFileOpen)     If $iReadOnly Then FileSetAttrib($sFilePath, "+R")     Return 0 EndFunc   ;==>__IniFileWriteEx ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __IniGetFileStringData ; Description ...: Support Function for _IniGetFileStringData ; Syntax.........: __IniGetFileStringData(ByRef $hIniFile, ByRef $iFlags, ByRef $aIniFile) ; Parameters ....: See _IniGetFileStringData() ; Return values .: See _IniGetFileStringData() ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: This function is used internally by _IniGetFileStringData ; =============================================================================================================================== Func __IniGetFileStringData(ByRef $hIniFile, ByRef $iFlags, ByRef $aIniFile)     Local $sData, $iSL = BitAND($iFlags, $INI_STRIPLEADING), $iST = BitAND($iFlags, $INI_STRIPTRAILING)     Local $sData = ($iSL ? "" : $aIniFile[3]) & $aIniFile[4] & ($iST ? "" : $aIniFile[5])     For $i = 6 To $aIniFile[0] Step 6         $sData &= $aIniFile[$i] & $aIniFile[$i + 1] & $aIniFile[$i + 2] & ($iSL ? "" : $aIniFile[$i + 3]) & $aIniFile[$i + 4] & ($iST ? "" : $aIniFile[$i + 5])     Next     Return $sData EndFunc   ;==>__IniGetFileStringData ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __IniSaveCache ; Description ...: Save in Cache last Read Section ; Syntax.........: __IniSaveCache(ByRef $hIniFile, ByRef $sSectionData, ByRef $sSectionName, ByRef $iFlags, ByRef $iSectionName, ByRef $aIniFile) ; Parameters ....: $hIniFile     - Handle to the INI file to query "see _IniOpenFileEx()" ;                  $sSectionData - Section Strings text/data ;                  $sSectionName - Section Name ;                  $iFlags       - Section Flags ;                  $iSectionName - Number of SectionName in INI File ;                  $aIniFile     - Array of INI File ; Return values .: None ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: This function is Internal Only ; =============================================================================================================================== Func __IniSaveCache(ByRef $hIniFile, ByRef $sSectionData, ByRef $sSectionName, ByRef $iFlags, ByRef $iSectionName, ByRef $aIniFile)     $_HINI[$hIniFile][7] = $sSectionName     $_HINI[$hIniFile][8] = (BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) = $INI_MERGE) ? 1 : $iSectionName     $_HINI[$hIniFile][9] = $iFlags     If $iSectionName > 1 And Not BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) Then         $aIniFile[1] = $sSectionData         $_HINI[$hIniFile][10] = 1     Else         $aIniFile[1] = ""         $_HINI[$hIniFile][10] = $_HINI[$hIniFile][6]     EndIf     Return 0 EndFunc   ;==>__IniSaveCache ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __GetSeparatorCharacter ; Description ...: Get Separator Character (non present character) ; Syntax.........: __GetSeparatorCharacter(ByRef $sData) ; Parameters ....: $sData  - INI String\Text Data ; Return values .: None ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: For Internal Use Only ; =============================================================================================================================== Func __GetSeparatorCharacter(ByRef $sData)     If Not StringInStr($sData, ChrW(8232), 1) Then Return ChrW(8232)     If Not StringInStr($sData, ChrW(8233), 1) Then Return ChrW(8233)     For $i = 1 To 31         If $i > 8 And $i < 14 Then ContinueLoop         If Not StringInStr($sData, Chr($i), 1) Then Return Chr($i)     Next     $sData = StringRegExpReplace($sData, '\r\n?', @LF)     Return @CR EndFunc   ;==>__GetSeparatorCharacter example
    #include <IniEx.au3> #include <Array.au3> Local $sData = @CRLF, $aData, $iData, $iTimerDiff, $hIniFile FileDelete(@DesktopDir & "\Test.ini") For $i = 1 To 10 $sData &= "[SectionName_" & $i & "]" & @CRLF For $y = 1 to 100000 $sData &= "KeyName" & $y & " = Value" & $y & @CRLF Next Next FileWrite(@DesktopDir & "\Test.ini", $sData)    ;25 MB - 1.000.000 Line, Key-Value $sData = "" $iTimerDiff = TimerInit() ;;_IniOpenFileEx() $hIniFile = _IniOpenFileEx(@DesktopDir & "\Test.ini") If @Error Then ConsoleWrite("Error - " & @Error & @LF) Exit EndIf $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("_IniOpenFileEx TimerDiff - " & $iTimerDiff & @LF) $iTimerDiff = TimerInit() ;;_IniGetSectionNumberEx() $iData = _IniGetSectionNumberEx($hIniFile) If @Error Then ConsoleWrite("Error - " & @Error & @LF) Exit EndIf $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniGetSectionNumberEx TimerDiff - " & $iTimerDiff & @LF) ConsoleWrite("SectionNumber - " & $iData & @LF & @LF) $iTimerDiff = TimerInit() ;;_IniRenameSectionEx() _IniRenameSectionEx($hIniFile, "SectionName_10", "SectionName_111") If @Error Then ConsoleWrite("Error - " & @Error & @LF) Exit EndIf $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniRenameSectionEx TimerDiff - " & $iTimerDiff & @LF & @LF) $iTimerDiff = TimerInit() ;;_IniReadSectionNamesEx() $aData = _IniReadSectionNamesEx($hIniFile) If @Error Then ConsoleWrite("Error - " & @Error & @LF) Exit EndIf $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniReadSectionNamesEx TimerDiff - " & $iTimerDiff & @LF & @LF) _ArrayDisplay($aData) $iTimerDiff = TimerInit() ;;_IniReadSectionEx() $sData = _IniReadSectionEx($hIniFile, "SectionName_8") $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniReadSectionEx TimerDiff - " & $iTimerDiff & @LF & @LF) ;;ConsoleWrite($sData & @LF & @LF) ;;MsgBox(0, "SectionName_8", $sData) $iTimerDiff = TimerInit() ;;_IniReadSectionEx() $aData = _IniReadSectionEx($hIniFile, "SectionName_8", $INI_2DARRAYFIELD) ;$INI_NOOCCURRENCE + $INI_MERGE + $INI_2DARRAYFIELD $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniReadSectionEx TimerDiff - " & $iTimerDiff & @LF & @LF) _ArrayDisplay($aData, "IniReadSectionEx") $iTimerDiff = TimerInit() ;;_IniReadEx() $sData = _IniReadEx($hIniFile, "SectionName_8", "KeyName99980") $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniReadEx TimerDiff - " & $iTimerDiff& @LF) ConsoleWrite($sData & @LF & @LF) $iTimerDiff = TimerInit() ;;_IniReadEx() $aData = _IniReadEx($hIniFile, "SectionName_8", "KeyName99988", "Default Return", $INI_ARRAYDATA) ;$INI_NOOCCURRENCE + $INI_MERGE + $INI_ARRAYDATA $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniReadEx TimerDiff - " & $iTimerDiff & @LF) ConsoleWrite($aData[1] & @LF & @LF) _ArrayDisplay($aData, "IniReadEx") $iTimerDiff = TimerInit() ;;_IniDeleteEx() _IniDeleteEx($hIniFile, "SectionName_8", "KeyName99988") ;$INI_IGNOREDUPLICATE + $INI_NOOCCURRENCE + $INI_REMOVE $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniDeleteEx TimerDiff - " & $iTimerDiff & @LF & @LF) $iTimerDiff = TimerInit() ;;_IniWriteSectionEx() _IniWriteSectionEx($hIniFile, "SectionName_8", "KeyNameX = ValueX") ; $INI_NOOCCURRENCE + $INI_IGNOREDUPLICATE + $INI_MERGE + $INI_REMOVE + $INI_OVERWRITEALL + $INI_APPENDDATA $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniWriteSectionEx TimerDiff - " & $iTimerDiff & @LF & @LF) ConsoleWrite(_IniReadEx($hIniFile, "SectionName_8", "KeyNameX") & @LF) $iTimerDiff = TimerInit() For $i = 1 To 5     _IniWriteSectionEx($hIniFile, "SectionName_8", "KeyNameX" & $i & " =  ValueX" & $i) Next For $i = 6 To 10     _IniWriteEx($hIniFile, "SectionName_8", "KeyNameX" & $i, "ValueX" & $i) Next $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniWrite*Ex TimerDiff - " & $iTimerDiff & @LF) $iTimerDiff = TimerInit() ;;_IniReadEx() For $i = 1 To 10 ConsoleWrite(_IniReadEx($hIniFile, "SectionName_8", "KeyNameX" & $i) & @LF) Next $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniReadEx TimerDiff - " & $iTimerDiff & @LF) _IniCloseFileEx($hIniFile) Exit ;~ >Running:(3.3.11.3):C:\Program Files (x86)\AutoIt3\Beta\autoit3.exe "C:\Users\DXRW4E\Desktop\New AutoIt v3 Script.au3"     ;~ --> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop ;~ _IniOpenFileEx TimerDiff - 2656.48548057389 ;~ IniGetSectionNumberEx TimerDiff - 0.0343594296492653 ;~ SectionNumber - 10 ;~   ;~ IniRenameSectionEx TimerDiff - 0.204971769976651 ;~   ;~ IniReadSectionNamesEx TimerDiff - 0.0584505240010489 ;~   ;~ IniReadSectionEx TimerDiff - 6.80316707055452 ;~   ;~ IniReadSectionEx TimerDiff - 1831.04639075913 ;~   ;~ IniReadEx TimerDiff - 24.1380917325683 ;~ Value99980 ;~   ;~ IniReadEx TimerDiff - 111.67841469541 ;~ Value99988 ;~   ;~ IniDeleteEx TimerDiff - 43.9488700091941 ;~   ;~ IniWriteSectionEx TimerDiff - 28.2560891228314 ;~   ;~ ValueX ;~ IniWrite*Ex TimerDiff - 261.353224415258 ;~ ValueX1 ;~ ValueX2 ;~ ValueX3 ;~ ValueX4 ;~ ValueX5 ;~ ValueX6 ;~ ValueX7 ;~ ValueX8 ;~ ValueX9 ;~ ValueX10 ;~ IniReadEx TimerDiff - 261.622965684803 ;~ +>00:07:21 AutoIt3.exe ended.rc:0 ;~ >Exit code: 0    Time: 5.914 ; $INI_OPEN_FILEQUEUE (268435456) - Open INI file from Memory\Variable, $sFilePath must contain String Text Data of INI file $hIniFile = _IniOpenFileEx(@DesktopDir & "\Test.ini") ;ect ect ect ;or $hIniFile = _IniOpenFileEx($sData, $INI_OPEN_FILEQUEUE) ;ect ect ect ;Or direct mode, without load ini or using handles ; $sSectionName - The name of the section containing the Key\Value, This parameter can be NULL (use the $NULL_REF to set NULL this parameter) ; If $sSectionName is NULL, $hIniFile must be contain Section String\Key\Value\Data ;; _IniDeleteEx($hIniFile, $sSectionName, $sKeyName) _IniDeleteEx($sData, $NULL_REF, $sKeyName) ;$NULL_REF = NULL ;; _IniReadEx($hIniFile, $sSectionName, $sKeyName) _IniDeleteEx($sData, $NULL_REF, $sKeyName) ;$NULL_REF = NULL ;; _IniReadSectionEx($hIniFile, $sSectionName, $sKeyName) _IniReadSectionEx($sData, $NULL_REF, $sKeyName) ;$NULL_REF = NULL ;; _IniWriteEx($hIniFile, $sSectionName, $sKeyName, $sValue) _IniWriteEx($sData, $NULL_REF, $sKeyName, $sValue) ;$NULL_REF = NULL ;;ect ect ect So for all other functions  
    IniEx.au3
  2. Thanks
    DXRW4E got a reaction from Professor_Bernd in Run as administrator ?   
    maybe this will help you

    If Not IsAdmin() Then ShellExecute(@AutoItExe, "", "", "runas") ProcessClose(@AutoItPID) Exit Else MsgBox(64, "1", "IsAdmin() = " & IsAdmin()) RunWait(@WindowsDir & "\regedit.exe", @WindowsDir, @SW_MAXIMIZE) EndIf MsgBox(64, "2", "IsAdmin() = " & IsAdmin() & @LF & $CmdLineRaw) ; ShellExecute(@AutoItExe, "ect ect ect", "", "runas") RunWait(@WindowsDir & "\regedit.exe", @WindowsDir, @SW_MAXIMIZE)
    Ciao.
  3. Like
    DXRW4E got a reaction from Fr33b0w in _FileReadToArray() fails. Most of the time   
    You will need\should use _FileReadToArrayEx ,  It must be faster and it will have to do exactly All what you want them to do
    #include <Array.au3> #include "_FileReadToArrayEx.au3" Local $aArray $fTimerDiff = TimerInit() $aArray = _FileReadToArrayEx(@DesktopDir & '\ZZj2_Test.Won.Two.csv', ",", $FRTA_ARRAYFIELD + 0 + $FRTA_STRIPALL + $FRTA_CHECKSINGEQUOTE) ;$aArray = _FileReadToArrayEx(@DesktopDir & '\Test.inf', ",", 0 + 1 + 16 + 12) $fTimerDiff = TimerDiff($fTimerDiff) ConsoleWrite("_FileReadToArrayEx() : " & $fTimerDiff & @CRLF) _ArrayDisplay($aArray) _ArrayDisplay(($aArray[1])) _ArrayDisplay(($aArray[6])) #include <Array.au3> #include "_FileReadToArrayEx.au3" Local $aArray, $sData $aArray = _FileReadToArrayEx(@DesktopDir & '\ZZj2_Test.Won.Two.csv', ",", BitOR($FRTA_NOCOUNT, $FRTA_ARRAYFIELD, $FRTA_STRIPALL)) If Not @Error Then ;;Local $iaArray = UBound($aArray) - 1 ; or $iaArray = @Extended For $i = 0 To UBound($aArray) - 1 For $y = 0 To UBound($aArray[$i]) - 1 $sData &= ($aArray[$i])[$y] & "," Next $sData = StringTrimRight($sData, 1) & @CRLF Next EndIf ConsoleWrite($sData & @LF) ;Or $aArray = _FileReadToArrayEx(@DesktopDir & '\ZZj2_Test.Won.Two.csv', ",", BitOR($FRTA_ARRAYFIELD, $FRTA_STRIPALL, $FRTA_CHECKSINGEQUOTE)) If Not @Error Then ;;Local $iaArray = UBound($aArray) - 1 ; or $iaArray = @Extended For $i = 1 To ($aArray)[0] For $y = 1 To ($aArray[$i])[0] $sData &= ($aArray[$i])[$y] & "," Next $sData = StringTrimRight($sData, 1) & @CRLF Next EndIf ConsoleWrite($sData & @LF) Ciao.
  4. Like
    DXRW4E got a reaction from Skysnake in Run as administrator ?   
    maybe this will help you

    If Not IsAdmin() Then ShellExecute(@AutoItExe, "", "", "runas") ProcessClose(@AutoItPID) Exit Else MsgBox(64, "1", "IsAdmin() = " & IsAdmin()) RunWait(@WindowsDir & "\regedit.exe", @WindowsDir, @SW_MAXIMIZE) EndIf MsgBox(64, "2", "IsAdmin() = " & IsAdmin() & @LF & $CmdLineRaw) ; ShellExecute(@AutoItExe, "ect ect ect", "", "runas") RunWait(@WindowsDir & "\regedit.exe", @WindowsDir, @SW_MAXIMIZE)
    Ciao.
  5. Like
    DXRW4E got a reaction from Taz77 in CRC32, MD4, MD5, SHA1 -for files   
    First thanks for this code i used for a long time this code successfully in my Tool, but unfortunately it has limits, if you put them large files (such as an ISO 5GB) crashes or returns Wrong Hash, in web there are thousands of examples and threads, when everything very simple ehhhh https://msdn.microsoft.com/en-us/library/windows/desktop/aa382380(v=vs.85).aspx
     

    If Not IsDeclared("arDllCall") Then Global Static $arDllCall Global Const $hKernel32DLL = DllOpen("Kernel32.dll") Global Const $hAdvapi32Dll = DllOpen("AdvApi32.dll") Func _MD5ForFile($sFile) $arDllCall = DllCall($hKernel32DLL, "hwnd", "CreateFileW", "wstr", $sFile, "dword", 0x80000000, "dword", 3, "ptr", 0, "dword", 3, "dword", 0x80, "ptr", 0) If @Error Or $arDllCall[0] = -1 Then Return SetError(1, 0, "") EndIf Local $hFile = $arDllCall[0] $arDllCall = DllCall($hAdvapi32Dll, "int", "CryptAcquireContextW", "ULONG_PTR*", 0, "ptr", 0, "ptr", 0, "dword", 1, "dword", 0xF0000000) ; CRYPT_VERIFYCONTEXT If @Error Or Not $arDllCall[0] Then DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(3, 0, "") EndIf Local $hContext = $arDllCall[1] $arDllCall = DllCall($hAdvapi32Dll, "int", "CryptCreateHash", "ULONG_PTR", $hContext, "dword", 0x00008003, "ptr", 0, "dword", 0, "ULONG_PTR*", 0) If @Error Or Not $arDllCall[0] Then DllCall($hAdvapi32Dll, "int", "CryptReleaseContext", "ULONG_PTR", $hContext, "dword", 0) DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(3, 0, "") EndIf Local $hHashMD5 = $arDllCall[5], $bSucceeded = 1, $Buffer = DllStructCreate("byte[65535]") While $bSucceeded $arDllCall = DllCall($hKernel32DLL, "BOOL", "ReadFile", "HANDLE", $hFile, "ptr", DllStructGetPtr($Buffer), "dword", 65535, "dword*", 0, "ptr", Null) If @Error Or $arDllCall[4] = 0 Then ExitLoop $bSucceeded = $arDllCall[0] $arDllCall = DllCall($hAdvapi32Dll, "int", "CryptHashData", "ULONG_PTR", $hHashMD5, "struct*", $Buffer, "dword", $arDllCall[4], "dword", 0) If @Error Or Not $arDllCall[0] Then DllCall($hAdvapi32Dll, "int", "CryptDestroyHash", "ULONG_PTR", $hHashMD5) DllCall($hAdvapi32Dll, "int", "CryptReleaseContext", "ULONG_PTR", $hContext, "dword", 0) DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(4, 0, "") EndIf WEnd If Not $bSucceeded Then DllCall($hAdvapi32Dll, "int", "CryptDestroyHash", "ULONG_PTR", $hHashMD5) DllCall($hAdvapi32Dll, "int", "CryptReleaseContext", "ULONG_PTR", $hContext, "dword", 0) DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(5, 0, "") EndIf Local $tOutMD5 = DllStructCreate("byte[16]") $arDllCall = DllCall($hAdvapi32Dll, "int", "CryptGetHashParam", "ULONG_PTR", $hHashMD5, "dword", 2, "ptr", DllStructGetPtr($tOutMD5), "dword*", 16, "dword", 0) If @Error Or Not $arDllCall[0] Then DllCall($hAdvapi32Dll, "int", "CryptDestroyHash", "ULONG_PTR", $hHashMD5) DllCall($hAdvapi32Dll, "int", "CryptReleaseContext", "ULONG_PTR", $hContext, "dword", 0) DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(6, 0, "") EndIf Local $sSHA1 = Hex(DllStructGetData($tOutMD5, 1)) DllCall($hAdvapi32Dll, "int", "CryptDestroyHash", "ULONG_PTR", $hHashMD5) DllCall($hAdvapi32Dll, "int", "CryptReleaseContext", "ULONG_PTR", $hContext, "dword", 0) DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(0, 0, $sSHA1) EndFunc Func _SHA1ForFile($sFile) $arDllCall = DllCall($hKernel32DLL, "hwnd", "CreateFileW", "wstr", $sFile, "dword", 0x80000000, "dword", 3, "ptr", 0, "dword", 3, "dword", 0x80, "ptr", 0) If @Error Or $arDllCall[0] = -1 Then Return SetError(1, 0, "") EndIf Local $hFile = $arDllCall[0] $arDllCall = DllCall($hAdvapi32Dll, "int", "CryptAcquireContextW", "ULONG_PTR*", 0, "ptr", 0, "ptr", 0, "dword", 1, "dword", 0xF0000000) ; CRYPT_VERIFYCONTEXT If @Error Or Not $arDllCall[0] Then DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(2, 0, "") EndIf Local $hContext = $arDllCall[1] $arDllCall = DllCall($hAdvapi32Dll, "int", "CryptCreateHash", "ULONG_PTR", $hContext, "dword", 0x00008004, "ptr", 0, "dword", 0, "ULONG_PTR*", 0) If @Error Or Not $arDllCall[0] Then DllCall($hAdvapi32Dll, "int", "CryptReleaseContext", "ULONG_PTR", $hContext, "dword", 0) DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(3, 0, "") EndIf Local $hHashSHA1 = $arDllCall[5], $bSucceeded = 1, $Buffer = DllStructCreate("byte[65535]") While $bSucceeded $arDllCall = DllCall($hKernel32DLL, "BOOL", "ReadFile", "HANDLE", $hFile, "ptr", DllStructGetPtr($Buffer), "dword", 65535, "dword*", 0, "ptr", Null) If @Error Or $arDllCall[4] = 0 Then ExitLoop $bSucceeded = $arDllCall[0] $arDllCall = DllCall($hAdvapi32Dll, "int", "CryptHashData", "ULONG_PTR", $hHashSHA1, "struct*", $Buffer, "dword", $arDllCall[4], "dword", 0) If @Error Or Not $arDllCall[0] Then DllCall($hAdvapi32Dll, "int", "CryptDestroyHash", "ULONG_PTR", $hHashSHA1) DllCall($hAdvapi32Dll, "int", "CryptReleaseContext", "ULONG_PTR", $hContext, "dword", 0) DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(4, 0, "") EndIf WEnd If Not $bSucceeded Then DllCall($hAdvapi32Dll, "int", "CryptDestroyHash", "ULONG_PTR", $hHashSHA1) DllCall($hAdvapi32Dll, "int", "CryptReleaseContext", "ULONG_PTR", $hContext, "dword", 0) DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(5, 0, "") EndIf Local $tOutSHA1 = DllStructCreate("byte[20]") $arDllCall = DllCall($hAdvapi32Dll, "int", "CryptGetHashParam", "ULONG_PTR", $hHashSHA1, "dword", 2, "ptr", DllStructGetPtr($tOutSHA1), "dword*", 20, "dword", 0) If @Error Or Not $arDllCall[0] Then DllCall($hAdvapi32Dll, "int", "CryptDestroyHash", "ULONG_PTR", $hHashSHA1) DllCall($hAdvapi32Dll, "int", "CryptReleaseContext", "ULONG_PTR", $hContext, "dword", 0) DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(6, 0, "") EndIf Local $sSHA1 = Hex(DllStructGetData($tOutSHA1, 1)) DllCall($hAdvapi32Dll, "int", "CryptDestroyHash", "ULONG_PTR", $hHashSHA1) DllCall($hAdvapi32Dll, "int", "CryptReleaseContext", "ULONG_PTR", $hContext, "dword", 0) DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(0, 0, $sSHA1) EndFunc
    Ciao a tutti.
  6. Like
    DXRW4E got a reaction from Mugen in CRC32, MD4, MD5, SHA1 -for files   
    First thanks for this code i used for a long time this code successfully in my Tool, but unfortunately it has limits, if you put them large files (such as an ISO 5GB) crashes or returns Wrong Hash, in web there are thousands of examples and threads, when everything very simple ehhhh https://msdn.microsoft.com/en-us/library/windows/desktop/aa382380(v=vs.85).aspx
     

    If Not IsDeclared("arDllCall") Then Global Static $arDllCall Global Const $hKernel32DLL = DllOpen("Kernel32.dll") Global Const $hAdvapi32Dll = DllOpen("AdvApi32.dll") Func _MD5ForFile($sFile) $arDllCall = DllCall($hKernel32DLL, "hwnd", "CreateFileW", "wstr", $sFile, "dword", 0x80000000, "dword", 3, "ptr", 0, "dword", 3, "dword", 0x80, "ptr", 0) If @Error Or $arDllCall[0] = -1 Then Return SetError(1, 0, "") EndIf Local $hFile = $arDllCall[0] $arDllCall = DllCall($hAdvapi32Dll, "int", "CryptAcquireContextW", "ULONG_PTR*", 0, "ptr", 0, "ptr", 0, "dword", 1, "dword", 0xF0000000) ; CRYPT_VERIFYCONTEXT If @Error Or Not $arDllCall[0] Then DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(3, 0, "") EndIf Local $hContext = $arDllCall[1] $arDllCall = DllCall($hAdvapi32Dll, "int", "CryptCreateHash", "ULONG_PTR", $hContext, "dword", 0x00008003, "ptr", 0, "dword", 0, "ULONG_PTR*", 0) If @Error Or Not $arDllCall[0] Then DllCall($hAdvapi32Dll, "int", "CryptReleaseContext", "ULONG_PTR", $hContext, "dword", 0) DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(3, 0, "") EndIf Local $hHashMD5 = $arDllCall[5], $bSucceeded = 1, $Buffer = DllStructCreate("byte[65535]") While $bSucceeded $arDllCall = DllCall($hKernel32DLL, "BOOL", "ReadFile", "HANDLE", $hFile, "ptr", DllStructGetPtr($Buffer), "dword", 65535, "dword*", 0, "ptr", Null) If @Error Or $arDllCall[4] = 0 Then ExitLoop $bSucceeded = $arDllCall[0] $arDllCall = DllCall($hAdvapi32Dll, "int", "CryptHashData", "ULONG_PTR", $hHashMD5, "struct*", $Buffer, "dword", $arDllCall[4], "dword", 0) If @Error Or Not $arDllCall[0] Then DllCall($hAdvapi32Dll, "int", "CryptDestroyHash", "ULONG_PTR", $hHashMD5) DllCall($hAdvapi32Dll, "int", "CryptReleaseContext", "ULONG_PTR", $hContext, "dword", 0) DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(4, 0, "") EndIf WEnd If Not $bSucceeded Then DllCall($hAdvapi32Dll, "int", "CryptDestroyHash", "ULONG_PTR", $hHashMD5) DllCall($hAdvapi32Dll, "int", "CryptReleaseContext", "ULONG_PTR", $hContext, "dword", 0) DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(5, 0, "") EndIf Local $tOutMD5 = DllStructCreate("byte[16]") $arDllCall = DllCall($hAdvapi32Dll, "int", "CryptGetHashParam", "ULONG_PTR", $hHashMD5, "dword", 2, "ptr", DllStructGetPtr($tOutMD5), "dword*", 16, "dword", 0) If @Error Or Not $arDllCall[0] Then DllCall($hAdvapi32Dll, "int", "CryptDestroyHash", "ULONG_PTR", $hHashMD5) DllCall($hAdvapi32Dll, "int", "CryptReleaseContext", "ULONG_PTR", $hContext, "dword", 0) DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(6, 0, "") EndIf Local $sSHA1 = Hex(DllStructGetData($tOutMD5, 1)) DllCall($hAdvapi32Dll, "int", "CryptDestroyHash", "ULONG_PTR", $hHashMD5) DllCall($hAdvapi32Dll, "int", "CryptReleaseContext", "ULONG_PTR", $hContext, "dword", 0) DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(0, 0, $sSHA1) EndFunc Func _SHA1ForFile($sFile) $arDllCall = DllCall($hKernel32DLL, "hwnd", "CreateFileW", "wstr", $sFile, "dword", 0x80000000, "dword", 3, "ptr", 0, "dword", 3, "dword", 0x80, "ptr", 0) If @Error Or $arDllCall[0] = -1 Then Return SetError(1, 0, "") EndIf Local $hFile = $arDllCall[0] $arDllCall = DllCall($hAdvapi32Dll, "int", "CryptAcquireContextW", "ULONG_PTR*", 0, "ptr", 0, "ptr", 0, "dword", 1, "dword", 0xF0000000) ; CRYPT_VERIFYCONTEXT If @Error Or Not $arDllCall[0] Then DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(2, 0, "") EndIf Local $hContext = $arDllCall[1] $arDllCall = DllCall($hAdvapi32Dll, "int", "CryptCreateHash", "ULONG_PTR", $hContext, "dword", 0x00008004, "ptr", 0, "dword", 0, "ULONG_PTR*", 0) If @Error Or Not $arDllCall[0] Then DllCall($hAdvapi32Dll, "int", "CryptReleaseContext", "ULONG_PTR", $hContext, "dword", 0) DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(3, 0, "") EndIf Local $hHashSHA1 = $arDllCall[5], $bSucceeded = 1, $Buffer = DllStructCreate("byte[65535]") While $bSucceeded $arDllCall = DllCall($hKernel32DLL, "BOOL", "ReadFile", "HANDLE", $hFile, "ptr", DllStructGetPtr($Buffer), "dword", 65535, "dword*", 0, "ptr", Null) If @Error Or $arDllCall[4] = 0 Then ExitLoop $bSucceeded = $arDllCall[0] $arDllCall = DllCall($hAdvapi32Dll, "int", "CryptHashData", "ULONG_PTR", $hHashSHA1, "struct*", $Buffer, "dword", $arDllCall[4], "dword", 0) If @Error Or Not $arDllCall[0] Then DllCall($hAdvapi32Dll, "int", "CryptDestroyHash", "ULONG_PTR", $hHashSHA1) DllCall($hAdvapi32Dll, "int", "CryptReleaseContext", "ULONG_PTR", $hContext, "dword", 0) DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(4, 0, "") EndIf WEnd If Not $bSucceeded Then DllCall($hAdvapi32Dll, "int", "CryptDestroyHash", "ULONG_PTR", $hHashSHA1) DllCall($hAdvapi32Dll, "int", "CryptReleaseContext", "ULONG_PTR", $hContext, "dword", 0) DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(5, 0, "") EndIf Local $tOutSHA1 = DllStructCreate("byte[20]") $arDllCall = DllCall($hAdvapi32Dll, "int", "CryptGetHashParam", "ULONG_PTR", $hHashSHA1, "dword", 2, "ptr", DllStructGetPtr($tOutSHA1), "dword*", 20, "dword", 0) If @Error Or Not $arDllCall[0] Then DllCall($hAdvapi32Dll, "int", "CryptDestroyHash", "ULONG_PTR", $hHashSHA1) DllCall($hAdvapi32Dll, "int", "CryptReleaseContext", "ULONG_PTR", $hContext, "dword", 0) DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(6, 0, "") EndIf Local $sSHA1 = Hex(DllStructGetData($tOutSHA1, 1)) DllCall($hAdvapi32Dll, "int", "CryptDestroyHash", "ULONG_PTR", $hHashSHA1) DllCall($hAdvapi32Dll, "int", "CryptReleaseContext", "ULONG_PTR", $hContext, "dword", 0) DllCall($hKernel32DLL, "int", "CloseHandle", "hwnd", $hFile) Return SetError(0, 0, $sSHA1) EndFunc
    Ciao a tutti.
  7. Like
    DXRW4E got a reaction from ahmeddzcom in FileMove And iF File Exists Rename   
    The thing is very complicated because of the file extension (that sometimes does not exist) etc etc, the safe way is _FileExistsEx '?do=embed' frameborder='0' data-embedContent>>

    ; #FUNCTION# ==================================================================================================================== ; Name...........: _FileExistsEx ; Description ...: Get New Files Name ; Syntax.........: _FileExistsEx(ByRef $sFilePath[, $iFileExists]) ; Parameters ....: $sFilePath - The Fullpath file ; $iFileExists - Optional ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _FileExistsEx(ByRef $sFilePath, $iFileExists = 0) While FileExists($sFilePath) $iFileExists += 1 $sFilePath = StringRegExpReplace($sFilePath & " ", "( - \(\d+\))?(\.[^\.\\]*)?(\h)$", " - (" & $iFileExists & ")$2") WEnd EndFunc Local $sFilePath = @DesktopDir & "\FileName1.xxx" _FileExistsEx($sFilePath) ;if the file exists - $sFilePath = @DesktopDir & "\FileName1 (1).xxx" _FileExistsEx($sFilePath, 7) ;if the file exists - $sFilePath = @DesktopDir & "\FileName1 (8).xxx" Ciao.
  8. Like
    DXRW4E got a reaction from Trong in Determining Windows Version? @OSVersion Returns   
    as always need to use the search field in the forum
    Windows 9 has never existed exactly for this reason, there is confusion (problems) between WinNT9 and WinNT95 (at least so said microsoft officially)


    Ciao.
  9. Like
    DXRW4E got a reaction from Trong in IniReadSection: Problem with big INI file   
    Ciao.
  10. Like
    DXRW4E got a reaction from ravkr in Need a few text files with unicode characters   
    I do not do ??, but it does Microsoft
    That is the maximum that can be done in this regard, the IsTextUnicode is a official function microsoft, is the best of the best even if you read on the web there are many complaints, but all notepad or text editor, refer and use the IsTextUnicode, in the official page of IsTextUnicode is everything well explained, microsoft himself says that in one point nothing is 100% suresave, but al notepad or text editor using the IsTextUnicode mod, so in general there some compatibility.
     
    however no one uses the UTF16-BE, both in Windows or C ++ or other (Wide Character are UTF16-LE) so in general with unicode means the UTF16-LE, so the UTF16-LE takes precedence

    Local $hFileOpen = FileOpen(@DesktopDir & "\text.txt", 26) If $hFileOpen = -1 Then ;Error Else FileWrite($hFileOpen, Binary("0x61000067")) FileClose($hFileOpen) EndIfand open the text.txt with notepad2.exe 
    or Windows NotePad


    Ciao.
  11. Like
    DXRW4E got a reaction from mLipok in Location of Temporary Internet Files Directory   
    %userprofile%Local SettingsTemporary Internet Files = DIRID 16416

    Global Const $CSIDL_INTERNET_CACHE = 0x0020 ; dwFlags values for use with SHGetFolderPath ; current value for user, verify it exists Global Const $SHGFP_TYPE_CURRENT = 0x0000 ; default value Global Const $SHGFP_TYPE_DEFAULT = 0x0001 MsgBox(0, 1, _WinAPI_SHGetFolderPath(16416)) ;;Or MsgBox(0, 1, _WinAPI_SHGetFolderPath($CSIDL_INTERNET_CACHE)) Func _WinAPI_SHGetFolderPath($nFolder, $dwFlags = $SHGFP_TYPE_CURRENT) Local $path = DllStructCreate("wchar[260]") Local $folder = DllCall("shell32.dll", "int", "SHGetFolderPathW", _ "hwnd", 0, _ "int", $nFolder, _ "ptr", 0, _ "dword", $dwFlags, _ "ptr", DllStructGetPtr($path) _ ) If $folder[0] < 0 Then Return SetError(1, "", "") Return DllStructGetData($path, 1) EndFunc Ciao.
  12. Like
    DXRW4E got a reaction from trancexx in AutoIt v3.3.13.19 Beta   
    I'm not a pro of the C++ indeed I know little, but what do I know that is not Rvalue or Lvalue that is a temporary object (that must be destroyed when no longer needed), and a temporary object is const, all standart library have already func (with paramenter) in pointer and reference and const and non-const (Operator and Function Overloading, if not this does not work after (1 + (2 + 3)) or ("String1" + ("Sring2" + "String3")) etc etc), so is not wrong to send a temporary object as (const) byref


     
    Ciao.
  13. Like
    DXRW4E got a reaction from doestergaard in How do I get just the directories that contains .inf files?   
    official way will have to be this
    #include <Array.au3> If Not IsDeclared("arDllCall") Then     Global Static $arDllCall EndIf Global Const $hSetupApiDll = DllOpen("SetupApi.dll") Global Const $hKernel32DLL = DllOpen("Kernel32.dll") Global Const $ERROR_INSUFFICIENT_BUFFER = 122 ;(0x7A) - The data area passed to a system call is too small. Local $aInfFieList =_FileListToArrayEx(@WindowsDir & "\inf", "*.Inf", 13) _ArrayDisplay($aInfFieList) MsgBox(0, 1, _SetupGetInfFileList(Null)) Local $sInfFieList, $aDirectoryPath = _FileListToArrayEx(@WindowsDir & "\inf", "*", 14) If Not @Error Then     For $i = 1 To $aDirectoryPath[0]         $sInfFieList &= _SetupGetInfFileList($aDirectoryPath[$i])     Next EndIf MsgBox(0, 1, $sInfFieList) ; #FUNCTION# ======================================================================================================================================================= ; Name...........: _FileListToArrayEx ; Description ...: Lists files and\or folders in a specified path (Similar to using Dir with the /B Switch) ; Syntax.........: _FileListToArrayEx($sPath[, $sFilter = "*"[, $iFlag = 0]]) ; Parameters ....: $sPath   - Path to generate filelist for. ;                  $sFilter - Optional the filter to use, default is *. (Multiple filter groups such as "All "*.png|*.jpg|*.bmp") Search the Autoit3 helpfile for the word "WildCards" For details. ;                  $iFlag   - Optional: specifies whether to return files folders or both Or Full Path (add the flags together for multiple operations): ;                  |$iFlag = 0 (Default) Return both files and folders ;                  |$iFlag = 1 Return files only ;                  |$iFlag = 2 Return Folders only ;                  |$iFlag = 4 Search SubDirectory ;                  |$iFlag = 8 Return Full Path ;                  |$iFlag = 16 $sFilter do Case-Sensitive matching (By Default $sFilter do Case-Insensitive matching) ;                  |$iFlag = 32 Disable the return the count in the first element - effectively makes the array 0-based (must use UBound() to get the size in this case). ;                    By Default the first element ($array[0]) contains the number of file found, the remaining elements ($array[1], $array[2], etc.) ;                  |$iFlag = 64 $sFilter is REGEXP Mod, See Pattern Parameters in StringRegExp (Can not be combined with flag 16) ;                  |$iFlag = 128 Return Backslash at the beginning of the file name, example Return "\Filename1.xxx" (Can not be combined with flag 8) ; Return values .: Failure - @Error ;                  |1 = Path not found or invalid ;                  |2 = Invalid $sFilter ;                  |3 = No File(s) Found ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: The array returned is one-dimensional and is made up as follows: ;                                $array[0] = Number of Files\Folders returned ;                                $array[1] = 1st File\Folder ;                                $array[2] = 2nd File\Folder ;                                $array[3] = 3rd File\Folder ;                                $array[n] = nth File\Folder ; Related .......: ; Link ..........: ; Example .......: Yes ; Note ..........: Special Thanks to SolidSnake & Tlem ; ================================================================================================================================================================== Func _FileListToArrayEx($sPath, $sFilter = "*", $iFlag = 0)     Local Const $hSR = StringRegExpReplace     $sPath = $hSR($sPath & "\", "(?!\A)[\\/]+\h*", "\\")     If Not FileExists($sPath) Then Return SetError(1, 1, "")     If StringRegExp($sFilter, (BitAND($iFlag, 64) ? '^\s*$|\v|[\\/:><"]|^\||\|\||\|$' : '^\s*$|\v|\\')) Then Return SetError(2, 2, "")     Local $hSearch, $sFile, $sFileList, $sSubDir = BitAND($iFlag, 4), $sDelim = (BitAND($iFlag, 128) ? "|\" : (BitAND($iFlag, 8) ? "|" & $sPath : "|"))     $hSearch = FileFindFirstFile($sPath & "*")     If @Error Then Return SetError(3, 3, "")     Local $hWSearch = $hSearch, $hWSTMP, $SearchWD, $iExtended, $iFlags = (BitAND($iFlag, 3) = 3 ? 0 : BitAND($iFlag, 3)), $iFilter = $sFilter = "*" ? 0 : 1     If Not BitAND($iFlag, 64) Then $sFilter = (BitAND($iFlag, 16) ? "(" : "(?i)(") & $hSR($hSR($hSR($hSR($sFilter, "[^*?|]+", "\\Q$0\\E"), "\\E(?=\||$)", "$0\$"), "(?<=^|\|)\\Q", "^$0"), "\*+", ".*") & ")"     While 1         $sFile = FileFindNextFile($hWSearch)         If @Error Then             If $hWSearch = $hSearch Then ExitLoop             FileClose($hWSearch)             $hWSearch -= 1             $SearchWD = StringLeft($SearchWD, StringInStr($SearchWD, "\", 1, -2))         ElseIf $sSubDir Then             $iExtended = @Extended             If ($iFlags + $iExtended <> 2) Then                 If $iFilter Then                     If StringRegExp($sFile, $sFilter) Then $sFileList &= $sDelim & $SearchWD & $sFile                 Else                     $sFileList &= $sDelim & $SearchWD & $sFile                 EndIf             EndIf             If Not $iExtended Then ContinueLoop             $hWSTMP = FileFindFirstFile($sPath & $SearchWD & $sFile & "\*")             If $hWSTMP = -1 Then ContinueLoop             $hWSearch = $hWSTMP             $SearchWD &= $sFile & "\"         ElseIf ($iFlags + @Extended) <> 2 And StringRegExp($sFile, $sFilter) Then             $sFileList &= $sDelim & $sFile         EndIf     WEnd     FileClose($hSearch)     If Not $sFileList Then Return SetError(3, 3, "")     Return StringSplit(StringTrimLeft($sFileList, 1), "|", StringReplace(BitAND($iFlag, 32), "32", 2)) EndFunc    ;==>_FileListToArrayEx ; #FUNCTION# ============================================================================================================================================== ; Name...........: _SetupGetInfFileList ; Description ...: The SetupGetInfFileList function returns a list of INF files located in a caller-specified directory to a call-supplied buffer. ; Syntax.........: _SetupGetInfFileList($DirectoryPath, $InfStyle) ; Parameters ....: $DirectoryPath - Optional pointer to a null-terminated string containing the path of the directory in which to search. ;                    If this value is NULL, the %windir%\inf directory is used. ;                  $InfStyle   - Type of INF file to search for. May be a combination of the following flags. ;                  |$INF_STYLE_OLDNT (1) - A legacy INF file format. ;                  |$INF_STYLE_WIN4 (2)  - A Windows INF file format. ; Return values .: If the function succeeds, the return value is a String Inf file List value. ; Remarks .......: ; Related .......: ; Author ........: DXRW4E ; ========================================================================================================================================================= Func _SetupGetInfFileList($sDirectoryPath, $InfStyle = 2)     $arDllCall = DllCall($hSetupApiDll, "BOOL", "SetupGetInfFileListW", "WSTR", $sDirectoryPath, "DWORD", $InfStyle, "WSTR", "", "DWORD", Null, "DWORD*", 0)     If @Error Then Return SetError(@Error, 0, 0)     ;If Not $arDllCall[0] And _WinAPI_GetLastErrorEx() = $ERROR_INSUFFICIENT_BUFFER Then $arDllCall = DllCall($hSetupApiDll, "BOOL", "SetupGetInfFileListW", "WSTR", $sDirectoryPath, "DWORD", $InfStyle, "WSTR", "", "DWORD", $arDllCall[5], "DWORD*", 0)     ;If $arDllCall[0] Then Return SetError(0, $arDllCall[5], $arDllCall[3])     Local $ReturnBuffer = DllStructCreate("BYTE[" & $arDllCall[5] * 2 & "]")     $arDllCall = DllCall($hSetupApiDll, "BOOL", "SetupGetInfFileListW", "WSTR", $sDirectoryPath, "DWORD", $InfStyle, "STRUCT*", $ReturnBuffer, "DWORD", $arDllCall[5], "DWORD*", 0)     If $arDllCall[0] Then Return SetError(0, $arDllCall[5], StringRegExpReplace(BinaryToString(DllStructGetData($ReturnBuffer, 1), 2), "\x00+", @LF))     Return SetError(_WinAPI_GetLastErrorEx(), 0, -1) EndFunc    ;==>_SetupGetInfFileList Func _WinAPI_GetLastErrorEx()     $arDllCall = DllCall($hKernel32DLL, "long", "GetLastError")     Return $arDllCall[0] EndFunc    ;==>_WinAPI_GetLastErrorEx Ciao.
  14. Like
    DXRW4E got a reaction from mohan93 in Exporting HKCU registry entries from a MSI file using Script   
    Example http://msdn.microsoft.com/en-us/library/aa372865(v=vs.85).aspx

    #include <Array.au3> Global Const $msiOpenDatabaseModeReadOnly = 0 ;; Opens a database read-only, no persistent changes. Global Static $oInstaller, $oDatabase, $oView, $oRecord, $sFilePath, $aRegistry[101][4] = [[0,100]] $sFilePath = FileOpenDialog("Select a MSI file...", @ScriptDir, "MSI (*.msi)") ;;"MSI (*.msi;*.msp)" If Not @Error Then $oInstaller = ObjCreate("WindowsInstaller.Installer") If IsObj($oInstaller) Then $oDatabase = $oInstaller.OpenDatabase($sFilePath, $msiOpenDatabaseModeReadOnly) If IsObj($oDatabase) Then $oView = $oDatabase.OpenView("SELECT `Registry`.`Key`, `Registry`.`Name`, `Registry`.`Value` FROM `Registry` WHERE `Registry`.`Root`=0 ORDER BY `Registry`.`Root`") If IsObj($oView) Then $oView.Execute() While 1 $oRecord = $oView.Fetch If Not IsObj($oRecord) Then ExitLoop $aRegistry[0][0] += 1 If $aRegistry[0][0] = $aRegistry[0][1] Then $aRegistry[0][1] *= 2 ReDim $aRegistry[$aRegistry[0][1] + 1][4] EndIf $aRegistry[$aRegistry[0][0]][0] = "HKCR" For $i = 1 To 3 $aRegistry[$aRegistry[0][0]][$i] = $oRecord.StringData($i) Next WEnd $oView.Close ReDim $aRegistry[$aRegistry[0][0] + 1][4] Else MsgBox(0, "Error", 4) EndIf Else MsgBox(0, "Error", 3) EndIf Else MsgBox(0, "Error", 2) EndIf Else MsgBox(0, "Error", 1) EndIf $oView = "" $oDatabase = "" _ArrayDisplay($aRegistry) #include <Array.au3> Global Const $msiOpenDatabaseModeReadOnly = 0 ;; Opens a database read-only, no persistent changes. Global Static $oInstaller, $oDatabase, $oView, $oRecord, $sFilePath, $aRegistry[101][4] = [[0,100]] $sFilePath = FileOpenDialog("Select a MSI file...", @ScriptDir, "MSI (*.msi)") ;;"MSI (*.msi;*.msp)" If Not @Error Then $oInstaller = ObjCreate("WindowsInstaller.Installer") If IsObj($oInstaller) Then $oDatabase = $oInstaller.OpenDatabase($sFilePath, $msiOpenDatabaseModeReadOnly) If IsObj($oDatabase) Then $oView = $oDatabase.OpenView("SELECT `Registry`.`Key`, `Registry`.`Name`, `Registry`.`Value` FROM `Registry` WHERE `Registry`.`Root`=1 ORDER BY `Registry`.`Root`") If IsObj($oView) Then $oView.Execute() While 1 $oRecord = $oView.Fetch If Not IsObj($oRecord) Then ExitLoop $aRegistry[0][0] += 1 If $aRegistry[0][0] = $aRegistry[0][1] Then $aRegistry[0][1] *= 2 ReDim $aRegistry[$aRegistry[0][1] + 1][4] EndIf $aRegistry[$aRegistry[0][0]][0] = "HKCU" For $i = 1 To 3 $aRegistry[$aRegistry[0][0]][$i] = $oRecord.StringData($i) Next WEnd $oView.Close ReDim $aRegistry[$aRegistry[0][0] + 1][4] Else MsgBox(0, "Error", 4) EndIf Else MsgBox(0, "Error", 3) EndIf Else MsgBox(0, "Error", 2) EndIf Else MsgBox(0, "Error", 1) EndIf $oView = "" $oDatabase = "" _ArrayDisplay($aRegistry) Ciao.
  15. Like
    DXRW4E got a reaction from DW1 in RegEx lazy quantifier   
    yes right, but the '">Yarp' is already the first Match, so everything is ok
     
    try
    #include <Array.au3> Local $sString = '<TD colSpan=4><SPAN style="FONT-VARIANT: small-caps">Sub-Categories: [<A href="Categories.aspx?id=2b249c75-f666-424e-b555-bf9ee8f34152">Yarp</A>] ' $sString &= '[<A href="Categories.aspx?id=584378e4-917a-4fce-a6ff-e75fb966e36f">Nay</A>] [<A href="Categories.aspx?id=042394b4-1c0e-42d9-a9ba-bca9ea1394b1">Nada</A>] ' $sString &= '[<A href="Categories.aspx?id=8d72025e-a23a-4c81-8174-d3fc4e1eb469">Yarp</A>] ' Local $aTemp = StringRegExp($sString, 'href="(.*?)">Yarp', 3) _ArrayDisplay($aTemp) or tell RegExp to find the last 'href='
    #include <Array.au3> Local $sString = '<TD colSpan=4><SPAN style="FONT-VARIANT: small-caps">Sub-Categories: [<A href="Categories.aspx?id=2b249c75-f666-424e-b555-bf9ee8f34152">Nope</A>] ' $sString &= '[<A href="Categories.aspx?id=584378e4-917a-4fce-a6ff-e75fb966e36f">Nay</A>] [<A href="Categories.aspx?id=042394b4-1c0e-42d9-a9ba-bca9ea1394b1">Nada</A>] ' $sString &= '[<A href="Categories.aspx?id=8d72025e-a23a-4c81-8174-d3fc4e1eb469">Yarp</A>] ' Local $aTemp = StringRegExp($sString, '.*href="(.*?)">Yarp', 3) _ArrayDisplay($aTemp) Ciao.
  16. Like
    DXRW4E got a reaction from DW1 in RegEx lazy quantifier   
    wat works OK, is the pattern who is not OK, not the RegExp
    #include <Array.au3> Local $sString = '<TD colSpan=4><SPAN style="FONT-VARIANT: small-caps">Sub-Categories: [<A href="Categories.aspx?id=2b249c75-f666-424e-b555-bf9ee8f34152">Nope</A>] ' $sString &= '[<A href="Categories.aspx?id=584378e4-917a-4fce-a6ff-e75fb966e36f">Nay</A>] [<A href="Categories.aspx?id=042394b4-1c0e-42d9-a9ba-bca9ea1394b1">Nada</A>] ' $sString &= '[<A href="Categories.aspx?id=8d72025e-a23a-4c81-8174-d3fc4e1eb469">Yarp</A>] ' Local $aTemp = StringRegExp($sString, 'href="(.*?)">Yarp', 3) _ArrayDisplay($aTemp) so check href=" '<TD colSpan=4><SPAN style="FONT-VARIANT: small-caps">Sub-Categories: [<A href=" and stops until ">Yarp
    Ciao.
  17. Like
    DXRW4E got a reaction from DW1 in RegEx lazy quantifier   
    #include <Array.au3> Local $sString = '<TD colSpan=4><SPAN style="FONT-VARIANT: small-caps">Sub-Categories: [<A href="Categories.aspx?id=2b249c75-f666-424e-b555-bf9ee8f34152">Nope</A>] ' $sString &= '[<A href="Categories.aspx?id=584378e4-917a-4fce-a6ff-e75fb966e36f">Nay</A>] [<A href="Categories.aspx?id=042394b4-1c0e-42d9-a9ba-bca9ea1394b1">Nada</A>] ' $sString &= '[<A href="Categories.aspx?id=8d72025e-a23a-4c81-8174-d3fc4e1eb469">Yarp</A>] ' Local $aTemp = StringRegExp($sString, 'href="([^"\r\n]*)">Yarp', 3) _ArrayDisplay($aTemp) ;or $aTemp = StringRegExp($sString, 'href="?([^"\r\n\>\<]*)"?>Yarp', 3) _ArrayDisplay($aTemp)  
    Ciao.
  18. Like
    DXRW4E got a reaction from iFFgen in INI File Processing Functions   
    IniEx.au3 (INI File Processing Functions) solve many problems, such as the limits of AutoIt Default INI function, and add many other options, since all function work by reference so IniEx.au3 also use less memory, and provide a really good performance in speed
     
    #include-Once ; #INDEX# ======================================================================================================================= ; Title .........: IniEx ; AutoIt Version : v3.3.9.22++ ; Language ......: English ; Description ...: INI File Processing Functions ; Author(s) .....: DXRW4E ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_IniClearCache() ;_IniCloseFileEx() ;_IniDeleteEx() ;_IniFileWriteEx() ;_IniGetFileInformationEx() ;_IniGetFileStringData() ;_IniGetSectionNumberEx() ;_IniOpenFileEx() ;_IniOpenFile() ;_IniReadEx() ;_IniReadSectionEx() ;_IniReadSectionNamesEx() ;_IniRenameSectionEx() ;_IniWriteEx() ;_IniWriteSectionEx() ; =============================================================================================================================== ; #INTERNAL_USE_ONLY# =========================================================================================================== ;__GetSeparatorCharacter() ;__IniFileWriteEx() ;__IniGetFileStringData() ;__IniReadSectionEx() ;__IniSaveCache() ;__IniWriteSectionEx() ; =============================================================================================================================== ; #CONSTANTS# =================================================================================================================== Global Const $INI_STRIPLEADING            = 1           ; $STR_STRIPLEADING  - strip leading white space Global Const $INI_STRIPTRAILING           = 2           ; $STR_STRIPTRAILING - strip trailing white space Global Const $INI_STRIPLEADTRAILING       = 3            ; BitOR($STR_STRIPLEADING,  $STR_STRIPTRAILING) Global Const $INI_ARRAYDATA               = 4 Global Const $INI_ARRAYDATA_NOCOUNT       = 8 Global Const $INI_NOWRITEREADONLY         = 16 Global Const $INI_FO_UNICODE              = 32          ; $FO_UNICODE Global Const $INI_FO_UTF16_LE             = 32          ; $FO_UTF16_LE Global Const $INI_FO_UTF16_BE             = 64          ; $FO_UTF16_BE Global Const $INI_FO_UTF8                 = 128         ; $FO_UTF8 Global Const $INI_FO_UTF8_NOBOM           = 256         ; $FO_UTF8_NOBOM Global Const $INI_NOOCCURRENCE            = 512 Global Const $INI_MERGE                   = 1024 Global Const $INI_NOCREATE                = 2048 Global Const $INI_APPENDDATA              = 4096 Global Const $INI_REPLACEONLY             = 8192 Global Const $INI_FO_UTF8_FULL            = 16384       ; $FO_UTF8_FULL Global Const $INI_NOOVERWRITE             = 32768 Global Const $INI_OVERWRITEALL            = 65536 Global Const $INI_IGNOREDUPLICATE         = 131072 Global Const $INI_DELETE                  = 262144 Global Const $INI_RENAME                  = 524288 Global Const $INI_REMOVE                  = 1048576 ;Global Const $INI_RESERVED*               = 2097152 ;Global Const $INI_RESERVED*               = 4194304 ;Global Const $INI_RESERVED*               = 8388608 Global Const $INI_OPEN_EXISTING           = 16777216 Global Const $INI_CREATEPATH              = 33554432 Global Const $INI_REPAIR_ERROR            = 67108864 Global Const $INI_DISCARDCHANGES          = 134217728 Global Const $INI_OPEN_FILEQUEUE          = 268435456 ;Global Const $INI_RESERVED*               = 536870912 Global Const $INI_2DARRAYFIELD            = 1073741824 ;;;; THESE ARE SPECIAL FLAGS, ARE USED INTERNALLY ONLY ;;;; Global Const $INI_INTERNAL_USE_ONLY       = 2147483648 Global Const $INI_FO_STYLE                = BitOR(31, $INI_OPEN_EXISTING, $INI_CREATEPATH, $INI_REPAIR_ERROR, $INI_OPEN_FILEQUEUE) Global Const $INI_MERGE_NOOCCURRENCE      = BitOR($INI_MERGE, $INI_NOOCCURRENCE) Global Const $INI_REMOVE_RENAME           = BitOR($INI_REMOVE, $INI_RENAME) Global Const $INI_REMOVE_DELETE           = BitOR($INI_REMOVE, $INI_DELETE) Global Const $INI_NOCREATE_REMOVE_DELETE  = BitOR($INI_NOCREATE, $INI_REMOVE, $INI_DELETE) Global Const $INI_NOOCCURRENCE_IGNOREDUPLICATE = BitOr($INI_NOOCCURRENCE, $INI_IGNOREDUPLICATE) Global Const $INI_OVERWRITEALL_APPENDDATA = BitOR($INI_OVERWRITEALL, $INI_APPENDDATA) Global Const $NULL_REF = Null Global Const $sINI_OPENFILE_EX            = @LF & "[]" & @LF ;;;; DO NOT EVER USE\CHANGE\EDIT THESE VARIABLES ;;;; ;;;;  THESE VARIABLES ARE USED INTERNALLY ONLY   ;;;; Global Static $INI_NULL_REF = Null Global Static $_HINI[11][11] = [[10, 0]] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniOpenFileEx ; Description ...: The _IniOpenFileEx function opens an INI file and returns a handle to it. ; Syntax.........: _IniOpenFileEx($sFilePath[, $iFlags]]) ; Parameters ....: $sFilePath       - INI File Path ;                   $iFlags          - Optional, (add the flags together for multiple operations): ;                  This Flags will be ignored if the $INI_CREATEPATH is not set\used ;                  | A file may fail to open due to access rights or attributes. ;                  | The default mode when writing text is ANSI - use the unicode flags to change this. When writing unicode files ;                  | the Windows default mode (and the fastest in AutoIt due to the least conversion) is UTF16 Little Endian (mode 32). ;                  | $INI_FO_* Flags will be ignored if the $INI_CREATEPATH is not Set\Used ;                  |$INI_FO_UNICODE or $INI_UTF16_LE (32) - Use Unicode UTF16 Little Endian reading and writing mode. Reading does not override existing BOM. ;                  |$INI_FO_UTF16_BE (64)                 - Use Unicode UTF16 Big Endian reading and writing mode. Reading does not override existing BOM. ;                  |$INI_FO_UTF8 (128)                    - Use Unicode UTF8 (with BOM) reading and writing mode. Reading does not override existing BOM. ;                  |$INI_FO_UTF8_NOBOM (256)              - Use Unicode UTF8 (without BOM) reading and writing mode. ;                  |$INI_FO_UTF8_FULL (16384)             - When opening for reading and no BOM is present, use full file UTF8 detection. If this is not used then only the initial part of the file is checked for UTF8. ;                  ;;;;;;;;;;;; ;                  |$INI_OPEN_EXISTING (16777216)      - If the INI File (Path) is Already Open use that (Handle) (Default Always Opens a New) ;                  |$INI_CREATEPATH (33554432)         - Create INI File if does not exist (Default if file not exist Return Error) ;                  |$INI_REPAIR_ERROR (67108864)       - If exist Error when Opening the INI File Repair Error, example as this line (@CRLF & [SectionName & @CRLF) repair in (@CRLF & [SectionName] & @CRLF), Default Return Error ;                  |$INI_OPEN_FILEQUEUE (268435456)    - Open INI file from Memory\Variable, $sFilePath must contain String Text Data of INI file ; Return values .: Success - INI Handle ;                  Failure - Returns 0 or String\Text of error line (check @Extended for error line number) ;                  @Error  - 0 = No error. ;                  |1 = File cannot be opened or found. ;                  |2 = Error when Opening the INI File ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniOpenFileEx($sFilePath, $iFlags = 0)     If BitAND($iFlags, $INI_OPEN_EXISTING) Then         For $i = 1 To $_HINI[0][0]             If $_HINI[$i][2] = $sFilePath Then Return SetError(0, $i, $i)         Next     EndIf     Local $sCS, $_sCS = "\r", $hFilePath, $iFileEncoding, $aFileData, $aErrorLine, $iFO_Style = BitXOR(BitOR($iFlags, $INI_FO_STYLE), $INI_FO_STYLE)     If BitAND($iFlags, $INI_OPEN_FILEQUEUE) Then         $aFileData = StringRegExpReplace($sINI_OPENFILE_EX & $sFilePath, '\r(?!\n)', @CRLF)    ;;;;, '(?<!\r)\n', @CRLF)         $sFilePath = "FileQueue"         $iFileEncoding = $iFO_Style    ;;(StringIsASCII($aFileData) ? 0 : 32)     Else         $hFilePath = FileOpen($sFilePath)         If $hFilePath = -1 Then             If Not FileExists($sFilePath) Then                 If Not BitAND($iFlags, $INI_CREATEPATH) Then Return SetError(1, 0, 0)                 $iFO_Style += 10        ;;$iFO_Style = 42             EndIf             $hFilePath = FileOpen($sFilePath, $iFO_Style)             If $hFilePath = -1 Then Return SetError(1, 0, 0)         EndIf         $aFileData = StringRegExpReplace($sINI_OPENFILE_EX & FileRead($hFilePath), '\r(?!\n)', @CRLF)    ;;;;, '(?<!\r)\n', @CRLF)         $iFileEncoding = FileGetEncoding($hFilePath)         FileClose($hFilePath)     EndIf     $aErrorLine = StringRegExp($aFileData, '\n\K[\h\f\xb\x0]*\[[^\]\n]*(?:\n|$)', 1)     If Not @Error Then         Local $iErrorLine = @Extended - (StringLen($aErrorLine[0]) - 1)         If Not BitAND($iFlags, $INI_REPAIR_ERROR) Then Return SetError(2, StringSplit(StringLeft($aFileData, $iErrorLine), @LF)[0] - 2, $aErrorLine[0])         $aFileData = StringRegExpReplace($aFileData, '(\n[\h\f\xb\x0]*\[[^\]\r\n]*)(?=[\r\n]|$)', "$1]")     EndIf     $sCS = __GetSeparatorCharacter($aFileData)     If $sCS = @CR Then $_sCS = ""     $aFileData = StringRegExpReplace($aFileData & @CRLF & "[", "\n\K(?>[" & $_sCS & "\n\h\f\xb\x0]*\n|\x0*)(?=[\h\f\xb\x0]*\[)", $sCS & "${0}" & $sCS)     $aFileData = StringRegExp($aFileData & $sCS, $sCS & "([\h\f\xb\x0]*\[)([^\]\n]*)(\][^\n]*\n)((?>[" & $_sCS & "\n\h\f\xb\x0]*\n)*)([^" & $sCS & "]*)" & $sCS & "([^" & $sCS & "]*)", 3)     $aFileData[0] = UBound($aFileData) - 1     If $aFileData[0] < 5 Then Return SetError(1, 0, 0) ; should not happen ever     $aFileData[$aFileData[0]] = StringTrimRight($aFileData[$aFileData[0]], 2)     For $iHINI = 1 To $_HINI[0][0]         If Not $_HINI[$iHINI][0] Then ExitLoop     Next     If $iHINI > $_HINI[0][0] Then         ReDim $_HINI[$iHINI + $iHINI][11]         $_HINI[0][0] = $iHINI + $iHINI - 1     EndIf     $aFileData[2] = $iHINI     If Not $_sCS Then         $aFileData[3] = StringAddCR($aFileData[3])         $aFileData[4] = StringAddCR($aFileData[4])         $aFileData[5] = StringAddCR($aFileData[5])     EndIf     For $i = 7 To $aFileData[0] Step 6         $_HINI[$iHINI][5] &= @LF & $aFileData[$i] & @CR & $i         If Not $_sCS Then             $aFileData[$i + 1] = StringAddCR($aFileData[$i + 1])             $aFileData[$i + 2] = StringAddCR($aFileData[$i + 2])             $aFileData[$i + 3] = StringAddCR($aFileData[$i + 3])             $aFileData[$i + 4] = StringAddCR($aFileData[$i + 4])         EndIf     Next     $_HINI[0][1] += 1    ;;($_HINI[0][1] < 1) ? 1 : $_HINI[0][1] + 1     $_HINI[$iHINI][0] = $iHINI     $_HINI[$iHINI][1] = $aFileData     $_HINI[$iHINI][2] = $sFilePath     $_HINI[$iHINI][3] = $iFileEncoding     $_HINI[$iHINI][4] = ($aFileData[0] - 5) / 6     $_HINI[$iHINI][5] = StringReplace($_HINI[$iHINI][5], "\E", "\e", 0, 1)     $_HINI[$iHINI][7] = Null     Return $iHINI EndFunc   ;==>_IniOpenFileEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniOpenFile ; Description ...: The _IniOpenFile function opens an INI file and returns a handle to it. ; Parameters ....: the same as the _IniOpenFileEx(), See _IniOpenFileEx() ; Return values .: See _IniOpenFileEx() ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: _IniOpenFile() is the same as the _IniOpenFileEx(), only that _IniOpenFile()  force the check\repair of @CR or @LF in @CRLF ;                    performance\speed does not change much with _IniOpenFileEx(), _IniOpenFile() can only be about 1% or 5% or10% slower ; =============================================================================================================================== Func _IniOpenFile($sFilePath, $iFlags = 0)     If BitAND($iFlags, $INI_OPEN_EXISTING) Then         For $i = 1 To $_HINI[0][0]             If $_HINI[$i][2] = $sFilePath Then Return SetError(0, $i, $i)         Next     EndIf     Local $hFilePath, $iFileEncoding, $aFileData, $aErrorLine, $iFO_Style = BitXOR(BitOR($iFlags, $INI_FO_STYLE), $INI_FO_STYLE)     If BitAND($iFlags, $INI_OPEN_FILEQUEUE) Then         $aFileData = StringRegExpReplace($sINI_OPENFILE_EX & $sFilePath, '\r\n?', @LF)         $sFilePath = "FileQueue"         $iFileEncoding = $iFO_Style    ;;(StringIsASCII($aFileData) ? 0 : 32)     Else         $hFilePath = FileOpen($sFilePath)         If $hFilePath = -1 Then             If Not FileExists($sFilePath) Then                 If Not BitAND($iFlags, $INI_CREATEPATH) Then Return SetError(1, 0, 0)                 $iFO_Style += 10        ;;$iFO_Style = 42             EndIf             $hFilePath = FileOpen($sFilePath, $iFO_Style)             If $hFilePath = -1 Then Return SetError(1, 0, 0)         EndIf         $aFileData = StringRegExpReplace($sINI_OPENFILE_EX & FileRead($hFilePath), '\r\n?', @LF)         $iFileEncoding = FileGetEncoding($hFilePath)         FileClose($hFilePath)     EndIf     $aErrorLine = StringRegExp($aFileData, '\n\K[\h\f\xb\x0]*\[[^\]\n]*(?:\n|$)', 1)     If Not @Error Then         Local $iErrorLine = @Extended - (StringLen($aErrorLine[0]) - 1)         If Not BitAND($iFlags, $INI_REPAIR_ERROR) Then Return SetError(2, StringSplit(StringLeft($aFileData, $iErrorLine), @LF)[0] - 2, $aErrorLine[0])         $aFileData = StringRegExpReplace($aFileData, '(\n[\h\f\xb\x0]*\[[^\]\n]*)(?=\n|$)', "$1]")     EndIf     $aFileData = StringRegExpReplace($aFileData & @LF & "[", '\n\K(?>[\n\h\f\xb\x0]*\n|\x0*)(?=[\h\f\xb\x0]*\[)', @CR & "${0}" & @CR)     $aFileData = StringRegExp($aFileData & @CR, '\r([\h\f\xb\x0]*\[)([^\]\n]*)(\][^\n]*\n)((?>[\n\h\f\xb\x0]*\n)*)([^\r]*)\r([^\r]*)', 3)     $aFileData[0] = UBound($aFileData) - 1     If $aFileData[0] < 5 Then Return SetError(1, 0, 0) ; should not happen ever     $aFileData[$aFileData[0]] = StringTrimRight($aFileData[$aFileData[0]], 1)     For $iHINI = 1 To $_HINI[0][0]         If Not $_HINI[$iHINI][0] Then ExitLoop     Next     If $iHINI > $_HINI[0][0] Then         ReDim $_HINI[$iHINI + $iHINI][11]         $_HINI[0][0] = $iHINI + $iHINI - 1     EndIf     $aFileData[2] = $iHINI     $aFileData[3] = StringAddCR($aFileData[3])     $aFileData[4] = StringAddCR($aFileData[4])     $aFileData[5] = StringAddCR($aFileData[5])     For $i = 7 To $aFileData[0] Step 6         $_HINI[$iHINI][5] &= @LF & $aFileData[$i] & @CR & $i         $aFileData[$i + 1] = StringAddCR($aFileData[$i + 1])         $aFileData[$i + 2] = StringAddCR($aFileData[$i + 2])         $aFileData[$i + 3] = StringAddCR($aFileData[$i + 3])         $aFileData[$i + 4] = StringAddCR($aFileData[$i + 4])     Next     $_HINI[0][1] += 1    ;;($_HINI[0][1] < 1) ? 1 : $_HINI[0][1] + 1     $_HINI[$iHINI][0] = $iHINI     $_HINI[$iHINI][1] = $aFileData     $_HINI[$iHINI][2] = $sFilePath     $_HINI[$iHINI][3] = $iFileEncoding     $_HINI[$iHINI][4] = ($aFileData[0] - 5) / 6     $_HINI[$iHINI][5] = StringReplace($_HINI[$iHINI][5], "\E", "\e", 0, 1)     $_HINI[$iHINI][7] = Null     Return $iHINI EndFunc   ;==>_IniOpenFileEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniCloseFileEx ; Description ...: The _IniCloseFileEx function closes the INI file opened by a call to _IniOpenFileEx. ; Syntax.........: _IniCloseFileEx($hIniFile[, $iFlags]) ; Parameters ....: $hIniFile - Handle or INI Path to the INI file to be closed, This parameter can be NULL (use the $NULL_REF to set NULL this parameter) ;                    if $hIniFile is NULL Function Close All Open Handle or INI Path ;                   $iFlags  - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ;                  |Default - always Commits the changes that were made when the INI file was opened by _IniOpenFileEx() ;                  |$INI_DISCARDCHANGES (134217728) - Discards the changes that were made when the INI file was opened by _IniOpenFileEx() ; Return values .: NONE ; Author ........: DXRW4E ; Remarks .......: ; =============================================================================================================================== Func _IniCloseFileEx($hIniFile, $iFlags = 0)     If $hIniFile = $NULL_REF Then         For $i = 1 To $_HINI[0][0]             If Not BitAND($iFlags, $INI_DISCARDCHANGES) And $_HINI[$i][2] <> "FileQueue" Then _IniFileWriteEx($i, $iFlags)             For $y = 0 To 10                 $_HINI[$i][$y] = ""             Next         Next         $_HINI[0][1] = 0     Else         $hIniFile = _IniGetFileInformationEx($hIniFile)         If @Error Then Return SetError(1, 0, 0)         If Not BitAND($iFlags, $INI_DISCARDCHANGES) And $_HINI[$hIniFile][2] <> "FileQueue" Then _IniFileWriteEx($hIniFile, $iFlags)         For $i = 0 To 10             $_HINI[$hIniFile][$i] = ""         Next         $_HINI[0][1] -= 1     EndIf     Return 0 EndFunc   ;==>_IniCloseFileEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniDeleteEx ; Description ...: Delete\Remove - Section\KeyName in INI File. ; Syntax.........: _IniDeleteEx(ByRef $hIniFile, $sSectionName[, $sKeyName[, $iFlags[, $scKeyName]]]) ; Parameters ....: $hIniFile     - Handle to the INI file to query "see _IniOpenFileEx()" ;                   $sSectionName - The name of the section containing the Key\Value, This parameter can be NULL (use the $NULL_REF to set NULL this parameter) ;                    If $sSectionName is NULL, $hIniFile must be contain Section String\Key\Value\Data and $sKeyName the name of the key to delete ;                  $sKeyName     - The key name to delete, If $INI_OVERWRITEALL if set\used, $sKeyName will be writte exactly as in $sKeyName (without Edit\Formatting) ;                    This parameter can be NULL (use the $NULL_REF to set NULL this parameter), If $sKeyName is NULL, $hIniFile must be contain INI String\Text Data and $sSectionName the name of the section to delete ;                   $iFlags       - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ;                  |$INI_NOOCCURRENCE (512)       - Check only first section if there are more than one ;                  |$INI_IGNOREDUPLICATE (131072) - Proceed\Execute (Add\Delete\Replace\Edit ect ect) Once Only (Ignore all other Duplicate\Occurrences of KeyName\Value\Data) ;                  |$INI_DELETE (262144)          - Delete\Remove KeyName\Value\Data ;                  |$INI_REMOVE (1048576)         - Remove\Delete Section ;                   $scKeyName    - Optional, Key-Name separator character, Default is '=', This parameter can not be '"' or @CR or @LF ; Return values .: Returns a 0 (check @Extended for number of edit performed) ;                  @Error  - 0 = No error. ;                  |1 = Invalid IniHandle. ;                  |3 = SectionName not found ; Remarks .......: $INI_MERGE (1024) - (Join section if more than one in INI file) is always set\used by default, to disable it just use the $INI_NOOCCURRENCE ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniDeleteEx(ByRef $hIniFile, $sSectionName, $sKeyName = "", $iFlags = 0, $scKeyName = "=")     If Not $scKeyName Then $scKeyName = "="     If $sSectionName = $NULL_REF Then         Local $iOffSet = StringInStr($hIniFile, @LF, 1)         If StringRegExp(StringLeft($hIniFile, $iOffSet), '^(?i)[\h\f\xb\x0]*(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*') Then             If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $hIniFile = StringRegExpReplace($hIniFile, '\n[\h\f\xb\x0]*(?i)(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*', "")             $hIniFile = StringTrimLeft($hIniFile, $iOffSet)             SetExtended(1)         Else             $hIniFile = StringRegExpReplace($hIniFile, '\n[\h\f\xb\x0]*(?i)(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*', "", (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? 1 : 0))         EndIf     ElseIf $sKeyName = $NULL_REF Then         ;Not Recommended (NOT SAFE), if the Section (contains) String\Text Data is greater than 4.5 MB, the Section will be ignored         $hIniFile = StringTrimRight(StringRegExpReplace($hIniFile & @LF & "[", "(?is)\n[\h\f\xb\x0]*\[\Q" & StringReplace($sSectionName, "\E", "\e", 0, 1) & "\E\][^\n]*(?>\n?(?![\h\f\xb\x0]*\[))(.*?(?=\n[\h\f\xb\x0]*\[))", "", (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? 1 : 0)), 2)     Else         If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")         ;;;;If Not $sSectionName Then Return SetError(2, 0, "")    ;Invalid Section Name         If StringInStr($sSectionName, "\E", 1) Then $sSectionName = StringReplace($sSectionName, "\E", "\e", 0, 1)         If Not $sKeyName Or BitAND($iFlags, $INI_REMOVE_DELETE) = $INI_REMOVE Then             $iFlags = BitOr($iFlags, $INI_REMOVE)             __IniWriteSectionEx($hIniFile, $sSectionName, $INI_NULL_REF, $iFlags, $INI_NULL_REF, $_HINI[$hIniFile][1])         Else             $iFlags = BitOR(BitAND($iFlags, $INI_NOOCCURRENCE_IGNOREDUPLICATE), $INI_DELETE, $INI_MERGE)             If $_HINI[$hIniFile][7] <> $sSectionName Or ($_HINI[$hIniFile][8] > 1 And BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) <> BitAND($_HINI[$hIniFile][9], $INI_MERGE_NOOCCURRENCE)) Then                 __IniReadSectionEx($hIniFile, $sSectionName, $iFlags, $_HINI[$hIniFile][1])                 If @Error Then Return SetError(3, 0, "")             EndIf             Local $aKeyValue[2][3] = [[1],[$sKeyName]]             __IniWriteSectionEx($hIniFile, $sSectionName, $aKeyValue, $iFlags, $scKeyName, $_HINI[$hIniFile][1])         EndIf     EndIf     Return SetError(0, @Extended, 0) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniReadEx ; Description ...: The _IniReadEx Retrieves a string from the specified section in an Ini file ; Syntax.........: _IniReadEx($hIniFile, $sSectionName, $sKeyName[, $sDefault[, $iFlags[, $scKeyName]]]) ; Parameters ....: $hIniFile      - Handle to the INI file to query "see _IniOpenFileEx()" ;                   $sSectionName  - The name of the section containing the key name, This parameter can be NULL (use the $NULL_REF to set NULL this parameter) ;                    If $sSectionName is NULL, $hIniFile must be contain Section String\Key\Value\Data ;                   $sKeyName      - The name of the key whose associated string is to be retrieved ;                   $sDefault      - The default value to return if the requested KeyName is not found. ;                   $iFlags        - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ;                  |$INI_ARRAYDATA (4)         - Read All KeyName and Return Array of ValueString ;                  |$INI_ARRAYDATA_NOCOUNT (8) - Disable the return count in the first element, This Flags will be ignored if the $INI_ARRAYDATA is not set\used ;                  |$INI_NOOCCURRENCE (512)    - Read only first section if there are more than one ;                  |$INI_MERGE (1024)          - Join section if more than one in INI file, This Flag will be ignored if the $INI_NOOCCURRENCE is set\used ;                   $scKeyName - Optional, Key-Name separator character, Default is '=', This parameter can not be '"' or @CR or @LF ; Return values .: The first occurrence of requested key value as a string Or Array of Value String ;                  Failure - Returns $sDefault parameter ;                  @Error  - 0 = No error. ;                  |1 = Invalid IniHandle. ;                  |3 = SectionName not found ;                  |5 = Invalid KeyName ;                  |6 = KeyName not found ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniReadEx(ByRef $hIniFile, $sSectionName, $sKeyName, $sDefault = "", $iFlags = 0, $scKeyName = "=")     ;;If Not $sKeyName Then Return SetError(5, 0, "")     If StringInStr($sKeyName, "\E", 1) Then $sKeyName = StringReplace($sKeyName, "\E", "\e", 0, 1)     Local $aValueString, $sValueString, $iArray = BitAND($iFlags, $INI_ARRAYDATA)     If $sSectionName = $NULL_REF Then         $aValueString = StringRegExp(StringLeft($hIniFile, StringInStr($hIniFile, @LF, 1)), '^(?i)[\h\f\xb\x0]*(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)(?>[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*)(?|"([^\r\n]*)"|(.*?))[\h\f\xb\x0]*(?=[\r\n]|$)', 1)     Else         If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")         If StringInStr($sSectionName, "\E", 1) Then $sSectionName = StringReplace($sSectionName, "\E", "\e", 0, 1)         If $_HINI[$hIniFile][7] <> $sSectionName Or ($_HINI[$hIniFile][8] > 1 And BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) <> BitAND($_HINI[$hIniFile][9], $INI_MERGE_NOOCCURRENCE)) Then             _IniReadSectionEx($hIniFile, $sSectionName, BitOR($iFlags, $INI_STRIPLEADTRAILING))             If @Error Then Return SetError(3, 0, "")         EndIf         $aValueString = StringRegExp(StringLeft(($_HINI[$hIniFile][1])[$_HINI[$hIniFile][10]], StringInStr(($_HINI[$hIniFile][1])[$_HINI[$hIniFile][10]], @LF, 1)), '^(?i)[\h\f\xb\x0]*(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)(?>[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*)(?|"([^\r\n]*)"|(.*?))[\h\f\xb\x0]*(?=[\r\n]|$)', 1)         ;;;;$aValueString = StringRegExp(($sSectionName = $NULL_REF ? $hIniFile : ($_HINI[$hIniFile][1])[$_HINI[$hIniFile][10]]), '(?im)^[\h\f\xb\x0]*(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*(?|"([^\r\n]*)"|(.*?))[\h\f\xb\x0]*(?=[\r\n]|$)', 3)     EndIf     If Not @Error Then         If Not $iArray Then Return $aValueString[0]         $sValueString = $aValueString[0] & @LF     EndIf     $aValueString = StringRegExp(($sSectionName = $NULL_REF ? $hIniFile : ($_HINI[$hIniFile][1])[$_HINI[$hIniFile][10]]), '\n[\h\f\xb\x0]*(?i)(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)(?>[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*)(?|"([^\r\n]*)"|(.*?))[\h\f\xb\x0]*(?=[\r\n]|$)', ($iArray ? 3 : 1))     If @Error Then Return SetError(6, 0, $sDefault)     If Not $iArray Then Return $aValueString[0]     For $i = 0 To UBound($aValueString) - 1         $sValueString &= $aValueString[$i] & @LF     Next     Return StringSplit(StringTrimRight($sValueString, 1), @LF, (BitAND($iFlags, $INI_ARRAYDATA_NOCOUNT) ? 3 : 1)) EndFunc   ;==>_IniReadEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniReadSectionEx ; Description ...: The _IniReadSectionEx Retrieves all the lines for the specified section ; Syntax.........: _IniReadSectionEx(ByRef $hIniFile, $sSectionName[, $iFlags[, $scKeyName]) ; Parameters ....: $hIniFile      - Handle to the INI file to query "see _IniOpenFileEx()" ;                   $sSectionName  - The name of the section containing the Key\Value, This parameter can be NULL (use the $NULL_REF to set NULL this parameter) ;                    If $sSectionName is NULL, $hIniFile must be contain Section String\Key\Value\Data ;                   $iFlags        - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ;                    Default Return Section String\Text Data ;                  |$INI_NOOCCURRENCE (512)        - Read only first section if there are more than one ;                  |$INI_MERGE (1024)              - Join section if more than one in INI file, This Flag will be ignored if the $INI_NOOCCURRENCE is set\used ;                  |$INI_2DARRAYFIELD (1073741824) - Return 2DArray ;                     $aArray[0][0] = number of elements ;                     $aArray[0][1] = Key-Name separator character, Defaut is '=' ;                     $aArray[1][0] = "KeyName" ;                     $aArray[1][1] = "Value" ;                     $aArray[1][2] = "Unmodified contents of a line (example '    KeyName  = Value')" ;                     $aArray[n][0] = "KeyName" ;                     $aArray[n][1] = "Value" ;                     $aArray[n][2] = "Unmodified contents of a line (example ' KeyName =  Value')" ;                   $scKeyName - Optional, Key-Name separator character, Default is '=', This parameter can not be '"' or @CR or @LF ; Return values .: String\Text Data Or 2D Array ;                  @Error  - 0 = No error. ;                  |1 = Invalid IniHandle. ;                  |3 = SectionName's not found ;                  |4 = Array is invalid, Key\Value not found ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniReadSectionEx(ByRef $hIniFile, $sSectionName, $iFlags = 0, $scKeyName = "=")     If Not $scKeyName Then $scKeyName = "="     If $sSectionName = $NULL_REF Then         Local $_aSectionData = StringRegExp($hIniFile, '(?m)^((?>[\h\f\xb\x0]*)((?>"[^"\r\n]+"|(?:[^"\s' & $scKeyName & '\x0]+|(?>[\h\f\xb\x0]+)(?!' & $scKeyName & '))*))(?>[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*)(?|"([^\r\n]*)"|(.*?))[\h\f\xb\x0]*(?=[\r\n]|$))', 3)     Else         If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")         If $_HINI[$hIniFile][7] <> $sSectionName Or ($_HINI[$hIniFile][8] > 1 And BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) <> BitAND($_HINI[$hIniFile][9], $INI_MERGE_NOOCCURRENCE)) Then             $iFlags = BitOR($iFlags, $INI_NOCREATE)             __IniReadSectionEx($hIniFile, $sSectionName, $iFlags, $_HINI[$hIniFile][1])             If @Error Then Return SetError(3, 0, "")         EndIf         If Not BitAND($iFlags, $INI_2DARRAYFIELD) Then Return ($_HINI[$hIniFile][1])[$_HINI[$hIniFile][10]]         Local $_aSectionData = StringRegExp(($_HINI[$hIniFile][1])[$_HINI[$hIniFile][10]], '(?m)^((?>[\h\f\xb\x0]*)((?>"[^"\r\n]+"|(?:[^"\s' & $scKeyName & '\x0]+|(?>[\h\f\xb\x0]+)(?!' & $scKeyName & '))*))(?>[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*)(?|"([^\r\n]*)"|(.*?))[\h\f\xb\x0]*(?=[\r\n]|$))', 3)     EndIf     If @Error Then Return SetError(4, 0, "")     Local $iaSectionData = UBound($_aSectionData), $aSectionData[$iaSectionData / 3 + 1][3] = [[0,$scKeyName,$iaSectionData - 1]]     For $i = 0 To $aSectionData[0][2] Step 3         $aSectionData[0][0] += 1         $aSectionData[$aSectionData[0][0]][0] = $_aSectionData[$i + 1]         $aSectionData[$aSectionData[0][0]][1] = $_aSectionData[$i + 2]         $aSectionData[$aSectionData[0][0]][2] = $_aSectionData[$i]     Next     Return SetError(0, $aSectionData[0][0], $aSectionData) EndFunc   ;==>_IniReadSectionEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniReadSectionNamesEx ; Description ...: The _IniReadSectionNamesEx Retrieves the names of all sections in an INI file ; Syntax.........: _IniReadSectionNamesEx($hIniFile[, $iFlags]) ; Parameters ....: $hIniFile - Handle to the INI file to query "see _IniOpenFileEx()" ;                   $iFlags   - Optional, Flag to indicate the type of action that should be performed ;                  |$INI_ARRAYDATA_NOCOUNT (8) - disable the return count in the first element ;                  |$NULL_REF (NULL)           - $hIniFile must be contain INI String\Section\Key\Value\Data ; Return values .: Array of SectionNames String, and set @Extended = Number of Section's ;                  @Error  - 0 = No error. ;                  |1 = Array is invalid, Invalid IniHandle. ;                  |3 = Array is invalid, SectionName's not found ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniReadSectionNamesEx(ByRef $hIniFile, $iFlags = 0)     If $iFlags = $NULL_REF Then         Local $aSectionNames, $iANC = BitAND($iFlags, $INI_ARRAYDATA_NOCOUNT)         $aSectionNames = StringRegExp(($iANC ? @LF : @LF & "[]" & @LF) & $hIniFile, "\n[\h\f\xb\x0]*\[([^\r\n]*)\]", 3)         If @Error Then Return SetError(1, 0, "")         If $iANC Then Return SetError(0, UBound($aSectionNames), $aSectionNames)         $aSectionNames[0] = UBound($aSectionNames) - 1         Return SetError(0, $aSectionNames[0], $aSectionNames)     EndIf     If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")     If Not $_HINI[$hIniFile][4] Then Return SetError(3, 0, "")     If BitAND($iFlags, $INI_ARRAYDATA_NOCOUNT) Then Return SetError(0, $_HINI[$hIniFile][4], StringRegExp($_HINI[$hIniFile][5], "\n([^\r\n]*)", 3))     Return SetError(0, $_HINI[$hIniFile][4], StringRegExp(@LF & $_HINI[$hIniFile][4] & $_HINI[$hIniFile][5], "\n([^\r\n]*)", 3)) EndFunc   ;==>_IniReadSectionNamesEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniRenameSectionEx ; Description ...: The _IniRenameSectionEx rename the sections in an INI file ; Syntax.........: _IniRenameSectionEx($hIniFile[, $iFlags]) ; Parameters ....: $hIniFile      - Handle to the INI file to query "see _IniOpenFileEx()" ;                   $iFlags        - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ;                  |$INI_NOOCCURRENCE (512) - Rename only first section if there are more than one ;                  |$INI_MERGE (1024)       - Join section if more than one in INI\INI file, This Flag will be ignored if the $INI_NOOCCURRENCE is set\used ;                  |$NULL_REF (NULL)        - $hIniFile must be contain INI String\Section\Key\Value\Data ; Return values .: Returns a 0 (check @Extended for number of edit performed) ;                  @Error  - 0 = No error. ;                  |1 = Invalid IniHandle. ;                  |3 = SectionName's not found ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniRenameSectionEx(ByRef $hIniFile, $sSectionName, $sNewSectionName, $iFlags = 0)     ;;;;If Not $sSectionName Or Not $sNewSectionName Then Return SetError(2, 0, "")    ;Invalid Section Name     If $iFlags = $NULL_REF Then         $hIniFile = StringRegExpReplace($hIniFile, "(?mi)^[\h\f\xb\x0]*\[\K\Q" & StringReplace($sSectionName, "\E", "\e", 0, 1) & "\E(?=\])", StringReplace($sNewSectionName, "\", "\\", 0, 1), (BitAND($iFlags, $INI_NOOCCURRENCE) ? 1 : 0))     Else         If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")         If StringInStr($sSectionName, "\E", 1) Then $sSectionName = StringReplace($sSectionName, "\E", "\e", 0, 1)         $iFlags = BitXOR(BitOR($iFlags, $INI_REMOVE_RENAME), $INI_REMOVE)         If BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) = $INI_MERGE And Not __IniReadSectionEx($hIniFile, $sSectionName, $iFlags, $_HINI[$hIniFile][1]) Then Return SetError(3, 0, 0)         __IniWriteSectionEx($hIniFile, $sSectionName, $sNewSectionName, $iFlags, $INI_NULL_REF, $_HINI[$hIniFile][1])     EndIf     Return SetError(@Error, @Extended, 0) EndFunc   ;==>_IniRenameSectionEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniWriteEx ; Description ...: Write\Add\Replace\Delete\Change\Edit a KeyName\Value\Data in INI File ; Syntax.........: _IniWriteEx(ByRef $hIniFile, $sSectionName, $sKeyName, $sValue[, $iFlags[, $scKeyName]]) ; Parameters ....: $hIniFile     - Handle to the INI file to query "see _IniOpenFileEx()" ;                   $sSectionName - The name of the section containing the Key\Value, This parameter can be NULL (use the $NULL_REF to set NULL this parameter) ;                    If $sSectionName is NULL, $hIniFile must be contain Section String\Key\Value\Data ;                  $sKeyName     - The key name in the in the .ini file. ;                  $sKeyName     - The value to write/change. ;                   $iFlags       - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ;                  |$INI_STRIPLEADING (1)         - strip leading white space Section, This Flag will be ignored if the $INI_OVERWRITEALL or $INI_APPENDDATA is set\used ;                  |$INI_STRIPTRAILING (2)        - trailing white space Section, This Flag will be ignored if the $INI_OVERWRITEALL or $INI_APPENDDATA is set\used ;                  |$INI_NOOCCURRENCE (512)       - Check only first section if there are more than one ;                  |$INI_NOCREATE (2048)          - Not Create New Section If Section Not Exist ;                  |$INI_APPENDDATA (4096)        - Add KeyName\Value\Data (Append Mod) ;                  |$INI_REPLACEONLY (8192)       - Add KeyName\Value\Data Only if Exist ;                  |$INI_NOOVERWRITE (32768)      - Add KeyName\Value\Data Only if Not Exist ;                  |$INI_OVERWRITEALL (65536)     - Overwrite All data in Section (Replaces all KeyName\Value\Data in the Section) ;                  |$INI_IGNOREDUPLICATE (131072) - Proceed\Execute (Add\Delete\Replace\Edit ect ect) Once Only (Ignore all other Duplicate\Occurrences of KeyName\Value\Data) ;                  |$INI_DELETE (262144)          - Delete\Remove KeyName\Value\Data ;                   $scKeyName     - Optional, Key-Name separator character, Default is '=', This parameter can not be '"' or @CR or @LF ; Return values .: Returns a 0 (check @Extended for number of edit performed) ;                  @Error  - 0 = No error. ;                  |1 = Invalid IniHandle. ;                  |3 = SectionName's not found ;                  |5 = Invalid KeyName ; Author ........: DXRW4E ; Remarks .......: $INI_MERGE (1024) - (Join section if more than one in INI file) is always set\used by default, to disable it just use the $INI_NOOCCURRENCE ; =============================================================================================================================== Func _IniWriteEx(ByRef $hIniFile, $sSectionName, $sKeyName, $sValue, $iFlags = 0, $scKeyName = "=")     ;;If Not $sKeyName Then Return SetError(5, 0, "")     If Not $scKeyName Then $scKeyName = "="     If $sSectionName = $NULL_REF Then         If BitAND($iFlags, $INI_OVERWRITEALL_APPENDDATA) Then             If BitAND($iFlags, $INI_OVERWRITEALL) Then $hIniFile = ""             $hIniFile &= $sKeyName & $scKeyName & $sValue & @CRLF         Else             Local $asKeyValue, $sKNPattern, $iOffSet = StringInStr($hIniFile, @LF, 1)             $sKNPattern = '\n[\h\f\xb\x0]*(?i)(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*'             If StringRegExp(StringLeft($hIniFile, $iOffSet), '^(?i)[\h\f\xb\x0]*(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*') Then                 If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $hIniFile = StringRegExpReplace($hIniFile, $sKNPattern, "")                 If BitAND($iFlags, $INI_DELETE) Then                     $hIniFile = StringTrimLeft($hIniFile, $iOffSet)                 ElseIf Not BitAND($iFlags, $INI_NOOVERWRITE) Then                     $hIniFile = $sKeyName & $scKeyName & $sValue & @CRLF & StringTrimLeft($hIniFile, $iOffSet)                 EndIf             ElseIf BitAND($iFlags, $INI_DELETE) Then                 $hIniFile = StringRegExpReplace($hIniFile, $sKNPattern, "", (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? 1 : 0))             Else                 $asKeyValue = StringRegExp($hIniFile, $sKNPattern, 1)                 $iOffSet = @Extended - 1                 If Not @Error Then                     If BitAND($iFlags, $INI_NOOVERWRITE) Then                         If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $hIniFile = StringLeft($hIniFile, $iOffSet) & StringRegExpReplace(StringTrimLeft($hIniFile, $iOffSet), $sKNPattern, "")                     Else                         $hIniFile = StringLeft($hIniFile, $iOffSet + 1 - StringLen($asKeyValue[0])) & $sKeyName & $scKeyName & $sValue & @CR & (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? StringTrimLeft($hIniFile, $iOffSet) : StringRegExpReplace(StringTrimLeft($hIniFile, $iOffSet), $sKNPattern, ""))                     EndIf                 ElseIf Not BitAND($iFlags, $INI_REPLACEONLY) Then                     $hIniFile &= $sKeyName & $scKeyName & $sValue & @CRLF                 Else                     Return SetError(0, 0, 0)                 EndIf             EndIf         EndIf         Return SetError(0, 1, 0)     Else         If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")         ;;;;If Not $sSectionName Then Return SetError(2, 0, "")    ;Invalid Section Name         If StringInStr($sSectionName, "\E", 1) Then $sSectionName = StringReplace($sSectionName, "\E", "\e", 0, 1)         Local $aKeyValue[2][3] = [[1],[$sKeyName,"",$sKeyName & $scKeyName & $sValue]]         $iFlags = BitOR(BitXOR($iFlags, BitAND($iFlags, $INI_REMOVE_RENAME)), $INI_MERGE)         If $_HINI[$hIniFile][7] <> $sSectionName Or ($_HINI[$hIniFile][8] > 1 And BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) <> BitAND($_HINI[$hIniFile][9], $INI_MERGE_NOOCCURRENCE)) Then             __IniReadSectionEx($hIniFile, $sSectionName, $iFlags, $_HINI[$hIniFile][1])             If @Error Then Return SetError(3, 0, "")         EndIf         __IniWriteSectionEx($hIniFile, $sSectionName, $aKeyValue, $iFlags, $scKeyName, $_HINI[$hIniFile][1])     EndIf     Return SetError(@Error, @Extended, 0) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniWriteSectionEx ; Description ...: Add\Replace\Delete\Remove\Rename\Change\Edit a Section\KeyName\Value\Data in INI File. ; Syntax.........: _IniWriteSectionEx() ; Parameters ....: $hIniFile     - Handle to the INI file to query "see _IniOpenFileEx()" ;                   $sSectionName - The name of the section containing the Key\Value\Data ;                  $aKeyValue    - String\Text Data (example 'KeyName=Value 7 @LF & KeyName2=Value2') or an 2DArray is passed as data, the return Array of IniReadSectionEx() can be used immediately. ;                    If $aKeyValue is String\Text Data and $INI_OVERWRITEALL or $INI_APPENDDATA if Set\Used, $aKeyValue will be writte exactly as in $aKeyValue (without Edit\Formatting) ;                   $iFlags       - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ;                  |$INI_STRIPLEADING (1)         - strip leading white space Section, This Flag will be ignored if the $INI_OVERWRITEALL or $INI_APPENDDATA is set\used ;                  |$INI_STRIPTRAILING (2)        - trailing white space Section, This Flag will be ignored if the $INI_OVERWRITEALL or $INI_APPENDDATA is set\used ;                  |$INI_NOOCCURRENCE (512)       - Check only first section if there are more than one ;                  |$INI_NOCREATE (2048)          - Not Create New Section If Section Not Exist ;                  |$INI_APPENDDATA (4096)        - Add KeyName\Value\Data (Append Mod) ;                  |$INI_REPLACEONLY (8192)       - Add KeyName\Value\Data Only if Exist ;                  |$INI_NOOVERWRITE (32768)      - Add KeyName\Value\Data Only if Not Exist ;                  |$INI_OVERWRITEALL (65536)     - Overwrite All data in Section (Replaces all KeyName\Value\Data in the Section) ;                  |$INI_IGNOREDUPLICATE (131072) - Proceed\Execute (Add\Delete\Replace\Edit ect ect) Once Only (Ignore all other Duplicate\Occurrences of KeyName\Value\Data) ;                  |$INI_DELETE (262144)          - Delete\Remove KeyName\Value\Data ;                  |$INI_RENAME (524288)          - Renames a section ;                  |$INI_REMOVE (1048576)         - Remove\Delete Section ;                   $scKeyName     - Optional, Key-Name separator character, Default is '=', This parameter can not be '"' or @CR or @LF ; Return values .: Returns a 0 (check @Extended for number of edit performed) ;                  @Error  - 0 = No error. ;                  |1 = Invalid IniHandle. ;                  |3 = SectionName's not found ;                  |5 = Invalid KeyName ; Remarks .......: ; Author ........: DXRW4E ; Remarks .......: $INI_MERGE (1024) - (Join section if more than one in INI file) is always set\used by default, to disable it just use the $INI_NOOCCURRENCE ; =============================================================================================================================== Func _IniWriteSectionEx(ByRef $hIniFile, $sSectionName, $aKeyValue, $iFlags = 0, $scKeyName = "=") ;~     If $sSectionName = $NULL_REF Then ;~         If Not $scKeyName Then $scKeyName = "=" ;~         If IsArray($aKeyValue) Then ;~             Local $iCols = UBound($aKeyValue, 2) ;~             If UBound($aKeyValue, 0) <> 2 Or $iCols < 2 Then Return SetError(7, 0, "") ;~             If $iCols = 2 Then ;~                 ReDim $aKeyValue[$aKeyValue[0][0] + 1][3] ;~                 For $i = 1 To $aKeyValue[0][0] ;~                     $aKeyValue[$i][2] = $aKeyValue[$i][0] & $scKeyName & $aKeyValue[$i][1] ;~                 Next ;~             EndIf ;~         ElseIf Not BitAND($iFlags, $INI_OVERWRITEALL_APPENDDATA) Then ;~             $aKeyValue = _IniReadSectionEx($aKeyValue, Null, $INI_2DARRAYFIELD, $scKeyName) ;~             If @Error Then Return SetError(7, 0, "") ;~         EndIf ;~         If BitAND($iFlags, $INI_OVERWRITEALL_APPENDDATA) Then ;~             If BitAND($iFlags, $INI_OVERWRITEALL) Then $hIniFile = "" ;~             If IsArray($aKeyValue) Then ;~                 For $i = 1 To $aKeyValue[0][0] ;~                     $hIniFile &= $aKeyValue[$i][2] & @CRLF ;~                 Next ;~             Else ;~                 ;;    KeyName\Value\Text Data will be writte exactly as in $aKeyValue (without Edit\Formatting ect ect) ;~                 $hIniFile &= $aKeyValue & (StringRight($aKeyValue, 1) = @LF ? "" : @CRLF) ;~             EndIf ;~             Return SetError(0, 1, 0) ;~         Else ;~             Local $asKeyValue, $iKeyValue = 0, $sKNPattern, $iOffSet = StringInStr($hIniFile, @LF, 1) ;~             For $i = 1 To $aKeyValue[0][0] ;~                 $sKNPattern = '\n[\h\f\xb\x0]*(?i)(?>\Q"' & $aKeyValue[$i][0] & '"\E|\Q' & $aKeyValue[$i][0] & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*' ;~                 If StringRegExp(StringLeft($hIniFile, $iOffSet), '^(?i)[\h\f\xb\x0]*(?>\Q"' & $aKeyValue[$i][0] & '"\E|\Q' & $aKeyValue[$i][0] & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*') Then ;~                     If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $hIniFile = StringRegExpReplace($hIniFile, $sKNPattern, "") ;~                     If BitAND($iFlags, $INI_DELETE) Then ;~                         $hIniFile = StringTrimLeft($hIniFile, $iOffSet) ;~                     ElseIf Not BitAND($iFlags, $INI_NOOVERWRITE) Then ;~                         $hIniFile = $aKeyValue[$i][2] & @CRLF & StringTrimLeft($hIniFile, $iOffSet) ;~                     EndIf ;~                 ElseIf BitAND($iFlags, $INI_DELETE) Then ;~                     $hIniFile = StringRegExpReplace($hIniFile, $sKNPattern, "", (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? 1 : 0)) ;~                 Else ;~                     $asKeyValue = StringRegExp($hIniFile, $sKNPattern, 1) ;~                     $iOffSet = @Extended - 1 ;~                     If Not @Error Then ;~                         If BitAND($iFlags, $INI_NOOVERWRITE) Then ;~                             If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $hIniFile = StringLeft($hIniFile, $iOffSet) & StringRegExpReplace(StringTrimLeft($hIniFile, $iOffSet), $sKNPattern, "") ;~                         Else ;~                             $hIniFile = StringLeft($hIniFile, $iOffSet + 1 - StringLen($asKeyValue[0])) & $aKeyValue[$i][2] & @CR & (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? StringTrimLeft($hIniFile, $iOffSet) : StringRegExpReplace(StringTrimLeft($hIniFile, $iOffSet), $sKNPattern, "")) ;~                         EndIf ;~                     ElseIf Not BitAND($iFlags, $INI_REPLACEONLY) Then ;~                         $hIniFile &= $aKeyValue[$i][2] & @CRLF ;~                     Else ;~                         $iKeyValue -= 1 ;~                     EndIf ;~                 EndIf ;~                 $iKeyValue += 1 ;~             Next ;~             Return SetError(0, $iKeyValue, 0) ;~         EndIf ;~     EndIf     If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")     ;;;;If Not $sSectionName Then Return SetError(2, 0, "")    ;Invalid Section Name     If StringInStr($sSectionName, "\E", 1) Then $sSectionName = StringReplace($sSectionName, "\E", "\e", 0, 1)     If BitAND($iFlags, $INI_REMOVE) Then         __IniWriteSectionEx($hIniFile, $sSectionName, $INI_NULL_REF, $iFlags, $INI_NULL_REF, $_HINI[$hIniFile][1])     ElseIf BitAND($iFlags, $INI_RENAME) Then         ;;;;    $aKeyValue is New Section Name         ;;If Not $aKeyValue Then Return SetError(5, 0, "")         If BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) = $INI_MERGE And Not __IniReadSectionEx($hIniFile, $sSectionName, $iFlags, $_HINI[$hIniFile][1]) Then Return SetError(3, 0, 0)         __IniWriteSectionEx($hIniFile, $sSectionName, $aKeyValue, $iFlags, $INI_NULL_REF, $_HINI[$hIniFile][1])     Else         If Not $scKeyName Then $scKeyName = "="         If IsArray($aKeyValue) Then             Local $iCols = UBound($aKeyValue, 2)             If UBound($aKeyValue, 0) <> 2 Or $iCols < 2 Then Return SetError(5, 0, "")             If $iCols = 2 Then                 ReDim $aKeyValue[$aKeyValue[0][0] + 1][3]                 For $i = 1 To $aKeyValue[0][0]                     $aKeyValue[$i][2] = $aKeyValue[$i][0] & $scKeyName & $aKeyValue[$i][1]                 Next             EndIf         ElseIf Not BitAND($iFlags, $INI_OVERWRITEALL_APPENDDATA) Then             $aKeyValue = _IniReadSectionEx($aKeyValue, Null, $INI_2DARRAYFIELD, $scKeyName)             If @Error Then Return SetError(5, 0, "")         EndIf         $iFlags = BitOR($iFlags, $INI_MERGE)         If $_HINI[$hIniFile][7] <> $sSectionName Or ($_HINI[$hIniFile][8] > 1 And BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) <> BitAND($_HINI[$hIniFile][9], $INI_MERGE_NOOCCURRENCE)) Then             __IniReadSectionEx($hIniFile, $sSectionName, $iFlags, $_HINI[$hIniFile][1])             If @Error Then Return SetError(3, 0, "")         EndIf         __IniWriteSectionEx($hIniFile, $sSectionName, $aKeyValue, $iFlags, $scKeyName, $_HINI[$hIniFile][1])     EndIf     Return SetError(@Error, @Extended, 0) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniGetSectionNumberEx ; Description ...: The _IniGetSectionNumberEx Retrieves the number of all sections in an INI file ; Syntax.........: _IniGetSectionNumberEx(Byref $hIniFile) ; Parameters ....: $hIniFile      - Handle to the INI file to query "see _IniOpenFileEx()" ; Return values .: Number of Section's ;                  @Error  - 0 = No error. ;                  |1 = Invalid IniHandle. ;                  |3 = SectionName's not found ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniGetSectionNumberEx(ByRef $hIniFile)     If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then         Local $aSectionNames = StringRegExp(@LF & $hIniFile, "\n[\h\f\xb\x0]*\[[^\r\n]*\K\]", 3)    ;StringRegExp($hIniFile, "(?m)^[\h\f\xb\x0]*\[[^\r\n]*\]", 3)         Return SetError(@Error, 0, UBound($aSectionNames))     EndIf     Return SetError(($_HINI[$hIniFile][4] ? 0 : 3), 0, $_HINI[$hIniFile][4]) EndFunc   ;==>_IniGetSectionNumberEx ; #FUNCTION# =========================================================================================================== ; Name...........: _IniGetFileInformationEx ; Description ...: Returns information about an INI file ; Syntax.........: _IniGetFileInformationEx($hIniFile[, $iFlags]) ; Parameters ....: $hIniFile    - Handle of INI file previously opened by _IniOpenFileEx, see _IniOpenFileEx() ;                  $iFlags - Optional ;                  |0  - Return INI Handle (Default) ;                  |1  - Return INI File Array Data (is array of arrays) ;                  |2  - Return INI File Path ;                  |3  - Return INI Encoding ;                  |4  - Return INI Section Number ; Return values .: See Flag parameter ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: ; =============================================================================================================================== Func _IniGetFileInformationEx($hIniFile, $iFlags = 0)     If Not $hIniFile Then Return SetError(1, 0, "")     If $_HINI[0][1] < 0 Then         $_HINI[0][1] = 0         Return SetError(1, 0, "")     ElseIf IsString($hIniFile) Then         ;;If StringIsDigit($hIniFile) And StringLeft($hIniFile, 1) <> "0" Then         ;;    $hIniFile = Number($hIniFile)         ;;Else             For $i = 1 To $_HINI[0][0]                 If $_HINI[$i][2] = $hIniFile Then ExitLoop             Next             $hIniFile = $i         ;;EndIf     EndIf     If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")    ; Or $hIniFile <> $_HINI[$hIniFile][0]     If $iFlags < 1 Or $iFlags > 4 Then Return $hIniFile     Return SetError(0, $hIniFile, $_HINI[$hIniFile][$iFlags]) EndFunc   ;==>_IniGetFileInformationEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniGetFileStringData ; Description ...: The _IniGetFileStringData Retrieves all INI Lines\String\Text Data ; Syntax.........: _IniGetFileStringData(ByRef $hIniFile[, $iFlags]) ; Parameters ....: $hIniFile      - Handle to the INI file to query "see _IniOpenFileEx()" ;                   $iFlags        - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ;                  |$INI_STRIPLEADING (1)          - strip leading white space Section ;                  |$INI_STRIPTRAILING (2)         - strip trailing white space Section ; Return values .: String\Text Data ;                  @Error  - 0 = No error. ;                  |1 = Invalid IniHandle. ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniGetFileStringData(ByRef $hIniFile, $iFlags = 0)     If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")     ;;Local $sData, $iSL = BitAND($iFlags, $INI_STRIPLEADING), $iST = BitAND($iFlags, $INI_STRIPTRAILING)     ;;$sData = ($iSL ? "" : ($_HINI[$hIniFile][1])[3]) & ($_HINI[$hIniFile][1])[4] & ($iST ? "" : ($_HINI[$hIniFile][1])[5])     ;;For $i = 6 To ($_HINI[$hIniFile][1])[0] Step 6     ;;    $sData &= ($_HINI[$hIniFile][1])[$i] & ($_HINI[$hIniFile][1])[$i + 1] & ($_HINI[$hIniFile][1])[$i + 2] & ($iSL ? "" : ($_HINI[$hIniFile][1])[$i + 3]) & ($_HINI[$hIniFile][1])[$i + 4] & ($iST ? "" : ($_HINI[$hIniFile][1])[$i + 5])     ;;Next     Local $sData = __IniGetFileStringData($hIniFile, $iFlags, $_HINI[$hIniFile][1])     Return SetError(0, $_HINI[$hIniFile][3], $sData) EndFunc   ;==>_IniGetFileStringData ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniClearCache ; Description ...: Clear INI File Processing Functions Cache ; Syntax.........: _IniClearCache(ByRef $aIniFile) ; Parameters ....: $hIniFile     - Handle to the INI file to query "see _IniOpenFileEx()" ; Return values .: None ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: This function is useful to Run after _IniRea*Ex Funcion's, only in the case when in the INI file are duplicated function ;                   and if the flag $INI_MERGE or $INI_NOOCCURRENCE is not set\used, because in this case the _IniReadEx\_IniReadSectionEx saves ;                   in cache the Function's\String\Data to be fast during the loop ect ect, so only in cases when you Get\Read Occurrence Function ;                   and the flag $INI_MERGE or $INI_NOOCCURRENCE is not set\used ;                   All other function as _IniDeleteEx or _IniWrite*Ex use by Default or Force the use of $INI_MERGE flag ;                   So in 99.9% of cases you do not Need\Have to run _IniClearCache(), because the INI File Processing Functions Work's only By Reference ; =============================================================================================================================== Func _IniClearCache(ByRef $hIniFile)     If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")     $_HINI[$hIniFile][6] = ""     __IniSaveCache($hIniFile, $_HINI[$hIniFile][6], $INI_NULL_REF, $_HINI[$hIniFile][6], $_HINI[$hIniFile][6], $_HINI[$hIniFile][1])     Return 0 EndFunc   ;==>_IniClearCache ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniFileWrite ; Description ...: Write a Ini File ; Syntax.........: _IniFileWriteEx(ByRef $hIniFile[, $iFlags[, $sFilePath[, $iFileEncoding]]]) ; Parameters ....: $hIniFile      - Handle to the INI file to query "see _IniOpenFileEx()" ;                   $iFlags        - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ;                  |$INI_STRIPLEADING (1)     - strip leading white space Section ;                  |$INI_STRIPTRAILING (2)    - trailing white space Section ;                  |$INI_NOWRITEREADONLY (16) - Do not Write\Replace\Edit the ReadOnly file (Default Write\Replace\Edit the ReadOnly files) ;                   $sFilePath     - Optional, use alternative FilePath, By Default always is used (Default) PathFile ;                   $iFileEncoding - Optional, use alternative FileEncoding, By Default always is used (Default) FileEncoding ; Return values .: Returns a 0 ;                  @Error  - 0 = No error. ;                  |1  =  Invalid IniHandle. ;                  |9  =  Invalid FilePath ;                  |10 = A file may fail to open due to access rights or attributes. ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniFileWriteEx(ByRef $hIniFile, $iFlags = 0, $sFilePath = Default, $iFileEncoding = Default)     If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "")     If $_HINI[$hIniFile][2] = "FileQueue" And Not $sFilePath Then Return SetError(9, 0, "")     If $sFilePath = Default Then $sFilePath = $_HINI[$hIniFile][2]     If $iFileEncoding = Default Then $iFileEncoding = $_HINI[$hIniFile][3] + 10     ;;Local $hFileOpen, $iSL = BitAND($iFlags, $INI_STRIPLEADING), $iST = BitAND($iFlags, $INI_STRIPTRAILING)     ;;$hFileOpen = FileOpen($_HINI[$hIniFile][2], $_HINI[$hIniFile][3] + 10)     ;; ;; Check if file opened for writing OK     ;;If $hFileOpen = -1 Then     ;;    Return SetError(10, 0, 0)     ;;EndIf     ;;FileWrite($hFileOpen, ($iSL ? "" : ($_HINI[$hIniFile][1])[3]) & ($_HINI[$hIniFile][1])[4] & ($iST ? "" : ($_HINI[$hIniFile][1])[5]))     ;;For $i = 6 To ($_HINI[$hIniFile][1])[0] Step 6     ;;    FileWrite($hFileOpen, ($_HINI[$hIniFile][1])[$i] & ($_HINI[$hIniFile][1])[$i + 1] & ($_HINI[$hIniFile][1])[$i + 2] & ($iSL ? "" : ($_HINI[$hIniFile][1])[$i + 3]) & ($_HINI[$hIniFile][1])[$i + 4] & ($iST ? "" : ($_HINI[$hIniFile][1])[$i + 5]))     ;;Next     ;;FileClose($hFileOpen)     __IniFileWriteEx($hIniFile, $iFlags, $sFilePath, $iFileEncoding, $_HINI[$hIniFile][1])     Return SetError(@Error, @Extended, 0) EndFunc   ;==>_IniFileWriteEx ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __IniReadSectionEx ; Description ...: Support Function for _IniReadSectionEx ; Syntax.........: __IniReadSectionEx(ByRef $aIniFile, ByRef $sSectionName, ByRef $iFlags) ; Parameters ....: See _IniReadSectionEx() ; Return values .: See _IniReadSectionEx() ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: This function is used internally by _IniReadSectionEx ; =============================================================================================================================== Func __IniReadSectionEx(ByRef $hIniFile, ByRef $sSectionName, ByRef $iFlags, ByRef $aIniFile)     ;;;;If Not $sSectionName Then Return SetError(2, 0, "")    ;Invalid Section Name     If StringInStr($sSectionName, "\E", 1) Then $sSectionName = StringReplace($sSectionName, "\E", "\e", 0, 1)     Local $sSectionData, $aSectionName, $iSectionName = 1     $aSectionName = StringRegExp($_HINI[$hIniFile][5], "\n(?is)\Q" & $sSectionName & "\E\r([^\n]+)", 3)     If @Error Then         If BitAND($iFlags, $INI_NOCREATE_REMOVE_DELETE) Then Return SetError(3, 0, "")         $aIniFile[0] += 6         Redim $aIniFile[$aIniFile[0] + 1]         $aIniFile[$aIniFile[0] - 5] = "["         $aIniFile[$aIniFile[0] - 4] = $sSectionName         $aIniFile[$aIniFile[0] - 3] = "]" & @CRLF         $_HINI[$hIniFile][4] += 1         $_HINI[$hIniFile][5] &= @LF & $sSectionName & @CR & ($aIniFile[0] - 4)         $_HINI[$hIniFile][6] = $aIniFile[0] - 1     Else         $_HINI[$hIniFile][6] = $aSectionName[0] + 3         $iSectionName = UBound($aSectionName)         ;;If BitAND($iFlags, $INI_STRIPLEADTRAILING) = $INI_STRIPLEADTRAILING Then    ;; BitOR($INI_STRIPLEADING,  $INI_STRIPTRAILING)         ;;    $sSectionData = $aIniFile[$aSectionName[0] + 3]         ;;ElseIf BitAND($iFlags, $INI_STRIPLEADING) Then         ;;    $sSectionData = $aIniFile[$aSectionName[0] + 3] & $aIniFile[$aSectionName[0] + 4]         ;;ElseIf BitAND($iFlags, $INI_STRIPTRAILING) Then         ;;    $sSectionData = $aIniFile[$aSectionName[0] + 2] & $aIniFile[$aSectionName[0] + 3]         ;;Else         ;;    $sSectionData = $aIniFile[$aSectionName[0] + 2] & $aIniFile[$aSectionName[0] + 3] & $aIniFile[$aSectionName[0] + 4]         ;;EndIf         If Not BitAND($iFlags, $INI_NOOCCURRENCE) And $iSectionName > 1 Then             $sSectionData = $aIniFile[$aSectionName[0] + 3]             For $i = 1 To $iSectionName - 1                 $sSectionData &= $aIniFile[$aSectionName[$i] + 3]                 If BitAND($iFlags, $INI_MERGE) Then                     For $y = $aSectionName[$i] - 1 To $aSectionName[$i] + 4                         $aIniFile[$y] = ""                     Next                     $_HINI[$hIniFile][5] = StringRegExpReplace($_HINI[$hIniFile][5], '\n(?is)\Q' & $sSectionName & '\E\r' & $aSectionName[$i], "")                 EndIf             Next             If BitAND($iFlags, $INI_MERGE) Then $aIniFile[$aSectionName[0] + 3] = $sSectionData         EndIf     EndIf     __IniSaveCache($hIniFile, $sSectionData, $sSectionName, $iFlags, $iSectionName, $aIniFile)     Return $iSectionName    ;SetError(Not $iSectionName, $iSectionName, $sSectionData) EndFunc   ;==>__IniReadSectionEx ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __IniWriteSectionEx ; Description ...: Support Function for _IniWriteSectionEx ; Syntax.........: __IniWriteSectionEx(ByRef $hIniFile, ByRef $sSectionName, ByRef $aKeyValue, ByRef $iFlags, ByRef $scKeyName, ByRef $aIniFile) ; Parameters ....: See _IniWriteSectionEx() ; Return values .: See _IniWriteSectionEx() ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: This function is used internally by _IniWriteSectionEx ; =============================================================================================================================== Func __IniWriteSectionEx(ByRef $hIniFile, ByRef $sSectionName, ByRef $aKeyValue, ByRef $iFlags, ByRef $scKeyName, ByRef $aIniFile)     If BitAND($iFlags, $INI_REMOVE) Then         Local $iaSectionName, $aSectionName = StringRegExp($_HINI[$hIniFile][5], '\n(?is)\Q' & $sSectionName & '\E\r([^\n]+)', 3)         If @Error Then Return SetError(3, 0, 0)         $iaSectionName = UBound($aSectionName) - 1         If BitAND($iFlags, $INI_NOOCCURRENCE) Then $iaSectionName = 0         For $i = 0 To $iaSectionName             For $y = $aSectionName[$i] - 1 To $aSectionName[$i] + 4                 $aIniFile[$y] = ""             Next         Next         $_HINI[$hIniFile][4] -= $iaSectionName + 1         $_HINI[$hIniFile][5] = StringRegExpReplace($_HINI[$hIniFile][5], '\n(?is)\Q' & $sSectionName & '\E\r[^\r\n]+', "", Int($iaSectionName = 0))         Return SetError(0, @Extended, 0)     ElseIf BitAND($iFlags, $INI_RENAME) Then         Local $iaSectionName, $aSectionName = StringRegExp($_HINI[$hIniFile][5], '\n(?is)\Q' & $sSectionName & '\E\r([^\n]+)', 3)         If @Error Then Return SetError(3, 0, 0)         $iaSectionName = UBound($aSectionName) - 1         If BitAND($iFlags, $INI_NOOCCURRENCE) Then $iaSectionName = 0         ;; $aKeyValue is New Section Name         For $i = 0 To $iaSectionName             $aIniFile[$aSectionName[$i]] = $aKeyValue         Next         $_HINI[$hIniFile][5] = StringRegExpReplace($_HINI[$hIniFile][5], '\n\K(?is)\Q' & $sSectionName & '\E(?=\r)', StringReplace(StringReplace($aKeyValue, "\", "\\", 0, 1), "\E", "\e", 0, 1), Int($iaSectionName = 0))         Return SetError(0, @Extended, 0)     Else         Local $iSN = $_HINI[$hIniFile][10]         If BitAND($iFlags, $INI_OVERWRITEALL_APPENDDATA) Then             If BitAND($iFlags, $INI_OVERWRITEALL) Then $aIniFile[$iSN] = ""             If BitAND($iFlags, $INI_STRIPLEADING) Then $aIniFile[$iSN - 1] = ""             If BitAND($iFlags, $INI_STRIPTRAILING) Then $aIniFile[$iSN + 1] = ""             If IsArray($aKeyValue) Then                 For $i = 1 To $aKeyValue[0][0]                     $aIniFile[$iSN] &= $aKeyValue[$i][2] & @CRLF                 Next             Else                 ;;    KeyName\Value\Text Data will be writte exactly as in $aKeyValue (without Edit\Formatting ect ect)                 $aIniFile[$iSN] &= $aKeyValue & (StringRight($aKeyValue, 1) = @LF ? "" : @CRLF)             EndIf             Return SetError(0, 1, 0)         Else             Local $asKeyValue, $iKeyValue = 0, $sKNPattern, $iOffSet = StringInStr($aIniFile[$iSN], @LF, 1)             For $i = 1 To $aKeyValue[0][0]                 $sKNPattern = '\n[\h\f\xb\x0]*(?i)(?>\Q"' & $aKeyValue[$i][0] & '"\E|\Q' & $aKeyValue[$i][0] & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*'                 If StringRegExp(StringLeft($aIniFile[$iSN], $iOffSet), '^(?i)[\h\f\xb\x0]*(?>\Q"' & $aKeyValue[$i][0] & '"\E|\Q' & $aKeyValue[$i][0] & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*') Then                     If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $aIniFile[$iSN] = StringRegExpReplace($aIniFile[$iSN], $sKNPattern, "")                     If BitAND($iFlags, $INI_DELETE) Then                         $aIniFile[$iSN] = StringTrimLeft($aIniFile[$iSN], $iOffSet)                     ElseIf Not BitAND($iFlags, $INI_NOOVERWRITE) Then                         $aIniFile[$iSN] = $aKeyValue[$i][2] & @CRLF & StringTrimLeft($aIniFile[$iSN], $iOffSet)                     EndIf                 ElseIf BitAND($iFlags, $INI_DELETE) Then                     $aIniFile[$iSN] = StringRegExpReplace($aIniFile[$iSN], $sKNPattern, "", (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? 1 : 0))                 Else                     $asKeyValue = StringRegExp($aIniFile[$iSN], $sKNPattern, 1)                     $iOffSet = @Extended - 1                     If Not @Error Then                         If BitAND($iFlags, $INI_NOOVERWRITE) Then                             If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $aIniFile[$iSN] = StringLeft($aIniFile[$iSN], $iOffSet) & StringRegExpReplace(StringTrimLeft($aIniFile[$iSN], $iOffSet), $sKNPattern, "")                         Else                             $aIniFile[$iSN] = StringLeft($aIniFile[$iSN], $iOffSet + 1 - StringLen($asKeyValue[0])) & $aKeyValue[$i][2] & @CR & (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? StringTrimLeft($aIniFile[$iSN], $iOffSet) : StringRegExpReplace(StringTrimLeft($aIniFile[$iSN], $iOffSet), $sKNPattern, ""))                         EndIf                     ElseIf Not BitAND($iFlags, $INI_REPLACEONLY) Then                         $aIniFile[$iSN] &= $aKeyValue[$i][2] & @CRLF                     Else                         $iKeyValue -= 1                     EndIf                 EndIf                 $iKeyValue += 1             Next             Return SetError(0, $iKeyValue, 0)         EndIf     EndIf EndFunc ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __IniFileWriteEx ; Description ...: Support Function for _IniFileWriteEx ; Syntax.........: __IniFileWriteEx(ByRef $hIniFile, ByRef $iFlags, ByRef $sFilePath, ByRef $iFileEncoding, ByRef $aIniFile) ; Parameters ....: See _IniFileWriteEx() ; Return values .: See _IniFileWriteEx() ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: This function is used internally by _IniFileWriteEx ; =============================================================================================================================== Func __IniFileWriteEx(ByRef $hIniFile, ByRef $iFlags, ByRef $sFilePath, ByRef $iFileEncoding, ByRef $aIniFile)     Local $hFileOpen, $iSL = BitAND($iFlags, $INI_STRIPLEADING), $iST = BitAND($iFlags, $INI_STRIPTRAILING), $iReadOnly = 0     $hFileOpen = FileOpen($sFilePath, $iFileEncoding)     ; Check if file opened for writing OK     If $hFileOpen = -1 Then         If Not BitAND($iFlags, $INI_NOWRITEREADONLY) And StringInStr(FileGetAttrib($sFilePath), "R") Then             FileSetAttrib($sFilePath, "-R")             $iReadOnly = 1             $hFileOpen = FileOpen($sFilePath, $iFileEncoding)             If $hFileOpen = -1 Then Return SetError(10, 0, 0)         Else             Return SetError(10, 0, 0)         EndIf     EndIf     FileWrite($hFileOpen, ($iSL ? "" : $aIniFile[3]) & $aIniFile[4] & ($iST ? "" : $aIniFile[5]))     For $i = 6 To $aIniFile[0] Step 6         FileWrite($hFileOpen, $aIniFile[$i] & $aIniFile[$i + 1] & $aIniFile[$i + 2] & ($iSL ? "" : $aIniFile[$i + 3]) & $aIniFile[$i + 4] & ($iST ? "" : $aIniFile[$i + 5]))     Next     FileClose($hFileOpen)     If $iReadOnly Then FileSetAttrib($sFilePath, "+R")     Return 0 EndFunc   ;==>__IniFileWriteEx ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __IniGetFileStringData ; Description ...: Support Function for _IniGetFileStringData ; Syntax.........: __IniGetFileStringData(ByRef $hIniFile, ByRef $iFlags, ByRef $aIniFile) ; Parameters ....: See _IniGetFileStringData() ; Return values .: See _IniGetFileStringData() ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: This function is used internally by _IniGetFileStringData ; =============================================================================================================================== Func __IniGetFileStringData(ByRef $hIniFile, ByRef $iFlags, ByRef $aIniFile)     Local $sData, $iSL = BitAND($iFlags, $INI_STRIPLEADING), $iST = BitAND($iFlags, $INI_STRIPTRAILING)     Local $sData = ($iSL ? "" : $aIniFile[3]) & $aIniFile[4] & ($iST ? "" : $aIniFile[5])     For $i = 6 To $aIniFile[0] Step 6         $sData &= $aIniFile[$i] & $aIniFile[$i + 1] & $aIniFile[$i + 2] & ($iSL ? "" : $aIniFile[$i + 3]) & $aIniFile[$i + 4] & ($iST ? "" : $aIniFile[$i + 5])     Next     Return $sData EndFunc   ;==>__IniGetFileStringData ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __IniSaveCache ; Description ...: Save in Cache last Read Section ; Syntax.........: __IniSaveCache(ByRef $hIniFile, ByRef $sSectionData, ByRef $sSectionName, ByRef $iFlags, ByRef $iSectionName, ByRef $aIniFile) ; Parameters ....: $hIniFile     - Handle to the INI file to query "see _IniOpenFileEx()" ;                  $sSectionData - Section Strings text/data ;                  $sSectionName - Section Name ;                  $iFlags       - Section Flags ;                  $iSectionName - Number of SectionName in INI File ;                  $aIniFile     - Array of INI File ; Return values .: None ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: This function is Internal Only ; =============================================================================================================================== Func __IniSaveCache(ByRef $hIniFile, ByRef $sSectionData, ByRef $sSectionName, ByRef $iFlags, ByRef $iSectionName, ByRef $aIniFile)     $_HINI[$hIniFile][7] = $sSectionName     $_HINI[$hIniFile][8] = (BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) = $INI_MERGE) ? 1 : $iSectionName     $_HINI[$hIniFile][9] = $iFlags     If $iSectionName > 1 And Not BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) Then         $aIniFile[1] = $sSectionData         $_HINI[$hIniFile][10] = 1     Else         $aIniFile[1] = ""         $_HINI[$hIniFile][10] = $_HINI[$hIniFile][6]     EndIf     Return 0 EndFunc   ;==>__IniSaveCache ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __GetSeparatorCharacter ; Description ...: Get Separator Character (non present character) ; Syntax.........: __GetSeparatorCharacter(ByRef $sData) ; Parameters ....: $sData  - INI String\Text Data ; Return values .: None ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: For Internal Use Only ; =============================================================================================================================== Func __GetSeparatorCharacter(ByRef $sData)     If Not StringInStr($sData, ChrW(8232), 1) Then Return ChrW(8232)     If Not StringInStr($sData, ChrW(8233), 1) Then Return ChrW(8233)     For $i = 1 To 31         If $i > 8 And $i < 14 Then ContinueLoop         If Not StringInStr($sData, Chr($i), 1) Then Return Chr($i)     Next     $sData = StringRegExpReplace($sData, '\r\n?', @LF)     Return @CR EndFunc   ;==>__GetSeparatorCharacter example
    #include <IniEx.au3> #include <Array.au3> Local $sData = @CRLF, $aData, $iData, $iTimerDiff, $hIniFile FileDelete(@DesktopDir & "\Test.ini") For $i = 1 To 10 $sData &= "[SectionName_" & $i & "]" & @CRLF For $y = 1 to 100000 $sData &= "KeyName" & $y & " = Value" & $y & @CRLF Next Next FileWrite(@DesktopDir & "\Test.ini", $sData)    ;25 MB - 1.000.000 Line, Key-Value $sData = "" $iTimerDiff = TimerInit() ;;_IniOpenFileEx() $hIniFile = _IniOpenFileEx(@DesktopDir & "\Test.ini") If @Error Then ConsoleWrite("Error - " & @Error & @LF) Exit EndIf $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("_IniOpenFileEx TimerDiff - " & $iTimerDiff & @LF) $iTimerDiff = TimerInit() ;;_IniGetSectionNumberEx() $iData = _IniGetSectionNumberEx($hIniFile) If @Error Then ConsoleWrite("Error - " & @Error & @LF) Exit EndIf $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniGetSectionNumberEx TimerDiff - " & $iTimerDiff & @LF) ConsoleWrite("SectionNumber - " & $iData & @LF & @LF) $iTimerDiff = TimerInit() ;;_IniRenameSectionEx() _IniRenameSectionEx($hIniFile, "SectionName_10", "SectionName_111") If @Error Then ConsoleWrite("Error - " & @Error & @LF) Exit EndIf $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniRenameSectionEx TimerDiff - " & $iTimerDiff & @LF & @LF) $iTimerDiff = TimerInit() ;;_IniReadSectionNamesEx() $aData = _IniReadSectionNamesEx($hIniFile) If @Error Then ConsoleWrite("Error - " & @Error & @LF) Exit EndIf $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniReadSectionNamesEx TimerDiff - " & $iTimerDiff & @LF & @LF) _ArrayDisplay($aData) $iTimerDiff = TimerInit() ;;_IniReadSectionEx() $sData = _IniReadSectionEx($hIniFile, "SectionName_8") $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniReadSectionEx TimerDiff - " & $iTimerDiff & @LF & @LF) ;;ConsoleWrite($sData & @LF & @LF) ;;MsgBox(0, "SectionName_8", $sData) $iTimerDiff = TimerInit() ;;_IniReadSectionEx() $aData = _IniReadSectionEx($hIniFile, "SectionName_8", $INI_2DARRAYFIELD) ;$INI_NOOCCURRENCE + $INI_MERGE + $INI_2DARRAYFIELD $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniReadSectionEx TimerDiff - " & $iTimerDiff & @LF & @LF) _ArrayDisplay($aData, "IniReadSectionEx") $iTimerDiff = TimerInit() ;;_IniReadEx() $sData = _IniReadEx($hIniFile, "SectionName_8", "KeyName99980") $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniReadEx TimerDiff - " & $iTimerDiff& @LF) ConsoleWrite($sData & @LF & @LF) $iTimerDiff = TimerInit() ;;_IniReadEx() $aData = _IniReadEx($hIniFile, "SectionName_8", "KeyName99988", "Default Return", $INI_ARRAYDATA) ;$INI_NOOCCURRENCE + $INI_MERGE + $INI_ARRAYDATA $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniReadEx TimerDiff - " & $iTimerDiff & @LF) ConsoleWrite($aData[1] & @LF & @LF) _ArrayDisplay($aData, "IniReadEx") $iTimerDiff = TimerInit() ;;_IniDeleteEx() _IniDeleteEx($hIniFile, "SectionName_8", "KeyName99988") ;$INI_IGNOREDUPLICATE + $INI_NOOCCURRENCE + $INI_REMOVE $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniDeleteEx TimerDiff - " & $iTimerDiff & @LF & @LF) $iTimerDiff = TimerInit() ;;_IniWriteSectionEx() _IniWriteSectionEx($hIniFile, "SectionName_8", "KeyNameX = ValueX") ; $INI_NOOCCURRENCE + $INI_IGNOREDUPLICATE + $INI_MERGE + $INI_REMOVE + $INI_OVERWRITEALL + $INI_APPENDDATA $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniWriteSectionEx TimerDiff - " & $iTimerDiff & @LF & @LF) ConsoleWrite(_IniReadEx($hIniFile, "SectionName_8", "KeyNameX") & @LF) $iTimerDiff = TimerInit() For $i = 1 To 5     _IniWriteSectionEx($hIniFile, "SectionName_8", "KeyNameX" & $i & " =  ValueX" & $i) Next For $i = 6 To 10     _IniWriteEx($hIniFile, "SectionName_8", "KeyNameX" & $i, "ValueX" & $i) Next $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniWrite*Ex TimerDiff - " & $iTimerDiff & @LF) $iTimerDiff = TimerInit() ;;_IniReadEx() For $i = 1 To 10 ConsoleWrite(_IniReadEx($hIniFile, "SectionName_8", "KeyNameX" & $i) & @LF) Next $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniReadEx TimerDiff - " & $iTimerDiff & @LF) _IniCloseFileEx($hIniFile) Exit ;~ >Running:(3.3.11.3):C:\Program Files (x86)\AutoIt3\Beta\autoit3.exe "C:\Users\DXRW4E\Desktop\New AutoIt v3 Script.au3"     ;~ --> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop ;~ _IniOpenFileEx TimerDiff - 2656.48548057389 ;~ IniGetSectionNumberEx TimerDiff - 0.0343594296492653 ;~ SectionNumber - 10 ;~   ;~ IniRenameSectionEx TimerDiff - 0.204971769976651 ;~   ;~ IniReadSectionNamesEx TimerDiff - 0.0584505240010489 ;~   ;~ IniReadSectionEx TimerDiff - 6.80316707055452 ;~   ;~ IniReadSectionEx TimerDiff - 1831.04639075913 ;~   ;~ IniReadEx TimerDiff - 24.1380917325683 ;~ Value99980 ;~   ;~ IniReadEx TimerDiff - 111.67841469541 ;~ Value99988 ;~   ;~ IniDeleteEx TimerDiff - 43.9488700091941 ;~   ;~ IniWriteSectionEx TimerDiff - 28.2560891228314 ;~   ;~ ValueX ;~ IniWrite*Ex TimerDiff - 261.353224415258 ;~ ValueX1 ;~ ValueX2 ;~ ValueX3 ;~ ValueX4 ;~ ValueX5 ;~ ValueX6 ;~ ValueX7 ;~ ValueX8 ;~ ValueX9 ;~ ValueX10 ;~ IniReadEx TimerDiff - 261.622965684803 ;~ +>00:07:21 AutoIt3.exe ended.rc:0 ;~ >Exit code: 0    Time: 5.914 ; $INI_OPEN_FILEQUEUE (268435456) - Open INI file from Memory\Variable, $sFilePath must contain String Text Data of INI file $hIniFile = _IniOpenFileEx(@DesktopDir & "\Test.ini") ;ect ect ect ;or $hIniFile = _IniOpenFileEx($sData, $INI_OPEN_FILEQUEUE) ;ect ect ect ;Or direct mode, without load ini or using handles ; $sSectionName - The name of the section containing the Key\Value, This parameter can be NULL (use the $NULL_REF to set NULL this parameter) ; If $sSectionName is NULL, $hIniFile must be contain Section String\Key\Value\Data ;; _IniDeleteEx($hIniFile, $sSectionName, $sKeyName) _IniDeleteEx($sData, $NULL_REF, $sKeyName) ;$NULL_REF = NULL ;; _IniReadEx($hIniFile, $sSectionName, $sKeyName) _IniDeleteEx($sData, $NULL_REF, $sKeyName) ;$NULL_REF = NULL ;; _IniReadSectionEx($hIniFile, $sSectionName, $sKeyName) _IniReadSectionEx($sData, $NULL_REF, $sKeyName) ;$NULL_REF = NULL ;; _IniWriteEx($hIniFile, $sSectionName, $sKeyName, $sValue) _IniWriteEx($sData, $NULL_REF, $sKeyName, $sValue) ;$NULL_REF = NULL ;;ect ect ect So for all other functions  
    IniEx.au3
  19. Like
    DXRW4E got a reaction from michaelslamet in Another RegEx help needed   
    StringRegExpReplace("20101006152623", "(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})", "$1-$2-$3 $4:$5:$6") Ciao.
  20. Like
    DXRW4E got a reaction from SirWayNe in _XLSXReadToArray (using only Autoit)   
    Hi SirWayNe, thanks for reporting, try now?

    Ciao.
  21. Like
    DXRW4E reacted to Zedna in StringRepeat - very fast (using memset)   
    This function is very fast compared to standard _StringRepeat() when number of repeated chars is big.
    In my tests this version is faster than original for > 50 chars.
    Time needed for this new StringRepeat() is constant no matter how many chars you repeat (nCount)
    so for big numbers of repeated characters it's MUCH FASTER (hundred times).

    StringRepeat Function:

    Func StringRepeat($sChar, $nCount) $tBuffer = DLLStructCreate("char[" & $nCount & "]") DllCall("msvcrt.dll", "ptr:cdecl", "memset", "ptr", DLLStructGetPtr($tBuffer), "int", Asc($sChar), "int", $nCount) Return DLLStructGetData($tBuffer, 1) EndFunc
    Testing example for compare speed with standard _StringRepeat (try to change number of chars):

    #include <String.au3> $start = TimerInit() _StringRepeat('a',1000) ConsoleWrite(TimerDiff($start)& @CRLF) $start = TimerInit() StringRepeat('a',1000) ConsoleWrite(TimerDiff($start)& @CRLF) Func StringRepeat($sChar, $nCount) $tBuffer = DLLStructCreate("char[" & $nCount & "]") DllCall("msvcrt.dll", "ptr:cdecl", "memset", "ptr", DLLStructGetPtr($tBuffer), "int", Asc($sChar), "int", $nCount) Return DLLStructGetData($tBuffer, 1) EndFunc
    EDIT:
    There is one difference/limitation from original _StringRepeat(): This new StringRepeat() can repeat only one character, so it's not posiible to do: StringRepeat('abc',3) --> result is 'aaa'
    Maybe I should change its name from StringRepeat() to CharRepeat()

    EDIT2:
    Here is MemSet in form of UDF:

    Func MemSet($pDest, $nChar, $nCount) DllCall("msvcrt.dll", "ptr:cdecl", "memset", "ptr", $pDest, "int", $nChar, "int", $nCount) If @error Then Return SetError(1,0,False) Return True EndFunc
  22. Like
    DXRW4E got a reaction from Xandy in Download Windows 7 image   
    http://www.heidoc.net/joomla/technology-science/microsoft/14-windows-7-direct-download-links

    Ciao.
  23. Like
    DXRW4E got a reaction from VelvetElvis in _FileListToArrayEx   
    Hi All, Sorry for my English


    #include-once ; #UDF# ======================================================================================================================= ; Title .........: File List To Array ; AutoIt Version : 3.3.8.1 ; Language ......: English ; Description ...: Lists files and\or folders in a specified path (Similar to using Dir with the /B Switch) ; Author(s) .....: DXRW4E ; Notes .........: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;~ _FileListToArrayEx ; =============================================================================================================================== ; #FUNCTION# ======================================================================================================================================================= ; Name...........: _FileListToArrayEx ; Description ...: Lists files and\or folders in a specified path (Similar to using Dir with the /B Switch) ; Syntax.........: _FileListToArrayEx($sPath[, $sFilter = "*"[, $iFlag = 0]]) ; Parameters ....: $sPath - Path to generate filelist for. ; $sFilter - Optional the filter to use, default is *. (Multiple filter groups such as "All "*.png|*.jpg|*.bmp") Search the Autoit3 helpfile for the word "WildCards" For details. ; $iFlag - Optional: specifies whether to return files folders or both Or Full Path (add the flags together for multiple operations): ; |$iFlag = 0 (Default) Return both files and folders ; |$iFlag = 1 Return files only ; |$iFlag = 2 Return Folders only ; |$iFlag = 4 Search SubDirectory ; |$iFlag = 8 Return Full Path ; |$iFlag = 16 $sFilter do Case-Sensitive matching (By Default $sFilter do Case-Insensitive matching) ; |$iFlag = 32 Disable the return the count in the first element - effectively makes the array 0-based (must use UBound() to get the size in this case). ; By Default the first element ($array[0]) contains the number of file found, the remaining elements ($array[1], $array[2], etc.) ; |$iFlag = 64 $sFilter is REGEXP Mod, See Pattern Parameters in StringRegExp (Can not be combined with flag 16) ; |$iFlag = 128 Return Backslash at the beginning of the file name, example Return "\Filename1.xxx" (Can not be combined with flag 8) ; Return values .: Failure - @Error ; |1 = Path not found or invalid ; |2 = Invalid $sFilter ; |3 = No File(s) Found ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: The array returned is one-dimensional and is made up as follows: ; $array[0] = Number of Files\Folders returned ; $array[1] = 1st File\Folder ; $array[2] = 2nd File\Folder ; $array[3] = 3rd File\Folder ; $array[n] = nth File\Folder ; Related .......: ; Link ..........: ; Example .......: Yes ; Note ..........: Special Thanks to SolidSnake & Tlem ; ================================================================================================================================================================== Func _FileListToArrayEx($sPath, $sFilter = "*", $iFlag = 0) $sPath = StringRegExpReplace($sPath & "\", "(?!\A)[\\/]+\h*", "\\") If Not FileExists($sPath) Then Return SetError(1, 1, "") If StringRegExp($sFilter, StringReplace('^\s*$|\v|[\\/:><"]|^\||\|\||\|$', "[" & Chr(BitAND($iFlag, 64) + 28) & '\/:><"]|^\||\|\||\|$', "\\\\")) Then Return SetError(2, 2, "") Local $hSearch, $sFile, $sFileList, $sSubDir = BitAND($iFlag, 4), $sDelim = "|", $sDirFilter = StringReplace($sFilter, "*", "") $hSearch = FileFindFirstFile($sPath & "*") If @Error Then Return SetError(3, 3, "") Local $hWSearch = $hSearch, $hWSTMP, $SearchWD, $Extended, $iFlags = StringReplace(BitAND($iFlag, 1) + BitAND($iFlag, 2), "3", "0") If BitAND($iFlag, 8) Then $sDelim &= $sPath If BitAND($iFlag, 128) Then $sDelim = "|\" If Not BitAND($iFlag, 64) Then $sFilter = StringRegExpReplace(BitAND($iFlag, 16) & "(?i)(", "16\(\?\i\)|\d+", "") & StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace($sFilter, "[^*?|]+", "\\Q$0\\E"), "\\E(?=\||$)", "$0\$"), "(?<=^|\|)\\Q", "^$0"), "\*+", ".*") & ")" While 1 $sFile = FileFindNextFile($hWSearch) If @Error Then If $hWSearch = $hSearch Then ExitLoop FileClose($hWSearch) $hWSearch -= 1 $SearchWD = StringLeft($SearchWD, StringInStr($SearchWD, "\", 1, -2)) ElseIf $sSubDir Then $Extended = @Extended If ($iFlags + $Extended <> 2) Then If $sDirFilter Then If StringRegExp($sFile, $sFilter) Then $sFileList &= $sDelim & $SearchWD & $sFile Else $sFileList &= $sDelim & $SearchWD & $sFile EndIf EndIf If Not $Extended Then ContinueLoop $hWSTMP = FileFindFirstFile($sPath & $SearchWD & $sFile & "\*") If $hWSTMP = -1 Then ContinueLoop $hWSearch = $hWSTMP $SearchWD &= $sFile & "\" Else If ($iFlags + @Extended = 2) Or StringRegExp($sFile, $sFilter) = 0 Then ContinueLoop $sFileList &= $sDelim & $sFile EndIf WEnd FileClose($hSearch) If Not $sFileList Then Return SetError(3, 3, "") Return StringSplit(StringTrimLeft($sFileList, 1), "|", StringReplace(BitAND($iFlag, 32), "32", 2)) EndFunc ;==>_FileListToArrayEx
    Registry Key List To Array - Read Registry KeySybKey
    _FileListToArrayEx.au3
  24. Like
    DXRW4E reacted to FredAI in Set Acl permissions UDF   
    Hi.

    I've been working on this for a while. I think now it's good enough to post it here.

    Functions to do most everything with the DACL and ownership on all types of objects: Files or folders, Registry keys, services, Kernel and WMI objects, etc.

    Here's a good example to test:

    #include 'Permissions.au3' _InitiatePermissionResources() FileWrite(@ScriptDir&'test.txt','Test') Local $TI = TimerInit() Local $ret = _DenyAllAccess(@ScriptDir&'test.txt',$SE_FILE_OBJECT,@UserName) Local $TD = TimerDiff($TI) MsgBox(0,'','Deny all access to test.txt and take ownership:'&@CRLF&@CRLF& _ '_DenyAllAccesss return value: '&$ret&' Time: '&Round($TD,2)&' miliseconds.'&@CRLF& _ 'Check the file permissons before closing the message box.') $TI = TimerInit() $ret = _GrantReadAccess(@ScriptDir&'test.txt',$SE_FILE_OBJECT,'Administrators') $TD = TimerDiff($TI) MsgBox(0,'','Grant everyone read access, all access to admins and system, and set the owner: Admins group'&@CRLF&@CRLF& _ '_GrantReadAccesss return value: '&$ret&' Time: '&Round($TD,2)&' miliseconds.'&@CRLF& _ 'Check the file permissons before closing the message box.') $TI = TimerInit() $ret = _GrantAllAccess(@ScriptDir&'test.txt') $TD = TimerDiff($TI) MsgBox(0,'','Grant everyone access'&@CRLF&@CRLF& _ '_GrantAllAccesss return value: '&$ret&' Time: '&Round($TD,2)&' miliseconds.'&@CRLF& _ 'Check the file permissons before closing the message box.') $TI = TimerInit() $ret = _CopyFullDacl(@ScriptDir&'test.txt',$SE_FILE_OBJECT,@ScriptDir) $TD = TimerDiff($TI) MsgBox(0,'','Restore all inherited permissions'&@CRLF&@CRLF& _ '_CopyFullDacl return value: '&$ret&' Time: '&Round($TD,2)&' miliseconds.'&@CRLF& _ 'Check the file permissons before closing the message box.') $TI = TimerInit() Local $aPerm[2][3] = [['Restricted',1,$GENERIC_ALL],['Users',1,$GENERIC_ALL]] $ret = _EditObjectPermissions(@ScriptDir&'test.txt',$aPerm) $TD = TimerDiff($TI) MsgBox(0,'','Add two granted access aces: Restricted and Users'&@CRLF&@CRLF& _ '_EditObjectPermissions return value: '&$ret&' Time: '&Round($TD,2)&' miliseconds.'&@CRLF& _ 'Check the file permissons before closing the message box.') $TI = TimerInit() Dim $aPerm[2][3] = [['Restricted',1,$GENERIC_READ],['Users',1,$GENERIC_READ]] $ret = _EditObjectPermissions(@ScriptDir&'test.txt',$aPerm) $TD = TimerDiff($TI) MsgBox(0,'','Give only read access to the Restricted and Users groups'&@CRLF&@CRLF& _ '_EditObjectPermissions return value: '&$ret&' Time: '&Round($TD,2)&' miliseconds.'&@CRLF& _ 'Check the file permissons before closing the message box.') $TI = TimerInit() Dim $aPerm[2][3] = [['Restricted',0,$GENERIC_ALL],['Users',0,$GENERIC_ALL]] $ret = _EditObjectPermissions(@ScriptDir&'test.txt',$aPerm) $TD = TimerDiff($TI) MsgBox(0,'','Deny access to the Restricted and Users groups'&@CRLF&@CRLF& _ '_EditObjectPermissions return value: '&$ret&' Time: '&Round($TD,2)&' miliseconds.'&@CRLF& _ 'Check the file permissons before closing the message box.') $TI = TimerInit() Local $Hndl = _Permissions_OpenProcess(@AutoItPID) Local $SDBefore = _GetObjectStringSecurityDescriptor($Hndl,$SE_KERNEL_OBJECT) Local $CODRet = _ClearObjectDacl($Hndl,$SE_KERNEL_OBJECT) Local $DARet = _DenyAllAccess($Hndl,$SE_KERNEL_OBJECT) Local $SDAfter = _GetObjectStringSecurityDescriptor($Hndl,$SE_KERNEL_OBJECT) $TD = Round(TimerDiff($TI),2) MsgBox(0,'', 'Deny everyone access to the current process:'&@CRLF&@CRLF& _ '@AutoItPID original security descriptor: '&@CRLF&$SDBefore&@CRLF&@CRLF& _ '_ClearObjectDacl return value: '&$CODRet&@CRLF&@CRLF& _ '_DenyAllAccess_ return value: '&$DARet&@CRLF&@CRLF& _ 'New @AutoItPID security descriptor: '&@CRLF& _ $SDAfter&@CRLF&@CRLF& 'Time taken: '&$TD&' miliseconds.') _Permissions_CloseHandle($Hndl) FileDelete(@ScriptDir&'test.txt') _ClosePermissionResources()I'm planning to add functions to deal with the Sacl in the future, even though I don't think it's very important.

    Edit: Let me know if you need an example for the registry.

    Updated: Fixed a bug in the _ClearObjectDacl function. I thought that adding a null DACL would work fine, but it causes problems later when adding a new DACL.
    Those who have downloaded, please update.
    Shoot! Now it wasn't clearing the DACL at all. Updated again. I think it's fixed now.

    Updated 9/11/2011 - Added the security descriptor functions and removed unnecessary constants.

    Updated 10/11/2011 - There were some functions missing in the index, and some parameters in the comments. Also removed the "MustDeclareVars" option. (About 50 total downloads before)

    Update 12/12/2011 - Added more functions:





    New Update 12/12/2011 - Missing declaration keywords in 3 constants. Sorry

    Update 16/12/2011 - Added support for all object types, including window and process handles. Added more functions, modified most of them, and removed one.

    Here's the new function list:





    Updated 22/2/2012.. This time I'm including SecurityConstants.au3 and FileConstants.au3 to prevent constants conflicts. Added a few more functions and fixed a few bugs.

    Also added the ability to include the inherited aces in the _EditObjectPermissions function.

    Now the permissions array can have four elements (optional). It will still work with three elements arrays though. The fourth element is intended to have the inheritance flag for the corresponding ace.

    Here's the new list of functions:






    400 previous downloads
    Permissions.au3
×
×
  • Create New...