Jump to content
VollachR

Verifying Ini File Format?

Recommended Posts

VollachR

Hi,

I've written a specialty INI file editor for a specific set of INI files related to a bigger script I'm working on.

I'm trying to create a verification script that checks the ini files structure and format and gives an error if they are not in expected format.

What I did so far is create a couple of custom arrays, each with the list of Sections expected in the files and I use IniReadSectionNames in order to read the sections from the selected INI file and compare it to the array.

It works fine, excepts it only gives an error if one or more of the sections in the custom array is missing, if they all exist but there are other additional sections that shouldn't be there it doesn't give an error and continue to open the editor screen.

Here are the relevant part of my script:

The Custom Verification Arrays:

;Creating Arrays for INI Verification
Global $aSettingsVerify[7]
$aSettingsVerify[1] = "Conversion"
$aSettingsVerify[2] = "AIO"
$aSettingsVerify[3] = "Data"
$aSettingsVerify[4] = "Redist"
$aSettingsVerify[5] = "Split"
$aSettingsVerify[6] = "Autorun"
Global $aDataVerify[6]
$aDataVerify[1] = "Compression"
$aDataVerify[2] = "Exclude"
$aDataVerify[3] = "LangExclude"
$aDataVerify[4] = "PreCommands"
$aDataVerify[5] = "PostCommands"

The IniReadSectionNames verification part:

Case $OK
                If StringInStr($ActiveConfig, "Settings.ini") Then
                    $CheckArray1 = IniReadSectionNames($ActiveConfig)
                    $CheckArray2 = _ArrayCompare($aSettingsVerify, $CheckArray1)
                    $CheckArray3 = UBound($CheckArray2, 1)
                    If $CheckArray3 = 1 Then
                        GUIDelete($ConfigStart)
                        SettingsGUI()
                    EndIf
                    If $CheckArray3 > 1 Then
                        WrongIni()
                    EndIf
                EndIf
                If StringInStr($ActiveConfig, "Data") Then
                    $CheckArray1 = IniReadSectionNames($ActiveConfig)
                    $CheckArray2 = _ArrayCompare($aDataVerify, $CheckArray1)
                    $CheckArray3 = UBound($CheckArray2, 1)
                    If $CheckArray3 = 1 Then
                        GUIDelete($ConfigStart)
                        DataGUI()
                    EndIf
                    If $CheckArray3 > 1 Then
                        WrongIni()
                    EndIf
                EndIf

The Function that performs the compare: (Found it in another thread on this forums somewhere by using Google Search)

;Compares Imported INI file with the Verification array
Func _ArrayCompare(ByRef $a1, ByRef $a2)
    Local $nOldSize = UBound($a2)
    Local $a3[$nOldSize], $nNewSize = $nOldSize

    For $i = 0 To UBound($a1) - 1
        For $j = 0 To $nOldSize - 1
            If Not $a3[$j] And ($a1[$i] = $a2[$j]) Then
                $a3[$j] = 1
                $nNewSize -= 1
            EndIf
        Next
    Next

    Local $a4[$nNewSize], $j = 0
    For $i = 0 To $nOldSize - 1
        If Not $a3[$i] Then
            $a4[$j] = $a2[$i]
            $j += 1
        EndIf
    Next

    Return $a4
EndFunc   ;==>_ArrayCompare

 

Any way to make a check if there are sections other than the ones in the Verification Array and produce an error?

Thanks


Ron Vollach
Microsoft Certified Professional (MCP)
Creator of Ultimate Conversion Compressor (UCC)
UCC Wikia

Share this post


Link to post
Share on other sites
Melba23

VollachR,

Run a check of the size of the array returned by IniReadSectionNames - if it is larger than the checking array there are too many entries.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Subz

As Melba23 pointed out you can compare section name count for example:

If UBound($CheckArray1) - 1 <> UBound($aSettingsVerify) - 1 Then ... ;~ Action here

Alternatively you can get an array of incorrect names and also compare the sizes for example:

#include <Array.au3>
Global $aVerify[7]
$aVerify[1] = "Conversion"
$aVerify[2] = "AIO"
$aVerify[3] = "Data"
$aVerify[4] = "Redist"
$aVerify[5] = "Split"
$aVerify[6] = "Autorun"

;~ IniReadSection
Global $aSection[9]
$aSection[1] = "Conversion"
$aSection[2] = "AIO"
$aSection[3] = "Data"
$aSection[4] = "Redist"
$aSection[5] = "Split"
$aSection[6] = "Autorun"
$aSection[7] = "AutoRunning"
$aSection[8] = "Confersion"

Global $aCompare = _SectionCompare($aSection, $aVerify)
_ArrayDisplay($aCompare, "Error Return = " & @error)

Func _SectionCompare($_aSections, $_aVerification)
    Local $_iError, $_iSearch
    If (UBound($_aSections) -1) < (UBound($_aVerification) - 1) Then $_iError = -1 ;~ $_aSections Array Count less than $_aVerification Array Count
    If (UBound($_aSections) -1) = (UBound($_aVerification) - 1) Then $_iError = 0 ;~ $_aSections Array Count equal to $_aVerification Aay Count
    If (UBound($_aSections) -1) > (UBound($_aVerification) - 1) Then $_iError = 1 ;~ $_aSections Array Count greater than $_aVerification Array Count
    ;~ Check items in $_aSections that match an item in $_aVerification
    For $i = UBound($_aVerification) - 1 To 0 Step - 1
        ConsoleWrite($_aVerification[$i] & @CRLF)
        $_iSearch = _ArraySearch($_aSections, $_aVerification[$i])
        If $_iSearch = -1 Then ContinueLoop
        _ArrayDelete($_aSections, $_iSearch)
    Next
    Return SetError($_iError, 0, $_aSections)
EndFunc

 

Share this post


Link to post
Share on other sites
VollachR
21 minutes ago, Melba23 said:

VollachR,

Run a check of the size of the array returned by IniReadSectionNames - if it is larger than the checking array there are too many entries.

M23

I thought about that but I'm not sure how to modify the existing function to include that check, as I said, I found that function online, don't remember where or who wrote it but I didn't do it myself, all I did was remove the _ArrayDisplay that was near the end of the function.

 

5 minutes ago, Subz said:

As Melba23 pointed out you can compare section name count for example:

If UBound($CheckArray1) - 1 <> UBound($aSettingsVerify) - 1 Then ... ;~ Action here

Alternatively you can get an array of incorrect names and also compare the sizes for example:

#include <Array.au3>
Global $aVerify[7]
$aVerify[1] = "Conversion"
$aVerify[2] = "AIO"
$aVerify[3] = "Data"
$aVerify[4] = "Redist"
$aVerify[5] = "Split"
$aVerify[6] = "Autorun"

;~ IniReadSection
Global $aSection[9]
$aSection[1] = "Conversion"
$aSection[2] = "AIO"
$aSection[3] = "Data"
$aSection[4] = "Redist"
$aSection[5] = "Split"
$aSection[6] = "Autorun"
$aSection[7] = "AutoRunning"
$aSection[8] = "Confersion"

Global $aCompare = _SectionCompare($aSection, $aVerify)
_ArrayDisplay($aCompare, "Error Return = " & @error)

Func _SectionCompare($_aSections, $_aVerification)
    Local $_iError, $_iSearch
    If (UBound($_aSections) -1) < (UBound($_aVerification) - 1) Then $_iError = -1 ;~ $_aSections Array Count less than $_aVerification Array Count
    If (UBound($_aSections) -1) = (UBound($_aVerification) - 1) Then $_iError = 0 ;~ $_aSections Array Count equal to $_aVerification Aay Count
    If (UBound($_aSections) -1) > (UBound($_aVerification) - 1) Then $_iError = 1 ;~ $_aSections Array Count greater than $_aVerification Array Count
    ;~ Check items in $_aSections that match an item in $_aVerification
    For $i = UBound($_aVerification) - 1 To 0 Step - 1
        ConsoleWrite($_aVerification[$i] & @CRLF)
        $_iSearch = _ArraySearch($_aSections, $_aVerification[$i])
        If $_iSearch = -1 Then ContinueLoop
        _ArrayDelete($_aSections, $_iSearch)
    Next
    Return SetError($_iError, 0, $_aSections)
EndFunc

 

I don't see how the 2nd example will work, if somebody modifies the ini file and add a section that shouldn't be there I have no way to guess what section name that person added, so I can't really create an array with incorrect names as that can be anything that isn't in the verification array.

As for the first suggestion, as I said above for Melba23's answer, I'm not sure where or how to add that into the existing _ArrayCompare function, or is there away to add it in the part of the script that calls the function without messing things up?


Ron Vollach
Microsoft Certified Professional (MCP)
Creator of Ultimate Conversion Compressor (UCC)
UCC Wikia

Share this post


Link to post
Share on other sites
Subz

The $aSection above was an example of an IniReadSection, it should return the differences, here is another example since I didn't  make the first a 2D Array and forgot about comparing the results after the loop.  As I only have partial piece of your script I can't test so will leave it with you.

#include <Array.au3>

Global $aSettingsVerify[7]
    $aSettingsVerify[1] = "Conversion"
    $aSettingsVerify[2] = "AIO"
    $aSettingsVerify[3] = "Data"
    $aSettingsVerify[4] = "Redist"
    $aSettingsVerify[5] = "Split"
    $aSettingsVerify[6] = "Autorun"

Global $aDataVerify[6]
    $aDataVerify[1] = "Compression"
    $aDataVerify[2] = "Exclude"
    $aDataVerify[3] = "LangExclude"
    $aDataVerify[4] = "PreCommands"
    $aDataVerify[5] = "PostCommands"

If StringInStr($ActiveConfig, "Settings.ini") Then
    $CheckArray1 = IniReadSectionNames($ActiveConfig)
    $CheckArray2 = _SectionCompare($CheckArray1, $aSettingsVerify)
    Switch @error
        Case -2, -1, 1
            GUIDelete($ConfigStart)
            SettingsGUI()
    EndSwitch
    _ArrayDisplay($CheckArray2, "Error Return = " & @error)
EndIf
If StringInStr($ActiveConfig, "Data") Then
    $CheckArray1 = IniReadSectionNames($ActiveConfig)
    $CheckArray2 = _SectionCompare($CheckArray1, $aDataVerify)
    Switch @error
        Case -2, -1, 1
            GUIDelete($ConfigStart)
            SettingsGUI()
    EndSwitch
    _ArrayDisplay($CheckArray2, "Error Return = " & @error)
EndIf

; ==================================================================================================
; Func _SectionCompare($_aSections, $_aVerification)
;
; $_aSections       := Section Names Array
; $_aVerifcation    := Verification Array
;
; Returns:
;   Success: "" with @error set to 0
;   Failure: "" if $_aSections is empty or $_vResult Array with differnces, with @error set
;       @error = -2 = $_aSections Array contains incorrect data
;       @error = -1 $_aSections Array Count less than $_aVerification Array Count
;       @error = 1 $_aSections Array Count greater than $_aVerification Array Count
;
; Author: Subz
; ==================================================================================================

Func _SectionCompare($_aSections, $_aVerification)
    Local $_iError, $_iSearch
    If (UBound($_aSections) -1) < (UBound($_aVerification) - 1) Then $_iError = -1 ;~ $_aSections Array Count less than $_aVerification Array Count
    If (UBound($_aSections) -1) = (UBound($_aVerification) - 1) Then $_iError = 0 ;~ $_aSections Array Count equal to $_aVerification Aay Count
    If (UBound($_aSections) -1) > (UBound($_aVerification) - 1) Then $_iError = 1 ;~ $_aSections Array Count greater than $_aVerification Array Count
    ;~ Check items in $_aSections that match an item in $_aVerification
    For $i = UBound($_aVerification) - 1 To 0 Step - 1
        $_iSearch = _ArraySearch($_aSections, $_aVerification[$i], 0, 0, 0, 0, 1, 0)
        If $_iSearch = -1 Then ContinueLoop
        _ArrayDelete($_aSections, $_iSearch)
    Next
    $_iError = UBound($_aSections) -1 = 0 ? 0 : -2
    $_vReturn = UBound($_aSections) = 0 ? "" : $_aSections
    Return SetError($_iError, 0, $_vReturn)
EndFunc

 

Share this post


Link to post
Share on other sites
VollachR

OK, turned out I didn't need that additional check after all, my existing check was enough once I moved another part of the script from another "Case" into the "Case $OK" portion, it was probably a logic issue.

I accidentally made the script import the in sections (with IniReadSection) to Arrays before performing the check instead of after, which caused my problem, now that I moved it to be done after the check is performed I get the error message at every situation it needs to be without any additional checks.

That's the change I made:

Case $OK
                If StringInStr($ActiveConfig, "Settings.ini") Then
                    $CheckArray1 = IniReadSectionNames($ActiveConfig)
                    $CheckArray2 = _ArrayCompare($aSettingsVerify, $CheckArray1)
                    $CheckArray3 = UBound($CheckArray2, 1)
                    If $CheckArray3 = 1 Then
                        Global $aConversion = IniReadSection($ActiveConfig, "Conversion")
                        Global $aAIO = IniReadSection($ActiveConfig, "AIO")
                        Global $aData = IniReadSection($ActiveConfig, "Data")
                        Global $aRedist = IniReadSection($ActiveConfig, "Redist")
                        Global $aSplit = IniReadSection($ActiveConfig, "Split")
                        Global $aAutorun = IniReadSection($ActiveConfig, "Autorun")
                        GUIDelete($ConfigStart)
                        SettingsGUI()
                    EndIf
                    If $CheckArray3 > 1 Then
                        WrongIni()
                    EndIf
                EndIf
                If StringInStr($ActiveConfig, "Data") Then
                    $CheckArray1 = IniReadSectionNames($ActiveConfig)
                    $CheckArray2 = _ArrayCompare($aDataVerify, $CheckArray1)
                    $CheckArray3 = UBound($CheckArray2, 1)
                    If $CheckArray3 = 1 Then
                        Global $aCompression = IniReadSection($ActiveConfig, "Compression")
                        Global $aExclude = IniReadSection($ActiveConfig, "Exclude")
                        Global $aLangExclude = IniReadSection($ActiveConfig, "LangExclude")
                        Global $aPreCommands = IniReadSection($ActiveConfig, "PreCommands")
                        Global $aPostCommands = IniReadSection($ActiveConfig, "PostCommands")
                        GUIDelete($ConfigStart)
                        DataGUI()
                    EndIf
                    If $CheckArray3 > 1 Then
                        WrongIni()
                    EndIf
                EndIf

Before I had these IniReadSection lines in a previous Case for a ComboBox that let the user select the Ini file to edit before enabling the OK button, now it's in the OK button case after the check if it's correct.

These IniReadSection arrays are used to later fill the edit fields in the GUI, don't know why creating them earlier caused a problem but it works now.


Ron Vollach
Microsoft Certified Professional (MCP)
Creator of Ultimate Conversion Compressor (UCC)
UCC Wikia

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • nooneclose
      By nooneclose
      How do I properly convert this to Autoit? This is a VBA macro that I recorded in Excel.
       ActiveSheet.Outline.ShowLevels RowLevels:=2 I need this to close my subtotal once it is finished. 
      any help will be greatly appreciated. 
    • iMacg3
      By iMacg3
      Hi,
      I was looking into a way to delete a registry key (not a specific value, an entire key) if it is present. I was considering using RegRead and RegDelete. However, RegRead appears to only read values, not just keys. Is there a way to delete an entire registry key if it is present? I have heard that the below function may help.
       
      #include-once ; #UDF# ======================================================================================================================= ; Title .........: Reads\Search the name of a Key\Subkey\Value ; AutoIt Version : 3.3.8.1 ; Language ......: English ; Description ...: Lists all Keys\Subkeys\Values in a specified registry key ; Author(s) .....: DXRW4E ; Notes .........: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;~ _RegEnumKeyEx ;~ _RegEnumValEx ; =============================================================================================================================== #Region ;**** Global constants and vars **** Global Const $sValueTypes[12] = ["REG_NONE","REG_SZ","REG_EXPAND_SZ","REG_BINARY","REG_DWORD","REG_DWORD_BIG_ENDIAN","REG_LINK","REG_MULTI_SZ","REG_RESOURCE_LIST","REG_FULL_RESOURCE_DESCRIPTOR","REG_RESOURCE_REQUIREMENTS_LIST","REG_QWORD"] #EndRegion ;**** Global constants and vars **** ; #FUNCTION# ======================================================================================================================== ; Name...........: _RegEnumKeyEx ; Description ...: Lists all subkeys in a specified registry key ; Syntax.........: _RegEnumKeyEx($KeyName[, $iFlag = 0[, $sFilter = "*"]]) ; Parameters ....: $KeyName - The registry key to read. ; $iFlag - Optional specifies Recursion (add the flags together for multiple operations): ; |$iFlag = 0 (Default) All Key-SubKeys Recursive Mod ; |$iFlag = 1 All SubKeys Not Recursive Mod ; |$iFlag = 2 Include in ArrayList in the first element $KeyName ; |$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 strings returned, the remaining elements ($array[1], $array[2], etc.) ; |$iFlag = 64 $sFilter is REGEXP Mod, See Pattern Parameters in StringRegExp ; |$iFlag = 128 Enum value's name (_RegEnumKeyEx Return a 2D array, maximum Array Size limit is 3999744 Key\Value) ; |$iFlag = 256 Reads a value data, this flag will be ignored if the $iFlag = 128 is not set ; $sFilter - Optional the filter to use, default is *. (Multiple filter groups such as "All "*.XXx|*.YYY|*.ZZZ") ; Search the Autoit3 helpfile for the word "WildCards" For details. ; $vFilter - Optional the filter to use for ValueName, $vFilter will be ignored if the $iFlag = 128 is not set ; default is *. (Multiple filter groups such as "All "*.XXx|*.YYY|*.ZZZ") Search the Autoit3 helpfile for the word "WildCards" For details. ; $iValueTypes - Optional, set Value Types to search (Default $iValueTypes = 0 Read All), $iValueTypes will be ignored if the $iFlag = 128 is not set ; (add the flags together for multiple operations): ; 1 = REG_SZ ; 2 = REG_EXPAND_SZ ; 3 = REG_BINARY ; 4 = REG_DWORD ; 5 = REG_DWORD_BIG_ENDIAN ; 6 = REG_LINK ; 7 = REG_MULTI_SZ ; 8 = REG_RESOURCE_LIST ; 9 = REG_FULL_RESOURCE_DESCRIPTOR ; 10 = REG_RESOURCE_REQUIREMENTS_LIST ; 11 = REG_QWORD ; Return values .: Success - Return Array List (See Remarks) ; Failure - @Error ; |1 = Invalid $sFilter ; |2 = No Key-SubKey(s) Found ; |3 = Invalid $vFilter ; |4 = No Value-Name(s) Found ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: The array returned is one-dimensional and is made up as follows: ; $array[0] = Number of Key-SubKeys returned ; $array[1] = 1st Key\SubKeys ; $array[2] = 2nd Key\SubKeys ; $array[3] = 3rd Key\SubKeys ; $array[n] = nth Key\SubKeys ; ; If is set the $iFlag = 128 The array returned is 2D array and is made up as follows: ; $array[0][0] = Number of Key-SubKeys returned ; $array[1][0] = 1st Key\SubKeys ; $array[1][1] = 1st Value name ; $array[1][2] = 1st Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[1][3] = 1st Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[2][0] = 2nd Key\SubKeys ; $array[2][1] = 2nd Value name ; $array[2][2] = 2nd Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[2][3] = 2nd Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[n][0] = nth Key\SubKeys ; Related .......: _RegEnumValEx() ; Link ..........: ; Example .......: _RegEnumKeyEx("HKEY_CURRENT_USER\Software\AutoIt v3") ; Note ..........: ; =================================================================================================================================== Func _RegEnumKeyEx($KeyName, $iFlag = 0, $sFilter = "*", $vFilter = "*", $iValueTypes = 0) If StringRegExp($sFilter, StringReplace("^\s*$|\v|\\|^\||\|\||\|$", Chr(BitAND($iFlag, 64) + 28) & "\|^\||\|\||\|$", "\\\\")) Then Return SetError(1, 0, "") Local $IndexSubKey[101] = [100], $SubKeyName, $BS = "\", $sKeyList, $I = 1, $sKeyFlag = BitAND($iFlag, 1), $sKeyFilter = StringReplace($sFilter, "*", "") If BitAND($iFlag, 2) Then $sKeyList = @LF & $KeyName 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 $I $IndexSubKey[$I] += 1 $SubKeyName = RegEnumKey($KeyName, $IndexSubKey[$I]) If @error Then $IndexSubKey[$I] = 0 $I -= 1 $KeyName = StringLeft($KeyName, StringInStr($KeyName, "\", 1, -1) - 1) ContinueLoop EndIf If $sKeyFilter Then If StringRegExp($SubKeyName, $sFilter) Then $sKeyList &= @LF & $KeyName & $BS & $SubKeyName Else $sKeyList &= @LF & $KeyName & $BS & $SubKeyName EndIf If $sKeyFlag Then ContinueLoop $I += 1 If $I > $IndexSubKey[0] Then $IndexSubKey[0] += 100 ReDim $IndexSubKey[$IndexSubKey[0] + 1] EndIf $KeyName &= $BS & $SubKeyName WEnd If Not $sKeyList Then Return SetError(2, 0, "") If BitAND($iFlag, 128) <> 128 Then Return StringSplit(StringTrimLeft($sKeyList, 1), @LF, StringReplace(BitAND($iFlag, 32), "32", 2)) $sKeyList = _RegEnumValEx(StringSplit(StringTrimLeft($sKeyList, 1), @LF), $iFlag, $vFilter, $iValueTypes) Return SetError(@Error, 0, $sKeyList) EndFunc ; #FUNCTION# ======================================================================================================================== ; Name...........: _RegEnumValEx ; Description ...: Lists all values in a specified registry key ; Syntax.........: _RegEnumValEx($KeyName[, $iFlag = 0[, $sFilter = "*"]]) ; Parameters ....: $KeyName - The registry key to read Or one-dimensional array RegKeyList ; use _RegEnumKeyEx() to get $RegKeyList (example $RegKeyList = [3, 1st Key\SubKeys, 2st Key\SubKeys, nth Key\SubKeys]) ; |$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 strings returned, the remaining elements ($array[1], $array[2], etc.) ; |$iFlag = 64 $sFilter is REGEXP Mod, See Pattern Parameters in StringRegExp ; |$iFlag = 256 Reads a value data ; $sFilter - Optional the filter to use, default is *. (Multiple filter groups such as "All "*.XXx|*.YYY|*.ZZZ") ; Search the Autoit3 helpfile for the word "WildCards" For details. ; $iValueTypes - Optional, set Value Types to search (Default $iValueTypes = 0 Read All) ; (add the flags together for multiple operations): ; 1 = REG_SZ ; 2 = REG_EXPAND_SZ ; 3 = REG_BINARY ; 4 = REG_DWORD ; 5 = REG_DWORD_BIG_ENDIAN ; 6 = REG_LINK ; 7 = REG_MULTI_SZ ; 8 = REG_RESOURCE_LIST ; 9 = REG_FULL_RESOURCE_DESCRIPTOR ; 10 = REG_RESOURCE_REQUIREMENTS_LIST ; 11 = REG_QWORD ; Return values .: Success - Return Array List (See Remarks) ; Failure - @Error ; |3 = Invalid $sFilter ; |4 = No Value-Name(s) Found ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: The array returned is 2D array and is made up as follows: ; $array[0][0] = Number of Key-SubKeys returned ; $array[1][0] = 1st Key\SubKeys ; $array[1][1] = 1st Value name ; $array[1][2] = 1st Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[1][3] = 1st Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[2][0] = 2nd Key\SubKeys ; $array[2][1] = 2nd Value name ; $array[2][2] = 2nd Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[2][3] = 2nd Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[n][0] = nth Key\SubKeys ; Related .......: _RegEnumKeyEx() ; Link ..........: ; Example .......: _RegEnumValEx("HKEY_CURRENT_USER\Software\AutoIt v3") ; Note ..........: ; =================================================================================================================================== Func _RegEnumValEx($aKeyList, $iFlag = 0, $sFilter = "*", $iValueTypes = 0) If StringRegExp($sFilter, "\v") Then Return SetError(3, 0, "") If Not IsArray($aKeyList) Then $aKeyList = StringSplit($aKeyList, @LF) Local $aKeyValList[1954][4], $iKeyVal = Int(BitAND($iFlag, 32) = 0), $sKeyVal = 1953, $sRegEnumVal, $iRegEnumVal, $RegRead = BitAND($iFlag, 256), $vFilter = StringReplace($sFilter, "*", "") 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"), "\*+", ".*") & ")" For $i = 1 To $aKeyList[0] $iRegEnumVal = 0 While 1 If $iKeyVal = $sKeyVal Then If $sKeyVal = 3999744 Then ExitLoop $sKeyVal *= 2 ReDim $aKeyValList[$sKeyVal + 1][4] EndIf $aKeyValList[$iKeyVal][0] = $aKeyList[$i] $iRegEnumVal += 1 $sRegEnumVal = RegEnumVal($aKeyList[$i], $iRegEnumVal) If @Error <> 0 Then If $iRegEnumVal = 1 And $vFilter = "" Then $iKeyVal += 1 ExitLoop EndIf $aKeyValList[$iKeyVal][2] = $sValueTypes[@Extended] If BitAND(@Extended, $iValueTypes) <> $iValueTypes Then ContinueLoop If $vFilter And Not StringRegExp($sRegEnumVal, $sFilter) Then ContinueLoop $aKeyValList[$iKeyVal][1] = $sRegEnumVal If $RegRead Then $aKeyValList[$iKeyVal][3] = RegRead($aKeyList[$i], $sRegEnumVal) $iKeyVal += 1 WEnd Next $sRegEnumVal = $iKeyVal - Int(BitAND($iFlag, 32) = 0) If Not $sRegEnumVal Or ($sRegEnumVal = 1 And $vFilter = "" And $aKeyValList[$iKeyVal - $sRegEnumVal][2] = "") Then Return SetError(4, 0, "") ReDim $aKeyValList[$iKeyVal][4] If Not BitAND($iFlag, 32) Then $aKeyValList[0][0] = $iKeyVal - 1 Return $aKeyValList EndFunc Thanks.
       
    • great77
      By great77
      ; put the root in a variable $sRoot = "C:\Project\PHexample\" Global $sCurrentTime = _NowCalc() ; We can use that variable here Global $aList = _FileListToArray($sRoot, Default, 2) If @error Then Exit ;;;;;;MsgBox(0, "Error", "_FileListToArray returned @error = " & @error) ;;;;;;;;;;;This is a loop that runs from 1 to the number of items listed in the first element of the returned  array For $i = 1 To UBound($aList) - 1     MsgBox(0, "Folder date", $sRoot & "" & $aList[$i] & @CRLF & @CRLF & FileGetTime($sRoot & "" & $aList[$i], 1, 1))     MsgBox(0, "Folder date", FileGetTime($sRoot & "" & $aList[$i], 1, 1))      $a_filenew = StringReplace(StringReplace(StringReplace(_NowCalc(), "/", ""), ":", ""), " ", "")       MsgBox(0, "Folder date", $a_filenew) $adex =  _DateDiff('D', FileGetTime($sRoot & "" & $aList[$i], 1, 1), $a_filenew)  MsgBox(0,"ade", $adex) Next I have a code as seen above, but the difference in time is returning zero. I understand that the date yyyymmddhhmmss but how can I find the difference.
      The purpose is to try find the difference in days. Any suggestion?  
    • TrashBoat
      By TrashBoat
      So i have been working on this 2d physics game and added some physics to it but got stuck on this problem that the character ( the cube ) is sliding all the time but it should not do that because of this friction function:
      If $horizontalVelocity > 0 Then If $inAir Then $currFriction = $airFriction $horizontalVelocity -= $currFriction $birbX += $horizontalVelocity EndIf this line "$horizontalVelocity -= $currFriction" should nullify the velocity to 0 but it stays somewhere in 0.09. How do i fix this?
      Here's the game's source code and what i have done so far:
      Now i don't expect you reading my nasty code and understanding what it does but any help would be appreciated.
       
      Edit: I guess the problem is solved, i have updated the source code if anyone needs it.
    • TheSaint
      By TheSaint
      Here is a simple program that some of you might appreciate.
      It is a more full fleshed out version of something I worked on a while back as a proof of concept.
      I will just quote the information found in the Program Information dialog.

      Older Screenshot
      INItoSQL DB.zip
      INItoSQL DB v1.1.zip  (see Post #3 for update details)
      INItoSQL DB v1.4.zip  (see Post #4 for update details)
      INItoSQL DB v1.6.zip  (see Post #7 for update details) BIG THANKS to ResNullius for huge speed improvement etc.
      Program requires the sqlite3.dll, not included, but easily enough obtained.
      I have also included the beginnings of a new UDF (SimpleSQL_UDF) I am working, which you can use with the included 'Check conversion.au3' file to check a resulting conversion ... just modify the values for a few variables to suit your situation.
      I've not yet gotten around to coding a testing/checking results script, so I recommend the following open source program, which I have been using for some time. It was here, but is now here at GitHub - DB Browser for SQLite
×