mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-04-11 18:57:30 +03:00
[REFACTOR] Рефакторинг.
This commit is contained in:
parent
f747ef55d1
commit
39b62d20da
5 changed files with 19 additions and 42 deletions
|
@ -8,12 +8,10 @@
|
||||||
import ru.gravit.launcher.request.websockets.RequestInterface;
|
import ru.gravit.launcher.request.websockets.RequestInterface;
|
||||||
|
|
||||||
public class SetProfileRequest extends Request<SetProfileRequestEvent> implements RequestInterface {
|
public class SetProfileRequest extends Request<SetProfileRequestEvent> implements RequestInterface {
|
||||||
private transient ClientProfile profile;
|
|
||||||
@LauncherNetworkAPI
|
@LauncherNetworkAPI
|
||||||
public String client;
|
public String client;
|
||||||
|
|
||||||
public SetProfileRequest(ClientProfile profile) {
|
public SetProfileRequest(ClientProfile profile) {
|
||||||
this.profile = profile;
|
|
||||||
this.client = profile.getTitle();
|
this.client = profile.getTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
import ru.gravit.launcher.hasher.HashedEntry;
|
import ru.gravit.launcher.hasher.HashedEntry;
|
||||||
import ru.gravit.launcher.hasher.HashedFile;
|
import ru.gravit.launcher.hasher.HashedFile;
|
||||||
import ru.gravit.launcher.request.Request;
|
import ru.gravit.launcher.request.Request;
|
||||||
import ru.gravit.launcher.request.UpdateAction;
|
|
||||||
import ru.gravit.launcher.request.update.UpdateRequest.State.Callback;
|
import ru.gravit.launcher.request.update.UpdateRequest.State.Callback;
|
||||||
import ru.gravit.launcher.request.websockets.LegacyRequestBridge;
|
import ru.gravit.launcher.request.websockets.LegacyRequestBridge;
|
||||||
import ru.gravit.launcher.request.websockets.RequestInterface;
|
import ru.gravit.launcher.request.websockets.RequestInterface;
|
||||||
|
@ -26,7 +25,6 @@
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Queue;
|
|
||||||
|
|
||||||
public final class UpdateRequest extends Request<UpdateRequestEvent> implements RequestInterface {
|
public final class UpdateRequest extends Request<UpdateRequestEvent> implements RequestInterface {
|
||||||
|
|
||||||
|
@ -168,26 +166,6 @@ public double getTotalSizeMiB() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void fillActionsQueue(Queue<UpdateAction> queue, HashedDir mismatch) {
|
|
||||||
for (Entry<String, HashedEntry> mapEntry : mismatch.map().entrySet()) {
|
|
||||||
String name = mapEntry.getKey();
|
|
||||||
HashedEntry entry = mapEntry.getValue();
|
|
||||||
HashedEntry.Type entryType = entry.getType();
|
|
||||||
switch (entryType) {
|
|
||||||
case DIR: // cd - get - cd ..
|
|
||||||
queue.add(new UpdateAction(UpdateAction.Type.CD, name, entry));
|
|
||||||
fillActionsQueue(queue, (HashedDir) entry);
|
|
||||||
queue.add(UpdateAction.CD_BACK);
|
|
||||||
break;
|
|
||||||
case FILE: // get
|
|
||||||
queue.add(new UpdateAction(UpdateAction.Type.GET, name, entry));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new AssertionError("Unsupported hashed entry type: " + entryType.name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UpdateRequestEvent requestDo() throws Exception {
|
public UpdateRequestEvent requestDo() throws Exception {
|
||||||
LogHelper.debug("Start update request");
|
LogHelper.debug("Start update request");
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class ServerWrapper extends JsonConfigurable<ServerWrapper.Config> {
|
||||||
public ClassLoader loader;
|
public ClassLoader loader;
|
||||||
public ClientPermissions permissions;
|
public ClientPermissions permissions;
|
||||||
public static ServerWrapper wrapper;
|
public static ServerWrapper wrapper;
|
||||||
private static Gson gson;
|
public static Gson gson;
|
||||||
private static GsonBuilder gsonBuiler;
|
private static GsonBuilder gsonBuiler;
|
||||||
|
|
||||||
public static Path modulesDir = Paths.get(System.getProperty("serverwrapper.modulesDir", "modules"));
|
public static Path modulesDir = Paths.get(System.getProperty("serverwrapper.modulesDir", "modules"));
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package ru.gravit.launcher.server.setup;
|
package ru.gravit.launcher.server.setup;
|
||||||
|
|
||||||
import ru.gravit.launcher.LauncherConfig;
|
|
||||||
import ru.gravit.launcher.server.ServerWrapper;
|
import ru.gravit.launcher.server.ServerWrapper;
|
||||||
import ru.gravit.utils.PublicURLClassLoader;
|
import ru.gravit.utils.PublicURLClassLoader;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
@ -24,20 +23,22 @@ public void run() throws IOException {
|
||||||
System.out.println("Print jar filename:");
|
System.out.println("Print jar filename:");
|
||||||
String jarName = commands.commandHandler.readLine();
|
String jarName = commands.commandHandler.readLine();
|
||||||
Path jarPath = Paths.get(jarName);
|
Path jarPath = Paths.get(jarName);
|
||||||
JarFile file = new JarFile(jarPath.toFile());
|
String mainClassName = null;
|
||||||
URL jarURL = jarPath.toUri().toURL();
|
try (JarFile file = new JarFile(jarPath.toFile())) {
|
||||||
urlClassLoader = new PublicURLClassLoader(new URL[]{jarURL});
|
URL jarURL = jarPath.toUri().toURL();
|
||||||
LogHelper.info("Check jar MainClass");
|
urlClassLoader = new PublicURLClassLoader(new URL[]{jarURL});
|
||||||
String mainClassName = file.getManifest().getMainAttributes().getValue("Main-Class");
|
LogHelper.info("Check jar MainClass");
|
||||||
if (mainClassName == null) {
|
mainClassName = file.getManifest().getMainAttributes().getValue("Main-Class");
|
||||||
LogHelper.error("Main-Class not found in MANIFEST");
|
if (mainClassName == null) {
|
||||||
return;
|
LogHelper.error("Main-Class not found in MANIFEST");
|
||||||
}
|
return;
|
||||||
try {
|
}
|
||||||
Class mainClass = Class.forName(mainClassName, false, urlClassLoader);
|
try {
|
||||||
} catch (ClassNotFoundException e) {
|
Class.forName(mainClassName, false, urlClassLoader);
|
||||||
LogHelper.error(e);
|
} catch (ClassNotFoundException e) {
|
||||||
return;
|
LogHelper.error(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
LogHelper.info("Found MainClass %s", mainClassName);
|
LogHelper.info("Found MainClass %s", mainClassName);
|
||||||
System.out.println("Print launchserver websocket host:");
|
System.out.println("Print launchserver websocket host:");
|
||||||
|
@ -66,7 +67,6 @@ public void run() throws IOException {
|
||||||
wrapper.config.password = password;
|
wrapper.config.password = password;
|
||||||
wrapper.config.title = title;
|
wrapper.config.title = title;
|
||||||
wrapper.config.stopOnError = false;
|
wrapper.config.stopOnError = false;
|
||||||
LauncherConfig cfg = null;
|
|
||||||
|
|
||||||
if (wrapper.auth()) {
|
if (wrapper.auth()) {
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -9,8 +9,9 @@
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
public class ConfigManager {
|
public class ConfigManager {
|
||||||
private final HashMap<String, JsonConfigurable> CONFIGURABLE = new HashMap<>();
|
private final HashMap<String, JsonConfigurable> CONFIGURABLE = new HashMap<>();
|
||||||
|
|
||||||
public void registerConfigurable(String name, JsonConfigurable reconfigurable) {
|
public void registerConfigurable(String name, JsonConfigurable reconfigurable) {
|
||||||
VerifyHelper.putIfAbsent(CONFIGURABLE, name.toLowerCase(), Objects.requireNonNull(reconfigurable, "adapter"),
|
VerifyHelper.putIfAbsent(CONFIGURABLE, name.toLowerCase(), Objects.requireNonNull(reconfigurable, "adapter"),
|
||||||
|
|
Loading…
Reference in a new issue