Sign in to follow this  
Followers 0
Somniis

Easy update script

7 posts in this topic

Use this as a button. Just have the file to download (if new version) and a INI with the current version in it on the web server of your choice.

$CURRENT = "the web address to the new(er) file"
$CVER = "the webaddress to the INI with current version in it"
$INI = path to the INI on computer with version in it
$DLDIR = path to save the newer version

Case $msg = $BUTTON
            Dim $sd = 0
            Dim $nv = 0
            
            Dim $d = InetGet($CVER, @ScriptDir & "\data\check.ini")
            
            If $d = 0 Then
                MsgBox(16, "Error", "Cannot connect to server.  Please check internet settings!")
                FileDelete(@ScriptDir & "\data\check.ini")
                $sd = 1
            EndIf
            
            If $sd = 0 Then
                Dim $c_Ini = IniRead(@ScriptDir & "\data\check.ini", "Data", "Ver", "")
                Dim $this_Ini = IniRead($INI, "Data", "Ver" , "")
            
                If $this_Ini < $c_Ini Then
                    $nv = 1
                ElseIf $this_Ini = $c_Ini Then
                    $nv = 0
                EndIf
                
                If $nv = 1 Then
                    Dim $size = InetGetSize($CURRENT)
                    
                    If $size < 100000 Then;retrieves webpage instead of file if small size - only have this here because the file I used was on geocities free :-)
                        Msgbox(16, "Error", "Download server is down.  Please try again later.")
                        FileDelete(@ScriptDir & "\data\check.ini")
                        $sd = 1
                    EndIf
            
                    If $sd = 0 And $nv = 1 Then
                        Dim $kb = Round($size / 1024, 0);convert to kilobytes and chop off decimal places
                        $m1 = MsgBox(4, "New version available", "New version(" & $c_Ini & ") is " & $kb & "kb.  Download?")
                        If $m1 = 6 Then;Yes
                            Dim $dl = InetGet($CURRENT, $DLDIR, 1, 1)
                            If $dl = 0 Then
                                MsgBox(16, "Error", "Cannot connect to server.  Please check internet settings!")
                            EndIf
                            ProgressOn("Downloading...", "Retrieving new version.")
                            While @InetGetActive
                                Dim $p = (100 * @InetGetBytesRead) / $size
                                ProgressSet($p, @InetGetBytesRead & "/" & $size & " bytes", "Download in progress.")
                                Sleep(250)
                            WEnd
                            ProgressOff()
                            FileDelete(@ScriptDir & "\data\check.ini")
                            MsgBox(64, "Done", "The file was downloaded to: " & $DLDIR)
                        EndIf
                    EndIf
                ElseIf $nv = 0 Then
                    MsgBox(64, "Update complete", "No newer version available.")
                    FileDelete(@ScriptDir & "\data\check.ini")
                EndIf
            EndIf

INI should have this format:

[Data]

Ver=1.0 (or 1.2, 1.3, etc.)

All this code does is download the INI on the webserver, compare the Ver number in it with the one of the current script, and compare the two numbers gained to determine if a newer version is available.

Pretty simple, but I hope it may help someone. :)

Share this post


Link to post
Share on other sites



I don't see where you change the ini's version number for when you check for the next update, or am I just missing that?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I don't see where you change the ini's version number for when you check for the next update, or am I just missing that?

Ahhhh, sorry. I have a variable that holds the version of the script that is running. I just write that into a INI when the script starts up everytime. Then, if it is lower than the one on the web server, it downloads. :)

Share this post


Link to post
Share on other sites

uhhh im lost wut does this do?


A great place to start Autoit 1-2-3

Share this post


Link to post
Share on other sites

uhhh im lost wut does this do?

Allows the end-user to update their application... all you have to do is put the necessary information in there, and have your application check to see if there is an update (however you want to do that).

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I thought it would be easy to see what it does by simply looking at the code. :)

Share this post


Link to post
Share on other sites

I thought it would be easy to see what it does by simply looking at the code. :)

LOL... well if you actually broke it down line by line... It would be :) (Imagine it encoded :mellow:)

(I have one that I made a while back, think I will clean it up (make it usuable by all) and submit it too... a bit different then the others on here.)


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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