INIReadSections, Loop, Combo - Array?

  • Hallo Leute,

    ich schreibe gerade ein Programm für den FireFox um Profile zu sichern.

    Die Anzahl bzw. die Namen der Profile des FF lese ich wie folgt aus und lasse aus den ausgelesenen Namen die Einträge für das Combo-Element generieren.

    [autoit]

    $combo1 = GUICtrlCreateCombo("alle Profile", 120, 147, 145, 50)
    $wahl1 = GUICtrlSetData($combo1, "alle Profile", "alle Profile")

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

    Dim $profileslist = IniReadSectionNames($profilesdir & "\profiles.ini")
    For $i = 2 To $profileslist[0] ;durch die 2 wird erst der 2. Wert ausgegeben, der 1. Wert wird ignoriert
    Dim $profilename = IniRead($profilesdir & "\profiles.ini", $profileslist[$i], "Name", "-NichtGefunden-")
    GUICtrlSetData($combo1, $profilename, $lastprofile)
    Next

    [/autoit]


    Durch das obige Script werden die Sections-Namen aus der INI ausgelesen und als Data-Werte an die Como übergeben. Das klappt soweit sehr gut.
    Problematisch ist nun für mich, das ich zu den Namen auch die passenden Pfade benötige, die ebenfalls in der "Profiles.ini" unter den Sections-Namen stehen.
    Kann ich irgendwie die Werte für "Name und "Pfad" zu den jeweiligen Sectionsnamen in ein Array schreiben, um später damit zu arbeiten?
    Und wenn JA, Wie?

    Danke im Voraus

    PS: Hier mal ein Auszug aus der erwähnten INI

  • So Beispielsweise:

    Code
    $asPath[0][0] -> Anzahl der Elemente
    $asPath[n][0] -> Name der Sektion
    $asPath[n][1] -> Der Pfad in der Sektion
    Spoiler anzeigen
    [autoit]

    #include <Array.au3>

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

    Global $asPath[1][2] ;// Array für die Pfade deklaieren
    Global $sINI = 'xyz.ini' ;// Pfad der INI
    Global $asReadSN = IniReadSectionNames($sINI)

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

    Global $iOne, $asReadS, $iTwo

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

    ; ++++++++++ +++++++++ ++++++++ +++++++ +++++ ++++ +++ ++ +

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

    For $iOne = 1 To $asReadSN[0]
    ConsoleWrite(@CRLF & $asReadSN[$iOne] & @CRLF)
    $asReadS = IniReadSection($sINI, $asReadSN[$iOne])
    For $iTwo = 1 To $asReadS[0][0]
    ConsoleWrite(' ' & $asReadS[$iTwo][0] & ' = ' & $asReadS[$iTwo][1] & @CRLF)
    If $asReadS[$iTwo][0] = 'Path' Then ;// Hier nach "Path" suchen...
    ReDim $asPath[UBound($asPath) +1][2]
    $asPath[0][0] += 1
    $asPath[$asPath[0][0]][0] = $asReadSN[$iOne]
    $asPath[$asPath[0][0]][1] = $asReadS[$iTwo][1]
    EndIf
    Next
    Next

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

    ConsoleWrite(@CRLF)
    _ArrayDisplay($asPath)

    [/autoit]
  • Vielen Dank!

    @Make-Grafik: Das funktioniert soweit schon sehr gut.

    Nun würde ich das? array gern um den Wert von "Name" aus der INI erweitern
    Also Sectionsname Name Pfad.
    Durch die mehrfachen Schleifen bekommeich das iwie nicht hin.

    Ich lasse mir am Ende erstmal eine MsgBox anzeigen, um die Werte zu kontrollieren

    Spoiler anzeigen
    [autoit]

    #include <Array.au3>

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

    Global $asPath[1][2] ;// Array für die Pfade deklaieren
    Global $sINI = @AppDataDir & "\Mozilla\Firefox\profiles.ini" ;// Pfad der INI
    Global $asReadSN = IniReadSectionNames($sINI)

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

    Global $iOne, $asReadS, $iTwo

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

    ; ++++++++++ +++++++++ ++++++++ +++++++ +++++ ++++ +++ ++ +

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

    For $iOne = 1 To $asReadSN[0]
    ConsoleWrite(@CRLF & $asReadSN[$iOne] & @CRLF)
    $asReadS = IniReadSection($sINI, $asReadSN[$iOne])
    For $iTwo = 1 To $asReadS[0][0]
    ConsoleWrite(' ' & $asReadS[$iTwo][0] & ' = ' & $asReadS[$iTwo][1] & @CRLF)
    If $asReadS[$iTwo][0] = 'Path' Then ;// Hier nach "Path" suchen...
    ReDim $asPath[UBound($asPath) +1][2]
    $asPath[0][0] += 1
    $asPath[$asPath[0][0]][0] = $asReadSN[$iOne]
    $asPath[$asPath[0][0]][1] = $asReadS[$iTwo][1]
    EndIf
    Next
    Next

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

    ;ConsoleWrite(@CRLF)
    ;_ArrayDisplay($asPath)
    MsgBox(4096, "", $asPath[10][0])

    [/autoit]
  • Besten Dank.

    Klappt soweit.
    Ist jedoch für die spätere Weiterverarbeitung nicht so gut.

    Ich versuche nun, deinen Code so umzustricken, das ich am Ende alles in einer Zeile habe.
    Also Nummer, SectionsName, Name, Pfad
    Nur wenn ich das Array so gestalte, kann ich später problemlos darauf zurückgreifen.

    Hintergrund:

    1. die maximale Anzahl vorhandener Profile soll aus der INI über die SectionsNamen ausgelesen werden
    2. aus den SecrtionNamen soll der Wert für Name ausgelesen werden
    3. im Combo-Feld sollen nun alle Namen lesbar und entsprechend auswählbar sein
    4. der vom Benutzer selektierte Wert im Combo soll in eine Variable geschrieben werden
    5. Anhand dieser Variable generiere ich einen Hinweis: "Profil "Name" wird nun gesichert..."
    6. über die Variable aus Comboread weise ich dem finalen Kopierprozess den passenden Pfad zu

    Vielleicht lässt es sich logisch ja auch anders realisieren. Zumal die SectionsNamen immer gleich sind und am Ende nur hochgezählt wird (Profile0, Profile1, usw.)