private static GithubRelease GetNewestReleaseMono() { string outputFilePath = Application.StartupPath + @"/release.json"; GithubRelease rel = null; if (File.Exists(Application.StartupPath + "/release.json")) { File.Delete(Application.StartupPath + "/release.json"); } MonoHelper.DownloadFile( "https://api.github.com/repos/BlackDragonBE/MarkdownToRW_Converter/releases/latest", outputFilePath, "MarkdownToRW_Converter"); // Read json if (File.Exists(Application.StartupPath + "/release.json")) { var json = ""; using (StreamReader sr = new StreamReader(outputFilePath.Replace("\"", ""))) { json = sr.ReadToEnd(); } rel = JsonConvert.DeserializeObject <GithubRelease>(json); File.Delete(Application.StartupPath + "/release.json"); } return(rel); }
private static void StartAppUpdate(GithubRelease newestRelease) { // Copy updater.exe to folder above // Run updater.exe on folder above // Updater gets current folder & path to zip as arguments & starts // This app exists // Preparation Console.WriteLine("Downloading new release..."); string downloadUrl = ""; string downloadName = ""; foreach (GithubRelease.Asset asset in newestRelease.assets) { if (asset.name.Contains("GUI")) { downloadName = asset.name; downloadUrl = asset.browser_download_url; } } string zipPath = Directory.GetParent(Application.StartupPath) + "/" + downloadName; string newUpdaterPath = Directory.GetParent(Application.StartupPath) + "/RWUpdater.exe"; //Download update MonoHelper.DownloadFile(downloadUrl, zipPath, "MarkdownToRW_Converter"); // Copy updater to folder above if (File.Exists(newUpdaterPath)) { File.Delete(newUpdaterPath); } File.Copy(Application.StartupPath + "/RWUpdater.exe", newUpdaterPath); File.Copy(Application.StartupPath + "/DotNetZip.dll", Directory.GetParent(Application.StartupPath) + "/DotNetZip.dll"); // Run updater & quit Process.Start(newUpdaterPath, DragonUtil.SurroundWithQuotes(Application.StartupPath) + " " + DragonUtil.SurroundWithQuotes(zipPath)); Environment.Exit(0); }
private static GithubRelease GetNewestRelease() { GithubRelease release = null; try { var http = new HttpClient(); http.Request.UserAgent = "MarkdownToRW_Converter"; http.Request.Accept = HttpContentTypes.ApplicationJson; var response = http.Get(RELEASE_URL); release = response.StaticBody <GithubRelease>(); } catch (Exception e) { Console.WriteLine("Update check failed:\n" + e); } return(release); }
public static void CheckForUpdates() { _thisVersion = DragonVersion.VERSION; Console.WriteLine("Checking for new version..."); GithubRelease newestRelease = null; if (!MonoHelper.IsRunningOnMono) //Regular Windows { newestRelease = GetNewestRelease(); } else { newestRelease = GetNewestReleaseMono(); } if (newestRelease != null) { var githubNewestVersion = Convert.ToDecimal(newestRelease.tag_name); if (githubNewestVersion > _thisVersion) { if (MessageBox.Show( "New version available!\n" + newestRelease.name + " (Current: v" + _thisVersion + ")\n\nRelease notes:\n" + newestRelease.body + "\n\nClick yes to download and install new release. ", "Update to " + newestRelease.name, MessageBoxButtons.YesNo) == DialogResult.Yes ) { StartAppUpdate(newestRelease); } } else { Console.WriteLine("Application is up to date!"); } } else { Console.WriteLine("Couldn't download release info."); } }