mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[ANY] Рефакторинг
This commit is contained in:
parent
3bfed5c3c7
commit
dcf9a56c01
12 changed files with 22 additions and 24 deletions
|
@ -1,6 +1,5 @@
|
||||||
package pro.gravit.launchserver.binary.tasks;
|
package pro.gravit.launchserver.binary.tasks;
|
||||||
|
|
||||||
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
|
|
||||||
import org.bouncycastle.asn1.x500.X500Name;
|
import org.bouncycastle.asn1.x500.X500Name;
|
||||||
import org.bouncycastle.asn1.x500.X500NameBuilder;
|
import org.bouncycastle.asn1.x500.X500NameBuilder;
|
||||||
import org.bouncycastle.asn1.x500.style.BCStyle;
|
import org.bouncycastle.asn1.x500.style.BCStyle;
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
import pro.gravit.launcher.managers.ClientGsonManager;
|
import pro.gravit.launcher.managers.ClientGsonManager;
|
||||||
import pro.gravit.launcher.managers.ClientHookManager;
|
import pro.gravit.launcher.managers.ClientHookManager;
|
||||||
import pro.gravit.launcher.managers.ConsoleManager;
|
import pro.gravit.launcher.managers.ConsoleManager;
|
||||||
import pro.gravit.launcher.modules.events.ClosePhase;
|
|
||||||
import pro.gravit.launcher.modules.events.PreConfigPhase;
|
import pro.gravit.launcher.modules.events.PreConfigPhase;
|
||||||
import pro.gravit.launcher.request.Request;
|
import pro.gravit.launcher.request.Request;
|
||||||
import pro.gravit.launcher.request.RequestException;
|
import pro.gravit.launcher.request.RequestException;
|
||||||
|
@ -88,7 +87,7 @@ public static void main(String... args) throws Throwable {
|
||||||
ConsoleManager.initConsole();
|
ConsoleManager.initConsole();
|
||||||
HWIDProvider.registerHWIDs();
|
HWIDProvider.registerHWIDs();
|
||||||
LauncherEngine.modulesManager.invokeEvent(new PreConfigPhase());
|
LauncherEngine.modulesManager.invokeEvent(new PreConfigPhase());
|
||||||
LauncherConfig config = Launcher.getConfig();
|
Launcher.getConfig(); // init config
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
new LauncherEngine().start(args);
|
new LauncherEngine().start(args);
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
import pro.gravit.launcher.client.UserSettings;
|
import pro.gravit.launcher.client.UserSettings;
|
||||||
import pro.gravit.launcher.hasher.HashedDir;
|
import pro.gravit.launcher.hasher.HashedDir;
|
||||||
import pro.gravit.launcher.profiles.ClientProfile;
|
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
import pro.gravit.launcher.serialize.HOutput;
|
import pro.gravit.launcher.serialize.HOutput;
|
||||||
import pro.gravit.launcher.serialize.stream.StreamObject;
|
import pro.gravit.launcher.serialize.stream.StreamObject;
|
||||||
import pro.gravit.launcher.utils.DirWatcher;
|
import pro.gravit.launcher.utils.DirWatcher;
|
||||||
import pro.gravit.launcher.utils.NativeJVMHalt;
|
|
||||||
import pro.gravit.utils.PublicURLClassLoader;
|
|
||||||
import pro.gravit.utils.Version;
|
import pro.gravit.utils.Version;
|
||||||
import pro.gravit.utils.helper.*;
|
import pro.gravit.utils.helper.*;
|
||||||
import pro.gravit.utils.helper.JVMHelper.OS;
|
import pro.gravit.utils.helper.JVMHelper.OS;
|
||||||
|
|
|
@ -5,18 +5,15 @@
|
||||||
import pro.gravit.launcher.hasher.HashedDir;
|
import pro.gravit.launcher.hasher.HashedDir;
|
||||||
import pro.gravit.launcher.hasher.HashedEntry;
|
import pro.gravit.launcher.hasher.HashedEntry;
|
||||||
import pro.gravit.launcher.hasher.HashedFile;
|
import pro.gravit.launcher.hasher.HashedFile;
|
||||||
import pro.gravit.launcher.managers.SettingsManager;
|
|
||||||
import pro.gravit.launcher.request.update.UpdateRequest;
|
import pro.gravit.launcher.request.update.UpdateRequest;
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class LauncherUpdateController {
|
public class LauncherUpdateController {
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
import pro.gravit.utils.PublicURLClassLoader;
|
import pro.gravit.utils.PublicURLClassLoader;
|
||||||
import pro.gravit.utils.Version;
|
import pro.gravit.utils.Version;
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
import pro.gravit.utils.helper.JVMHelper;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
import pro.gravit.launcher.LauncherTrustManager;
|
import pro.gravit.launcher.LauncherTrustManager;
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,6 @@ public R request(StdWebSocketService service) throws Exception {
|
||||||
return requestDo(service);
|
return requestDo(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
protected R requestDo(StdWebSocketService service) throws Exception {
|
protected R requestDo(StdWebSocketService service) throws Exception {
|
||||||
return service.requestSync(this);
|
return service.requestSync(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
public abstract class ClientWebSocketService extends ClientJSONPoint {
|
public abstract class ClientWebSocketService extends ClientJSONPoint {
|
||||||
public final Gson gson;
|
public final Gson gson;
|
||||||
|
|
|
@ -18,7 +18,8 @@
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
public class StdWebSocketService extends ClientWebSocketService {
|
public class StdWebSocketService extends ClientWebSocketService {
|
||||||
private final ConcurrentHashMap<UUID, CompletableFuture> futureMap = new ConcurrentHashMap<>();
|
@SuppressWarnings("rawtypes")
|
||||||
|
private final ConcurrentHashMap<UUID, CompletableFuture> futureMap = new ConcurrentHashMap<>();
|
||||||
private final HashSet<EventHandler> eventHandlers = new HashSet<>();
|
private final HashSet<EventHandler> eventHandlers = new HashSet<>();
|
||||||
public void registerEventHandler(EventHandler handler)
|
public void registerEventHandler(EventHandler handler)
|
||||||
{
|
{
|
||||||
|
@ -50,7 +51,8 @@ public<T extends WebSocketEvent> void eventHandle(T webSocketEvent) {
|
||||||
processEventHandlers(webSocketEvent);
|
processEventHandlers(webSocketEvent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CompletableFuture future = futureMap.get(event.requestUUID);
|
@SuppressWarnings("rawtypes")
|
||||||
|
CompletableFuture future = futureMap.get(event.requestUUID);
|
||||||
if(future != null) {
|
if(future != null) {
|
||||||
if (event instanceof ErrorRequestEvent) {
|
if (event instanceof ErrorRequestEvent) {
|
||||||
future.completeExceptionally(new RequestException(((ErrorRequestEvent) event).error));
|
future.completeExceptionally(new RequestException(((ErrorRequestEvent) event).error));
|
||||||
|
|
|
@ -17,12 +17,13 @@
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
public class AsyncDownloader {
|
public class AsyncDownloader {
|
||||||
|
public static final Callback IGNORE = (ignored) -> {};
|
||||||
public AsyncDownloader(Callback callback) {
|
public AsyncDownloader(Callback callback) {
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AsyncDownloader() {
|
public AsyncDownloader() {
|
||||||
callback = (ignored) -> {};
|
callback = IGNORE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
|
@ -33,11 +34,18 @@ public interface Callback
|
||||||
public final Callback callback;
|
public final Callback callback;
|
||||||
public static class SizedFile
|
public static class SizedFile
|
||||||
{
|
{
|
||||||
public final String path;
|
public final String urlPath, filePath;
|
||||||
public final long size;
|
public final long size;
|
||||||
|
|
||||||
public SizedFile(String path, long size) {
|
public SizedFile(String path, long size) {
|
||||||
this.path = path;
|
this.urlPath = path;
|
||||||
|
this.filePath = path;
|
||||||
|
this.size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SizedFile(String urlPath, String filePath, long size) {
|
||||||
|
this.urlPath = urlPath;
|
||||||
|
this.filePath = filePath;
|
||||||
this.size = size;
|
this.size = size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,8 +75,8 @@ public void downloadListInOneThread(List<SizedFile> files, String baseURL, Path
|
||||||
String path = baseUri.getPath();
|
String path = baseUri.getPath();
|
||||||
for(AsyncDownloader.SizedFile currentFile : files)
|
for(AsyncDownloader.SizedFile currentFile : files)
|
||||||
{
|
{
|
||||||
URL url = new URI(scheme,host,path + currentFile.path, "", "").toURL();
|
URL url = new URI(scheme, host, path + currentFile.urlPath, "", "").toURL();
|
||||||
downloadFile(url, targetDir.resolve(currentFile.path), currentFile.size);
|
downloadFile(url, targetDir.resolve(currentFile.filePath), currentFile.size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public List<List<SizedFile>> sortFiles(List<SizedFile> files, int threads)
|
public List<List<SizedFile>> sortFiles(List<SizedFile> files, int threads)
|
||||||
|
@ -90,7 +98,8 @@ public List<List<SizedFile>> sortFiles(List<SizedFile> files, int threads)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture[] runDownloadList(List<List<SizedFile>> files, String baseURL, Path targetDir, Executor executor) {
|
@SuppressWarnings("rawtypes")
|
||||||
|
public CompletableFuture[] runDownloadList(List<List<SizedFile>> files, String baseURL, Path targetDir, Executor executor) {
|
||||||
int threads = files.size();
|
int threads = files.size();
|
||||||
CompletableFuture[] futures = new CompletableFuture[threads];
|
CompletableFuture[] futures = new CompletableFuture[threads];
|
||||||
for(int i=0;i<threads;++i)
|
for(int i=0;i<threads;++i)
|
||||||
|
|
|
@ -2,12 +2,10 @@
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
2
modules
2
modules
|
@ -1 +1 @@
|
||||||
Subproject commit 3bee30b78fb6a2e92fc97e3b6a257a8c4e9d4d54
|
Subproject commit c3ce7d13bf9b31a6121b35198059d7289f855d0f
|
Loading…
Reference in a new issue