Skip to content

Commit d72bbe7

Browse files
committed
Support the new machine code method in IsOnRightMachine
1 parent f7ee321 commit d72bbe7

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

src/main/java/io/cryptolens/methods/Helpers.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public static String GetMachineCode(int v) {
106106
public static boolean IsOnRightMachine(LicenseKey license) {
107107
return IsOnRightMachine(license, false);
108108
}
109-
109+
110110
/**
111111
* Check if the device is registered with the license key.
112112
* @param license The license key object.
@@ -118,6 +118,32 @@ public static boolean IsOnRightMachine(LicenseKey license, boolean isFloatingLic
118118
return IsOnRightMachine(license, isFloatingLicense, false);
119119
}
120120

121+
/**
122+
* Check if the device is registered with the license key.
123+
* @param license The license key object.
124+
* @param v If set to 2, this method will use the UUID of the device instead of depending
125+
* on slf4j. Note, it currently only supports Windows. You can read more
126+
* here: https://help.cryptolens.io/faq/index#java.
127+
* @return True if the license is registered with this machine and False otherwise.
128+
*/
129+
public static boolean IsOnRightMachine(LicenseKey license, int v) {
130+
return IsOnRightMachine(license, v, false);
131+
}
132+
133+
/**
134+
* Check if the device is registered with the license key.
135+
* @param license The license key object.
136+
* @param isFloatingLicense If this is a floating license, this parameter has to be set to true.
137+
* You can enable floating licenses by setting @see ActivateModel.FloatingTimeInterval.
138+
* @param v If set to 2, this method will use the UUID of the device instead of depending
139+
* on slf4j. Note, it currently only supports Windows. You can read more
140+
* here: https://help.cryptolens.io/faq/index#java.
141+
* @return True if the license is registered with this machine and False otherwise.
142+
*/
143+
public static boolean IsOnRightMachine(LicenseKey license, int v, boolean isFloatingLicense) {
144+
return IsOnRightMachine(license, v, isFloatingLicense, false);
145+
}
146+
121147
/**
122148
* Check if the device is registered with the license key.
123149
* @param license The license key object
@@ -134,6 +160,26 @@ public static boolean IsOnRightMachine(LicenseKey license, boolean isFloatingLic
134160
return IsOnRightMachine(license, current_mid, isFloatingLicense, allowOverdraft);
135161
}
136162

163+
/**
164+
* Check if the device is registered with the license key.
165+
* @param license The license key object.
166+
* @param v If set to 2, this method will use the UUID of the device instead of depending
167+
* on slf4j. Note, it currently only supports Windows. You can read more
168+
* here: https://help.cryptolens.io/faq/index#java.
169+
* @param isFloatingLicense If this is a floating license, this parameter has to be set to true.
170+
* You can enable floating licenses by setting @see ActivateModel.FloatingTimeInterval.
171+
* @param allowOverdraft If floating licensing is enabled with overdraft, this parameter should be set to true.
172+
* You can enable overdraft by setting ActivateModel.MaxOverdraft" to a value greater than 0.
173+
* @return True if the license is registered with this machine and False otherwise.
174+
*/
175+
public static boolean IsOnRightMachine(LicenseKey license, int v, boolean isFloatingLicense, boolean allowOverdraft) {
176+
177+
String current_mid = Helpers.GetMachineCode(v);
178+
179+
return IsOnRightMachine(license, current_mid, isFloatingLicense, allowOverdraft);
180+
}
181+
182+
137183

138184
/**
139185
* Check if the device is registered with the license key. This method is useful for platforms where the

src/test/java/io/cryptolens/HelpersTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package io.cryptolens;
22

33
import io.cryptolens.methods.Helpers;
4+
import io.cryptolens.models.ActivatedMachine;
45
import io.cryptolens.models.DataObject;
56
import io.cryptolens.models.LicenseKey;
67
import junit.framework.Test;
78
import junit.framework.TestCase;
89
import junit.framework.TestSuite;
910

11+
import java.io.BufferedReader;
12+
import java.io.IOException;
13+
import java.io.InputStreamReader;
1014
import java.util.ArrayList;
1115

1216
/**
@@ -64,5 +68,25 @@ public void testApp()
6468

6569
String[] featurePath = "moduleA.video".split(".");
6670

71+
}
72+
73+
public void testMachineCode() throws IOException {
74+
75+
Helpers.GetMachineCode();
76+
77+
String mc = Helpers.GetMachineCode(2);
78+
79+
LicenseKey license = new LicenseKey();
80+
license.ActivatedMachines = new ArrayList<>();
81+
ActivatedMachine machine = new ActivatedMachine();
82+
machine.Mid = mc;
83+
license.ActivatedMachines.add(machine);
84+
85+
Helpers.IsOnRightMachine(license, 2);
86+
87+
assertTrue(Helpers.IsOnRightMachine(license, 2));
88+
89+
90+
6791
}
6892
}

0 commit comments

Comments
 (0)