Add error reporting to the launcher

This reports errors to the user and exits the launcher but
ONLY if a previous version of WJ could not be found. Existing
users will fail silently and be unable to update. New users
will get some kind of error they can report to the team without
the launcher getting stuck.
This commit is contained in:
Chris Bessent 2021-03-09 05:31:45 -07:00
parent 8bd034afe5
commit 873cb51585

View File

@ -9,6 +9,7 @@ using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Wabbajack.Launcher.Annotations;
using System.Collections.Generic;
namespace Wabbajack.Launcher
{
@ -27,6 +28,7 @@ namespace Wabbajack.Launcher
private string _status = "Checking for Updates";
private Release _version;
private List<string> _errors = new List<string>();
public string Status
{
@ -61,24 +63,33 @@ namespace Wabbajack.Launcher
return new Version(0, 0, 0, 0);
}).FirstOrDefault();
}
catch (Exception)
catch (Exception ex)
{
FinishAndExit();
_errors.Add(ex.Message);
await FinishAndExit();
}
if (_version == null)
FinishAndExit();
{
_errors.Add("Unable to parse Github releases");
await FinishAndExit();
}
Status = "Looking for Updates";
var base_folder = Path.Combine(Directory.GetCurrentDirectory(), _version.Tag);
if (File.Exists(Path.Combine(base_folder, "Wabbajack.exe")))
FinishAndExit();
{
await FinishAndExit();
}
var asset = _version.Assets.FirstOrDefault(a => a.Name == _version.Tag + ".zip");
if (asset == null)
FinishAndExit();
{
_errors.Add("No zip file for release " + _version.Tag);
await FinishAndExit();
}
var wc = new WebClient();
wc.DownloadProgressChanged += UpdateProgress;
@ -88,12 +99,24 @@ namespace Wabbajack.Launcher
{
data = await wc.DownloadDataTaskAsync(asset.BrowserDownloadUrlFast);
}
catch (Exception)
catch (Exception ex)
{
_errors.Add(ex.Message);
// Something went wrong so fallback to original URL
try
{
data = await wc.DownloadDataTaskAsync(asset.BrowserDownloadUrl);
}
catch (Exception ex2)
{
_errors.Add(ex2.Message);
await FinishAndExit();
throw; // avoid unsigned variable 'data'
}
}
try
{
using (var zip = new ZipArchive(new MemoryStream(data), ZipArchiveMode.Read))
{
foreach (var entry in zip.Entries)
@ -110,10 +133,21 @@ namespace Wabbajack.Launcher
await o.CopyToAsync(of);
}
}
FinishAndExit();
}
catch (Exception ex)
{
_errors.Add(ex.Message);
}
finally
{
await FinishAndExit();
}
private void FinishAndExit()
}
private async Task FinishAndExit()
{
try
{
Status = "Launching...";
var wjFolder = Directory.EnumerateDirectories(Directory.GetCurrentDirectory())
@ -127,8 +161,25 @@ namespace Wabbajack.Launcher
WorkingDirectory = wjFolder,
};
Process.Start(info);
}
catch (Exception ex)
{
if (_errors.Count == 0)
{
Status = "Failed: Unknown error";
await Task.Delay(10000);
}
foreach (var error in _errors)
{
Status = "Failed: " + error;
await Task.Delay(10000);
}
}
finally
{
Environment.Exit(0);
}
}
private void UpdateProgress(object sender, DownloadProgressChangedEventArgs e)
{