Reset metrics key if data is corrupted

This commit is contained in:
Timothy Baldridge 2020-06-01 16:27:57 -06:00
parent 4c0119561a
commit 124704939d
2 changed files with 16 additions and 7 deletions

View File

@ -19,9 +19,21 @@ namespace Wabbajack.Common
using var _ = await _creationLock.WaitAsync();
if (!Utils.HaveEncryptedJson(Consts.MetricsKeyHeader))
{
await Utils.MakeRandomKey().ToEcryptedJson(Consts.MetricsKeyHeader);
var key = Utils.MakeRandomKey();
await key.ToEcryptedJson(Consts.MetricsKeyHeader);
return key;
}
try
{
return await Utils.FromEncryptedJson<string>(Consts.MetricsKeyHeader);
}
catch (Exception)
{
var key = Utils.MakeRandomKey();
await key.ToEcryptedJson(Consts.MetricsKeyHeader);
return key;
}
return await Utils.FromEncryptedJson<string>(Consts.MetricsKeyHeader);
}
/// <summary>
/// This is all we track for metrics, action, and value. The action will be like

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
@ -46,13 +46,10 @@ namespace Wabbajack.Lib
public static async Task<Common.Http.Client> GetClient()
{
var client = new Common.Http.Client();
if (Utils.HaveEncryptedJson(Consts.MetricsKeyHeader))
client.Headers.Add((Consts.MetricsKeyHeader, await Utils.FromEncryptedJson<string>(Consts.MetricsKeyHeader)));
client.Headers.Add((Consts.MetricsKeyHeader, await Metrics.GetMetricsKey()));
return client;
}
public static async Task<Uri> GetModUpgrade(Archive oldArchive, Archive newArchive, TimeSpan? maxWait = null, TimeSpan? waitBetweenTries = null)
{
maxWait ??= TimeSpan.FromMinutes(10);