Jump to content
rayven

Need Assistance With My Update Script

Recommended Posts

Good day,

I am trying to write an update script to update my existing IP Detection program.

The program is suppose to read the local version and compare it to a text file found on a web server.

If the version's match (e.g., 2.0 from the text file, and 2.0 for the local version,) vno update would be needed.

However, if the text file says 3.0, and the local program version is 2.0, download the update, delete the old exe, and replace it with the newer version 3.0 of the file.

I have the following file, perhaps I forgot something in it?

ip-detect-update.au3

Share this post


Link to post
Share on other sites
Posted (edited)

You shouldn't declare Global variables within functions, but the main problem I can see is that $localExeVersion = "" it should be $localExeVersion = FileGetVersion (...).

Would also use _VersionCompare to compare versions, example:

;IP Detect Update script
;© 2019 by Daniel Chavez
;Purpose: This updates iP Detect if there are changes
#include <IE.au3>
#include <INet.au3>
#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

Global $g_bDebug = True ;~ Toggle debug mode
Global $g_sUpdatePathIs = @ScriptDir & "\GetIPV2.exe"
Global $g_sToBeReplacedPathIs = @ScriptDir & "\GetIP.exe"

doVersionCheck()

Func doVersionCheck($_bVersionCheck = False)
    Local $hDownload
    Local $sServerUpdateExe = "https://mydomain.us/win/GetIPV2.exe"
    Local $sServerVersionFile = "https://mydomain.us/win/IPDetectData/version.txt"
    Local $vLocalExeVersion = FileGetVersion($g_sToBeReplacedPathIs)
    Local $vRemoteExeVersion = _INetGetSource($sServerVersionFile)
    Local $iVersionCompare = _VersionCompare($vLocalExeVersion, $vRemoteExeVersion)
    Switch $iVersionCompare
        Case 0
            If $g_bDebug Then MsgBox(4096, "Version Compare", "Both versions are equal")
            If $_bVersionCheck Then Return 0
        Case 1
            If $g_bDebug Then MsgBox(4096, "Version Compare", "Local Version is greater than remote version." & @CRLF & "Local Version := " & $vLocalExeVersion & @CRLF & "Remote Version := " & $vRemoteExeVersion)
        Case 2
            If $_bVersionCheck Then Return 1
            If $g_bDebug Then MsgBox(4096, "Version Compare", "Remote Version is greater than local version, let's update it")
            $hDownload = InetGet($sServerUpdateExe, $g_sUpdatePathIs, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
            Do
                Sleep(250)
            Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)
            MsgBox(0,"Download Finished","download completed", 3)
            DownloadDeleteRename()
    EndSwitch
EndFunc

Func DownloadDeleteRename()
    Local $iRetryOrNot, $bUpdateFailed = False
    FileDelete($g_sToBeReplacedPathIs)
    FileMove($g_sUpdatePathIs, $g_sToBeReplacedPathIs, 1)
    If doVersionCheck(True) Then
        $iRetryOrNot = MsgBox(16 + 5,"Update error detected","Likely cause: Firewall/Antivirus prevented the download. ")
        If $iRetryOrNot = 4 Then
            doVersionCheck()
        Else
            Exit
        EndIf
    EndIf
EndFunc

 

Edited by Subz

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

×
×
  • Create New...