Skip to content
This repository was archived by the owner on Dec 22, 2019. It is now read-only.

Updater

Matthias Beerens edited this page May 25, 2017 · 3 revisions

Overview

This is the actual Updater class. This class will allow you to easily add updating on your client machine with minimal configuration.

API

// Client side updater logic
public sealed class Updater
{
    // Gets a thread-safe instance of the updater
    public static Updater Instance { get; }

    // Fires whenever a check for update ended both success and failure
    public event EventHandler<CheckForUpdatesCompletedEventArgs> CheckForUpdatesCompleted;

    // Url to check for updates from
    public string UpdateURL { get; set; }

    // Specify the client installation mode
    public InstallationMode InstallationMode { get; set; } 

    // Indicate if we want to start updating as soon as the updater gets initialized
    public bool StartUpdating { get; set; }

    // Indicate if we want to update with or without GUI
    public bool UpdateSilently { get; set; } 

    // The command line argument to use for the silent switch
    public string UpdateSilentlyCmdArg { get; set; }

    // The command line argument to use for the update switch
    public string StartUpdatingCmdArg { get; set; }

    // The command line argument to use for the wait switch
    public string WaitForProcessCmdArg { get; set; }

    // Indicate if we want to wait for the specified pid to end before starting the application
    public bool WaitForProcessExit { get; set; }

    // Used to specify custom path variables that can be used in the update file
    public PathVariableConverter Converter { get; private set; }

    // Indicate if we want to allow unsafe connections (HTTP)
    public bool AllowUnsafeConnection { get; set; }

    // Gets the current clean up task
    public CleanUpTask CleanUpTask { get; private set; }

    // Gets the current cache update task
    public UpdateCacheTask UpdateCacheTask { get; private set; }
    
    // Gets the current hash cache file. 
    public HashCacheFile GetCache();

    // Indicate if the updater is already initialized
    public bool IsInitialized { get; private set; }

    // Fluent-API set unsafe connections propery
    public Updater ConfigureUnsafeConnections(bool allow);

    // Fluent-API set installation mode
    public Updater ConfigureInstallationMode(InstallationMode mode);

    // Fluent-API set silent switch argument
    public Updater ConfigureSilentCmdArg(string cmdArg);

    // Fluent-API set update switch argument
    public Updater ConfigureUpdateCmdArg(string cmdArg);

    // Fluent-API set wait switch argument
    public Updater ConfigureWaitForProcessCmdArg(string cmdArg);

    // Initialize the updater
    public void Initialize();

    // Check for updates synchronously
    public CheckForUpdatesTask.Data CheckForUpdates();
    public CheckForUpdatesTask.Data CheckForUpdates(IWin32Window owner);

    // Check for updates asynchronously
    public CheckForUpdatesTask CheckForUpdatesAsync();
    public CheckForUpdatesTask CheckForUpdatesAsync(IWin32Window owner);
}

Example Usage

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        // we still want our updater to have visual styles in case of update command argument switch
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        InitializeUpdater();

        Application.Run(new MyApplicationForm());
    }

    private static void InitializeUpdater()
    {
        Updater.Instance.UpdateURL = "http://matthiware.dev/UpdateLib/Dev/updatefile.xml";

        Updater.Instance
            .ConfigureUnsafeConnections(true)
            .ConfigureInstallationMode(InstallationMode.Shared)
            .Initialize();
    }
}
Clone this wiki locally