Sign in to follow this  
Followers 0
pl4y0n

Help me improve my script

7 posts in this topic

First of all thx to System238 for give me an exemple about how to organize my script and how to store data

If can anyone help me improve my script pls write here

Thx

here is my store script

Store Data Use ini.au3

Share this post


Link to post
Share on other sites



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.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by pl4y0n

Share this post


Link to post
Share on other sites

You can use fileinstall function.


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#6 ·  Posted (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.

#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 by System238

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

@System238 when i'll go a litle "pro" i'll try this but first i just practice array, ini file , functions :unsure:

anyways thx for your exemple and litle tuts and for your work :>

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0