au3scr Posted April 17, 2008 Share Posted April 17, 2008 When i pres save for settings file ($saveb) it duplicates text ant then saves it , how to fix it? expandcollapse popup#include <guiconstants.au3> #include <File.au3> #include <String.au3> #include <GuiEdit.au3> GUICreate("Config Editor",640,800) $configpath = GUICtrlCreateInput("file path not loaded",3,3,634) $load = GUICtrlCreateButton("Load",3,25+1) $reload = GUICtrlCreateButton("ReLoad",3 + 33,25+1) $save = GUICtrlCreateButton("Save",3 + 33 + 45,25+1) $loadb = GUICtrlCreateButton("Load",3,25+26) $reloadb = GUICtrlCreateButton("ReLoad",3 + 33,25+26) $saveb = GUICtrlCreateButton("Save",3 + 33 + 45,25+26) GUICtrlCreateLabel("<--- For settings file path",3+33+45+28+ 10,35) GUICtrlCreateLabel("<--- Bottons for main settings file",3+33+45+28+ 10,55) $edit1 = GUICtrlCreateEdit("file path not loaded",3,3 + 77,634,800 - 93) GUISetState (@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $save $pathtexet = GUICtrlRead($configpath) $crypt = _StringEncrypt(1,$pathtexet,"keerulinesalas6na",1) FileWrite(@ScriptDir&"\path",$crypt) Case $load $read = FileReadLine (@ScriptDir&"\path",1) $decrypted = _StringEncrypt(0,$read,"keerulinesalas6na",1) $configfilepath = $decrypted GUICtrlSetData($configpath,$configfilepath) Case $reload $read = FileReadLine (@ScriptDir&"\path",1) $decrypted = _StringEncrypt(0,$read,"keerulinesalas6na",1) $configfilepath = $decrypted GUICtrlSetData($configpath,$configfilepath) Case $loadb $read = FileRead (@ScriptDir&"\path") $decrypted = _StringEncrypt(0,$read,"keerulinesalas6na",1) $configfile = $decrypted $set = FileRead($decrypted) GUICtrlSetData($edit1, $set) Case $reloadb $read = FileRead (@ScriptDir&"\path") $decrypted = _StringEncrypt(0,$read,"keerulinesalas6na",1) $configfile = $decrypted $set = FileRead($decrypted) GUICtrlSetData($edit1, $set) Case $saveb $read = FileRead (@ScriptDir&"\path") $decrypted = _StringEncrypt(0,$read,"keerulinesalas6na",1) $configfile = $decrypted $settingstexet = GUICtrlRead($edit1) $set = FileWrite ($configfile,$settingstexet) EndSwitch Wend Link to comment Share on other sites More sharing options...
weaponx Posted April 17, 2008 Share Posted April 17, 2008 How do you ever get anything done? You are using FileWriteLine without an existing handle so its appending to an existing file...use FileOpen() with the option to replace contents. Link to comment Share on other sites More sharing options...
au3scr Posted April 17, 2008 Author Share Posted April 17, 2008 But in this function it works Func Defaults($iDelay = 0) Local $sCmdFile FileDelete($configfilepath) $sCmdFile = 'toor' & @CRLF _ & 'NO' & @CRLF _ & 'YES' & @CRLF _ & 'YES' & @CRLF _ & 'C:\Program Files\Mozilla Firefox\firefox.exe' & @CRLF _ & 'Notepad' & @CRLF _ & @ProgramFilesDir & '\7-Zip\7zFM.exe' & @CRLF _ & @ProgramFilesDir & '\OpenOffice.org 2.3\program\swriter.exe' & @CRLF _ & @ProgramFilesDir & '\OpenOffice.org 2.3\program\smath.exe' & @CRLF _ & @ProgramFilesDir & '\OpenOffice.org 2.3\program\simpress.exe' & @CRLF _ & @ProgramFilesDir & '\OpenOffice.org 2.3\program\sdraw.exe' & @CRLF _ & @ProgramFilesDir & '\OpenOffice.org 2.3\program\scalc.exe' & @CRLF _ & @ProgramFilesDir & '\OpenOffice.org 2.3\program\sbase.exe' & @CRLF _ & @ProgramFilesDir & '\Notepad++\notepad++.exe' & @CRLF _ & 'Word' & @CRLF _ & 'Excel' & @CRLF _ & 'Wallpapers=YES' & @CRLF _ & @ProgramFilesDir & '\IrfanView\i_view32.exe' & @CRLF _ & @ProgramFilesDir & '\GIMP-2.0\bin\gimp-2.4.exe' & @CRLF _ & @SystemDir & '\mspaint.exe' & @CRLF _ & @ProgramFilesDir & '\VideoLAN\VLC\vlc.exe' & @CRLF _ & 'root' & @CRLF _ & 'C:\run.exe' & @CRLF _ & 'C:\taskmanager.exe' FileWrite($configfilepath, $sCmdFile) EndFunc ;==>Defaults Link to comment Share on other sites More sharing options...
GEOSoft Posted April 17, 2008 Share Posted April 17, 2008 Sure it will, because you deleted the file first so you can use FileWrite or FileWriteLine without first using FileOpen() but it the file exists then any FileWrite or FileWriteLine will append to the existing file. There are two ways to do what you want when using an existing file. $tFile = FileOpen("myFile.txt", 2) FileClose($tFile) Write whatever you want to the file "myFile.txt" because it is now blank. However this method is prefered, $tFile = FileOpen("myFile.txt", 2) Write whatever you want to $tFile Write some more to $tFile FileClose($tFile) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
weaponx Posted April 17, 2008 Share Posted April 17, 2008 Yes it works because you are deleting the file: FileDelete($configfilepath) And then you are using FileWrite(): FileWrite($configfilepath, $sCmdFile) Link to comment Share on other sites More sharing options...
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