Show error message if Goldberg could not be downloaded/extracted, prompting the user to do so manually.

Try to skip getting DLC from SteamDB on error.
This commit is contained in:
Jeddunk 2021-04-06 16:55:53 +02:00
parent 19f460d12d
commit 8e62880e23
2 changed files with 96 additions and 54 deletions

View File

@ -6,6 +6,7 @@ using System.Linq;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using GoldbergGUI.Core.Models;
using GoldbergGUI.Core.Utils;
using MvvmCross.Logging;
@ -85,7 +86,10 @@ namespace GoldbergGUI.Core.Services
_log = log;
var download = await Download().ConfigureAwait(false);
if (download) await Extract(_goldbergZipPath).ConfigureAwait(false);
if (download)
{
await Extract(_goldbergZipPath).ConfigureAwait(false);
}
return await GetGlobalSettings().ConfigureAwait(false);
}
@ -378,6 +382,8 @@ namespace GoldbergGUI.Core.Services
}
private async Task StartDownload(string downloadUrl)
{
try
{
var client = new HttpClient();
_log.Debug(downloadUrl);
@ -390,6 +396,13 @@ namespace GoldbergGUI.Core.Services
_log.Info("Download finished!");
}
}
catch (Exception e)
{
ShowErrorMessage();
_log.Error(e.ToString);
Environment.Exit(1);
}
}
// Empty subfolder ./goldberg/
// Extract all from archive to subfolder ./goldberg/
@ -397,13 +410,34 @@ namespace GoldbergGUI.Core.Services
{
_log.Debug("Start extraction...");
await Task.Run(() =>
{
try
{
Directory.Delete(_goldbergPath, true);
ZipFile.ExtractToDirectory(archivePath, _goldbergPath);
}
catch (Exception e)
{
ShowErrorMessage();
_log.Error(e.ToString);
Environment.Exit(1);
// throw;
}
}).ConfigureAwait(false);
_log.Debug("Extraction done!");
}
private void ShowErrorMessage()
{
if (Directory.Exists(_goldbergPath))
{
Directory.Delete(_goldbergPath, true);
}
Directory.CreateDirectory(_goldbergPath);
MessageBox.Show("Could not setup Goldberg Emulator!\n" +
"Please download it manually and extract its content into the \"goldberg\" subfolder!");
}
// https://gitlab.com/Mr_Goldberg/goldberg_emulator/-/blob/master/generate_interfaces_file.cpp
// (maybe) check DLL date first
public async Task GenerateInterfacesFile(string filePath)

View File

@ -218,6 +218,8 @@ namespace GoldbergGUI.Core.Services
// ReSharper disable once InvertIf
if (useSteamDb)
{
try
{
var steamDbUri = new Uri($"https://steamdb.info/app/{steamApp.AppId}/dlc/");
@ -268,6 +270,12 @@ namespace GoldbergGUI.Core.Services
_log.Error("Could not get DLC from SteamDB!");
}
}
catch (Exception e)
{
_log.Error("Could not get DLC from SteamDB!");
_log.Error(e.ToString);
}
}
}
else
{