pl4y0n Posted April 21, 2011 Share Posted April 21, 2011 First of all thx to System238 for give me an exemple about how to organize my script and how to store dataIf can anyone help me improve my script pls write hereThxhere is my store scriptStore Data Use ini.au3 Link to comment Share on other sites More sharing options...
wakillon Posted April 21, 2011 Share Posted April 21, 2011 Try global $data = InputBox(" ","enter your data") global $file = "myfile.ini" global $read = "" global $asection[10] For $_I = 0 To 9 $asection[$_I]= "section" & $_I+1 Next _store($file,$data,$read,$asection) Func _Store ($file,$data,$read,$asection) For $_I = 0 To 9 $read = IniReadSection($file,$asection[$_I]) if @error then iniwrite($file,$asection[$_I],"data",$data) exit EndIf Next Endfunc ;_store AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
pl4y0n Posted April 21, 2011 Author Share Posted April 21, 2011 (edited) Try global $data = InputBox(" ","enter your data") global $file = "myfile.ini" global $read = "" global $asection[10] For $_I = 0 To 9 $asection[$_I]= "section" & $_I+1 Next _store($file,$data,$read,$asection) Func _Store ($file,$data,$read,$asection) For $_I = 0 To 9 $read = IniReadSection($file,$asection[$_I]) if @error then iniwrite($file,$asection[$_I],"data",$data) exit EndIf Next Endfunc ;_store Wow you're briliant that's what i'm tryng to you You read my mind Thx you very mutch edit: how can i include my ini file to a program if i type #include <myfile.ini> it sais >"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\Alex\My Documents\Autolt\Store Data Use ini 2.au3" C:\Documents and Settings\Alex\My Documents\Autolt\myfile.ini (1) : ==> Unable to parse line.: ["section"1] ^ ERROR >Exit code: 1 Time: 0.244 Edited April 21, 2011 by pl4y0n Link to comment Share on other sites More sharing options...
wakillon Posted April 21, 2011 Share Posted April 21, 2011 You can use fileinstall function. AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
pl4y0n Posted April 21, 2011 Author Share Posted April 21, 2011 How to check if data is duplicate global $data = InputBox(" ","enter your data") global $file = "myfile.ini" global $asection[100] global $akey[100] fileinstall("myfile.ini","myfile.ini") For $I = 0 To 99 $asection[$I]= "section" & $I+1 Next For $I = 0 To 99 $akey[$I]= "key" & $I+1 Next _store($file,$data,$asection) _checkfile($file,$asection,$data) Func _store($file,$data,$asection) For $i = 0 To 99 $read = IniReadSection($file,$asection[$I]) if @error then iniwrite($file,$asection[$I],$akey[$I],$data) msgbox(0,"Store Data","Stored data: " & $data & " in section " & $i+1 & " key " & $i+1) ExitLoop EndIf Next Endfunc ;_store func _checkfile($file,$asection,$data) $datacheck = IniRead($file,$asection,$akey,$data) if $datacheck = $data Then msgbox(0,"","123456789"); EndIf EndFunc Link to comment Share on other sites More sharing options...
Skitty Posted April 22, 2011 Share Posted April 22, 2011 (edited) How to check if data is duplicate global $data = InputBox(" ","enter your data") global $file = "myfile.ini" global $asection[100] global $akey[100] fileinstall("myfile.ini","myfile.ini") For $I = 0 To 99 $asection[$I]= "section" & $I+1 Next For $I = 0 To 99 $akey[$I]= "key" & $I+1 Next _store($file,$data,$asection) _checkfile($file,$asection,$data) Func _store($file,$data,$asection) For $i = 0 To 99 $read = IniReadSection($file,$asection[$I]) if @error then iniwrite($file,$asection[$I],$akey[$I],$data) msgbox(0,"Store Data","Stored data: " & $data & " in section " & $i+1 & " key " & $i+1) ExitLoop EndIf Next Endfunc ;_store func _checkfile($file,$asection,$data) $datacheck = IniRead($file,$asection,$akey,$data) if $datacheck = $data Then msgbox(0,"","123456789"); EndIf EndFunc If you wan't to get serious about storing your scripts data, use the sqlite example I gave you earlier. I got the pm you sent but, I'm afraid I'm quite lazy and I don't wan't to explain detail by detail on how to use the example. instead, expirament with the below script and add msgbox's every where so you can see exactly whats happening with the variables. expandcollapse popup#include<Crypt.au3> #include<SQLite.au3> #include<SQLite.dll.au3> ;Global $Exclusions = "Svchost.exe,explorer.exe" ; Exclude files by name... ;Global $ExclusionsByExt = "ini,exe,scr,bat,msi,dll" ; Only scan by these file extensions... Global $DB, $Size = 20 ; file larger than 20mb are not scanned... _Crypt_Startup() _SQLite_Startup() If Not FileExists(@ScriptDir&"\DataBase.db") Then $DB=_SQLite_Open(@ScriptDir&"\DataBase.db") _SQLite_Exec($DB,"CREATE TABLE DataBase (Adress,Val1,Val2,Val3,Val4,Val5);") _Process() Else $DB=_SQLite_Open(@ScriptDir&"\DataBase.db") _Process(True) EndIf _SQLite_Shutdown() _Crypt_Shutdown() Func _Process($State = False) If $State = False Then _Scan(@HomeDrive) ElseIf $State = True Then _Anulyze() Else MsgBox(16,"","Error") EndIf EndFunc Func _Scan($SourceFolder) Local $File Local $Search $Search = FileFindFirstFile($SourceFolder & "\*.*") If $Search = -1 Then Return While 1 $File = FileFindNextFile($Search) If @error = 1 Then ExitLoop If @extended = 1 Then _Scan($SourceFolder & "\" & $File) Else ;ToolTip("PROCESSING: "&$SourceFolder & "\" & $File) _Xzamin($SourceFolder & "\" & $File) EndIf WEnd FileClose($Search) EndFunc ;==>_SCANSYSTEM Func _Xzamin($File) Local $S=StringSplit($File,"\",2) Local $i=UBound($S) - 1 Local $S2=StringSplit($S[$i],".",2) Local $I2=UBound($S2) - 1 ;If StringInStr($Exclusions,$S[$i]) Then Return 1; exclusions ~ ;If Not StringInStr($ExclusionsByExt,$S2[$I2]) Then Return 1; exclusions ~ If Round(FileGetSize($File)/1048576,2) > $Size Then Return 1 Local $FO=FileOpen($File) If @error Then _DataAddEx("DataBase",FileGetShortName($File),"Error opening file") Return 1 EndIf Local $FR=FileRead($FO) _DataAddEx("DataBase", _ FileGetShortName($File), _ _Crypt_HashData($FR,$CALG_MD5), _ FileGetTime($File,0,1), _ FileGetSize($File), _ FileGetAttrib($File), _ @YEAR&"/"&@Mon&"/"&@MDAY) FileClose($FO) Return 1 EndFunc Func _Anulyze() Local $hQuery, $aRow, $sMsg _SQlite_Query (-1, "SELECT * FROM DataBase;", $hQuery) ; the query While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK ToolTip("PROCESSING: "&$aRow[0]) $Ar=_DataQueryEx("DataBase",$aRow[0],True) If IsArray($Ar) Then Local $FO=FileOpen($Ar[0]) Local $FR=FileRead($FO) If _Crypt_HashData($FR,$CALG_MD5) <> $Ar[1] Then MsgBox(0,"Statistics","===File Change Information==="& @CRLF & _ "File.......................... "& FileGetLongName($Ar[0]) & @CRLF & _ "Previouse Hash................ "& _Crypt_HashData($FR,$CALG_MD5) & @CRLF & _ "Current Hash.................. "& $Ar[1] & @CRLF & _ "Previouse Time................ "& $Ar[2] & @CRLF & _ "Current Time.................. "& FileGetTime($ar[0],0,1) & @CRLF & _ "Previouse File size........... "& $Ar[3]& "B" & @CRLF & _ "Current File size............. "& FileGetSize($Ar[0]) & "B" & @CRLF & _ "Current File size............. "& Round(FileGetSize($Ar[0])/1048576,2)& "Mb" & @CRLF & _ "Previouse file Attrib......... "& $Ar[4] & @CRLF & _ "Current File Attrib........... "& FileGetAttrib($Ar[0]) & @CRLF & _ "Scane generated on date....... "& $Ar[5]) EndIf FileClose($FO) EndIf WEnd ToolTip("") Return 1 EndFunc Func _DataAddEx($Table,$Adress,$Val1,$Val2 = "",$Val3 = "", $Val4 = "",$Val5 = "") Local $Data _SQLite_QuerySingleRow($DB,"SELECT Adress FROM "&$Table&" WHERE Adress='"&$Adress&"'",$Data) If $Data[0] <> "" Then _SQLite_Exec($DB,"UPDATE "&$Table&" SET Val1='"&$Val1&"', Val2='"&$Val2&"', Val3='"&$Val3&"', Val4='"&$Val4&"', Val5='"&$Val5&"' WHERE Adress='"&$Adress&"'") Else _SQLite_Exec($DB,"INSERT INTO "&$Table&" (Adress,Val1,Val2,Val3,Val4,Val5) VALUES ('"&$Adress&"','"&$Val1&"','"&$Val2&"','"&$Val3&"','"&$Val4&"','"&$Val5&"');") EndIf EndFunc Func _DataQueryEx($Table,$Adress,$Ar = False) Local $Ret If _SQLite_QuerySingleRow($DB,"SELECT * FROM "&$Table&" WHERE Adress='"&$Adress&"'",$Ret) == $SQLITE_OK Then ; =>"*"<= means all... If $Ret[0] == "" Then Return @error Else If $Ar Then Return $Ret Return $Ret[1] EndIf EndIf EndFunc I tried to make everything as simple as capable by me. Edit: This might look complicated to unfamiliar eye's, but I assure you it's actually pretty damn simple. If you really think this is beyond you, do what I do whenever I encounter a crazy ass script. Dismantle it variable by variable and see whats actually going on step by step by adding a msgbox (or tooltip with a sleep() func under it) below or above a variable and see whats actually happening. Also, when using the scite editor, click on a function (Udf or native) and press the [F1] key to open the help file, the help file will advise you more or less on how the function in question works and its required parameters. Edited April 22, 2011 by System238 Link to comment Share on other sites More sharing options...
pl4y0n Posted April 22, 2011 Author Share Posted April 22, 2011 @System238 when i'll go a litle "pro" i'll try this but first i just practice array, ini file , functions anyways thx for your exemple and litle tuts and for your work 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