Jump to content



Photo

View/edit Ini Files


  • Please log in to reply
13 replies to this topic

#1 strate

strate

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 539 posts

Posted 06 May 2006 - 11:22 PM

This is a script that I've created for one of my programs so that a user unfimiliar with INI files could change the values. This is my first contribution to the site so be gentle. I made it for my needs but see no reason in adding to it. Any recommendations would be great! It will work for any* INI file.

*Known problem: It crashes when creating the treeview for a LARGE ini that consists of 2K sections. Help solving that would be great also.

Beta is needed.

Plain Text         
#include <GUIConstants.au3> #Include <GuiTreeView.au3> #include <File.au3> $INIFile = 'C:\GUI Label Entry.ini' $EditMainGUI = GUICreate("View/Edit INI File", 350, 193) $treeview = GUICtrlCreateTreeView(6, 6, 230, 180, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) _ReadinINI() $b_INIView = GUICtrlCreateButton("&View/Edit", 245, 6, 100, 20) $b_INIColExp = GUICtrlCreateButton("&Collapse./Expand.", 245, 30, 100, 20) $b_INIPrint = GUICtrlCreateButton("&Print INI File", 245, 54, 100, 20) $b_INIExit = GUICtrlCreateButton("&Exit", 245, 78, 100, 20) GUISetState() While 1     $msg = GUIGetMsg()     Select         Case $msg = $b_INIExit Or $msg = $GUI_EVENT_CLOSE             ExitLoop         Case $msg = $b_INIView             $item = GUICtrlRead($treeview)  ; Get the controlID of the current selected treeview item             If $item = 0 Then                 _HideGUIMSGBoxShowGUI(64, "INI Edit", "No item currently selected.")             Else                 $advmsg = GUICtrlRead($item, 1); Get advanced infos about the treeview item                 If ($advmsg[0] == 0) Then                     _HideGUIMSGBoxShowGUI(16, "INI Edit: Error", "Error while retrieving info about selected item.")                 Else                     Global $Value = IniRead($INIFile, _GUICtrlTreeViewGetText($treeview, _GUICtrlTreeViewGetParentHandle($treeview)), $advmsg[0], 'ERROR')                     GUISetState(@SW_HIDE)                     $Edit = MsgBox(48 + 4096 + 4, "INI Edit", "Current key selected:   " & $advmsg[0] & @CR _                              & '         With a value of:   ' & $Value & @CR _                              & @CR _                              & 'Do you want to edit this value?')                     If $Edit = 6 Then; User wants to edit the value                         _EditValue()                     Else                         GUISetState(@SW_SHOW)                     EndIf                 EndIf             EndIf         Case $msg = $b_INIColExp             $item = GUICtrlRead($treeview)             If $item > 0 Then                 $hItem = GUICtrlGetHandle($item)                 GuiCtrlSendMsg($treeview, $TVM_EXPAND, $TVE_TOGGLE, $hItem)             EndIf         Case $msg = $b_INIPrint             _FilePrint ($INIFile)     EndSelect WEnd GUIDelete() Exit Func _HideGUIMSGBoxShowGUI($MsgBoxOptions, $MsgBoxTitle, $MsgBoxText)     GUISetState(@SW_HIDE)     Global $MsgAsr = MsgBox($MsgBoxOptions, $MsgBoxTitle, $MsgBoxText)     GUISetState(@SW_SHOW)     Return $MsgAsr EndFunc ;==>_HideGUIMSGBoxShowGUI Func _EditValue()     $EditGUI = GUICreate("INI Edit", 392, 89, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))     GUICtrlCreateLabel("Value:", 10, 10, 30, 20)     $Input_EditValue = GUICtrlCreateInput($Value, 10, 30, 370, 20)     $b_EditValue_Save = GUICtrlCreateButton("Save", 10, 60, 50, 20)     $b_EditValue_Restore = GUICtrlCreateButton("Restore Original Value", 70, 60, 120, 20)     $b_EditValue_Exit = GUICtrlCreateButton("Exit", 200, 60, 50, 20)     GUISetState()     While 1         $msg = GUIGetMsg()         Select             Case $msg = $GUI_EVENT_CLOSE                 ExitLoop             Case $msg = $b_EditValue_Exit                 ExitLoop             Case $msg = $b_EditValue_Restore                 GUICtrlSetData($Input_EditValue, $Value)                 GUICtrlSetState($Input_EditValue, $GUI_FOCUS)             Case $msg = $b_EditValue_Save                 $Edit = MsgBox(48 + 4096 + 4, "INI Edit", "Are you sure you want to replace:" & @CR _                          & '          ' & $Value & @CR _                          & 'With:' & @CR _                          & '          ' & GUICtrlRead($Input_EditValue))                 If $Edit = 6 Then; User wants to edit the value                     $Err = IniWrite($INIFile, _GUICtrlTreeViewGetText($treeview, _GUICtrlTreeViewGetParentHandle($treeview)), $advmsg[0], GUICtrlRead($Input_EditValue))                     If $Err = 0 Then MsgBox(4096, 'Error Occured', 'New value was NOT added to the INI File.')                     GUISwitch($EditMainGUI)                     _GUICtrlTreeViewExpand($treeview, 0)                     GUISwitch($EditGUI)                     ExitLoop                 EndIf         EndSelect     WEnd     GUIDelete()     GUISetState(@SW_SHOW) EndFunc ;==>_EditValue Func _ReadinINI()     $var = IniReadSectionNames($INIFile)     If @error Then         MsgBox(4096, "", "Error occured, probably no INI file.")     Else         Dim $generalitem[1]         For $i = 1 To $var[0]             ReDim $generalitem[UBound($generalitem) + 1]             $generalitem [UBound($generalitem) - 1] = GUICtrlCreateTreeViewItem($var[$i], $treeview)             GUICtrlSetState(-1, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))             GUICtrlSetColor(-1, 0x0000C0)             $var1 = IniReadSection($INIFile, $var[$i])             If @error Then                 MsgBox(4096, "", "Error occured, probably no INI file.")                 Exit             Else                 For $ii = 1 To $var1[0][0]                     $DetailItem = GUICtrlCreateTreeViewItem($var1[$ii][0], $generalitem[$i])                 Next             EndIf         Next     EndIf EndFunc ;==>_ReadinINI

Edited by strate, 06 May 2006 - 11:23 PM.

INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...







#2 nfwu

nfwu

    I'm not active on these forums

  • Active Members
  • PipPipPipPipPipPip
  • 1,234 posts

Posted 06 May 2006 - 11:37 PM

So someone did a treeview for one!

Well... look at by (n00bish) one in my sig: Under UDFs : _DialogEditIni()

#)

#3 strate

strate

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 539 posts

Posted 06 May 2006 - 11:45 PM

So someone did a treeview for one!

Well... look at by (n00bish) one in my sig: Under UDFs : _DialogEditIni()

#)

I like that, never thought about the adding, removing sections, and a save as. I think yours might intimidate some of my coworkers, lol.
INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

#4 Valuater

Valuater

    www.PayFreeWireless.com

  • MVPs
  • 11,078 posts

Posted 07 May 2006 - 12:31 AM

i couldn't get either one of nfwu's .. t.au3 or the posted code to wrk... just kept gwtting errors.. anyways i played with yours alittle

it read my 493 line ini... right off the bat... but they are just numbers, so i added the actual value to the script

Plain Text         
#include <GUIConstants.au3> #Include <GuiTreeView.au3> #include <File.au3> $INIFile = @ScriptDir & "\lang.lng" $EditMainGUI = GUICreate("View/Edit INI File", 350, 193) $treeview = GUICtrlCreateTreeView(6, 6, 230, 180, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) _ReadinINI() $b_INIView = GUICtrlCreateButton("&View/Edit", 245, 6, 100, 20) $b_INIColExp = GUICtrlCreateButton("&Collapse./Expand.", 245, 30, 100, 20) $b_INIPrint = GUICtrlCreateButton("&Print INI File", 245, 54, 100, 20) $b_INIExit = GUICtrlCreateButton("&Exit", 245, 78, 100, 20) GUISetState() ; Or StringLeft($item, 3) = "*= " While 1     $msg = GUIGetMsg()     Select         Case $msg = $b_INIExit Or $msg = $GUI_EVENT_CLOSE             ExitLoop         Case $msg = $b_INIView             $item = GUICtrlRead($treeview)   ; Get the controlID of the current selected treeview item             If $item = 0 Then                 _HideGUIMSGBoxShowGUI(64, "INI Edit", "No item currently selected.")             Else                 $advmsg = GUICtrlRead($item, 1); Get advanced infos about the treeview item                 If ($advmsg[0] == 0) Then                     _HideGUIMSGBoxShowGUI(16, "INI Edit: Error", "Error while retrieving info about selected item.")                 ElseIf StringLeft($advmsg[0], 7) == "Value= " Then                     MsgBox(64, "INI Value", "Please Select the Corresponding key   ", 2)                   Else                     Global $Value = IniRead($INIFile, _GUICtrlTreeViewGetText($treeview, _GUICtrlTreeViewGetParentHandle($treeview)), $advmsg[0], 'ERROR')                     GUISetState(@SW_HIDE)                     $Edit = MsgBox(48 + 4096 + 4, "INI Edit", "Current key selected:   " & $advmsg[0] & @CR _                              & '         With a value of:   ' & $Value & @CR _                              & @CR _                              & 'Do you want to edit this value?')                     If $Edit = 6 Then; User wants to edit the value                         _EditValue()                     Else                         GUISetState(@SW_SHOW)                     EndIf                 EndIf             EndIf         Case $msg = $b_INIColExp             $item = GUICtrlRead($treeview)             If $item > 0 Then                 $hItem = GUICtrlGetHandle($item)                 GuiCtrlSendMsg($treeview, $TVM_EXPAND, $TVE_TOGGLE, $hItem)             EndIf         Case $msg = $b_INIPrint             _FilePrint ($INIFile)     EndSelect WEnd GUIDelete() Exit Func _HideGUIMSGBoxShowGUI($MsgBoxOptions, $MsgBoxTitle, $MsgBoxText)     GUISetState(@SW_HIDE)     Global $MsgAsr = MsgBox($MsgBoxOptions, $MsgBoxTitle, $MsgBoxText)     GUISetState(@SW_SHOW)     Return $MsgAsr EndFunc;==>_HideGUIMSGBoxShowGUI Func _EditValue()     $EditGUI = GUICreate("INI Edit", 392, 89, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))     GUICtrlCreateLabel("Value:", 10, 10, 30, 20)     $Input_EditValue = GUICtrlCreateInput($Value, 10, 30, 370, 20)     $b_EditValue_Save = GUICtrlCreateButton("Save", 10, 60, 50, 20)     $b_EditValue_Restore = GUICtrlCreateButton("Restore Original Value", 70, 60, 120, 20)     $b_EditValue_Exit = GUICtrlCreateButton("Exit", 200, 60, 50, 20)     GUISetState()     While 1         $msg = GUIGetMsg()         Select             Case $msg = $GUI_EVENT_CLOSE                 ExitLoop             Case $msg = $b_EditValue_Exit                 ExitLoop             Case $msg = $b_EditValue_Restore                 GUICtrlSetData($Input_EditValue, $Value)                 GUICtrlSetState($Input_EditValue, $GUI_FOCUS)             Case $msg = $b_EditValue_Save                 $Edit = MsgBox(48 + 4096 + 4, "INI Edit", "Are you sure you want to replace:" & @CR _                          & '          ' & $Value & @CR _                          & 'With:' & @CR _                          & '          ' & GUICtrlRead($Input_EditValue))                 If $Edit = 6 Then; User wants to edit the value                     $Err = IniWrite($INIFile, _GUICtrlTreeViewGetText($treeview, _GUICtrlTreeViewGetParentHandle($treeview)), $advmsg[0], GUICtrlRead($Input_EditValue))                     If $Err = 0 Then MsgBox(4096, 'Error Occured', 'New value was NOT added to the INI File.')                     GUISwitch($EditMainGUI)                     _GUICtrlTreeViewExpand($treeview, 0)                     GUISwitch($EditGUI)                     ExitLoop                 EndIf         EndSelect     WEnd     GUIDelete()     GUISetState(@SW_SHOW) EndFunc;==>_EditValue Func _ReadinINI()     $var = IniReadSectionNames($INIFile)     If @error Then         MsgBox(4096, "", "Error occured, probably no INI file.")     Else         Dim $generalitem[1]         For $i = 1 To $var[0]             ReDim $generalitem[UBound($generalitem) + 1]             $generalitem [UBound($generalitem) - 1] = GUICtrlCreateTreeViewItem($var[$i], $treeview)             GUICtrlSetState(-1, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))             GUICtrlSetColor(-1, 0x0000C0)             $var1 = IniReadSection($INIFile, $var[$i])             If @error Then                 MsgBox(4096, "", "Error occured, probably no INI file.")                 Exit             Else                 For $ii = 1 To $var1[0][0]                     $DetailItem = GUICtrlCreateTreeViewItem($var1[$ii][0], $generalitem[$i])                     GUICtrlSetState(-1, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))                     GUICtrlSetColor(-1, 0x0000C0)                     $look = GUICtrlCreateTreeViewItem("Value= " &$var1[$ii][1], $generalitem[$i])                 Next             EndIf         Next     EndIf EndFunc;==>_ReadinINI


8)

Posted Image

Clic The Pic!!!


#5 nfwu

nfwu

    I'm not active on these forums

  • Active Members
  • PipPipPipPipPipPip
  • 1,234 posts

Posted 07 May 2006 - 12:38 AM

i couldn't get either one of nfwu's .. t.au3 or the posted code to wrk... just kept gwtting errors.. anyways i played with yours alittle


You require to input a valid ini file into the function... sorry but it does not create inis...

#)

#6 Valuater

Valuater

    www.PayFreeWireless.com

  • MVPs
  • 11,078 posts

Posted 07 May 2006 - 12:57 AM

You require to input a valid ini file into the function... sorry but it does not create inis...

#)


i used this
_DialogEditIni(@ScriptDir & "\lang.lng")

for one
and..

_EditIniDialog(@ScriptDir & "\lang.lng")

for the other

i got all kinds of errors

example

from posted code ElseIf $msg == $SectionDelButton Or $msg == $SectionDelButton Or _                         $msg == $SectionEdiButton Or $msg == $PairNewButton Or _                         $msg == $PairDelButton Or $msg == $PairEdiButton Or $msg == $SaveSavButton                     MsgBox(262160, $EIDtitle & " - Error", "You are in (Read-Only) Mode." & @CRLF & "You are not allowed to edit the data")


there is no "Then"

8)

Posted Image

Clic The Pic!!!


#7 nfwu

nfwu

    I'm not active on these forums

  • Active Members
  • PipPipPipPipPipPip
  • 1,234 posts

Posted 07 May 2006 - 12:59 AM

I see now... thanks for pointing out my syntax errors...

Edit: Come to think of that it is wierd... I used the exact same code to produce the screenshot...

#)

Edited by nfwu, 07 May 2006 - 01:01 AM.


#8 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 07 May 2006 - 09:59 AM

this is really nice. Good work!
My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

#9 Valuater

Valuater

    www.PayFreeWireless.com

  • MVPs
  • 11,078 posts

Posted 07 May 2006 - 10:03 AM

this is really nice. Good work!



@Razer... did you try my updated version???

8)

Posted Image

Clic The Pic!!!


#10 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 07 May 2006 - 10:21 AM

i have now, that is much better
My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

#11 Valuater

Valuater

    www.PayFreeWireless.com

  • MVPs
  • 11,078 posts

Posted 07 May 2006 - 10:23 AM

i have now, that is much better



Thanks...

and i like your web site... nice and clean looking

8)

Posted Image

Clic The Pic!!!


#12 gw_1966

gw_1966

    Seeker

  • Active Members
  • 17 posts

Posted 04 May 2007 - 05:55 AM

Hi.

I dont know if anyone can help me. But when I tried to use this script. It did everything fine but edit the ini file. It came up with the error
"Subscript used with non-Array variable."
If ($advmsg[0] == 0) Then
If ($advmsg^ ERROR
It seems to stop on this line. Any ideas?
CheersGrant

#13 ToKicoBrothers

ToKicoBrothers

    Seeker

  • Active Members
  • 30 posts

Posted 04 May 2007 - 04:40 PM

Very cool script!!! :)
Posted Image Posted Image Posted Image Posted Image My Scripts: SimplePlayer 1.0 - A very simple music player. PCInfo 1.2 - A script that displays PC information.

#14 PsaltyDS

PsaltyDS

    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 14 May 2007 - 11:00 AM

Hi.

I dont know if anyone can help me. But when I tried to use this script. It did everything fine but edit the ini file. It came up with the error
"Subscript used with non-Array variable."
If ($advmsg[0] == 0) Then
If ($advmsg^ ERROR
It seems to stop on this line. Any ideas?

I think it's because of this:
$advmsg = GUICtrlRead($item, 1); Get advanced infos about the treeview item                 If ($advmsg[0] == 0) Then                      ; ...                 EndIf


I don't think GuiCtrlRead() ever returns an array, even for advanced mode. So the array reference is inappropriate. In this code, $item is the control ID of a TreeViewItem, and GuiCtrlRead($item, 1) returns the text of $item.

:)

Edited by PsaltyDS, 14 May 2007 - 11:06 AM.

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users