mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Still work without build server
This commit is contained in:
parent
2661454fb9
commit
fef7fa9241
@ -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<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)
|
||||
|
@ -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(
|
||||
|
@ -86,6 +86,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);
|
||||
|
Loading…
Reference in New Issue
Block a user