forked from Snoooopy/MetroUnlocker
First release build.
This commit is contained in:
36
MetroUnlocker/LibTSForge/Modifiers/ProductKeyInstaller.cs
Normal file
36
MetroUnlocker/LibTSForge/Modifiers/ProductKeyInstaller.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
|
||||
using MetroUnlocker.LibTSForge.SPP;
|
||||
|
||||
namespace MetroUnlocker.LibTSForge.Modifiers
|
||||
{
|
||||
public static class ProductKeyInstaller
|
||||
{
|
||||
public static void InstallGeneratedProductKey(PhysicalStoreVersion version, bool production, Guid actId)
|
||||
{
|
||||
ProductKeyConfig keyConfig = new ProductKeyConfig();
|
||||
|
||||
keyConfig.LoadConfig(actId);
|
||||
|
||||
ProductConfig config;
|
||||
keyConfig.Products.TryGetValue(actId, out config);
|
||||
|
||||
if (config == null) throw new ArgumentException("Activation ID " + actId + " not found in ProductKeyConfig.");
|
||||
|
||||
ProductKey pkey = config.GetRandomKey();
|
||||
|
||||
Guid instPkeyId = SLApi.GetInstalledProductKeyId(actId);
|
||||
if (instPkeyId != Guid.Empty) SLApi.UninstallProductKey(instPkeyId);
|
||||
|
||||
if (pkey.Algorithm != PKeyAlgorithm.PKEY2009)
|
||||
throw new Exception("The key algorithm isn't 2009");
|
||||
|
||||
uint status = SLApi.InstallProductKey(pkey);
|
||||
|
||||
if (status != 0)
|
||||
throw new ApplicationException("Failed to install generated product key.");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user