diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 865c1963..3e35b5ea 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -5,10 +5,6 @@ import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.managers.GarbageManager; import ru.gravit.launcher.profiles.ClientProfile; -import ru.gravit.launcher.serialize.config.ConfigObject; -import ru.gravit.launcher.serialize.config.TextConfigReader; -import ru.gravit.launcher.serialize.config.TextConfigWriter; -import ru.gravit.launcher.serialize.config.entry.*; import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.launchserver.auth.AuthLimiter; import ru.gravit.launchserver.auth.handler.AuthHandler; @@ -138,9 +134,9 @@ public static class ExeConf { } private final class ProfilesFileVisitor extends SimpleFileVisitor { - private final Collection> result; + private final Collection result; - private ProfilesFileVisitor(Collection> result) { + private ProfilesFileVisitor(Collection result) { this.result = result; } @@ -151,12 +147,12 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO // Read profile ClientProfile profile; try (BufferedReader reader = IOHelper.newReader(file)) { - profile = new ClientProfile(TextConfigReader.read(reader, true)); + profile = Launcher.gson.fromJson(reader,ClientProfile.class); } profile.verify(); // Add SIGNED profile to result list - result.add(new SignedObjectHolder<>(profile, privateKey)); + result.add(profile); return super.visitFile(file, attrs); } } @@ -240,7 +236,7 @@ public static void main(String... args) throws Throwable { private final AtomicBoolean started = new AtomicBoolean(false); // Updates and profiles - private volatile List> profilesList; + private volatile List profilesList; public volatile Map> updatesDirMap; @@ -308,7 +304,7 @@ public LaunchServer(Path dir) throws IOException, InvalidKeySpecException { generateConfigIfNotExists(); LogHelper.info("Reading LaunchServer config file"); try (BufferedReader reader = IOHelper.newReader(configFile)) { - config = new Config(TextConfigReader.read(reader, true), dir, this); + config = Launcher.gson.fromJson(reader,Config.class); } config.verify(); @@ -399,7 +395,7 @@ private void generateConfigIfNotExists() throws IOException { LogHelper.info("Creating LaunchServer config"); Config newConfig; try (BufferedReader reader = IOHelper.newReader(IOHelper.getResourceURL("ru/gravit/launchserver/defaults/config.cfg"))) { - newConfig = new Config(TextConfigReader.read(reader, false), dir, this); + newConfig = Launcher.gson.fromJson(reader,Config.class); } // Set server address @@ -409,13 +405,13 @@ private void generateConfigIfNotExists() throws IOException { // Write LaunchServer config LogHelper.info("Writing LaunchServer config file"); try (BufferedWriter writer = IOHelper.newWriter(configFile)) { - TextConfigWriter.write(newConfig.block, writer, true); + Launcher.gson.toJson(newConfig,writer); } } @SuppressWarnings("ReturnOfCollectionOrArrayField") - public Collection> getProfiles() { + public Collection getProfiles() { return profilesList; } @@ -464,11 +460,11 @@ public void syncLauncherBinaries() throws IOException { public void syncProfilesDir() throws IOException { LogHelper.info("Syncing profiles dir"); - List> newProfies = new LinkedList<>(); + List newProfies = new LinkedList<>(); IOHelper.walk(profilesDir, new ProfilesFileVisitor(newProfies), false); // Sort and set new profiles - newProfies.sort(Comparator.comparing(a -> a.object)); + newProfies.sort(Comparator.comparing(a -> a)); profilesList = Collections.unmodifiableList(newProfies); } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/ProfilesRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/ProfilesRequest.java index a009d8b5..c15f06f3 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/ProfilesRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/ProfilesRequest.java @@ -17,9 +17,9 @@ public final class ProfilesRequest extends Request { public static final class Result { @LauncherAPI - public final List> profiles; + public final List profiles; - private Result(List> profiles) { + private Result(List profiles) { this.profiles = Collections.unmodifiableList(profiles); } } @@ -46,7 +46,7 @@ protected Result requestDo(HInput input, HOutput output) throws Exception { readError(input); int count = input.readLength(0); - List> profiles = new ArrayList<>(count); + List profiles = new ArrayList<>(count); for (int i = 0; i < count; i++) profiles.add(new SignedObjectHolder<>(input, config.publicKey, ClientProfile.RO_ADAPTER)); diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java index 43427bcd..242960aa 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java @@ -8,14 +8,6 @@ import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.request.auth.AuthServerRequest; import ru.gravit.launcher.request.update.ProfilesRequest; -import ru.gravit.launcher.serialize.config.ConfigObject; -import ru.gravit.launcher.serialize.config.TextConfigReader; -import ru.gravit.launcher.serialize.config.TextConfigWriter; -import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; -import ru.gravit.launcher.serialize.config.entry.BooleanConfigEntry; -import ru.gravit.launcher.serialize.config.entry.IntegerConfigEntry; -import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; -import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.IOHelper; @@ -50,11 +42,11 @@ public static boolean auth(ServerWrapper wrapper) { Boolean auth = new AuthServerRequest(cfg, config.login, SecurityHelper.newRSAEncryptCipher(cfg.publicKey).doFinal(IOHelper.encode(config.password)), 0, config.title).request(); if (auth == null) throw new Exception("Non auth!"); // security check ProfilesRequest.Result result = new ProfilesRequest(cfg).request(); - for (SignedObjectHolder p : result.profiles) { - LogHelper.debug("Get profile: %s", p.object.getTitle()); - if (p.object.getTitle().equals(config.title)) { - wrapper.profile = p.object; - Launcher.profile = p.object; + for (ClientProfile p : result.profiles) { + LogHelper.debug("Get profile: %s", p.getTitle()); + if (p.getTitle().equals(config.title)) { + wrapper.profile = p; + Launcher.profile = p; LogHelper.debug("Found profile: %s", Launcher.profile.getTitle()); break; } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java index 1dbdcbdb..a8c147f0 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java @@ -1,5 +1,7 @@ package ru.gravit.launcher; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import ru.gravit.launcher.modules.ModulesManagerInterface; import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.serialize.HInput; @@ -61,6 +63,8 @@ public final class Launcher { public static int PATCH = 0; public static int BUILD = 3; public static Version.Type RELEASE = Version.Type.DEV; + public static GsonBuilder gsonBuilder; + public static Gson gson; @LauncherAPI public static LauncherConfig getConfig() {