Jump to content

What's wrong in my first script ?


Recommended Posts

I'm looking for assistance for debugging what's wrong in my first coded script...

It's an engine and definition updater for the free, stand alone antivirus Syscleaner from Trendmicro.

The script feature a little intelligence because it grab the updates only if needed due to a remote <> local version checking.

Two temp files are created, core.tmp and pattern.tmp, I'm unable to delete both files even using a fileclose command before deleting.

Could someone of you take a look at the scripts and see what's wrong ?

Thanking in advance!

Mario

;Trend Micro Sysclean updater v1.0
;Made by MaRionics

#include <File.au3>
#include <GUIConstants.au3>
#Include <GuiEdit.au3>
#include <Process.au3>
;#NoTrayIcon

; Include the needed files into the compiled .exe
;FileInstall("C:\sysclean\logo1.jpg", @scriptdir & "\logo1.jpg")
;FileInstall("C:\sysclean\logo2.jpg", @scriptdir & "\logo2.jpg")
;FileInstall("C:\sysclean\unzip.exe", @scriptdir & "\unzip.exe")
;FileInstall("C:\sysclean\unzip.txt", @scriptdir & "\unzip.txt")

$url = "http://www.trendmicro.com/download/dcs.asp"
$CoreDlUrl = "http://www.trendmicro.com/ftp/products/tsc/sysclean.com"
$PatternDlPage = "http://www.trendmicro.com/download/viruspattern.asp"
$PatternDlLink = "http://www.trendmicro.com/ftp/products/pattern"
$font="Arial"
;----------------------GUI
GuiCreate(" Trend Micro Sysclean µpdater v1.0 ", 350, 175,(@DesktopWidth-350)/2, (@DesktopHeight-175)/2 , -1, $WS_EX_TOOLWINDOW + $WS_EX_LAYERED )
GUISetState (@SW_SHOW)

GuiCtrlCreateLabel("", 5, 5, 340, 110, $SS_GRAYFRAME)
GUICtrlSetBkColor(-1,0xFFFFD0)
GUICtrlCreateLabel("", 10, 10, 330, 100, $SS_GRAYFRAME)
GUICtrlCreateLabel("", 11, 11, 328, 98)
GUICtrlSetBkColor(-1,0xFFFFD0)

GUICtrlCreatePic(@scriptdir & "\logo1.jpg",220,125, 123,43)
GUICtrlCreatePic(@scriptdir & "\logo2.jpg",9,125, 205,43)
;******************** GUI messages ********************
GUICtrlCreateLabel (" Core:",  15, 18, 200) 
GUICtrlSetFont (-1,9, 800, 1 , $font); will display bold characters
GUICtrlSetBkColor(-1,0xFFFFD0)

GUICtrlCreateLabel (" Pattern:",  15, 38, 170)
GUICtrlSetFont (-1,9, 800, 1 , $font); will display bold characters
GUICtrlSetBkColor(-1,0xFFFFD0)

$GuiCoreChk = GUICtrlCreateLabel ("-",  52, 20, 150) 
GUICtrlSetBkColor(-1,0xFFFFD0)
$GuiCoreChkExtended = GUICtrlCreateLabel ("",  270, 18, 25)
GUICtrlSetFont (-1,9, 800, 1 , $font); will display bold characters
GUICtrlSetBkColor(-1,0xFFFFD0)

$GuiPatternChk = GUICtrlCreateLabel ("-",  66, 40, 220)
GUICtrlSetBkColor(-1,0xFFFFD0)
$GuiPatternChkExtended = GUICtrlCreateLabel ("",  284, 38, 25)
GUICtrlSetFont (-1,9, 800, 1 , $font); will display bold characters
GUICtrlSetBkColor(-1,0xFFFFD0)

$StatusMessage = GUICtrlCreateEdit ("",18,65,313,37, BitOr($ES_READONLY, $ES_MULTILINE, $SS_BLACKRECT))
GUICtrlSetData ($StatusMessage, "Initalizing and checking internet connection...")
;******************** If SyscleanUp.ini was not found then a new one will be created and then loaded ********************
If NOT fileexists (@scriptdir & "\updater.ini") then
    GUICtrlSetData ($StatusMessage, "updater.ini not found, writing default, re-initalizing and checking internet connection...")
    Sleep(3000)
    IniWrite(@ScriptDir & "\updater.ini", "Startup", "PingTarget", "www.google.com")
    IniWrite(@ScriptDir & "\updater.ini", "Startup", "LocalCoreMd5", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")
    IniWrite(@ScriptDir & "\updater.ini", "Startup", "LocalPatternVersion", "N/A")
    IniWrite(@ScriptDir & "\updater.ini", "Startup", "PauseBetweenTasks", "750")
    IniWrite(@ScriptDir & "\updater.ini", "Startup", "AutoExit", "No")
    IniWrite(@ScriptDir & "\updater.ini", "Startup", "PauseBeforeExit", "4000") 
EndIf

$PingTarget = IniRead(@ScriptDir & "\updater.ini", "Startup", "PingTarget", "N/A")
$LocalCoreMd5 = IniRead(@ScriptDir & "\updater.ini", "Startup", "LocalCoreMd5", "N/A")
$LocalPatternVersion = IniRead(@ScriptDir & "\updater.ini", "Startup", "LocalPatternVersion", "N/A")
$PauseBeforeExit = IniRead(@ScriptDir & "\updater.ini", "Startup", "PauseBeforeExit", "N/A")
$PauseBetweenTasks = IniRead(@ScriptDir & "\updater.ini", "Startup", "PauseBetweenTasks", "N/A")
$AutoExit = IniRead(@ScriptDir & "\updater.ini", "Startup", "AutoExit", "N/A")
;******************** Internet connection check ********************
$var = Ping("www.google.com",250)
If $var Then; also possible:  If @error = 0 Then ...
    GUICtrlSetData ($StatusMessage, "Internet connection available, roundtrip was " & $var & " ms")
    Sleep(3000)
Else
    GUICtrlSetData ($StatusMessage, "ERROR! Internet connection test failure. Program END, press the close button [x] to quit")
; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    Wend
        Exit
EndIf

; ******************** CORE HANDLING SECTION ********************
GUICtrlSetData ($StatusMessage, "Checking Core component...")
;----------------------Read INETGet data
InetGet($url, @ScriptDir & "\core.tmp")
$RemoteCoreMd5 = FileOpen (@ScriptDir & "\core.tmp", 0 )
;----------------------Get total file lines of source
$cnt = 0
While 1
    $linenum = FileReadLine( $RemoteCoreMd5 )
    $cnt = $cnt + 1
    If @error = -1 Then ExitLoop
Wend
;----------------------Get the RemoteCoreMd5 hash value
$i = 0
Do
    $line = FileReadLine ( $RemoteCoreMd5 , $i )
    $result = StringInStr( $line, "*SysClean.com")
        if $result > 0 then ExitLoop
    $i = $i + 1
Until $i = $cnt

$RemoteCoreMd5 = StringMid($line, 23, 32)
FileClose (@ScriptDir & "\core.tmp")
;----------------------If local and remote Md5 are different then a core download will start
If $LocalCoreMd5 = $RemoteCoreMd5 Then
    $CoreUpdateTrigger = 0
    Sleep($PauseBetweenTasks)   
    GUICtrlSetData ($GuiCoreChk, "No update available") 
    GUICtrlSetData ($StatusMessage, "Core is up-to-date...")
    Sleep($PauseBetweenTasks)
Else
;----------------------Core file size detection and download with transfer % display
    $CoreUpdateTrigger = 1
    $CoreSize = InetGetSize($CoreDlUrl)
    InetGet($CoreDlUrl , @ScriptDir & "\Sysclean.com",1,1)  
    While @InetGetActive
        $currentsspercent = Round (@InetGetBytesRead / $CoreSize * 100, 1)
        $progressbar1 = GUICtrlCreateProgress (52,21,210,11)
        GUICtrlSetData ($progressbar1,$currentsspercent)
        GUICtrlSetData ($StatusMessage, "Update found, downloading new component...")   
        Sleep(200)
    wend
        GUICtrlSetData ($GuiCoreChkExtended,"OK")
        Sleep($PauseBetweenTasks)
        
EndIf
; ******************** CORE HANDLING SECTION END ********************

; ******************** PATTERN HANDLING SECTION ********************
GUICtrlSetData ($StatusMessage, "Checking Pattern component...")
;----------------------Read INETGet data
InetGet($PatternDlPage, @ScriptDir & "\pattern.tmp")
$RemotePatternVersion = FileOpen (@ScriptDir & "\pattern.tmp", 0 )
;----------------------Get total file lines of source
$cnt = 0
While 1
    $linenum = FileReadLine( $RemotePatternVersion )
    $cnt = $cnt + 1
    If @error = -1 Then ExitLoop
Wend
;----------------------Get the RemotePatternVersion number value
$i = 0
Do
    $line = FileReadLine ( $RemotePatternVersion , $i )
    $result = StringInStr( $line, "latest pattern file number")
        if $result > 0 then ExitLoop
    $i = $i + 1
Until $i = $cnt

$RemotePatternVersion = StringMid($line, 65, 8)
$PatternDlLink = $PatternDlLink & "/lpt" & StringMid($RemotePatternVersion, 3, 3) & ".zip"
FileClose (@ScriptDir & "\pattern.tmp")
;----------------------If local and remote Md5 are different then a pattern download will start
If $LocalPatternVersion = $RemotePatternVersion Then 
    $PatternUpdateTrigger = 0
    Sleep($PauseBetweenTasks)
    GUICtrlSetData ($GuiPatternChk, "No update available")
    GUICtrlSetData ($StatusMessage, "Pattern is up-to-date...") 
    Sleep($PauseBetweenTasks)
Else
;----------------------Pattern file size detection and download with transfer % display
    $PatternUpdateTrigger = 1
    $PatternSize = InetGetSize($PatternDlLink )
    InetGet($PatternDlLink  , @ScriptDir & "\lpt" & StringMid($RemotePatternVersion, 3, 3) & ".zip",1,1)    
    While @InetGetActive
        $currentsspercent = Round (@InetGetBytesRead / $PatternSize * 100, 1)
        $progressbar2 = GUICtrlCreateProgress (67,41,210,11)
        GUICtrlSetData ($progressbar2,$currentsspercent)
        GUICtrlSetData ($StatusMessage, "Update found from version " & $LocalPatternVersion & " to " & $RemotePatternVersion & " -  downloading new component...")
        Sleep(200)
    wend
        GUICtrlSetData ($GuiPatternChkExtended,"OK")
        Sleep($PauseBetweenTasks)
EndIf
; ******************** End ********************

; ******************** UNZIP but only if needed********************
If $PatternUpdateTrigger = 1 Then
    Sleep($PauseBetweenTasks)
    FileDelete(@ScriptDir & "\" & "lpt$vpn.*")
    GUICtrlSetData ($StatusMessage, "Unzipping downloaded component(s) and removing temporary files...")
    Sleep($PauseBetweenTasks)
    Runwait(@ScriptDir & "\unzip.exe" & " -o "& "lpt" & StringMid($RemotePatternVersion, 3, 3) & ".zip")
    FileDelete(@ScriptDir & "\" & "lpt*.zip")
EndIf
; ******************** UNZIP end ********************

; ******************** Close and delete unneeded files ********************
FileDelete(@ScriptDir & "\*.tmp")
; ******************** Close and delete unneeded files end ********************

; ******************** SyscleanUp.ini update ********************
If $CoreUpdateTrigger = 1 Or $PatternUpdateTrigger = 1 Then
Sleep($PauseBetweenTasks)
GUICtrlSetData ($StatusMessage, "Updating settings...")
IniWrite(@ScriptDir & "\updater.ini", "Startup", "LocalCoreMd5", $RemoteCoreMd5)
IniWrite(@ScriptDir & "\updater.ini", "Startup", "LocalPatternVersion", $RemotePatternVersion)
Sleep($PauseBetweenTasks)
EndIf
; ******************** SyscleanUp.ini update end ********************

If StringUpper($AutoExit) = "YES" Then
;******************** Wait before auto exit ********************
    $y = $PauseBeforeExit / 1000
    For $i = $y to 1 Step -1
    If $CoreUpdateTrigger = 1 Or $PatternUpdateTrigger = 1 Then
        GUICtrlSetData ($StatusMessage, "Update successfull, program will end in " & $i & " seconds...")
    Else
        GUICtrlSetData ($StatusMessage, "Nothing to update, program will end in " & $i & " seconds...")
    EndIf   
    Sleep(1000)
    Next
; ******************** Wait before auto exit end ********************
Else
    If $CoreUpdateTrigger = 1 Or $PatternUpdateTrigger = 1 Then
        GUICtrlSetData ($StatusMessage, "Update successfull, auto-exit is disabled, press the close button [x] to quit...")
    Else
        GUICtrlSetData ($StatusMessage, "Nothing to update, auto-exit is disabled, press the close button [x] to quit...")
    EndIf   
    
; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    Wend
EndIf
Edited by MarioX
Link to comment
Share on other sites

How about closing the handles themselves.

FileClose (@ScriptDir & "\core.tmp")

should be

FileClose ($RemoteCoreMd5)

and do the same with the other FileOpen and FileClose.

Edited by MHz
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...