Skip to content

Commit

Permalink
Merge pull request #27 from cryptlex/get-total-deactivations
Browse files Browse the repository at this point in the history
feat: add GetLicenseAllowedDeactivations and GetLicenseTotalDeactivations
  • Loading branch information
ahmad-kemsan authored Feb 9, 2024
2 parents 6c43991 + 53bb75b commit b1bacc6
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/Cryptlex.LexActivator/LexActivator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,60 @@ public static uint GetLicenseTotalActivations()
throw new LexActivatorException(status);
}
}

/// <summary>
/// Gets the allowed deactivations of the license.
/// </summary>
/// <returns>Returns the allowed deactivations.</returns>
public static uint GetLicenseAllowedDeactivations()
{
uint allowedDeactivations = 0;
int status;
if (LexActivatorNative.IsWindows())
{
status = IntPtr.Size == 4 ? LexActivatorNative.GetLicenseAllowedDeactivations_x86(ref allowedDeactivations) : LexActivatorNative.GetLicenseAllowedActivations(ref allowedDeactivations);
}
else
{
status = LexActivatorNative.GetLicenseAllowedDeactivations(ref allowedDeactivations);
}
switch (status)
{
case LexStatusCodes.LA_OK:
return allowedDeactivations;
case LexStatusCodes.LA_FAIL:
return 0;
default:
throw new LexActivatorException(status);
}
}

/// <summary>
/// Gets the total deactivations of the license.
/// </summary>
/// <returns>Returns the total deactivations.</returns>
public static uint GetLicenseTotalDeactivations()
{
uint totalDeactivations = 0;
int status;
if (LexActivatorNative.IsWindows())
{
status = IntPtr.Size == 4 ? LexActivatorNative.GetLicenseTotalDeactivations_x86(ref totalDeactivations) : LexActivatorNative.GetLicenseTotalActivations(ref totalDeactivations);
}
else
{
status = LexActivatorNative.GetLicenseTotalDeactivations(ref totalDeactivations);
}
switch (status)
{
case LexStatusCodes.LA_OK:
return totalDeactivations;
case LexStatusCodes.LA_FAIL:
return 0;
default:
throw new LexActivatorException(status);
}
}

/// <summary>
/// Gets the license creation date timestamp.
Expand Down
12 changes: 12 additions & 0 deletions src/Cryptlex.LexActivator/LexActivatorNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ public static bool IsWindows()
[DllImport(DLL_FILE_NAME, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern int GetLicenseTotalActivations(ref uint totalActivations);

[DllImport(DLL_FILE_NAME, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern int GetLicenseAllowedDeactivations(ref uint allowedDeactivations);

[DllImport(DLL_FILE_NAME, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern int GetLicenseTotalDeactivations(ref uint totalDeactivations);

[DllImport(DLL_FILE_NAME, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern int GetLicenseCreationDate(ref uint creationDate);

Expand Down Expand Up @@ -491,6 +497,12 @@ public static bool IsWindows()

[DllImport(DLL_FILE_NAME_X86, CharSet = CharSet.Unicode, EntryPoint = "GetLicenseTotalActivations", CallingConvention = CallingConvention.Cdecl)]
public static extern int GetLicenseTotalActivations_x86(ref uint totalActivations);

[DllImport(DLL_FILE_NAME_X86, CharSet = CharSet.Unicode, EntryPoint = "GetLicenseAllowedDeactivations", CallingConvention = CallingConvention.Cdecl)]
public static extern int GetLicenseAllowedDeactivations_x86(ref uint allowedDeactivations);

[DllImport(DLL_FILE_NAME_X86, CharSet = CharSet.Unicode, EntryPoint = "GetLicenseTotalDeactivations", CallingConvention = CallingConvention.Cdecl)]
public static extern int GetLicenseTotalDeactivations_x86(ref uint totalDeactivations);

[DllImport(DLL_FILE_NAME_X86, CharSet = CharSet.Unicode, EntryPoint = "GetLicenseCreationDate", CallingConvention = CallingConvention.Cdecl)]
public static extern int GetLicenseCreationDate_x86(ref uint creationDate);
Expand Down

0 comments on commit b1bacc6

Please sign in to comment.