diff --git a/Launcher/runtime/dialog/scenes/options/options.js b/Launcher/runtime/dialog/scenes/options/options.js index b7749643..88fa0b9c 100644 --- a/Launcher/runtime/dialog/scenes/options/options.js +++ b/Launcher/runtime/dialog/scenes/options/options.js @@ -131,6 +131,7 @@ var options = { } options.update(); }); + testMod.setFocusTraversable(false); checkBoxList.add(testMod); testMod.getStyleClass().add("modname"); if(modDescription != "") { diff --git a/LauncherCore/src/main/java/ru/gravit/launcher/managers/GsonManager.java b/LauncherCore/src/main/java/ru/gravit/launcher/managers/GsonManager.java index bf89bb33..bf93aafd 100644 --- a/LauncherCore/src/main/java/ru/gravit/launcher/managers/GsonManager.java +++ b/LauncherCore/src/main/java/ru/gravit/launcher/managers/GsonManager.java @@ -4,6 +4,7 @@ import com.google.gson.GsonBuilder; import ru.gravit.launcher.hasher.HashedEntry; import ru.gravit.launcher.hasher.HashedEntryAdapter; +import ru.gravit.utils.helper.CommonHelper; public class GsonManager { public GsonBuilder gsonBuilder; @@ -12,8 +13,8 @@ public class GsonManager { public Gson configGson; public void initGson() { - gsonBuilder = new GsonBuilder(); - configGsonBuilder = new GsonBuilder(); + gsonBuilder = CommonHelper.newBuilder(); + configGsonBuilder = CommonHelper.newBuilder(); configGsonBuilder.setPrettyPrinting(); registerAdapters(gsonBuilder); registerAdapters(configGsonBuilder); diff --git a/LauncherCore/src/main/java/ru/gravit/utils/helper/CommonHelper.java b/LauncherCore/src/main/java/ru/gravit/utils/helper/CommonHelper.java index 5f7548e3..11e00272 100644 --- a/LauncherCore/src/main/java/ru/gravit/utils/helper/CommonHelper.java +++ b/LauncherCore/src/main/java/ru/gravit/utils/helper/CommonHelper.java @@ -6,6 +6,18 @@ import javax.script.ScriptEngine; import javax.script.ScriptEngineFactory; import javax.script.ScriptEngineManager; + +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; +import java.util.Base64; import java.util.Collection; import java.util.LinkedList; import java.util.Locale; @@ -120,4 +132,23 @@ public static String[] parseCommand(CharSequence line) throws CommandException { // Return result as array return result.toArray(new String[0]); } + + @LauncherAPI + public static GsonBuilder newBuilder() { + return new GsonBuilder().registerTypeHierarchyAdapter(byte[].class, + ByteArrayToBase64TypeAdapter.INSTANCE); + } + + private static class ByteArrayToBase64TypeAdapter implements JsonSerializer, JsonDeserializer { + private static final ByteArrayToBase64TypeAdapter INSTANCE = new ByteArrayToBase64TypeAdapter(); + private Base64.Decoder decoder = Base64.getUrlDecoder(); + private Base64.Encoder encoder = Base64.getUrlEncoder(); + public byte[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + return decoder.decode(json.getAsString()); + } + + public JsonElement serialize(byte[] src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(encoder.encodeToString(src)); + } + } }