Skip to content

Commit 05339d2

Browse files
authored
Merge pull request #138 from xADDBx/WrathNexusPremiumDL
2 parents 2290b20 + c88053b commit 05339d2

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

ModFinderClient/MainWindow.xaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public MainWindow()
5252

5353
Window = this;
5454

55+
// Force Init; Start Verification Request
56+
_ = Main.Settings;
57+
5558
CheckForUpdate();
5659

5760
installedMods.DataContext = ModDB;
@@ -880,6 +883,7 @@ private async void TryAquireNexusAPIKeyAsync()
880883
{
881884
var bytes = Encoding.UTF8.GetBytes(key);
882885
Main.Settings.NexusApiKeyBytes = ProtectedData.Protect(bytes, null, DataProtectionScope.CurrentUser);
886+
Main.Settings.IsKeyActuallyPremium = true;
883887
Main.Settings.Save();
884888
}
885889
else

ModFinderClient/Util/Settings.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
using System.Security.Cryptography;
1+
using Newtonsoft.Json;
2+
using NexusModsNET;
3+
using System.Security.Cryptography;
24
using System.Text;
5+
using System.Threading.Tasks;
36

47
namespace ModFinder.Util
58
{
@@ -8,7 +11,10 @@ public class Settings
811
public string AutoWrathPath { get; set; }
912
public string WrathPath { get; set; }
1013
public byte[] NexusApiKeyBytes { get; set; }
11-
public string MaybeGetNexusKey()
14+
15+
[JsonIgnore]
16+
internal bool? IsKeyActuallyPremium;
17+
private string GetPlainNexusKey()
1218
{
1319
if (NexusApiKeyBytes == null)
1420
{
@@ -17,16 +23,30 @@ public string MaybeGetNexusKey()
1723
var plain = ProtectedData.Unprotect(NexusApiKeyBytes, null, DataProtectionScope.CurrentUser);
1824
return Encoding.UTF8.GetString(plain);
1925
}
26+
public string MaybeGetNexusKey()
27+
{
28+
if (!IsKeyActuallyPremium.HasValue || !IsKeyActuallyPremium.Value)
29+
{
30+
return null;
31+
}
32+
return GetPlainNexusKey();
33+
}
2034

2135
private static Settings _Instance;
2236
public static Settings Load()
2337
{
2438
if (_Instance == null)
2539
{
2640
if (Main.TryReadFile("Settings.json", out var settingsRaw))
41+
{
2742
_Instance = IOTool.FromString<Settings>(settingsRaw);
43+
Task.Run(_Instance.VerifyNexusPremium);
44+
}
2845
else
46+
{
2947
_Instance = new();
48+
_Instance.Save();
49+
}
3050
}
3151

3252
return _Instance;
@@ -39,5 +59,16 @@ public void Save()
3959
IOTool.Write(this, Main.AppPath("Settings.json"));
4060
});
4161
}
62+
63+
internal async void VerifyNexusPremium()
64+
{
65+
var maybeKey = GetPlainNexusKey();
66+
if (maybeKey != null)
67+
{
68+
var client = NexusModsFactory.New(maybeKey, "Modfinder", Main.ProductVersion);
69+
var user = await client.CreateUserInquirer().GetUserAsync();
70+
IsKeyActuallyPremium = user.IsPremium;
71+
}
72+
}
4273
}
4374
}

0 commit comments

Comments
 (0)