diff --git a/Source/Core/General/UpdateChecker.cs b/Source/Core/General/UpdateChecker.cs index d54a47f7..8312c3ce 100755 --- a/Source/Core/General/UpdateChecker.cs +++ b/Source/Core/General/UpdateChecker.cs @@ -58,121 +58,128 @@ namespace CodeImp.DoomBuilder worker.RunWorkerCompleted += RunWorkerCompleted; worker.WorkerSupportsCancellation = true; worker.RunWorkerAsync(); - } + } private static void DoWork(object sender, DoWorkEventArgs e) { - string updaterpath = Path.Combine(General.AppPath, "Updater.exe"); - if(!File.Exists(updaterpath)) - { - ShowResult("Update check failed: \"" + updaterpath + "\" does not exist!"); - e.Cancel = true; - return; - } - - string inipath = Path.Combine(General.AppPath, "Updater.ini"); - if(!File.Exists(inipath)) - { - ShowResult("Update check failed: \"" + inipath + "\" does not exist!"); - e.Cancel = true; - return; - } + try + { + string updaterpath = Path.Combine(General.AppPath, "Updater.exe"); + if (!File.Exists(updaterpath)) + { + ShowResult("Update check failed: \"" + updaterpath + "\" does not exist!"); + e.Cancel = true; + return; + } - // Get some ini values... - string url = string.Empty; - string updaterpackname = string.Empty; - string[] inilines = File.ReadAllLines(inipath); - foreach(string line in inilines) - { - string cplatform = (Environment.Is64BitProcess ? "x64" : "x86"); - if(line.StartsWith("URL")) url = line.Substring(3).Trim(); - else if(line.StartsWith("UpdaterName")) updaterpackname = line.Substring(11).Trim().Replace("[PLATFORM]", cplatform); - } + string inipath = Path.Combine(General.AppPath, "Updater.ini"); + if (!File.Exists(inipath)) + { + ShowResult("Update check failed: \"" + inipath + "\" does not exist!"); + e.Cancel = true; + return; + } - if(string.IsNullOrEmpty(url)) - { - ShowResult("Update check failed: failed to get update url from Updater.ini!"); - e.Cancel = true; - return; - } + // Get some ini values... + string url = string.Empty; + string updaterpackname = string.Empty; + string[] inilines = File.ReadAllLines(inipath); + foreach (string line in inilines) + { + string cplatform = (Environment.Is64BitProcess ? "x64" : "x86"); + if (line.StartsWith("URL")) url = line.Substring(3).Trim(); + else if (line.StartsWith("UpdaterName")) updaterpackname = line.Substring(11).Trim().Replace("[PLATFORM]", cplatform); + } - if(string.IsNullOrEmpty(updaterpackname)) - { - ShowResult("Update check failed: failed to get updater pack name from Updater.ini!"); - e.Cancel = true; - return; - } + if (string.IsNullOrEmpty(url)) + { + ShowResult("Update check failed: failed to get update url from Updater.ini!"); + e.Cancel = true; + return; + } - // Get local revision number - int localrev = General.ThisAssembly.GetName().Version.Revision; - int actuallocalrev = localrev; - if(!verbose) localrev = Math.Max(localrev, General.Settings.IgnoredRemoteRevision); + if (string.IsNullOrEmpty(updaterpackname)) + { + ShowResult("Update check failed: failed to get updater pack name from Updater.ini!"); + e.Cancel = true; + return; + } - // Get remote revision numbers - int remoterev, remoteupdaterrev; - MemoryStream stream = DownloadWebFile(Path.Combine(url, "Versions.txt")); - if(stream == null) - { - ShowResult("Update check failed: failed to retrieve remote revision info.\nCheck your Internet connection and try again."); - e.Cancel = true; - return; - } + // Get local revision number + int localrev = General.ThisAssembly.GetName().Version.Revision; + int actuallocalrev = localrev; + if (!verbose) localrev = Math.Max(localrev, General.Settings.IgnoredRemoteRevision); - List lines = new List(2); - using(StreamReader reader = new StreamReader(stream)) - { - while(!reader.EndOfStream) lines.Add(reader.ReadLine()); - } + // Get remote revision numbers + int remoterev, remoteupdaterrev; + MemoryStream stream = DownloadWebFile(Path.Combine(url, "Versions.txt")); + if (stream == null) + { + ShowResult("Update check failed: failed to retrieve remote revision info.\nCheck your Internet connection and try again."); + e.Cancel = true; + return; + } - if(lines.Count != 2) - { - ShowResult("Update check failed: invalid remote revision number."); - e.Cancel = true; - return; - } + List lines = new List(2); + using (StreamReader reader = new StreamReader(stream)) + { + while (!reader.EndOfStream) lines.Add(reader.ReadLine()); + } - if(!int.TryParse(lines[0], out remoterev)) - { - ShowResult("Update check failed: failed to retrieve remote revision number."); - e.Cancel = true; - return; - } + if (lines.Count != 2) + { + ShowResult("Update check failed: invalid remote revision number."); + e.Cancel = true; + return; + } - if(!int.TryParse(lines[1], out remoteupdaterrev)) - { - ShowResult("Update check failed: failed to retrieve remote updater revision number."); - e.Cancel = true; - return; - } + if (!int.TryParse(lines[0], out remoterev)) + { + ShowResult("Update check failed: failed to retrieve remote revision number."); + e.Cancel = true; + return; + } - // Update the updater! - string result = UpdateUpdater(url, updaterpackname, remoteupdaterrev); - if(!string.IsNullOrEmpty(result)) - { - ShowResult("Update check failed: " + result); - e.Cancel = true; - return; - } + if (!int.TryParse(lines[1], out remoteupdaterrev)) + { + ShowResult("Update check failed: failed to retrieve remote updater revision number."); + e.Cancel = true; + return; + } - if(remoterev > localrev) - { - // Get changelog info - string changelog = GetChangelog(url, actuallocalrev); + // Update the updater! + string result = UpdateUpdater(url, updaterpackname, remoteupdaterrev); + if (!string.IsNullOrEmpty(result)) + { + ShowResult("Update check failed: " + result); + e.Cancel = true; + return; + } - if(string.IsNullOrEmpty(changelog)) - { - ShowResult("Update check failed: failed to retrieve changelog.\nCheck your Internet connection and try again."); - e.Cancel = true; - return; - } + if (remoterev > localrev) + { + // Get changelog info + string changelog = GetChangelog(url, actuallocalrev); - // Pass data to MainForm - General.MainWindow.UpdateAvailable(remoterev, changelog); - } - else if(verbose) - { - ShowResult(NO_UPDATE_REQUIRED); - } + if (string.IsNullOrEmpty(changelog)) + { + ShowResult("Update check failed: failed to retrieve changelog.\nCheck your Internet connection and try again."); + e.Cancel = true; + return; + } + + // Pass data to MainForm + General.MainWindow.UpdateAvailable(remoterev, changelog); + } + else if (verbose) + { + ShowResult(NO_UPDATE_REQUIRED); + } + } + catch (Exception ex) + { + General.ErrorLogger.Add(ErrorType.Warning, string.Format("Update check failed:\n\n{0}", ex.ToString())); + } } private static string UpdateUpdater(string url, string updaterpackname, int remoterev) diff --git a/Source/Core/Windows/MainForm.cs b/Source/Core/Windows/MainForm.cs index 8a695789..c508c60e 100755 --- a/Source/Core/Windows/MainForm.cs +++ b/Source/Core/Windows/MainForm.cs @@ -3164,7 +3164,7 @@ namespace CodeImp.DoomBuilder.Windows //mxd. Check updates clicked private void itemhelpcheckupdates_Click(object sender, EventArgs e) { - UpdateChecker.PerformCheck(true); + UpdateChecker.PerformCheck(true); } //mxd. Github issues clicked diff --git a/Source/Core/app.config b/Source/Core/app.config index de20aa9a..d82da5de 100644 --- a/Source/Core/app.config +++ b/Source/Core/app.config @@ -6,5 +6,4 @@ -