SmallBasic | AutoUpdater - Snippet

SmallBasic | AutoUpdater - 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 avaible 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
  3. a textfile
  4. a file uploader
  5. the LitDev extension (alternative)

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

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

In the first line, you write the version number of the program you would like to update. Only numbers are allowed!
In the second line you write the count of all following lines.
In the third line you start to write the download links for the files you want to download. One line for each link.
Please note that the Updater downloads the files like the checkfile. That is why it doesn't work with every file uploader, too.
After that you write the directory you want to copy the file to. New folders will be created automatically. You need to write two back slashes instead of one!
There are two ways to write the directory:
  • Write the whole path
  • Write PD at the start of the line. This will tell the Updater to copy the file to the programs directory. Than leave one space and write a path (which starts with two back slashes)
Let's make an example:
1.1.1
2.4
5.C:\\AutoUpdater - Test\\Test2.txt
6.
PD \\AutoUpdater - Test\\Test1.txt

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 2

Now we want to integrate the Updater 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. Simply 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.
Go to the subroutine UpdaterStart.
It should look like this:
Sub UpdaterStart
AutoUpdaterVersion = "1.0"
ProgramVersion = 1.0 'This is the version of the program you want to update.
CheckLink = "http://sbautoupdater.npage.de/get_file.php?id=24521039&vnr=428469" 'The downloadlink for the checkfile (which contains all needed information)  IMPORATANT: Never change the link of the checkfile. Otherwise the program won't work!!!
CheckFileDestination = Program.Directory + "\\Note Program.txt" 'The place where the checkfile gets copied to.
Programm()
EndSub

AutoupdaterVersion show's the version of the Updater. So, you know which version you used.
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.

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

The second way

For this way you need to download and install the LitDev extension for SmallBasic.

Copy the snippet in a new program. Now we need to edit it a bit.
Go to the subroutine UpdaterStart.
It should look like this:
Sub UpdaterStart
AutoUpdaterVersion = "1.0"
ProgramVersion = 1.0 'This is the version of the program you want to update.
CheckLink = "http://sbautoupdater.npage.de/get_file.php?id=24521039&vnr=428469" 'The downloadlink for the checkfile (which contains all needed information)  IMPORATANT: Never change the link of the checkfile. Otherwise the program won't work!!!
CheckFileDestination = Program.Directory + "\\Note Program.txt" 'The place where the checkfile gets copied to.
Programm()
EndSub

AutoupdaterVersion show's the version of the Updater. So, you know which version you used.
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.

After this, go to the subroutine UpdateDone.
It should look like this:
Sub UpdateDone
  For o = 1 To 5
    UpdateDoneSpace[o] = Text.GetCharacter(10)
    TextWindow.WriteLine(UpdateDoneSpace[o])
  EndFor
  TextWindow.WriteLine("The update is done!")
  TextWindow.Write("Your new version is ")
  TextWindow.ForegroundColor = "Red"
  TextWindow.Write(File.ReadLine(CheckFileDestination, 1))
  TextWindow.ForegroundColor = "Gray"
  TextWindow.WriteLine(".")
  For o = 1 To 11
    UpdateDoneSpace[o] = Text.GetCharacter(10)
    TextWindow.WriteLine(UpdateDoneSpace[o])
  EndFor
  File.DeleteFile(CheckFileDestination)
  'File.WriteLine(Program.Directory + "\\YourNewTextfile.txt", 1, "1")  'This line is only needed if you want to use the AutoUpdater as a seperate program.
  Program.Delay(5000) 'Only for the user. It is not necessary.
  Program.End()
EndSub

Next create a new textfile in your programs directory. Write a 0 in the first line. Save it.
Delete the ' in front of File.WriteLine. Edit the part YourNewTextfile.txt to the textfile you created.

Now save the program. After this, start the new program and end it after it started.
Copy thefollowing files to your programs directory:
  • TheNewProgramsName.exe
  • SmallBasicLibrary.dll
  • LitDev.dll
Now open your program. Go to the line where you want to start the Updater.
I suggest to do this at the start of the program.
Copy this to your program to start the updater:
Sub StartUpdater
  If File.ReadLine(Program.Directory + "\\YourNewTextfile.txt", 1) = 0 Then
    LDProcess.Start(Program.Directory + "\\TheNewProgramsName.exe", "")
    Program.End()
  ElseIf File.ReadLine(Program.Directory + "\\YourNewTextfile.txt", 1) = 1 Then
    TheStartSubroutineOfYourProgram()
  EndIf
EndSub
 
Sub TheStartSubroutineOfYourProgram
  File.WriteLine(Program.Directory + "\\YourNewTextfile.txt", 1, "0")
  'Your programs code
EndSub

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

Notes
 
This snippet is still in work. There may be bugs and missing options!
I am planning to update the snippet and to create different versions of the Updater.
That's why you should visit this side from time to time.

I hope that this snippet is useful for you.
Please leave me a comment and some feedback.
Leave a Comment
  • Please add 5 and 2 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Maheshkumar S Tiwari edited Revision 5. Comment: minor edit

  • Maheshkumar S Tiwari edited Revision 4. Comment: Added tags

  • Timo Sö edited Revision 3. Comment: Deleted an unneeded sentence

Page 1 of 1 (3 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Timo Sö edited Revision 3. Comment: Deleted an unneeded sentence

  • Maheshkumar S Tiwari edited Revision 4. Comment: Added tags

  • Maheshkumar S Tiwari edited Revision 5. Comment: minor edit

  • Well written article and useful - I look forward to the next one...

  • Very nice article! Comprehensive but simple enough for a beginner to follow.

Page 1 of 1 (5 items)