Skip to content

Commit 38f6c7d

Browse files
authored
Merge pull request #30 from cryptlex/ahmad/unlimited-syntax
Implementation of unlimited syntax
2 parents ff9fdaf + 999ea91 commit 38f6c7d

File tree

4 files changed

+60
-25
lines changed

4 files changed

+60
-25
lines changed

src/main/java/com/cryptlex/lexactivator/LexActivator.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import java.nio.charset.StandardCharsets;
99
import java.io.UnsupportedEncodingException;
1010
import com.sun.jna.ptr.IntByReference;
11+
import com.sun.jna.ptr.LongByReference;
12+
import java.math.BigInteger;
1113
import java.util.ArrayList;
1214
import java.util.List;
1315
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -35,6 +37,11 @@ public class LexActivator {
3537
public static final int LA_RELEASES_ALL = 1;
3638
public static final int LA_RELEASES_ALLOWED = 2;
3739

40+
// Convert long to BigInteger to correctly handle unsigned 64-bit values
41+
private static BigInteger toUnsignedBigInteger(long value) {
42+
return BigInteger.valueOf(value).and(BigInteger.valueOf(0xFFFFFFFFFFFFFFFFL));
43+
}
44+
3845
/**
3946
* Sets the absolute path of the Product.dat file. This function must be called
4047
* on every start of your program before any other functions are called.
@@ -363,13 +370,14 @@ public static void SetReleaseChannel(String releaseChannel) throws LexActivatorE
363370
}
364371

365372
/**
366-
* Sets the lease duration for the activation.
373+
* Sets the lease duration for the activation. The activation lease duration
374+
* is honoured when the allow client lease duration property is enabled.
367375
*
368-
* @param leaseDuration
376+
* @param leaseDuration value of the lease duration. A value of -1 indicates unlimited lease duration.
369377
*
370378
* @throws LexActivatorException
371379
*/
372-
public static void SetActivationLeaseDuration(int leaseDuration) throws LexActivatorException {
380+
public static void SetActivationLeaseDuration(long leaseDuration) throws LexActivatorException {
373381
int status;
374382
status = LexActivatorNative.SetActivationLeaseDuration(leaseDuration);
375383
if (LA_OK != status) {
@@ -601,21 +609,22 @@ public static String GetLicenseMetadata(String key) throws LexActivatorException
601609
public static LicenseMeterAttribute GetLicenseMeterAttribute(String name)
602610
throws LexActivatorException, UnsupportedEncodingException {
603611
int status;
604-
IntByReference allowedUses = new IntByReference(0);
605-
IntByReference totalUses = new IntByReference(0);
606-
IntByReference grossUses = new IntByReference(0);
612+
LongByReference allowedUses = new LongByReference(0);
613+
// These references can still hold the uint64_t values populated by the native function
614+
LongByReference totalUses = new LongByReference(0);
615+
LongByReference grossUses = new LongByReference(0);
607616

608617
if (Platform.isWindows()) {
609618
status = LexActivatorNative.GetLicenseMeterAttribute(new WString(name), allowedUses, totalUses, grossUses);
610619
if (LA_OK == status) {
611-
return new LicenseMeterAttribute(name, allowedUses.getValue(), totalUses.getValue(),
612-
grossUses.getValue());
620+
return new LicenseMeterAttribute(name, allowedUses.getValue(), toUnsignedBigInteger(totalUses.getValue()),
621+
toUnsignedBigInteger(grossUses.getValue()));
613622
}
614623
} else {
615624
status = LexActivatorNative.GetLicenseMeterAttribute(name, allowedUses, totalUses, grossUses);
616625
if (LA_OK == status) {
617-
return new LicenseMeterAttribute(name, allowedUses.getValue(), totalUses.getValue(),
618-
grossUses.getValue());
626+
return new LicenseMeterAttribute(name, allowedUses.getValue(), toUnsignedBigInteger(totalUses.getValue()),
627+
toUnsignedBigInteger(grossUses.getValue()));
619628
}
620629
}
621630
throw new LexActivatorException(status);
@@ -652,9 +661,9 @@ public static String GetLicenseKey() throws LexActivatorException, UnsupportedEn
652661
* @return Returns the allowed activations
653662
* @throws LexActivatorException
654663
*/
655-
public static int GetLicenseAllowedActivations() throws LexActivatorException {
664+
public static long GetLicenseAllowedActivations() throws LexActivatorException {
656665
int status;
657-
IntByReference allowedActivations = new IntByReference(0);
666+
LongByReference allowedActivations = new LongByReference(0);
658667
status = LexActivatorNative.GetLicenseAllowedActivations(allowedActivations);
659668
switch (status) {
660669
case LA_OK:
@@ -692,9 +701,9 @@ public static int GetLicenseTotalActivations() throws LexActivatorException {
692701
* @return Returns the allowed deactivations
693702
* @throws LexActivatorException
694703
*/
695-
public static int GetLicenseAllowedDeactivations() throws LexActivatorException {
704+
public static long GetLicenseAllowedDeactivations() throws LexActivatorException {
696705
int status;
697-
IntByReference allowedDeactivations = new IntByReference(0);
706+
LongByReference allowedDeactivations = new LongByReference(0);
698707
status = LexActivatorNative.GetLicenseAllowedDeactivations(allowedDeactivations);
699708
switch (status) {
700709
case LA_OK:

src/main/java/com/cryptlex/lexactivator/LexActivatorNative.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.nio.CharBuffer;
99
import java.nio.ByteBuffer;
1010
import com.sun.jna.ptr.IntByReference;
11+
import com.sun.jna.ptr.LongByReference;
1112
import com.sun.jna.Callback;
1213

1314
public class LexActivatorNative implements Library {
@@ -88,7 +89,7 @@ public interface ReleaseUpdateCallbackTypeA extends Callback {
8889

8990
public static native int SetReleaseChannel(WString releaseChannel);
9091

91-
public static native int SetActivationLeaseDuration(int leaseDuration);
92+
public static native int SetActivationLeaseDuration(long leaseDuration);
9293

9394
public static native int SetOfflineActivationRequestMeterAttributeUses(String name, int uses);
9495

@@ -126,9 +127,9 @@ public interface ReleaseUpdateCallbackTypeA extends Callback {
126127

127128
public static native int GetLicenseMetadata(WString key, CharBuffer value, int length);
128129

129-
public static native int GetLicenseMeterAttribute(String name, IntByReference allowedUses, IntByReference totalUses, IntByReference grossUses);
130+
public static native int GetLicenseMeterAttribute(String name, LongByReference allowedUses, LongByReference totalUses, LongByReference grossUses);
130131

131-
public static native int GetLicenseMeterAttribute(WString name, IntByReference allowedUses, IntByReference totalUses, IntByReference grossUses);
132+
public static native int GetLicenseMeterAttribute(WString name, LongByReference allowedUses, LongByReference totalUses, LongByReference grossUses);
132133

133134
public static native int GetLicenseKey(ByteBuffer licenseKey, int length);
134135

@@ -142,11 +143,11 @@ public interface ReleaseUpdateCallbackTypeA extends Callback {
142143

143144
public static native int GetLicenseMaintenanceExpiryDate(IntByReference maintenanceExpiryDate);
144145

145-
public static native int GetLicenseAllowedActivations(IntByReference allowedActivations);
146+
public static native int GetLicenseAllowedActivations(LongByReference allowedActivations);
146147

147148
public static native int GetLicenseTotalActivations(IntByReference totalActivations);
148149

149-
public static native int GetLicenseAllowedDeactivations(IntByReference allowedDeactivations);
150+
public static native int GetLicenseAllowedDeactivations(LongByReference allowedDeactivations);
150151

151152
public static native int GetLicenseTotalDeactivations(IntByReference totalDeactivations);
152153

src/main/java/com/cryptlex/lexactivator/LicenseMeterAttribute.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
package com.cryptlex.lexactivator;
2+
import java.math.BigInteger;
23

34
public class LicenseMeterAttribute {
45

6+
/**
7+
* The name of the meter attribute.
8+
*/
59
public String name;
610

7-
public int allowedUses;
11+
/**
12+
* The allowed uses of the meter attribute. A value of -1 indicates unlimited allowed uses.
13+
*/
14+
public long allowedUses;
815

9-
public int totalUses;
16+
/**
17+
* The total uses of the meter attribute.
18+
*/
19+
public BigInteger totalUses;
1020

11-
public int grossUses;
21+
/**
22+
* The gross uses of the meter attribute.
23+
*/
24+
public BigInteger grossUses;
1225

13-
public LicenseMeterAttribute(String name, int allowedUses, int totalUses, int grossUses) {
26+
public LicenseMeterAttribute(String name, long allowedUses, BigInteger totalUses, BigInteger grossUses) {
1427
this.name = name;
1528
this.allowedUses = allowedUses;
1629
this.totalUses = totalUses;

src/main/java/com/cryptlex/lexactivator/UserLicense.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,23 @@
22

33
public class UserLicense {
44

5-
public int allowedActivations;
5+
/**
6+
* The allowed activations of the license. A value of -1 indicates unlimited number of activations.
7+
*/
8+
public long allowedActivations;
69

7-
public int allowedDeactivations;
10+
/**
11+
* The allowed deactivations of the license. A value of -1 indicates unlimited number of deactivations.
12+
*/
13+
public long allowedDeactivations;
814

15+
/**
16+
* The license key.
17+
*/
918
public String key;
1019

20+
/**
21+
* The license type (node-locked or hosted-floating).
22+
*/
1123
public String type;
1224
}

0 commit comments

Comments
 (0)