mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
Разделение на человекочитаемый gson и машинный
This commit is contained in:
parent
7e97915fd1
commit
8df7d148da
4 changed files with 28 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
|||
package ru.gravit.launchserver;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.annotations.Expose;
|
||||
import ru.gravit.launcher.Launcher;
|
||||
|
@ -262,6 +263,9 @@ public static void main(String... args) throws Throwable {
|
|||
|
||||
public volatile Map<String, SignedObjectHolder<HashedDir>> updatesDirMap;
|
||||
|
||||
public static Gson gson;
|
||||
public static GsonBuilder gsonBuilder;
|
||||
|
||||
public LaunchServer(Path dir) throws IOException, InvalidKeySpecException {
|
||||
// Setup config locations
|
||||
this.dir = dir;
|
||||
|
@ -380,12 +384,20 @@ public static void initGson()
|
|||
{
|
||||
if(Launcher.gson != null) return;
|
||||
Launcher.gsonBuilder = new GsonBuilder();
|
||||
Launcher.gsonBuilder.setPrettyPrinting();
|
||||
Launcher.gsonBuilder.registerTypeAdapter(AuthProvider.class, new AuthProviderAdapter());
|
||||
Launcher.gsonBuilder.registerTypeAdapter(TextureProvider.class, new TextureProviderAdapter());
|
||||
Launcher.gsonBuilder.registerTypeAdapter(AuthHandler.class, new AuthHandlerAdapter());
|
||||
Launcher.gsonBuilder.registerTypeAdapter(HWIDHandler.class, new HWIDHandlerAdapter());
|
||||
Launcher.gson = Launcher.gsonBuilder.create();
|
||||
|
||||
//Human readable
|
||||
LaunchServer.gsonBuilder = new GsonBuilder();
|
||||
LaunchServer.gsonBuilder.setPrettyPrinting();
|
||||
LaunchServer.gsonBuilder.registerTypeAdapter(AuthProvider.class, new AuthProviderAdapter());
|
||||
LaunchServer.gsonBuilder.registerTypeAdapter(TextureProvider.class, new TextureProviderAdapter());
|
||||
LaunchServer.gsonBuilder.registerTypeAdapter(AuthHandler.class, new AuthHandlerAdapter());
|
||||
LaunchServer.gsonBuilder.registerTypeAdapter(HWIDHandler.class, new HWIDHandlerAdapter());
|
||||
LaunchServer.gson = LaunchServer.gsonBuilder.create();
|
||||
}
|
||||
|
||||
private LauncherBinary binary() {
|
||||
|
@ -454,7 +466,7 @@ private void generateConfigIfNotExists() throws IOException {
|
|||
// Write LaunchServer config
|
||||
LogHelper.info("Writing LaunchServer config file");
|
||||
try (BufferedWriter writer = IOHelper.newWriter(configFile)) {
|
||||
Launcher.gson.toJson(newConfig,writer);
|
||||
LaunchServer.gson.toJson(newConfig,writer);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public void invoke(String... args) throws Exception {
|
|||
ClientProfile profile = new ClientProfile("1.7.10","asset1.7.10",0,"Test1.7.10","localhost",25565,true,false,"net.minecraft.launchwrapper.Launch");
|
||||
try(Writer writer = IOHelper.newWriter(LaunchServer.server.dir.resolve("profiles").resolve("Test.cfg")))
|
||||
{
|
||||
Launcher.gson.toJson(profile,writer);
|
||||
LaunchServer.gson.toJson(profile,writer);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
import ru.gravit.launchserver.command.Command;
|
||||
import ru.gravit.launchserver.socket.Client;
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
|
@ -35,17 +36,25 @@ public void invoke(String... args) throws Exception {
|
|||
verifyArgs(args,2);
|
||||
if(args[0].equals("unload"))
|
||||
{
|
||||
LogHelper.info("Sessions write to %s",args[1]);
|
||||
Set<Client> clientSet = server.sessionManager.getSessions();
|
||||
try(Writer writer = IOHelper.newWriter(Paths.get(args[1])))
|
||||
{
|
||||
Launcher.gson.toJson(server.sessionManager.getSessions(),writer);
|
||||
LaunchServer.gson.toJson(clientSet,writer);
|
||||
}
|
||||
LogHelper.subInfo("Write %d sessions",clientSet.size());
|
||||
} else if(args[0].equals("load"))
|
||||
{
|
||||
LogHelper.info("Sessions read from %s",args[1]);
|
||||
int size = 0;
|
||||
try(Reader reader = IOHelper.newReader(Paths.get(args[1])))
|
||||
{
|
||||
Type setType = new TypeToken<HashSet<Client>>(){}.getType();
|
||||
server.sessionManager.loadSessions(Launcher.gson.fromJson(reader,setType));
|
||||
Set<Client> clientSet = LaunchServer.gson.fromJson(reader,setType);
|
||||
size = clientSet.size();
|
||||
server.sessionManager.loadSessions(clientSet);
|
||||
}
|
||||
LogHelper.subInfo("Readed %d sessions",size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,13 +53,13 @@ public void invoke(String... args) throws IOException, CommandException {
|
|||
ClientProfile client;
|
||||
String profilePath = String.format("ru/gravit/launchserver/defaults/profile%s.cfg", version.name);
|
||||
try (BufferedReader reader = IOHelper.newReader(IOHelper.getResourceURL(profilePath))) {
|
||||
client = Launcher.gson.fromJson(reader,ClientProfile.class);
|
||||
client = LaunchServer.gson.fromJson(reader,ClientProfile.class);
|
||||
}
|
||||
client.setTitle(dirName);
|
||||
client.setDir(dirName);
|
||||
try (BufferedWriter writer = IOHelper.newWriter(IOHelper.resolveIncremental(server.profilesDir,
|
||||
dirName, "cfg"))) {
|
||||
Launcher.gson.toJson(client,writer);
|
||||
LaunchServer.gson.toJson(client,writer);
|
||||
}
|
||||
|
||||
// Finished
|
||||
|
|
Loading…
Reference in a new issue