Small Basic: AutoUpdater Code Snippet

Small Basic: AutoUpdater Code Snippet



Introduction


I created this snippet, because I really missed an option like this in SmallBasic.

I never saw something like this in another SmallBasic program before.

This snippet will check if a newer version of your program is available for download.
And if there is a new version, it will download and install it.

What do you need?


You need...
  1.  SmallBasic
  2.  the snippet and the AUextension
  3. a textfile
  4. a file uploader

The file uploader


This snippet will not work with every file uploader.
The best way is to create an own website. There are many free providers like hpage and Oyla.
If you find a file uploader for which it works, please leave a comment with a link.

It is very important that you can re-upload the file. So the link does not change, but you can change the text inside the file.
Otherwise the snippet will not work!

Step 1

Preparations


You need to install the AUextension to run the AutoUpdater.
To do this, you must copy the files in the folder "AUextension" into the "lib" folder of SmallBasic.
Usually it is located at "C:\Program Files (x86)\Microsoft\SmallBasic\lib" or "C:\Program Files\Microsoft\SmallBasic\lib".
If the lib folder doesn't exist, create it.

Next you must create a new textfile at the same location the AutoUpdater is.
Call it however you want. In my examples I call it YourProgramFile.txt.
In the first line you write the actual version of your program.
In the second line you write a 0.

Step 2

Creating the updatefile


There are two ways to create the updatefile.
  1. With the Filecreator
  2. Manually

With the Filecreator

This is the easy and fast way.
You can find the Filecreator inside the .zip archive you downloaded sooner.
Doubleclick the "AutoUpdater - Filecreator v2.0.exe" and the program should start.
It should look like this:



If you press the "Help"-button you get more detailled information about every part of the program.
Simply click the button you want to get information about and read the text in textboxes.
If you click the "Help"-button it should look like this:



To get back press the "Back"-button.

To create a new file you need to enter a name first.
After this you must enter the first version of the program you want to update. Only numbers are allowed!
Next choose the right command. For example you want to download a file and copy it to the program directory.
To do this you need to choose the "Install PD" option. Simply click the button. A green rectangle should appear around it.
Now you need to enter the download link and the directory.
We want to copy the file into the program directory, so we must start with the path there.
For example you want to copy the file to "C:\test\myfiles\testfile.txt".
The program directory is "C:\test\AutoUpdater.exe". Now you only have to add "myfiles\testfile.txt".
If this is done click the "Add"-burron. Now your changes appear in the textbox at the right.
The delete options do not need a link.
The version option does not need a link and a directory, but you should change the version number (you must increase it).

If you want to save your file, press the "Save"-button. Your file will be saved at the directory of the Filecreator with the name you entered.
If you want to load a file, press the "Load"-button and choose the file you want to load. Only textfiles are supported.
If you want to delete your current progress, press the "Clear"-button.

You can do manual changes on the right side.
It works similar than without the program.
Your changes will be saved automatical.
Only do this if you know what you do!

Manually


First you need to create a new textfile.
After you did this, open the new file.

In the first line you write total count of versions with +1 for the mot new version.
In the second line you write the actual Version and then ##;## and then version 1 and then ##;## and then version 2 and so on.
In the third line you write the total count of lines and then ##;## and then the position (line) of version 1 and then ##;## and then the position (line) of Version 2 and so on.
In the fourth line you write Ver, four spaces and then the versionnumber of the first version.
In the next lines you write what the AutoUpdater must do to update to this version.
Remember the spaces. Everything after position number 7 is your entry.
That's why you must write after Ver four spaces, after InstPD one space, after Down three spaces and so on.
That's the done filestructur:
01.Total count of versions   'with +1 for the most new version
02.Actual Version##;##Version 1##;##Version 2##;##Version 3    And so on
03.Total count of lines##;##Position (line) of Version 1##;##Position (line) of Version 2##;##Position (line) of Version 3  
04.Ver    First Version (versionsnumber)
05.Down   Downloadlink         ->  You must combine these two lines! They do not work alone!
06.InstPD Installationpath    -> 
07.DeleN  Deletepath
08.Ver    Second Version (versionsnumber)
09.Down   Downloadlink
10.InstN  Installationpath
11.DelePD Deletepath
12.Ver    Third Version (versionsnumber)
13.Down   Downloadlink
14.InstPD Installationpath
15.DelePD Deletepath

Let's fill this structur with an example:
01.4
02.2.5##;##1.0##;##2.0##;##2.5
03.13##;##4##;##7##;##10
04.Ver    1.0
05.Down   http://test5353b2.npage.de/get_file.php?id=26437414&vnr=862723
06.InstN  C:\InstN.txt
07.Ver    2.0
08.Down   http://test5353b2.npage.de/get_file.php?id=26437414&vnr=862723
09.InstPD \InstPD.txt
10.Ver    2.5
11.Down   http://test5353b2.npage.de/get_file.php?id=26437414&vnr=862723
12.InstPD \InstPD2.txt
13.DelePD \InstPD.txt

Remember the slashes at the InstPD and DelePD commands.
In addition after the Down command must be the InstN or InstPD command.
The InstN command needs administrator rights. You must start the AutoUpdater as administrator if you want to use it.
Please note that some special characters like ä, ö, ü and ß are not supported for the complete path!

Now upload the file to your file uploader and copy the link.

Step 3


Now we want to integrate the AutoUpdater in your program.
There are two ways to do this.
Please note that I used the textwindow in my snippet. But this is not necessary.

The first way


Simply copy and paste the snippet in your program. But don't paste it in a subroutine!
Now you can start the updater whenever you want. But first you must edit it a bit.
Search for
ini()
 
If startoption = 0 Then
  UpdateCheck()
ElseIf startoption = 1 Then
  TWUpdaterStart()
EndIf

and replace it with
Sub UpdaterStart
  ini()
  If startoption = 0 Then
    UpdateCheck()
  ElseIf startoption = 1 Then
    TWUpdaterStart()
  EndIf
EndSub

Now you can simply start the updater if you write
UpdaterStart()

The negative point of this way is, that you can't update the program.exe file.

Now we need to edit the snippet a bit more.
Go to the subroutine ini.
It should look like this:
'DO YOUR CHANGES HERE
Sub ini
  startoption = 1 '0 = Graphics Window     1 = Text Window
  AutoUpdaterVersion = "2.0" 'Don't change this. ;)
  yptfp = Program.Directory+"\YourProgramFile.txt" 'Your programs text file path
  ProgramVersion = File.ReadLine(yptfp, 1) 'This is the version of the program you want to update.
  CheckLink = "https://alfa3044.alfahosting-server.de/ftplogin/web139/ftp_download.php?filesize=384&download=%2Ffiles%2FTestcheckdatei2.txt"''The downloadlink of the checkfile (which contains all needed information)  IMPORATANT: Never change the link of the checkfile. Otherwise the program won't work!!!
  CheckFileDestination = Program.Directory + "\\Testcheckdatei2.txt" 'The place where the checkfile gets copied to.
  picwebadr = "http://social.technet.microsoft.com/wiki/contents/articles/19708.small-basic-autoupdater-code-snippet.aspx" 'Everytime you click on the picture in the middle, the standard browser will open this side Graphics Window only
  Picw = 190 'the width of your picture in pixel
  Pich = 110 'the height of your picture in pixel
  picpath = Program.Directory+"\AutoUpdater.gif" 'The directory of the picture in the Graphics Window
EndSub
'DO YOUR CHANGES HERE

startoption defines if the Updater interface is the graphics window (0) or the textwindow (1).
AutoupdaterVersion show's the version of the Updater. So, you know which version you used.
yptfp is the path to the textfile of your program. The Updater gets the actual program version from this file.
ProgramVersion show's the version of your program. Edit it to the correct version. Only numbers are allowed!
CheckLink is the link of the textfile you uploaded sooner. Change it to the new link.
CheckFileDestination is the directory where the checkfile will be downloaded to.
picwebadr is the webside which appears if you click (in the grahics window) on the picture in the middle.
Picw is the width of this picture (in pixel).
Pich is the height of this picture (in pixel).
picpath is directory of the picture in the middle.

Save and start your program.
Your new updater should start now.

The second way


You can run the AutoUpdater as a seperate program, too.
Copy the snippet in a new program. Now we need to edit it a bit.
Go to the subroutine ini.
It should look like this:
'DO YOUR CHANGES HERE
Sub ini
  startoption = 1 '0 = Graphics Window     1 = Text Window
  AutoUpdaterVersion = "2.0" 'Don't change this. ;)
  yptfp = Program.Directory+"\YourProgramFile.txt" 'Your programs text file path
  ProgramVersion = File.ReadLine(yptfp, 1) 'This is the version of the program you want to update.
  CheckLink = "https://alfa3044.alfahosting-server.de/ftplogin/web139/ftp_download.php?filesize=384&download=%2Ffiles%2FTestcheckdatei2.txt"''The downloadlink of the checkfile (which contains all needed information)  IMPORATANT: Never change the link of the checkfile. Otherwise the program won't work!!!
  CheckFileDestination = Program.Directory + "\\Testcheckdatei2.txt" 'The place where the checkfile gets copied to.
  picwebadr = "http://social.technet.microsoft.com/wiki/contents/articles/19708.small-basic-autoupdater-code-snippet.aspx" 'Everytime you click on the picture in the middle, the standard browser will open this side Graphics Window only
  Picw = 190 'the width of your picture in pixel
  Pich = 110 'the height of your picture in pixel
  picpath = Program.Directory+"\AutoUpdater.gif" 'The directory of the picture in the Graphics Window
EndSub
'DO YOUR CHANGES HERE

startoption defines if the Updater interface is the graphics window (0) or the textwindow (1).
AutoupdaterVersion show's the version of the Updater. So, you know which version you used.
yptfp is the path to the textfile of your program. The Updater gets the actual program version from this file.
ProgramVersion show's the version of your program. Edit it to the correct version. Only numbers are allowed!
CheckLink is the link of the textfile you uploaded sooner. Change it to the new link.
CheckFileDestination is the directory where the checkfile will be downloaded to.
picwebadr is the webside which appears if you click (in the grahics window) on the picture in the middle.
Picw is the width of this picture (in pixel).
Pich is the height of this picture (in pixel).
picpath is directory of the picture in the middle.

Now save the program. After this, start the new program and end it after it started.
Copy the following files to your programs directory:
  • AutoUpdater.exe
  • SmallBasicLibrary.dll
  • AUextension.dll
Now open your program. Go to the line where you want to start the AutoUpdater.
I suggest to do this at the start of the program.
Copy this to your program to start the updater:
StartUpdater()

Sub
StartUpdater
  If File.ReadLine(Program.Directory + "\\YourProgramFile.txt", 2) = 0 Then
    AUoptions.StartProcess(Program.Directory + "\\AutoUpdater.exe")
    Program.End()
  ElseIf File.ReadLine(Program.Directory + "\\YourProgramFile.txt", 2) = 1 Then
    TheStartSubroutineOfYourProgram()
  EndIf
EndSub
 
Sub TheStartSubroutineOfYourProgram
  File.WriteLine(Program.Directory + "\\YourProgramFile.txt", 2, "0")
  'Your programs code
EndSub

Save and start your program.
Your new updater should start now.

Notes

 
This snippet is still a work in progress. There may be bugs and missing options!
I am planning to update the snippet step by step.
That's why you should visit this TNWiki article from time to time.

Please read the README file in .zip archive you downloaded.
It contains a short summary about the AutoUpdater.

The actual version of the AutoUpdater and the Filecreator is 2.0.

I hope that this snippet is useful for you.
Please leave a comment and some feedback.
 
Sort by: Published Date | Most Recent | Most Useful
Comments
Page 1 of 1 (5 items)