mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Merge pull request #959 from erri120/no-build-server
Work without build server
This commit is contained in:
commit
fb22cb31bb
@ -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
|
||||
|
@ -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 Http.Client();
|
||||
|
||||
try
|
||||
{
|
||||
var result = client.GetAsync($"{Consts.WabbajackBuildServerUri}heartbeat").Result;
|
||||
_isBuildServerDown = result.StatusCode != HttpStatusCode.OK && result.StatusCode != HttpStatusCode.InternalServerError;
|
||||
}
|
||||
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<Archive[]> 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<AbstractDownloadState?> InferDownloadState(Hash hash)
|
||||
{
|
||||
if (BuildServerStatus.IsBuildServerDown)
|
||||
return null;
|
||||
|
||||
var client = await GetClient();
|
||||
var results = await client.GetJsonAsync<Archive[]>($"{Consts.WabbajackBuildServerUri}mod_files/by_hash/{hash.ToHex()}");
|
||||
|
||||
var results = await client.GetJsonAsync<Archive[]>(
|
||||
$"{Consts.WabbajackBuildServerUri}mod_files/by_hash/{hash.ToHex()}");
|
||||
|
||||
await DownloadDispatcher.PrepareAll(results.Select(r => r.State));
|
||||
foreach (var result in results)
|
||||
|
@ -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<string> UpdateNexusCache()
|
||||
|
@ -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(
|
||||
|
@ -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<string> 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<string>(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<string>(Consts.MetricsKeyHeader)!;
|
||||
regKey.SetValue("x-metrics-key", key);
|
||||
return key;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Probably an encryption error
|
||||
await Utils.DeleteEncryptedJson(Consts.MetricsKeyHeader);
|
||||
return await GetMetricsKey();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@ -86,6 +69,9 @@ namespace Wabbajack.Lib
|
||||
/// <param name="value"></param>
|
||||
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();
|
||||
|
@ -290,21 +290,16 @@ namespace Wabbajack.Lib.NexusApi
|
||||
|
||||
private async Task<T> GetCached<T>(string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
var builder = new UriBuilder(url)
|
||||
{
|
||||
Host = Consts.WabbajackBuildServerUri.Host,
|
||||
Scheme = Consts.WabbajackBuildServerUri.Scheme,
|
||||
Port = Consts.WabbajackBuildServerUri.Port
|
||||
};
|
||||
return await Get<T>(builder.ToString(), HttpClient.WithHeader((Consts.MetricsKeyHeader, await Metrics.GetMetricsKey())));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (BuildServerStatus.IsBuildServerDown)
|
||||
return await Get<T>(url);
|
||||
}
|
||||
|
||||
var builder = new UriBuilder(url)
|
||||
{
|
||||
Host = Consts.WabbajackBuildServerUri.Host,
|
||||
Scheme = Consts.WabbajackBuildServerUri.Scheme,
|
||||
Port = Consts.WabbajackBuildServerUri.Port
|
||||
};
|
||||
return await Get<T>(builder.ToString(), HttpClient.WithHeader((Consts.MetricsKeyHeader, await Metrics.GetMetricsKey())));
|
||||
}
|
||||
|
||||
public async Task<string> 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<ModInfo>(url);
|
||||
try
|
||||
{
|
||||
return await GetCached<ModInfo>(url);
|
||||
}
|
||||
catch (HttpException)
|
||||
{
|
||||
return await Get<ModInfo>(url);
|
||||
}
|
||||
}
|
||||
|
||||
return await Get<ModInfo>(url);
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user