From fd54f4739fa3571c14ec230d7c84a210af3f6ac1 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 4 Dec 2019 22:45:24 +0700 Subject: [PATCH 1/8] =?UTF-8?q?[FEATURE]=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BB=D0=B8=D1=88=D0=BD=D0=B5=D0=B3=D0=BE?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launcher/LauncherEngine.java | 2 - .../launcher/client/ClientLauncher.java | 9 +- .../launcher/client/ClientProcessBuilder.java | 2 +- .../pro/gravit/launcher/client/DirBridge.java | 2 + .../launcher/client/FunctionalBridge.java | 144 ------------------ 5 files changed, 11 insertions(+), 148 deletions(-) delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 87c67a80..0f9d5895 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -166,8 +166,6 @@ public void start(String... args) throws Throwable { LauncherEngine.modulesManager.invokeEvent(new ClientEngineInitPhase(this)); runtimeProvider.preLoad(); LauncherGuardManager.initGuard(false); - FunctionalBridge.getHWID = CommonHelper.newThread("GetHWID Thread", true, FunctionalBridge::getHWID); - FunctionalBridge.getHWID.start(); LogHelper.debug("Dir: %s", DirBridge.dir); runtimeProvider.run(args); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 4171e7ca..c0ce62b8 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -10,6 +10,7 @@ import pro.gravit.launcher.hasher.FileNameMatcher; import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.hwid.HWIDProvider; +import pro.gravit.launcher.hwid.OshiHWIDProvider; import pro.gravit.launcher.managers.ClientGsonManager; import pro.gravit.launcher.managers.ClientHookManager; import pro.gravit.launcher.modules.events.PreConfigPhase; @@ -48,6 +49,12 @@ import java.util.stream.Stream; public final class ClientLauncher { + + @LauncherAPI + public static int getClientJVMBits() { + return LauncherGuardManager.guard.getClientJVMBits(); + } + private static final class ClassPathFileVisitor extends SimpleFileVisitor { private final Stream.Builder result; @@ -327,7 +334,7 @@ public static Process launch( context.playerProfile = params.pp; context.args.add(javaBin.toString()); context.args.add(MAGICAL_INTEL_OPTION); - if (params.ram > 0 && params.ram <= FunctionalBridge.getJVMTotalMemory()) { + if (params.ram > 0) { context.args.add("-Xms" + params.ram + 'M'); context.args.add("-Xmx" + params.ram + 'M'); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java index f658b4fb..c51b3938 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java @@ -88,7 +88,7 @@ public ClientLauncherContext build() throws IOException { context.args.add(MAGICAL_INTEL_OPTION); context.params = params; if(paramsWriter != null) paramsWriter.write(context); - if (params.ram > 0 && params.ram <= FunctionalBridge.getJVMTotalMemory()) { + if (params.ram > 0) { context.args.add("-Xms" + params.ram + 'M'); context.args.add("-Xmx" + params.ram + 'M'); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java b/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java index 6e4ff2dd..f33fe32e 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java @@ -106,6 +106,8 @@ public static void setUseLegacyDir(boolean b) { try { DirBridge.dir = getLauncherDir(projectName); if (!IOHelper.exists(DirBridge.dir)) Files.createDirectories(DirBridge.dir); + DirBridge.defaultUpdatesDir = DirBridge.dir.resolve("updates"); + if (!IOHelper.exists(DirBridge.defaultUpdatesDir)) Files.createDirectories(DirBridge.defaultUpdatesDir); DirBridge.dirStore = getStoreDir(projectName); if (!IOHelper.exists(DirBridge.dirStore)) Files.createDirectories(DirBridge.dirStore); DirBridge.dirProjectStore = getProjectStoreDir(projectName); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java b/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java deleted file mode 100644 index 9b42be65..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java +++ /dev/null @@ -1,144 +0,0 @@ -package pro.gravit.launcher.client; - -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherAPI; -import pro.gravit.launcher.api.AuthService; -import pro.gravit.launcher.events.request.AuthRequestEvent; -import pro.gravit.launcher.guard.LauncherGuardManager; -import pro.gravit.launcher.hasher.FileNameMatcher; -import pro.gravit.launcher.hasher.HashedDir; -import pro.gravit.launcher.hwid.HWID; -import pro.gravit.launcher.hwid.OshiHWIDProvider; -import pro.gravit.launcher.managers.ConsoleManager; -import pro.gravit.launcher.managers.HasherManager; -import pro.gravit.launcher.managers.HasherStore; -import pro.gravit.launcher.request.Request; -import pro.gravit.utils.Version; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.helper.SecurityHelper; - -import java.nio.file.Path; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -public class FunctionalBridge { - @LauncherAPI - public static final ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(0); - @LauncherAPI - public static OshiHWIDProvider hwidProvider; - @LauncherAPI - public static final AtomicReference hwid = new AtomicReference<>(); - @LauncherAPI - public static Thread getHWID = null; - - private static long cachedMemorySize = -1; - - @LauncherAPI - public static HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, HashedDir hdir, FileNameMatcher matcher, boolean digest) { - return () -> { - if (hdir == null) { - Request.requestError(java.lang.String.format("Директории '%s' нет в кэше", dirName)); - } - ClientLauncher.verifyHDir(dir, hdir, matcher, digest); - return hdir; - }; - } - - @LauncherAPI - public static void startTask(Runnable task) { - threadPool.execute(task); - } - - @LauncherAPI - public static HWID getHWID() { - HWID hhwid = hwid.get(); - if (hhwid == null) { - if (hwidProvider == null) hwidProvider = new OshiHWIDProvider(); - hwid.set(hwidProvider.getHWID()); - } - return hhwid; - } - - @LauncherAPI - public static long getTotalMemory() { - if (cachedMemorySize > 0) return cachedMemorySize; - if (hwidProvider == null) hwidProvider = new OshiHWIDProvider(); - return (cachedMemorySize = hwidProvider.getTotalMemory() >> 20); - } - - @LauncherAPI - public static int getClientJVMBits() { - return LauncherGuardManager.guard.getClientJVMBits(); - } - - @LauncherAPI - public static long getJVMTotalMemory() { - if (getClientJVMBits() == 32) { - return Math.min(getTotalMemory(), 1536); - } else { - return getTotalMemory(); - } - } - - @LauncherAPI - public static HasherStore getDefaultHasherStore() { - return HasherManager.getDefaultStore(); - } - - @LauncherAPI - public static void registerUserSettings(String typename, Class clazz) { - UserSettings.providers.register(typename, clazz); - } - - @LauncherAPI - public static void close() throws Exception { - threadPool.awaitTermination(2, TimeUnit.SECONDS); - } - - @LauncherAPI - public static void setAuthParams(AuthRequestEvent event) { - if (event.session != 0) { - Request.setSession(event.session); - } - LauncherGuardManager.guard.setProtectToken(event.protectToken); - AuthService.permissions = event.permissions; - if (event.playerProfile != null) { - AuthService.username = event.playerProfile.username; - AuthService.uuid = event.playerProfile.uuid; - } - } - - @FunctionalInterface - public interface HashedDirRunnable { - HashedDir run() throws Exception; - } - - @LauncherAPI - public static void evalCommand(String cmd) { - ConsoleManager.handler.eval(cmd, false); - } - - @LauncherAPI - public static void addPlainOutput(LogHelper.Output output) { - LogHelper.addOutput(output, LogHelper.OutputTypes.PLAIN); - } - - @LauncherAPI - public static String getLauncherVersion() { - return String.format("GravitLauncher v%d.%d.%d build %d", - Version.MAJOR, - Version.MINOR, - Version.PATCH, - Version.BUILD - ); - } - - @LauncherAPI - public static byte[] encryptPassword(String string) throws Exception { - byte[] encode = IOHelper.encode(string); - return SecurityHelper.encrypt(Launcher.getConfig().passwordEncryptKey, encode); - } -} From 03471e8bbf80fb46f4c0b305161773f69eafe850 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 4 Dec 2019 23:08:36 +0700 Subject: [PATCH 2/8] =?UTF-8?q?[FEATURE]=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20ListDownloader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launcher/LauncherEngine.java | 1 - .../client/LauncherUpdateController.java | 31 +- .../launcher/downloader/ListDownloader.java | 252 ---------------- .../request/update/LauncherRequest.java | 11 +- .../request/update/UpdateRequest.java | 277 +----------------- modules | 2 +- 6 files changed, 13 insertions(+), 561 deletions(-) delete mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 0f9d5895..ae9c10f8 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -158,7 +158,6 @@ public void start(String... args) throws Throwable { } }; } - if (UpdateRequest.getController() == null) UpdateRequest.setController(new LauncherUpdateController()); Objects.requireNonNull(args, "args"); if (started.getAndSet(true)) throw new IllegalStateException("Launcher has been already started"); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java index 4fbdf4ff..62c1e1e5 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java @@ -1,7 +1,6 @@ package pro.gravit.launcher.client; import pro.gravit.launcher.NewLauncherSettings; -import pro.gravit.launcher.downloader.ListDownloader; import pro.gravit.launcher.events.request.UpdateRequestEvent; import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.hasher.HashedEntry; @@ -17,21 +16,10 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.List; import java.util.concurrent.atomic.AtomicReference; +@Deprecated +public class LauncherUpdateController { -public class LauncherUpdateController implements UpdateRequest.UpdateController { - @Override - public void preUpdate(UpdateRequest request, UpdateRequestEvent e) { - - } - - @Override - public void preDiff(UpdateRequest request, UpdateRequestEvent e) { - - } - - @Override public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff diff) throws IOException { if (e.zip && e.fullDownload) return; if (SettingsManager.settings.featureStore) { @@ -116,19 +104,4 @@ public Path tryFind(NewLauncherSettings.HashedStoreEntry en, HashedFile file) th }); return ret.get(); } - - @Override - public void preDownload(UpdateRequest request, UpdateRequestEvent e, List adds) { - - } - - @Override - public void postDownload(UpdateRequest request, UpdateRequestEvent e) { - - } - - @Override - public void postUpdate(UpdateRequest request, UpdateRequestEvent e) { - - } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java b/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java deleted file mode 100644 index 741cdf3f..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java +++ /dev/null @@ -1,252 +0,0 @@ -package pro.gravit.launcher.downloader; - -import org.apache.http.HttpResponse; -import org.apache.http.client.ResponseHandler; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.impl.client.LaxRedirectStrategy; -import pro.gravit.utils.helper.CommonHelper; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.helper.VerifyHelper; - -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.concurrent.*; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -public class ListDownloader { - private static final AtomicInteger COUNTER_THR = new AtomicInteger(0); - private static final ThreadFactory FACTORY = r -> CommonHelper.newThread("Downloader Thread #" + COUNTER_THR.incrementAndGet(), true, r); - - private static ExecutorService newExecutor() { - return new ThreadPoolExecutor(0, VerifyHelper.verifyInt(Integer.parseInt(System.getProperty("launcher.downloadThreads", "3")), VerifyHelper.POSITIVE, "Thread max count must be positive."), 5, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), FACTORY); - } - - @FunctionalInterface - public interface DownloadCallback { - void stateChanged(String filename, long downloadedSize, long size); - } - - @FunctionalInterface - public interface DownloadTotalCallback { - void addTotal(long size); - } - - public static class DownloadTask { - public final String apply; - public long size; - public final String urlApply; - - public DownloadTask(String apply, long size) { - this.apply = apply; - urlApply = apply; - this.size = size; - } - - public DownloadTask(String urlApply, String apply, long size) { - this.apply = apply; - this.urlApply = urlApply; - this.size = size; - } - } - - public void download(String base, List applies, Path dstDirFile, DownloadCallback callback, DownloadTotalCallback totalCallback) throws IOException, URISyntaxException { - try (CloseableHttpClient httpclient = HttpClients.custom().setUserAgent(IOHelper.USER_AGENT) - .setRedirectStrategy(new LaxRedirectStrategy()) - .build()) { - applies.sort(Comparator.comparingLong(a -> a.size)); - List> toExec = new ArrayList<>(); - URI baseUri = new URI(base); - String scheme = baseUri.getScheme(); - String host = baseUri.getHost(); - int port = baseUri.getPort(); - if (port != -1) - host = host + ":" + port; - String path = baseUri.getPath(); - List excs = new CopyOnWriteArrayList<>(); - for (DownloadTask apply : applies) { - URI u = new URI(scheme, host, path + apply.urlApply, "", ""); - callback.stateChanged(apply.apply, 0L, apply.size); - Path targetPath = dstDirFile.resolve(apply.apply); - toExec.add(() -> { - if (LogHelper.isDebugEnabled()) - LogHelper.debug("Download URL: %s to file %s dir: %s", u.toString(), targetPath.toAbsolutePath().toString(), dstDirFile.toAbsolutePath().toString()); - try { - httpclient.execute(new HttpGet(u), new FileDownloadResponseHandler(targetPath, apply, callback, totalCallback, false)); - } catch (IOException e) { - excs.add(e); - } - return null; - }); - } - try { - ExecutorService e = newExecutor(); - e.invokeAll(toExec); - e.shutdown(); - e.awaitTermination(4, TimeUnit.HOURS); - } catch (InterruptedException t) { - LogHelper.error(t); - } - if (!excs.isEmpty()) { - IOException toThrow = excs.remove(0); - excs.forEach(toThrow::addSuppressed); - throw toThrow; - } - } - } - - public void downloadZip(String base, List applies, Path dstDirFile, DownloadCallback callback, DownloadTotalCallback totalCallback, boolean fullDownload) throws IOException { - /*try (CloseableHttpClient httpclient = HttpClients.custom() - .setRedirectStrategy(new LaxRedirectStrategy()) - .build()) { - HttpGet get; - URI u = new URL(base).toURI(); - LogHelper.debug("Download ZIP URL: %s", u.toString()); - get = new HttpGet(u); - httpclient.execute(get, new FileDownloadResponseHandler(dstDirFile, callback, totalCallback, true)); - }*/ - try (ZipInputStream input = IOHelper.newZipInput(new URL(base))) { - for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry()) { - if (entry.isDirectory()) - continue; // Skip directories - // Unpack entry - String name = entry.getName(); - callback.stateChanged(name, 0L, entry.getSize()); - LogHelper.subInfo("Downloading file: '%s'", name); - if (fullDownload || applies.stream().anyMatch((t) -> t.apply.equals(name))) { - Path fileName = IOHelper.toPath(name); - transfer(input, dstDirFile.resolve(fileName), fileName.toString(), entry.getSize(), callback, totalCallback); - } - } - } - } - - public void downloadOne(String url, Path target) throws IOException, URISyntaxException { - try (CloseableHttpClient httpclient = HttpClients.custom() - .setRedirectStrategy(new LaxRedirectStrategy()) - .build()) { - - HttpGet get; - URI u = new URL(url).toURI(); - if (LogHelper.isDebugEnabled()) { - LogHelper.debug("Download URL: %s", u.toString()); - } - get = new HttpGet(u); - httpclient.execute(get, new FileDownloadResponseHandler(target.toAbsolutePath())); - } - } - - static class FileDownloadResponseHandler implements ResponseHandler { - private final Path target; - private final DownloadTask task; - private final DownloadCallback callback; - private final DownloadTotalCallback totalCallback; - private final boolean zip; - - public FileDownloadResponseHandler(Path target) { - this.target = target; - this.task = null; - this.zip = false; - callback = null; - totalCallback = null; - } - - public FileDownloadResponseHandler(Path target, DownloadTask task, DownloadCallback callback, DownloadTotalCallback totalCallback, boolean zip) { - this.target = target; - this.task = task; - this.callback = callback; - this.totalCallback = totalCallback; - this.zip = zip; - } - - public FileDownloadResponseHandler(Path target, DownloadCallback callback, DownloadTotalCallback totalCallback, boolean zip) { - this.target = target; - this.task = null; - this.callback = callback; - this.totalCallback = totalCallback; - this.zip = zip; - } - - @Override - public Path handleResponse(HttpResponse response) throws IOException { - InputStream source = response.getEntity().getContent(); - int returnCode = response.getStatusLine().getStatusCode(); - if (returnCode != 200) { - throw new IllegalStateException(String.format("Request download file %s return code %d", target.toString(), returnCode)); - } - long contentLength = response.getEntity().getContentLength(); - if (task != null && contentLength != task.size) { - if (task.size > 0) - LogHelper.warning("Missing content length: expected %d | found %d", task.size, contentLength); - else task.size = contentLength; - } - if (zip) { - try (ZipInputStream input = IOHelper.newZipInput(source)) { - ZipEntry entry = input.getNextEntry(); - while (entry != null) { - if (entry.isDirectory()) { - entry = input.getNextEntry(); - continue; - } - long size = entry.getSize(); - String filename = entry.getName(); - Path target = this.target.resolve(filename); - if (callback != null) { - callback.stateChanged(entry.getName(), 0, entry.getSize()); - } - if (LogHelper.isDevEnabled()) { - LogHelper.dev("Resolved filename %s to %s", filename, target.toAbsolutePath().toString()); - } - transfer(source, target, filename, size, callback, totalCallback); - entry = input.getNextEntry(); - } - - } - return null; - } - if (callback != null && task != null) { - callback.stateChanged(task.apply, 0, task.size); - transfer(source, this.target, task.apply, task.size, callback, totalCallback); - } else - IOHelper.transfer(source, this.target); - return this.target; - } - } - - public static void transfer(InputStream input, Path file, String filename, long size, DownloadCallback callback, DownloadTotalCallback totalCallback) throws IOException { - try (OutputStream fileOutput = IOHelper.newOutput(file)) { - long downloaded = 0L; - - // Download with digest update - byte[] bytes = IOHelper.newBuffer(); - while (downloaded < size) { - int remaining = (int) Math.min(size - downloaded, bytes.length); - int length = input.read(bytes, 0, remaining); - if (length < 0) - throw new EOFException(String.format("%d bytes remaining", size - downloaded)); - - // Update file - fileOutput.write(bytes, 0, length); - - // Update state - downloaded += length; - //totalDownloaded += length; - totalCallback.addTotal(length); - callback.stateChanged(filename, downloaded, size); - } - } - } -} \ No newline at end of file diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java index 8f3615f4..91109b14 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java @@ -3,7 +3,6 @@ import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.downloader.ListDownloader; import pro.gravit.launcher.events.request.LauncherRequestEvent; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; @@ -15,6 +14,8 @@ import java.io.IOException; import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -60,9 +61,13 @@ public static void update(LauncherRequestEvent result) throws IOException { IOHelper.transfer(BINARY_PATH, stream); }*/ try { - ListDownloader downloader = new ListDownloader(); Files.deleteIfExists(C_BINARY_PATH); - downloader.downloadOne(result.url, C_BINARY_PATH); + URL url = new URL(result.url); + URLConnection connection = url.openConnection(); + try(InputStream in = connection.getInputStream()) + { + IOHelper.transfer(in, C_BINARY_PATH); + } try (InputStream in = IOHelper.newInput(C_BINARY_PATH)) { IOHelper.transfer(in, BINARY_PATH); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java index ac6eface..29e25f15 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java @@ -1,313 +1,40 @@ package pro.gravit.launcher.request.update; -import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.downloader.ListDownloader; import pro.gravit.launcher.events.request.UpdateRequestEvent; -import pro.gravit.launcher.hasher.FileNameMatcher; -import pro.gravit.launcher.hasher.HashedDir; -import pro.gravit.launcher.hasher.HashedEntry; -import pro.gravit.launcher.hasher.HashedFile; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.update.UpdateRequest.State.Callback; import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; import pro.gravit.launcher.request.websockets.WebSocketRequest; -import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; - -import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; -import java.time.Duration; -import java.time.Instant; -import java.util.ArrayList; -import java.util.List; -import java.util.Map.Entry; import java.util.Objects; public final class UpdateRequest extends Request implements WebSocketRequest { - public interface UpdateController { - void preUpdate(UpdateRequest request, UpdateRequestEvent e); - - void preDiff(UpdateRequest request, UpdateRequestEvent e); - - void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff diff) throws IOException; - - void preDownload(UpdateRequest request, UpdateRequestEvent e, List adds); - - void postDownload(UpdateRequest request, UpdateRequestEvent e); - - void postUpdate(UpdateRequest request, UpdateRequestEvent e); - } - - private static UpdateController controller; - - public static void setController(UpdateController controller) { - UpdateRequest.controller = controller; - } - - public static UpdateController getController() { - return controller; - } @Override public String getType() { return "update"; } - public static final class State { - @FunctionalInterface - public interface Callback { - @LauncherAPI - void call(State state); - } - @LauncherAPI - public final long fileDownloaded; - @LauncherAPI - public final long fileSize; - @LauncherAPI - public final long totalDownloaded; - @LauncherAPI - public final long totalSize; - @LauncherAPI - public final String filePath; - - @LauncherAPI - public final Duration duration; - - public State(String filePath, long fileDownloaded, long fileSize, long totalDownloaded, long totalSize, Duration duration) { - this.filePath = filePath; - this.fileDownloaded = fileDownloaded; - this.fileSize = fileSize; - this.totalDownloaded = totalDownloaded; - this.totalSize = totalSize; - - // Also store time of creation - this.duration = duration; - } - - @LauncherAPI - public double getBps() { - long seconds = duration.getSeconds(); - if (seconds == 0) - return -1.0D; // Otherwise will throw /0 exception - return totalDownloaded / (double) seconds; - } - - @LauncherAPI - public Duration getEstimatedTime() { - double bps = getBps(); - if (bps <= 0.0D) - return null; // Otherwise will throw /0 exception - return Duration.ofSeconds((long) (getTotalRemaining() / bps)); - } - - @LauncherAPI - public double getFileDownloadedKiB() { - return fileDownloaded / 1024.0D; - } - - @LauncherAPI - public double getFileDownloadedMiB() { - return getFileDownloadedKiB() / 1024.0D; - } - - @LauncherAPI - public double getFileDownloadedPart() { - if (fileSize == 0) - return 0.0D; - return (double) fileDownloaded / fileSize; - } - - @LauncherAPI - public long getFileRemaining() { - return fileSize - fileDownloaded; - } - - @LauncherAPI - public double getFileRemainingKiB() { - return getFileRemaining() / 1024.0D; - } - - @LauncherAPI - public double getFileRemainingMiB() { - return getFileRemainingKiB() / 1024.0D; - } - - @LauncherAPI - public double getFileSizeKiB() { - return fileSize / 1024.0D; - } - - @LauncherAPI - public double getFileSizeMiB() { - return getFileSizeKiB() / 1024.0D; - } - - @LauncherAPI - public double getTotalDownloadedKiB() { - return totalDownloaded / 1024.0D; - } - - @LauncherAPI - public double getTotalDownloadedMiB() { - return getTotalDownloadedKiB() / 1024.0D; - } - - @LauncherAPI - public double getTotalDownloadedPart() { - if (totalSize == 0) - return 0.0D; - return (double) totalDownloaded / totalSize; - } - - @LauncherAPI - public long getTotalRemaining() { - return totalSize - totalDownloaded; - } - - @LauncherAPI - public double getTotalRemainingKiB() { - return getTotalRemaining() / 1024.0D; - } - - @LauncherAPI - public double getTotalRemainingMiB() { - return getTotalRemainingKiB() / 1024.0D; - } - - @LauncherAPI - public double getTotalSizeKiB() { - return totalSize / 1024.0D; - } - - @LauncherAPI - public double getTotalSizeMiB() { - return getTotalSizeKiB() / 1024.0D; - } - } @Override public UpdateRequestEvent requestDo(StandartClientWebSocketService service) throws Exception { LogHelper.debug("Start update request"); - UpdateRequestEvent e = (UpdateRequestEvent) service.sendRequest(this); - if (controller != null) controller.preUpdate(this, e); - LogHelper.debug("Start update"); - Launcher.profile.pushOptionalFile(e.hdir, !Launcher.profile.isUpdateFastCheck()); - if (controller != null) controller.preDiff(this, e); - HashedDir.Diff diff = e.hdir.diff(localDir, matcher); - if (controller != null) controller.postDiff(this, e, diff); - final List adds = new ArrayList<>(); - if (controller != null) controller.preDownload(this, e, adds); - diff.mismatch.walk(IOHelper.CROSS_SEPARATOR, (path, name, entry) -> { - if (entry.getType().equals(HashedEntry.Type.FILE)) { - if (!entry.flag) { - HashedFile file = (HashedFile) entry; - totalSize += file.size; - adds.add(new ListDownloader.DownloadTask(path, file.size)); - } - } else if (entry.getType().equals(HashedEntry.Type.DIR)) { - try { - Files.createDirectories(dir.resolve(path)); - } catch (IOException ex) { - LogHelper.error(ex); - } - } - return HashedDir.WalkAction.CONTINUE; - }); - totalSize = diff.mismatch.size(); - startTime = Instant.now(); - updateState("UnknownFile", 0L, 100); - ListDownloader listDownloader = new ListDownloader(); - LogHelper.info("Download %s to %s", dirName, dir.toAbsolutePath().toString()); - if (e.zip && !adds.isEmpty()) { - listDownloader.downloadZip(e.url, adds, dir, this::updateState, (add) -> totalDownloaded += add, e.fullDownload); - } else { - listDownloader.download(e.url, adds, dir, this::updateState, (add) -> totalDownloaded += add); - } - if (controller != null) controller.postDownload(this, e); - deleteExtraDir(dir, diff.extra, diff.extra.flag); - if (controller != null) controller.postUpdate(this, e); - LogHelper.debug("Update success"); - return e; + return (UpdateRequestEvent) service.sendRequest(this); } // Instance @LauncherNetworkAPI - private final String dirName; private transient final Path dir; public Path getDir() { return dir; } - private transient final FileNameMatcher matcher; - - private transient final boolean digest; - private transient volatile Callback stateCallback; - // State - private transient HashedDir localDir; - private transient long totalDownloaded; - - private transient long totalSize; - - private transient Instant startTime; - @LauncherAPI - public UpdateRequest(String dirName, Path dir, FileNameMatcher matcher, boolean digest) { - this.dirName = IOHelper.verifyFileName(dirName); + public UpdateRequest(Path dir) { this.dir = Objects.requireNonNull(dir, "dir"); - this.matcher = matcher; - this.digest = digest; - } - - private void deleteExtraDir(Path subDir, HashedDir subHDir, boolean flag) throws IOException { - for (Entry mapEntry : subHDir.map().entrySet()) { - String name = mapEntry.getKey(); - Path path = subDir.resolve(name); - - // Delete list and dirs based on type - HashedEntry entry = mapEntry.getValue(); - HashedEntry.Type entryType = entry.getType(); - switch (entryType) { - case FILE: - updateState(IOHelper.toString(path), 0, 0); - Files.delete(path); - break; - case DIR: - deleteExtraDir(path, (HashedDir) entry, flag || entry.flag); - break; - default: - throw new AssertionError("Unsupported hashed entry type: " + entryType.name()); - } - } - - // Delete! - if (flag) { - updateState(IOHelper.toString(subDir), 0, 0); - Files.delete(subDir); - } - } - - @Override - public UpdateRequestEvent request() throws Exception { - Files.createDirectories(dir); - localDir = new HashedDir(dir, matcher, false, digest); - - // Start request - return super.request(); - } - - @LauncherAPI - public void setStateCallback(Callback callback) { - stateCallback = callback; - } - - private void updateState(String filePath, long fileDownloaded, long fileSize) { - if (stateCallback != null) - stateCallback.call(new State(filePath, fileDownloaded, fileSize, - totalDownloaded, totalSize, Duration.between(startTime, Instant.now()))); } } diff --git a/modules b/modules index 3cf0cb41..5069ebac 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 3cf0cb41a64b1f05d76bdc67f83d67d80ebe41f1 +Subproject commit 5069ebacddc00b261dd03036fc637a8aa803e2d5 From 4eb9c7fe7c1f2a42b21de599b6e2838fd21c3616 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 4 Dec 2019 23:42:41 +0700 Subject: [PATCH 3/8] =?UTF-8?q?[FEATURE]=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20apache=20http=20client=20=D0=B8=D0=B7=20?= =?UTF-8?q?=D0=BE=D0=B1=D1=8F=D0=B7=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5?= =?UTF-8?q?=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Launcher/build.gradle | 1 - LauncherAPI/build.gradle | 1 - 2 files changed, 2 deletions(-) diff --git a/Launcher/build.gradle b/Launcher/build.gradle index 0836fc7f..3db21f40 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -55,7 +55,6 @@ task javadocJar(type: Jar) { dependencies { pack project(':LauncherAuthlib') bundle 'com.github.oshi:oshi-core:3.13.0' - bundle 'org.apache.httpcomponents:httpclient:4.5.10' pack 'io.netty:netty-codec-http:4.1.43.Final' pack 'org.ow2.asm:asm-tree:7.1' } diff --git a/LauncherAPI/build.gradle b/LauncherAPI/build.gradle index 820aa7f6..c6382a08 100644 --- a/LauncherAPI/build.gradle +++ b/LauncherAPI/build.gradle @@ -3,7 +3,6 @@ dependencies { compile project(':LauncherCore') - compileOnly 'org.apache.httpcomponents:httpclient:4.5.10' compileOnly 'io.netty:netty-codec-http:4.1.43.Final' testCompile 'org.junit.jupiter:junit-jupiter:5.4.1' } From f839691c87b27a23a3092566694b1f0f20a3a772 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 4 Dec 2019 23:49:52 +0700 Subject: [PATCH 4/8] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 5069ebac..f986d6b7 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 5069ebacddc00b261dd03036fc637a8aa803e2d5 +Subproject commit f986d6b73705742b60a0db7feef2d8daacc43a5a From 4136f4a6e8c3f29cb10128f18d878de573010075 Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 5 Dec 2019 01:22:07 +0700 Subject: [PATCH 5/8] =?UTF-8?q?[FEATURE]=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=B1=D0=BE=D0=BB=D1=8C=D1=88=D0=B8=D0=BD=D1=81?= =?UTF-8?q?=D1=82=D0=B2=D0=BE=20=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B5?= =?UTF-8?q?=D0=BA,=20=D0=BE=D1=82=D0=BD=D0=BE=D1=81=D0=B2=D1=89=D0=B8?= =?UTF-8?q?=D1=85=D1=81=D1=8F=20=D0=BA=20=D1=80=D0=B0=D0=BD=D1=82=D0=B0?= =?UTF-8?q?=D0=B9=D0=BC=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launcher/NewLauncherSettings.java | 29 +---- .../client/LauncherUpdateController.java | 104 +++++++++--------- .../launcher/console/FeatureCommand.java | 34 ------ .../console/store/CopyStoreDirCommand.java | 47 -------- .../console/store/LinkStoreDirCommand.java | 47 -------- .../console/store/StoreListCommand.java | 27 ----- .../launcher/managers/ConsoleManager.java | 10 -- .../launcher/managers/SettingsManager.java | 4 - 8 files changed, 52 insertions(+), 250 deletions(-) delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/console/FeatureCommand.java delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/console/store/CopyStoreDirCommand.java delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/console/store/LinkStoreDirCommand.java delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/console/store/StoreListCommand.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java b/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java index 5c45135d..b812b3c5 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java +++ b/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java @@ -8,37 +8,10 @@ import java.util.*; public class NewLauncherSettings { - @LauncherAPI - public String login; - @LauncherAPI - public String auth; - @LauncherAPI - public byte[] rsaPassword; - @LauncherAPI - public int profile; - @LauncherAPI - public transient Path updatesDir; - @LauncherAPI - public String updatesDirPath; - @LauncherAPI - public boolean autoEnter; - @LauncherAPI - public boolean debug; - @LauncherAPI - public boolean fullScreen; - @LauncherAPI - public boolean offline; - @LauncherAPI - public int ram; - - @LauncherAPI - public byte[] lastDigest; - @LauncherAPI - public List lastProfiles = new LinkedList<>(); @LauncherAPI public Map userSettings = new HashMap<>(); @LauncherAPI - public boolean featureStore; + public List features = new ArrayList<>(); @LauncherAPI public String consoleUnlockKey; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java index 62c1e1e5..c66a7ee1 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java @@ -22,60 +22,58 @@ public class LauncherUpdateController { public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff diff) throws IOException { if (e.zip && e.fullDownload) return; - if (SettingsManager.settings.featureStore) { - LogHelper.info("Enabled HStore feature. Find"); - AtomicReference lastEn = new AtomicReference<>(null); - //ArrayList removed = new ArrayList<>(); - diff.mismatch.walk(File.separator, (path, name, entry) -> { - if (entry.getType() == HashedEntry.Type.DIR) { - Files.createDirectories(request.getDir().resolve(path)); - return HashedDir.WalkAction.CONTINUE; - } - HashedFile file = (HashedFile) entry; - //Первый экспериментальный способ - честно обходим все возможные Store - Path ret = null; - if (lastEn.get() == null) { - for (NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs) { - ret = tryFind(en, file); - if (ret != null) { - lastEn.set(en); - break; - } - } - } else { - ret = tryFind(lastEn.get(), file); - } - if (ret == null) { - for (NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs) { - ret = tryFind(en, file); - if (ret != null) { - lastEn.set(en); - break; - } - } - } - if (ret != null) { - //Еще раз проверим корректность хеша - //Возможно эта проверка избыточна - //if(file.isSame(ret, true)) - { - Path source = request.getDir().resolve(path); - if (LogHelper.isDebugEnabled()) { - LogHelper.debug("Copy file %s to %s", ret.toAbsolutePath().toString(), source.toAbsolutePath().toString()); - } - //Let's go! - Files.deleteIfExists(source); - Files.copy(ret, source); - try (InputStream input = IOHelper.newInput(ret)) { - IOHelper.transfer(input, source); - } - entry.flag = true; - //removed.add(path.replace('\\', '/')); - } - } + LogHelper.info("Enabled HStore feature. Find"); + AtomicReference lastEn = new AtomicReference<>(null); + //ArrayList removed = new ArrayList<>(); + diff.mismatch.walk(File.separator, (path, name, entry) -> { + if (entry.getType() == HashedEntry.Type.DIR) { + Files.createDirectories(request.getDir().resolve(path)); return HashedDir.WalkAction.CONTINUE; - }); - } + } + HashedFile file = (HashedFile) entry; + //Первый экспериментальный способ - честно обходим все возможные Store + Path ret = null; + if (lastEn.get() == null) { + for (NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs) { + ret = tryFind(en, file); + if (ret != null) { + lastEn.set(en); + break; + } + } + } else { + ret = tryFind(lastEn.get(), file); + } + if (ret == null) { + for (NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs) { + ret = tryFind(en, file); + if (ret != null) { + lastEn.set(en); + break; + } + } + } + if (ret != null) { + //Еще раз проверим корректность хеша + //Возможно эта проверка избыточна + //if(file.isSame(ret, true)) + { + Path source = request.getDir().resolve(path); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("Copy file %s to %s", ret.toAbsolutePath().toString(), source.toAbsolutePath().toString()); + } + //Let's go! + Files.deleteIfExists(source); + Files.copy(ret, source); + try (InputStream input = IOHelper.newInput(ret)) { + IOHelper.transfer(input, source); + } + entry.flag = true; + //removed.add(path.replace('\\', '/')); + } + } + return HashedDir.WalkAction.CONTINUE; + }); } public Path tryFind(NewLauncherSettings.HashedStoreEntry en, HashedFile file) throws IOException { diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/FeatureCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/FeatureCommand.java deleted file mode 100644 index 78a27999..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/console/FeatureCommand.java +++ /dev/null @@ -1,34 +0,0 @@ -package pro.gravit.launcher.console; - -import pro.gravit.launcher.managers.SettingsManager; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.helper.LogHelper; - -public class FeatureCommand extends Command { - @Override - public String getArgsDescription() { - return "[feature] [true/false]"; - } - - @Override - public String getUsageDescription() { - return "Enable or disable feature"; - } - - @Override - public void invoke(String... args) throws Exception { - verifyArgs(args, 2); - boolean enabled = Boolean.parseBoolean(args[1]); - switch (args[0]) { - case "store": { - SettingsManager.settings.featureStore = enabled; - break; - } - default: { - LogHelper.info("Features: [store]"); - return; - } - } - LogHelper.info("Feature %s %s", args[0], enabled ? "enabled" : "disabled"); - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/store/CopyStoreDirCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/store/CopyStoreDirCommand.java deleted file mode 100644 index 763855ac..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/console/store/CopyStoreDirCommand.java +++ /dev/null @@ -1,47 +0,0 @@ -package pro.gravit.launcher.console.store; - -import pro.gravit.launcher.NewLauncherSettings; -import pro.gravit.launcher.managers.SettingsManager; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.helper.LogHelper; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -public class CopyStoreDirCommand extends Command { - @Override - public String getArgsDescription() { - return "[index] [overwrite(true/false)]"; - } - - @Override - public String getUsageDescription() { - return "Copy dir in GravitLauncherStore"; - } - - @Override - public void invoke(String... args) throws Exception { - verifyArgs(args, 2); - int ind = 1; - int index = Integer.parseInt(args[0]); - boolean overwrite = Boolean.parseBoolean(args[1]); - for (NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs) { - if (ind == index) { - LogHelper.info("Copy [%d] FullPath: %s name: %s", ind, e.fullPath, e.name); - Path path = Paths.get(e.fullPath); - if (!Files.isDirectory(path)) { - LogHelper.error("Directory %s not found", path.toAbsolutePath().toString()); - return; - } - Path target = Paths.get(SettingsManager.settings.updatesDirPath).resolve(e.name); - if (Files.exists(target) && !overwrite) { - LogHelper.error("Directory %s found, flag overwrite not found", target.toAbsolutePath().toString()); - return; - } - Files.copy(path, target); - } - ind++; - } - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/store/LinkStoreDirCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/store/LinkStoreDirCommand.java deleted file mode 100644 index 35120f31..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/console/store/LinkStoreDirCommand.java +++ /dev/null @@ -1,47 +0,0 @@ -package pro.gravit.launcher.console.store; - -import pro.gravit.launcher.NewLauncherSettings; -import pro.gravit.launcher.managers.SettingsManager; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.helper.LogHelper; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -public class LinkStoreDirCommand extends Command { - - @Override - public String getArgsDescription() { - return "[index]"; - } - - @Override - public String getUsageDescription() { - return "Create symlink to GravitLauncherStore directory"; - } - - @Override - public void invoke(String... args) throws Exception { - verifyArgs(args, 1); - int ind = 1; - int index = Integer.parseInt(args[0]); - for (NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs) { - if (ind == index) { - LogHelper.info("Copy [%d] FullPath: %s name: %s", ind, e.fullPath, e.name); - Path path = Paths.get(e.fullPath); - if (!Files.isDirectory(path)) { - LogHelper.error("Directory %s not found", path.toAbsolutePath().toString()); - return; - } - Path target = Paths.get(SettingsManager.settings.updatesDirPath).resolve(e.name); - if (Files.exists(target)) { - LogHelper.error("Directory %s already exists", target.toAbsolutePath().toString()); - return; - } - Files.createSymbolicLink(path, target); - } - ind++; - } - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/store/StoreListCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/store/StoreListCommand.java deleted file mode 100644 index 3ed81fc7..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/console/store/StoreListCommand.java +++ /dev/null @@ -1,27 +0,0 @@ -package pro.gravit.launcher.console.store; - -import pro.gravit.launcher.NewLauncherSettings; -import pro.gravit.launcher.managers.SettingsManager; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.helper.LogHelper; - -public class StoreListCommand extends Command { - @Override - public String getArgsDescription() { - return null; - } - - @Override - public String getUsageDescription() { - return "List GravitLauncherStore"; - } - - @Override - public void invoke(String... args) { - int ind = 1; - for (NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs) { - LogHelper.info("[%d] FullPath: %s name: %s", ind, e.fullPath, e.name); - ind++; - } - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java index 07b41d72..19098f36 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java @@ -1,13 +1,9 @@ package pro.gravit.launcher.managers; import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.console.FeatureCommand; import pro.gravit.launcher.console.UnlockCommand; import pro.gravit.launcher.console.admin.ExecCommand; import pro.gravit.launcher.console.admin.LogListenerCommand; -import pro.gravit.launcher.console.store.CopyStoreDirCommand; -import pro.gravit.launcher.console.store.LinkStoreDirCommand; -import pro.gravit.launcher.console.store.StoreListCommand; import pro.gravit.utils.command.BaseCommandCategory; import pro.gravit.utils.command.CommandHandler; import pro.gravit.utils.command.JLineCommandHandler; @@ -57,16 +53,10 @@ public static boolean checkUnlockKey(String key) { public static void unlock() { handler.registerCommand("debug", new DebugCommand()); - handler.registerCommand("feature", new FeatureCommand()); BaseCommandCategory admin = new BaseCommandCategory(); admin.registerCommand("exec", new ExecCommand()); admin.registerCommand("logListen", new LogListenerCommand()); handler.registerCategory(new CommandHandler.Category(admin, "admin", "Server admin commands")); - BaseCommandCategory store = new BaseCommandCategory(); - store.registerCommand("storeList", new StoreListCommand()); - store.registerCommand("copyStoreDir", new CopyStoreDirCommand()); - store.registerCommand("linkStoreDir", new LinkStoreDirCommand()); - handler.registerCategory(new CommandHandler.Category(admin, "store", "Store admin commands")); isConsoleUnlock = true; } } diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java index 55921ab5..edf1dfe6 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java @@ -42,8 +42,6 @@ public SettingsManager() { @LauncherAPI @Override public NewLauncherSettings getConfig() { - if (settings.updatesDir != null) - settings.updatesDirPath = settings.updatesDir.toString(); return settings; } @@ -57,8 +55,6 @@ public NewLauncherSettings getDefaultConfig() { @Override public void setConfig(NewLauncherSettings config) { settings = config; - if (settings.updatesDirPath != null) - settings.updatesDir = Paths.get(settings.updatesDirPath); if (settings.consoleUnlockKey != null && !ConsoleManager.isConsoleUnlock) { if (ConsoleManager.checkUnlockKey(settings.consoleUnlockKey)) { ConsoleManager.unlock(); From 71018a0cdfc367bb5a01ff6afcf506276c137d4b Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 5 Dec 2019 01:35:36 +0700 Subject: [PATCH 6/8] =?UTF-8?q?[FEATURE]=20UUID=20=D0=B2=20ClientProfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/hash/DownloadClientCommand.java | 2 ++ .../pro/gravit/launcher/profiles/ClientProfile.java | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java index 54b3f738..ef403ecc 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java @@ -15,6 +15,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Collections; +import java.util.UUID; public final class DownloadClientCommand extends Command { @@ -61,6 +62,7 @@ public void invoke(String... args) throws IOException, CommandException { } client.setTitle(dirName); client.setDir(dirName); + client.setUUID(UUID.randomUUID()); try (BufferedWriter writer = IOHelper.newWriter(IOHelper.resolveIncremental(server.profilesDir, dirName, "json"))) { Launcher.gsonManager.configGson.toJson(client, writer); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java index 8ef8ea5f..3530d993 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -86,6 +86,8 @@ public String toString() { @LauncherAPI private int sortIndex; @LauncherAPI + private UUID uuid; + @LauncherAPI private String title; @LauncherAPI private String info; @@ -384,11 +386,19 @@ public void setVersion(Version version) { this.version = version.name; } + public void setUUID(UUID uuid) { + this.uuid = uuid; + } + @Override public String toString() { return title; } + public UUID getUUID() { + return uuid; + } + @LauncherAPI public void verify() { // Version From 20913cdbc6d50075c8b2e3ee116c3ccae5b8b154 Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 5 Dec 2019 02:24:19 +0700 Subject: [PATCH 7/8] =?UTF-8?q?[FIX]=20=D0=9D=D0=B5=D0=BA=D0=BE=D1=80?= =?UTF-8?q?=D1=80=D0=B5=D0=BA=D1=82=D0=BD=D1=8B=D0=B9=20UpdateRequest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/request/update/UpdateRequest.java | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java index 29e25f15..3c8344bf 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java @@ -1,17 +1,18 @@ package pro.gravit.launcher.request.update; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.UpdateRequestEvent; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.utils.helper.LogHelper; -import java.nio.file.Path; -import java.util.Objects; public final class UpdateRequest extends Request implements WebSocketRequest { + public UpdateRequest(String dirName) { + this.dirName = dirName; + } + @Override public String getType() { return "update"; @@ -27,14 +28,5 @@ public UpdateRequestEvent requestDo(StandartClientWebSocketService service) thro // Instance @LauncherNetworkAPI - private transient final Path dir; - - public Path getDir() { - return dir; - } - - @LauncherAPI - public UpdateRequest(Path dir) { - this.dir = Objects.requireNonNull(dir, "dir"); - } + private final String dirName; } From b21c8b04c31a71cae274a9c2336f60953a98fe73 Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 5 Dec 2019 02:25:53 +0700 Subject: [PATCH 8/8] =?UTF-8?q?[FIX]=20=D0=9D=D0=B5=D0=BA=D0=BE=D1=80?= =?UTF-8?q?=D1=80=D0=B5=D0=BA=D1=82=D0=BD=D1=8B=D0=B9=20UpdateRequest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launcher/client/LauncherUpdateController.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java index c66a7ee1..599dc121 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java @@ -21,6 +21,7 @@ public class LauncherUpdateController { public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff diff) throws IOException { + /* if (e.zip && e.fullDownload) return; LogHelper.info("Enabled HStore feature. Find"); AtomicReference lastEn = new AtomicReference<>(null); @@ -74,6 +75,7 @@ public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff } return HashedDir.WalkAction.CONTINUE; }); + */ } public Path tryFind(NewLauncherSettings.HashedStoreEntry en, HashedFile file) throws IOException {