40 lines
1.5 KiB
Java
40 lines
1.5 KiB
Java
![]() |
package io.gitlab.jfronny.glaunch.gson;
|
||
|
|
||
|
import com.google.gson.*;
|
||
|
import io.gitlab.jfronny.glaunch.model.Rules;
|
||
|
import io.gitlab.jfronny.glaunch.util.Utils;
|
||
|
|
||
|
import java.lang.reflect.Type;
|
||
|
|
||
|
public class RulesDeserializer implements JsonDeserializer<Rules> {
|
||
|
@Override
|
||
|
public Rules deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||
|
boolean valid = true;
|
||
|
for (JsonElement rule : json.getAsJsonArray()) {
|
||
|
JsonObject ro = rule.getAsJsonObject();
|
||
|
if (!ro.get("action").getAsJsonPrimitive().getAsString().equals("allow"))
|
||
|
throw new JsonParseException("Unexpected action in argument");
|
||
|
if (ro.has("features")) { //TODO support has_custom_resolution
|
||
|
valid = false;
|
||
|
continue;
|
||
|
}
|
||
|
if (ro.has("os")) {
|
||
|
JsonObject osObject = ro.get("os").getAsJsonObject();
|
||
|
if (osObject.has("name")) {
|
||
|
if (!Utils.getOs().equals(osObject.get("name").getAsString())) {
|
||
|
valid = false;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (osObject.has("version")) {
|
||
|
if (!System.getProperty("os.version").matches(osObject.get("version").getAsString())) {
|
||
|
valid = false;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return new Rules(valid);
|
||
|
}
|
||
|
}
|