/// <summary> /// Check if a new version is available on github. If it is download it. /// </summary> /// <param name="user">github user name</param> /// <param name="repository">github repository name</param> /// <param name="currentVersion">Version to compare against</param> /// <param name="destinationFile">destination name of the update file</param> /// <param name="logger">An optional logger.</param> /// <returns><see langword="true"/> if a new version is available, otherwise <see langword="false"/></returns> public static async Task <bool> CheckDownloadNewVersionAsync(string user, string repository, Version currentVersion, string destinationFile, Logger logger = null) { return(await Task.Run(async() => { if (logger is null) { logger = new Logger(Path.ChangeExtension(destinationFile, ".log")); } var gitHub = new GitHubApi(); try { var latestReleaseJson = await gitHub.GetLatestReleaseJSONAsync(user, repository); var version = GitHubApi.ParseVersion(latestReleaseJson); logger.Log($"Comparing {currentVersion} with latest version on github {version}"); if (version > currentVersion) { var updateUrl = GitHubApi.ParseDownloadUrl(latestReleaseJson); //new version download await gitHub.DownloadFileAsync(updateUrl, destinationFile); return true; } return false; } catch (Exception e) { logger.Log(e.Message); return false; } })); }
private static async Task <string> DownloadInstallerAsync(this GitHubApi gitHub, string destination) { var latestReleaseJson = await gitHub.GetLatestReleaseJSONAsync(user, repo); var urlInstaller = GitHubApi.ParseDownloadUrl(latestReleaseJson); var installerFileName = Path.Combine(destination, Path.GetFileName(urlInstaller)); await gitHub.DownloadFileAsync(urlInstaller, installerFileName); return(installerFileName); }