From 2661454fb90b87e6da16b8ec2dbd67c86b0544c8 Mon Sep 17 00:00:00 2001 From: erri120 Date: Tue, 14 Jul 2020 14:14:28 +0200 Subject: [PATCH 1/4] Fixed main window not appearing after splash screen --- Wabbajack/View Models/MainWindowVM.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Wabbajack/View Models/MainWindowVM.cs b/Wabbajack/View Models/MainWindowVM.cs index 0aea4ef4..773352f4 100644 --- a/Wabbajack/View Models/MainWindowVM.cs +++ b/Wabbajack/View Models/MainWindowVM.cs @@ -126,7 +126,8 @@ namespace Wabbajack var fvi = FileVersionInfo.GetVersionInfo(assembly.Location); VersionDisplay = $"v{fvi.FileVersion}"; Utils.Log($"Wabbajack Version: {fvi.FileVersion}"); - var tsk = Metrics.Send("started_wabbajack", fvi.FileVersion); + + Task.Run(() => Metrics.Send("started_wabbajack", fvi.FileVersion)); } catch (Exception ex) { From fef7fa9241b6851714cb825a86302f405e6799f3 Mon Sep 17 00:00:00 2001 From: erri120 Date: Tue, 14 Jul 2020 14:15:01 +0200 Subject: [PATCH 2/4] Still work without build server --- Wabbajack.Lib/ClientAPI.cs | 56 ++++++++++++++++++++++++++---- Wabbajack.Lib/MO2Compiler.cs | 6 ++-- Wabbajack.Lib/Metrics.cs | 3 ++ Wabbajack.Lib/NexusApi/NexusApi.cs | 30 ++++++++-------- 4 files changed, 72 insertions(+), 23 deletions(-) diff --git a/Wabbajack.Lib/ClientAPI.cs b/Wabbajack.Lib/ClientAPI.cs index cd94f577..ec5cbfd8 100644 --- a/Wabbajack.Lib/ClientAPI.cs +++ b/Wabbajack.Lib/ClientAPI.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; - using System.Linq; - using System.Net; +using System.Linq; +using System.Net; using System.Net.Http; using System.Text; using System.Threading.Tasks; @@ -9,10 +9,45 @@ using Wabbajack.Common; using Wabbajack.Common.Exceptions; using Wabbajack.Common.Serialization.Json; using Wabbajack.Lib.Downloaders; - using Wabbajack.VirtualFileSystem; - - namespace Wabbajack.Lib + +namespace Wabbajack.Lib { + public static class BuildServerStatus + { + private static bool _didCheck; + private static bool _isBuildServerDown; + + private static bool CheckBuildServer() + { + var client = new Wabbajack.Lib.Http.Client(); + + try + { + var result = client.GetAsync($"{Consts.WabbajackBuildServerUri}heartbeat").Result; + _isBuildServerDown = result.StatusCode != HttpStatusCode.OK; + } + catch (Exception) + { + _isBuildServerDown = true; + } + finally + { + _didCheck = true; + } + + Utils.Log($"Build server is {(_isBuildServerDown ? "down" : "alive")}"); + return _isBuildServerDown; + } + + public static bool IsBuildServerDown + { + get + { + return _didCheck ? _isBuildServerDown : CheckBuildServer(); + } + } + } + [JsonName("ModUpgradeRequest")] public class ModUpgradeRequest { @@ -98,11 +133,15 @@ using Wabbajack.Lib.Downloaders; public static async Task SendModListDefinition(ModList modList) { var client = await GetClient(); + if (BuildServerStatus.IsBuildServerDown) + return; await client.PostAsync($"{Consts.WabbajackBuildServerUri}list_definitions/ingest", new StringContent(modList.ToJson(), Encoding.UTF8, "application/json")); } public static async Task GetExistingGameFiles(WorkQueue queue, Game game) { + if(BuildServerStatus.IsBuildServerDown) + return new Archive[0]; var client = await GetClient(); var metaData = game.MetaData(); var results = @@ -120,8 +159,13 @@ using Wabbajack.Lib.Downloaders; public static async Task InferDownloadState(Hash hash) { + if (BuildServerStatus.IsBuildServerDown) + return null; + var client = await GetClient(); - var results = await client.GetJsonAsync($"{Consts.WabbajackBuildServerUri}mod_files/by_hash/{hash.ToHex()}"); + + var results = await client.GetJsonAsync( + $"{Consts.WabbajackBuildServerUri}mod_files/by_hash/{hash.ToHex()}"); await DownloadDispatcher.PrepareAll(results.Select(r => r.State)); foreach (var result in results) diff --git a/Wabbajack.Lib/MO2Compiler.cs b/Wabbajack.Lib/MO2Compiler.cs index f54ce672..94c92b6e 100644 --- a/Wabbajack.Lib/MO2Compiler.cs +++ b/Wabbajack.Lib/MO2Compiler.cs @@ -101,6 +101,9 @@ namespace Wabbajack.Lib Info("Using Profiles: " + string.Join(", ", SelectedProfiles.OrderBy(p => p))); Utils.Log($"VFS File Location: {VFSCacheName}"); + Utils.Log($"MO2 Folder: {MO2Folder}"); + Utils.Log($"Downloads Folder: {MO2DownloadsFolder}"); + Utils.Log($"Game Folder: {GamePath}"); if (cancel.IsCancellationRequested) return false; @@ -174,7 +177,6 @@ namespace Wabbajack.Lib if (cancel.IsCancellationRequested) return false; UpdateTracker.NextStep("Inferring metas for game file downloads"); await InferMetas(); - if (cancel.IsCancellationRequested) return false; UpdateTracker.NextStep("Reindexing downloads after meta inferring"); @@ -411,8 +413,6 @@ namespace Wabbajack.Lib var meta = await ClientAPI.InferDownloadState(vf.Hash); - - if (meta == null) { await vf.AbsoluteName.WithExtension(Consts.MetaFileExtension).WriteAllLinesAsync( diff --git a/Wabbajack.Lib/Metrics.cs b/Wabbajack.Lib/Metrics.cs index e4c5b97a..33e5fd74 100644 --- a/Wabbajack.Lib/Metrics.cs +++ b/Wabbajack.Lib/Metrics.cs @@ -86,6 +86,9 @@ namespace Wabbajack.Lib /// public static async Task Send(string action, string value) { + if (BuildServerStatus.IsBuildServerDown) + return; + var key = await GetMetricsKey(); Utils.Log($"File hash check (-42) {key}"); var client = new Http.Client(); diff --git a/Wabbajack.Lib/NexusApi/NexusApi.cs b/Wabbajack.Lib/NexusApi/NexusApi.cs index 72dd7864..d833703a 100644 --- a/Wabbajack.Lib/NexusApi/NexusApi.cs +++ b/Wabbajack.Lib/NexusApi/NexusApi.cs @@ -290,21 +290,16 @@ namespace Wabbajack.Lib.NexusApi private async Task GetCached(string url) { - try - { - var builder = new UriBuilder(url) - { - Host = Consts.WabbajackBuildServerUri.Host, - Scheme = Consts.WabbajackBuildServerUri.Scheme, - Port = Consts.WabbajackBuildServerUri.Port - }; - return await Get(builder.ToString(), HttpClient.WithHeader((Consts.MetricsKeyHeader, await Metrics.GetMetricsKey()))); - } - catch (Exception) - { + if (BuildServerStatus.IsBuildServerDown) return await Get(url); - } + var builder = new UriBuilder(url) + { + Host = Consts.WabbajackBuildServerUri.Host, + Scheme = Consts.WabbajackBuildServerUri.Scheme, + Port = Consts.WabbajackBuildServerUri.Port + }; + return await Get(builder.ToString(), HttpClient.WithHeader((Consts.MetricsKeyHeader, await Metrics.GetMetricsKey()))); } public async Task GetNexusDownloadLink(NexusDownloader.State archive) @@ -362,7 +357,14 @@ namespace Wabbajack.Lib.NexusApi var url = $"https://api.nexusmods.com/v1/games/{game.MetaData().NexusName}/mods/{modId}.json"; if (useCache) { - return await GetCached(url); + try + { + return await GetCached(url); + } + catch (HttpException) + { + return await Get(url); + } } return await Get(url); From ce47387e93784cf514eeebfb10bb8195de742ab7 Mon Sep 17 00:00:00 2001 From: erri120 Date: Tue, 14 Jul 2020 14:19:09 +0200 Subject: [PATCH 3/4] Updated CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 516cbf38..347173d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ### Changelog +#### Version - next +* Wabbajack will continue working even if the build server is down +* Fixed an issue where the main window does not appear after the splash screen + #### Version - 2.1.2.0 - 7/13/2020 * Can heal hand selected MEGA files * Several backend fixes From 0363f0419a7154cfbd4120b1432bc3c75144440f Mon Sep 17 00:00:00 2001 From: erri120 Date: Tue, 14 Jul 2020 14:44:07 +0200 Subject: [PATCH 4/4] Smaller bug fixes --- Wabbajack.Lib/ClientAPI.cs | 4 +- Wabbajack.Lib/FileUploader/AuthorAPI.cs | 1 - Wabbajack.Lib/Metrics.cs | 79 ++++++++++--------------- 3 files changed, 33 insertions(+), 51 deletions(-) diff --git a/Wabbajack.Lib/ClientAPI.cs b/Wabbajack.Lib/ClientAPI.cs index ec5cbfd8..e0cb595e 100644 --- a/Wabbajack.Lib/ClientAPI.cs +++ b/Wabbajack.Lib/ClientAPI.cs @@ -19,12 +19,12 @@ namespace Wabbajack.Lib private static bool CheckBuildServer() { - var client = new Wabbajack.Lib.Http.Client(); + var client = new Http.Client(); try { var result = client.GetAsync($"{Consts.WabbajackBuildServerUri}heartbeat").Result; - _isBuildServerDown = result.StatusCode != HttpStatusCode.OK; + _isBuildServerDown = result.StatusCode != HttpStatusCode.OK && result.StatusCode != HttpStatusCode.InternalServerError; } catch (Exception) { diff --git a/Wabbajack.Lib/FileUploader/AuthorAPI.cs b/Wabbajack.Lib/FileUploader/AuthorAPI.cs index 041368d5..4ffabd9f 100644 --- a/Wabbajack.Lib/FileUploader/AuthorAPI.cs +++ b/Wabbajack.Lib/FileUploader/AuthorAPI.cs @@ -40,7 +40,6 @@ namespace Wabbajack.Lib.FileUploader { var client = await GetAuthorizedClient(); return await client.GetStringAsync($"{Consts.WabbajackBuildServerUri}jobs/enqueue_job/{jobtype}"); - } public static async Task UpdateNexusCache() diff --git a/Wabbajack.Lib/Metrics.cs b/Wabbajack.Lib/Metrics.cs index 33e5fd74..a51ed1f3 100644 --- a/Wabbajack.Lib/Metrics.cs +++ b/Wabbajack.Lib/Metrics.cs @@ -1,14 +1,7 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Security.Cryptography; -using System.Text; using System.Threading.Tasks; using Microsoft.Win32; using Wabbajack.Common; -using Wabbajack.Common.Exceptions; namespace Wabbajack.Lib { @@ -17,7 +10,7 @@ namespace Wabbajack.Lib public const string Downloading = "downloading"; public const string BeginInstall = "begin_install"; public const string FinishInstall = "finish_install"; - private static AsyncLock _creationLock = new AsyncLock(); + private static readonly AsyncLock _creationLock = new AsyncLock(); public static async ValueTask GetMetricsKey() { @@ -29,53 +22,43 @@ namespace Wabbajack.Lib // When there's no file or regkey var key = Utils.MakeRandomKey(); await key.ToEcryptedJson(Consts.MetricsKeyHeader); - using (RegistryKey regKey = Registry.CurrentUser.CreateSubKey(@"Software\Wabbajack", RegistryKeyPermissionCheck.Default)!) - { - regKey.SetValue("x-metrics-key", key); - } + using RegistryKey regKey = Registry.CurrentUser.CreateSubKey(@"Software\Wabbajack", RegistryKeyPermissionCheck.Default)!; + regKey.SetValue("x-metrics-key", key); return key; } - else + + // If there is no file but a registry key, create the file and transfer the data from the registry key + using (RegistryKey regKey = Registry.CurrentUser.OpenSubKey(@"Software\Wabbajack", RegistryKeyPermissionCheck.Default)!) { - // If there is no file but a registry key, create the file and transfer the data from the registry key - using (RegistryKey regKey = Registry.CurrentUser.OpenSubKey(@"Software\Wabbajack", RegistryKeyPermissionCheck.Default)!) - { - string key = (string)regKey.GetValue(Consts.MetricsKeyHeader)!; - await key.ToEcryptedJson(Consts.MetricsKeyHeader); - return key; - } + string key = (string)regKey.GetValue(Consts.MetricsKeyHeader)!; + await key.ToEcryptedJson(Consts.MetricsKeyHeader); + return key; } } - else - { - if (Utils.HaveRegKeyMetricsKey()) - { - // When there's a file and a regkey - using (RegistryKey regKey = Registry.CurrentUser.OpenSubKey(@"Software\Wabbajack", RegistryKeyPermissionCheck.Default)!) - { - return (string)regKey.GetValue(Consts.MetricsKeyHeader)!; - } - } - else - { - // If there's a regkey and a file, return regkey - using (RegistryKey regKey = Registry.CurrentUser.CreateSubKey(@"Software\Wabbajack", RegistryKeyPermissionCheck.Default)!) - { - try - { - string key = await Utils.FromEncryptedJson(Consts.MetricsKeyHeader)!; - regKey.SetValue("x-metrics-key", key); - return key; - } - catch (Exception) - { - // Probably an encryption error - await Utils.DeleteEncryptedJson(Consts.MetricsKeyHeader); - return await GetMetricsKey(); - } - } + if (Utils.HaveRegKeyMetricsKey()) + { + // When there's a file and a regkey + using RegistryKey regKey = Registry.CurrentUser.OpenSubKey(@"Software\Wabbajack", RegistryKeyPermissionCheck.Default)!; + return (string)regKey.GetValue(Consts.MetricsKeyHeader)!; + } + + // If there's a regkey and a file, return regkey + using (RegistryKey regKey = Registry.CurrentUser.CreateSubKey(@"Software\Wabbajack", RegistryKeyPermissionCheck.Default)!) + { + try + { + string key = await Utils.FromEncryptedJson(Consts.MetricsKeyHeader)!; + regKey.SetValue("x-metrics-key", key); + return key; } + catch (Exception) + { + // Probably an encryption error + await Utils.DeleteEncryptedJson(Consts.MetricsKeyHeader); + return await GetMetricsKey(); + } + } } ///