Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Check for updates

Léo Peyronnet edited this page Sep 2, 2020 · 7 revisions

Table of content


Introduction

When you create a software, you usually want to update it to add new features or correct bugs. Thanks to LeoCorpLibrary, it's very simple to implement an update system.

To use the methods and other features of LeoCorpLibrary, dont forget to add this line of code on top of your code file.

C#

using LeoCorpLibrary;

VB

Imports LeoCorpLibrary

Functions

a. IsAvailable

This function is available in version 1.1 and higher.

Compatibility
Framework Compatibility
.NET Framework 4.7.2 ✔ Compatible
.NET Core 3.1 ✔ Compatible

The IsAvailable() method allows you to check if a updates are avaialable for your software. Returns a bool value.

LeoCorpLibrary.Update.IsAvailable()

Note: You need to place the namespace LeoCorpLibrary before the Update class because of a conflict with Control.Update.

Here's this method's arguments

Type Argument Description Example
string version Curent version of the software "1.0.0.0"
string lastVersion Last version of the software "1.1.0.0"

Here's an example of usage that uses the GetLastVersion method:

C#

string lastVersion = LeoCorpLibrary.Update.GetLastVersion("https://dl.dropboxusercontent.com/s/j3fn78x3lcmowpr/Version.txt");
if (LeoCorpLibrary.Update.IsAvailable("1.0.0.0", lastVersion)) // If updates are available
{
    MessageBox.Show("Update available");
}
else
{
    MessageBox.Show("No update available");
}

VB

Dim lastVersion = LeoCorpLibrary.Update.GetLastVersion("https://dl.dropboxusercontent.com/s/j3fn78x3lcmowpr/Version.txt")
If (LeoCorpLibrary.Update.IsAvailable("1.0.0.0", lastVersion)) Then ' If updates are available
    MsgBox("Update available")
Else
    MsgBox("No update available")
End If

Go to top

b. Check

This function is available in version 1.1 and higher.

Compatibility
Framework Compatibility
.NET Framework 4.7.2 ✔ Compatible
.NET Core 3.1 ✔ Compatible

The Check() method allows you to check updates for your software. If updates are available, a specified form will show. Same thing if no updates are avaialable.

LeoCorpLibrary.Update.Check()

Note: You need to place the namespace LeoCorpLibrary before the Update class because of a conflict with Control.Update.

Here's this method's arguments

Type Argument Description Example
string version Curent version of the software "1.0.0.0"
string lastVersion Last version of the software "1.1.0.0"
Form availableUpdateForm Form to show when updates are available Form1
Form noUpdateForm From to show when no updates are available Form2

Here's an example that uses the GetLastVersion method:

C#

string lastVersion = LeoCorpLibrary.Update.GetLastVersion("https://dl.dropboxusercontent.com/s/j3fn78x3lcmowpr/Version.txt");
LeoCorpLibrary.Update.Check("1.0.0.0", lastVersion, new MAJ_AV(), new MAJ_UN());
// A window will open depending on the result

VB

Dim LastVersion = LeoCorpLibrary.Update.GetLastVersion("https://dl.dropboxusercontent.com/s/j3fn78x3lcmowpr/Version.txt")
LeoCorpLibrary.Update.Check("1.0.0.0", LastVersion, new MAJ_AV, new MAJ_UN)
' A Windows will open depending on the result

Go to top

c. GetLastVersion

This function is available in version 1.1 and higher.

Compatibility
Framework Compatibility
.NET Framework 4.7.2 ✔ Compatible
.NET Core 3.1 ✔ Compatible

The GetLastVersion() method download a string from a specfic webpage where a .txt file that countains the last version. Returns a string.

This method has only one argument:

Type Argument Description Example
string lastVersionFileLink Link of the file that countains the last version "https://example.com/Version.txt"

Note: You need to place the namespace LeoCorpLibrary before the Update class because of a conflict with Control.Update.

Here's an example of usage:

C#

string lastVersion = LeoCorpLibrary.Update.GetLastVersion("https://dl.dropboxusercontent.com/s/j3fn78x3lcmowpr/Version.txt");
// You can use the lastVersion variable in the IsAvailable() method. 
// or in the Check() method.

VB

Dim LastVersion = LeoCorpLibrary.Update.GetLastVersion("https://dl.dropboxusercontent.com/s/j3fn78x3lcmowpr/Version.txt")
' You can use the lastVersion variable in the IsAvailable() method. 
' or in the Check() method.

Go to top

d. Install

This function is available in version 1.1 and higher.

Compatibility
Framework Compatibility
.NET Framework 4.7.2 ✔ Compatible
.NET Core 3.1 ✔ Compatible

The Install() method allow to install an update for your software. if you want to update your program using this method, we advice you to uise this method in another program (Updater). This program needs admin privileges to update the software. You can enable this feature in app.manifest. You can create it in Visual Studio. Edit this:

- <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
+ <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />

Here's this method's arguments:

Type Argument Description Example
string filePath Location of the file "C:/Programme/Program.exe"
string lastVersionLink Link of the new file "https://example.com/Program.exe"
bool fromAppStartupPath (Optional) Open the file from Application.StartupPath true

Note: You need to place the namespace LeoCorpLibrary before the Update class because of a conflict with Control.Update.

Example :

C#

string link = "https://dl.dropboxusercontent.com/s/tlekj6j834tgi3r/GestionPersoX.exe";

LeoCorpLibrary.Update.Install("C:/Programme/Programme.exe", link);
// If the program is in 'C:\Program'

LeoCorpLibrary.Update.Install("/Programme.exe", link, true)

VB

Dim link = "https://dl.dropboxusercontent.com/s/tlekj6j834tgi3r/GestionPersoX.exe"

LeoCorpLibrary.Update.Install("C:/Programme/Programme.exe", link)
' If the program is in 'C:\Progtam'

LeoCorpLibrary.Update.Install("/Programme.exe", link, True)

Go to top

e. GetLastVersionAsync

This function is available in version 2.1 and higher.

Compatibility
Framework Compatibility
.NET Framework 4.7.2 ✔ Compatible
.NET Core 3.1 ✔ Compatible

The GetLastVersionAsync() method allows you to obtain the last version of the software asynchronously from a *.txt file.

It's in

LeoCorpLibrary.Update.GetLastVersionAsync()

Here's this method's argument:

Type Argument Description Example
string lastVersionFileLink Link of the file where is stored the last version "https://example.com/Version.txt"

Note: You need to place the namespace LeoCorpLibrary before the Update class because of a conflict with Control.Update.

Here's an example of usage:

C#

async void GetVersion()
{
    string version = await LeoCorpLibrary.Update.GetLastVersionAsync("https://dl.dropboxusercontent.com/s/j3fn78x3lcmowpr/Version.txt");
}

VB

Private Async Sub GetVersion()
    Dim version As String = Await LeoCorpLibrary.Update.GetLastVersionAsync("https://dl.dropboxusercontent.com/s/j3fn78x3lcmowpr/Version.txt")
End Sub

Go to top