Saltar al contenido principal

UpdateManager class

Namespace: Velopack

Provides functionality for checking for updates, downloading updates, and applying updates to the current application.

public class UpdateManager

Constructors

ConstructorSummary
UpdateManagerCreates a new UpdateManager instance using the specified URL or file path to the releases feed, and the specified channel name.
UpdateManagerCreates a new UpdateManager instance using the specified URL or file path to the releases feed, and the specified channel name.

UpdateManager(urlOrPath, options, locator)

public UpdateManager(string urlOrPath, UpdateOptions? options = null, IVelopackLocator? locator = null)

Creates a new UpdateManager instance using the specified URL or file path to the releases feed, and the specified channel name.

Parameters

NameTypeDescription
urlOrPathstringA basic URL or file path to use when checking for updates.
optionsUpdateOptionsOverride / configure default update behaviors.
locatorIVelopackLocatorThis should usually be left null. Providing an IVelopackLocator allows you to mock up certain application paths.
For example, if you wanted to test that updates are working in a unit test, you could provide an instance of TestVelopackLocator.

UpdateManager(source, options, locator)

public UpdateManager(IUpdateSource source, UpdateOptions? options = null, IVelopackLocator? locator = null)

Creates a new UpdateManager instance using the specified URL or file path to the releases feed, and the specified channel name.

Parameters

NameTypeDescription
sourceIUpdateSourceThe source describing where to search for updates. This can be a custom source, if you are integrating with some private resource,
or it could be one of the predefined sources. (eg. SimpleWebSource or GithubSource, etc).
optionsUpdateOptionsOverride / configure default update behaviors.
locatorIVelopackLocatorThis should usually be left null. Providing an IVelopackLocator allows you to mock up certain application paths.
For example, if you wanted to test that updates are working in a unit test, you could provide an instance of TestVelopackLocator.

Properties

PropertySummary
AppIdThe currently installed application Id. This would be what you set when you create your release.
IsInstalledTrue if this application is currently installed, and is able to download/check for updates.
IsPortableA flag indicating if this is a portable build, and that the settings should be self-contained in the package.
UpdatePendingRestartReturns a VelopackAsset if there is a local update prepared that requires a call to ApplyUpdatesAndRestart to be applied.
CurrentVersionThe currently installed app version when you created your release. Null if this is not a currently installed app.
SourceThe update source to use when checking for/downloading updates.
LogThe logger to use for diagnostic messages.
LocatorThe locator to use when searching for local file paths.
ChannelThe channel to use when searching for packages.
DefaultChannelThe default channel to search for packages in, if one was not provided by the user.
IsNonDefaultChannelIf true, an explicit channel was provided by the user, and it's different than the default channel.
ShouldAllowVersionDowngradeIf true, UpdateManager should return the latest asset in the feed, even if that version is lower than the current version.
MaximumDeltasBeforeFallbackThe maximum number of deltas to consider before falling back to a full update.

AppId

public virtual string? AppId { get; }

The currently installed application Id. This would be what you set when you create your release.

IsInstalled

public virtual bool IsInstalled { get; }

True if this application is currently installed, and is able to download/check for updates.

IsPortable

public virtual bool IsPortable { get; }

A flag indicating if this is a portable build, and that the settings should be self-contained in the package. On Windows, this is true for portable builds, and false for non-portable builds which were installed by Setup.exe On OSX and Linux, this is always false, because settings and application files should be stored in the user's home directory.

UpdatePendingRestart

public virtual VelopackAsset? UpdatePendingRestart { get; }

Returns a VelopackAsset if there is a local update prepared that requires a call to ApplyUpdatesAndRestart to be applied.

CurrentVersion

public virtual SemanticVersion? CurrentVersion { get; }

The currently installed app version when you created your release. Null if this is not a currently installed app.

Source

protected IUpdateSource Source { get; }

The update source to use when checking for/downloading updates.

Log

protected IVelopackLogger Log { get; }

The logger to use for diagnostic messages.

Locator

protected IVelopackLocator Locator { get; }

The locator to use when searching for local file paths.

Channel

protected string Channel { get; }

The channel to use when searching for packages.

DefaultChannel

protected string DefaultChannel { get; }

The default channel to search for packages in, if one was not provided by the user.

IsNonDefaultChannel

protected bool IsNonDefaultChannel { get; }

If true, an explicit channel was provided by the user, and it's different than the default channel.

ShouldAllowVersionDowngrade

protected bool ShouldAllowVersionDowngrade { get; }

If true, UpdateManager should return the latest asset in the feed, even if that version is lower than the current version.

MaximumDeltasBeforeFallback

protected int MaximumDeltasBeforeFallback { get; }

The maximum number of deltas to consider before falling back to a full update.

Methods

MethodSummary
CheckForUpdatesChecks for updates, returning null if there are none available. If there are updates available, this method will return an
CheckForUpdatesAsyncChecks for updates, returning null if there are none available. If there are updates available, this method will return an
CreateDeltaUpdateStrategyGiven a feed of releases, and the latest local full release, and the latest remote full release, this method will return a delta
DownloadUpdatesDownloads the specified updates to the local app packages directory. If the update contains delta packages and ignoreDeltas=false,
DownloadUpdatesAsyncDownloads the specified updates to the local app packages directory. If the update contains delta packages and ignoreDeltas=false,
ApplyUpdatesAndRestartThis will exit your app immediately, apply updates, and then optionally relaunch the app using the specified
ApplyUpdatesAndExitThis will exit your app immediately, apply updates, and then optionally relaunch the app using the specified
WaitExitThenApplyUpdatesThis will launch the Velopack updater and tell it to wait for this program to exit gracefully.
DownloadAndApplyDeltaUpdatesGiven a folder containing the extracted base package, and a list of delta updates, downloads and applies the
CleanPackagesExceptRemoves any incomplete files (.partial) and packages (.nupkg) from the packages directory that does not match
VerifyPackageChecksumAsyncCheck a package checksum against the one in the release entry, and throws if the checksum does not match.
EnsureInstalledThrows an exception if the current application is not installed.
AcquireUpdateLockAcquires a globally unique mutex/lock for the current application, to avoid concurrent install/uninstall/update operations.

CheckForUpdates()

public UpdateInfo? CheckForUpdates()

Checks for updates, returning null if there are none available. If there are updates available, this method will return an UpdateInfo object containing the latest available release, and any delta updates that can be applied if they are available.

Returns UpdateInfo — Null if no updates, otherwise UpdateInfo containing the version of the latest update available.

CheckForUpdatesAsync()

public virtual Task<UpdateInfo?> CheckForUpdatesAsync()

Checks for updates, returning null if there are none available. If there are updates available, this method will return an UpdateInfo object containing the latest available release, and any delta updates that can be applied if they are available.

Returns Task<UpdateInfo> — Null if no updates, otherwise UpdateInfo containing the version of the latest update available.

CreateDeltaUpdateStrategy(feed, latestLocalFull, latestRemoteFull)

protected virtual UpdateInfo CreateDeltaUpdateStrategy(VelopackAsset[] feed, VelopackAsset? latestLocalFull, VelopackAsset latestRemoteFull)

Given a feed of releases, and the latest local full release, and the latest remote full release, this method will return a delta update strategy to be used by DownloadUpdatesAsync.

Parameters

NameTypeDescription
feedVelopackAsset[]
latestLocalFullVelopackAsset
latestRemoteFullVelopackAsset

Returns UpdateInfo

DownloadUpdates(updates, progress)

public void DownloadUpdates(UpdateInfo updates, Action<int>? progress = null)

Downloads the specified updates to the local app packages directory. If the update contains delta packages and ignoreDeltas=false, this method will attempt to unpack and prepare them. If there is no delta update available, or there is an error preparing delta packages, this method will fall back to downloading the full version of the update. This function will acquire a global update lock so may fail if there is already another update operation in progress.

Parameters

NameTypeDescription
updatesUpdateInfoThe updates to download. Should be retrieved from CheckForUpdates().
progressAction<int>The progress callback. Will be called with values from 0-100.

DownloadUpdatesAsync(updates, progress, cancelToken)

public virtual Task DownloadUpdatesAsync(UpdateInfo updates, Action<int>? progress = null, CancellationToken cancelToken = default)

Downloads the specified updates to the local app packages directory. If the update contains delta packages and ignoreDeltas=false, this method will attempt to unpack and prepare them. If there is no delta update available, or there is an error preparing delta packages, this method will fall back to downloading the full version of the update. This function will acquire a global update lock so may fail if there is already another update operation in progress.

Parameters

NameTypeDescription
updatesUpdateInfoThe updates to download. Should be retrieved from CheckForUpdates().
progressAction<int>The progress callback. Will be called with values from 0-100.
cancelTokenCancellationTokenAn optional cancellation token if you wish to stop this operation.

Returns Task

ApplyUpdatesAndRestart(toApply, restartArgs)

public void ApplyUpdatesAndRestart(VelopackAsset? toApply, string[]? restartArgs = null)

This will exit your app immediately, apply updates, and then optionally relaunch the app using the specified restart arguments. If you need to save state or clean up, you should do that before calling this method. The user may be prompted during the update, if the update requires additional frameworks to be installed etc. You can check if there are pending updates by checking UpdatePendingRestart.

Parameters

NameTypeDescription
toApplyVelopackAssetThe target release to apply. Can be left null to auto-apply the newest downloaded release.
restartArgsstring[]The arguments to pass to the application when it is restarted.

ApplyUpdatesAndExit(toApply)

public void ApplyUpdatesAndExit(VelopackAsset? toApply)

This will exit your app immediately, apply updates, and then optionally relaunch the app using the specified restart arguments. If you need to save state or clean up, you should do that before calling this method. The user may be prompted during the update, if the update requires additional frameworks to be installed etc. You can check if there are pending updates by checking UpdatePendingRestart.

Parameters

NameTypeDescription
toApplyVelopackAssetThe target release to apply. Can be left null to auto-apply the newest downloaded release.

WaitExitThenApplyUpdates(toApply, silent, restart, restartArgs)

public void WaitExitThenApplyUpdates(VelopackAsset? toApply, bool silent = false, bool restart = true, string[]? restartArgs = null)

This will launch the Velopack updater and tell it to wait for this program to exit gracefully. You should then clean up any state and exit your app. The updater will apply updates and then optionally restart your app. The updater will only wait for 60 seconds before giving up. You can check if there are pending updates by checking UpdatePendingRestart.

Parameters

NameTypeDescription
toApplyVelopackAssetThe target release to apply. Can be left null to auto-apply the newest downloaded release.
silentboolConfigure whether Velopack should show a progress window / dialogs during the updates or not.
restartboolConfigure whether Velopack should restart the app after the updates have been applied.
restartArgsstring[]The arguments to pass to the application when it is restarted.

DownloadAndApplyDeltaUpdates(updates, targetFile, progress, cancelToken)

protected virtual Task DownloadAndApplyDeltaUpdates(UpdateInfo updates, string targetFile, Action<int> progress, CancellationToken cancelToken)

Given a folder containing the extracted base package, and a list of delta updates, downloads and applies the delta updates to the base package.

Parameters

NameTypeDescription
updatesUpdateInfoAn update object containing one or more delta's
targetFilestringThe reconstructed full update after all delta's are applied
progressAction<int>A callback reporting process of delta application progress (from 0-100).
cancelTokenCancellationTokenA token to use to cancel the request.

Returns Task

CleanPackagesExcept(assetToKeep)

protected virtual void CleanPackagesExcept(string? assetToKeep)

Removes any incomplete files (.partial) and packages (.nupkg) from the packages directory that does not match the provided asset. If assetToKeep is null, all packages will be deleted.

Parameters

NameTypeDescription
assetToKeepstring

VerifyPackageChecksumAsync(release, filePathOverride)

protected virtual Task VerifyPackageChecksumAsync(VelopackAsset release, string? filePathOverride = null)

Check a package checksum against the one in the release entry, and throws if the checksum does not match.

Parameters

NameTypeDescription
releaseVelopackAssetThe entry to check
filePathOverridestringOptional file path, if not specified the package will be loaded from %pkgdir%/release.OriginalFilename.

Returns Task

EnsureInstalled()

protected virtual void EnsureInstalled()

Throws an exception if the current application is not installed.

AcquireUpdateLock()

protected virtual Task<IDisposable> AcquireUpdateLock()

Acquires a globally unique mutex/lock for the current application, to avoid concurrent install/uninstall/update operations.

Returns Task<IDisposable>


Generated from Velopack 1.1.1