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

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

View file

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