INI Datei eine VAR pro KEY

  • Hallo,
    Ich habe folgendes Problem:
    Ich möchte das am anfang des Programmes aus einer INI datei jeder KEY in eine andere VAR kommt!
    Das hat folgenden Grund:
    ich mache gerade ein PS2 ISO OVERVIEW tool, bei click auf ein Bild soll das nächste kommen.
    Die bilder sind in der ini gespeichert.

    Hier mein code:

    Spoiler anzeigen
    [autoit]


    #RequireAdmin

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

    #region
    #cs
    Global Const $Path_Pic_1 = @ScriptDir & "\Bild1.bmp"
    Global Const $Path_Pic_2 = @ScriptDir & "\Bild2.bmp"
    Global $Pic_State = $Path_Pic_1
    #ce
    #endregion

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

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

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

    DirCreate(@ScriptDir & "\cover\")
    DirCreate(@ScriptDir & "\opt\")

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

    If not FileExists(@ScriptDir & "\opt\options.ini") Then
    IniWrite(@ScriptDir & "\opt\options.ini","MAIN","Success","true")
    EndIf
    If not FileExists(@ScriptDir & "\opt\path.ini") Then
    MsgBox(0,"INFO","Please go to Options and set youre Emulator path!")
    EndIf
    If not FileExists(@ScriptDir & "\cover\default.jpg") Then
    FileInstall("C:\Users\Dustin\Desktop\Projekte\PS2 ISO Overview\default.jpg", @ScriptDir & "\cover\default.jpg")
    EndIf

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

    $allgames = IniReadSection(@ScriptDir & "\opt\games.ini","MAIN")
    If @error Then
    MsgBox(4096, "", "Error occurred, probably no INI file.")
    Else
    For $i = 1 To $allgames[0][0]

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

    MsgBox(4096, "", "Key: " & $allgames[$i][0] & @CRLF & "Value: " & $allgames[$i][1])
    Next
    EndIf

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

    ;MsgBox(0,"",@ScriptDir & "\cover\default.jpg")
    #Region ### START Koda GUI section ### Form=C:\Users\Dustin\Desktop\Projekte\PS2 ISO Overview\gui_main.kxf
    $gui_main = GUICreate("PlayStation 2 ISO Overview by ChaosClan", 345, 538, 192, 124)
    GUISetFont(12, 400, 0, "Comic Sans MS")
    $pb_game = GUICtrlCreatePic(@ScriptDir & "\cover\default.jpg", 8, 8, 321, 401)
    $bt_start_game = GUICtrlCreateButton("START GAME", 8, 424, 147, 49)
    $bt_options = GUICtrlCreateButton("Options...", 184, 424, 139, 49)
    $Register = GUICtrlCreateButton("Register", 120, 488, 91, 41)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    #Region ### START Koda GUI section ### Form=C:\Users\Dustin\Desktop\Projekte\PS2 ISO Overview\gui_options.kxf
    $gui_options = GUICreate("Options...", 178, 318, 192, 124)
    GUISetFont(12, 400, 0, "Comic Sans MS")
    $bt_add_game_gui = GUICtrlCreateButton("Add Game", 8, 16, 161, 57, $BS_NOTIFY)
    $bt_emulator_path = GUICtrlCreateButton("Emulator Path", 8, 88, 161, 57, $BS_NOTIFY)
    $bt_credits_options = GUICtrlCreateButton("Credits", 8, 160, 161, 57, $BS_NOTIFY)
    $bt_apply = GUICtrlCreateButton("Apply", 8, 232, 161, 57, $BS_NOTIFY)
    GUISetState(@SW_HIDE)
    #EndRegion ### END Koda GUI section ###

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

    #Region ### START Koda GUI section ### Form=C:\Users\Dustin\Desktop\Projekte\PS2 ISO Overview\gui_add_game.kxf
    $gui_add_game = GUICreate("Add Game", 419, 204, 192, 124)
    GUISetFont(12, 400, 0, "Comic Sans MS")
    $ib_iso_path = GUICtrlCreateInput("", 128, 8, 233, 31, $GUI_SS_DEFAULT_INPUT)
    $Label1 = GUICtrlCreateLabel("ISO File:", 8, 8, 75, 27, 0)
    $bt_iso_select = GUICtrlCreateButton("...", 376, 8, 35, 33, $BS_NOTIFY)
    $Label2 = GUICtrlCreateLabel("Cover Path:", 8, 64, 87, 27, 0)
    $ib_cover_path = GUICtrlCreateInput("", 128, 64, 233, 31, $GUI_SS_DEFAULT_INPUT)
    $bt_cover_select = GUICtrlCreateButton("...", 376, 64, 35, 33, $BS_NOTIFY)
    $bt_add_game = GUICtrlCreateButton("ADD GAME", 8, 168, 403, 25, $BS_NOTIFY)
    $Label3 = GUICtrlCreateLabel("Name:", 8, 120, 49, 27)
    $ib_name = GUICtrlCreateInput("", 128, 120, 233, 31)
    GUISetState(@SW_HIDE)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

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

    Case $bt_add_game_gui
    GUISetState(@SW_SHOW, $gui_add_game)
    Case $bt_emulator_path
    $path = InputBox("Please give me youre Path to the PS2 Emulator","Youre Path:")
    IniWrite(@ScriptDir & "\opt\path.ini","MAIN","Path",$path)

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

    Case $bt_credits_options
    MsgBox(0,"INFO","Coded by Dustin" & @CRLF & "Made in AutoIT")

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

    Case $bt_start_game

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

    Case $bt_options
    GUISetState(@SW_SHOW, $gui_options)

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

    Case $bt_apply
    GUISetState(@SW_HIDE, $gui_options)

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

    Case $Register
    MsgBox(0,"INFO","Please go to ... and download the register Tool!")

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

    Case $bt_iso_select
    $isopath = FileOpenDialog("ISO...", "C:\", "ISO Files (*.iso; *.bin;)")
    GUICtrlSetData($ib_iso_path, $isopath)

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

    Case $bt_cover_select
    $coverpath = FileOpenDialog("ISO...", "C:\", "IMG Files (*.jpg; *.jpeg; *.png; *.bmp)")
    GUICtrlSetData($ib_cover_path, $coverpath)
    Case $bt_add_game
    If $ib_iso_path = "" Then
    MsgBox(64,"ERROR","Restarting... Please dont leave a the ISO path blank!")
    Exit
    EndIf
    If $ib_name = "" Then
    MsgBox(64,"ERROR","Restarting... Please dont leave a the name blank!")
    Exit
    EndIf
    If $ib_cover_path = "" Then
    $v = 1
    Else
    $v = 0
    EndIf

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

    $iso_var = GUICtrlRead($ib_iso_path)
    $cover_var = GUICtrlRead($ib_cover_path)
    $name_var = GUICtrlRead($ib_name)

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

    If $v = 1 Then
    IniWrite(@ScriptDir & "\opt\games.ini","MAIN",$name_var,$iso_var)
    IniWrite(@ScriptDir & "\opt\cover.ini","MAIN",$name_var,$cover_var)
    MsgBox(0,"INFO","Game added!")
    Else
    MsgBox(0,"INFO","use default cover")
    IniWrite(@ScriptDir & "\opt\games.ini","MAIN",$name_var,$iso_var)
    IniWrite(@ScriptDir & "\opt\cover.ini","MAIN",$name_var,"default")
    MsgBox(0,"INFO","Game added!")
    EndIf

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

    Case $pb_game
    #cs
    if $Pic_State == $Path_Pic_1 Then
    GUICtrlSetImage($GUI_PictureBox, $Path_Pic_2)
    $Pic_State = $Path_Pic_2
    ElseIf $Pic_State == $Path_Pic_2 Then
    GUICtrlSetImage($GUI_PictureBox, $Path_Pic_1)
    $Pic_State = $Path_Pic_1
    EndIf
    #ce

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

    EndSwitch
    WEnd

    [/autoit]
    • Offizieller Beitrag

    Einfach in einer eigenen Sektion speichern, der Keyname ist dabei völlig egal, den brauchst du gar nicht, muß nur angegeben werden, da die INI das erwartet:

    Code
    [bilder]
    bild1=Pfad1
    bild2=Pfad2
    bild3=Pfad3


    In deinem Skript lädst du beim Start die Pfade in ein Array:

    [autoit]

    $aPicture = IniReadSection('Pfad_INI_Datei', 'bilder')
    ; Bild1 ist dann $aPicture[1][1], Bild2 ist dann $aPicture[2][1] usw.

    [/autoit]