11package io .cryptolens .methods ;
22
3- import com .google .gson .Gson ;
43import com .google .gson .JsonArray ;
54import com .google .gson .JsonParser ;
6- import com . google . gson . reflect . TypeToken ;
5+
76import io .cryptolens .internal .BasicResult ;
87import io .cryptolens .models .ActivatedMachine ;
98import io .cryptolens .models .LicenseKey ;
1312import oshi .hardware .HardwareAbstractionLayer ;
1413import oshi .software .os .OperatingSystem ;
1514
16- import java .lang .reflect .Type ;
1715import java .nio .charset .StandardCharsets ;
1816import java .security .MessageDigest ;
19- import java .util .HashMap ;
20- import java .util .HashSet ;
17+
2118
2219/**
2320 * A collection of helper methods that operate on a license key.
@@ -209,10 +206,11 @@ public class MyClass<T>
209206
210207 /**
211208 * <p>Uses the notes field to determine if a certain feature exists (instead of the 8 feature flags).</p>
212- * <p><strong>Formatting: </strong> <p>The notes field needs to be formatted as a JSON array of strings or objects that contain </p>
213- * For example, ["f1", "f2"] means f1 and f2 are true. You can also have feature bundling, eg. ["f1", {"f2": ["voice","image"]}],
209+ * <p><strong>Formatting: </strong> <p>The notes field needs to be formatted as a JSON array of strings or of JSON arrays
210+ * where the first element specifies the feature name and the second element is a list of features.</p>
211+ * For example, ["f1", "f2"] means f1 and f2 are true. You can also have feature bundling, eg. ["f1", ["f2",["voice","image"]]],
214212 * which means that f1 and f2 are true, as well as f2.limited and f2.image. You can set any depth, eg. you can have
215- * ["f1", { "f2":[{ "voice": ["all"]} , "image"]} ] means f2.voice.all is true as well as f2.voice and f2.
213+ * ["f1", [ "f2",[[ "voice", ["all"]] , "image"]] ] means f2.voice.all is true as well as f2.voice and f2.
216214 * The dots symbol is used to specify the "sub-features".
217215 * </p>
218216 * @param licenseKey a license key object.
@@ -227,13 +225,14 @@ public static boolean HasFeature(LicenseKey licenseKey, String featureName) {
227225
228226 boolean found = false ;
229227 for (int i = 0 ; i < featurePath .length ; i ++) {
228+ found = false ;
230229 int index = -1 ;
231230 for (int j = 0 ; j < array .size (); j ++) {
232231
233- if (!array .get (j ).isJsonObject () && array .get (j ).getAsString ().equals (featurePath [i ])) {
232+ if (!array .get (j ).isJsonArray () && array .get (j ).getAsString ().equals (featurePath [i ])) {
234233 found = true ;
235234 break ;
236- } else if (array .get (j ).isJsonObject () && array .get (j ).getAsJsonObject ().keySet (). contains (featurePath [i ])){
235+ } else if (array .get (j ).isJsonArray () && array .get (j ).getAsJsonArray ().get ( 0 ). getAsString (). equals (featurePath [i ])){
237236 found = true ;
238237 index = j ;
239238 break ;
@@ -244,8 +243,9 @@ public static boolean HasFeature(LicenseKey licenseKey, String featureName) {
244243 }
245244 if (i + 1 < featurePath .length && index != -1 ) {
246245 // still have some sub features to go through.
247- array = array .get (index ).getAsJsonObject ().get (featurePath [i ]).getAsJsonArray ();
248- found = false ;
246+ // TODO: need to check if it's actually a json array or null?
247+ // TODO: try catch
248+ array = array .get (index ).getAsJsonArray ().get (1 ).getAsJsonArray ();
249249 }
250250 }
251251
0 commit comments