Added error reporting to Update Checker; Fixed update checking failure in certain setups

This commit is contained in:
ZZYZX 2019-12-24 23:32:37 +02:00
parent fb925016ae
commit d559ba30d7
3 changed files with 107 additions and 101 deletions

View file

@ -58,121 +58,128 @@ namespace CodeImp.DoomBuilder
worker.RunWorkerCompleted += RunWorkerCompleted; worker.RunWorkerCompleted += RunWorkerCompleted;
worker.WorkerSupportsCancellation = true; worker.WorkerSupportsCancellation = true;
worker.RunWorkerAsync(); worker.RunWorkerAsync();
} }
private static void DoWork(object sender, DoWorkEventArgs e) private static void DoWork(object sender, DoWorkEventArgs e)
{ {
string updaterpath = Path.Combine(General.AppPath, "Updater.exe"); try
if(!File.Exists(updaterpath)) {
{ string updaterpath = Path.Combine(General.AppPath, "Updater.exe");
ShowResult("Update check failed: \"" + updaterpath + "\" does not exist!"); if (!File.Exists(updaterpath))
e.Cancel = true; {
return; 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;
}
// Get some ini values... string inipath = Path.Combine(General.AppPath, "Updater.ini");
string url = string.Empty; if (!File.Exists(inipath))
string updaterpackname = string.Empty; {
string[] inilines = File.ReadAllLines(inipath); ShowResult("Update check failed: \"" + inipath + "\" does not exist!");
foreach(string line in inilines) e.Cancel = true;
{ return;
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(url)) // Get some ini values...
{ string url = string.Empty;
ShowResult("Update check failed: failed to get update url from Updater.ini!"); string updaterpackname = string.Empty;
e.Cancel = true; string[] inilines = File.ReadAllLines(inipath);
return; 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)) if (string.IsNullOrEmpty(url))
{ {
ShowResult("Update check failed: failed to get updater pack name from Updater.ini!"); ShowResult("Update check failed: failed to get update url from Updater.ini!");
e.Cancel = true; e.Cancel = true;
return; return;
} }
// Get local revision number if (string.IsNullOrEmpty(updaterpackname))
int localrev = General.ThisAssembly.GetName().Version.Revision; {
int actuallocalrev = localrev; ShowResult("Update check failed: failed to get updater pack name from Updater.ini!");
if(!verbose) localrev = Math.Max(localrev, General.Settings.IgnoredRemoteRevision); e.Cancel = true;
return;
}
// Get remote revision numbers // Get local revision number
int remoterev, remoteupdaterrev; int localrev = General.ThisAssembly.GetName().Version.Revision;
MemoryStream stream = DownloadWebFile(Path.Combine(url, "Versions.txt")); int actuallocalrev = localrev;
if(stream == null) if (!verbose) localrev = Math.Max(localrev, General.Settings.IgnoredRemoteRevision);
{
ShowResult("Update check failed: failed to retrieve remote revision info.\nCheck your Internet connection and try again.");
e.Cancel = true;
return;
}
List<string> lines = new List<string>(2); // Get remote revision numbers
using(StreamReader reader = new StreamReader(stream)) int remoterev, remoteupdaterrev;
{ MemoryStream stream = DownloadWebFile(Path.Combine(url, "Versions.txt"));
while(!reader.EndOfStream) lines.Add(reader.ReadLine()); 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) List<string> lines = new List<string>(2);
{ using (StreamReader reader = new StreamReader(stream))
ShowResult("Update check failed: invalid remote revision number."); {
e.Cancel = true; while (!reader.EndOfStream) lines.Add(reader.ReadLine());
return; }
}
if(!int.TryParse(lines[0], out remoterev)) if (lines.Count != 2)
{ {
ShowResult("Update check failed: failed to retrieve remote revision number."); ShowResult("Update check failed: invalid remote revision number.");
e.Cancel = true; e.Cancel = true;
return; return;
} }
if(!int.TryParse(lines[1], out remoteupdaterrev)) if (!int.TryParse(lines[0], out remoterev))
{ {
ShowResult("Update check failed: failed to retrieve remote updater revision number."); ShowResult("Update check failed: failed to retrieve remote revision number.");
e.Cancel = true; e.Cancel = true;
return; return;
} }
// Update the updater! if (!int.TryParse(lines[1], out remoteupdaterrev))
string result = UpdateUpdater(url, updaterpackname, remoteupdaterrev); {
if(!string.IsNullOrEmpty(result)) ShowResult("Update check failed: failed to retrieve remote updater revision number.");
{ e.Cancel = true;
ShowResult("Update check failed: " + result); return;
e.Cancel = true; }
return;
}
if(remoterev > localrev) // Update the updater!
{ string result = UpdateUpdater(url, updaterpackname, remoteupdaterrev);
// Get changelog info if (!string.IsNullOrEmpty(result))
string changelog = GetChangelog(url, actuallocalrev); {
ShowResult("Update check failed: " + result);
e.Cancel = true;
return;
}
if(string.IsNullOrEmpty(changelog)) if (remoterev > localrev)
{ {
ShowResult("Update check failed: failed to retrieve changelog.\nCheck your Internet connection and try again."); // Get changelog info
e.Cancel = true; string changelog = GetChangelog(url, actuallocalrev);
return;
}
// Pass data to MainForm if (string.IsNullOrEmpty(changelog))
General.MainWindow.UpdateAvailable(remoterev, changelog); {
} ShowResult("Update check failed: failed to retrieve changelog.\nCheck your Internet connection and try again.");
else if(verbose) e.Cancel = true;
{ return;
ShowResult(NO_UPDATE_REQUIRED); }
}
// 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) private static string UpdateUpdater(string url, string updaterpackname, int remoterev)

View file

@ -3164,7 +3164,7 @@ namespace CodeImp.DoomBuilder.Windows
//mxd. Check updates clicked //mxd. Check updates clicked
private void itemhelpcheckupdates_Click(object sender, EventArgs e) private void itemhelpcheckupdates_Click(object sender, EventArgs e)
{ {
UpdateChecker.PerformCheck(true); UpdateChecker.PerformCheck(true);
} }
//mxd. Github issues clicked //mxd. Github issues clicked

View file

@ -6,5 +6,4 @@
<runtime> <runtime>
<loadFromRemoteSources enabled="true"/> <loadFromRemoteSources enabled="true"/>
</runtime> </runtime>
<dllmap dll="devil.dll" target="libIL.so.1" os="linux" />
</configuration> </configuration>