Earthquake Posted August 14, 2006 Posted August 14, 2006 (edited) Hi Snipez, I wanted to write a little INI writer. The functionality is: Select a displayed name (is needed for another program, which reads the INI). Specify the file (via a little Browse Button). Save the record (write displayed name and the path of the program into an array). And last but not least a finish button, to write the INI. I've got the program finished so far, but the users of this program want me to change the Browse Button, that not C: is displayed, but the folder in which the last Program was selected (and saved). When I select a Program via Browse, the path may be "C:/Testfolder/Program.exe". I want to delete the "Program.exe" entry to save the "C:/Testfolder" in a new variable to use it with the Browse Button. Here's the code (I know its a GUI, but the function should be more standard coding ): expandcollapse popup#include <GUIConstants.au3> GUI() Func GUI() Local $Array1[1], $Array2[1] Local $iniFilename Local $Browse $iniDirectory = (@ScriptDir) $iniFilename = (@ScriptDir & '\Scriptlibary.ini') If FileExists($iniFilename) Then $Backup = MsgBox(1,"Backup","Do you want a backup of the old Scriptlibary.ini?") Select Case $Backup = $GUI_EVENT_CLOSE Exit Case $Backup = 1 DirCreate($iniDirectory & "\BackupINI") FileDelete($iniDirectory & "\BackupINI\Scriptlibary (Backup).ini") FileCopy($iniFilename, $iniDirectory & '\BackupINI\Scriptlibary (Backup).ini') MsgBox(4096,"Stored",'Backup has been created and stored in ' & @ScriptDir & '\Backup\Scriptlibary.ini') Case $Backup = 2 EndSelect EndIf $Counter=0 GUICreate(".ini Creator for Tool Launcher", 395,165, -1, -1, -1, 0x00000018) GUICtrlCreateLabel(".ini Creator for GPSD Tool Launcher", 110, 15, 200) GUICtrlCreateLabel("Displayed name:", 10, 50, 100) GUICtrlCreateLabel("Path of the program:", 10, 85, 100) GUICtrlCreateLabel("Record Nr. " & $Counter +1, 120, 114, 100) GUICtrlCreateLabel("Note: Only saved records will appear in the .ini!", 90, 140, 250) $NameProgram = GUICtrlCreateInput("Name", 110, 48, 180, 20) $ProgramPath = GUICtrlCreateInput("Path", 110, 81, 115, 20) $Browse = GUICtrlCreateButton ("Browse...", 235, 81, 55, 20) $NextButton = GUICtrlCreateButton("Save", 300, 43, 80, 60) $OkButton = GUICtrlCreateButton("Finish", 300, 110, 80, 20) GUISetState() $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $OkButton If $Counter = 0 Then $Counter = $Counter + 1 ReDim $Array1[$Counter] ReDim $Array2[$Counter] $Array1[$Counter - 1] = GUICtrlRead($NameProgram) $Array2[$Counter - 1] = GUICtrlRead($ProgramPath) EndIf ExitLoop Case $msg = $NextButton $Counter = $Counter + 1 ReDim $Array1[$Counter] ReDim $Array2[$Counter] $Array1[$Counter - 1] = GUICtrlRead($NameProgram) $Array2[$Counter - 1] = GUICtrlRead($ProgramPath) GUICtrlSetData($NameProgram,"") GUICtrlSetData($ProgramPath,"") GUICtrlCreateLabel("Record Nr. " & $Counter +1, 120, 114, 100) Case $msg = $Browse $Specified = FileOpenDialog("Select the tool, you want to insert","C:\", "Executes (*.exe)") If @error Then MsgBox(4096,"Error", "No file chosen") $Specified = StringReplace($Specified, "1", "Path") Else $Specified = StringReplace($Specified, "|", @CRLF) EndIf GUICtrlSetData($ProgramPath, $Specified) EndSelect WEnd FileOpen($iniFilename,2) FileWriteLine ($iniFilename,"[START]") FileWriteLine ($iniFilename,"") FileWriteLine ($iniFilename,"Amount=" & $Counter) FileWriteLine ($iniFilename,"") FileWriteLine ($iniFilename,"[Names]") FileWriteLine ($iniFilename,"") For $iCount = 0 To UBound($Array1) - 1 FileWriteLine ($iniFilename,'Script' & $iCount + 1 & '=' & $Array1[$iCount]) FileWriteLine ($iniFilename,$Array1[$iCount] & '=' & $Array2[$iCount]) Next FileClose($iniFilename) MsgBox(4096,"Done!", ".ini File has been written") EndFunc Thx a lot! EDIT: The INI will be writen in the folder, you save the program (but I bet u see the code and know more about it, then me ) Edited August 14, 2006 by Earthquake Yes, I am a noob! But at least I try to learn!Moddingtech.de - Home of the german Modding-Scene!
MHz Posted August 14, 2006 Posted August 14, 2006 Why not use an ini file to save the path $Specified = FileOpenDialog("Select the tool, you want to insert", IniRead(@ScriptDir & '\Settings.ini', 'Paths', 'SaveDir', 'C:\') , "Executes (*.exe)") If @error Then MsgBox(4096,"Error", "No file chosen") $Specified = StringReplace($Specified, "1", "Path") Else IniWrite(@ScriptDir & '\Settings', 'Paths', 'SaveDir', StringLeft($Specified, StringInStr($Specified, '\', 0, -1)-1)) $Specified = StringReplace($Specified, "|", @CRLF) EndIf The FileOpenDialog() can read from the Settings.ini, and later can be saved to it.
Earthquake Posted August 14, 2006 Author Posted August 14, 2006 This was quick! I already thougt of something like the new .ini File, but I wasnt sure. Thanks a lot!!! P.S. You had a little error in the code, but I found it IniWrite(@ScriptDir & '\Settings[u].ini[/u]', 'Paths', 'SaveDir', StringLeft($Specified, StringInStr($Specified, '\', 0, -1)-1)) ---- Problem solved ---- Yes, I am a noob! But at least I try to learn!Moddingtech.de - Home of the german Modding-Scene!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now