/// <summary> /// Begins to download an update if one is available /// </summary> public void DownloadUpdate() { if (latestRelease is null) { DownloadingFailed?.Invoke(this, new ExceptionEventArgs <Exception>(new FileNotFoundException("There isn't any update available"), "There isn't any update available")); return; } if (File.Exists(downloadPath)) { File.Delete(downloadPath); } try { DownloadingStarted?.Invoke(this, new DownloadStartedEventArgs(latestVersion)); State = UpdaterState.Downloading; string fileUrl = latestRelease.Assets[0].BrowserDownloadUrl; string filePath = $@"{downloadPath}\{Path.GetFileName(fileUrl)}"; downloadFilePath = filePath; updateStartTime = DateTime.Now; webClient.DownloadFileAsync(new Uri(fileUrl), filePath); } catch (Exception e) { DownloadingFailed?.Invoke(this, new ExceptionEventArgs <Exception>(e, e.Message)); return; } }
/// <summary> /// Downloads the new EXE from github. /// </summary> /// <returns>Awaitable Task</returns> /// <exception cref="NullReferenceException">Thrown when the Repository is null</exception> /// <exception cref="FileLoadException">Thrown when the asset file is a .zip</exception> public async Task DownloadUpdateAsync() { DownloadingStarted?.Invoke(this, EventArgs.Empty); State = UpdaterState.Downloading; if (client == null) { client = new WebClient(); } if (repository == null) { throw new NullReferenceException("Could not retrieve Repository"); } if (repository.Assets[0].Name.EndsWith(".zip")) { throw new FileLoadException("The downloaded file is a zip file, which is not supported"); } string destination = Path.GetTempPath() + repository.Assets[0].Name; downloadedAssetPath = destination; client.DownloadProgressChanged += DownloadProgressChanged; await client.DownloadFileTaskAsync(repository.Assets[0].BrowserDownloadUrl, destination); State = UpdaterState.Idle; DownloadingCompleted?.Invoke(this, EventArgs.Empty); }