Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Clan CDH on June 01, 2006, 11:26 PM

Title: Updater
Post by: Clan CDH on June 01, 2006, 11:26 PM
How would I make an updater for one of my programs that checks every time you startup the program for it to update if there is a new version available?  I really want it to be PHP based because I know how to read it and I know it's probably the simplest way to do it.  I'll be posting this questions in similar forums hoping to get an answer asap.
Title: Re: Updater
Post by: MyndFyre on June 02, 2006, 01:38 AM
One thing you should know is that your executables can't be overwritten while they're in memory.
Title: Re: Updater
Post by: FrOzeN on June 02, 2006, 06:10 AM
On some webpage just have a file called "version.txt", then inside it just in plain text have the latest version, eg "1.2.0".

In your Visual Basic project, when it loads. You should call a function to access this webpage (probably easiest done with Inet, better to do with Winsock) and check to see if your .exe's version is the same as the one on the webpage. If it's not, tell the user that there program is out of date and provide them with a link to a new version, or setup your project to download the new version (which could be difficult).

Note that if you call Inet(), place the call in another function which has DoEvents above the call of Inet. This way your program doesn't freeze up while it checks the version.

You don't need php to do this.
Title: Re: Updater
Post by: Spht on June 02, 2006, 08:09 AM
There are several ways to do this.

If I recall correctly, Userloser's CheckVersion.bcp downloads a binary file on a web server that contains the latest build number, and compares that with the local copy and notifies the user of an update if it is different.

In WebBot, I utilize Botnet databases, and always keep an entry that is the current build information (this contains the build date, version info, and build number).  On each connect when the database is downloaded the user is notified and complete download instructions are presented if there is an update available.  Additionally, due to the nature of Botnet database updates, when a new version is published, all online Webbots are immediately notified of the update automatically.
Title: Re: Updater
Post by: Joe[x86] on June 02, 2006, 08:27 AM
If Inet1.OpenURL("http://some.web.server/path/sometextfile.txt") = App.Major & "." & App.Minor & "." & App.Revision Then
    ' Current
Else
    ' Upgrade
End If
Title: Re: Updater
Post by: Clan CDH on June 02, 2006, 11:40 AM
some guy on the stealthbot forums told me to use msinet.ocx and it gives me an error, as for winsock, i really haven't learned it yet.  im trying a method that someone posted on another forum but this is by far the most helpful one that i've used so far.  thx and i could use some other input since i cant use the msinet.ocx

anyways i just tried this other method and it did not work, it was a post at vbcity made here (http://www.vbcity.com/forums/topic.asp?tid=15217&highlight=updater) and it did not work.  anyways i would try J's thing if the inet was working for me but i have to get a license thing and i'm using enterprise edition
Title: Re: Updater
Post by: FrostWraith on June 02, 2006, 12:21 PM
Quote from: Clan CDH on June 02, 2006, 11:40 AM
anyways i would try J's thing if the inet was working for me but i have to get a license thing and i'm using enterprise edition

Did you register it like FrOzeN explained?
Title: Re: Updater
Post by: Clan CDH on June 02, 2006, 01:03 PM
ya i did, do that if u saw my reply and i got it to work i needed the stupid vbclient to install the licenses for me so i just got that working
Title: Re: Updater
Post by: rabbit on June 02, 2006, 05:02 PM
As for winsock, which is by far the better method, use this: http://www.jmarshall.com/easy/http/
Specifically GET, as POST really is just not necessary at all for this sort of thing.
Title: Re: Updater
Post by: Clan CDH on June 04, 2006, 11:28 PM
my pro friend says inet is way better but he cant help me right now cuz he's on vacation.
Title: Re: Updater
Post by: UserLoser on June 04, 2006, 11:38 PM
Quote from: MyndFyre[vL] on June 02, 2006, 01:38 AM
One thing you should know is that your executables can't be overwritten while they're in memory.

Not even with VirtualProtect, then dumping the memory block to a binary file?!
Title: Re: Updater
Post by: Hdx on June 05, 2006, 11:44 AM
Heres a bad way to do it.
But it works.
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
private patched as boolean

Private Sub Form_Terminate()
If patched Then x = Shell(App.Path & "\update.bat")
End Sub


Public Sub Update()
    If Inet.openURL("http://some.place.on.the.web/myProggie/currentver.txt") <> App.Major & "." & App.Minor & "." & App.Revision Then
        MsgBox "OMGEEZ J00S NOT UPDATED!!! UPDATORZING NOWZORZ LAWLEZ!!"
        Call URLDownloadToFile(0, "http://some.place.on.the.web/myProggie/Current.exe", App.Path & "\update.exe", 0, 0)
       
        Open App.Path & "\update.bat" For Output As #1
            Print #1, "ren " & App.EXEName & ".exe " & "OLD_VER-" & App.Major & "." & App.Minor & "." & App.Revision & ".exe"
            Print #1, "ren update.exe " & App.EXEName & ".exe"
            Print #1, "run " & App.EXEName & ".exe"
        Close #1
        patched = True
        For Each frm In Forms
            Unload frm
        Next frm
    Else
        MsgBox "OMG JOOS UPDATED!! 1337 YOEZ!!!"
    End If
End Sub

Note: I'm extreamly bored sitting in class so I wrote this in like 2 mins
~-~(HDX)~-~
Title: Re: Updater
Post by: Clan CDH on June 05, 2006, 12:56 PM
Quote from: HdxBmx27 on June 05, 2006, 11:44 AM
Heres a bad way to do it.
But it works.
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
private patched as boolean

Private Sub Form_Terminate()
If patched Then x = Shell(App.Path & "\update.bat")
End Sub


Public Sub Update()
    If Inet.openURL("http://some.place.on.the.web/myProggie/currentver.txt") <> App.Major & "." & App.Minor & "." & App.Revision Then
        MsgBox "OMGEEZ J00S NOT UPDATED!!! UPDATORZING NOWZORZ LAWLEZ!!"
        Call URLDownloadToFile(0, "http://some.place.on.the.web/myProggie/Current.exe", App.Path & "\update.exe", 0, 0)
       
        Open App.Path & "\update.bat" For Output As #1
            Print #1, "ren " & App.EXEName & ".exe " & "OLD_VER-" & App.Major & "." & App.Minor & "." & App.Revision & ".exe"
            Print #1, "ren update.exe " & App.EXEName & ".exe"
            Print #1, "run " & App.EXEName & ".exe"
        Close #1
        patched = True
        For Each frm In Forms
            Unload frm
        Next frm
    Else
        MsgBox "OMG JOOS UPDATED!! 1337 YOEZ!!!"
    End If
End Sub

Note: I'm extreamly bored sitting in class so I wrote this in like 2 mins
~-~(HDX)~-~

thx im tryin this out now

edit:  i keep getting an error on this line(its the object required error)
Quote
    If Inet.OpenURL("http://mehateeggz.googlepages.com/CurrentVer.txt") <> App.Major & "." & App.Minor & "." & App.Revision Then
Title: Re: Updater
Post by: l2k-Shadow on June 05, 2006, 02:25 PM
You need to load inet into your app, (internet file transfer protocol) or something like that it should be called in your components (CTRL+T) directory.
Title: Re: Updater
Post by: Clan CDH on June 05, 2006, 02:30 PM
Quote from: l2k-Shadow on June 05, 2006, 02:25 PM
You need to load inet into your app, (internet file transfer protocol) or something like that it should be called in your components (CTRL+T) directory.

i know, i m not that newbish, i think it might be a problem with my text file?
http://mehateeggz.googlepages.com/CurrentVer.txt
Title: Re: Updater
Post by: l2k-Shadow on June 05, 2006, 02:32 PM
Quote from: Clan CDH on June 05, 2006, 02:30 PM
Quote from: l2k-Shadow on June 05, 2006, 02:25 PM
You need to load inet into your app, (internet file transfer protocol) or something like that it should be called in your components (CTRL+T) directory.

i know, i m not that newbish, i think it might be a problem with my text file?
http://mehateeggz.googlepages.com/CurrentVer.txt

Well you said that it is throwing an object required error. And by definition object required error means that you are trying to call an object that is not there, which in this case you are calling an INET control, which the VB has detected missing, so therefore that is the only problem that is able to be associated with this error in this line of code.
Title: Re: Updater
Post by: Clan CDH on June 05, 2006, 03:34 PM
Quote from: l2k-Shadow on June 05, 2006, 02:32 PM
Quote from: Clan CDH on June 05, 2006, 02:30 PM
Quote from: l2k-Shadow on June 05, 2006, 02:25 PM
You need to load inet into your app, (internet file transfer protocol) or something like that it should be called in your components (CTRL+T) directory.

i know, i m not that newbish, i think it might be a problem with my text file?
http://mehateeggz.googlepages.com/CurrentVer.txt

Well you said that it is throwing an object required error. And by definition object required error means that you are trying to call an object that is not there, which in this case you are calling an INET control, which the VB has detected missing, so therefore that is the only problem that is able to be associated with this error in this line of code.

i know, but it's not missing the inet control because i have it in there, it highlights that whole line, i believe it might be in the app.major, could that be possible?

edit:  here's my form maybe im doing something wrong
http://mehateeggz.googlepages.com/Updater.frm
Title: Re: Updater
Post by: warz on June 05, 2006, 06:28 PM

If Inet.OpenURL("http://mehateeggz.googlepages.com/CurrentVer.txt") <> App.Major & "." & App.Minor & "." & App.Revision Then


I'm not sure if i'm correct - but wouldn't it be better in this case to use a string comparison function rather than greater than or less than? Would App.Major & "." & App.Minor & "." & App.Revision be treated as a string? I don't think it'd be treated as any numerical data. Maybe try something similar to strcmp, or something.

If you are infact allowed to use greater than or less than on two strings, then it might be better to enclose the values to the right of the comparison operators in parenthesis so it does the & operations, and then looks at the entire string, because it might be trying to do this:


if (Inet.OpenURL("http://mehateeggz.googlepages.com/CurrentVer.txt") <> App.Major) & "." & App.minor [...]
Title: Re: Updater
Post by: rabbit on June 05, 2006, 07:06 PM
Cascade checks should be used.  IE: Check the major version first.  If the supplied is lower than the check, update, otherwise move on to the minor version, do the same, and move on the to revision.
Title: Re: Updater
Post by: Hdx on June 05, 2006, 07:38 PM
Quote from: warz on June 05, 2006, 06:28 PM
I'm not sure if i'm correct - but wouldn't it be better in this case to use a string comparison function rather than greater than or less than? Would App.Major & "." & App.Minor & "." & App.Revision be treated as a string? I don't think it'd be treated as any numerical data. Maybe try something similar to strcmp, or something.

If you are infact allowed to use greater than or less than on two strings, then it might be better to enclose the values to the right of the comparison operators in parenthesis so it does the & operations, and then looks at the entire string, because it might be trying to do this:


if (Inet.OpenURL("http://mehateeggz.googlepages.com/CurrentVer.txt") <> App.Major) & "." & App.minor [...]

Well, VB being the newbish languuage it is, dosent matter. The strings are conceated(sp?) before the comparisions are done.
Therefor my line works fine.


Quote from: rabbit on June 05, 2006, 07:06 PM
Cascade checks should be used. IE: Check the major version first. If the supplied is lower than the check, update, otherwise move on to the minor version, do the same, and move on the to revision.
Why? we're talking to a kiddie here, using VB. I honestly don't think it should be cascading, when it all can be done in one move.
Oh well, w/e

Quote from: Clan CDH on June 05, 2006, 03:34 PMi know, but it's not missing the inet control because i have it in there, it highlights that whole line, i believe it might be in the app.major, could that be possible?

edit: here's my form maybe im doing something wrong
http://mehateeggz.googlepages.com/Updater.frm
Yes you are missing the 'Inet' control.
Your control is named 'Inet1'
It MUST be named 'Inet', considering you have the 1, it cant find it! There for you get the error!!!
DUA!
Anyways.
Pay attention boyo :P

My code works FINE, I tested it many times in 2rd period, many times.
(Our school has a personal HTTP server in each lab(for php programming) and I have access to them all <3)
~-~(HDX)~-~
Title: Re: Updater
Post by: rabbit on June 05, 2006, 08:27 PM
It's a lot easier to cascade than to compare strings.
Title: Re: Updater
Post by: Clan CDH on June 05, 2006, 09:59 PM
woops i didn't see that i guess >_< imma go in and beat me self over the head now
Title: Re: Updater
Post by: l2k-Shadow on June 06, 2006, 02:24 PM
AFAIK, upon compilation, VB changes the <> to StrComp() when comparing strings.
Title: Re: Updater
Post by: warz on June 06, 2006, 02:45 PM
Quote from: l2k-Shadow on June 06, 2006, 02:24 PM
AFAIK, upon compilation, VB changes the <> to StrComp() when comparing strings.

eh, i doubt that.
Title: Re: Updater
Post by: rabbit on June 06, 2006, 03:49 PM
AFAIK it changes it to two different calls: a <> b becomes a < b and a > b
Title: Re: Updater
Post by: warz on June 06, 2006, 04:10 PM
AFAYK.
Title: Re: Updater
Post by: rabbit on June 06, 2006, 07:12 PM
Quote from: warz on June 06, 2006, 04:10 PM
AFAYK.
Yes...I pinch.
Title: Re: Updater
Post by: vuther.de on June 14, 2006, 11:49 AM
Not sure if anyone has given him a solution, but Clan CDH, if you want my code I made for my bot for auto-updating, I'll give you it.
Title: Re: Updater
Post by: Hdx on June 14, 2006, 05:58 PM
mm, reviving a dead thread, w/o adding anything, thanks.
And yes he has been helped:
Poke (http://forum.valhallalegends.com/index.php?topic=15111.msg153850#msg153850)
~-~(HDX)~-~