mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Improve metric key storage
This commit is contained in:
parent
817dbef7ae
commit
4e482e53a2
@ -3,8 +3,10 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Win32;
|
||||||
using Wabbajack.Common.Exceptions;
|
using Wabbajack.Common.Exceptions;
|
||||||
|
|
||||||
namespace Wabbajack.Common
|
namespace Wabbajack.Common
|
||||||
@ -21,22 +23,53 @@ namespace Wabbajack.Common
|
|||||||
using var _ = await _creationLock.WaitAsync();
|
using var _ = await _creationLock.WaitAsync();
|
||||||
if (!Utils.HaveEncryptedJson(Consts.MetricsKeyHeader))
|
if (!Utils.HaveEncryptedJson(Consts.MetricsKeyHeader))
|
||||||
{
|
{
|
||||||
|
if (!Utils.HaveRegKeyMetricsKey())
|
||||||
|
{
|
||||||
|
// When there's no file or regkey
|
||||||
var key = Utils.MakeRandomKey();
|
var key = Utils.MakeRandomKey();
|
||||||
await key.ToEcryptedJson(Consts.MetricsKeyHeader);
|
await key.ToEcryptedJson(Consts.MetricsKeyHeader);
|
||||||
|
using (RegistryKey regKey = Registry.CurrentUser.CreateSubKey(@"Software\Wabbajack", RegistryKeyPermissionCheck.Default)!)
|
||||||
|
{
|
||||||
|
regKey.SetValue("x-metrics-key", key);
|
||||||
|
}
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// When there's a file but no regkey
|
||||||
|
Utils.Log("user has reg key but no file");
|
||||||
|
// 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;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return await Utils.FromEncryptedJson<string>(Consts.MetricsKeyHeader);
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
var key = Utils.MakeRandomKey();
|
if (Utils.HaveRegKeyMetricsKey())
|
||||||
await key.ToEcryptedJson(Consts.MetricsKeyHeader);
|
{
|
||||||
|
// 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
|
||||||
|
{
|
||||||
|
Utils.Log("user has file but no regkey");
|
||||||
|
// If there's a regkey and a file, return regkey
|
||||||
|
using (RegistryKey regKey = Registry.CurrentUser.CreateSubKey(@"Software\Wabbajack", RegistryKeyPermissionCheck.Default)!)
|
||||||
|
{
|
||||||
|
string key = await Utils.FromEncryptedJson<string>(Consts.MetricsKeyHeader)!;
|
||||||
|
regKey.SetValue("x-metrics-key", key);
|
||||||
return key;
|
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".
|
||||||
|
@ -21,6 +21,7 @@ using ICSharpCode.SharpZipLib.BZip2;
|
|||||||
using IniParser;
|
using IniParser;
|
||||||
using IniParser.Model.Configuration;
|
using IniParser.Model.Configuration;
|
||||||
using IniParser.Parser;
|
using IniParser.Parser;
|
||||||
|
using Microsoft.Win32;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using RocksDbSharp;
|
using RocksDbSharp;
|
||||||
@ -970,6 +971,21 @@ namespace Wabbajack.Common
|
|||||||
return Consts.LocalAppDataPath.Combine(key).IsFile;
|
return Consts.LocalAppDataPath.Combine(key).IsFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool HaveRegKey()
|
||||||
|
{
|
||||||
|
return Registry.CurrentUser.OpenSubKey(@"Software\Wabbajack") != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool HaveRegKeyMetricsKey()
|
||||||
|
{
|
||||||
|
if (HaveRegKey())
|
||||||
|
{
|
||||||
|
return Registry.CurrentUser.OpenSubKey(@"Software\Wabbajack")!.GetValueNames().Contains(Consts.MetricsKeyHeader);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static IObservable<(FileEventType, FileSystemEventArgs)> AppLocalEvents { get; }
|
public static IObservable<(FileEventType, FileSystemEventArgs)> AppLocalEvents { get; }
|
||||||
|
|
||||||
public static IObservable<bool> HaveEncryptedJsonObservable(string key)
|
public static IObservable<bool> HaveEncryptedJsonObservable(string key)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user