Updating in LB

by John Richardson

jw.richardson@btopenworld.com


For additional information on this topic, see

Downloading a File to Disk - By Alyce Watson


Home

Using WINMM.DLL

Liberty BASIC Default Variables

Updating in LB

Internet - Downloading a File to Disk

API Corner - Easy Font Manipulations

Multiple Windows and Displays

Mapping Real World Coordinates

Linear and Non-Linear Equations

About Ingemar Bjerle

Submission Guildlines

Newsletter Help

Index

Programs are always being updated. Windows 3.1 was the height of technology at one time, but along came Win 95, 98, Me, 2000 and now XP. Have you ever wanted to listen to some music and been forced to download yet another version of RealPlayer? Another example is DirectX - some old games need DirectX 2 or 3, but now most need version 7, 8 or even 9!

Updating is a good idea because it allows you to gain access to new, advanced features and therefore improves your experience with the product. LB2 introduced sprites into the language and LB3 added 32-bit API calls. Now LB 4 is just around the corner!

Apart from going to a software store, the main method of upgrading software is on the Internet. If you see a new version of FreeForm you can download it from the group's files area.

The easiest and fastest way of upgrading is through a wizard in the program. For example Norton AntiVirus's 'LiveUpdate' allows you to download virus definitions directly from the program.

Your LB programs can also do this! If you like, your program can download new versions automatically using a wizard! It works by downloading the update to a file and then loading the file into the application - simple but effective.

As an example, we will have a program that plays .wav files. The skins can be updated using the Internet. It'll be like WinAmp or Windows Media Player, but automatic.

Here's an English version of the updating section of the program:

  1. Make a window.

  2. Check if there is an updated skin.

  3. Add a button allowing the user to update the skin if they haven't already done so.

  4. If the button is pressed, ask the user to connect to the Internet.

  5. Download the new skin.

  6. Restart the program.

  7. When, at step 2, the new skin is found it should be drawn.

So, without further ado, here's the example program:

'--- START OF CODE ---'

nomainwin

'Load a sample window.
WindowWidth = 305
WindowHeight = 225
UpperLeftX = int((DisplayWidth - WindowWidth) / 2)
UpperLeftY = int((DisplayHeight - WindowHeight) / 2)

graphicbox #main.graphics1, 0, 0, 300, 200
button #main.button1, "Play", [play], UL, 175, 120, 105, 25
button #main.button2, "Update", [update], UL, 175, 155, 105, 25

open "Upgrading in LB" for window as #main

print #main, "trapclose [quit]"
print #main.graphics1, "down"

[redraw]
'The code between here and 'wait' will draw the default
'skin unless an update exists.

dim info$(1,10)
files "c:\", "skin.bmp", info$(
if val(info$(0, 0)) <> 0 then
 loadbmp "skin", "c:\skin.bmp"
 print #main.graphics1, "place 0 0; drawbmp skin; flush"
else
 print #main.graphics1, "fill red; backcolor yellow; place 10 10; boxfilled 290 190; flush"
end if

wait

[play]
'This is just to make the program do something useful!
filedialog "Open", "*.wav", soundFile$
if soundFile$ = "" or right$(soundFile$, 4) <> ".wav" then wait
playwave soundFile$ 'Play the sound!
wait

[update]
'Below is the code for the messagebox.
calldll #user32, "MessageBeep", _MB_ICONINFORMATION as long, beepResult as boolean
mbflags = _MB_ICONINFORMATION OR _MB_OKCANCEL
calldll #user32, "MessageBoxA", _
0 as long, _
"To download a new skin please connect to the internet and press 'OK'. If you would like to stop this process, click 'Cancel'." as ptr, _
"Music Player Lite" as ptr, _
mbflags as long, _
mbResult as long
if mbResult = 1 then call DownloadSkin  'mbResult = 1 => "OK"
if mbResult = 2 then wait               'mbResult = 2 => "Cancel"
goto [redraw]

[quit] 'trapclose
close #main
end

sub DownloadSkin 'Here's the update code:

'This is the dll that does all of the internet stuff.

'Original URLMON.dll routine from http://alycesrestaurant.com/

open "URLmon" for dll as #url

'This is the URL of the skin.
urlfile$ = "http://www.btinternet.com/~encryptor/skin.bmp"

'This is where the file is downloaded to.
localfile$ = "c:\skin.bmp"

calldll #url, "URLDownloadToFileA",_
0 as long,_         'Leave this setting!
urlfile$ as ptr,_
localfile$ as ptr,_
0 as long,_         'Must be 0.
0 as long,_         'Callback address.
ret as long

'If there was an error, a non-zero value is returned.
if ret <> 0 then notice "Error"; chr$(13); "The update has failed."

goto [endSub]

[quit]          'This branch label is in the sub also
close #url      'so that it doesn't crash if the user
goto [endSub]   'tries to close the window.

[endSub]
close #url
end sub         'Go back to the main program.

'--- END OF CODE ---'

Well, I hope that this tutorial has been of use and that your programs can be updated using the Internet. Hopefully it'll be with a better program than Music Player Lite!


Home

Using WINMM.DLL

Liberty BASIC Default Variables

Updating in LB

Internet - Downloading a File to Disk

API Corner - Easy Font Manipulations

Multiple Windows and Displays

Mapping Real World Coordinates

Linear and Non-Linear Equations

About Ingemar Bjerle

Submission Guildlines

Newsletter Help

Index