/// <summary> /// Returns a value indicating if a new update is available. /// </summary> /// <param name="url">The URL from which the update manifest can be downloaded.</param> /// <param name="xmlPublicKey">The public key formatted as an XML document.</param> /// <param name="currentVersion">The current version of the product.</param> /// <returns> /// <see langword="true" /> if a new version of the product is available; otherwise, <see langword="false" />. /// </returns> public UpdateInformation MostRecentUpdateOnRemoteServer(Uri url, string xmlPublicKey, Version currentVersion) { { Lokad.Enforce.Argument(() => url); Lokad.Enforce.Argument(() => xmlPublicKey); Lokad.Enforce.Argument(() => currentVersion); } UpdateInformation info; var manifestXml = HttpGetString(url); if (string.IsNullOrWhiteSpace(manifestXml)) { info = new UpdateInformation { LatestAvailableVersion = "0.0.0.0", UpdateIsAvailableAndValid = false }; return info; } // Create a new XML document. var xmlDoc = new XmlDocument { PreserveWhitespace = true }; // Load an XML file into the XmlDocument object. xmlDoc.LoadXml(manifestXml); // Verify the signature of the signed XML. var cryptoProvider = new RSACryptoServiceProvider(); cryptoProvider.FromXmlString(xmlPublicKey); if (!VerifyXml(xmlDoc, cryptoProvider)) { info = new UpdateInformation { LatestAvailableVersion = "0.0.0.0", UpdateIsAvailableAndValid = false }; return info; } var s = new XmlSerializer(typeof(UpdateInformation)); using (var sr = new StringReader(manifestXml)) { info = (UpdateInformation)s.Deserialize(new XmlTextReader(sr)); info.UpdateIsAvailableAndValid = new Version(info.LatestAvailableVersion) > currentVersion; } return info; }
/// <summary> /// Starts the download of the application update. /// </summary> /// <param name="information">The object that provides all the information about the new update.</param> /// <returns>A task that handles the download process and returns a file object pointing to the newly downloaded file.</returns> public Task<FileInfo> StartDownloadAsync(UpdateInformation information) { return Task<FileInfo>.Factory.StartNew(StartDownload, information, TaskCreationOptions.LongRunning); }
private async Task<FileInfo> DownloadUpdateAsync(UpdateInformation info) { return await m_Updater.StartDownloadAsync(info); }