;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; AutoIt Version: 3.3.0.0 ;; ;; ;; ;; Template AutoIt script. ;; ;; ;; ;; AUTHOR: TheSaint ;; ;; ;; ;; SCRIPT FUNCTION: Example file with several examples to test the Virtual_INI_UDF ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #Include "Virtual_INI_UDF.au3" #Include ; IMPORTANT - These examples should be done in order, either individually (recommended), ; or all at once, as later functions require files and entries done by earlier ones. ;~ TestIniCreateSave() ;~ TestIniOpen() ;~ TestIniOpenRead() ;~ TestIniOpenAddKeySave() ;~ TestIniOpenUpdateSave() ;~ TestIniOpenAddSectionSave() ;~ TestIniOpenRemoveKeySave() ;~ TestIniOpenInformAddInformSave() ;~ TestIniOpenRenameKeySave() ;~ TestIniOpenRenameSectionSave() ;~ TestIniOpenReadCreateWriteSectionSave() ;~ TestIniOpenReadCreateWriteNewSectionSave() ;~ TestIniOpenSectionNamesArray() ;~ TestIniOpenKeyNamesArray() Exit ; Create an INI structure and Save it. Func TestIniCreateSave() Local $inidata, $inifle, $savfle $savfle = @ScriptDir & "\Saved.ini" ; $inidata = _Ini_Create("Created Section", "key", "value") If @error <> 1 Then _Ini_Show($inidata, "", "After Create") If @error <> 1 Then ; User needs to add code to check if exists etc. _Ini_Save($inidata, $savfle) ;If @error = 1 Then prompt for an alternate save file name etc. EndIf EndIf $inidata = _Ini_Close($inidata) EndFunc ;=> TestIniCreateSave ; Open an INI file into an INI structure and display it. Func TestIniOpen() Local $inidata, $inifle $inifle = @ScriptDir & "\Saved.ini" ; $inidata = _Ini_Open($inifle) If @error <> 1 Then _Ini_Show($inidata, "", "After Open") EndIf $inidata = _Ini_Close($inidata) EndFunc ;=> TestIniOpen ; Open an INI file into an INI structure and show requested key's value. Func TestIniOpenRead() Local $inidata, $inifle, $inival $inifle = @ScriptDir & "\Saved.ini" ; $inidata = _Ini_Open($inifle) If @error <> 1 Then $inival = _Ini_Read($inidata, "Created Section", "key") MsgBox(262208, "INI Value Read", $inival, 0) EndIf $inidata = _Ini_Close($inidata) EndFunc ;=> TestIniOpenRead ; Open an INI file into an INI structure and add specified key & value. Func TestIniOpenAddKeySave() Local $inidata, $inifle, $savfle $inifle = @ScriptDir & "\Saved.ini" $savfle = @ScriptDir & "\Saved.ini" ; $inidata = _Ini_Open($inifle) If @error <> 1 Then _Ini_Show($inidata, "", "Before Add Key") If @error <> 1 Then $inidata = _Ini_AddUpdate($inidata, "Created Section", "reduce", "6") If @error <> 1 Then _Ini_Show($inidata, "", "After Add Key") If @error <> 1 Then _Ini_Save($inidata, $savfle) If @error <> 1 Then $inidata = _Ini_Open($inifle) If @error <> 1 Then _Ini_Show($inidata, "", "Open After Save") EndIf EndIf EndIf EndIf EndIf EndIf $inidata = _Ini_Close($inidata) EndFunc ;=> TestIniOpenAddKeySave ; Open an INI file into an INI structure and update specified key with new value. Func TestIniOpenUpdateSave() Local $inidata, $inifle, $savfle $inifle = @ScriptDir & "\Saved.ini" $savfle = @ScriptDir & "\Saved.ini" ; $inidata = _Ini_Open($inifle) If @error <> 1 Then _Ini_Show($inidata, "", "Before Update Value") If @error <> 1 Then $inidata = _Ini_AddUpdate($inidata, "Created Section", "reduce", "") If @error <> 1 Then _Ini_Show($inidata, "", "After Update Value") If @error <> 1 Then _Ini_Save($inidata, $savfle) If @error <> 1 Then $inidata = _Ini_Open($inifle) If @error <> 1 Then _Ini_Show($inidata, "", "Open After Save") EndIf EndIf EndIf EndIf EndIf EndIf $inidata = _Ini_Close($inidata) EndFunc ;=> TestIniOpenUpdateSave ; Open an INI file into an INI structure and add specified section, key & value. Func TestIniOpenAddSectionSave() Local $inidata, $inifle, $savfle $inifle = @ScriptDir & "\Saved.ini" $savfle = @ScriptDir & "\Saved.ini" ; $inidata = _Ini_Open($inifle) If @error <> 1 Then _Ini_Show($inidata, "", "Before Add Section") If @error <> 1 Then $inidata = _Ini_AddUpdate($inidata, "New Section", "reduce", "8") If @error <> 1 Then _Ini_Show($inidata, "", "After Add Section") If @error <> 1 Then _Ini_Save($inidata, $savfle) If @error <> 1 Then $inidata = _Ini_Open($inifle) If @error <> 1 Then _Ini_Show($inidata, "", "Open After Save") EndIf EndIf EndIf EndIf EndIf EndIf $inidata = _Ini_Close($inidata) EndFunc ;=> TestIniOpenAddSectionSave ; Open an INI file into an INI structure and remove specified key. Func TestIniOpenRemoveKeySave() Local $inidata, $inifle, $savfle $inifle = @ScriptDir & "\Saved.ini" $savfle = @ScriptDir & "\Saved.ini" ; $inidata = _Ini_Open($inifle) If @error <> 1 Then _Ini_Show($inidata, "", "Before Remove Key") If @error <> 1 Then $inidata = _Ini_Remove($inidata, "Created Section", "reduce") If @error <> 1 Then _Ini_Show($inidata, "", "After Remove Key") If @error <> 1 Then _Ini_Save($inidata, $savfle) If @error <> 1 Then $inidata = _Ini_Open($inifle) If @error <> 1 Then _Ini_Show($inidata, "", "Open After Save") EndIf EndIf EndIf EndIf EndIf EndIf $inidata = _Ini_Close($inidata) EndFunc ;=> TestIniOpenRemoveKeySave ; Open an INI file into an INI structure and Inform on content details, then add ; some specified keys & values, and then Inform again, reporting on changes. Func TestIniOpenInformAddInformSave() Local $after, $before, $inidata, $inifle, $savfle $inifle = @ScriptDir & "\Saved.ini" $savfle = @ScriptDir & "\Saved.ini" ; $inidata = _Ini_Open($inifle) If @error <> 1 Then _Ini_Show($inidata, "", "Before Add Keys") $before = _Ini_Inform($inidata, 1) $inidata = _Ini_AddUpdate($inidata, "Created Section", "reduce", "6") If @error <> 1 Then $inidata = _Ini_AddUpdate($inidata, "Created Section", "more", "sex") If @error <> 1 Then $inidata = _Ini_AddUpdate($inidata, "New Section", "action", "Fly too high.") If @error <> 1 Then $after = _Ini_Inform($inidata) $before = StringSplit($before, "|", 1) $after = StringSplit($after, "|", 1) MsgBox(262208, "INI Changes Information", _ "More Characters = " & $after[1] - $before[1] & @LF & _ "More Words = " & $after[2] - $before[2] & @LF & _ "More Bytes = " & $after[3] - $before[3], 0) _Ini_Save($inidata, $savfle) If @error <> 1 Then $inidata = _Ini_Open($inifle) If @error <> 1 Then _Ini_Show($inidata, "", "Open After Save (Add Keys)") EndIf Else _Ini_Show($inidata, "", "After Add Keys (Save Failed)") EndIf Else MsgBox(262208, "INI Changes Information", "Third change failed.", 0) _Ini_Show($inidata, "", "After Third Key Failed To Add") EndIf Else MsgBox(262208, "INI Changes Information", "Second change failed.", 0) _Ini_Show($inidata, "", "After Second Key Failed To Add") EndIf Else MsgBox(262208, "INI Changes Information", "No Changes.", 0) EndIf EndIf $inidata = _Ini_Close($inidata) EndFunc ;=> TestIniOpenInformAddInformSave ; Open an INI file into an INI structure and rename specified key. Func TestIniOpenRenameKeySave() Local $inidata, $inifle, $savfle $inifle = @ScriptDir & "\Saved.ini" $savfle = @ScriptDir & "\Saved.ini" ; $inidata = _Ini_Open($inifle) If @error <> 1 Then _Ini_Show($inidata, "", "Before Rename Key") If @error <> 1 Then $inidata = _Ini_Rename($inidata, "Created Section", "induced", "reduce") If @error <> 1 Then _Ini_Show($inidata, "", "Afer Rename Key") If @error <> 1 Then _Ini_Save($inidata, $savfle) If @error <> 1 Then $inidata = _Ini_Open($inifle) If @error <> 1 Then _Ini_Show($inidata, "", "Open After Save") EndIf EndIf EndIf EndIf EndIf EndIf $inidata = _Ini_Close($inidata) EndFunc ;=> TestIniOpenRenameKeySave ; Open an INI file into an INI structure and rename specified section. Func TestIniOpenRenameSectionSave() Local $inidata, $inifle, $savfle $inifle = @ScriptDir & "\Saved.ini" $savfle = @ScriptDir & "\Saved.ini" ; $inidata = _Ini_Open($inifle) If @error <> 1 Then _Ini_Show($inidata, "", "Before Rename Section") If @error <> 1 Then $inidata = _Ini_Rename($inidata, "Created Section", "Original Section") If @error <> 1 Then _Ini_Show($inidata, "", "After Rename Section") If @error <> 1 Then _Ini_Save($inidata, $savfle) If @error <> 1 Then $inidata = _Ini_Open($savfle) If @error <> 1 Then _Ini_Show($inidata, "", "Open After Save") EndIf EndIf EndIf EndIf EndIf EndIf $inidata = _Ini_Close($inidata) EndFunc ;=> TestIniOpenRenameSectionSave ; Open an INI file into an INI structure and read specified section, then create ; another INI structure and then write the previous read section and Save. ; It attempts to read a non-existent section first, using the Report flag. Func TestIniOpenReadCreateWriteSectionSave() Local $inidata, $inifle, $savfle $inifle = @ScriptDir & "\Saved.ini" $savfle = @ScriptDir & "\Saved_2.ini" ; $inidata = _Ini_Open($inifle) If @error <> 1 Then _Ini_Show($inidata, "", "After Open (File 1)") If @error <> 1 Then $inival = _Ini_Read($inidata, "Created Section", "", 1) If @error = 1 Then $inival = _Ini_Read($inidata, "Original Section") EndIf If $inival <> "" Then MsgBox(262208, "INI Value Read", $inival, 0) $inidata = _Ini_Create("New Section", "newkey", "new value") If @error <> 1 Then _Ini_Show($inidata, "", "After Create (File 2)") If @error <> 1 Then ; We could Save to file at this point, and then even ; open it to Write the Section to, though not needed, ; as INI structure is still in virtual memory. $inidata = _Ini_WriteSection($inidata, $inival) If @error <> 1 Then _Ini_Show($inidata, "", "After Add Section (File 2)") If @error <> 1 Then _Ini_Save($inidata, $savfle) If @error <> 1 Then $inidata = _Ini_Open($savfle) If @error <> 1 Then _Ini_Show($inidata, "", "Open After Save (File 2)") EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf $inidata = _Ini_Close($inidata) EndFunc ;=> TestIniOpenReadCreateWriteSectionSave ; Open an INI file into an INI structure and read specified section, then open another INI file ; into an INI structure and then write the previous read section with a new name and Save. Func TestIniOpenReadCreateWriteNewSectionSave() Local $inidata, $inifle, $inival, $savfle $inifle = @ScriptDir & "\Saved.ini" $savfle = @ScriptDir & "\Saved_2.ini" ; $inidata = _Ini_Open($inifle) If @error <> 1 Then _Ini_Show($inidata, "", "After Open (File 1)") If @error <> 1 Then $inival = _Ini_Read($inidata, "New Section") If @error <> 1 Then MsgBox(262208, "INI Value Read", $inival, 0) $inidata = _Ini_Open($savfle) If @error <> 1 Then _Ini_Show($inidata, "", "After Open (File 2)") If @error <> 1 Then $inidata = _Ini_WriteSection($inidata, $inival, "Another Section") If @error <> 1 Then _Ini_Show($inidata, "", "After Add Renamed Section (File 2)") If @error <> 1 Then _Ini_Save($inidata, $savfle) If @error <> 1 Then $inidata = _Ini_Open($savfle) If @error <> 1 Then _Ini_Show($inidata, "", "Open After Save (File 2)") EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf $inidata = _Ini_Close($inidata) EndFunc ;=> TestIniOpenReadCreateWriteNewSectionSave Func TestIniOpenSectionNamesArray() Local $inidata, $inifle, $inisects $inifle = @ScriptDir & "\Saved_2.ini" ; $inidata = _Ini_Open($inifle) If @error <> 1 Then _Ini_Show($inidata, "", "After Open") If @error <> 1 Then $inisects = _Ini_SectionNames($inidata) If @error <> 1 Then If $inisects = "" Then MsgBox(262208, "INI Sections Information", "No sections were found.", 0) Else MsgBox(262208, "INI Keys Information", "Sections = " & $inisects, 0) $inisects = StringSplit($inisects, "|", 1) _ArrayDisplay($inisects, "Sections Found") EndIf EndIf EndIf EndIf $inidata = _Ini_Close($inidata) EndFunc ;=> TestIniOpenSectionNamesArray Func TestIniOpenKeyNamesArray() Local $inidata, $inifle, $inikeys $inifle = @ScriptDir & "\Saved_2.ini" ; $inidata = _Ini_Open($inifle) If @error <> 1 Then _Ini_Show($inidata, "", "After Open") If @error <> 1 Then $inikeys = _Ini_KeyNames($inidata, "Original Section") If @error <> 1 Then If $inikeys = "" Then MsgBox(262208, "INI Keys Information", "No keys were found.", 0) Else MsgBox(262208, "INI Keys Information", "Keys = " & $inikeys, 0) $inikeys = StringSplit($inikeys, "|", 1) _ArrayDisplay($inikeys, "Keys Found") EndIf EndIf EndIf EndIf $inidata = _Ini_Close($inidata) EndFunc ;=> TestIniOpenKeyNamesArray