From 5939ed758f7012e4ce799313a3b64c594d7da765 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 18 Jan 2020 17:33:18 +0700 Subject: [PATCH] =?UTF-8?q?[ANY]=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=83=D1=81=D1=82=D0=B0=D1=80=D0=B5=D0=B2=D1=88?= =?UTF-8?q?=D0=B8=D1=85=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/client/ClientProcessBuilder.java | 153 ------------------ .../client/LauncherUpdateController.java | 104 ------------ .../launcher/managers/HasherManager.java | 9 -- .../gravit/launcher/managers/HasherStore.java | 68 -------- 4 files changed, 334 deletions(-) delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/managers/HasherManager.java delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/managers/HasherStore.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java deleted file mode 100644 index 0d579e7e..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java +++ /dev/null @@ -1,153 +0,0 @@ -package pro.gravit.launcher.client; - -import pro.gravit.launcher.ClientLauncherWrapper; -import pro.gravit.launcher.guard.LauncherGuardManager; -import pro.gravit.launcher.hasher.HashedDir; -import pro.gravit.launcher.managers.ClientHookManager; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.utils.DirWatcher; -import pro.gravit.utils.helper.EnvHelper; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JVMHelper; -import pro.gravit.utils.helper.LogHelper; - -import java.io.IOException; -import java.nio.file.Path; -import java.util.Collections; -import java.util.List; - -import static pro.gravit.launcher.client.ClientLauncher.checkJVMBitsAndVersion; - -public class ClientProcessBuilder { - private HashedDir assetHDir; - private HashedDir clientHDir; - private ClientProfile profile; - private ClientLauncher.Params params; - private Path nativesDir = IOHelper.toPath("natives"); - private Path resourcepacksDir = IOHelper.toPath("resourcepacks"); - private boolean pipeOutput = false; - private boolean clientLaunchStarting = false; - public interface ParamsWriter - { - void write(ClientLauncherContext context); - } - private ParamsWriter paramsWriter; - - private static final String MAGICAL_INTEL_OPTION = "-XX:HeapDumpPath=ThisTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump"; - - public ClientProcessBuilder setAssetHDir(HashedDir assetHDir) { - this.assetHDir = assetHDir; - return this; - } - - public ClientProcessBuilder setClientHDir(HashedDir clientHDir) { - this.clientHDir = clientHDir; - return this; - } - - public ClientProcessBuilder setProfile(ClientProfile profile) { - this.profile = profile; - return this; - } - - public ClientProcessBuilder setParams(ClientLauncher.Params params) { - this.params = params; - return this; - } - - public ClientProcessBuilder setNativesDir(Path nativesDir) { - this.nativesDir = nativesDir; - return this; - } - - public ClientProcessBuilder setResourcepacksDir(Path resourcepacksDir) { - this.resourcepacksDir = resourcepacksDir; - return this; - } - - public ClientProcessBuilder setPipeOutput(boolean pipeOutput) { - this.pipeOutput = pipeOutput; - return this; - } - - public ClientProcessBuilder setParamsWriter(ParamsWriter paramsWriter) { - this.paramsWriter = paramsWriter; - return this; - } - - public ClientLauncherContext build() throws IOException { - LogHelper.debug("Writing ClientLauncher params"); - ClientLauncherContext context = new ClientLauncherContext(); - clientLaunchStarting = true; - checkJVMBitsAndVersion(); - LogHelper.debug("Resolving JVM binary"); - Path javaBin = LauncherGuardManager.getGuardJavaBinPath(); - context.javaBin = javaBin; - context.clientProfile = profile; - context.playerProfile = params.pp; - context.args.add(javaBin.toString()); - context.args.add(MAGICAL_INTEL_OPTION); - context.params = params; - if(paramsWriter != null) paramsWriter.write(context); - if (params.ram > 0) { - context.args.add("-Xms" + params.ram + 'M'); - context.args.add("-Xmx" + params.ram + 'M'); - } - context.args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled()))); - context.args.add(JVMHelper.jvmProperty(LogHelper.STACKTRACE_PROPERTY, Boolean.toString(LogHelper.isStacktraceEnabled()))); - context.args.add(JVMHelper.jvmProperty(LogHelper.DEV_PROPERTY, Boolean.toString(LogHelper.isDevEnabled()))); - context.args.add(JVMHelper.jvmProperty(LogHelper.NO_JANSI_PROPERTY, "true")); // Отключаем JAnsi для нормального вывода в DEBUG окно - JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.CUSTOMDIR_PROPERTY); - JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.USE_CUSTOMDIR_PROPERTY); - JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.USE_OPTDIR_PROPERTY); - JVMHelper.addSystemPropertyToArgs(context.args, DirWatcher.IGN_OVERFLOW); - if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) { - if (JVMHelper.OS_VERSION.startsWith("10.")) { - LogHelper.debug("MustDie 10 fix is applied"); - context.args.add(JVMHelper.jvmProperty("os.name", "Windows 10")); - context.args.add(JVMHelper.jvmProperty("os.version", "10.0")); - } - } - // Add classpath and main class - String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); - context.pathLauncher = pathLauncher; - context.args.add(ClientLauncherWrapper.MAGIC_ARG); - Collections.addAll(context.args, profile.getJvmArgs()); - profile.pushOptionalJvmArgs(context.args); - context.args.add("-Djava.library.path=".concat(params.clientDir.resolve(nativesDir).toString())); // Add Native Path - context.args.add("-javaagent:".concat(pathLauncher)); - ClientHookManager.clientLaunchHook.hook(context); - LauncherGuardManager.guard.addCustomParams(context); - context.args.add(ClientLauncher.class.getName()); - ClientHookManager.clientLaunchFinallyHook.hook(context); - - // Print commandline debug message - LogHelper.debug("Commandline: " + context.args); - - // Build client process - LogHelper.debug("Launching client instance"); - ProcessBuilder builder = new ProcessBuilder(context.args); - context.builder = builder; - LauncherGuardManager.guard.addCustomEnv(context); - //else - //builder.environment().put("CLASSPATH", classPathString.toString()); - EnvHelper.addEnv(builder); - builder.directory(params.clientDir.toFile()); - builder.inheritIO(); - if (pipeOutput) { - builder.redirectErrorStream(true); - builder.redirectOutput(ProcessBuilder.Redirect.PIPE); - } - List command = builder.command(); - // Let's rock! - ClientHookManager.preStartHook.hook(context, builder); - context.process = builder.start(); - if (builder.command() != command) { - LogHelper.error("Something strange cheating..."); - System.exit(100); - return null; - } - ClientHookManager.postStartHook.hook(context, builder); - return context; - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java deleted file mode 100644 index 74ebd59a..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java +++ /dev/null @@ -1,104 +0,0 @@ -package pro.gravit.launcher.client; - -import pro.gravit.launcher.NewLauncherSettings; -import pro.gravit.launcher.events.request.UpdateRequestEvent; -import pro.gravit.launcher.hasher.HashedDir; -import pro.gravit.launcher.hasher.HashedEntry; -import pro.gravit.launcher.hasher.HashedFile; -import pro.gravit.launcher.request.update.UpdateRequest; -import pro.gravit.utils.helper.LogHelper; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.concurrent.atomic.AtomicReference; - -@Deprecated -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); - //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 { - AtomicReference ret = new AtomicReference<>(null); - en.hdir.walk(File.separator, (path, name, entry) -> { - if (entry.getType() == HashedEntry.Type.DIR) return HashedDir.WalkAction.CONTINUE; - HashedFile tfile = (HashedFile) entry; - if (tfile.isSame(file)) { - if (LogHelper.isDevEnabled()) { - LogHelper.dev("[DIR:%s] Found file %s in %s", en.name, name, path); - } - Path tdir = Paths.get(en.fullPath).resolve(path); - try { - if (tfile.isSame(tdir, true)) { - if (LogHelper.isDevEnabled()) { - LogHelper.dev("[DIR:%s] Confirmed file %s in %s", en.name, name, path); - } - ret.set(tdir); - return HashedDir.WalkAction.STOP; - } - } catch (IOException e) { - LogHelper.error("Check file error %s %s", e.getClass().getName(), e.getMessage()); - } - } - return HashedDir.WalkAction.CONTINUE; - }); - return ret.get(); - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/HasherManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/HasherManager.java deleted file mode 100644 index eaf8c4c5..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/HasherManager.java +++ /dev/null @@ -1,9 +0,0 @@ -package pro.gravit.launcher.managers; - -public class HasherManager { - public static final HasherStore defaultStore = new HasherStore(); - - public static HasherStore getDefaultStore() { - return defaultStore; - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/HasherStore.java b/Launcher/src/main/java/pro/gravit/launcher/managers/HasherStore.java deleted file mode 100644 index 57095622..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/HasherStore.java +++ /dev/null @@ -1,68 +0,0 @@ -package pro.gravit.launcher.managers; - -import pro.gravit.launcher.hasher.FileNameMatcher; -import pro.gravit.launcher.hasher.HashedDir; -import pro.gravit.launcher.hasher.HashedEntry; -import pro.gravit.launcher.profiles.ClientProfile; -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.util.Collection; -import java.util.LinkedList; -import java.util.Map; - -public class HasherStore { - public Map store; - - public static class HasherStoreEnity { - - public HashedDir hdir; - - public Path dir; - - public Collection shared; - } - - - public void addProfileUpdateDir(ClientProfile profile, Path dir, HashedDir hdir) { - HasherStoreEnity e = new HasherStoreEnity(); - e.hdir = hdir; - e.dir = dir; - e.shared = profile.getShared(); - - store.put(profile.getTitle(), e); - } - - - public void copyCompareFilesTo(String name, Path targetDir, HashedDir targetHDir, String[] shared) { - store.forEach((key, e) -> { - if (key.equals(name)) return; - FileNameMatcher nm = new FileNameMatcher(shared, null, null); - HashedDir compare = targetHDir.sideCompare(e.hdir, nm, new LinkedList<>(), true); - compare.map().forEach((arg1, arg2) -> recurseCopy(arg1, arg2, name, targetDir, e.dir)); - }); - } - - - public void recurseCopy(String filename, HashedEntry entry, String name, Path targetDir, Path sourceDir) { - if (!IOHelper.isDir(targetDir)) { - try { - Files.createDirectories(targetDir); - } catch (IOException e1) { - LogHelper.error(e1); - } - } - if (entry.getType().equals(HashedEntry.Type.DIR)) { - ((HashedDir) entry).map().forEach((arg1, arg2) -> recurseCopy(arg1, arg2, name, targetDir.resolve(filename), sourceDir.resolve(filename))); - } else if (entry.getType().equals(HashedEntry.Type.FILE)) { - try { - IOHelper.copy(sourceDir.resolve(filename), targetDir.resolve(filename)); - } catch (IOException e) { - LogHelper.error(e); - } - } - } -}