Ini in 3D Array einlesen?

  • Hallo,

    ich versuche gerade eine Inidatei in einen 3D Array einlesen zu lassen. Im Moment bin ich so weit:

    Spoiler anzeigen
    [autoit]

    Func _IniReadToArray($i_File)

    [/autoit] [autoit][/autoit] [autoit]

    Dim $i_Array[1][2][1]

    [/autoit] [autoit][/autoit] [autoit]

    $i_IniReadSectionNames = IniReadSectionNames($i_File)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    For $i_Loop = 1 To $i_IniReadSectionNames[0]

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ReDim $i_Array[UBound($i_Array, 1)][UBound($i_Array, 2)][$i_Loop]
    $i_Array[0][0][$i_Loop - 1] = $i_IniReadSectionNames[$i_Loop]

    [/autoit] [autoit][/autoit] [autoit]

    $i_Section = IniReadSection($i_File, $i_IniReadSectionNames[$i_Loop])

    [/autoit] [autoit][/autoit] [autoit]

    For $i_Loop2 = 1 To $i_Section[0][0]

    [/autoit] [autoit][/autoit] [autoit]

    ReDim $i_Array[$i_Loop2 + 1][UBound($i_Array, 2)][UBound($i_Array, 3)]

    [/autoit] [autoit][/autoit] [autoit]

    $i_Array[$i_Loop2 - 1][0][$i_Loop - 1] = $i_Section[$i_Loop2][0]
    $i_Array[$i_Loop2 - 1][1][$i_Loop - 1] = $i_Section[$i_Loop2][1]

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Next
    Next

    [/autoit] [autoit][/autoit] [autoit]

    _ArrayDisplayTree($i_Array, 0, "Array In Array")
    EndFunc ;==>_IniReadToArray

    [/autoit]
    _ArrayDisplayTree.au3
    [autoit]

    #include <GuiImageList.au3>
    #include <TreeViewConstants.au3>
    #include <WindowsConstants.au3>
    #include <GuiTreeView.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Func _ArrayDisplayTree($aArray, $iExpand = 1, $sTitle = "Array: TreeView Display", $sDimension = "", $sElement = "", $iWidth = 380, $iHeight = 640, $iRootColor = 0xCC0000, $iDimensionColor = 0x00AA00, $iElementColor = 0x0000FF)
    ;By Eukalyptus ;)
    If Not IsArray($aArray) Then Return SetError(1, 0, 0)
    Local $iEventMode = Opt("GUIOnEventMode", 0)
    Local $aIndex[UBound($aArray, 0) + 1], $sRoot = "Array "
    $aIndex[0] = 1
    For $i = 1 To UBound($aArray, 0)
    $aIndex[$i] = "0"
    $aIndex[0] *= UBound($aArray, $i)
    $sRoot &= "[" & UBound($aArray, $i) & "]"
    Next
    Local $hGui = GUICreate($sTitle, $iWidth, $iHeight, Default, Default, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU))
    Local $iStyle = BitOR($TVS_DISABLEDRAGDROP, $TVS_HASBUTTONS, $TVS_LINESATROOT)
    Local $hTreeView = GUICtrlCreateTreeView(2, 2, $iWidth - 4, $iHeight - 26, $iStyle)
    Local $hParent = GUICtrlCreateTreeViewItem($sRoot, $hTreeView)
    GUICtrlSetColor(-1, $iRootColor)
    Local $hImageList = _GUIImageList_Create(11, 11)
    _GUIImageList_Add($hImageList, _GUICtrlTreeView_CreateSolidBitMap($hTreeView, 0x666666, 11, 11))
    _GUIImageList_Add($hImageList, _GUICtrlTreeView_CreateSolidBitMap($hTreeView, 0xAA0000, 11, 11))
    _GUIImageList_Add($hImageList, _GUICtrlTreeView_CreateSolidBitMap($hTreeView, 0x00AA00, 11, 11))
    _GUIImageList_Add($hImageList, _GUICtrlTreeView_CreateSolidBitMap($hTreeView, 0x0000CC, 11, 11))
    _GUIImageList_Add($hImageList, _GUICtrlTreeView_CreateSolidBitMap($hTreeView, 0xFFAA00, 11, 11))
    _GUIImageList_Add($hImageList, _GUICtrlTreeView_CreateSolidBitMap($hTreeView, 0xFF00FF, 11, 11))
    _GUICtrlTreeView_SetNormalImageList($hTreeView, $hImageList)
    Local $hProgress = GUICtrlCreateProgress(2, $iHeight - 20, $iWidth - 4, 18, 0x1)
    GUISetState()
    _GUICtrlTreeView_BeginUpdate($hTreeView)
    _ArrayDisplayTreeAddItems($aArray, $hTreeView, $hParent, $aIndex, $hProgress, 0, $iRootColor, $iDimensionColor, $iElementColor, $sDimension, $sElement)
    _GUICtrlTreeView_Expand($hTreeView, $hParent, False)
    _GUICtrlTreeView_EndUpdate($hTreeView)
    Switch $iExpand
    Case 1
    _GUICtrlTreeView_Expand($hTreeView, $hParent)
    Case 2
    Local $sExpand = "#0", $hTree = ControlGetHandle($hGui, "", $hTreeView)
    For $i = 0 To UBound($aIndex) - 1
    ControlTreeView($hGui, "", $hTree, "Expand", $sExpand)
    $sExpand &= "|#0"
    Next
    Case Else
    Local $hTree = ControlGetHandle($hGui, "", $hTreeView)
    ControlTreeView($hGui, "", $hTree, "Expand", "#0")
    EndSwitch
    GUICtrlSetData($hProgress, 0)
    While GUIGetMsg() <> -3
    WEnd
    GUIDelete($hGui)
    Opt("GUIOnEventMode", $iEventMode)
    EndFunc ;==>_ArrayDisplayTree

    [/autoit] [autoit][/autoit] [autoit]

    Func _ArrayDisplayTreeAddItems($aArray, $hTreeView, $hParent, $aIndex, $hProgress, $iStep, $iRootColor, $iDimensionColor, $iElementColor, $sDim, $sEle)
    Local $sExexute = "$aArray", $sElement = $sEle, $sDimension, $Temp, $hItem
    $hItem = $hParent
    For $i = 1 To UBound($aArray, 0) - 1
    $Temp = _GUICtrlTreeView_GetItemByIndex($hTreeView, $hItem, $aIndex[$i])
    If $Temp = 0 Then
    $sDimension = $sDim
    For $j = 1 To UBound($aIndex) - 1
    Switch $j
    Case $i
    $sDimension &= "[" & $aIndex[$i] & "] "
    Case Else
    $sDimension &= "_ "
    EndSwitch
    Next
    $hItem = GUICtrlCreateTreeViewItem($sDimension, $hItem)
    GUICtrlSetColor(-1, $iDimensionColor)
    _GUICtrlTreeView_SetImageIndex($hTreeView, $hItem, Mod($i, 4) + 1)
    Else
    _GUICtrlTreeView_SelectItem($hTreeView, $Temp, $TVGN_CARET)
    $hItem = GUICtrlRead($hTreeView)
    EndIf
    $sExexute &= "[" & $aIndex[$i] & "] "
    $sElement &= "[" & $aIndex[$i] & "] "
    Next
    For $i = 1 To UBound($aArray, UBound($aArray, 0));-1
    $Temp = Execute($sExexute & "[" & $i - 1 & "]")
    If IsArray($Temp) Then
    Local $aElementIndex[UBound($Temp, 0) + 1], $sRoot = "Array ", $hElementItem
    $aElementIndex[0] = 1
    For $j = 1 To UBound($Temp, 0)
    $aElementIndex[$j] = "0"
    $aElementIndex[0] *= UBound($Temp, $j)
    $sRoot &= "[" & UBound($Temp, $j) & "]"
    Next
    $hElementItem = GUICtrlCreateTreeViewItem($sElement & "[" & $i - 1 & "] = <" & $sRoot & ">", $hItem)
    GUICtrlSetColor(-1, $iRootColor)
    _GUICtrlTreeView_SetImageIndex($hTreeView, $hElementItem, 5)
    _ArrayDisplayTreeAddItems($Temp, $hTreeView, $hElementItem, $aElementIndex, $hProgress, 0, $iRootColor, $iDimensionColor, $iElementColor, "SUB " & $sDim, "SUB " & $sEle)
    ContinueLoop
    EndIf
    $Temp = GUICtrlCreateTreeViewItem($sElement & "[" & $i - 1 & "] = <" & $Temp & ">", $hItem)
    GUICtrlSetColor(-1, $iElementColor)
    _GUICtrlTreeView_SetImageIndex($hTreeView, $Temp, 5)
    $iStep += 1
    Next
    GUICtrlSetData($hProgress, $iStep * 100 / $aIndex[0])
    $Temp = UBound($aIndex) - 1
    Switch $Temp
    Case 1
    Return
    Case 2
    $aIndex[$Temp - 1] += 1
    If $aIndex[1] >= UBound($aArray, 1) Then Return
    Case Else
    $aIndex[$Temp - 1] += 1
    For $i = $Temp To 2 Step -1
    Switch 1
    Case $aIndex[$i] >= UBound($aArray, $i)
    $aIndex[$i] = 0
    $aIndex[$i - 1] += 1
    If $aIndex[1] >= UBound($aArray, 1) Then Return
    If $aIndex[$i - 1] >= UBound($aArray, $i - 1) Then ContinueLoop
    EndSwitch
    Next
    EndSwitch
    _ArrayDisplayTreeAddItems($aArray, $hTreeView, $hParent, $aIndex, $hProgress, $iStep, $iRootColor, $iDimensionColor, $iElementColor, $sDim, $sEle)
    EndFunc ;==>_ArrayDisplayTreeAddItems

    [/autoit]

    Ich möchte nämlich einen Array nach folgendem Schema erzeugen:

    $Array[0][0][1] ==> Sectionname
    $Array[0][1][0] ==> 0 = Key, 1 = Value
    $Array[1][0][0] ==> Key oder Value

    Doch irgendwie habe ich da meine Probleme mit 3D Arrays, da ich sie nicht so oft benutze (fast nie).
    Als 2D Array ist es mir nicht übersichtlich genug...

    Ich hoffe jemand kann dieses Problem lösen ich blicke da bei diesen ganzen Array-Dinger nicht mehr durch :wacko:

    • Offizieller Beitrag

    Guckst du:

    [autoit]

    Local $INI = @ScriptDir & '\Deine.INI'
    Local $section = 'section_name'
    Local $aSection = IniReadSection($INI, $section)
    Local $aIni[$aSection[0][0]][3]
    For $i = 1 To UBound($aSection) -1
    $aIni[$i-1][0] = $section
    $aIni[$i-1][1] = $aSection[$i][0]
    $aIni[$i-1][2] = $aSection[$i][1]
    Next
    _ArrayDisplay($aIni)

    [/autoit]
  • Danke BugFix. Hab das gleich mal alles umgesetzt. Hier wer es braucht:

    Spoiler anzeigen
    [autoit]

    $Ret = _IniReadToArray("Settings.ini")
    $Read = _IniRead_Array($Ret, "Inet", "InetConnectionWait")

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox(0, "", $D3D)

    [/autoit] [autoit][/autoit] [autoit]

    Func _IniRead_Array($xArray, $xSection, $xKey) ;Deepred (AutoIt.de)
    For $Loop = 0 To UBound($xArray) -1
    Switch $xArray[$Loop][0]
    Case $xSection
    If $xArray[$Loop][1] = $xKey Then Return $xArray[$Loop][2]
    EndSwitch
    Next
    Return 0
    EndFunc ;==>_IniRead_Array

    [/autoit] [autoit][/autoit] [autoit]

    Func _IniReadToArray($zFile) ;Deepred (AutoIt.de)
    Local $sSectionNames = IniReadSectionNames($zFile)
    Local $VirtIni[1][3]
    Local $Counter = 0
    For $l = 1 To $sSectionNames[0]
    $IRSTA = _IniReadSectionToArray($zFile, $sSectionNames[$l])
    For $x = 0 To UBound($IRSTA) - 1
    ReDim $VirtIni[$Counter + 1][3]
    $VirtIni[$Counter][0] = $IRSTA[$x][0]
    $VirtIni[$Counter][1] = $IRSTA[$x][1]
    $VirtIni[$Counter][2] = $IRSTA[$x][2]
    $Counter += 1
    Next
    Next
    Return $VirtIni
    EndFunc ;==>_IniReadToArray

    [/autoit] [autoit][/autoit] [autoit]

    Func _IniReadSectionToArray($iFile, $iSection) ;Deepred (AutoIt.de)
    Local $INI = @ScriptDir & '\' & $iFile
    Local $aSection = IniReadSection($INI, $iSection)
    Local $aIni[$aSection[0][0]][3]
    For $i = 1 To UBound($aSection) - 1
    $aIni[$i - 1][0] = $iSection
    $aIni[$i - 1][1] = $aSection[$i][0]
    $aIni[$i - 1][2] = $aSection[$i][1]
    Next
    Return $aIni
    EndFunc ;==>_IniReadSectionToArray

    [/autoit]

    Es ist besonders bei ganz vielen Ini-Abfragen von Vorteil, da es glaub ich deutlich schneller ist als einzelne IniRead -Abfragen.

  • Ist das wirklich schnell?

    Besser wäre doch:
    1. Inireadsectionnames
    2. Inireadsection für jeden Section
    und dann das Array einmal entsprechend zu deklarieren? Spart die Redim-Bremse!

    Wobei man dann auch für jede Section mit einem anderen Array arbeiten könnte.

    • Offizieller Beitrag

    Hallo,

    Redim ist immer eine Bremse aber man kann es beschleunigen wenn man das Array um mehr als 1 vergrößert.

    Beispiel
    [autoit]

    Dim $test1[1][3]
    Dim $test2[1][3]
    Dim $test3[1][3]
    Dim $test4[1][3]

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $Start1 = TimerInit()
    For $i = 1 To 20000
    If UBound($test1) < $i Then ReDim $test1[UBound($test1)+1][3]
    Next
    $Time1 = TimerDiff($Start1)

    [/autoit] [autoit][/autoit] [autoit]

    $Start2 = TimerInit()
    For $i = 1 To 20000
    If UBound($test2) < $i Then ReDim $test2[UBound($test2)+10][3]
    Next
    $Time2 = TimerDiff($Start2)

    [/autoit] [autoit][/autoit] [autoit]

    $Start3 = TimerInit()
    For $i = 1 To 20000
    If UBound($test3) < $i Then ReDim $test3[UBound($test3)+100][3]
    Next
    $Time3 = TimerDiff($Start3)

    [/autoit] [autoit][/autoit] [autoit]

    $Start4 = TimerInit()
    For $i = 1 To 20000
    If UBound($test4) < $i Then ReDim $test4[UBound($test4)+1000][3]
    Next
    $Time4 = TimerDiff($Start4)

    [/autoit] [autoit][/autoit] [autoit]

    $Out = "1 - Zeilen: " & UBound($test1) & " Dauer: " & $Time1 & " ms" & @CRLF
    $Out &= "2 - Zeilen: " & UBound($test2) & " Dauer: " & $Time2 & " ms" & @CRLF
    $Out &= "3 - Zeilen: " & UBound($test3) & " Dauer: " & $Time3 & " ms" & @CRLF
    $Out &= "4 - Zeilen: " & UBound($test4) & " Dauer: " & $Time4 & " ms" & @CRLF

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox(0, "", $Out)

    [/autoit]
  • Ok. Ich hab es jetzt so gemacht, das Redim immer um die Anzahl der folgenden Einträge vergrößert wird. Code:

    Spoiler anzeigen
    [autoit]

    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_Compression=4
    #AutoIt3Wrapper_Run_Obfuscator=y
    #Obfuscator_Parameters=/striponly
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.0.0
    Author: myName

    Script Function:
    Template AutoIt script.

    #ce ----------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    ; Script Start - Add your code below here

    [/autoit] [autoit][/autoit] [autoit]

    $Timer = TimerInit()
    $Ret = _IniReadToArray("Settings.ini")
    $Read = _IniRead_Array($Ret, "Desktop Radio", "PlayerGUIEnableTrans")
    $Diff = TimerDiff($Timer)

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox(0, "", $Diff)

    [/autoit] [autoit][/autoit] [autoit]

    Func _IniRead_Array($xArray, $xSection, $xKey)
    For $Loop = 0 To UBound($xArray) - 1
    Switch $xArray[$Loop][0]
    Case $xSection
    If $xArray[$Loop][1] = $xKey Then Return $xArray[$Loop][2]
    EndSwitch
    Next
    Return 0
    EndFunc ;==>_IniRead_Array

    [/autoit] [autoit][/autoit] [autoit]

    Func _IniReadToArray($zFile)
    Local $sSectionNames = IniReadSectionNames($zFile)
    Local $VirtIni[1][3]
    Local $Counter = 0
    For $l = 1 To $sSectionNames[0]
    $IRSTA = _IniReadSectionToArray($zFile, $sSectionNames[$l])
    ReDim $VirtIni[$Counter + UBound($IRSTA)][3]
    For $x = 0 To UBound($IRSTA) - 1
    $VirtIni[$Counter][0] = $IRSTA[$x][0]
    $VirtIni[$Counter][1] = $IRSTA[$x][1]
    $VirtIni[$Counter][2] = $IRSTA[$x][2]
    $Counter += 1
    Next
    Next
    Return $VirtIni
    EndFunc ;==>_IniReadToArray

    [/autoit] [autoit][/autoit] [autoit]

    Func _IniReadSectionToArray($iFile, $iSection)
    Local $INI = @ScriptDir & '\' & $iFile
    Local $aSection = IniReadSection($INI, $iSection)
    Local $aIni[$aSection[0][0]][3]
    For $i = 1 To UBound($aSection) - 1
    $aIni[$i - 1][0] = $iSection
    $aIni[$i - 1][1] = $aSection[$i][0]
    $aIni[$i - 1][2] = $aSection[$i][1]
    Next
    Return $aIni
    EndFunc ;==>_IniReadSectionToArray

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit]

    Zeit: 3 ms - (-0,8 ms)