Jump to content

My Autoupdater


jackyyll
 Share

Recommended Posts

Just thought i would post this. I have seen many others ones, but they didnt do what i wanted it to do, so i wrote my own using code snippets from theres... Here you go:

Code to check if a new version is out (Put at the top of your main program)

Local $verini = 'http://yoursitet.com/ver/ver.ini';site with the newest ver.ini (containing the current ver)
Local $ping = Ping('www.google.com', 250);Website to ping to check if internet access is available

If $ping = 0 Then;Start Auto updater // Test for internet access, if none exists, close program
    $msg1 = MsgBox(0, "title", "Error! No internet connection detected. Close program now?");Alert that there was an error and ask to close the program
    If $msg1 = 1 Then;If press OK
        Exit;Close the program
    EndIf
EndIf
ConsoleWrite("Ping: " & $ping)
If $ping > 0 Then;If has internet access
    InetGet($verini, @ScriptDir & "\Data\ver.ini", 1);Download the newest version info
    If IniRead(@ScriptDir & '\Data\ver.ini', 'Version', 'FileVer', 'Not Found') > IniRead(@ScriptDir & '\Data\version.ini', 'Version', 'FileVer', 'Not Found') Then;Check if the current version is outdated
        SplashOff();Spalsh Screens off
        SplashTextOn("title", "A newer version has been found and is updating!  Please wait, the program will now restart...");Inform user that the program will now update
        Sleep(2500);Wait 2.5 seconds
        SplashOff();Splash Screens off
        RunWait('update.exe', @ScriptDir);Run the update tool
        Exit;Close the program so it can be updated
    Else
        FileDelete(@ScriptDir & '\Data\ver.ini');If the version is not outdated, delete the ver.ini
    EndIf
EndIf;End Auto updater

update.exe (will download the newest version)

ProcessClose("MAINPROGRAM.exe")

$newestver = IniRead(@ScriptDir & '\Data\ver.ini', 'Version', 'FileVer', 'Not Found')
$website = 'http://yoursite.com/' & $newestver & '/MAINPROGRAM.exe'

If FileExists(@ScriptDir & '\MAINPROGRAM.exe') Then
    FileDelete(@ScriptDir & '\MAINPROGRAM.exe')
Else
    InetGet($website, "MAINPROGRAM.exe", 1)
    IniWrite(@ScriptDir & '\Data\version.ini', 'Version', 'FileVer', $newestver)
    FileDelete(@ScriptDir & '\Data\ver.ini')
    Sleep(10)
    SplashOff()
    SplashTextOn("Updater", "Successfully updated to the latest version.")
    Sleep(5000)
    SplashOff()
    RunWait('MAINPROGRAM.exe', @ScriptDir)
EndIf
Exit

Your servers should have these files:

http://www.yoursite.com/ver/ver.ini
http://www.yoursite.com/NEWESTVERNUMBER/MAINPROGRAM.exe (replacing NEWESTVERNUMBER with something like 1.5 and MAINPROGRAM.exe with your programs name)

Your programs folder should have a Data folder which will have a version.ini in it that has the information on the current version (of the mainprogram that the user has now)

The ver.ini on the server should hold the NEWEST version number.

The ini's should look like this:

[Version]
FileVer=1.0

Hmm didn't think this post would be this long :)

~Marc

Link to comment
Share on other sites

i used some of your script and others to make my own:

Local $ping = Ping("www.google.com");Website to ping to check if internet access is available
If $ping = 0 Then MsgBox(0, "Title", "Error! Please connect to the Internet and try again!")
If $ping <> 0 Then
    Local $Website = "http://www.yoursite.net/yourapp/yourapp.exe"
    Local $myini = "http://www.yoursite.net/yourapp/update.ini"
    InetGet($myini,"C:\Update.ini", 1)
    if IniRead("C:\Update.ini","Update","FileVer","Not Found") > FileGetVersion("yourapp.exe") Then
    $msgA = Msgbox(4,"Update","Updates are available, Update now?")
    if $msgA = 6 Then
    ProcessClose("yourapp.exe")
    FileDelete(@Scriptdir & "\yourapp.exe")
    INetGet($Website,@scriptdir & "\yourapp.exe", 1, 0)
yourapp.exe"))
    EndIf
    EndIf
    If IniRead("C:\Update.ini","Update","FileVer","Not Found") <= FileGetVersion("yourapp.exe") Then
    Msgbox(0,"Latest","You currently have the latest version of yourapp")
    EndIf
EndIf

I like it because it only closes the program and deletes it if there is a newer version.

The update.ini looks like this

[Update]
FileVer=0.0.0.4
Edited by RazerM
My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

[...]

ProcessClose("yourapp.exe")

FileDelete(@Scriptdir & "\yourapp.exe")

INetGet($Website,@scriptdir & "\yourapp.exe", 1, 0)

yourapp.exe"))

[...]

Ok cool, and what happens if file download fails? the main prog is gone and you've lost older & newer files!

You should only Rename the main prog and delete it only when (and if) the newer version has been succesfully downloaded.

Link to comment
Share on other sites

yes ill update my script. Thx

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

i used some of your script and others to make my own:

Local $ping = Ping("www.google.com");Website to ping to check if internet access is available
If $ping = 0 Then MsgBox(0, "Title", "Error! Please connect to the Internet and try again!")
If $ping <> 0 Then
    Local $Website = "http://www.yoursite.net/yourapp/yourapp.exe"
    Local $myini = "http://www.yoursite.net/yourapp/update.ini"
    InetGet($myini,"C:\Update.ini", 1)
    if IniRead("C:\Update.ini","Update","FileVer","Not Found") > FileGetVersion("yourapp.exe") Then
    $msgA = Msgbox(4,"Update","Updates are available, Update now?")
    if $msgA = 6 Then
    ProcessClose("yourapp.exe")
    FileDelete(@Scriptdir & "\yourapp.exe")
    INetGet($Website,@scriptdir & "\yourapp.exe", 1, 0)
yourapp.exe"))
    EndIf
    EndIf
    If IniRead("C:\Update.ini","Update","FileVer","Not Found") <= FileGetVersion("yourapp.exe") Then
    Msgbox(0,"Latest","You currently have the latest version of yourapp")
    EndIf
EndIf

I like it because it only closes the program and deletes it if there is a newer version.

The update.ini looks like this

[Update]
FileVer=0.0.0.4
Mine also deletes the mainprogram. And if the download fails you can just run update.exe.
Link to comment
Share on other sites

here is a far better version than my last it checks the filesize in bytes beforecontinuing to download

EDIT: Added more checks and new version info, deletes update.ini after use and uses new ini key called FileVerDescript so you can have 0.4 as version instead of 0.0.0.4 it is only used in a messagebox

Local $ping = Ping("www.google.com");Website to ping to check if internet access is available
Local $Website = "http://www.yoursite.com/yourapp/yourapp.exe"
Local $myini = "http://www.yoursite.com/yourapp/update.ini"
If $ping = 0 Then MsgBox(0, "yourapp - Update", "Error! Please connect to the Internet and try again!")
Global $exesize = InetGetSize("http://www.yoursite.com/yourapp/yourapp.exe")
If $ping <> 0 Then
    InetGet($myini,"C:\Update.ini", 1)
    If $exesize <> IniRead("C:\Update.ini", "Size", "Bytes", 0) Then MsgBox(48, "Error!", "Filesize stated in ini does not match file on server!")
    If $exesize = IniRead("C:\Update.ini", "Size", "Bytes", 0) Then
    if IniRead("C:\Update.ini","Update","FileVer","Not Found") > FileGetVersion("yourapp.exe") Then
    $msgA = Msgbox(4,"Update","yourapp version " & IniRead("C:\Update.ini","Update","FileVerDescript","Not Found") & " is available, Update now?")
    if $msgA = 6 Then
    ProcessClose("yourapp.exe")
    FileMove(@Scriptdir & "\yourapp.exe", @Scriptdir & "\yourappOld.bak.exe")
    INetGet($Website,@scriptdir & "\yourapp.exe", 1, 0)
    $updatecheck = FileExists(@Scriptdir & "\yourapp.exe")
    $exesize = InetGetSize("http://www.yoursite.com/yourapp/yourapp.exe")
    If $updatecheck = 1 And $exesize = IniRead("C:\Update.ini", "Size", "Bytes", 0) Then
        MsgBox(0, "Complete", "yourapp has been updated to: Version " & IniRead("C:\Update.ini","Update","FileVerDescript","Not Found"))
        FileDelete(@Scriptdir & "\yourappOld.bak.exe")
    EndIf
    If $updatecheck = 0 Or $exesize <> IniRead("C:\Update.ini", "Size", "Bytes", 0) Then
        FileMove(@Scriptdir & "\yourappOld.bak.exe", @Scriptdir & "\yourapp.exe")
        MsgBox(48, "Error!", "The download failed - Updater has restored your previous yourapp file")
    EndIf
    EndIf
    EndIf
    If IniRead("C:\Update.ini","Update","FileVer","Not Found") <= FileGetVersion("yourapp.exe") Then
    Msgbox(0,"Latest","You currently have the latest version of yourapp")
    EndIf
    EndIf
FileDelete("C:\Update.ini")
EndIf

The ini should look like

[Update]
FileVer=0.0.0.5
FileVerDescript=0.5
[Size]
Bytes=232639

Edit:removed a reference to my program

Edited by RazerM
My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

Whats the point of checking file size? And whats the point of FileVerDescription? It's kind of overkill :)

It checks file size to make sure that it doesnt download an incomplete or corrupt file. FileVerDescript can be used for 0.4 instead of 0.0.0.4 it is only used for the mesagebox

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
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...