Jump to content

Spybot - Search & Destroy Updater


koiron
 Share

Recommended Posts

I wrote this to bypass using Spybot's integrated updater because I find it's a pain to run. This script will play nice with Spybot's integrated updater, so if you update in one, and try the other, you should not have conflicts.

While the source is posted below, there are a few files which are needed for it to run (icons and unzip). You can download the package from my website.

Hope you enjoy. I'd love to hear any comments/requests about the script ^_^

#cs ----------------------------------------------------------------------------
    
    Spybot - Search & Destroy Updater
    AutoIt Version: 3.2.4.9
    Author: Koiron
    URL: http://koiron.au3.googlepages.com
    
    Script Function:
    - Downloads updates for Spybot Search & Destroy in Windows
    
#ce ----------------------------------------------------------------------------

#include <GUIConstants.au3>
#include <GUIListView.au3>
#include <GUICombo.au3>
AutoItSetOption("TrayIconDebug", 0)
AutoItSetOption("TrayAutoPause", 0)
;TraySetIcon("icons.icl", 0)
AutoItSetOption("TrayIconHide", 1)

$ScriptLoc = @ScriptDir
$SpybotLoc = IniRead($ScriptLoc & "\SpybotSD_Settings.ini", "Updates", "Path", "")
If FileExists($SpybotLoc & "\SpybotSD.exe") = 0 Then
    $SpybotLoc = ""
EndIf
If $SpybotLoc = "" Then
    $yy = FileSelectFolder("Please locate where you installed Spybot Search & Destroy", "", "", "C:\Program Files\Spybot - Search & Destroy")
    If @error Then
        Exit
    Else
        IniWrite($ScriptLoc & "\SpybotSD_Settings.ini", "Updates", "Path", $yy)
        $SpybotLoc = $yy
    EndIf
EndIf
$SpybotLoc = FileGetShortName($SpybotLoc)
$UpdateLoc = $SpybotLoc & "\Updates"
$OnlineIni = $UpdateLoc & "\online.ini"
$DownloadedIni = $UpdateLoc & "\downloaded.ini"

$FormSpybotUpdate = GUICreate("Update Spybot Search & Destroy", 507, 434)
$ButtonSearch = GUICtrlCreateButton("Search for Updates", 8, 8, 123, 25, 0)
$ComboMirrors = GUICtrlCreateCombo("", 136, 10, 177, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
GUICtrlSetState(-1, $GUI_DISABLE)
$ButtonUpdate = GUICtrlCreateButton("Download Updates", 320, 8, 115, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
$Buttonabort = GUICtrlCreateButton("Abort", 440, 8, 59, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
$ListViewUpdates = GUICtrlCreateListView("Update|Info|Date", 8, 40, 490, 286, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_CHECKBOXES))
GUICtrlSendMsg($ListViewUpdates, 0x101E, 0, 200)
GUICtrlSendMsg($ListViewUpdates, 0x101E, 1, 200)
GUICtrlSendMsg($ListViewUpdates, 0x101E, 2, 80)
GUICtrlCreateContextMenu($ListViewUpdates)
$MenuitemSelectall = GUICtrlCreateMenuItem("Select all", $ListViewUpdates)
$MenuitemDeselectall = GUICtrlCreateMenuItem("Deselect all", $ListViewUpdates)
$GroupUpdateProgress = GUICtrlCreateGroup("Update Progress", 8, 336, 489, 89)
$LabelDownload1 = GUICtrlCreateLabel("Inactive", 20, 356, 466, 17)
$LabelDownload2 = GUICtrlCreateLabel("...", 20, 376, 466, 17)
$Progress1 = GUICtrlCreateProgress(20, 396, 466, 17, $PBS_SMOOTH)
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUISetState(@SW_SHOW)

If $CmdLine[0] = 1 Then
    Switch $CmdLine[1]
        Case "-autoupdate"
            $auto = ListUpdates()
            If $auto = "Update" Then
                GetUpdates()
            EndIf
            Exit
    EndSwitch
EndIf

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ButtonSearch
            ListUpdates()
        Case $ButtonUpdate
            GetUpdates()
        Case $MenuitemSelectall
            SelectAll()
        Case $MenuitemDeselectall
            DeselectAll()
    EndSwitch
WEnd

Func ListUpdates()
    GUICtrlSetState($ButtonSearch, $GUI_DISABLE)
    GUICtrlSetState($ButtonUpdate, $GUI_DISABLE)
    GUICtrlSetState($Buttonabort, $GUI_ENABLE)
    $aborted = 0
    $updatedirchk = FileExists($UpdateLoc)
    If $updatedirchk = 0 Then
        $updatedirchk = DirCreate($UpdateLoc)
    EndIf
    If $updatedirchk = 1 Then
        $url = IniRead($ScriptLoc & "\SpybotSD_Settings.ini", "Updates", "RemoteINI", "http://www.safer-networking.org/updates/spybotsd.ini")
        $size = InetGetSize($url)
        If @error Then
            GUICtrlSetData($LabelDownload1, "Searching for Updates... Error!")
            GUICtrlSetState($ButtonSearch, $GUI_ENABLE)
            GUICtrlSetState($Buttonabort, $GUI_DISABLE)
        Else
            $sizekb = Int($size / 1024)
            InetGet($url, $OnlineIni, 1, 1)
            While @InetGetActive
                $nMsg = GUIGetMsg()
                If $nMsg = $GUI_EVENT_CLOSE Then Exit
                If $nMsg = $Buttonabort Then
                    $aborted = 1
                    InetGet("Abort")
                EndIf
                $bytesdone = @InetGetBytesRead
                $bytesdonekb = Int($bytesdone / 1024)
                $percent = Round($bytesdone / $size, 3) * 100
                GUICtrlSetData($LabelDownload1, "Searching for Updates...")
                GUICtrlSetData($LabelDownload2, $bytesdonekb & " KB of " & $sizekb & " KB -- " & $percent & "%")
                GUICtrlSetData($Progress1, $percent)
            WEnd
            If @InetGetBytesRead <> $size Then ;error !!!! somehow need to make this check the .ini has downloaded successfully a different way
                If $aborted = 1 Then
                    GUICtrlSetData($LabelDownload1, "Searching for Updates... Aborted!")
                    GUICtrlSetState($ButtonSearch, $GUI_ENABLE)
                    GUICtrlSetState($Buttonabort, $GUI_DISABLE)
                Else
                    GUICtrlSetData($LabelDownload1, "Searching for Updates... Error!")
                    GUICtrlSetState($ButtonSearch, $GUI_ENABLE)
                    GUICtrlSetState($Buttonabort, $GUI_DISABLE)
                EndIf
                GUICtrlSetData($LabelDownload2, "")
                GUICtrlSetData($Progress1, 0)
                FileDelete($OnlineIni)
            Else ;success
                GUICtrlSetData($LabelDownload1, "Searching for Updates... Done!")
                GUICtrlSetData($LabelDownload2, $sizekb & " KB of " & $sizekb & " KB -- 100%")
                GUICtrlSetData($Progress1, 100)
                GUICtrlSetState($ButtonSearch, $GUI_ENABLE)
                GUICtrlSetState($Buttonabort, $GUI_DISABLE)
                ;populate mirrors list now
                GUICtrlSetData($ComboMirrors, "|")
                $mirror = IniReadSection($OnlineIni, "-Mirrors")
                For $x = 1 To $mirror[0][0]
                    If $mirror[$x][0] <> "PlanetMirror (Global)" Then ;fuck this server, doesn't like to give file sizes on request
                        GUICtrlSetData($ComboMirrors, $mirror[$x][0], $mirror[1][0])
                    EndIf
                Next
                _GUICtrlComboSetCurSel($ComboMirrors, Random(1, $mirror[0][0], 1))
                ;populate the updates list now
                _GUICtrlListViewDeleteAllItems($ListViewUpdates)
                $section = IniReadSectionNames($OnlineIni)
                For $i = 1 To $section[0]
                    If (StringLeft($section[$i], 16) = "Detection rules:" Or StringLeft($section[$i], 25) = "Detection support library" Or StringLeft($section[$i], 26) = "Advanced detection library" Or $section[$i] = "Startup Info" Or $section[$i] = "Immunization database" Or $section[$i] = "TCP/IP Settings plugin") Then
                        $info = IniRead($OnlineIni, $section[$i], "Info", "")
                        $date = IniRead($OnlineIni, $section[$i], "Date", "")
                        $localfile = IniRead($OnlineIni, $section[$i], "LocalFile", "")
                        ;check if have update already
                        $dlreldate = IniRead($DownloadedIni, $localfile, "ReleaseDate", "")
                        If $dlreldate <> $date Then
                            $dlreldate = ""
                        EndIf
                        If $dlreldate = "" Then
                            GUICtrlCreateListViewItem($section[$i] & "|" & $info & "|" & $date, $ListViewUpdates)
                            GUICtrlSetImage(-1, $ScriptLoc & "\icons.icl", 3)
                        EndIf
                    EndIf
                Next
                _GUICtrlListViewSetCheckState($ListViewUpdates, -1, 1) ;check all
                If (_GUICtrlListViewGetItemCount($ListViewUpdates) > 0) Then
                    GUICtrlSetState($ComboMirrors, $GUI_ENABLE)
                    GUICtrlSetState($ButtonUpdate, $GUI_ENABLE)
                    Return "Update"
                EndIf
            EndIf
        EndIf
    Else
        GUICtrlSetData($LabelDownload1, "Error creating Updates directory!")
        GUICtrlSetState($ButtonSearch, $GUI_ENABLE)
        GUICtrlSetState($Buttonabort, $GUI_DISABLE)
    EndIf
EndFunc   ;==>ListUpdates

Func SelectAll()
    _GUICtrlListViewSetCheckState($ListViewUpdates, -1, 1) ;check all
EndFunc   ;==>SelectAll

Func DeselectAll()
    _GUICtrlListViewSetCheckState($ListViewUpdates, -1, 0) ;uncheck all
EndFunc   ;==>DeselectAll

Func GetUpdates()
    GUICtrlSetState($ButtonSearch, $GUI_DISABLE)
    GUICtrlSetState($ButtonUpdate, $GUI_DISABLE)
    GUICtrlSetState($Buttonabort, $GUI_ENABLE)
    $err = 0
    $upmirror = IniRead($OnlineIni, "-Mirrors", GUICtrlRead($ComboMirrors), "") ;!!!! change the default to something?
    $listviewcount = _GUICtrlListViewGetItemCount($ListViewUpdates)
    $listviewcount = $listviewcount - 1
    $aborted = 0
    FileSetAttrib($SpybotLoc, "-RASH", 1); is this needed? !!!!
    For $i = 0 To $listviewcount
        If (_GUICtrlListViewGetCheckedState($ListViewUpdates, $i) = 1 And $aborted = 0) Then
            $zz = $i + 16
            $title = _GUICtrlListViewGetItemText($ListViewUpdates, $i, 0)
            $destfile = IniRead($OnlineIni, $title, "LocalFile", "")
            $destfolder = IniRead($OnlineIni, $title, "DestinationFolder", "")
            $date = IniRead($OnlineIni, $title, "Date", "")
            $desc = IniRead($OnlineIni, $title, "Info", "")
            ;check if have update already
            $dlreldate = IniRead($DownloadedIni, $destfile, "ReleaseDate", "")
            If $dlreldate <> $date Then
                $dlreldate = ""
            EndIf
            If $dlreldate = "" Then
                $url = $upmirror & $destfile
                $size = InetGetSize($url)
                If @error Then
                    $err = 1
                    GUICtrlSetData($LabelDownload1, "Downloading " & $title & "... Error!")
                    GUICtrlSetData($LabelDownload2, "")
                    GUICtrlSetData($Progress1, 0)
                Else
                    $sizekb = Int($size / 1024)
                    InetGet($url, $UpdateLoc & "\" & $destfile, 1, 1)
                    While @InetGetActive
                        $nMsg = GUIGetMsg()
                        If $nMsg = $GUI_EVENT_CLOSE Then Exit
                        If $nMsg = $Buttonabort Then
                            $aborted = 1
                            InetGet("Abort")
                        EndIf
                        $bytesdone = @InetGetBytesRead
                        $bytesdonekb = Int($bytesdone / 1024)
                        $percent = Round($bytesdone / $size, 3) * 100
                        GUICtrlSetData($LabelDownload1, "Downloading " & $title & "...")
                        GUICtrlSetData($LabelDownload2, $bytesdonekb & " KB of " & $sizekb & " KB -- " & $percent & "%")
                        GUICtrlSetData($Progress1, $percent)
                    WEnd
                    If $aborted = 1 Then
                        GUICtrlSetData($LabelDownload1, "Downloading... Aborted!")
                        $err = 1
                        FileDelete($UpdateLoc & "\" & $destfile)
                        ExitLoop
                    Else ;success? if not unzip will error
                        GUICtrlSetData($LabelDownload1, "Downloading " & $title & "... Done!")
                        GUICtrlSetData($LabelDownload2, $sizekb & " KB of " & $sizekb & " KB -- 100%")
                        GUICtrlSetData($Progress1, 100)
                        
                        If ProcessExists("SpybotSD.exe") Then
                            ProcessClose("SpybotSD.exe")
                            ProcessWaitClose("SpybotSD.exe")
                        EndIf
                        If ProcessExists("TeaTimer.exe") Then
                            ProcessClose("TeaTimer.exe")
                            ProcessWaitClose("TeaTimer.exe")
                        EndIf
                        
                        GUICtrlSetData($LabelDownload1, "Extracting " & $title & "...")
                        $extract = RunWait($ScriptLoc & "\unzip.exe -joq " & $UpdateLoc & "\" & $destfile & " -d " & $SpybotLoc & "\" & $destfolder, "", @SW_HIDE)
                        If $extract > 0 Then
                            GUICtrlSetImage($zz, $ScriptLoc & "\icons.icl", 1)
                            GUICtrlSetData($LabelDownload1, "Extracting " & $title & "... Error!")
                            $err = 1
                        Else
                            $search = FileFindFirstFile($SpybotLoc & "\" & $destfolder & "install-*.ini")
                            If $search <> -1 Then
                                While 1
                                    $sfile = FileFindNextFile($search)
                                    If @error Then ExitLoop
                                    $esection = IniReadSectionNames($SpybotLoc & "\" & $destfolder & $sfile)
                                    For $e = 1 To $esection[0]
                                        $esource = IniRead($SpybotLoc & "\" & $destfolder & $sfile, $esection[$e], "Source", "")
                                        If FileExists($SpybotLoc & "\" & $esource) = 1 Then
                                            $edest = IniRead($SpybotLoc & "\" & $destfolder & $sfile, $esection[$e], "Destination", "")
                                            $emove = FileMove($SpybotLoc & "\" & $esource, $SpybotLoc & "\" & $edest, 9)
                                            If $emove = 0 Then
                                                GUICtrlSetImage($zz, $ScriptLoc & "\icons.icl", 1)
                                                GUICtrlSetData($LabelDownload1, "Moving files for " & $title & "... Error!")
                                                $err = 1
                                            EndIf
                                        EndIf
                                    Next
                                    FileDelete($SpybotLoc & "\" & $destfolder & $sfile)
                                WEnd
                            EndIf
                            FileClose($search)
                            GUICtrlSetImage($zz, $ScriptLoc & "\icons.icl", 2)
                            _GUICtrlListViewSetCheckState($ListViewUpdates, $i, 0)
                            ;write to the downloaded.ini file
                            IniDelete($DownloadedIni, $destfile)
                            IniWrite($DownloadedIni, $destfile, "InstallDate", @YEAR & "-" & @MON & "-" & @MDAY)
                            IniWrite($DownloadedIni, $destfile, "ReleaseDate", $date)
                            IniWrite($DownloadedIni, $destfile, "URL", $url)
                            IniWrite($DownloadedIni, $destfile, "LocalFile", $UpdateLoc & "\" & $destfile)
                            IniWrite($DownloadedIni, $destfile, "UpdateName", $title)
                            IniWrite($DownloadedIni, $destfile, "Description", $desc)
                            ;done
                            GUICtrlSetData($LabelDownload1, "Extracting " & $title & "... Done!")
                        EndIf
                    EndIf
                EndIf
            Else
                _GUICtrlListViewSetCheckState($ListViewUpdates, $i, 0)
            EndIf
        EndIf
    Next
    GUICtrlSetState($ButtonSearch, $GUI_ENABLE)
    GUICtrlSetState($ButtonUpdate, $GUI_ENABLE)
    GUICtrlSetState($Buttonabort, $GUI_DISABLE)
EndFunc   ;==>GetUpdates

#Region AutoIt3Wrapper directives section
#AutoIt3Wrapper_UseAnsi=Y           ;(Y/N) Use Ansi versions for AutoIt3a or AUT2EXEa. Default=N
#AutoIt3Wrapper_Icon=C:\AutoItScripts\SpybotSDUpdater\au3source\update.ico                           ;Filename of the Ico file to use
#AutoIt3Wrapper_OutFile=C:\AutoItScripts\SpybotSDUpdater\SpybotSD_Updater.exe                        ;Target exe/a3x filename.
#AutoIt3Wrapper_Allow_Decompile=N                ;(Y/N) Default = y which allows decompile.

#AutoIt3Wrapper_Res_Description=Spybot - Search & Destroy Updater               ;Description field
;#AutoIt3Wrapper_Res_Fileversion=0.0.0.0                ;File Version
;#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=  ;(Y/N/P) AutoIncrement FileVersion After Aut2EXE is finished. default=N
#AutoIt3Wrapper_Res_LegalCopyright=Copyright (c) 2007 Koiron             ;Copyright field
;#AutoIt3Wrapper_Res_Field=AutoIt Version|%AutoItVer%
://////=__=;Free format fieldname|fieldvalue
://////=__=://.=.googlepages.com            ;Free format fieldname|fieldvalue
;#AutoIt3Wrapper_Res_Field=Name|Value            ;Free format fieldname|fieldvalue

;#AutoIt3Wrapper_Res_Icon_Add=                   ; Filename of ICO to be added.
;#AutoIt3Wrapper_Res_Icon_Add=                   ; Filename of ICO to be added.

;#AutoIt3Wrapper_Run_Tidy=                       ;(Y/N) Run Tidy before compilation. default=N
;#AutoIt3Wrapper_Tidy_Stop_onerror=              ;(Y/N) Continue when only Warnings. default=Y
;#Tidy_Parameters=                               ;Tidy Parameters...see SciTE4AutoIt3 Helpfile for options
#EndRegion
Edited by koiron
-Koiron
Link to comment
Share on other sites

Looks great, thanks.

I see you have progress text there, but how about a progress bar?

Thanks for your comment. I thought about adding a progress bar in but never really went through with it :) I'll see what I can whip up later when I get home. One issue I've run into with progress and file sizes (inetgetsize) is some servers not returning sizes... Hence, why I filtered out the mirror 'PlanetMirror (Global)'
-Koiron
Link to comment
Share on other sites

  • 2 weeks later...

I tried calling your autoupdater from another script

Dim $appexe
$appexe = EnvGet("SystemDrive") & "\Install\Applications\SpybotSDUpdater\SpybotSD_Updater.exe"

If Not FileExists($appexe) Then
    Exit
EndIf

ShellExecuteWait($appexe,"-autoupdate")

It just sits there. The update progress is "inactive"

If I use

Run($appexe & " -autoupdate")

it works? Why is that?

Link to comment
Share on other sites

I tried calling your autoupdater from another script

Dim $appexe
$appexe = EnvGet("SystemDrive") & "\Install\Applications\SpybotSDUpdater\SpybotSD_Updater.exe"

If Not FileExists($appexe) Then
    Exit
EndIf

ShellExecuteWait($appexe,"-autoupdate")

It just sits there. The update progress is "inactive"

If I use

Run($appexe & " -autoupdate")

it works? Why is that?

I just tried your ShellExecuteWait() and it used the -autoupdate function fine. It sat there for a few seconds inactive, but eventually downloaded the update listing from spybot's server. Their server right now is really slow which may be the reason... Perhaps an AutoIt guru here may know a different reason? :)
-Koiron
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...