UpdateManager class
Namespace: Velopack
Provides functionality for checking for updates, downloading updates, and applying updates to the current application.
public class UpdateManager
Constructors
| Constructor | Summary |
|---|---|
UpdateManager | Creates a new UpdateManager instance using the specified URL or file path to the releases feed, and the specified channel name. |
UpdateManager | Creates 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
| Name | Type | Description |
|---|---|---|
urlOrPath | string | A basic URL or file path to use when checking for updates. |
options | UpdateOptions | Override / configure default update behaviors. |
locator | IVelopackLocator | This 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
| Name | Type | Description |
|---|---|---|
source | IUpdateSource | The 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). |
options | UpdateOptions | Override / configure default update behaviors. |
locator | IVelopackLocator | This 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
| Property | Summary |
|---|---|
AppId | The currently installed application Id. This would be what you set when you create your release. |
IsInstalled | True if this application is currently installed, and is able to download/check for updates. |
IsPortable | A flag indicating if this is a portable build, and that the settings should be self-contained in the package. |
UpdatePendingRestart | Returns a VelopackAsset if there is a local update prepared that requires a call to ApplyUpdatesAndRestart to be applied. |
CurrentVersion | The currently installed app version when you created your release. Null if this is not a currently installed app. |
Source | The update source to use when checking for/downloading updates. |
Log | The logger to use for diagnostic messages. |
Locator | The locator to use when searching for local file paths. |
Channel | The channel to use when searching for packages. |
DefaultChannel | The default channel to search for packages in, if one was not provided by the user. |
IsNonDefaultChannel | If true, an explicit channel was provided by the user, and it's different than the default channel. |
ShouldAllowVersionDowngrade | If true, UpdateManager should return the latest asset in the feed, even if that version is lower than the current version. |
MaximumDeltasBeforeFallback | The 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
| Method | Summary |
|---|---|
CheckForUpdates | Checks for updates, returning null if there are none available. If there are updates available, this method will return an |
CheckForUpdatesAsync | Checks for updates, returning null if there are none available. If there are updates available, this method will return an |
CreateDeltaUpdateStrategy | Given a feed of releases, and the latest local full release, and the latest remote full release, this method will return a delta |
DownloadUpdates | Downloads the specified updates to the local app packages directory. If the update contains delta packages and ignoreDeltas=false, |
DownloadUpdatesAsync | Downloads the specified updates to the local app packages directory. If the update contains delta packages and ignoreDeltas=false, |
ApplyUpdatesAndRestart | This will exit your app immediately, apply updates, and then optionally relaunch the app using the specified |
ApplyUpdatesAndExit | This will exit your app immediately, apply updates, and then optionally relaunch the app using the specified |
WaitExitThenApplyUpdates | This will launch the Velopack updater and tell it to wait for this program to exit gracefully. |
DownloadAndApplyDeltaUpdates | Given a folder containing the extracted base package, and a list of delta updates, downloads and applies the |
CleanPackagesExcept | Removes any incomplete files (.partial) and packages (.nupkg) from the packages directory that does not match |
VerifyPackageChecksumAsync | Check a package checksum against the one in the release entry, and throws if the checksum does not match. |
EnsureInstalled | Throws an exception if the current application is not installed. |
AcquireUpdateLock | Acquires 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
| Name | Type | Description |
|---|---|---|
feed | VelopackAsset[] | |
latestLocalFull | VelopackAsset | |
latestRemoteFull | VelopackAsset |
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
| Name | Type | Description |
|---|---|---|
updates | UpdateInfo | The updates to download. Should be retrieved from CheckForUpdates(). |
progress | Action<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
| Name | Type | Description |
|---|---|---|
updates | UpdateInfo | The updates to download. Should be retrieved from CheckForUpdates(). |
progress | Action<int> | The progress callback. Will be called with values from 0-100. |
cancelToken | CancellationToken | An 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
| Name | Type | Description |
|---|---|---|
toApply | VelopackAsset | The target release to apply. Can be left null to auto-apply the newest downloaded release. |
restartArgs | string[] | 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
| Name | Type | Description |
|---|---|---|
toApply | VelopackAsset | The 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
| Name | Type | Description |
|---|---|---|
toApply | VelopackAsset | The target release to apply. Can be left null to auto-apply the newest downloaded release. |
silent | bool | Configure whether Velopack should show a progress window / dialogs during the updates or not. |
restart | bool | Configure whether Velopack should restart the app after the updates have been applied. |
restartArgs | string[] | 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
| Name | Type | Description |
|---|---|---|
updates | UpdateInfo | An update object containing one or more delta's |
targetFile | string | The reconstructed full update after all delta's are applied |
progress | Action<int> | A callback reporting process of delta application progress (from 0-100). |
cancelToken | CancellationToken | A 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
| Name | Type | Description |
|---|---|---|
assetToKeep | string |
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
| Name | Type | Description |
|---|---|---|
release | VelopackAsset | The entry to check |
filePathOverride | string | Optional 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