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,10 +19,22 @@ namespace Wabbajack.Common
using var _ = await _creationLock.WaitAsync(); using var _ = await _creationLock.WaitAsync();
if (!Utils.HaveEncryptedJson(Consts.MetricsKeyHeader)) 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); return await Utils.FromEncryptedJson<string>(Consts.MetricsKeyHeader);
} }
catch (Exception)
{
var key = Utils.MakeRandomKey();
await key.ToEcryptedJson(Consts.MetricsKeyHeader);
return key;
}
}
/// <summary> /// <summary>
/// This is all we track for metrics, action, and value. The action will be like /// This is all we track for metrics, action, and value. The action will be like
/// "downloaded", the value "Joe's list". /// "downloaded", the value "Joe's list".

View File

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