Skip to content
Jacob edited this page Sep 1, 2023 · 2 revisions

Setup

Update-Checker requires its own function to run all the operations in. You can have as many of these functions as you want but they cannot be called the same thing for clear reasons.

At the top of you class file include the Update-Checker.

using Update_Checker;

Create a new method which can run the Update Checker methods. In the method create a instance of the UpdateChecker class. This method cannot return any information and must be ran async from the main program. Change the method's name to something more appropriate for what the class is doing.

public static async void doStuff()
{
    // Create a instance of the UpdateChecker class
    UpdateChecker checker = new UpdateChecker();
}

Checking for updates

In the UpdateChecker function we can call the different functions.

First we need to setup the repo which UpdateChecker will be accessing. Change the OWNERNAME to your github username, then set REPONAME to the name of repo you are trying to get the current version of

checker.OWNERNAME = "ChobbyCode";
checker.REPONAME = "Update-Checker";

We can quickly get to see if there is a update by using the method CheckForUpdates and passing in the current version. The CheckForUpdates method returns a bool which returns true if there is an update and false if there is not

IMPORTANT: When calling a UpdateChecker method make sure it is awaited. i.e "await checker.LatestUpdateTag".

// Checks for updates
string currentVersion = "v0.1.0"
bool isUpdate = await checker.CheckForUpdates(currentVersion); // Checks for update with current version and stores in variable

if(isUpdate){
    // Do update stuff here
}

If you want to reduce the amount of lines you can do as below. Both of the code snippets do the same thing.

if(await checker.CheckForUpdates("v0.1.0")){
    // Do update stuff here
}

All In One

using Update_Checker;

namespace TestProgram
{

    public class Program
    {
        public static void Main(string[] args)
        {
            doStuff();
            Console.ReadLine();
        }

        public static async void doStuff()
        {
            // Create a instance of the UpdateChecker class
            UpdateChecker checker = new UpdateChecker();

            checker.OWNERNAME = "ChobbyCode";
            checker.REPONAME = "Update-Checker";

            if (await checker.CheckForUpdates("v0.1.0"))
            {
                // Do update stuff here
            }
        }
    }
}

Clone this wiki locally