1- using System . Security . Cryptography ;
1+ using Newtonsoft . Json ;
2+ using NexusModsNET ;
3+ using System . Security . Cryptography ;
24using System . Text ;
5+ using System . Threading . Tasks ;
36
47namespace 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