From e68dcea6bcb5830659d17db40fc9a83a4eca9cc0 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Mon, 24 Oct 2022 18:21:26 +0100 Subject: [PATCH 01/52] Various tweaks to the Java component of the launcher Signed-off-by: TheKodeToad --- launcher/minecraft/MinecraftInstance.cpp | 13 +- libraries/README.md | 6 +- libraries/launcher/CMakeLists.txt | 4 +- .../org/prismlauncher/EntryPoint.java | 52 ++--- .../launcher/org/prismlauncher/Launcher.java | 2 +- .../org/prismlauncher/LauncherFactory.java | 19 +- .../org/prismlauncher/applet/LegacyFrame.java | 3 +- .../prismlauncher/impl/AbstractLauncher.java | 95 +++++++++ .../prismlauncher/impl/LegacyLauncher.java | 104 ++++++++++ .../prismlauncher/impl/OneSixLauncher.java | 190 ------------------ .../prismlauncher/impl/StandardLauncher.java | 51 +++++ .../org/prismlauncher/utils/Parameters.java | 12 +- .../org/prismlauncher/utils/Utils.java | 2 +- 13 files changed, 316 insertions(+), 237 deletions(-) create mode 100644 libraries/launcher/org/prismlauncher/impl/AbstractLauncher.java create mode 100644 libraries/launcher/org/prismlauncher/impl/LegacyLauncher.java delete mode 100644 libraries/launcher/org/prismlauncher/impl/OneSixLauncher.java create mode 100644 libraries/launcher/org/prismlauncher/impl/StandardLauncher.java diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index 3a820951..5a5245ed 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -3,6 +3,7 @@ * PolyMC - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Jamie Mansfield + * Copyright (C) 2022 TheKodeToad * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -647,7 +648,17 @@ QString MinecraftInstance::createLaunchScript(AuthSessionPtr session, MinecraftS { launchScript += "traits " + trait + "\n"; } - launchScript += "launcher onesix\n"; + + launchScript += "launcher "; + + // use legacy launcher if the traits are set + if (profile->getTraits().contains("legacyLaunch") || profile->getTraits().contains("alphaLaunch")) + launchScript += "legacy"; + else + launchScript += "standard"; + + launchScript += "\n"; + // qDebug() << "Generated launch script:" << launchScript; return launchScript; } diff --git a/libraries/README.md b/libraries/README.md index dc38477b..2971e32b 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -51,10 +51,10 @@ It: This means the process is essentially idle until the final command is sent. You can, for example, attach a profiler before you send it. -A `legacy` and `onesix` launchers are available. +A `legacy` and `standard` launchers are available. - `legacy` is intended for use with Minecraft versions < 1.6 and is deprecated. -- `onesix` can handle launching any Minecraft version, at the cost of some extra features `legacy` enables (custom window icon and title). +- `standard` can handle launching any Minecraft version, at the cost of some extra features `legacy` enables (custom window icon and title). Example (some parts have been censored): @@ -132,7 +132,7 @@ ext /home/peterix/minecraft/FTB/libraries/org/lwjgl/lwjgl/lwjgl-platform/2.9.1/l ext /home/peterix/minecraft/FTB/libraries/net/java/jinput/jinput-platform/2.0.5/jinput-platform-2.0.5-natives-linux.jar natives /home/peterix/minecraft/FTB/17ForgeTest/natives cp /home/peterix/minecraft/FTB/versions/1.7.10/1.7.10.jar -launcher onesix +launcher standard ``` Available under `GPL-3.0-only` (with classpath exception), sublicensed from its original `Apache-2.0` codebase diff --git a/libraries/launcher/CMakeLists.txt b/libraries/launcher/CMakeLists.txt index df25414f..ee88d0f9 100644 --- a/libraries/launcher/CMakeLists.txt +++ b/libraries/launcher/CMakeLists.txt @@ -10,7 +10,9 @@ set(SRC org/prismlauncher/EntryPoint.java org/prismlauncher/Launcher.java org/prismlauncher/LauncherFactory.java - org/prismlauncher/impl/OneSixLauncher.java + org/prismlauncher/impl/AbstractLauncher.java + org/prismlauncher/impl/LegacyLauncher.java + org/prismlauncher/impl/StandardLauncher.java org/prismlauncher/applet/LegacyFrame.java org/prismlauncher/exception/ParameterNotFoundException.java org/prismlauncher/exception/ParseException.java diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index 9144e1f1..73ff9753 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -81,33 +81,35 @@ public final class EntryPoint { } private Action parseLine(String inData) throws ParseException { - String[] tokens = inData.split("\\s+", 2); - - if (tokens.length == 0) + if (inData.length() == 0) throw new ParseException("Unexpected empty string!"); - switch (tokens[0]) { - case "launch": { - return Action.Launch; - } + String first = inData; + String second = null; + int splitPoint = inData.indexOf(' '); - case "abort": { - return Action.Abort; - } + if (splitPoint != -1) { + first = first.substring(0, splitPoint); + second = inData.substring(splitPoint + 1); + } - default: { - if (tokens.length != 2) + switch (first) { + case "launch": + return Action.LAUNCH; + case "abort": + return Action.ABORT; + default: + if (second == null || second.isEmpty()) throw new ParseException("Error while parsing:" + inData); - params.add(tokens[0], tokens[1]); + params.add(first, second); - return Action.Proceed; - } + return Action.PROCEED; } } public int listen() { - Action action = Action.Proceed; + Action action = Action.PROCEED; try (BufferedReader reader = new BufferedReader(new InputStreamReader( System.in, @@ -115,21 +117,21 @@ public final class EntryPoint { ))) { String line; - while (action == Action.Proceed) { + while (action == Action.PROCEED) { if ((line = reader.readLine()) != null) { action = parseLine(line); } else { - action = Action.Abort; + action = Action.ABORT; } } } catch (IOException | ParseException e) { - LOGGER.log(Level.SEVERE, "Launcher ABORT due to exception:", e); + LOGGER.log(Level.SEVERE, "Launcher abort due to exception:", e); return 1; } // Main loop - if (action == Action.Abort) { + if (action == Action.ABORT) { LOGGER.info("Launch aborted by the launcher."); return 1; @@ -138,7 +140,7 @@ public final class EntryPoint { try { Launcher launcher = LauncherFactory - .getInstance() + .INSTANCE .createLauncher(params); launcher.launch(); @@ -148,7 +150,7 @@ public final class EntryPoint { LOGGER.log(Level.SEVERE, "Wrong argument.", e); return 1; - } catch (Exception e) { + } catch (Throwable e) { LOGGER.log(Level.SEVERE, "Exception caught from launcher.", e); return 1; @@ -156,9 +158,9 @@ public final class EntryPoint { } private enum Action { - Proceed, - Launch, - Abort + PROCEED, + LAUNCH, + ABORT } } diff --git a/libraries/launcher/org/prismlauncher/Launcher.java b/libraries/launcher/org/prismlauncher/Launcher.java index 7f25717b..50c2c9c8 100644 --- a/libraries/launcher/org/prismlauncher/Launcher.java +++ b/libraries/launcher/org/prismlauncher/Launcher.java @@ -18,6 +18,6 @@ package org.prismlauncher; public interface Launcher { - void launch() throws Exception; + void launch() throws Throwable; } diff --git a/libraries/launcher/org/prismlauncher/LauncherFactory.java b/libraries/launcher/org/prismlauncher/LauncherFactory.java index 98f2bbba..354ad1f0 100644 --- a/libraries/launcher/org/prismlauncher/LauncherFactory.java +++ b/libraries/launcher/org/prismlauncher/LauncherFactory.java @@ -35,7 +35,8 @@ package org.prismlauncher; -import org.prismlauncher.impl.OneSixLauncher; +import org.prismlauncher.impl.LegacyLauncher; +import org.prismlauncher.impl.StandardLauncher; import org.prismlauncher.utils.Parameters; import java.util.HashMap; @@ -43,15 +44,21 @@ import java.util.Map; public final class LauncherFactory { - private static final LauncherFactory INSTANCE = new LauncherFactory(); + public static final LauncherFactory INSTANCE = new LauncherFactory(); private final Map launcherRegistry = new HashMap<>(); private LauncherFactory() { - launcherRegistry.put("onesix", new LauncherProvider() { + launcherRegistry.put("standard", new LauncherProvider() { @Override public Launcher provide(Parameters parameters) { - return new OneSixLauncher(parameters); + return new StandardLauncher(parameters); + } + }); + launcherRegistry.put("legacy", new LauncherProvider() { + @Override + public Launcher provide(Parameters parameters) { + return new LegacyLauncher(parameters); } }); } @@ -67,10 +74,6 @@ public final class LauncherFactory { return launcherProvider.provide(parameters); } - public static LauncherFactory getInstance() { - return INSTANCE; - } - public interface LauncherProvider { Launcher provide(Parameters parameters); diff --git a/libraries/launcher/org/prismlauncher/applet/LegacyFrame.java b/libraries/launcher/org/prismlauncher/applet/LegacyFrame.java index 4413efa8..f3359fca 100644 --- a/libraries/launcher/org/prismlauncher/applet/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/applet/LegacyFrame.java @@ -34,6 +34,7 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; +@SuppressWarnings("removal") public final class LegacyFrame extends Frame { private static final Logger LOGGER = Logger.getLogger("LegacyFrame"); @@ -105,7 +106,7 @@ public final class LegacyFrame extends Frame { appletWrap.setParameter("username", user); appletWrap.setParameter("sessionid", session); - appletWrap.setParameter("stand-alone", "true"); // Show the quit button. + appletWrap.setParameter("stand-alone", "true"); // Show the quit button. TODO: why won't this work? appletWrap.setParameter("haspaid", "true"); // Some old versions need this for world saves to work. appletWrap.setParameter("demo", isDemo ? "true" : "false"); appletWrap.setParameter("fullscreen", "false"); diff --git a/libraries/launcher/org/prismlauncher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/impl/AbstractLauncher.java new file mode 100644 index 00000000..49a984f5 --- /dev/null +++ b/libraries/launcher/org/prismlauncher/impl/AbstractLauncher.java @@ -0,0 +1,95 @@ +/* Copyright 2012-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.prismlauncher.impl; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.prismlauncher.Launcher; +import org.prismlauncher.exception.ParseException; +import org.prismlauncher.utils.Parameters; + +public abstract class AbstractLauncher implements Launcher { + + private static final int DEFAULT_WINDOW_WIDTH = 854; + private static final int DEFAULT_WINDOW_HEIGHT = 480; + + // parameters, separated from ParamBucket + protected final List mcParams; + private final String mainClass; + + // secondary parameters + protected final int width; + protected final int height; + protected final boolean maximize; + + protected final String serverAddress, serverPort; + + protected final ClassLoader classLoader; + + public AbstractLauncher(Parameters params) { + classLoader = ClassLoader.getSystemClassLoader(); + + mcParams = params.allSafe("param", new ArrayList()); + mainClass = params.firstSafe("mainClass", "net.minecraft.client.Minecraft"); + + serverAddress = params.firstSafe("serverAddress", null); + serverPort = params.firstSafe("serverPort", null); + + String windowParams = params.firstSafe("windowParams", null); + + if ("max".equals(windowParams) || windowParams == null) { + maximize = windowParams != null; + + width = DEFAULT_WINDOW_WIDTH; + height = DEFAULT_WINDOW_HEIGHT; + } else { + maximize = false; + + int byIndex = windowParams.indexOf('x'); + + if (byIndex != -1) { + try { + width = Integer.parseInt(windowParams.substring(0, byIndex)); + height = Integer.parseInt(windowParams.substring(byIndex + 1)); + return; + } catch(NumberFormatException pass) { + } + } + + throw new ParseException("Invalid window size parameter value: " + windowParams); + } + } + + protected Class loadMain() throws ClassNotFoundException { + return classLoader.loadClass(mainClass); + } + + protected void loadAndInvokeMain() throws Throwable, ClassNotFoundException { + invokeMain(loadMain()); + } + + protected void invokeMain(Class mainClass) throws Throwable { + MethodHandle method = MethodHandles.lookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)); + + method.invokeExact(mcParams.toArray(new String[0])); + } + +} diff --git a/libraries/launcher/org/prismlauncher/impl/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/impl/LegacyLauncher.java new file mode 100644 index 00000000..30a4dba7 --- /dev/null +++ b/libraries/launcher/org/prismlauncher/impl/LegacyLauncher.java @@ -0,0 +1,104 @@ +/* Copyright 2012-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.prismlauncher.impl; + +import java.applet.Applet; +import java.io.File; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.lang.reflect.Field; +import java.util.Collections; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.prismlauncher.applet.LegacyFrame; +import org.prismlauncher.utils.Parameters; +import org.prismlauncher.utils.Utils; + +@SuppressWarnings("removal") +public final class LegacyLauncher extends AbstractLauncher { + + private static final Logger LOGGER = Logger.getLogger("LegacyLauncher"); + + private final String user, session; + private final String title; + private final String appletClass; + + private final boolean noApplet; + private final String cwd; + + public LegacyLauncher(Parameters params) { + super(params); + + user = params.first("userName"); + session = params.first("sessionId"); + title = params.firstSafe("windowTitle", "Minecraft"); + appletClass = params.firstSafe("appletClass", "net.minecraft.client.MinecraftApplet"); + + List traits = params.allSafe("traits", Collections.emptyList()); + noApplet = traits.contains("noapplet"); + + cwd = System.getProperty("user.dir"); + } + + @Override + public void launch() throws Throwable { + Class main = loadMain(); + Field gameDirField = Utils.getMinecraftGameDirField(main); + + if (gameDirField == null) { + LOGGER.warning("Could not find Mineraft path field."); + } else { + gameDirField.setAccessible(true); + gameDirField.set(null, new File(cwd)); + } + + if (!noApplet) { + LOGGER.info("Launching with applet wrapper..."); + + try { + Class appletClass = classLoader.loadClass(this.appletClass); + + MethodHandle constructor = MethodHandles.lookup().findConstructor(appletClass, MethodType.methodType(void.class)); + Applet applet = (Applet) constructor.invoke(); + + LegacyFrame window = new LegacyFrame(title, applet); + + window.start( + user, + session, + width, + height, + maximize, + serverAddress, + serverPort, + mcParams.contains("--demo") + ); + + return; + } catch (Throwable e) { + LOGGER.log(Level.SEVERE, "Applet wrapper failed:", e); + + LOGGER.warning("Falling back to using main class."); + } + } + + invokeMain(main); + } + +} diff --git a/libraries/launcher/org/prismlauncher/impl/OneSixLauncher.java b/libraries/launcher/org/prismlauncher/impl/OneSixLauncher.java deleted file mode 100644 index d6443826..00000000 --- a/libraries/launcher/org/prismlauncher/impl/OneSixLauncher.java +++ /dev/null @@ -1,190 +0,0 @@ -/* Copyright 2012-2021 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.prismlauncher.impl; - -import org.prismlauncher.Launcher; -import org.prismlauncher.applet.LegacyFrame; -import org.prismlauncher.utils.Parameters; -import org.prismlauncher.utils.Utils; - -import java.applet.Applet; -import java.io.File; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.List; -import java.util.ArrayList; -import java.util.logging.Level; -import java.util.logging.Logger; - -public final class OneSixLauncher implements Launcher { - - private static final int DEFAULT_WINDOW_WIDTH = 854; - private static final int DEFAULT_WINDOW_HEIGHT = 480; - - private static final Logger LOGGER = Logger.getLogger("OneSixLauncher"); - - // parameters, separated from ParamBucket - private final List mcParams; - private final List traits; - private final String appletClass; - private final String mainClass; - private final String userName, sessionId; - private final String windowTitle; - - // secondary parameters - private final int winSizeW; - private final int winSizeH; - private final boolean maximize; - private final String cwd; - - private final String serverAddress; - private final String serverPort; - - private final ClassLoader classLoader; - - public OneSixLauncher(Parameters params) { - classLoader = ClassLoader.getSystemClassLoader(); - - mcParams = params.allSafe("param", new ArrayList()); - mainClass = params.firstSafe("mainClass", "net.minecraft.client.Minecraft"); - appletClass = params.firstSafe("appletClass", "net.minecraft.client.MinecraftApplet"); - traits = params.allSafe("traits", new ArrayList()); - - userName = params.first("userName"); - sessionId = params.first("sessionId"); - windowTitle = params.firstSafe("windowTitle", "Minecraft"); - - serverAddress = params.firstSafe("serverAddress", null); - serverPort = params.firstSafe("serverPort", null); - - cwd = System.getProperty("user.dir"); - - String windowParams = params.firstSafe("windowParams", null); - - if (windowParams != null) { - String[] dimStrings = windowParams.split("x"); - - if (windowParams.equalsIgnoreCase("max")) { - maximize = true; - - winSizeW = DEFAULT_WINDOW_WIDTH; - winSizeH = DEFAULT_WINDOW_HEIGHT; - } else if (dimStrings.length == 2) { - maximize = false; - - winSizeW = Integer.parseInt(dimStrings[0]); - winSizeH = Integer.parseInt(dimStrings[1]); - } else { - throw new IllegalArgumentException("Unexpected window size parameter value: " + windowParams); - } - } else { - maximize = false; - - winSizeW = DEFAULT_WINDOW_WIDTH; - winSizeH = DEFAULT_WINDOW_HEIGHT; - } - } - - private void invokeMain(Class mainClass) throws Exception { - Method method = mainClass.getMethod("main", String[].class); - - method.invoke(null, (Object) mcParams.toArray(new String[0])); - } - - private void legacyLaunch() throws Exception { - // Get the Minecraft Class and set the base folder - Class minecraftClass = classLoader.loadClass(mainClass); - - Field baseDirField = Utils.getMinecraftBaseDirField(minecraftClass); - - if (baseDirField == null) { - LOGGER.warning("Could not find Minecraft path field."); - } else { - baseDirField.setAccessible(true); - - baseDirField.set(null, new File(cwd)); - } - - System.setProperty("minecraft.applet.TargetDirectory", cwd); - - if (!traits.contains("noapplet")) { - LOGGER.info("Launching with applet wrapper..."); - - try { - Class mcAppletClass = classLoader.loadClass(appletClass); - - Applet mcApplet = (Applet) mcAppletClass.getConstructor().newInstance(); - - LegacyFrame mcWindow = new LegacyFrame(windowTitle, mcApplet); - - mcWindow.start( - userName, - sessionId, - winSizeW, - winSizeH, - maximize, - serverAddress, - serverPort, - mcParams.contains("--demo") - ); - - return; - } catch (Exception e) { - LOGGER.log(Level.SEVERE, "Applet wrapper failed: ", e); - - LOGGER.warning("Falling back to using main class."); - } - } - - invokeMain(minecraftClass); - } - - private void launchWithMainClass() throws Exception { - // window size, title and state, onesix - - // FIXME: there is no good way to maximize the minecraft window in onesix. - // the following often breaks linux screen setups - // mcparams.add("--fullscreen"); - - if (!maximize) { - mcParams.add("--width"); - mcParams.add(Integer.toString(winSizeW)); - mcParams.add("--height"); - mcParams.add(Integer.toString(winSizeH)); - } - - if (serverAddress != null) { - mcParams.add("--server"); - mcParams.add(serverAddress); - mcParams.add("--port"); - mcParams.add(serverPort); - } - - invokeMain(classLoader.loadClass(mainClass)); - } - - @Override - public void launch() throws Exception { - if (traits.contains("legacyLaunch") || traits.contains("alphaLaunch")) { - // legacy launch uses the applet wrapper - legacyLaunch(); - } else { - // normal launch just calls main() - launchWithMainClass(); - } - } - -} diff --git a/libraries/launcher/org/prismlauncher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/impl/StandardLauncher.java new file mode 100644 index 00000000..c651b060 --- /dev/null +++ b/libraries/launcher/org/prismlauncher/impl/StandardLauncher.java @@ -0,0 +1,51 @@ +/* Copyright 2012-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.prismlauncher.impl; + +import org.prismlauncher.utils.Parameters; + +public final class StandardLauncher extends AbstractLauncher { + + public StandardLauncher(Parameters params) { + super(params); + } + + @Override + public void launch() throws Throwable { + // window size, title and state + + // FIXME: there is no good way to maximize the minecraft window from here. + // the following often breaks linux screen setups + // mcparams.add("--fullscreen"); + + if (!maximize) { + mcParams.add("--width"); + mcParams.add(Integer.toString(width)); + mcParams.add("--height"); + mcParams.add(Integer.toString(height)); + } + + if (serverAddress != null) { + mcParams.add("--server"); + mcParams.add(serverAddress); + mcParams.add("--port"); + mcParams.add(serverPort); + } + + loadAndInvokeMain(); + } + +} diff --git a/libraries/launcher/org/prismlauncher/utils/Parameters.java b/libraries/launcher/org/prismlauncher/utils/Parameters.java index 98a40c28..dcaba18d 100644 --- a/libraries/launcher/org/prismlauncher/utils/Parameters.java +++ b/libraries/launcher/org/prismlauncher/utils/Parameters.java @@ -25,22 +25,22 @@ import java.util.Map; public final class Parameters { - private final Map> paramsMap = new HashMap<>(); + private final Map> map = new HashMap<>(); public void add(String key, String value) { - List params = paramsMap.get(key); + List params = map.get(key); if (params == null) { params = new ArrayList<>(); - paramsMap.put(key, params); + map.put(key, params); } params.add(value); } public List all(String key) throws ParameterNotFoundException { - List params = paramsMap.get(key); + List params = map.get(key); if (params == null) throw new ParameterNotFoundException(key); @@ -49,7 +49,7 @@ public final class Parameters { } public List allSafe(String key, List def) { - List params = paramsMap.get(key); + List params = map.get(key); if (params == null || params.isEmpty()) return def; @@ -67,7 +67,7 @@ public final class Parameters { } public String firstSafe(String key, String def) { - List params = paramsMap.get(key); + List params = map.get(key); if (params == null || params.isEmpty()) return def; diff --git a/libraries/launcher/org/prismlauncher/utils/Utils.java b/libraries/launcher/org/prismlauncher/utils/Utils.java index ae9a4de2..79f5367b 100644 --- a/libraries/launcher/org/prismlauncher/utils/Utils.java +++ b/libraries/launcher/org/prismlauncher/utils/Utils.java @@ -29,7 +29,7 @@ public final class Utils { * * @param clazz the class to scan */ - public static Field getMinecraftBaseDirField(Class clazz) { + public static Field getMinecraftGameDirField(Class clazz) { for (Field f : clazz.getDeclaredFields()) { // Has to be File if (f.getType() != File.class) From 9062d28704f8508a031612f102c27a63b3655e0a Mon Sep 17 00:00:00 2001 From: solonovamax Date: Thu, 27 Oct 2022 18:01:17 -0400 Subject: [PATCH 02/52] Get rid of singleton, and refactor LauncherFactory to be a static class Signed-off-by: solonovamax --- .../org/prismlauncher/EntryPoint.java | 5 +-- .../org/prismlauncher/LauncherFactory.java | 31 ++++++++++--------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index 73ff9753..37db6a5d 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -138,10 +138,7 @@ public final class EntryPoint { } try { - Launcher launcher = - LauncherFactory - .INSTANCE - .createLauncher(params); + Launcher launcher = LauncherFactory.createLauncher(params); launcher.launch(); diff --git a/libraries/launcher/org/prismlauncher/LauncherFactory.java b/libraries/launcher/org/prismlauncher/LauncherFactory.java index 354ad1f0..5b18cc5f 100644 --- a/libraries/launcher/org/prismlauncher/LauncherFactory.java +++ b/libraries/launcher/org/prismlauncher/LauncherFactory.java @@ -35,6 +35,7 @@ package org.prismlauncher; + import org.prismlauncher.impl.LegacyLauncher; import org.prismlauncher.impl.StandardLauncher; import org.prismlauncher.utils.Parameters; @@ -42,13 +43,11 @@ import org.prismlauncher.utils.Parameters; import java.util.HashMap; import java.util.Map; + public final class LauncherFactory { - - public static final LauncherFactory INSTANCE = new LauncherFactory(); - - private final Map launcherRegistry = new HashMap<>(); - - private LauncherFactory() { + private static final Map launcherRegistry = new HashMap<>(); + + static { launcherRegistry.put("standard", new LauncherProvider() { @Override public Launcher provide(Parameters parameters) { @@ -62,22 +61,24 @@ public final class LauncherFactory { } }); } - - public Launcher createLauncher(Parameters parameters) { + private LauncherFactory() { + } + + public static Launcher createLauncher(Parameters parameters) { String name = parameters.first("launcher"); - + LauncherProvider launcherProvider = launcherRegistry.get(name); - + if (launcherProvider == null) throw new IllegalArgumentException("Invalid launcher type: " + name); - + return launcherProvider.provide(parameters); } - + public interface LauncherProvider { - + Launcher provide(Parameters parameters); - + } - + } From 107fa6b4f73c4b9178e5055995500fa9ad75da27 Mon Sep 17 00:00:00 2001 From: solonovamax Date: Thu, 27 Oct 2022 19:52:09 -0400 Subject: [PATCH 03/52] Code refactors - Refactor LauncherFactory.LauncherProvider to LauncherFactory - Refactor all launcher related components to launcher package - some basic code cleanup - Rename all, allSafe -> getList and first, firstSafe -> getString - Rename Utils -> LegacyUtils Signed-off-by: solonovamax --- libraries/launcher/CMakeLists.txt | 13 +- .../launcher/net/minecraft/Launcher.java | 182 +++++++++--------- .../org/prismlauncher/EntryPoint.java | 4 +- .../{ => launcher}/Launcher.java | 5 +- .../{ => launcher}/LauncherFactory.java | 17 +- .../launcher/LauncherProvider.java | 44 +++++ .../{ => launcher}/impl/AbstractLauncher.java | 43 +++-- .../{ => launcher}/impl/LegacyLauncher.java | 29 +-- .../{ => launcher}/impl/StandardLauncher.java | 2 +- .../utils/{Utils.java => LegacyUtils.java} | 27 +-- .../org/prismlauncher/utils/Parameters.java | 32 +-- 11 files changed, 227 insertions(+), 171 deletions(-) rename libraries/launcher/org/prismlauncher/{ => launcher}/Launcher.java (94%) rename libraries/launcher/org/prismlauncher/{ => launcher}/LauncherFactory.java (89%) create mode 100644 libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java rename libraries/launcher/org/prismlauncher/{ => launcher}/impl/AbstractLauncher.java (80%) rename libraries/launcher/org/prismlauncher/{ => launcher}/impl/LegacyLauncher.java (86%) rename libraries/launcher/org/prismlauncher/{ => launcher}/impl/StandardLauncher.java (97%) rename libraries/launcher/org/prismlauncher/utils/{Utils.java => LegacyUtils.java} (71%) diff --git a/libraries/launcher/CMakeLists.txt b/libraries/launcher/CMakeLists.txt index ee88d0f9..d74c3641 100644 --- a/libraries/launcher/CMakeLists.txt +++ b/libraries/launcher/CMakeLists.txt @@ -8,16 +8,17 @@ set(CMAKE_JAVA_COMPILE_FLAGS -target 7 -source 7 -Xlint:deprecation -Xlint:unche set(SRC org/prismlauncher/EntryPoint.java - org/prismlauncher/Launcher.java - org/prismlauncher/LauncherFactory.java - org/prismlauncher/impl/AbstractLauncher.java - org/prismlauncher/impl/LegacyLauncher.java - org/prismlauncher/impl/StandardLauncher.java + org/prismlauncher/launcher/Launcher.java + org/prismlauncher/launcher/LauncherFactory.java + org/prismlauncher/launcher/LauncherProvider.java + org/prismlauncher/launcher/impl/AbstractLauncher.java + org/prismlauncher/launcher/impl/LegacyLauncher.java + org/prismlauncher/launcher/impl/StandardLauncher.java org/prismlauncher/applet/LegacyFrame.java org/prismlauncher/exception/ParameterNotFoundException.java org/prismlauncher/exception/ParseException.java org/prismlauncher/utils/Parameters.java - org/prismlauncher/utils/Utils.java + org/prismlauncher/utils/LegacyUtils.java net/minecraft/Launcher.java ) add_jar(NewLaunch ${SRC}) diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java index 6bf671be..f9fd0a97 100644 --- a/libraries/launcher/net/minecraft/Launcher.java +++ b/libraries/launcher/net/minecraft/Launcher.java @@ -16,157 +16,167 @@ package net.minecraft; + import java.applet.Applet; import java.applet.AppletStub; -import java.awt.*; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Graphics; import java.net.MalformedURLException; import java.net.URL; import java.util.Map; import java.util.TreeMap; + /* * WARNING: This class is reflectively accessed by legacy Forge versions. * Changing field and method declarations without further testing is not recommended. */ public final class Launcher extends Applet implements AppletStub { - + private final Map params = new TreeMap<>(); - + private Applet wrappedApplet; - - private URL documentBase; - + + private final URL documentBase; + private boolean active = false; - + public Launcher(Applet applet) { this(applet, null); } - + public Launcher(Applet applet, URL documentBase) { this.setLayout(new BorderLayout()); - + this.add(applet, "Center"); - + this.wrappedApplet = applet; - + try { if (documentBase != null) { this.documentBase = documentBase; } else if (applet.getClass().getPackage().getName().startsWith("com.mojang")) { // Special case only for Classic versions - + + // TODO: 2022-10-27 Can this be changed to https this.documentBase = new URL("http", "www.minecraft.net", 80, "/game/"); } else { + // TODO: 2022-10-27 Can this be changed to https? this.documentBase = new URL("http://www.minecraft.net/game/"); } } catch (MalformedURLException e) { throw new RuntimeException(e); } } - + public void replace(Applet applet) { this.wrappedApplet = applet; - + applet.setStub(this); applet.setSize(getWidth(), getHeight()); - + this.setLayout(new BorderLayout()); this.add(applet, "Center"); - + applet.init(); - + active = true; - + applet.start(); - + validate(); } - - public void setParameter(String name, String value) { - params.put(name, value); - } - - @Override - public String getParameter(String name) { - String param = params.get(name); - - if (param != null) - return param; - - try { - return super.getParameter(name); - } catch (Exception ignored) {} - - return null; - } - + @Override public boolean isActive() { return active; } - + @Override - public void appletResize(int width, int height) { - wrappedApplet.resize(width, height); + public URL getDocumentBase() { + return documentBase; } - - @Override - public void resize(int width, int height) { - wrappedApplet.resize(width, height); - } - - @Override - public void resize(Dimension d) { - wrappedApplet.resize(d); - } - - @Override - public void init() { - if (wrappedApplet != null) - wrappedApplet.init(); - } - - @Override - public void start() { - wrappedApplet.start(); - - active = true; - } - - @Override - public void stop() { - wrappedApplet.stop(); - - active = false; - } - - public void destroy() { - wrappedApplet.destroy(); - } - + @Override public URL getCodeBase() { try { + // TODO: 2022-10-27 Can this be changed to https? return new URL("http://www.minecraft.net/game/"); } catch (MalformedURLException e) { throw new RuntimeException(e); } } - + @Override - public URL getDocumentBase() { - return documentBase; + public String getParameter(String name) { + String param = params.get(name); + + if (param != null) + return param; + + try { + return super.getParameter(name); + } catch (Exception ignored) { + } + + return null; } - + + @Override + public void resize(int width, int height) { + wrappedApplet.resize(width, height); + } + + @Override + public void resize(Dimension d) { + wrappedApplet.resize(d); + } + + @Override + public void init() { + if (wrappedApplet != null) + wrappedApplet.init(); + } + + @Override + public void start() { + wrappedApplet.start(); + + active = true; + } + + @Override + public void stop() { + wrappedApplet.stop(); + + active = false; + } + + public void destroy() { + wrappedApplet.destroy(); + } + + @Override + public void appletResize(int width, int height) { + wrappedApplet.resize(width, height); + } + @Override public void setVisible(boolean b) { super.setVisible(b); - + wrappedApplet.setVisible(b); } - - public void update(Graphics paramGraphics) {} - - public void paint(Graphics paramGraphics) {} - + + public void paint(Graphics paramGraphics) { + } + + public void update(Graphics paramGraphics) { + } + + public void setParameter(String name, String value) { + params.put(name, value); + } + } diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index 37db6a5d..44e947b1 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -53,6 +53,8 @@ package org.prismlauncher; import org.prismlauncher.exception.ParseException; +import org.prismlauncher.launcher.Launcher; +import org.prismlauncher.launcher.LauncherFactory; import org.prismlauncher.utils.Parameters; import java.io.BufferedReader; @@ -81,7 +83,7 @@ public final class EntryPoint { } private Action parseLine(String inData) throws ParseException { - if (inData.length() == 0) + if (inData.isEmpty()) throw new ParseException("Unexpected empty string!"); String first = inData; diff --git a/libraries/launcher/org/prismlauncher/Launcher.java b/libraries/launcher/org/prismlauncher/launcher/Launcher.java similarity index 94% rename from libraries/launcher/org/prismlauncher/Launcher.java rename to libraries/launcher/org/prismlauncher/launcher/Launcher.java index 50c2c9c8..1cea255c 100644 --- a/libraries/launcher/org/prismlauncher/Launcher.java +++ b/libraries/launcher/org/prismlauncher/launcher/Launcher.java @@ -14,10 +14,9 @@ * limitations under the License. */ -package org.prismlauncher; +package org.prismlauncher.launcher; + public interface Launcher { - void launch() throws Throwable; - } diff --git a/libraries/launcher/org/prismlauncher/LauncherFactory.java b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java similarity index 89% rename from libraries/launcher/org/prismlauncher/LauncherFactory.java rename to libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java index 5b18cc5f..6c601171 100644 --- a/libraries/launcher/org/prismlauncher/LauncherFactory.java +++ b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea, * * This program is free software: you can redistribute it and/or modify @@ -33,11 +33,11 @@ * along with this program. If not, see . */ -package org.prismlauncher; +package org.prismlauncher.launcher; -import org.prismlauncher.impl.LegacyLauncher; -import org.prismlauncher.impl.StandardLauncher; +import org.prismlauncher.launcher.impl.LegacyLauncher; +import org.prismlauncher.launcher.impl.StandardLauncher; import org.prismlauncher.utils.Parameters; import java.util.HashMap; @@ -65,7 +65,7 @@ public final class LauncherFactory { } public static Launcher createLauncher(Parameters parameters) { - String name = parameters.first("launcher"); + String name = parameters.getString("launcher"); LauncherProvider launcherProvider = launcherRegistry.get(name); @@ -74,11 +74,4 @@ public final class LauncherFactory { return launcherProvider.provide(parameters); } - - public interface LauncherProvider { - - Launcher provide(Parameters parameters); - - } - } diff --git a/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java b/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java new file mode 100644 index 00000000..b6d1caab --- /dev/null +++ b/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 solonovamax, + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give + * you permission to link this library with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also meet, + * for each linked independent module, the terms and conditions of the + * license of that module. An independent module is a module which is + * not derived from or based on this library. If you modify this + * library, you may extend this exception to your version of the + * library, but you are not obliged to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.prismlauncher.launcher; + + +import org.prismlauncher.utils.Parameters; + + +public interface LauncherProvider { + Launcher provide(Parameters parameters); +} diff --git a/libraries/launcher/org/prismlauncher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java similarity index 80% rename from libraries/launcher/org/prismlauncher/impl/AbstractLauncher.java rename to libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java index 49a984f5..637c5da7 100644 --- a/libraries/launcher/org/prismlauncher/impl/AbstractLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java @@ -13,21 +13,22 @@ * limitations under the License. */ -package org.prismlauncher.impl; +package org.prismlauncher.launcher.impl; + + +import org.prismlauncher.exception.ParseException; +import org.prismlauncher.launcher.Launcher; +import org.prismlauncher.utils.Parameters; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import org.prismlauncher.Launcher; -import org.prismlauncher.exception.ParseException; -import org.prismlauncher.utils.Parameters; public abstract class AbstractLauncher implements Launcher { - + private static final int DEFAULT_WINDOW_WIDTH = 854; private static final int DEFAULT_WINDOW_HEIGHT = 480; @@ -43,21 +44,21 @@ public abstract class AbstractLauncher implements Launcher { protected final String serverAddress, serverPort; protected final ClassLoader classLoader; - - public AbstractLauncher(Parameters params) { + + protected AbstractLauncher(Parameters params) { classLoader = ClassLoader.getSystemClassLoader(); - - mcParams = params.allSafe("param", new ArrayList()); - mainClass = params.firstSafe("mainClass", "net.minecraft.client.Minecraft"); - - serverAddress = params.firstSafe("serverAddress", null); - serverPort = params.firstSafe("serverPort", null); - - String windowParams = params.firstSafe("windowParams", null); - + + mcParams = params.getList("param", new ArrayList()); + mainClass = params.getString("mainClass", "net.minecraft.client.Minecraft"); + + serverAddress = params.getString("serverAddress", null); + serverPort = params.getString("serverPort", null); + + String windowParams = params.getString("windowParams", null); + if ("max".equals(windowParams) || windowParams == null) { maximize = windowParams != null; - + width = DEFAULT_WINDOW_WIDTH; height = DEFAULT_WINDOW_HEIGHT; } else { @@ -70,7 +71,7 @@ public abstract class AbstractLauncher implements Launcher { width = Integer.parseInt(windowParams.substring(0, byIndex)); height = Integer.parseInt(windowParams.substring(byIndex + 1)); return; - } catch(NumberFormatException pass) { + } catch (NumberFormatException ignored) { } } @@ -81,8 +82,8 @@ public abstract class AbstractLauncher implements Launcher { protected Class loadMain() throws ClassNotFoundException { return classLoader.loadClass(mainClass); } - - protected void loadAndInvokeMain() throws Throwable, ClassNotFoundException { + + protected void loadAndInvokeMain() throws Throwable { invokeMain(loadMain()); } diff --git a/libraries/launcher/org/prismlauncher/impl/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java similarity index 86% rename from libraries/launcher/org/prismlauncher/impl/LegacyLauncher.java rename to libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java index 30a4dba7..181156c6 100644 --- a/libraries/launcher/org/prismlauncher/impl/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java @@ -13,7 +13,12 @@ * limitations under the License. */ -package org.prismlauncher.impl; +package org.prismlauncher.launcher.impl; + + +import org.prismlauncher.applet.LegacyFrame; +import org.prismlauncher.utils.LegacyUtils; +import org.prismlauncher.utils.Parameters; import java.applet.Applet; import java.io.File; @@ -26,10 +31,6 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -import org.prismlauncher.applet.LegacyFrame; -import org.prismlauncher.utils.Parameters; -import org.prismlauncher.utils.Utils; - @SuppressWarnings("removal") public final class LegacyLauncher extends AbstractLauncher { @@ -44,22 +45,22 @@ public final class LegacyLauncher extends AbstractLauncher { public LegacyLauncher(Parameters params) { super(params); - - user = params.first("userName"); - session = params.first("sessionId"); - title = params.firstSafe("windowTitle", "Minecraft"); - appletClass = params.firstSafe("appletClass", "net.minecraft.client.MinecraftApplet"); - - List traits = params.allSafe("traits", Collections.emptyList()); + + user = params.getString("userName"); + session = params.getString("sessionId"); + title = params.getString("windowTitle", "Minecraft"); + appletClass = params.getString("appletClass", "net.minecraft.client.MinecraftApplet"); + + List traits = params.getList("traits", Collections.emptyList()); noApplet = traits.contains("noapplet"); - + cwd = System.getProperty("user.dir"); } @Override public void launch() throws Throwable { Class main = loadMain(); - Field gameDirField = Utils.getMinecraftGameDirField(main); + Field gameDirField = LegacyUtils.getMinecraftGameDirField(main); if (gameDirField == null) { LOGGER.warning("Could not find Mineraft path field."); diff --git a/libraries/launcher/org/prismlauncher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java similarity index 97% rename from libraries/launcher/org/prismlauncher/impl/StandardLauncher.java rename to libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java index c651b060..c1d33958 100644 --- a/libraries/launcher/org/prismlauncher/impl/StandardLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package org.prismlauncher.impl; +package org.prismlauncher.launcher.impl; import org.prismlauncher.utils.Parameters; diff --git a/libraries/launcher/org/prismlauncher/utils/Utils.java b/libraries/launcher/org/prismlauncher/utils/LegacyUtils.java similarity index 71% rename from libraries/launcher/org/prismlauncher/utils/Utils.java rename to libraries/launcher/org/prismlauncher/utils/LegacyUtils.java index 79f5367b..7607d731 100644 --- a/libraries/launcher/org/prismlauncher/utils/Utils.java +++ b/libraries/launcher/org/prismlauncher/utils/LegacyUtils.java @@ -16,34 +16,39 @@ package org.prismlauncher.utils; + import java.io.File; import java.lang.reflect.Field; import java.lang.reflect.Modifier; -public final class Utils { - - private Utils() {} +public final class LegacyUtils { + + private LegacyUtils() { + } + /** * Finds a field that looks like a Minecraft base folder in a supplied class * * @param clazz the class to scan */ public static Field getMinecraftGameDirField(Class clazz) { - for (Field f : clazz.getDeclaredFields()) { + // Field we're looking for is always + // private static File obfuscatedName = null; + for (Field field : clazz.getDeclaredFields()) { // Has to be File - if (f.getType() != File.class) + if (field.getType() != File.class) continue; - + // And Private Static. - if (!Modifier.isStatic(f.getModifiers()) || !Modifier.isPrivate(f.getModifiers())) + if (!Modifier.isStatic(field.getModifiers()) || !Modifier.isPrivate(field.getModifiers())) continue; - - return f; + + return field; } - + return null; } - + } diff --git a/libraries/launcher/org/prismlauncher/utils/Parameters.java b/libraries/launcher/org/prismlauncher/utils/Parameters.java index dcaba18d..00b0701f 100644 --- a/libraries/launcher/org/prismlauncher/utils/Parameters.java +++ b/libraries/launcher/org/prismlauncher/utils/Parameters.java @@ -39,39 +39,39 @@ public final class Parameters { params.add(value); } - public List all(String key) throws ParameterNotFoundException { + public List getList(String key) throws ParameterNotFoundException { List params = map.get(key); - + if (params == null) throw new ParameterNotFoundException(key); - + return params; } - - public List allSafe(String key, List def) { + + public List getList(String key, List def) { List params = map.get(key); - + if (params == null || params.isEmpty()) return def; - + return params; } - - public String first(String key) throws ParameterNotFoundException { - List list = all(key); - + + public String getString(String key) throws ParameterNotFoundException { + List list = getList(key); + if (list.isEmpty()) throw new ParameterNotFoundException(key); - + return list.get(0); } - - public String firstSafe(String key, String def) { + + public String getString(String key, String def) { List params = map.get(key); - + if (params == null || params.isEmpty()) return def; - + return params.get(0); } From 99d9868116c14418cdcf5c033be7eed0d0cffd98 Mon Sep 17 00:00:00 2001 From: solonovamax Date: Thu, 27 Oct 2022 20:12:39 -0400 Subject: [PATCH 04/52] Cleanup EntryPoint code - Don't return an int from listen(). An enum is preferred. - Make parseLine() static, and pass Parameters to it. Signed-off-by: solonovamax --- .../org/prismlauncher/EntryPoint.java | 103 ++++++++++-------- 1 file changed, 58 insertions(+), 45 deletions(-) diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index 44e947b1..b1464f59 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -52,6 +52,7 @@ package org.prismlauncher; + import org.prismlauncher.exception.ParseException; import org.prismlauncher.launcher.Launcher; import org.prismlauncher.launcher.LauncherFactory; @@ -64,102 +65,114 @@ import java.nio.charset.StandardCharsets; import java.util.logging.Level; import java.util.logging.Logger; + public final class EntryPoint { - private static final Logger LOGGER = Logger.getLogger("EntryPoint"); - + private final Parameters params = new Parameters(); - + public static void main(String[] args) { EntryPoint listener = new EntryPoint(); - - int retCode = listener.listen(); - - if (retCode != 0) { - LOGGER.info("Exiting with " + retCode); - - System.exit(retCode); + + ExitCode exitCode = listener.listen(); + + if (exitCode != ExitCode.NORMAL) { + LOGGER.warning("Exiting with " + exitCode); + + System.exit(exitCode.numericalCode); } } - - private Action parseLine(String inData) throws ParseException { + + private static PreLaunchAction parseLine(String inData, Parameters params) throws ParseException { if (inData.isEmpty()) throw new ParseException("Unexpected empty string!"); - + String first = inData; String second = null; int splitPoint = inData.indexOf(' '); - + if (splitPoint != -1) { first = first.substring(0, splitPoint); second = inData.substring(splitPoint + 1); } - + switch (first) { case "launch": - return Action.LAUNCH; + return PreLaunchAction.LAUNCH; case "abort": - return Action.ABORT; + return PreLaunchAction.ABORT; default: if (second == null || second.isEmpty()) throw new ParseException("Error while parsing:" + inData); - + params.add(first, second); - - return Action.PROCEED; + + return PreLaunchAction.PROCEED; } } - - public int listen() { - Action action = Action.PROCEED; - + + public ExitCode listen() { + PreLaunchAction preLaunchAction = PreLaunchAction.PROCEED; + try (BufferedReader reader = new BufferedReader(new InputStreamReader( System.in, StandardCharsets.UTF_8 ))) { String line; - - while (action == Action.PROCEED) { + + while (preLaunchAction == PreLaunchAction.PROCEED) { if ((line = reader.readLine()) != null) { - action = parseLine(line); + preLaunchAction = parseLine(line, this.params); } else { - action = Action.ABORT; + preLaunchAction = PreLaunchAction.ABORT; } } } catch (IOException | ParseException e) { LOGGER.log(Level.SEVERE, "Launcher abort due to exception:", e); - - return 1; + + return ExitCode.ERROR; } - + // Main loop - if (action == Action.ABORT) { + if (preLaunchAction == PreLaunchAction.ABORT) { LOGGER.info("Launch aborted by the launcher."); - - return 1; + + return ExitCode.ERROR; } - + try { Launcher launcher = LauncherFactory.createLauncher(params); - + launcher.launch(); - - return 0; + + return ExitCode.NORMAL; } catch (IllegalArgumentException e) { LOGGER.log(Level.SEVERE, "Wrong argument.", e); - - return 1; + + return ExitCode.ERROR; } catch (Throwable e) { LOGGER.log(Level.SEVERE, "Exception caught from launcher.", e); - - return 1; + + return ExitCode.ERROR; } } - - private enum Action { + + private enum PreLaunchAction { PROCEED, LAUNCH, ABORT } - + + + private enum ExitCode { + NORMAL(0), + ERROR(1); + + private final int numericalCode; + + ExitCode(int numericalCode) { + this.numericalCode = numericalCode; + } + } + } From e5622ce824cf94074ced947ed7277886b2756ba9 Mon Sep 17 00:00:00 2001 From: solonovamax Date: Thu, 27 Oct 2022 20:16:08 -0400 Subject: [PATCH 05/52] Code cleanup to net.minecraft.Launcher No code logic has been changed, only: - add @Override annotatons - change setVisible(boolean b) -> setVisible(boolean visible) - Change block commend on class -> javadoc comment Signed-off-by: solonovamax --- libraries/launcher/net/minecraft/Launcher.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java index f9fd0a97..8928dbbe 100644 --- a/libraries/launcher/net/minecraft/Launcher.java +++ b/libraries/launcher/net/minecraft/Launcher.java @@ -28,8 +28,9 @@ import java.util.Map; import java.util.TreeMap; -/* +/** * WARNING: This class is reflectively accessed by legacy Forge versions. + *

* Changing field and method declarations without further testing is not recommended. */ public final class Launcher extends Applet implements AppletStub { @@ -47,6 +48,7 @@ public final class Launcher extends Applet implements AppletStub { } public Launcher(Applet applet, URL documentBase) { + super(); this.setLayout(new BorderLayout()); this.add(applet, "Center"); @@ -153,6 +155,7 @@ public final class Launcher extends Applet implements AppletStub { active = false; } + @Override public void destroy() { wrappedApplet.destroy(); } @@ -163,15 +166,17 @@ public final class Launcher extends Applet implements AppletStub { } @Override - public void setVisible(boolean b) { - super.setVisible(b); + public void setVisible(boolean visible) { + super.setVisible(visible); - wrappedApplet.setVisible(b); + wrappedApplet.setVisible(visible); } + @Override public void paint(Graphics paramGraphics) { } + @Override public void update(Graphics paramGraphics) { } From e86fbc697f819345cd42db7008509e89cfdddd73 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sat, 29 Oct 2022 09:47:09 +0100 Subject: [PATCH 06/52] Fix formatting Signed-off-by: TheKodeToad --- .../launcher/net/minecraft/Launcher.java | 80 +++++++++---------- .../org/prismlauncher/EntryPoint.java | 58 +++++++------- .../org/prismlauncher/launcher/Launcher.java | 3 +- .../launcher/LauncherFactory.java | 13 ++- .../launcher/LauncherProvider.java | 4 +- .../launcher/impl/AbstractLauncher.java | 18 ++--- .../launcher/impl/LegacyLauncher.java | 7 +- .../org/prismlauncher/utils/LegacyUtils.java | 14 ++-- 8 files changed, 94 insertions(+), 103 deletions(-) diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java index 8928dbbe..77050d90 100644 --- a/libraries/launcher/net/minecraft/Launcher.java +++ b/libraries/launcher/net/minecraft/Launcher.java @@ -16,7 +16,6 @@ package net.minecraft; - import java.applet.Applet; import java.applet.AppletStub; import java.awt.BorderLayout; @@ -27,40 +26,39 @@ import java.net.URL; import java.util.Map; import java.util.TreeMap; - /** * WARNING: This class is reflectively accessed by legacy Forge versions. *

* Changing field and method declarations without further testing is not recommended. */ public final class Launcher extends Applet implements AppletStub { - + private final Map params = new TreeMap<>(); - + private Applet wrappedApplet; - + private final URL documentBase; - + private boolean active = false; - + public Launcher(Applet applet) { this(applet, null); } - + public Launcher(Applet applet, URL documentBase) { super(); this.setLayout(new BorderLayout()); - + this.add(applet, "Center"); - + this.wrappedApplet = applet; - + try { if (documentBase != null) { this.documentBase = documentBase; } else if (applet.getClass().getPackage().getName().startsWith("com.mojang")) { // Special case only for Classic versions - + // TODO: 2022-10-27 Can this be changed to https this.documentBase = new URL("http", "www.minecraft.net", 80, "/game/"); } else { @@ -71,35 +69,35 @@ public final class Launcher extends Applet implements AppletStub { throw new RuntimeException(e); } } - + public void replace(Applet applet) { this.wrappedApplet = applet; - + applet.setStub(this); applet.setSize(getWidth(), getHeight()); - + this.setLayout(new BorderLayout()); this.add(applet, "Center"); - + applet.init(); - + active = true; - + applet.start(); - + validate(); } - + @Override public boolean isActive() { return active; } - + @Override public URL getDocumentBase() { return documentBase; } - + @Override public URL getCodeBase() { try { @@ -109,79 +107,79 @@ public final class Launcher extends Applet implements AppletStub { throw new RuntimeException(e); } } - + @Override public String getParameter(String name) { String param = params.get(name); - + if (param != null) return param; - + try { return super.getParameter(name); } catch (Exception ignored) { } - + return null; } - + @Override public void resize(int width, int height) { wrappedApplet.resize(width, height); } - + @Override public void resize(Dimension d) { wrappedApplet.resize(d); } - + @Override public void init() { if (wrappedApplet != null) wrappedApplet.init(); } - + @Override public void start() { wrappedApplet.start(); - + active = true; } - + @Override public void stop() { wrappedApplet.stop(); - + active = false; } - + @Override public void destroy() { wrappedApplet.destroy(); } - + @Override public void appletResize(int width, int height) { wrappedApplet.resize(width, height); } - + @Override public void setVisible(boolean visible) { super.setVisible(visible); - + wrappedApplet.setVisible(visible); } - + @Override public void paint(Graphics paramGraphics) { } - + @Override public void update(Graphics paramGraphics) { } - + public void setParameter(String name, String value) { params.put(name, value); } - + } diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index b1464f59..cb68b8fd 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -52,7 +52,6 @@ package org.prismlauncher; - import org.prismlauncher.exception.ParseException; import org.prismlauncher.launcher.Launcher; import org.prismlauncher.launcher.LauncherFactory; @@ -65,37 +64,37 @@ import java.nio.charset.StandardCharsets; import java.util.logging.Level; import java.util.logging.Logger; - public final class EntryPoint { + private static final Logger LOGGER = Logger.getLogger("EntryPoint"); - + private final Parameters params = new Parameters(); - + public static void main(String[] args) { EntryPoint listener = new EntryPoint(); - + ExitCode exitCode = listener.listen(); - + if (exitCode != ExitCode.NORMAL) { LOGGER.warning("Exiting with " + exitCode); - + System.exit(exitCode.numericalCode); } } - + private static PreLaunchAction parseLine(String inData, Parameters params) throws ParseException { if (inData.isEmpty()) throw new ParseException("Unexpected empty string!"); - + String first = inData; String second = null; int splitPoint = inData.indexOf(' '); - + if (splitPoint != -1) { first = first.substring(0, splitPoint); second = inData.substring(splitPoint + 1); } - + switch (first) { case "launch": return PreLaunchAction.LAUNCH; @@ -104,22 +103,22 @@ public final class EntryPoint { default: if (second == null || second.isEmpty()) throw new ParseException("Error while parsing:" + inData); - + params.add(first, second); - + return PreLaunchAction.PROCEED; } } - + public ExitCode listen() { PreLaunchAction preLaunchAction = PreLaunchAction.PROCEED; - + try (BufferedReader reader = new BufferedReader(new InputStreamReader( System.in, StandardCharsets.UTF_8 ))) { String line; - + while (preLaunchAction == PreLaunchAction.PROCEED) { if ((line = reader.readLine()) != null) { preLaunchAction = parseLine(line, this.params); @@ -129,50 +128,49 @@ public final class EntryPoint { } } catch (IOException | ParseException e) { LOGGER.log(Level.SEVERE, "Launcher abort due to exception:", e); - + return ExitCode.ERROR; } - + // Main loop if (preLaunchAction == PreLaunchAction.ABORT) { LOGGER.info("Launch aborted by the launcher."); - + return ExitCode.ERROR; } - + try { Launcher launcher = LauncherFactory.createLauncher(params); - + launcher.launch(); - + return ExitCode.NORMAL; } catch (IllegalArgumentException e) { LOGGER.log(Level.SEVERE, "Wrong argument.", e); - + return ExitCode.ERROR; } catch (Throwable e) { LOGGER.log(Level.SEVERE, "Exception caught from launcher.", e); - + return ExitCode.ERROR; } } - + private enum PreLaunchAction { PROCEED, LAUNCH, ABORT } - - + private enum ExitCode { NORMAL(0), ERROR(1); - + private final int numericalCode; - + ExitCode(int numericalCode) { this.numericalCode = numericalCode; } } - + } diff --git a/libraries/launcher/org/prismlauncher/launcher/Launcher.java b/libraries/launcher/org/prismlauncher/launcher/Launcher.java index 1cea255c..6f5c17b8 100644 --- a/libraries/launcher/org/prismlauncher/launcher/Launcher.java +++ b/libraries/launcher/org/prismlauncher/launcher/Launcher.java @@ -16,7 +16,8 @@ package org.prismlauncher.launcher; - public interface Launcher { + void launch() throws Throwable; + } diff --git a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java index 6c601171..761a4595 100644 --- a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java +++ b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java @@ -35,7 +35,6 @@ package org.prismlauncher.launcher; - import org.prismlauncher.launcher.impl.LegacyLauncher; import org.prismlauncher.launcher.impl.StandardLauncher; import org.prismlauncher.utils.Parameters; @@ -43,10 +42,10 @@ import org.prismlauncher.utils.Parameters; import java.util.HashMap; import java.util.Map; - public final class LauncherFactory { + private static final Map launcherRegistry = new HashMap<>(); - + static { launcherRegistry.put("standard", new LauncherProvider() { @Override @@ -63,15 +62,15 @@ public final class LauncherFactory { } private LauncherFactory() { } - + public static Launcher createLauncher(Parameters parameters) { String name = parameters.getString("launcher"); - + LauncherProvider launcherProvider = launcherRegistry.get(name); - + if (launcherProvider == null) throw new IllegalArgumentException("Invalid launcher type: " + name); - + return launcherProvider.provide(parameters); } } diff --git a/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java b/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java index b6d1caab..9b453c7b 100644 --- a/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java +++ b/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java @@ -35,10 +35,10 @@ package org.prismlauncher.launcher; - import org.prismlauncher.utils.Parameters; - public interface LauncherProvider { + Launcher provide(Parameters parameters); + } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java index 637c5da7..5aab40ff 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java @@ -15,7 +15,6 @@ package org.prismlauncher.launcher.impl; - import org.prismlauncher.exception.ParseException; import org.prismlauncher.launcher.Launcher; import org.prismlauncher.utils.Parameters; @@ -26,9 +25,8 @@ import java.lang.invoke.MethodType; import java.util.ArrayList; import java.util.List; - public abstract class AbstractLauncher implements Launcher { - + private static final int DEFAULT_WINDOW_WIDTH = 854; private static final int DEFAULT_WINDOW_HEIGHT = 480; @@ -44,21 +42,21 @@ public abstract class AbstractLauncher implements Launcher { protected final String serverAddress, serverPort; protected final ClassLoader classLoader; - + protected AbstractLauncher(Parameters params) { classLoader = ClassLoader.getSystemClassLoader(); - + mcParams = params.getList("param", new ArrayList()); mainClass = params.getString("mainClass", "net.minecraft.client.Minecraft"); - + serverAddress = params.getString("serverAddress", null); serverPort = params.getString("serverPort", null); - + String windowParams = params.getString("windowParams", null); - + if ("max".equals(windowParams) || windowParams == null) { maximize = windowParams != null; - + width = DEFAULT_WINDOW_WIDTH; height = DEFAULT_WINDOW_HEIGHT; } else { @@ -82,7 +80,7 @@ public abstract class AbstractLauncher implements Launcher { protected Class loadMain() throws ClassNotFoundException { return classLoader.loadClass(mainClass); } - + protected void loadAndInvokeMain() throws Throwable { invokeMain(loadMain()); } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java index 181156c6..57e29605 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java @@ -15,7 +15,6 @@ package org.prismlauncher.launcher.impl; - import org.prismlauncher.applet.LegacyFrame; import org.prismlauncher.utils.LegacyUtils; import org.prismlauncher.utils.Parameters; @@ -45,15 +44,15 @@ public final class LegacyLauncher extends AbstractLauncher { public LegacyLauncher(Parameters params) { super(params); - + user = params.getString("userName"); session = params.getString("sessionId"); title = params.getString("windowTitle", "Minecraft"); appletClass = params.getString("appletClass", "net.minecraft.client.MinecraftApplet"); - + List traits = params.getList("traits", Collections.emptyList()); noApplet = traits.contains("noapplet"); - + cwd = System.getProperty("user.dir"); } diff --git a/libraries/launcher/org/prismlauncher/utils/LegacyUtils.java b/libraries/launcher/org/prismlauncher/utils/LegacyUtils.java index 7607d731..ca648012 100644 --- a/libraries/launcher/org/prismlauncher/utils/LegacyUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/LegacyUtils.java @@ -16,17 +16,15 @@ package org.prismlauncher.utils; - import java.io.File; import java.lang.reflect.Field; import java.lang.reflect.Modifier; - public final class LegacyUtils { - + private LegacyUtils() { } - + /** * Finds a field that looks like a Minecraft base folder in a supplied class * @@ -39,16 +37,16 @@ public final class LegacyUtils { // Has to be File if (field.getType() != File.class) continue; - + // And Private Static. if (!Modifier.isStatic(field.getModifiers()) || !Modifier.isPrivate(field.getModifiers())) continue; - + return field; } - + return null; } - + } From c0b8c53e6960de48c6a43796b413d1780f681a3a Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sat, 29 Oct 2022 15:05:43 +0100 Subject: [PATCH 07/52] Attempt to sort out copyright headers Signed-off-by: TheKodeToad --- .../launcher/net/minecraft/Launcher.java | 58 ++++++++++--- .../org/prismlauncher/EntryPoint.java | 4 +- .../org/prismlauncher/applet/LegacyFrame.java | 60 +++++++++++--- .../exception/ParameterNotFoundException.java | 58 ++++++++++--- .../exception/ParseException.java | 58 ++++++++++--- .../org/prismlauncher/launcher/Launcher.java | 61 +++++++++++--- .../launcher/LauncherFactory.java | 26 +++++- .../launcher/LauncherProvider.java | 20 ++++- .../launcher/impl/AbstractLauncher.java | 60 +++++++++++--- .../launcher/impl/LegacyLauncher.java | 60 +++++++++++--- .../launcher/impl/StandardLauncher.java | 59 ++++++++++--- .../org/prismlauncher/utils/LegacyUtils.java | 58 ++++++++++--- .../org/prismlauncher/utils/Parameters.java | 82 ++++++++++++++----- 13 files changed, 548 insertions(+), 116 deletions(-) diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java index 77050d90..2f8a51c9 100644 --- a/libraries/launcher/net/minecraft/Launcher.java +++ b/libraries/launcher/net/minecraft/Launcher.java @@ -1,17 +1,55 @@ +// SPDX-License-Identifier: GPL-3.0-only /* - * Copyright 2012-2021 MultiMC Contributors + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 icelimetea + * Copyright (C) 2022 TheKodeToad + * Copyright (C) 2022 solonovamax * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. * - * http://www.apache.org/licenses/LICENSE-2.0 + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give + * you permission to link this library with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also meet, + * for each linked independent module, the terms and conditions of the + * license of that module. An independent module is a module which is + * not derived from or based on this library. If you modify this + * library, you may extend this exception to your version of the + * library, but you are not obliged to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package net.minecraft; diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index cb68b8fd..40494b7c 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -1,7 +1,9 @@ // SPDX-License-Identifier: GPL-3.0-only /* * PolyMC - Minecraft Launcher - * Copyright (C) 2022 icelimetea, + * Copyright (C) 2022 icelimetea + * Copyright (C) 2022 TheKodeToad + * Copyright (C) 2022 solonovamax * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/libraries/launcher/org/prismlauncher/applet/LegacyFrame.java b/libraries/launcher/org/prismlauncher/applet/LegacyFrame.java index f3359fca..20ec2503 100644 --- a/libraries/launcher/org/prismlauncher/applet/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/applet/LegacyFrame.java @@ -1,17 +1,57 @@ +// SPDX-License-Identifier: GPL-3.0-only /* - * Copyright 2012-2021 MultiMC Contributors + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 icelimetea + * Copyright (C) 2022 Sefa Eyeoglu + * Copyright (C) 2022 flow + * Copyright (C) 2022 Samisafool + * Copyright (C) 2022 TheKodeToad * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. * - * http://www.apache.org/licenses/LICENSE-2.0 + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give + * you permission to link this library with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also meet, + * for each linked independent module, the terms and conditions of the + * license of that module. An independent module is a module which is + * not derived from or based on this library. If you modify this + * library, you may extend this exception to your version of the + * library, but you are not obliged to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.prismlauncher.applet; diff --git a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java index 641e0c99..c083e02a 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java @@ -1,17 +1,55 @@ +// SPDX-License-Identifier: GPL-3.0-only /* - * Copyright 2012-2021 MultiMC Contributors + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 icelimetea + * Copyright (C) 2022 Sefa Eyeoglu + * Copyright (C) 2022 Samisafool * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. * - * http://www.apache.org/licenses/LICENSE-2.0 + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give + * you permission to link this library with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also meet, + * for each linked independent module, the terms and conditions of the + * license of that module. An independent module is a module which is + * not derived from or based on this library. If you modify this + * library, you may extend this exception to your version of the + * library, but you are not obliged to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.prismlauncher.exception; diff --git a/libraries/launcher/org/prismlauncher/exception/ParseException.java b/libraries/launcher/org/prismlauncher/exception/ParseException.java index 51d25a62..8904f9ee 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParseException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParseException.java @@ -1,17 +1,55 @@ +// SPDX-License-Identifier: GPL-3.0-only /* - * Copyright 2012-2021 MultiMC Contributors + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 icelimetea + * Copyright (C) 2022 Sefa Eyeoglu + * Copyright (C) 2022 Samisafool * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. * - * http://www.apache.org/licenses/LICENSE-2.0 + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give + * you permission to link this library with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also meet, + * for each linked independent module, the terms and conditions of the + * license of that module. An independent module is a module which is + * not derived from or based on this library. If you modify this + * library, you may extend this exception to your version of the + * library, but you are not obliged to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.prismlauncher.exception; diff --git a/libraries/launcher/org/prismlauncher/launcher/Launcher.java b/libraries/launcher/org/prismlauncher/launcher/Launcher.java index 6f5c17b8..a41e4af6 100644 --- a/libraries/launcher/org/prismlauncher/launcher/Launcher.java +++ b/libraries/launcher/org/prismlauncher/launcher/Launcher.java @@ -1,19 +1,58 @@ +// SPDX-License-Identifier: GPL-3.0-only /* - * Copyright 2012-2021 MultiMC Contributors + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 icelimetea + * Copyright (C) 2022 Sefa Eyeoglu + * Copyright (C) 2022 Samisafool + * Copyright (C) 2022 TheKodeToad + * Copyright (C) 2022 solonovamax * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. * - * http://www.apache.org/licenses/LICENSE-2.0 + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give + * you permission to link this library with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also meet, + * for each linked independent module, the terms and conditions of the + * license of that module. An independent module is a module which is + * not derived from or based on this library. If you modify this + * library, you may extend this exception to your version of the + * library, but you are not obliged to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ - package org.prismlauncher.launcher; public interface Launcher { diff --git a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java index 761a4595..e6de35fa 100644 --- a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java +++ b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java @@ -1,7 +1,11 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - Minecraft Launcher - * Copyright (C) 2022 icelimetea, + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 icelimetea + * Copyright (C) 2022 Sefa Eyeoglu + * Copyright (C) 2022 Samisafool + * Copyright (C) 2022 TheKodeToad + * Copyright (C) 2022 solonovamax * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,6 +35,23 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.prismlauncher.launcher; @@ -73,4 +94,5 @@ public final class LauncherFactory { return launcherProvider.provide(parameters); } + } diff --git a/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java b/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java index 9b453c7b..66d23c0f 100644 --- a/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java +++ b/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-only /* * PolyMC - Minecraft Launcher - * Copyright (C) 2022 solonovamax, + * Copyright (C) 2022 icelimetea + * Copyright (C) 2022 solonovamax * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,6 +32,23 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.prismlauncher.launcher; diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java index 5aab40ff..7a622b1b 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java @@ -1,16 +1,56 @@ -/* Copyright 2012-2021 MultiMC Contributors +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 icelimetea + * Copyright (C) 2022 Sefa Eyeoglu + * Copyright (C) 2022 TheKodeToad + * Copyright (C) 2022 solonovamax * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. * - * http://www.apache.org/licenses/LICENSE-2.0 + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give + * you permission to link this library with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also meet, + * for each linked independent module, the terms and conditions of the + * license of that module. An independent module is a module which is + * not derived from or based on this library. If you modify this + * library, you may extend this exception to your version of the + * library, but you are not obliged to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.prismlauncher.launcher.impl; diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java index 57e29605..fb1540bf 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java @@ -1,16 +1,56 @@ -/* Copyright 2012-2021 MultiMC Contributors +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 icelimetea + * Copyright (C) 2022 flow + * Copyright (C) 2022 TheKodeToad + * Copyright (C) 2022 solonovamax * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. * - * http://www.apache.org/licenses/LICENSE-2.0 + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give + * you permission to link this library with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also meet, + * for each linked independent module, the terms and conditions of the + * license of that module. An independent module is a module which is + * not derived from or based on this library. If you modify this + * library, you may extend this exception to your version of the + * library, but you are not obliged to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.prismlauncher.launcher.impl; diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java index c1d33958..5c884e99 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java @@ -1,16 +1,55 @@ -/* Copyright 2012-2021 MultiMC Contributors +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 icelimetea + * Copyright (C) 2022 TheKodeToad + * Copyright (C) 2022 solonovamax * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. * - * http://www.apache.org/licenses/LICENSE-2.0 + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give + * you permission to link this library with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also meet, + * for each linked independent module, the terms and conditions of the + * license of that module. An independent module is a module which is + * not derived from or based on this library. If you modify this + * library, you may extend this exception to your version of the + * library, but you are not obliged to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.prismlauncher.launcher.impl; diff --git a/libraries/launcher/org/prismlauncher/utils/LegacyUtils.java b/libraries/launcher/org/prismlauncher/utils/LegacyUtils.java index ca648012..8e7cbb74 100644 --- a/libraries/launcher/org/prismlauncher/utils/LegacyUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/LegacyUtils.java @@ -1,17 +1,55 @@ +// SPDX-License-Identifier: GPL-3.0-only /* - * Copyright 2012-2021 MultiMC Contributors + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 icelimetea + * Copyright (C) 2022 TheKodeToad + * Copyright (C) 2022 solonovamax * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. * - * http://www.apache.org/licenses/LICENSE-2.0 + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give + * you permission to link this library with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also meet, + * for each linked independent module, the terms and conditions of the + * license of that module. An independent module is a module which is + * not derived from or based on this library. If you modify this + * library, you may extend this exception to your version of the + * library, but you are not obliged to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.prismlauncher.utils; diff --git a/libraries/launcher/org/prismlauncher/utils/Parameters.java b/libraries/launcher/org/prismlauncher/utils/Parameters.java index 00b0701f..5596e88a 100644 --- a/libraries/launcher/org/prismlauncher/utils/Parameters.java +++ b/libraries/launcher/org/prismlauncher/utils/Parameters.java @@ -1,17 +1,57 @@ +// SPDX-License-Identifier: GPL-3.0-only /* - * Copyright 2012-2021 MultiMC Contributors + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 icelimetea + * Copyright (C) 2022 Sefa Eyeoglu + * Copyright (C) 2022 Samisafool + * Copyright (C) 2022 TheKodeToad + * Copyright (C) 2022 solonovamax * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. * - * http://www.apache.org/licenses/LICENSE-2.0 + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give + * you permission to link this library with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also meet, + * for each linked independent module, the terms and conditions of the + * license of that module. An independent module is a module which is + * not derived from or based on this library. If you modify this + * library, you may extend this exception to your version of the + * library, but you are not obliged to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.prismlauncher.utils; @@ -41,37 +81,37 @@ public final class Parameters { public List getList(String key) throws ParameterNotFoundException { List params = map.get(key); - + if (params == null) throw new ParameterNotFoundException(key); - + return params; } - + public List getList(String key, List def) { List params = map.get(key); - + if (params == null || params.isEmpty()) return def; - + return params; } - + public String getString(String key) throws ParameterNotFoundException { List list = getList(key); - + if (list.isEmpty()) throw new ParameterNotFoundException(key); - + return list.get(0); } - + public String getString(String key, String def) { List params = map.get(key); - + if (params == null || params.isEmpty()) return def; - + return params.get(0); } From a7b1700d4232cc055c50286a57d627db23d6b4cd Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sat, 29 Oct 2022 15:20:27 +0100 Subject: [PATCH 08/52] Better variable naming Signed-off-by: TheKodeToad --- .../launcher/net/minecraft/Launcher.java | 9 ++- .../org/prismlauncher/applet/LegacyFrame.java | 55 +++++++++---------- .../org/prismlauncher/launcher/Launcher.java | 1 + .../launcher/impl/LegacyLauncher.java | 4 +- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java index 2f8a51c9..aef09ca9 100644 --- a/libraries/launcher/net/minecraft/Launcher.java +++ b/libraries/launcher/net/minecraft/Launcher.java @@ -84,7 +84,6 @@ public final class Launcher extends Applet implements AppletStub { } public Launcher(Applet applet, URL documentBase) { - super(); this.setLayout(new BorderLayout()); this.add(applet, "Center"); @@ -167,8 +166,8 @@ public final class Launcher extends Applet implements AppletStub { } @Override - public void resize(Dimension d) { - wrappedApplet.resize(d); + public void resize(Dimension size) { + wrappedApplet.resize(size); } @Override @@ -209,11 +208,11 @@ public final class Launcher extends Applet implements AppletStub { } @Override - public void paint(Graphics paramGraphics) { + public void paint(Graphics graphics) { } @Override - public void update(Graphics paramGraphics) { + public void update(Graphics graphics) { } public void setParameter(String name, String value) { diff --git a/libraries/launcher/org/prismlauncher/applet/LegacyFrame.java b/libraries/launcher/org/prismlauncher/applet/LegacyFrame.java index 20ec2503..58125160 100644 --- a/libraries/launcher/org/prismlauncher/applet/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/applet/LegacyFrame.java @@ -74,19 +74,18 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -@SuppressWarnings("removal") public final class LegacyFrame extends Frame { private static final Logger LOGGER = Logger.getLogger("LegacyFrame"); - private final Launcher appletWrap; + private final Launcher launcher; - public LegacyFrame(String title, Applet mcApplet) { + public LegacyFrame(String title, Applet applet) { super(title); - appletWrap = new Launcher(mcApplet); + launcher = new Launcher(applet); - mcApplet.setStub(appletWrap); + applet.setStub(launcher); try { setIconImage(ImageIO.read(new File("icon.png"))); @@ -100,8 +99,8 @@ public final class LegacyFrame extends Frame { public void start ( String user, String session, - int winSizeW, - int winSizeH, + int width, + int height, boolean maximize, String serverAddress, String serverPort, @@ -130,9 +129,9 @@ public final class LegacyFrame extends Frame { LOGGER.warning("Mpticket file is corrupted!"); } else { // Assumes parameters are valid and in the correct order - appletWrap.setParameter("server", lines.get(0)); - appletWrap.setParameter("port", lines.get(1)); - appletWrap.setParameter("mppass", lines.get(2)); + launcher.setParameter("server", lines.get(0)); + launcher.setParameter("port", lines.get(1)); + launcher.setParameter("mppass", lines.get(2)); } } catch (IOException e) { LOGGER.log(Level.WARNING, "Unable to read mpticket file!", e); @@ -140,20 +139,20 @@ public final class LegacyFrame extends Frame { } if (serverAddress != null) { - appletWrap.setParameter("server", serverAddress); - appletWrap.setParameter("port", serverPort); + launcher.setParameter("server", serverAddress); + launcher.setParameter("port", serverPort); } - appletWrap.setParameter("username", user); - appletWrap.setParameter("sessionid", session); - appletWrap.setParameter("stand-alone", "true"); // Show the quit button. TODO: why won't this work? - appletWrap.setParameter("haspaid", "true"); // Some old versions need this for world saves to work. - appletWrap.setParameter("demo", isDemo ? "true" : "false"); - appletWrap.setParameter("fullscreen", "false"); + launcher.setParameter("username", user); + launcher.setParameter("sessionid", session); + launcher.setParameter("stand-alone", "true"); // Show the quit button. TODO: why won't this work? + launcher.setParameter("haspaid", "true"); // Some old versions need this for world saves to work. + launcher.setParameter("demo", isDemo ? "true" : "false"); + launcher.setParameter("fullscreen", "false"); - add(appletWrap); + add(launcher); - appletWrap.setPreferredSize(new Dimension(winSizeW, winSizeH)); + launcher.setPreferredSize(new Dimension(width, height)); pack(); @@ -165,8 +164,8 @@ public final class LegacyFrame extends Frame { validate(); - appletWrap.init(); - appletWrap.start(); + launcher.init(); + launcher.start(); setVisible(true); } @@ -174,14 +173,14 @@ public final class LegacyFrame extends Frame { private final class ForceExitHandler extends WindowAdapter { @Override - public void windowClosing(WindowEvent e) { + public void windowClosing(WindowEvent event) { new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(30000L); - } catch (InterruptedException localInterruptedException) { - localInterruptedException.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); } LOGGER.info("Forcing exit!"); @@ -190,9 +189,9 @@ public final class LegacyFrame extends Frame { } }).start(); - if (appletWrap != null) { - appletWrap.stop(); - appletWrap.destroy(); + if (launcher != null) { + launcher.stop(); + launcher.destroy(); } // old minecraft versions can hang without this >_< diff --git a/libraries/launcher/org/prismlauncher/launcher/Launcher.java b/libraries/launcher/org/prismlauncher/launcher/Launcher.java index a41e4af6..7bf9ba0d 100644 --- a/libraries/launcher/org/prismlauncher/launcher/Launcher.java +++ b/libraries/launcher/org/prismlauncher/launcher/Launcher.java @@ -53,6 +53,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.prismlauncher.launcher; public interface Launcher { diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java index fb1540bf..ed12cdf6 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java @@ -70,7 +70,9 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -@SuppressWarnings("removal") +/** + * Used to launch old versions that support applets. + */ public final class LegacyLauncher extends AbstractLauncher { private static final Logger LOGGER = Logger.getLogger("LegacyLauncher"); From ade7526f5fb1d9b8cc5f8b90904192474ba145b6 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sat, 29 Oct 2022 15:22:24 +0100 Subject: [PATCH 09/52] Remove the need for LegacyUtils Signed-off-by: TheKodeToad --- .../launcher/impl/LegacyLauncher.java | 27 +++++- .../org/prismlauncher/utils/LegacyUtils.java | 90 ------------------- 2 files changed, 25 insertions(+), 92 deletions(-) delete mode 100644 libraries/launcher/org/prismlauncher/utils/LegacyUtils.java diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java index ed12cdf6..c249c714 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java @@ -56,7 +56,6 @@ package org.prismlauncher.launcher.impl; import org.prismlauncher.applet.LegacyFrame; -import org.prismlauncher.utils.LegacyUtils; import org.prismlauncher.utils.Parameters; import java.applet.Applet; @@ -65,6 +64,7 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import java.lang.reflect.Field; +import java.lang.reflect.Modifier; import java.util.Collections; import java.util.List; import java.util.logging.Level; @@ -101,7 +101,7 @@ public final class LegacyLauncher extends AbstractLauncher { @Override public void launch() throws Throwable { Class main = loadMain(); - Field gameDirField = LegacyUtils.getMinecraftGameDirField(main); + Field gameDirField = getMinecraftGameDirField(main); if (gameDirField == null) { LOGGER.warning("Could not find Mineraft path field."); @@ -143,4 +143,27 @@ public final class LegacyLauncher extends AbstractLauncher { invokeMain(main); } + /** + * Finds a field that looks like a Minecraft base folder in a supplied class + * @param clazz the class to scan + * @return The found field. + */ + private static Field getMinecraftGameDirField(Class clazz) { + // Field we're looking for is always + // private static File obfuscatedName = null; + for (Field field : clazz.getDeclaredFields()) { + // Has to be File + if (field.getType() != File.class) + continue; + + // And Private Static. + if (!Modifier.isStatic(field.getModifiers()) || !Modifier.isPrivate(field.getModifiers())) + continue; + + return field; + } + + return null; + } + } diff --git a/libraries/launcher/org/prismlauncher/utils/LegacyUtils.java b/libraries/launcher/org/prismlauncher/utils/LegacyUtils.java deleted file mode 100644 index 8e7cbb74..00000000 --- a/libraries/launcher/org/prismlauncher/utils/LegacyUtils.java +++ /dev/null @@ -1,90 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -/* - * PolyMC - Minecraft Launcher - * Copyright (C) 2022 icelimetea - * Copyright (C) 2022 TheKodeToad - * Copyright (C) 2022 solonovamax - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Linking this library statically or dynamically with other modules is - * making a combined work based on this library. Thus, the terms and - * conditions of the GNU General Public License cover the whole - * combination. - * - * As a special exception, the copyright holders of this library give - * you permission to link this library with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also meet, - * for each linked independent module, the terms and conditions of the - * license of that module. An independent module is a module which is - * not derived from or based on this library. If you modify this - * library, you may extend this exception to your version of the - * library, but you are not obliged to do so. If you do not wish to do - * so, delete this exception statement from your version. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * This file incorporates work covered by the following copyright and - * permission notice: - * - * Copyright 2013-2021 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.prismlauncher.utils; - -import java.io.File; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; - -public final class LegacyUtils { - - private LegacyUtils() { - } - - /** - * Finds a field that looks like a Minecraft base folder in a supplied class - * - * @param clazz the class to scan - */ - public static Field getMinecraftGameDirField(Class clazz) { - // Field we're looking for is always - // private static File obfuscatedName = null; - for (Field field : clazz.getDeclaredFields()) { - // Has to be File - if (field.getType() != File.class) - continue; - - // And Private Static. - if (!Modifier.isStatic(field.getModifiers()) || !Modifier.isPrivate(field.getModifiers())) - continue; - - return field; - } - - return null; - } - -} - From 0cd1d7aa7e6580eaed5e32c53538678bbcdd6abc Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sat, 29 Oct 2022 15:24:55 +0100 Subject: [PATCH 10/52] Excessive safety Signed-off-by: TheKodeToad --- libraries/launcher/net/minecraft/Launcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java index aef09ca9..147c727e 100644 --- a/libraries/launcher/net/minecraft/Launcher.java +++ b/libraries/launcher/net/minecraft/Launcher.java @@ -93,7 +93,7 @@ public final class Launcher extends Applet implements AppletStub { try { if (documentBase != null) { this.documentBase = documentBase; - } else if (applet.getClass().getPackage().getName().startsWith("com.mojang")) { + } else if (applet.getClass().getPackage().getName().startsWith("com.mojang.")) { // Special case only for Classic versions // TODO: 2022-10-27 Can this be changed to https From 35d200356fdeb2d54c0ad0537c9c3b4cd9a8eb4d Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sat, 29 Oct 2022 15:31:41 +0100 Subject: [PATCH 11/52] Create launcher.impl.legacy Signed-off-by: TheKodeToad --- libraries/launcher/CMakeLists.txt | 5 ++--- .../launcher/org/prismlauncher/launcher/LauncherFactory.java | 2 +- .../{applet => launcher/impl/legacy}/LegacyFrame.java | 2 +- .../launcher/impl/{ => legacy}/LegacyLauncher.java | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) rename libraries/launcher/org/prismlauncher/{applet => launcher/impl/legacy}/LegacyFrame.java (99%) rename libraries/launcher/org/prismlauncher/launcher/impl/{ => legacy}/LegacyLauncher.java (98%) diff --git a/libraries/launcher/CMakeLists.txt b/libraries/launcher/CMakeLists.txt index d74c3641..f85c2354 100644 --- a/libraries/launcher/CMakeLists.txt +++ b/libraries/launcher/CMakeLists.txt @@ -11,14 +11,13 @@ set(SRC org/prismlauncher/launcher/Launcher.java org/prismlauncher/launcher/LauncherFactory.java org/prismlauncher/launcher/LauncherProvider.java + org/prismlauncher/launcher/impl/legacy/LegacyFrame.java + org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java org/prismlauncher/launcher/impl/AbstractLauncher.java - org/prismlauncher/launcher/impl/LegacyLauncher.java org/prismlauncher/launcher/impl/StandardLauncher.java - org/prismlauncher/applet/LegacyFrame.java org/prismlauncher/exception/ParameterNotFoundException.java org/prismlauncher/exception/ParseException.java org/prismlauncher/utils/Parameters.java - org/prismlauncher/utils/LegacyUtils.java net/minecraft/Launcher.java ) add_jar(NewLaunch ${SRC}) diff --git a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java index e6de35fa..22e92632 100644 --- a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java +++ b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java @@ -56,8 +56,8 @@ package org.prismlauncher.launcher; -import org.prismlauncher.launcher.impl.LegacyLauncher; import org.prismlauncher.launcher.impl.StandardLauncher; +import org.prismlauncher.launcher.impl.legacy.LegacyLauncher; import org.prismlauncher.utils.Parameters; import java.util.HashMap; diff --git a/libraries/launcher/org/prismlauncher/applet/LegacyFrame.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java similarity index 99% rename from libraries/launcher/org/prismlauncher/applet/LegacyFrame.java rename to libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java index 58125160..12196fd4 100644 --- a/libraries/launcher/org/prismlauncher/applet/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java @@ -54,7 +54,7 @@ * limitations under the License. */ -package org.prismlauncher.applet; +package org.prismlauncher.launcher.impl.legacy; import net.minecraft.Launcher; diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java similarity index 98% rename from libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java rename to libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java index c249c714..d7a98352 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java @@ -53,9 +53,9 @@ * limitations under the License. */ -package org.prismlauncher.launcher.impl; +package org.prismlauncher.launcher.impl.legacy; -import org.prismlauncher.applet.LegacyFrame; +import org.prismlauncher.launcher.impl.AbstractLauncher; import org.prismlauncher.utils.Parameters; import java.applet.Applet; From 609b30110ba93c2cb3863bd3c857be7af23275cc Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sun, 30 Oct 2022 15:27:24 +0000 Subject: [PATCH 12/52] Make main static Signed-off-by: TheKodeToad Inline local variable Signed-off-by: TheKodeToad --- .../launcher/org/prismlauncher/EntryPoint.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index 40494b7c..aab7d110 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -70,12 +70,8 @@ public final class EntryPoint { private static final Logger LOGGER = Logger.getLogger("EntryPoint"); - private final Parameters params = new Parameters(); - public static void main(String[] args) { - EntryPoint listener = new EntryPoint(); - - ExitCode exitCode = listener.listen(); + ExitCode exitCode = listen(); if (exitCode != ExitCode.NORMAL) { LOGGER.warning("Exiting with " + exitCode); @@ -112,7 +108,8 @@ public final class EntryPoint { } } - public ExitCode listen() { + private static ExitCode listen() { + Parameters parameters = new Parameters(); PreLaunchAction preLaunchAction = PreLaunchAction.PROCEED; try (BufferedReader reader = new BufferedReader(new InputStreamReader( @@ -123,7 +120,7 @@ public final class EntryPoint { while (preLaunchAction == PreLaunchAction.PROCEED) { if ((line = reader.readLine()) != null) { - preLaunchAction = parseLine(line, this.params); + preLaunchAction = parseLine(line, parameters); } else { preLaunchAction = PreLaunchAction.ABORT; } @@ -142,7 +139,7 @@ public final class EntryPoint { } try { - Launcher launcher = LauncherFactory.createLauncher(params); + Launcher launcher = LauncherFactory.createLauncher(parameters); launcher.launch(); From ac5b74301e7be057bf08aa78cf0cfbece27cd1c1 Mon Sep 17 00:00:00 2001 From: solonovamax Date: Mon, 31 Oct 2022 15:56:53 -0400 Subject: [PATCH 13/52] Cleanup splitting string into a pair Signed-off-by: solonovamax --- .../org/prismlauncher/EntryPoint.java | 90 +++++++++---------- .../launcher/impl/AbstractLauncher.java | 13 +-- .../org/prismlauncher/utils/StringUtils.java | 15 ++++ 3 files changed, 63 insertions(+), 55 deletions(-) create mode 100644 libraries/launcher/org/prismlauncher/utils/StringUtils.java diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index aab7d110..987dcc12 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -54,10 +54,12 @@ package org.prismlauncher; + import org.prismlauncher.exception.ParseException; import org.prismlauncher.launcher.Launcher; import org.prismlauncher.launcher.LauncherFactory; import org.prismlauncher.utils.Parameters; +import org.prismlauncher.utils.StringUtils; import java.io.BufferedReader; import java.io.IOException; @@ -66,58 +68,47 @@ import java.nio.charset.StandardCharsets; import java.util.logging.Level; import java.util.logging.Logger; + public final class EntryPoint { - private static final Logger LOGGER = Logger.getLogger("EntryPoint"); - + public static void main(String[] args) { ExitCode exitCode = listen(); - + if (exitCode != ExitCode.NORMAL) { LOGGER.warning("Exiting with " + exitCode); - + System.exit(exitCode.numericalCode); } } - - private static PreLaunchAction parseLine(String inData, Parameters params) throws ParseException { - if (inData.isEmpty()) + + private static PreLaunchAction parseLine(String input, Parameters params) throws ParseException { + if (input.isEmpty()) throw new ParseException("Unexpected empty string!"); - - String first = inData; - String second = null; - int splitPoint = inData.indexOf(' '); - - if (splitPoint != -1) { - first = first.substring(0, splitPoint); - second = inData.substring(splitPoint + 1); - } - - switch (first) { - case "launch": - return PreLaunchAction.LAUNCH; - case "abort": - return PreLaunchAction.ABORT; - default: - if (second == null || second.isEmpty()) - throw new ParseException("Error while parsing:" + inData); - - params.add(first, second); - - return PreLaunchAction.PROCEED; + + + if ("launch".equalsIgnoreCase(input)) { + return PreLaunchAction.LAUNCH; + } else if ("abort".equalsIgnoreCase(input)) { + return PreLaunchAction.ABORT; + } else { + String[] pair = StringUtils.splitStringPair(' ', input); + if (pair == null) + throw new ParseException("Error while parsing:" + input); + + params.add(pair[0], pair[1]); + + return PreLaunchAction.PROCEED; } } - + private static ExitCode listen() { Parameters parameters = new Parameters(); PreLaunchAction preLaunchAction = PreLaunchAction.PROCEED; - - try (BufferedReader reader = new BufferedReader(new InputStreamReader( - System.in, - StandardCharsets.UTF_8 - ))) { + + try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8))) { String line; - + while (preLaunchAction == PreLaunchAction.PROCEED) { if ((line = reader.readLine()) != null) { preLaunchAction = parseLine(line, parameters); @@ -127,49 +118,50 @@ public final class EntryPoint { } } catch (IOException | ParseException e) { LOGGER.log(Level.SEVERE, "Launcher abort due to exception:", e); - + return ExitCode.ERROR; } - + // Main loop if (preLaunchAction == PreLaunchAction.ABORT) { LOGGER.info("Launch aborted by the launcher."); - + return ExitCode.ERROR; } - + try { Launcher launcher = LauncherFactory.createLauncher(parameters); - + launcher.launch(); - + return ExitCode.NORMAL; } catch (IllegalArgumentException e) { LOGGER.log(Level.SEVERE, "Wrong argument.", e); - + return ExitCode.ERROR; } catch (Throwable e) { LOGGER.log(Level.SEVERE, "Exception caught from launcher.", e); - + return ExitCode.ERROR; } } - + private enum PreLaunchAction { PROCEED, LAUNCH, ABORT } - + + private enum ExitCode { NORMAL(0), ERROR(1); - + private final int numericalCode; - + ExitCode(int numericalCode) { this.numericalCode = numericalCode; } } - + } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java index 7a622b1b..c572db10 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java @@ -58,6 +58,7 @@ package org.prismlauncher.launcher.impl; import org.prismlauncher.exception.ParseException; import org.prismlauncher.launcher.Launcher; import org.prismlauncher.utils.Parameters; +import org.prismlauncher.utils.StringUtils; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -101,13 +102,13 @@ public abstract class AbstractLauncher implements Launcher { height = DEFAULT_WINDOW_HEIGHT; } else { maximize = false; - - int byIndex = windowParams.indexOf('x'); - - if (byIndex != -1) { + + String[] sizePair = StringUtils.splitStringPair('x', windowParams); + + if (sizePair != null) { try { - width = Integer.parseInt(windowParams.substring(0, byIndex)); - height = Integer.parseInt(windowParams.substring(byIndex + 1)); + width = Integer.parseInt(sizePair[0]); + height = Integer.parseInt(sizePair[1]); return; } catch (NumberFormatException ignored) { } diff --git a/libraries/launcher/org/prismlauncher/utils/StringUtils.java b/libraries/launcher/org/prismlauncher/utils/StringUtils.java new file mode 100644 index 00000000..9058e4b3 --- /dev/null +++ b/libraries/launcher/org/prismlauncher/utils/StringUtils.java @@ -0,0 +1,15 @@ +package org.prismlauncher.utils; + + +public final class StringUtils { + private StringUtils() { + } + + public static String[] splitStringPair(char splitChar, String input) { + int splitPoint = input.indexOf(splitChar); + if (splitPoint == -1) + return null; + + return new String[]{ input.substring(0, splitPoint), input.substring(splitPoint + 1) }; + } +} From 9b8096c6993df68ac99c5c24483e169fbec60979 Mon Sep 17 00:00:00 2001 From: solonovamax Date: Tue, 1 Nov 2022 11:27:31 -0400 Subject: [PATCH 14/52] Get rid of gross HashMap being used by `LauncherFactory` and instead use *fancy* enum Signed-off-by: solonovamax --- .../launcher/LauncherFactory.java | 49 +++++++-------- .../launcher/impl/StandardLauncher.java | 23 +++++-- .../launcher/impl/legacy/LegacyLauncher.java | 62 ++++++++++++------- 3 files changed, 84 insertions(+), 50 deletions(-) diff --git a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java index 22e92632..6f9be63c 100644 --- a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java +++ b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java @@ -56,43 +56,42 @@ package org.prismlauncher.launcher; + import org.prismlauncher.launcher.impl.StandardLauncher; import org.prismlauncher.launcher.impl.legacy.LegacyLauncher; import org.prismlauncher.utils.Parameters; -import java.util.HashMap; -import java.util.Map; public final class LauncherFactory { - - private static final Map launcherRegistry = new HashMap<>(); - - static { - launcherRegistry.put("standard", new LauncherProvider() { - @Override - public Launcher provide(Parameters parameters) { - return new StandardLauncher(parameters); - } - }); - launcherRegistry.put("legacy", new LauncherProvider() { - @Override - public Launcher provide(Parameters parameters) { - return new LegacyLauncher(parameters); - } - }); - } private LauncherFactory() { } - public static Launcher createLauncher(Parameters parameters) { - String name = parameters.getString("launcher"); + public static Launcher createLauncher(String launcherType, Parameters parameters) { + return createLauncher(LauncherType.valueOf(launcherType.toUpperCase()), parameters); + } - LauncherProvider launcherProvider = launcherRegistry.get(name); - - if (launcherProvider == null) - throw new IllegalArgumentException("Invalid launcher type: " + name); + public static Launcher createLauncher(LauncherType launcherType, Parameters parameters) { + LauncherProvider launcherProvider = launcherType.getLauncherProvider(); return launcherProvider.provide(parameters); } + public static Launcher createLauncher(Parameters parameters) { + return createLauncher(parameters.getString("launcher"), parameters); + } + + public enum LauncherType { + STANDARD(StandardLauncher.getProvider()), + LEGACY(LegacyLauncher.getProvider()); + + private final LauncherProvider launcherProvider; + + LauncherType(LauncherProvider launcherProvider) { + this.launcherProvider = launcherProvider; + } + + public LauncherProvider getLauncherProvider() { + return launcherProvider; + } + } } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java index 5c884e99..24b12c95 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java @@ -54,15 +54,23 @@ package org.prismlauncher.launcher.impl; + +import org.prismlauncher.launcher.Launcher; +import org.prismlauncher.launcher.LauncherProvider; import org.prismlauncher.utils.Parameters; + public final class StandardLauncher extends AbstractLauncher { - public StandardLauncher(Parameters params) { - super(params); - } + public StandardLauncher(Parameters params) { + super(params); + } - @Override + public static LauncherProvider getProvider() { + return new StandardLauncherProvider(); + } + + @Override public void launch() throws Throwable { // window size, title and state @@ -87,4 +95,11 @@ public final class StandardLauncher extends AbstractLauncher { loadAndInvokeMain(); } + + private static class StandardLauncherProvider implements LauncherProvider { + @Override + public Launcher provide(Parameters parameters) { + return new StandardLauncher(parameters); + } + } } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java index d7a98352..e342e788 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java @@ -55,6 +55,9 @@ package org.prismlauncher.launcher.impl.legacy; + +import org.prismlauncher.launcher.Launcher; +import org.prismlauncher.launcher.LauncherProvider; import org.prismlauncher.launcher.impl.AbstractLauncher; import org.prismlauncher.utils.Parameters; @@ -70,6 +73,7 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; + /** * Used to launch old versions that support applets. */ @@ -78,10 +82,13 @@ public final class LegacyLauncher extends AbstractLauncher { private static final Logger LOGGER = Logger.getLogger("LegacyLauncher"); private final String user, session; + private final String title; + private final String appletClass; private final boolean noApplet; + private final String cwd; public LegacyLauncher(Parameters params) { @@ -98,6 +105,35 @@ public final class LegacyLauncher extends AbstractLauncher { cwd = System.getProperty("user.dir"); } + public static LauncherProvider getProvider() { + return new LegacyLauncherProvider(); + } + + /** + * Finds a field that looks like a Minecraft base folder in a supplied class + * + * @param clazz the class to scan + * + * @return The found field. + */ + private static Field getMinecraftGameDirField(Class clazz) { + // Field we're looking for is always + // private static File obfuscatedName = null; + for (Field field : clazz.getDeclaredFields()) { + // Has to be File + if (field.getType() != File.class) + continue; + + // And Private Static. + if (!Modifier.isStatic(field.getModifiers()) || !Modifier.isPrivate(field.getModifiers())) + continue; + + return field; + } + + return null; + } + @Override public void launch() throws Throwable { Class main = loadMain(); @@ -130,7 +166,7 @@ public final class LegacyLauncher extends AbstractLauncher { serverAddress, serverPort, mcParams.contains("--demo") - ); + ); return; } catch (Throwable e) { @@ -143,27 +179,11 @@ public final class LegacyLauncher extends AbstractLauncher { invokeMain(main); } - /** - * Finds a field that looks like a Minecraft base folder in a supplied class - * @param clazz the class to scan - * @return The found field. - */ - private static Field getMinecraftGameDirField(Class clazz) { - // Field we're looking for is always - // private static File obfuscatedName = null; - for (Field field : clazz.getDeclaredFields()) { - // Has to be File - if (field.getType() != File.class) - continue; - // And Private Static. - if (!Modifier.isStatic(field.getModifiers()) || !Modifier.isPrivate(field.getModifiers())) - continue; - - return field; + private static class LegacyLauncherProvider implements LauncherProvider { + @Override + public Launcher provide(Parameters parameters) { + return new LegacyLauncher(parameters); } - - return null; } - } From dabb84f62a35ea67793425f9118ea6a5bca96e00 Mon Sep 17 00:00:00 2001 From: solonovamax Date: Tue, 1 Nov 2022 12:27:04 -0400 Subject: [PATCH 15/52] Cleanup launcher classes Cleanup a bunch of the code in launcher classes - Migrate the majority of the reflection to ReflectionUtils - Decrease logic in AbstractLauncher - Add logging to launcher classes at FINE level - make mcParams in AbstractLauncher an immutable list to prevent runtime manipulation - StandardLauncher instead copies the list to modify it Signed-off-by: solonovamax --- libraries/launcher/CMakeLists.txt | 1 + .../exception/ParameterNotFoundException.java | 22 ++- .../exception/ParseException.java | 21 +++ .../launcher/impl/AbstractLauncher.java | 67 ++++----- .../launcher/impl/StandardLauncher.java | 36 +++-- .../launcher/impl/legacy/LegacyLauncher.java | 80 +++-------- .../org/prismlauncher/utils/Parameters.java | 4 +- .../prismlauncher/utils/ReflectionUtils.java | 131 ++++++++++++++++++ 8 files changed, 248 insertions(+), 114 deletions(-) create mode 100644 libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java diff --git a/libraries/launcher/CMakeLists.txt b/libraries/launcher/CMakeLists.txt index f85c2354..45a43b93 100644 --- a/libraries/launcher/CMakeLists.txt +++ b/libraries/launcher/CMakeLists.txt @@ -18,6 +18,7 @@ set(SRC org/prismlauncher/exception/ParameterNotFoundException.java org/prismlauncher/exception/ParseException.java org/prismlauncher/utils/Parameters.java + org/prismlauncher/utils/ReflectionUtils.java net/minecraft/Launcher.java ) add_jar(NewLaunch ${SRC}) diff --git a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java index c083e02a..3dd6efc3 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java @@ -54,10 +54,28 @@ package org.prismlauncher.exception; + +@SuppressWarnings("serial") public final class ParameterNotFoundException extends IllegalArgumentException { - public ParameterNotFoundException(String key) { - super("Unknown parameter name: " + key); + public ParameterNotFoundException(String message, Throwable cause) { + super(message, cause); + } + + public ParameterNotFoundException(Throwable cause) { + super(cause); + } + + public ParameterNotFoundException(String message) { + super(message); + } + + public ParameterNotFoundException() { + super(); + } + + public static ParameterNotFoundException forParameterName(String parameterName) { + return new ParameterNotFoundException(String.format("Unknown parameter name '%s'", parameterName)); } } diff --git a/libraries/launcher/org/prismlauncher/exception/ParseException.java b/libraries/launcher/org/prismlauncher/exception/ParseException.java index 8904f9ee..2243f23f 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParseException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParseException.java @@ -54,10 +54,31 @@ package org.prismlauncher.exception; + +@SuppressWarnings({ "serial", "unused" }) public final class ParseException extends IllegalArgumentException { public ParseException(String message) { super(message); } + public ParseException(String message, Throwable cause) { + super(message, cause); + } + + public ParseException(Throwable cause) { + super(cause); + } + + public ParseException() { + super(); + } + + public static ParseException forInputString(String inputString) { + return new ParseException(String.format("Could not parse input string '%s'", inputString)); + } + + public static ParseException forInputString(String inputString, Throwable cause) { + return new ParseException(String.format("Could not parse input string '%s'", inputString), cause); + } } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java index c572db10..9dd7df10 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java @@ -55,81 +55,66 @@ package org.prismlauncher.launcher.impl; + import org.prismlauncher.exception.ParseException; import org.prismlauncher.launcher.Launcher; import org.prismlauncher.utils.Parameters; import org.prismlauncher.utils.StringUtils; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; import java.util.ArrayList; +import java.util.Collections; import java.util.List; + public abstract class AbstractLauncher implements Launcher { private static final int DEFAULT_WINDOW_WIDTH = 854; + private static final int DEFAULT_WINDOW_HEIGHT = 480; // parameters, separated from ParamBucket protected final List mcParams; - private final String mainClass; // secondary parameters protected final int width; + protected final int height; + protected final boolean maximize; - protected final String serverAddress, serverPort; + protected final String serverAddress; - protected final ClassLoader classLoader; + protected final String serverPort; + + protected final String mainClassName; protected AbstractLauncher(Parameters params) { - classLoader = ClassLoader.getSystemClassLoader(); + this.mcParams = Collections.unmodifiableList(params.getList("param", new ArrayList())); + this.mainClassName = params.getString("mainClass", "net.minecraft.client.Minecraft"); - mcParams = params.getList("param", new ArrayList()); - mainClass = params.getString("mainClass", "net.minecraft.client.Minecraft"); - - serverAddress = params.getString("serverAddress", null); - serverPort = params.getString("serverPort", null); + this.serverAddress = params.getString("serverAddress", null); + this.serverPort = params.getString("serverPort", null); String windowParams = params.getString("windowParams", null); - if ("max".equals(windowParams) || windowParams == null) { - maximize = windowParams != null; + this.maximize = "max".equalsIgnoreCase(windowParams); - width = DEFAULT_WINDOW_WIDTH; - height = DEFAULT_WINDOW_HEIGHT; - } else { - maximize = false; - + if (windowParams != null && !"max".equalsIgnoreCase(windowParams)) { String[] sizePair = StringUtils.splitStringPair('x', windowParams); - + if (sizePair != null) { try { - width = Integer.parseInt(sizePair[0]); - height = Integer.parseInt(sizePair[1]); - return; - } catch (NumberFormatException ignored) { + this.width = Integer.parseInt(sizePair[0]); + this.height = Integer.parseInt(sizePair[1]); + } catch (NumberFormatException e) { + throw new ParseException(String.format("Could not parse window parameters from '%s'", windowParams), e); } + } else { + throw new ParseException(String.format("Invalid window size parameters '%s'. Format: [height]x[width]", windowParams)); } - - throw new ParseException("Invalid window size parameter value: " + windowParams); + } else { + this.width = DEFAULT_WINDOW_WIDTH; + this.height = DEFAULT_WINDOW_HEIGHT; } } - - protected Class loadMain() throws ClassNotFoundException { - return classLoader.loadClass(mainClass); - } - - protected void loadAndInvokeMain() throws Throwable { - invokeMain(loadMain()); - } - - protected void invokeMain(Class mainClass) throws Throwable { - MethodHandle method = MethodHandles.lookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)); - - method.invokeExact(mcParams.toArray(new String[0])); - } - } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java index 24b12c95..fc0c9823 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java @@ -58,9 +58,17 @@ package org.prismlauncher.launcher.impl; import org.prismlauncher.launcher.Launcher; import org.prismlauncher.launcher.LauncherProvider; import org.prismlauncher.utils.Parameters; +import org.prismlauncher.utils.ReflectionUtils; + +import java.lang.invoke.MethodHandle; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; public final class StandardLauncher extends AbstractLauncher { + private static final Logger LOGGER = Logger.getLogger("LegacyLauncher"); + public StandardLauncher(Parameters params) { super(params); @@ -78,21 +86,27 @@ public final class StandardLauncher extends AbstractLauncher { // the following often breaks linux screen setups // mcparams.add("--fullscreen"); - if (!maximize) { - mcParams.add("--width"); - mcParams.add(Integer.toString(width)); - mcParams.add("--height"); - mcParams.add(Integer.toString(height)); + List launchParameters = new ArrayList<>(this.mcParams); + + if (!this.maximize) { + launchParameters.add("--width"); + launchParameters.add(Integer.toString(width)); + launchParameters.add("--height"); + launchParameters.add(Integer.toString(height)); } - if (serverAddress != null) { - mcParams.add("--server"); - mcParams.add(serverAddress); - mcParams.add("--port"); - mcParams.add(serverPort); + if (this.serverAddress != null) { + launchParameters.add("--server"); + launchParameters.add(serverAddress); + launchParameters.add("--port"); + launchParameters.add(serverPort); } - loadAndInvokeMain(); + LOGGER.info("Launching minecraft using the main class entrypoint"); + + MethodHandle method = ReflectionUtils.findMainEntrypoint(this.mainClassName); + + method.invokeExact((Object[]) launchParameters.toArray(new String[0])); } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java index e342e788..0ce3c57b 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java @@ -60,14 +60,11 @@ import org.prismlauncher.launcher.Launcher; import org.prismlauncher.launcher.LauncherProvider; import org.prismlauncher.launcher.impl.AbstractLauncher; import org.prismlauncher.utils.Parameters; +import org.prismlauncher.utils.ReflectionUtils; -import java.applet.Applet; import java.io.File; import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; import java.lang.reflect.Field; -import java.lang.reflect.Modifier; import java.util.Collections; import java.util.List; import java.util.logging.Level; @@ -87,7 +84,7 @@ public final class LegacyLauncher extends AbstractLauncher { private final String appletClass; - private final boolean noApplet; + private final boolean usesApplet; private final String cwd; @@ -100,8 +97,9 @@ public final class LegacyLauncher extends AbstractLauncher { appletClass = params.getString("appletClass", "net.minecraft.client.MinecraftApplet"); List traits = params.getList("traits", Collections.emptyList()); - noApplet = traits.contains("noapplet"); + usesApplet = !traits.contains("noapplet"); + //noinspection AccessOfSystemProperties cwd = System.getProperty("user.dir"); } @@ -109,74 +107,40 @@ public final class LegacyLauncher extends AbstractLauncher { return new LegacyLauncherProvider(); } - /** - * Finds a field that looks like a Minecraft base folder in a supplied class - * - * @param clazz the class to scan - * - * @return The found field. - */ - private static Field getMinecraftGameDirField(Class clazz) { - // Field we're looking for is always - // private static File obfuscatedName = null; - for (Field field : clazz.getDeclaredFields()) { - // Has to be File - if (field.getType() != File.class) - continue; - - // And Private Static. - if (!Modifier.isStatic(field.getModifiers()) || !Modifier.isPrivate(field.getModifiers())) - continue; - - return field; - } - - return null; - } - @Override public void launch() throws Throwable { - Class main = loadMain(); - Field gameDirField = getMinecraftGameDirField(main); + Class main = ClassLoader.getSystemClassLoader().loadClass(this.mainClassName); + Field gameDirField = ReflectionUtils.getMinecraftGameDirField(main); if (gameDirField == null) { - LOGGER.warning("Could not find Mineraft path field."); + LOGGER.warning("Could not find Minecraft path field"); } else { gameDirField.setAccessible(true); - gameDirField.set(null, new File(cwd)); + gameDirField.set(null /* field is static, so instance is null */, new File(cwd)); } - if (!noApplet) { - LOGGER.info("Launching with applet wrapper..."); + if (this.usesApplet) { + LOGGER.info("Launching legacy minecraft using applet wrapper..."); try { - Class appletClass = classLoader.loadClass(this.appletClass); - - MethodHandle constructor = MethodHandles.lookup().findConstructor(appletClass, MethodType.methodType(void.class)); - Applet applet = (Applet) constructor.invoke(); - - LegacyFrame window = new LegacyFrame(title, applet); + LegacyFrame window = new LegacyFrame(title, ReflectionUtils.createAppletClass(this.appletClass)); window.start( - user, - session, - width, - height, - maximize, - serverAddress, - serverPort, - mcParams.contains("--demo") + this.user, + this.session, + this.width, this.height, this.maximize, + this.serverAddress, this.serverPort, + this.mcParams.contains("--demo") ); - - return; } catch (Throwable e) { - LOGGER.log(Level.SEVERE, "Applet wrapper failed:", e); - - LOGGER.warning("Falling back to using main class."); + LOGGER.log(Level.SEVERE, "Running applet wrapper failed with exception", e); } - } + } else { + LOGGER.info("Launching legacy minecraft using the main class entrypoint"); + MethodHandle method = ReflectionUtils.findMainEntrypoint(main); - invokeMain(main); + method.invokeExact((Object[]) mcParams.toArray(new String[0])); + } } diff --git a/libraries/launcher/org/prismlauncher/utils/Parameters.java b/libraries/launcher/org/prismlauncher/utils/Parameters.java index 5596e88a..6fbd0ef1 100644 --- a/libraries/launcher/org/prismlauncher/utils/Parameters.java +++ b/libraries/launcher/org/prismlauncher/utils/Parameters.java @@ -83,7 +83,7 @@ public final class Parameters { List params = map.get(key); if (params == null) - throw new ParameterNotFoundException(key); + throw ParameterNotFoundException.forParameterName(key); return params; } @@ -101,7 +101,7 @@ public final class Parameters { List list = getList(key); if (list.isEmpty()) - throw new ParameterNotFoundException(key); + throw ParameterNotFoundException.forParameterName(key); return list.get(0); } diff --git a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java new file mode 100644 index 00000000..484e0d8a --- /dev/null +++ b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java @@ -0,0 +1,131 @@ +package org.prismlauncher.utils; + + +import java.applet.Applet; +import java.io.File; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.logging.Level; +import java.util.logging.Logger; + + +public final class ReflectionUtils { + private static final Logger LOGGER = Logger.getLogger("ReflectionUtils"); + + private ReflectionUtils() { + } + + /** + * Instantiate an applet class by name + * + * @param appletClassName The name of the applet class to resolve + * + * @return The instantiated applet class + * + * @throws ClassNotFoundException if the provided class name cannot be found + * @throws NoSuchMethodException if the no-args constructor cannot be found + * @throws IllegalAccessException if the constructor cannot be accessed via method handles + * @throws Throwable any exceptions from the class's constructor + */ + public static Applet createAppletClass(String appletClassName) throws Throwable { + Class appletClass = ClassLoader.getSystemClassLoader().loadClass(appletClassName); + + MethodHandle appletConstructor = MethodHandles.lookup().findConstructor(appletClass, MethodType.methodType(void.class)); + return (Applet) appletConstructor.invoke(); + } + + /** + * Finds a field that looks like a Minecraft base folder in a supplied class + * + * @param minecraftMainClass the class to scan + * + * @return The found field. + */ + public static Field getMinecraftGameDirField(Class minecraftMainClass) { + LOGGER.fine("Resolving minecraft game directory field"); + // Field we're looking for is always + // private static File obfuscatedName = null; + for (Field field : minecraftMainClass.getDeclaredFields()) { + // Has to be File + if (field.getType() != File.class) { + continue; + } + + int fieldModifiers = field.getModifiers(); + + + // Must be static + if (!Modifier.isStatic(fieldModifiers)) { + LOGGER.log(Level.FINE, "Rejecting field {0} because it is not static", field.getName()); + continue; + } + + // Must be private + if (!Modifier.isPrivate(fieldModifiers)) { + LOGGER.log(Level.FINE, "Rejecting field {0} because it is not private", field.getName()); + continue; + } + + // Must not be final + if (Modifier.isFinal(fieldModifiers)) { + LOGGER.log(Level.FINE, "Rejecting field {0} because it is final", field.getName()); + continue; + } + + LOGGER.log(Level.FINE, "Identified field {0} to match conditions for minecraft game directory field", field.getName()); + + return field; + } + + return null; + } + + /** + * Resolve main entrypoint and returns method handle for it. + *

+ * Resolves a method that matches the following signature + * + * public static void main(String[] args) { + *

+ * } + * + * + * @param entrypointClass The entrypoint class to resolve the method from + * + * @return The method handle for the resolved entrypoint + * + * @throws NoSuchMethodException If no method matching the correct signature can be found + * @throws IllegalAccessException If method handles cannot access the entrypoint + */ + public static MethodHandle findMainEntrypoint(Class entrypointClass) throws NoSuchMethodException, IllegalAccessException { + return MethodHandles.lookup().findStatic(entrypointClass, "main", MethodType.methodType(void.class, String[].class)); + } + + /** + * Resolve main entrypoint and returns method handle for it. + *

+ * Resolves a method that matches the following signature + * + * public static void main(String[] args) { + *

+ * } + * + * + * @param entrypointClassName The name of the entrypoint class to resolve the method from + * + * @return The method handle for the resolved entrypoint + * + * @throws ClassNotFoundException If a class cannot be found with the provided name + * @throws NoSuchMethodException If no method matching the correct signature can be found + * @throws IllegalAccessException If method handles cannot access the entrypoint + */ + public static MethodHandle findMainEntrypoint(String entrypointClassName) throws + ClassNotFoundException, + NoSuchMethodException, + IllegalAccessException { + return findMainEntrypoint(ClassLoader.getSystemClassLoader().loadClass(entrypointClassName)); + } +} From e899e31745e2f10fdd404127750b6ee22364d405 Mon Sep 17 00:00:00 2001 From: solonovamax Date: Tue, 1 Nov 2022 12:34:13 -0400 Subject: [PATCH 16/52] More informative exceptions in entrypoint Signed-off-by: solonovamax --- .../org/prismlauncher/EntryPoint.java | 83 +++++++++++-------- 1 file changed, 49 insertions(+), 34 deletions(-) diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index 987dcc12..07af4e55 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -71,22 +71,26 @@ import java.util.logging.Logger; public final class EntryPoint { private static final Logger LOGGER = Logger.getLogger("EntryPoint"); - + + private EntryPoint() { + } + public static void main(String[] args) { ExitCode exitCode = listen(); - + if (exitCode != ExitCode.NORMAL) { LOGGER.warning("Exiting with " + exitCode); - + + //noinspection CallToSystemExit System.exit(exitCode.numericalCode); } } - + private static PreLaunchAction parseLine(String input, Parameters params) throws ParseException { - if (input.isEmpty()) - throw new ParseException("Unexpected empty string!"); - - + if (input.isEmpty()) // TODO: 2022-11-01 Should we just ignore this? + throw new ParseException("Unexpected empty string! You should not pass empty newlines to stdin."); + + if ("launch".equalsIgnoreCase(input)) { return PreLaunchAction.LAUNCH; } else if ("abort".equalsIgnoreCase(input)) { @@ -94,22 +98,26 @@ public final class EntryPoint { } else { String[] pair = StringUtils.splitStringPair(' ', input); if (pair == null) - throw new ParseException("Error while parsing:" + input); - + throw new ParseException(String.format( + "Could not split input string '%s' by space. All input provided from stdin must be either 'launch', 'abort', or " + + "in the format '[param name] [param]'.", + input)); + params.add(pair[0], pair[1]); - + return PreLaunchAction.PROCEED; } } - + private static ExitCode listen() { Parameters parameters = new Parameters(); PreLaunchAction preLaunchAction = PreLaunchAction.PROCEED; - + try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8))) { String line; - + while (preLaunchAction == PreLaunchAction.PROCEED) { + //noinspection NestedAssignment if ((line = reader.readLine()) != null) { preLaunchAction = parseLine(line, parameters); } else { @@ -117,51 +125,58 @@ public final class EntryPoint { } } } catch (IOException | ParseException e) { - LOGGER.log(Level.SEVERE, "Launcher abort due to exception:", e); - - return ExitCode.ERROR; + LOGGER.log(Level.SEVERE, "Launcher abort due to exception", e); + + return ExitCode.ILLEGAL_ARGUMENT; } - + // Main loop if (preLaunchAction == PreLaunchAction.ABORT) { LOGGER.info("Launch aborted by the launcher."); - - return ExitCode.ERROR; + + return ExitCode.ABORT; } - + try { Launcher launcher = LauncherFactory.createLauncher(parameters); - + launcher.launch(); - + return ExitCode.NORMAL; } catch (IllegalArgumentException e) { LOGGER.log(Level.SEVERE, "Wrong argument.", e); - - return ExitCode.ERROR; + + return ExitCode.ILLEGAL_ARGUMENT; + } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException e) { + LOGGER.log(Level.SEVERE, "Caught reflection exception from launcher", e); + + return ExitCode.REFLECTION_EXCEPTION; } catch (Throwable e) { - LOGGER.log(Level.SEVERE, "Exception caught from launcher.", e); - + LOGGER.log(Level.SEVERE, "Exception caught from launcher", e); + return ExitCode.ERROR; } } - + private enum PreLaunchAction { PROCEED, LAUNCH, ABORT } - - + + private enum ExitCode { NORMAL(0), - ERROR(1); - + ABORT(1), + ERROR(2), + ILLEGAL_ARGUMENT(3), + REFLECTION_EXCEPTION(4); + private final int numericalCode; - + ExitCode(int numericalCode) { this.numericalCode = numericalCode; } } - + } From afe088dba18b83ae1ea79e3b31ef5026f68b7b6d Mon Sep 17 00:00:00 2001 From: solonovamax Date: Wed, 2 Nov 2022 15:10:05 -0400 Subject: [PATCH 17/52] Fix license headers - Update license headers in several files to remove multimc apache reference, when unneeded - LauncherFactory: we've entirely rewritten this class at this point, so it's fully under GPL code - Launcher: this interface contains zero logic, and only a single method named `launch`, so I doubt you can actually copyright that - LauncherProvider: same as above - ParseException, ParameterNotFoundException: same as above; this class contains almost no logic (And the logic that was added is under GPL) - ReflectionUtils, StringUtils: add license header - Everything else: modify the program name in the license header from "PolyMC - Minecraft Launcher" to "Prism Launcher" Signed-off-by: solonovamax --- .../launcher/net/minecraft/Launcher.java | 3 +- .../org/prismlauncher/EntryPoint.java | 3 +- .../exception/ParameterNotFoundException.java | 20 +--------- .../exception/ParseException.java | 20 +--------- .../org/prismlauncher/launcher/Launcher.java | 20 +--------- .../launcher/LauncherFactory.java | 20 +--------- .../launcher/LauncherProvider.java | 20 +--------- .../launcher/impl/AbstractLauncher.java | 3 +- .../launcher/impl/StandardLauncher.java | 3 +- .../launcher/impl/legacy/LegacyFrame.java | 7 +++- .../launcher/impl/legacy/LegacyLauncher.java | 3 +- .../org/prismlauncher/utils/Parameters.java | 3 +- .../prismlauncher/utils/ReflectionUtils.java | 38 ++++++++++++++++++ .../org/prismlauncher/utils/StringUtils.java | 40 ++++++++++++++++++- 14 files changed, 103 insertions(+), 100 deletions(-) diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java index 147c727e..8dff5692 100644 --- a/libraries/launcher/net/minecraft/Launcher.java +++ b/libraries/launcher/net/minecraft/Launcher.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index 07af4e55..444e665f 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax diff --git a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java index 3dd6efc3..48bf9f4c 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Samisafool @@ -33,23 +34,6 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * - * This file incorporates work covered by the following copyright and - * permission notice: - * - * Copyright 2013-2021 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. */ package org.prismlauncher.exception; diff --git a/libraries/launcher/org/prismlauncher/exception/ParseException.java b/libraries/launcher/org/prismlauncher/exception/ParseException.java index 2243f23f..0d5f3c10 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParseException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParseException.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Samisafool @@ -33,23 +34,6 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * - * This file incorporates work covered by the following copyright and - * permission notice: - * - * Copyright 2013-2021 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. */ package org.prismlauncher.exception; diff --git a/libraries/launcher/org/prismlauncher/launcher/Launcher.java b/libraries/launcher/org/prismlauncher/launcher/Launcher.java index 7bf9ba0d..d54cfd5c 100644 --- a/libraries/launcher/org/prismlauncher/launcher/Launcher.java +++ b/libraries/launcher/org/prismlauncher/launcher/Launcher.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Samisafool @@ -35,23 +36,6 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * - * This file incorporates work covered by the following copyright and - * permission notice: - * - * Copyright 2013-2021 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. */ package org.prismlauncher.launcher; diff --git a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java index 6f9be63c..03a76d29 100644 --- a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java +++ b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Samisafool @@ -35,23 +36,6 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * - * This file incorporates work covered by the following copyright and - * permission notice: - * - * Copyright 2013-2021 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. */ package org.prismlauncher.launcher; diff --git a/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java b/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java index 66d23c0f..73d0cdc5 100644 --- a/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java +++ b/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 solonovamax * @@ -32,23 +33,6 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * - * This file incorporates work covered by the following copyright and - * permission notice: - * - * Copyright 2013-2021 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. */ package org.prismlauncher.launcher; diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java index 9dd7df10..ac7a6223 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 TheKodeToad diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java index fc0c9823..61709bf7 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java index 12196fd4..391aa702 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 flow @@ -56,11 +57,13 @@ package org.prismlauncher.launcher.impl.legacy; + import net.minecraft.Launcher; import javax.imageio.ImageIO; import java.applet.Applet; -import java.awt.*; +import java.awt.Dimension; +import java.awt.Frame; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java index 0ce3c57b..17cdeb08 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 flow * Copyright (C) 2022 TheKodeToad diff --git a/libraries/launcher/org/prismlauncher/utils/Parameters.java b/libraries/launcher/org/prismlauncher/utils/Parameters.java index 6fbd0ef1..d019aa41 100644 --- a/libraries/launcher/org/prismlauncher/utils/Parameters.java +++ b/libraries/launcher/org/prismlauncher/utils/Parameters.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Samisafool diff --git a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java index 484e0d8a..b0eefec7 100644 --- a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java @@ -1,3 +1,41 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher + * + * Copyright (C) 2022 solonovamax + * Copyright (C) 2022 TheKodeToad + * Copyright (C) 2022 icelimetea + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give + * you permission to link this library with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also meet, + * for each linked independent module, the terms and conditions of the + * license of that module. An independent module is a module which is + * not derived from or based on this library. If you modify this + * library, you may extend this exception to your version of the + * library, but you are not obliged to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.prismlauncher.utils; diff --git a/libraries/launcher/org/prismlauncher/utils/StringUtils.java b/libraries/launcher/org/prismlauncher/utils/StringUtils.java index 9058e4b3..d470624c 100644 --- a/libraries/launcher/org/prismlauncher/utils/StringUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/StringUtils.java @@ -1,15 +1,51 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher + * + * Copyright (C) 2022 solonovamax + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give + * you permission to link this library with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also meet, + * for each linked independent module, the terms and conditions of the + * license of that module. An independent module is a module which is + * not derived from or based on this library. If you modify this + * library, you may extend this exception to your version of the + * library, but you are not obliged to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.prismlauncher.utils; public final class StringUtils { private StringUtils() { } - + public static String[] splitStringPair(char splitChar, String input) { int splitPoint = input.indexOf(splitChar); if (splitPoint == -1) return null; - + return new String[]{ input.substring(0, splitPoint), input.substring(splitPoint + 1) }; } } From 8ce78dcc54a8ed3e6292a8650692fa9c520a993d Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Thu, 3 Nov 2022 16:40:23 +0000 Subject: [PATCH 18/52] Try to improve consistency - Makes code formatting more consistent with the C++ codebase. Probably removes some trailing whitespace. Maybe it would be best to commit an Eclipse or IntelliJ code format preferences file? - Removes obscure suppressions. I personally think it's better to only suppress warnings that javac complains about. Suppressing a lot of non-standardised warnings (many of them turned off by default even in IntelliJ) just creates needless clutter. - Fixes some trivial warnings instead of suppressing them. serialVersionUID is sort of stupid, but I'd rather mentally ignore it or just fix it if it's really that annoying. Signed-off-by: TheKodeToad --- libraries/launcher/net/minecraft/Launcher.java | 12 ++++++------ .../launcher/org/prismlauncher/EntryPoint.java | 14 +++++--------- .../exception/ParameterNotFoundException.java | 7 ++++--- .../prismlauncher/exception/ParseException.java | 7 +++++-- .../prismlauncher/launcher/LauncherFactory.java | 4 ++-- .../launcher/impl/AbstractLauncher.java | 14 +++----------- .../launcher/impl/StandardLauncher.java | 9 +++------ .../launcher/impl/legacy/LegacyFrame.java | 5 ++--- .../launcher/impl/legacy/LegacyLauncher.java | 13 +++---------- .../org/prismlauncher/utils/ReflectionUtils.java | 9 ++++----- .../org/prismlauncher/utils/StringUtils.java | 5 +++-- 11 files changed, 40 insertions(+), 59 deletions(-) diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java index 8dff5692..796e4829 100644 --- a/libraries/launcher/net/minecraft/Launcher.java +++ b/libraries/launcher/net/minecraft/Launcher.java @@ -72,12 +72,12 @@ import java.util.TreeMap; */ public final class Launcher extends Applet implements AppletStub { + private static final long serialVersionUID = 1L; + private final Map params = new TreeMap<>(); private Applet wrappedApplet; - private final URL documentBase; - private boolean active = false; public Launcher(Applet applet) { @@ -85,11 +85,11 @@ public final class Launcher extends Applet implements AppletStub { } public Launcher(Applet applet, URL documentBase) { - this.setLayout(new BorderLayout()); + setLayout(new BorderLayout()); this.add(applet, "Center"); - this.wrappedApplet = applet; + wrappedApplet = applet; try { if (documentBase != null) { @@ -109,12 +109,12 @@ public final class Launcher extends Applet implements AppletStub { } public void replace(Applet applet) { - this.wrappedApplet = applet; + wrappedApplet = applet; applet.setStub(this); applet.setSize(getWidth(), getHeight()); - this.setLayout(new BorderLayout()); + setLayout(new BorderLayout()); this.add(applet, "Center"); applet.init(); diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index 444e665f..be180d6a 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -55,7 +55,6 @@ package org.prismlauncher; - import org.prismlauncher.exception.ParseException; import org.prismlauncher.launcher.Launcher; import org.prismlauncher.launcher.LauncherFactory; @@ -69,7 +68,6 @@ import java.nio.charset.StandardCharsets; import java.util.logging.Level; import java.util.logging.Logger; - public final class EntryPoint { private static final Logger LOGGER = Logger.getLogger("EntryPoint"); @@ -92,11 +90,11 @@ public final class EntryPoint { throw new ParseException("Unexpected empty string! You should not pass empty newlines to stdin."); - if ("launch".equalsIgnoreCase(input)) { + if ("launch".equalsIgnoreCase(input)) return PreLaunchAction.LAUNCH; - } else if ("abort".equalsIgnoreCase(input)) { + else if ("abort".equalsIgnoreCase(input)) return PreLaunchAction.ABORT; - } else { + else { String[] pair = StringUtils.splitStringPair(' ', input); if (pair == null) throw new ParseException(String.format( @@ -119,11 +117,10 @@ public final class EntryPoint { while (preLaunchAction == PreLaunchAction.PROCEED) { //noinspection NestedAssignment - if ((line = reader.readLine()) != null) { + if ((line = reader.readLine()) != null) preLaunchAction = parseLine(line, parameters); - } else { + else preLaunchAction = PreLaunchAction.ABORT; - } } } catch (IOException | ParseException e) { LOGGER.log(Level.SEVERE, "Launcher abort due to exception", e); @@ -165,7 +162,6 @@ public final class EntryPoint { ABORT } - private enum ExitCode { NORMAL(0), ABORT(1), diff --git a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java index 48bf9f4c..ad973ace 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java @@ -5,6 +5,8 @@ * Copyright (C) 2022 icelimetea * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Samisafool + * Copyright (C) 2022 solonovamax + * Copyright (C) 2022 TheKodeToad * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -38,10 +40,10 @@ package org.prismlauncher.exception; - -@SuppressWarnings("serial") public final class ParameterNotFoundException extends IllegalArgumentException { + private static final long serialVersionUID = 1L; + public ParameterNotFoundException(String message, Throwable cause) { super(message, cause); } @@ -55,7 +57,6 @@ public final class ParameterNotFoundException extends IllegalArgumentException { } public ParameterNotFoundException() { - super(); } public static ParameterNotFoundException forParameterName(String parameterName) { diff --git a/libraries/launcher/org/prismlauncher/exception/ParseException.java b/libraries/launcher/org/prismlauncher/exception/ParseException.java index 0d5f3c10..2fd693e7 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParseException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParseException.java @@ -5,6 +5,8 @@ * Copyright (C) 2022 icelimetea * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Samisafool + * Copyright (C) 2022 solonovamax + * Copyright (C) 2022 TheKodeToad * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -38,10 +40,10 @@ package org.prismlauncher.exception; - -@SuppressWarnings({ "serial", "unused" }) public final class ParseException extends IllegalArgumentException { + private static final long serialVersionUID = 1L; + public ParseException(String message) { super(message); } @@ -65,4 +67,5 @@ public final class ParseException extends IllegalArgumentException { public static ParseException forInputString(String inputString, Throwable cause) { return new ParseException(String.format("Could not parse input string '%s'", inputString), cause); } + } diff --git a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java index 03a76d29..4844a774 100644 --- a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java +++ b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java @@ -40,13 +40,12 @@ package org.prismlauncher.launcher; - import org.prismlauncher.launcher.impl.StandardLauncher; import org.prismlauncher.launcher.impl.legacy.LegacyLauncher; import org.prismlauncher.utils.Parameters; - public final class LauncherFactory { + private LauncherFactory() { } @@ -78,4 +77,5 @@ public final class LauncherFactory { return launcherProvider; } } + } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java index ac7a6223..8aec7c28 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java @@ -56,7 +56,6 @@ package org.prismlauncher.launcher.impl; - import org.prismlauncher.exception.ParseException; import org.prismlauncher.launcher.Launcher; import org.prismlauncher.utils.Parameters; @@ -66,26 +65,18 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; - public abstract class AbstractLauncher implements Launcher { private static final int DEFAULT_WINDOW_WIDTH = 854; - private static final int DEFAULT_WINDOW_HEIGHT = 480; // parameters, separated from ParamBucket protected final List mcParams; // secondary parameters - protected final int width; - - protected final int height; - + protected final int width, height; protected final boolean maximize; - - protected final String serverAddress; - - protected final String serverPort; + protected final String serverAddress, serverPort; protected final String mainClassName; @@ -118,4 +109,5 @@ public abstract class AbstractLauncher implements Launcher { this.height = DEFAULT_WINDOW_HEIGHT; } } + } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java index 61709bf7..a3ea2f4a 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java @@ -55,7 +55,6 @@ package org.prismlauncher.launcher.impl; - import org.prismlauncher.launcher.Launcher; import org.prismlauncher.launcher.LauncherProvider; import org.prismlauncher.utils.Parameters; @@ -66,10 +65,9 @@ import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; - public final class StandardLauncher extends AbstractLauncher { - private static final Logger LOGGER = Logger.getLogger("LegacyLauncher"); + private static final Logger LOGGER = Logger.getLogger("LegacyLauncher"); public StandardLauncher(Parameters params) { super(params); @@ -105,16 +103,15 @@ public final class StandardLauncher extends AbstractLauncher { LOGGER.info("Launching minecraft using the main class entrypoint"); - MethodHandle method = ReflectionUtils.findMainEntrypoint(this.mainClassName); - + MethodHandle method = ReflectionUtils.findMainMethod(this.mainClassName); method.invokeExact((Object[]) launchParameters.toArray(new String[0])); } - private static class StandardLauncherProvider implements LauncherProvider { @Override public Launcher provide(Parameters parameters) { return new StandardLauncher(parameters); } } + } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java index 391aa702..96b422b2 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java @@ -57,7 +57,6 @@ package org.prismlauncher.launcher.impl.legacy; - import net.minecraft.Launcher; import javax.imageio.ImageIO; @@ -77,7 +76,7 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -public final class LegacyFrame extends Frame { +public final class LegacyFrame extends Frame /* TODO consider JFrame */ { private static final Logger LOGGER = Logger.getLogger("LegacyFrame"); @@ -163,7 +162,7 @@ public final class LegacyFrame extends Frame { setResizable(true); if (maximize) - this.setExtendedState(MAXIMIZED_BOTH); + setExtendedState(MAXIMIZED_BOTH); validate(); diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java index 17cdeb08..71e4bc8d 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java @@ -56,7 +56,6 @@ package org.prismlauncher.launcher.impl.legacy; - import org.prismlauncher.launcher.Launcher; import org.prismlauncher.launcher.LauncherProvider; import org.prismlauncher.launcher.impl.AbstractLauncher; @@ -71,7 +70,6 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; - /** * Used to launch old versions that support applets. */ @@ -80,13 +78,9 @@ public final class LegacyLauncher extends AbstractLauncher { private static final Logger LOGGER = Logger.getLogger("LegacyLauncher"); private final String user, session; - private final String title; - private final String appletClass; - private final boolean usesApplet; - private final String cwd; public LegacyLauncher(Parameters params) { @@ -100,7 +94,6 @@ public final class LegacyLauncher extends AbstractLauncher { List traits = params.getList("traits", Collections.emptyList()); usesApplet = !traits.contains("noapplet"); - //noinspection AccessOfSystemProperties cwd = System.getProperty("user.dir"); } @@ -113,9 +106,9 @@ public final class LegacyLauncher extends AbstractLauncher { Class main = ClassLoader.getSystemClassLoader().loadClass(this.mainClassName); Field gameDirField = ReflectionUtils.getMinecraftGameDirField(main); - if (gameDirField == null) { + if (gameDirField == null) LOGGER.warning("Could not find Minecraft path field"); - } else { + else { gameDirField.setAccessible(true); gameDirField.set(null /* field is static, so instance is null */, new File(cwd)); } @@ -144,11 +137,11 @@ public final class LegacyLauncher extends AbstractLauncher { } } - private static class LegacyLauncherProvider implements LauncherProvider { @Override public Launcher provide(Parameters parameters) { return new LegacyLauncher(parameters); } } + } diff --git a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java index b0eefec7..ad9e57fd 100644 --- a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java @@ -49,8 +49,8 @@ import java.lang.reflect.Modifier; import java.util.logging.Level; import java.util.logging.Logger; - public final class ReflectionUtils { + private static final Logger LOGGER = Logger.getLogger("ReflectionUtils"); private ReflectionUtils() { @@ -160,10 +160,9 @@ public final class ReflectionUtils { * @throws NoSuchMethodException If no method matching the correct signature can be found * @throws IllegalAccessException If method handles cannot access the entrypoint */ - public static MethodHandle findMainEntrypoint(String entrypointClassName) throws - ClassNotFoundException, - NoSuchMethodException, - IllegalAccessException { + public static MethodHandle findMainMethod(String entrypointClassName) + throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException { return findMainEntrypoint(ClassLoader.getSystemClassLoader().loadClass(entrypointClassName)); } + } diff --git a/libraries/launcher/org/prismlauncher/utils/StringUtils.java b/libraries/launcher/org/prismlauncher/utils/StringUtils.java index d470624c..a371b0cb 100644 --- a/libraries/launcher/org/prismlauncher/utils/StringUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/StringUtils.java @@ -36,8 +36,8 @@ package org.prismlauncher.utils; - public final class StringUtils { + private StringUtils() { } @@ -46,6 +46,7 @@ public final class StringUtils { if (splitPoint == -1) return null; - return new String[]{ input.substring(0, splitPoint), input.substring(splitPoint + 1) }; + return new String[] { input.substring(0, splitPoint), input.substring(splitPoint + 1) }; } + } From cae1ba7cd8d447bb15df5a820c5d8e3665bb489d Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Thu, 3 Nov 2022 17:04:16 +0000 Subject: [PATCH 19/52] Less needless verbosity, and return fallback Needlessly verbose commit message ik. Signed-off-by: TheKodeToad --- .../prismlauncher/launcher/impl/StandardLauncher.java | 4 ---- .../launcher/impl/legacy/LegacyLauncher.java | 10 ++++------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java index a3ea2f4a..485f65ee 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java @@ -67,8 +67,6 @@ import java.util.logging.Logger; public final class StandardLauncher extends AbstractLauncher { - private static final Logger LOGGER = Logger.getLogger("LegacyLauncher"); - public StandardLauncher(Parameters params) { super(params); } @@ -101,8 +99,6 @@ public final class StandardLauncher extends AbstractLauncher { launchParameters.add(serverPort); } - LOGGER.info("Launching minecraft using the main class entrypoint"); - MethodHandle method = ReflectionUtils.findMainMethod(this.mainClassName); method.invokeExact((Object[]) launchParameters.toArray(new String[0])); } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java index 71e4bc8d..00f55095 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java @@ -127,14 +127,12 @@ public final class LegacyLauncher extends AbstractLauncher { this.mcParams.contains("--demo") ); } catch (Throwable e) { - LOGGER.log(Level.SEVERE, "Running applet wrapper failed with exception", e); + LOGGER.log(Level.SEVERE, "Running applet wrapper failed with exception; falling back to main class", e); } - } else { - LOGGER.info("Launching legacy minecraft using the main class entrypoint"); - MethodHandle method = ReflectionUtils.findMainEntrypoint(main); - - method.invokeExact((Object[]) mcParams.toArray(new String[0])); } + + MethodHandle method = ReflectionUtils.findMainEntrypoint(main); + method.invokeExact((Object[]) mcParams.toArray(new String[0])); } private static class LegacyLauncherProvider implements LauncherProvider { From 779bc2c63df131fce0d230401a5a891eb2eb8794 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Thu, 3 Nov 2022 17:11:14 +0000 Subject: [PATCH 20/52] Fix WrongMethodTypeException. Invoke exact don't work like that Signed-off-by: TheKodeToad --- .../org/prismlauncher/launcher/impl/StandardLauncher.java | 3 +-- .../prismlauncher/launcher/impl/legacy/LegacyLauncher.java | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java index 485f65ee..d5b7961a 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java @@ -63,7 +63,6 @@ import org.prismlauncher.utils.ReflectionUtils; import java.lang.invoke.MethodHandle; import java.util.ArrayList; import java.util.List; -import java.util.logging.Logger; public final class StandardLauncher extends AbstractLauncher { @@ -100,7 +99,7 @@ public final class StandardLauncher extends AbstractLauncher { } MethodHandle method = ReflectionUtils.findMainMethod(this.mainClassName); - method.invokeExact((Object[]) launchParameters.toArray(new String[0])); + method.invokeExact(launchParameters.toArray(new String[0])); } private static class StandardLauncherProvider implements LauncherProvider { diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java index 00f55095..b7109962 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java @@ -125,14 +125,14 @@ public final class LegacyLauncher extends AbstractLauncher { this.width, this.height, this.maximize, this.serverAddress, this.serverPort, this.mcParams.contains("--demo") - ); + ); } catch (Throwable e) { LOGGER.log(Level.SEVERE, "Running applet wrapper failed with exception; falling back to main class", e); } } MethodHandle method = ReflectionUtils.findMainEntrypoint(main); - method.invokeExact((Object[]) mcParams.toArray(new String[0])); + method.invokeExact(mcParams.toArray(new String[0])); } private static class LegacyLauncherProvider implements LauncherProvider { From 5b9bfe8891f007a9dcec1a4754df6bc62e0396eb Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Thu, 3 Nov 2022 17:30:13 +0000 Subject: [PATCH 21/52] Attempt to mimic clang-format Signed-off-by: TheKodeToad --- libraries/launcher/formatting-profile.xml | 399 ++++++++++++++++++ .../launcher/net/minecraft/Launcher.java | 65 ++- .../org/prismlauncher/EntryPoint.java | 35 +- .../launcher/LauncherFactory.java | 29 +- .../launcher/impl/AbstractLauncher.java | 9 +- .../launcher/impl/StandardLauncher.java | 15 +- .../launcher/impl/legacy/LegacyFrame.java | 40 +- .../launcher/impl/legacy/LegacyLauncher.java | 23 +- .../org/prismlauncher/utils/Parameters.java | 15 +- .../prismlauncher/utils/ReflectionUtils.java | 50 ++- .../org/prismlauncher/utils/StringUtils.java | 6 +- 11 files changed, 529 insertions(+), 157 deletions(-) create mode 100644 libraries/launcher/formatting-profile.xml diff --git a/libraries/launcher/formatting-profile.xml b/libraries/launcher/formatting-profile.xml new file mode 100644 index 00000000..bebc783e --- /dev/null +++ b/libraries/launcher/formatting-profile.xml @@ -0,0 +1,399 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java index 796e4829..ce9b59d4 100644 --- a/libraries/launcher/net/minecraft/Launcher.java +++ b/libraries/launcher/net/minecraft/Launcher.java @@ -68,7 +68,8 @@ import java.util.TreeMap; /** * WARNING: This class is reflectively accessed by legacy Forge versions. *

- * Changing field and method declarations without further testing is not recommended. + * Changing field and method declarations without further testing is not + * recommended. */ public final class Launcher extends Applet implements AppletStub { @@ -80,11 +81,10 @@ public final class Launcher extends Applet implements AppletStub { private final URL documentBase; private boolean active = false; - public Launcher(Applet applet) { - this(applet, null); - } + public Launcher(Applet applet) { this(applet, null); } - public Launcher(Applet applet, URL documentBase) { + public Launcher(Applet applet, URL documentBase) + { setLayout(new BorderLayout()); this.add(applet, "Center"); @@ -108,7 +108,8 @@ public final class Launcher extends Applet implements AppletStub { } } - public void replace(Applet applet) { + public void replace(Applet applet) + { wrappedApplet = applet; applet.setStub(this); @@ -127,17 +128,14 @@ public final class Launcher extends Applet implements AppletStub { } @Override - public boolean isActive() { - return active; - } + public boolean isActive() { return active; } @Override - public URL getDocumentBase() { - return documentBase; - } + public URL getDocumentBase() { return documentBase; } @Override - public URL getCodeBase() { + public URL getCodeBase() + { try { // TODO: 2022-10-27 Can this be changed to https? return new URL("http://www.minecraft.net/game/"); @@ -147,7 +145,8 @@ public final class Launcher extends Applet implements AppletStub { } @Override - public String getParameter(String name) { + public String getParameter(String name) + { String param = params.get(name); if (param != null) @@ -162,62 +161,54 @@ public final class Launcher extends Applet implements AppletStub { } @Override - public void resize(int width, int height) { - wrappedApplet.resize(width, height); - } + public void resize(int width, int height) { wrappedApplet.resize(width, height); } @Override - public void resize(Dimension size) { - wrappedApplet.resize(size); - } + public void resize(Dimension size) { wrappedApplet.resize(size); } @Override - public void init() { + public void init() + { if (wrappedApplet != null) wrappedApplet.init(); } @Override - public void start() { + public void start() + { wrappedApplet.start(); active = true; } @Override - public void stop() { + public void stop() + { wrappedApplet.stop(); active = false; } @Override - public void destroy() { - wrappedApplet.destroy(); - } + public void destroy() { wrappedApplet.destroy(); } @Override - public void appletResize(int width, int height) { - wrappedApplet.resize(width, height); - } + public void appletResize(int width, int height) { wrappedApplet.resize(width, height); } @Override - public void setVisible(boolean visible) { + public void setVisible(boolean visible) + { super.setVisible(visible); wrappedApplet.setVisible(visible); } @Override - public void paint(Graphics graphics) { - } + public void paint(Graphics graphics) {} @Override - public void update(Graphics graphics) { - } + public void update(Graphics graphics) {} - public void setParameter(String name, String value) { - params.put(name, value); - } + public void setParameter(String name, String value) { params.put(name, value); } } diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index be180d6a..88d5d8be 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -71,25 +71,25 @@ import java.util.logging.Logger; public final class EntryPoint { private static final Logger LOGGER = Logger.getLogger("EntryPoint"); - private EntryPoint() { - } + private EntryPoint() {} - public static void main(String[] args) { + public static void main(String[] args) + { ExitCode exitCode = listen(); if (exitCode != ExitCode.NORMAL) { LOGGER.warning("Exiting with " + exitCode); - //noinspection CallToSystemExit + // noinspection CallToSystemExit System.exit(exitCode.numericalCode); } } - private static PreLaunchAction parseLine(String input, Parameters params) throws ParseException { + private static PreLaunchAction parseLine(String input, Parameters params) throws ParseException + { if (input.isEmpty()) // TODO: 2022-11-01 Should we just ignore this? throw new ParseException("Unexpected empty string! You should not pass empty newlines to stdin."); - if ("launch".equalsIgnoreCase(input)) return PreLaunchAction.LAUNCH; else if ("abort".equalsIgnoreCase(input)) @@ -98,8 +98,8 @@ public final class EntryPoint { String[] pair = StringUtils.splitStringPair(' ', input); if (pair == null) throw new ParseException(String.format( - "Could not split input string '%s' by space. All input provided from stdin must be either 'launch', 'abort', or " + - "in the format '[param name] [param]'.", + "Could not split input string '%s' by space. All input provided from stdin must be either 'launch', 'abort', or " + + "in the format '[param name] [param]'.", input)); params.add(pair[0], pair[1]); @@ -108,7 +108,8 @@ public final class EntryPoint { } } - private static ExitCode listen() { + private static ExitCode listen() + { Parameters parameters = new Parameters(); PreLaunchAction preLaunchAction = PreLaunchAction.PROCEED; @@ -116,7 +117,7 @@ public final class EntryPoint { String line; while (preLaunchAction == PreLaunchAction.PROCEED) { - //noinspection NestedAssignment + // noinspection NestedAssignment if ((line = reader.readLine()) != null) preLaunchAction = parseLine(line, parameters); else @@ -157,23 +158,15 @@ public final class EntryPoint { } private enum PreLaunchAction { - PROCEED, - LAUNCH, - ABORT + PROCEED, LAUNCH, ABORT } private enum ExitCode { - NORMAL(0), - ABORT(1), - ERROR(2), - ILLEGAL_ARGUMENT(3), - REFLECTION_EXCEPTION(4); + NORMAL(0), ABORT(1), ERROR(2), ILLEGAL_ARGUMENT(3), REFLECTION_EXCEPTION(4); private final int numericalCode; - ExitCode(int numericalCode) { - this.numericalCode = numericalCode; - } + ExitCode(int numericalCode) { this.numericalCode = numericalCode; } } } diff --git a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java index 4844a774..1f7ea91b 100644 --- a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java +++ b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java @@ -46,36 +46,31 @@ import org.prismlauncher.utils.Parameters; public final class LauncherFactory { - private LauncherFactory() { - } + private LauncherFactory() + {} - public static Launcher createLauncher(String launcherType, Parameters parameters) { - return createLauncher(LauncherType.valueOf(launcherType.toUpperCase()), parameters); - } + public static Launcher createLauncher(String launcherType, Parameters parameters) + { return createLauncher(LauncherType.valueOf(launcherType.toUpperCase()), parameters); } - public static Launcher createLauncher(LauncherType launcherType, Parameters parameters) { + public static Launcher createLauncher(LauncherType launcherType, Parameters parameters) + { LauncherProvider launcherProvider = launcherType.getLauncherProvider(); return launcherProvider.provide(parameters); } - public static Launcher createLauncher(Parameters parameters) { - return createLauncher(parameters.getString("launcher"), parameters); - } + public static Launcher createLauncher(Parameters parameters) + { return createLauncher(parameters.getString("launcher"), parameters); } public enum LauncherType { - STANDARD(StandardLauncher.getProvider()), - LEGACY(LegacyLauncher.getProvider()); + STANDARD(StandardLauncher.getProvider()), LEGACY(LegacyLauncher.getProvider()); private final LauncherProvider launcherProvider; - LauncherType(LauncherProvider launcherProvider) { - this.launcherProvider = launcherProvider; - } + LauncherType(LauncherProvider launcherProvider) { this.launcherProvider = launcherProvider; } + + public LauncherProvider getLauncherProvider() { return launcherProvider; } - public LauncherProvider getLauncherProvider() { - return launcherProvider; - } } } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java index 8aec7c28..9eda8caf 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java @@ -80,7 +80,8 @@ public abstract class AbstractLauncher implements Launcher { protected final String mainClassName; - protected AbstractLauncher(Parameters params) { + protected AbstractLauncher(Parameters params) + { this.mcParams = Collections.unmodifiableList(params.getList("param", new ArrayList())); this.mainClassName = params.getString("mainClass", "net.minecraft.client.Minecraft"); @@ -99,10 +100,12 @@ public abstract class AbstractLauncher implements Launcher { this.width = Integer.parseInt(sizePair[0]); this.height = Integer.parseInt(sizePair[1]); } catch (NumberFormatException e) { - throw new ParseException(String.format("Could not parse window parameters from '%s'", windowParams), e); + throw new ParseException(String.format("Could not parse window parameters from '%s'", windowParams), + e); } } else { - throw new ParseException(String.format("Invalid window size parameters '%s'. Format: [height]x[width]", windowParams)); + throw new ParseException( + String.format("Invalid window size parameters '%s'. Format: [height]x[width]", windowParams)); } } else { this.width = DEFAULT_WINDOW_WIDTH; diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java index d5b7961a..e7b4599b 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java @@ -66,16 +66,13 @@ import java.util.List; public final class StandardLauncher extends AbstractLauncher { - public StandardLauncher(Parameters params) { - super(params); - } + public StandardLauncher(Parameters params) { super(params); } - public static LauncherProvider getProvider() { - return new StandardLauncherProvider(); - } + public static LauncherProvider getProvider() { return new StandardLauncherProvider(); } @Override - public void launch() throws Throwable { + public void launch() throws Throwable + { // window size, title and state // FIXME: there is no good way to maximize the minecraft window from here. @@ -104,9 +101,7 @@ public final class StandardLauncher extends AbstractLauncher { private static class StandardLauncherProvider implements LauncherProvider { @Override - public Launcher provide(Parameters parameters) { - return new StandardLauncher(parameters); - } + public Launcher provide(Parameters parameters) { return new StandardLauncher(parameters); } } } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java index 96b422b2..3cc10238 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java @@ -82,7 +82,8 @@ public final class LegacyFrame extends Frame /* TODO consider JFrame */ { private final Launcher launcher; - public LegacyFrame(String title, Applet applet) { + public LegacyFrame(String title, Applet applet) + { super(title); launcher = new Launcher(applet); @@ -98,35 +99,24 @@ public final class LegacyFrame extends Frame /* TODO consider JFrame */ { addWindowListener(new ForceExitHandler()); } - public void start ( - String user, - String session, - int width, - int height, - boolean maximize, - String serverAddress, - String serverPort, - boolean isDemo - ) { - // Implements support for launching in to multiplayer on classic servers using a mpticket - // file generated by an external program and stored in the instance's root folder. + public void start(String user, String session, int width, int height, boolean maximize, String serverAddress, + String serverPort, boolean isDemo) + { + // Implements support for launching in to multiplayer on classic servers using a + // mpticket + // file generated by an external program and stored in the instance's root + // folder. - Path mpticketFile = - Paths.get(System.getProperty("user.dir"), "..", "mpticket"); + Path mpticketFile = Paths.get(System.getProperty("user.dir"), "..", "mpticket"); - Path mpticketFileCorrupt = - Paths.get(System.getProperty("user.dir"), "..", "mpticket.corrupt"); + Path mpticketFileCorrupt = Paths.get(System.getProperty("user.dir"), "..", "mpticket.corrupt"); if (Files.exists(mpticketFile)) { try { List lines = Files.readAllLines(mpticketFile, StandardCharsets.UTF_8); if (lines.size() < 3) { - Files.move( - mpticketFile, - mpticketFileCorrupt, - StandardCopyOption.REPLACE_EXISTING - ); + Files.move(mpticketFile, mpticketFileCorrupt, StandardCopyOption.REPLACE_EXISTING); LOGGER.warning("Mpticket file is corrupted!"); } else { @@ -175,10 +165,12 @@ public final class LegacyFrame extends Frame /* TODO consider JFrame */ { private final class ForceExitHandler extends WindowAdapter { @Override - public void windowClosing(WindowEvent event) { + public void windowClosing(WindowEvent event) + { new Thread(new Runnable() { @Override - public void run() { + public void run() + { try { Thread.sleep(30000L); } catch (InterruptedException e) { diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java index b7109962..5395acec 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java @@ -83,7 +83,8 @@ public final class LegacyLauncher extends AbstractLauncher { private final boolean usesApplet; private final String cwd; - public LegacyLauncher(Parameters params) { + public LegacyLauncher(Parameters params) + { super(params); user = params.getString("userName"); @@ -97,12 +98,11 @@ public final class LegacyLauncher extends AbstractLauncher { cwd = System.getProperty("user.dir"); } - public static LauncherProvider getProvider() { - return new LegacyLauncherProvider(); - } + public static LauncherProvider getProvider() { return new LegacyLauncherProvider(); } @Override - public void launch() throws Throwable { + public void launch() throws Throwable + { Class main = ClassLoader.getSystemClassLoader().loadClass(this.mainClassName); Field gameDirField = ReflectionUtils.getMinecraftGameDirField(main); @@ -119,13 +119,8 @@ public final class LegacyLauncher extends AbstractLauncher { try { LegacyFrame window = new LegacyFrame(title, ReflectionUtils.createAppletClass(this.appletClass)); - window.start( - this.user, - this.session, - this.width, this.height, this.maximize, - this.serverAddress, this.serverPort, - this.mcParams.contains("--demo") - ); + window.start(this.user, this.session, this.width, this.height, this.maximize, this.serverAddress, + this.serverPort, this.mcParams.contains("--demo")); } catch (Throwable e) { LOGGER.log(Level.SEVERE, "Running applet wrapper failed with exception; falling back to main class", e); } @@ -137,9 +132,7 @@ public final class LegacyLauncher extends AbstractLauncher { private static class LegacyLauncherProvider implements LauncherProvider { @Override - public Launcher provide(Parameters parameters) { - return new LegacyLauncher(parameters); - } + public Launcher provide(Parameters parameters) { return new LegacyLauncher(parameters); } } } diff --git a/libraries/launcher/org/prismlauncher/utils/Parameters.java b/libraries/launcher/org/prismlauncher/utils/Parameters.java index d019aa41..3378775f 100644 --- a/libraries/launcher/org/prismlauncher/utils/Parameters.java +++ b/libraries/launcher/org/prismlauncher/utils/Parameters.java @@ -68,7 +68,8 @@ public final class Parameters { private final Map> map = new HashMap<>(); - public void add(String key, String value) { + public void add(String key, String value) + { List params = map.get(key); if (params == null) { @@ -80,7 +81,8 @@ public final class Parameters { params.add(value); } - public List getList(String key) throws ParameterNotFoundException { + public List getList(String key) throws ParameterNotFoundException + { List params = map.get(key); if (params == null) @@ -89,7 +91,8 @@ public final class Parameters { return params; } - public List getList(String key, List def) { + public List getList(String key, List def) + { List params = map.get(key); if (params == null || params.isEmpty()) @@ -98,7 +101,8 @@ public final class Parameters { return params; } - public String getString(String key) throws ParameterNotFoundException { + public String getString(String key) throws ParameterNotFoundException + { List list = getList(key); if (list.isEmpty()) @@ -107,7 +111,8 @@ public final class Parameters { return list.get(0); } - public String getString(String key, String def) { + public String getString(String key, String def) + { List params = map.get(key); if (params == null || params.isEmpty()) diff --git a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java index ad9e57fd..6e882387 100644 --- a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java @@ -38,7 +38,6 @@ package org.prismlauncher.utils; - import java.applet.Applet; import java.io.File; import java.lang.invoke.MethodHandle; @@ -53,8 +52,7 @@ public final class ReflectionUtils { private static final Logger LOGGER = Logger.getLogger("ReflectionUtils"); - private ReflectionUtils() { - } + private ReflectionUtils() {} /** * Instantiate an applet class by name @@ -65,13 +63,16 @@ public final class ReflectionUtils { * * @throws ClassNotFoundException if the provided class name cannot be found * @throws NoSuchMethodException if the no-args constructor cannot be found - * @throws IllegalAccessException if the constructor cannot be accessed via method handles + * @throws IllegalAccessException if the constructor cannot be accessed via + * method handles * @throws Throwable any exceptions from the class's constructor */ - public static Applet createAppletClass(String appletClassName) throws Throwable { + public static Applet createAppletClass(String appletClassName) throws Throwable + { Class appletClass = ClassLoader.getSystemClassLoader().loadClass(appletClassName); - MethodHandle appletConstructor = MethodHandles.lookup().findConstructor(appletClass, MethodType.methodType(void.class)); + MethodHandle appletConstructor = MethodHandles.lookup().findConstructor(appletClass, + MethodType.methodType(void.class)); return (Applet) appletConstructor.invoke(); } @@ -82,7 +83,8 @@ public final class ReflectionUtils { * * @return The found field. */ - public static Field getMinecraftGameDirField(Class minecraftMainClass) { + public static Field getMinecraftGameDirField(Class minecraftMainClass) + { LOGGER.fine("Resolving minecraft game directory field"); // Field we're looking for is always // private static File obfuscatedName = null; @@ -94,7 +96,6 @@ public final class ReflectionUtils { int fieldModifiers = field.getModifiers(); - // Must be static if (!Modifier.isStatic(fieldModifiers)) { LOGGER.log(Level.FINE, "Rejecting field {0} because it is not static", field.getName()); @@ -113,7 +114,8 @@ public final class ReflectionUtils { continue; } - LOGGER.log(Level.FINE, "Identified field {0} to match conditions for minecraft game directory field", field.getName()); + LOGGER.log(Level.FINE, "Identified field {0} to match conditions for minecraft game directory field", + field.getName()); return field; } @@ -124,8 +126,7 @@ public final class ReflectionUtils { /** * Resolve main entrypoint and returns method handle for it. *

- * Resolves a method that matches the following signature - * + * Resolves a method that matches the following signature * public static void main(String[] args) { *

* } @@ -135,34 +136,39 @@ public final class ReflectionUtils { * * @return The method handle for the resolved entrypoint * - * @throws NoSuchMethodException If no method matching the correct signature can be found + * @throws NoSuchMethodException If no method matching the correct signature + * can be found * @throws IllegalAccessException If method handles cannot access the entrypoint */ - public static MethodHandle findMainEntrypoint(Class entrypointClass) throws NoSuchMethodException, IllegalAccessException { - return MethodHandles.lookup().findStatic(entrypointClass, "main", MethodType.methodType(void.class, String[].class)); + public static MethodHandle findMainEntrypoint(Class entrypointClass) + throws NoSuchMethodException, IllegalAccessException + { + return MethodHandles.lookup().findStatic(entrypointClass, "main", + MethodType.methodType(void.class, String[].class)); } /** * Resolve main entrypoint and returns method handle for it. *

- * Resolves a method that matches the following signature - * + * Resolves a method that matches the following signature * public static void main(String[] args) { *

* } * * - * @param entrypointClassName The name of the entrypoint class to resolve the method from + * @param entrypointClassName The name of the entrypoint class to resolve the + * method from * * @return The method handle for the resolved entrypoint * - * @throws ClassNotFoundException If a class cannot be found with the provided name - * @throws NoSuchMethodException If no method matching the correct signature can be found + * @throws ClassNotFoundException If a class cannot be found with the provided + * name + * @throws NoSuchMethodException If no method matching the correct signature + * can be found * @throws IllegalAccessException If method handles cannot access the entrypoint */ public static MethodHandle findMainMethod(String entrypointClassName) - throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException { - return findMainEntrypoint(ClassLoader.getSystemClassLoader().loadClass(entrypointClassName)); - } + throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException + { return findMainEntrypoint(ClassLoader.getSystemClassLoader().loadClass(entrypointClassName)); } } diff --git a/libraries/launcher/org/prismlauncher/utils/StringUtils.java b/libraries/launcher/org/prismlauncher/utils/StringUtils.java index a371b0cb..08e6770e 100644 --- a/libraries/launcher/org/prismlauncher/utils/StringUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/StringUtils.java @@ -38,10 +38,10 @@ package org.prismlauncher.utils; public final class StringUtils { - private StringUtils() { - } + private StringUtils() {} - public static String[] splitStringPair(char splitChar, String input) { + public static String[] splitStringPair(char splitChar, String input) + { int splitPoint = input.indexOf(splitChar); if (splitPoint == -1) return null; From 404796d4b25902bf5312202e2ecbb97729b4c480 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Thu, 3 Nov 2022 17:33:21 +0000 Subject: [PATCH 22/52] Sorry for reverting a lot but copying a list just hurts me Signed-off-by: TheKodeToad --- .../launcher/impl/AbstractLauncher.java | 2 +- .../launcher/impl/StandardLauncher.java | 20 +++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java index 9eda8caf..391f71a9 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java @@ -82,7 +82,7 @@ public abstract class AbstractLauncher implements Launcher { protected AbstractLauncher(Parameters params) { - this.mcParams = Collections.unmodifiableList(params.getList("param", new ArrayList())); + this.mcParams = params.getList("param", new ArrayList()); this.mainClassName = params.getString("mainClass", "net.minecraft.client.Minecraft"); this.serverAddress = params.getString("serverAddress", null); diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java index e7b4599b..8ecfffb4 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java @@ -79,24 +79,22 @@ public final class StandardLauncher extends AbstractLauncher { // the following often breaks linux screen setups // mcparams.add("--fullscreen"); - List launchParameters = new ArrayList<>(this.mcParams); - if (!this.maximize) { - launchParameters.add("--width"); - launchParameters.add(Integer.toString(width)); - launchParameters.add("--height"); - launchParameters.add(Integer.toString(height)); + mcParams.add("--width"); + mcParams.add(Integer.toString(width)); + mcParams.add("--height"); + mcParams.add(Integer.toString(height)); } if (this.serverAddress != null) { - launchParameters.add("--server"); - launchParameters.add(serverAddress); - launchParameters.add("--port"); - launchParameters.add(serverPort); + mcParams.add("--server"); + mcParams.add(serverAddress); + mcParams.add("--port"); + mcParams.add(serverPort); } MethodHandle method = ReflectionUtils.findMainMethod(this.mainClassName); - method.invokeExact(launchParameters.toArray(new String[0])); + method.invokeExact(mcParams.toArray(new String[0])); } private static class StandardLauncherProvider implements LauncherProvider { From fb677a7489201163de7d8ad1960ba8404a8f8a10 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Thu, 3 Nov 2022 17:45:37 +0000 Subject: [PATCH 23/52] So turns out we can have nice things Signed-off-by: TheKodeToad --- .../org/prismlauncher/launcher/impl/AbstractLauncher.java | 1 - .../org/prismlauncher/launcher/impl/StandardLauncher.java | 2 -- .../org/prismlauncher/launcher/impl/legacy/LegacyFrame.java | 4 +++- .../prismlauncher/launcher/impl/legacy/LegacyLauncher.java | 2 ++ 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java index 391f71a9..7677df56 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java @@ -62,7 +62,6 @@ import org.prismlauncher.utils.Parameters; import org.prismlauncher.utils.StringUtils; import java.util.ArrayList; -import java.util.Collections; import java.util.List; public abstract class AbstractLauncher implements Launcher { diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java index 8ecfffb4..40a35473 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java @@ -61,8 +61,6 @@ import org.prismlauncher.utils.Parameters; import org.prismlauncher.utils.ReflectionUtils; import java.lang.invoke.MethodHandle; -import java.util.ArrayList; -import java.util.List; public final class StandardLauncher extends AbstractLauncher { diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java index 3cc10238..8f468cf6 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java @@ -60,6 +60,8 @@ package org.prismlauncher.launcher.impl.legacy; import net.minecraft.Launcher; import javax.imageio.ImageIO; +import javax.swing.JFrame; + import java.applet.Applet; import java.awt.Dimension; import java.awt.Frame; @@ -76,7 +78,7 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -public final class LegacyFrame extends Frame /* TODO consider JFrame */ { +public final class LegacyFrame extends JFrame { private static final Logger LOGGER = Logger.getLogger("LegacyFrame"); diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java index 5395acec..4defa8f3 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java @@ -121,6 +121,8 @@ public final class LegacyLauncher extends AbstractLauncher { window.start(this.user, this.session, this.width, this.height, this.maximize, this.serverAddress, this.serverPort, this.mcParams.contains("--demo")); + + return; } catch (Throwable e) { LOGGER.log(Level.SEVERE, "Running applet wrapper failed with exception; falling back to main class", e); } From 1da834f6507a8c494d38159208471afd5c9a877e Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Thu, 3 Nov 2022 17:50:54 +0000 Subject: [PATCH 24/52] *opinionated change* Remove LauncherFactory Factories in OOP are a classic example of over-enginneering. When you only have two launchers I personally think that it's not very useful. Signed-off-by: TheKodeToad --- libraries/launcher/CMakeLists.txt | 2 - .../org/prismlauncher/EntryPoint.java | 17 ++++- .../launcher/LauncherFactory.java | 76 ------------------- .../launcher/LauncherProvider.java | 46 ----------- .../launcher/impl/StandardLauncher.java | 9 --- .../launcher/impl/legacy/LegacyFrame.java | 1 - .../launcher/impl/legacy/LegacyLauncher.java | 9 --- 7 files changed, 15 insertions(+), 145 deletions(-) delete mode 100644 libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java delete mode 100644 libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java diff --git a/libraries/launcher/CMakeLists.txt b/libraries/launcher/CMakeLists.txt index 45a43b93..297ea27f 100644 --- a/libraries/launcher/CMakeLists.txt +++ b/libraries/launcher/CMakeLists.txt @@ -9,8 +9,6 @@ set(CMAKE_JAVA_COMPILE_FLAGS -target 7 -source 7 -Xlint:deprecation -Xlint:unche set(SRC org/prismlauncher/EntryPoint.java org/prismlauncher/launcher/Launcher.java - org/prismlauncher/launcher/LauncherFactory.java - org/prismlauncher/launcher/LauncherProvider.java org/prismlauncher/launcher/impl/legacy/LegacyFrame.java org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java org/prismlauncher/launcher/impl/AbstractLauncher.java diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index 88d5d8be..c33ab983 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -57,7 +57,8 @@ package org.prismlauncher; import org.prismlauncher.exception.ParseException; import org.prismlauncher.launcher.Launcher; -import org.prismlauncher.launcher.LauncherFactory; +import org.prismlauncher.launcher.impl.StandardLauncher; +import org.prismlauncher.launcher.impl.legacy.LegacyLauncher; import org.prismlauncher.utils.Parameters; import org.prismlauncher.utils.StringUtils; @@ -137,7 +138,19 @@ public final class EntryPoint { } try { - Launcher launcher = LauncherFactory.createLauncher(parameters); + Launcher launcher; + String type = parameters.getString("launcher"); + + switch (type) { + case "standard": + launcher = new StandardLauncher(parameters); + break; + case "legacy": + launcher = new LegacyLauncher(parameters); + break; + default: + throw new IllegalArgumentException("Invalid launcher type: " + type); + } launcher.launch(); diff --git a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java deleted file mode 100644 index 1f7ea91b..00000000 --- a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java +++ /dev/null @@ -1,76 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -/* - * Prism Launcher - * - * Copyright (C) 2022 icelimetea - * Copyright (C) 2022 Sefa Eyeoglu - * Copyright (C) 2022 Samisafool - * Copyright (C) 2022 TheKodeToad - * Copyright (C) 2022 solonovamax - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Linking this library statically or dynamically with other modules is - * making a combined work based on this library. Thus, the terms and - * conditions of the GNU General Public License cover the whole - * combination. - * - * As a special exception, the copyright holders of this library give - * you permission to link this library with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also meet, - * for each linked independent module, the terms and conditions of the - * license of that module. An independent module is a module which is - * not derived from or based on this library. If you modify this - * library, you may extend this exception to your version of the - * library, but you are not obliged to do so. If you do not wish to do - * so, delete this exception statement from your version. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.prismlauncher.launcher; - -import org.prismlauncher.launcher.impl.StandardLauncher; -import org.prismlauncher.launcher.impl.legacy.LegacyLauncher; -import org.prismlauncher.utils.Parameters; - -public final class LauncherFactory { - - private LauncherFactory() - {} - - public static Launcher createLauncher(String launcherType, Parameters parameters) - { return createLauncher(LauncherType.valueOf(launcherType.toUpperCase()), parameters); } - - public static Launcher createLauncher(LauncherType launcherType, Parameters parameters) - { - LauncherProvider launcherProvider = launcherType.getLauncherProvider(); - - return launcherProvider.provide(parameters); - } - - public static Launcher createLauncher(Parameters parameters) - { return createLauncher(parameters.getString("launcher"), parameters); } - - public enum LauncherType { - STANDARD(StandardLauncher.getProvider()), LEGACY(LegacyLauncher.getProvider()); - - private final LauncherProvider launcherProvider; - - LauncherType(LauncherProvider launcherProvider) { this.launcherProvider = launcherProvider; } - - public LauncherProvider getLauncherProvider() { return launcherProvider; } - - } - -} diff --git a/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java b/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java deleted file mode 100644 index 73d0cdc5..00000000 --- a/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java +++ /dev/null @@ -1,46 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -/* - * Prism Launcher - * - * Copyright (C) 2022 icelimetea - * Copyright (C) 2022 solonovamax - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Linking this library statically or dynamically with other modules is - * making a combined work based on this library. Thus, the terms and - * conditions of the GNU General Public License cover the whole - * combination. - * - * As a special exception, the copyright holders of this library give - * you permission to link this library with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also meet, - * for each linked independent module, the terms and conditions of the - * license of that module. An independent module is a module which is - * not derived from or based on this library. If you modify this - * library, you may extend this exception to your version of the - * library, but you are not obliged to do so. If you do not wish to do - * so, delete this exception statement from your version. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.prismlauncher.launcher; - -import org.prismlauncher.utils.Parameters; - -public interface LauncherProvider { - - Launcher provide(Parameters parameters); - -} diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java index 40a35473..43d706d6 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java @@ -55,8 +55,6 @@ package org.prismlauncher.launcher.impl; -import org.prismlauncher.launcher.Launcher; -import org.prismlauncher.launcher.LauncherProvider; import org.prismlauncher.utils.Parameters; import org.prismlauncher.utils.ReflectionUtils; @@ -66,8 +64,6 @@ public final class StandardLauncher extends AbstractLauncher { public StandardLauncher(Parameters params) { super(params); } - public static LauncherProvider getProvider() { return new StandardLauncherProvider(); } - @Override public void launch() throws Throwable { @@ -95,9 +91,4 @@ public final class StandardLauncher extends AbstractLauncher { method.invokeExact(mcParams.toArray(new String[0])); } - private static class StandardLauncherProvider implements LauncherProvider { - @Override - public Launcher provide(Parameters parameters) { return new StandardLauncher(parameters); } - } - } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java index 8f468cf6..198fb61a 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java @@ -64,7 +64,6 @@ import javax.swing.JFrame; import java.applet.Applet; import java.awt.Dimension; -import java.awt.Frame; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java index 4defa8f3..aa899a61 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java @@ -56,8 +56,6 @@ package org.prismlauncher.launcher.impl.legacy; -import org.prismlauncher.launcher.Launcher; -import org.prismlauncher.launcher.LauncherProvider; import org.prismlauncher.launcher.impl.AbstractLauncher; import org.prismlauncher.utils.Parameters; import org.prismlauncher.utils.ReflectionUtils; @@ -98,8 +96,6 @@ public final class LegacyLauncher extends AbstractLauncher { cwd = System.getProperty("user.dir"); } - public static LauncherProvider getProvider() { return new LegacyLauncherProvider(); } - @Override public void launch() throws Throwable { @@ -132,9 +128,4 @@ public final class LegacyLauncher extends AbstractLauncher { method.invokeExact(mcParams.toArray(new String[0])); } - private static class LegacyLauncherProvider implements LauncherProvider { - @Override - public Launcher provide(Parameters parameters) { return new LegacyLauncher(parameters); } - } - } From 9931c9a286c1746c1fb290da50ab31c9d7c7d228 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Thu, 3 Nov 2022 18:11:42 +0000 Subject: [PATCH 25/52] Remove arguments being passed twice Passing the classpath into stdin has no effect. Java is already provided the classpath with -cp, which pretty much takes up the largest part of the arguments anyway, which leads me to wonder, what's the point of stdin arguments at all? Signed-off-by: TheKodeToad --- launcher/minecraft/MinecraftInstance.cpp | 15 --------------- .../launcher/org/prismlauncher/EntryPoint.java | 2 +- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index 5a5245ed..39a7198c 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -629,21 +629,6 @@ QString MinecraftInstance::createLaunchScript(AuthSessionPtr session, MinecraftS launchScript += "sessionId " + session->session + "\n"; } - // libraries and class path. - { - QStringList jars, nativeJars; - profile->getLibraryFiles(runtimeContext(), jars, nativeJars, getLocalLibraryPath(), binRoot()); - for(auto file: jars) - { - launchScript += "cp " + file + "\n"; - } - for(auto file: nativeJars) - { - launchScript += "ext " + file + "\n"; - } - launchScript += "natives " + getNativePath() + "\n"; - } - for (auto trait : profile->getTraits()) { launchScript += "traits " + trait + "\n"; diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index c33ab983..36831179 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -81,7 +81,6 @@ public final class EntryPoint { if (exitCode != ExitCode.NORMAL) { LOGGER.warning("Exiting with " + exitCode); - // noinspection CallToSystemExit System.exit(exitCode.numericalCode); } } @@ -97,6 +96,7 @@ public final class EntryPoint { return PreLaunchAction.ABORT; else { String[] pair = StringUtils.splitStringPair(' ', input); + if (pair == null) throw new ParseException(String.format( "Could not split input string '%s' by space. All input provided from stdin must be either 'launch', 'abort', or " From 5912ef3b452b2c28693630249052fe23c790f6fb Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Thu, 3 Nov 2022 18:17:11 +0000 Subject: [PATCH 26/52] Just ignore empty lines Signed-off-by: TheKodeToad --- libraries/launcher/org/prismlauncher/EntryPoint.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index 36831179..06c6c79c 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -87,8 +87,8 @@ public final class EntryPoint { private static PreLaunchAction parseLine(String input, Parameters params) throws ParseException { - if (input.isEmpty()) // TODO: 2022-11-01 Should we just ignore this? - throw new ParseException("Unexpected empty string! You should not pass empty newlines to stdin."); + if (input.isEmpty()) + return PreLaunchAction.PROCEED; if ("launch".equalsIgnoreCase(input)) return PreLaunchAction.LAUNCH; From 4abf3a20c6fe3763e57b76ec873cc2355d067b90 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Thu, 3 Nov 2022 18:39:34 +0000 Subject: [PATCH 27/52] More standard code formatting profile Signed-off-by: TheKodeToad --- libraries/launcher/formatting-profile.xml | 6 +- .../launcher/net/minecraft/Launcher.java | 62 +++++++++++-------- .../org/prismlauncher/EntryPoint.java | 17 ++--- .../launcher/impl/AbstractLauncher.java | 3 +- .../launcher/impl/StandardLauncher.java | 7 ++- .../launcher/impl/legacy/LegacyFrame.java | 12 ++-- .../launcher/impl/legacy/LegacyLauncher.java | 6 +- .../org/prismlauncher/utils/Parameters.java | 15 ++--- .../prismlauncher/utils/ReflectionUtils.java | 17 +++-- .../org/prismlauncher/utils/StringUtils.java | 6 +- 10 files changed, 75 insertions(+), 76 deletions(-) diff --git a/libraries/launcher/formatting-profile.xml b/libraries/launcher/formatting-profile.xml index bebc783e..1b334838 100644 --- a/libraries/launcher/formatting-profile.xml +++ b/libraries/launcher/formatting-profile.xml @@ -246,11 +246,11 @@ - + - + @@ -262,7 +262,7 @@ - + diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java index ce9b59d4..3bd38e77 100644 --- a/libraries/launcher/net/minecraft/Launcher.java +++ b/libraries/launcher/net/minecraft/Launcher.java @@ -81,10 +81,11 @@ public final class Launcher extends Applet implements AppletStub { private final URL documentBase; private boolean active = false; - public Launcher(Applet applet) { this(applet, null); } + public Launcher(Applet applet) { + this(applet, null); + } - public Launcher(Applet applet, URL documentBase) - { + public Launcher(Applet applet, URL documentBase) { setLayout(new BorderLayout()); this.add(applet, "Center"); @@ -108,8 +109,7 @@ public final class Launcher extends Applet implements AppletStub { } } - public void replace(Applet applet) - { + public void replace(Applet applet) { wrappedApplet = applet; applet.setStub(this); @@ -128,14 +128,17 @@ public final class Launcher extends Applet implements AppletStub { } @Override - public boolean isActive() { return active; } + public boolean isActive() { + return active; + } @Override - public URL getDocumentBase() { return documentBase; } + public URL getDocumentBase() { + return documentBase; + } @Override - public URL getCodeBase() - { + public URL getCodeBase() { try { // TODO: 2022-10-27 Can this be changed to https? return new URL("http://www.minecraft.net/game/"); @@ -145,8 +148,7 @@ public final class Launcher extends Applet implements AppletStub { } @Override - public String getParameter(String name) - { + public String getParameter(String name) { String param = params.get(name); if (param != null) @@ -161,54 +163,62 @@ public final class Launcher extends Applet implements AppletStub { } @Override - public void resize(int width, int height) { wrappedApplet.resize(width, height); } + public void resize(int width, int height) { + wrappedApplet.resize(width, height); + } @Override - public void resize(Dimension size) { wrappedApplet.resize(size); } + public void resize(Dimension size) { + wrappedApplet.resize(size); + } @Override - public void init() - { + public void init() { if (wrappedApplet != null) wrappedApplet.init(); } @Override - public void start() - { + public void start() { wrappedApplet.start(); active = true; } @Override - public void stop() - { + public void stop() { wrappedApplet.stop(); active = false; } @Override - public void destroy() { wrappedApplet.destroy(); } + public void destroy() { + wrappedApplet.destroy(); + } @Override - public void appletResize(int width, int height) { wrappedApplet.resize(width, height); } + public void appletResize(int width, int height) { + wrappedApplet.resize(width, height); + } @Override - public void setVisible(boolean visible) - { + public void setVisible(boolean visible) { super.setVisible(visible); wrappedApplet.setVisible(visible); } @Override - public void paint(Graphics graphics) {} + public void paint(Graphics graphics) { + } @Override - public void update(Graphics graphics) {} + public void update(Graphics graphics) { + } - public void setParameter(String name, String value) { params.put(name, value); } + public void setParameter(String name, String value) { + params.put(name, value); + } } diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index 06c6c79c..5332bfc7 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -72,10 +72,10 @@ import java.util.logging.Logger; public final class EntryPoint { private static final Logger LOGGER = Logger.getLogger("EntryPoint"); - private EntryPoint() {} + private EntryPoint() { + } - public static void main(String[] args) - { + public static void main(String[] args) { ExitCode exitCode = listen(); if (exitCode != ExitCode.NORMAL) { @@ -85,8 +85,7 @@ public final class EntryPoint { } } - private static PreLaunchAction parseLine(String input, Parameters params) throws ParseException - { + private static PreLaunchAction parseLine(String input, Parameters params) throws ParseException { if (input.isEmpty()) return PreLaunchAction.PROCEED; @@ -109,8 +108,7 @@ public final class EntryPoint { } } - private static ExitCode listen() - { + private static ExitCode listen() { Parameters parameters = new Parameters(); PreLaunchAction preLaunchAction = PreLaunchAction.PROCEED; @@ -179,7 +177,10 @@ public final class EntryPoint { private final int numericalCode; - ExitCode(int numericalCode) { this.numericalCode = numericalCode; } + ExitCode(int numericalCode) { + this.numericalCode = numericalCode; + } + } } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java index 7677df56..938e3403 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java @@ -79,8 +79,7 @@ public abstract class AbstractLauncher implements Launcher { protected final String mainClassName; - protected AbstractLauncher(Parameters params) - { + protected AbstractLauncher(Parameters params) { this.mcParams = params.getList("param", new ArrayList()); this.mainClassName = params.getString("mainClass", "net.minecraft.client.Minecraft"); diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java index 43d706d6..0652cbae 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java @@ -62,11 +62,12 @@ import java.lang.invoke.MethodHandle; public final class StandardLauncher extends AbstractLauncher { - public StandardLauncher(Parameters params) { super(params); } + public StandardLauncher(Parameters params) { + super(params); + } @Override - public void launch() throws Throwable - { + public void launch() throws Throwable { // window size, title and state // FIXME: there is no good way to maximize the minecraft window from here. diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java index 198fb61a..d2496fa9 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java @@ -83,8 +83,7 @@ public final class LegacyFrame extends JFrame { private final Launcher launcher; - public LegacyFrame(String title, Applet applet) - { + public LegacyFrame(String title, Applet applet) { super(title); launcher = new Launcher(applet); @@ -101,8 +100,7 @@ public final class LegacyFrame extends JFrame { } public void start(String user, String session, int width, int height, boolean maximize, String serverAddress, - String serverPort, boolean isDemo) - { + String serverPort, boolean isDemo) { // Implements support for launching in to multiplayer on classic servers using a // mpticket // file generated by an external program and stored in the instance's root @@ -166,12 +164,10 @@ public final class LegacyFrame extends JFrame { private final class ForceExitHandler extends WindowAdapter { @Override - public void windowClosing(WindowEvent event) - { + public void windowClosing(WindowEvent event) { new Thread(new Runnable() { @Override - public void run() - { + public void run() { try { Thread.sleep(30000L); } catch (InterruptedException e) { diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java index aa899a61..953f83d9 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java @@ -81,8 +81,7 @@ public final class LegacyLauncher extends AbstractLauncher { private final boolean usesApplet; private final String cwd; - public LegacyLauncher(Parameters params) - { + public LegacyLauncher(Parameters params) { super(params); user = params.getString("userName"); @@ -97,8 +96,7 @@ public final class LegacyLauncher extends AbstractLauncher { } @Override - public void launch() throws Throwable - { + public void launch() throws Throwable { Class main = ClassLoader.getSystemClassLoader().loadClass(this.mainClassName); Field gameDirField = ReflectionUtils.getMinecraftGameDirField(main); diff --git a/libraries/launcher/org/prismlauncher/utils/Parameters.java b/libraries/launcher/org/prismlauncher/utils/Parameters.java index 3378775f..d019aa41 100644 --- a/libraries/launcher/org/prismlauncher/utils/Parameters.java +++ b/libraries/launcher/org/prismlauncher/utils/Parameters.java @@ -68,8 +68,7 @@ public final class Parameters { private final Map> map = new HashMap<>(); - public void add(String key, String value) - { + public void add(String key, String value) { List params = map.get(key); if (params == null) { @@ -81,8 +80,7 @@ public final class Parameters { params.add(value); } - public List getList(String key) throws ParameterNotFoundException - { + public List getList(String key) throws ParameterNotFoundException { List params = map.get(key); if (params == null) @@ -91,8 +89,7 @@ public final class Parameters { return params; } - public List getList(String key, List def) - { + public List getList(String key, List def) { List params = map.get(key); if (params == null || params.isEmpty()) @@ -101,8 +98,7 @@ public final class Parameters { return params; } - public String getString(String key) throws ParameterNotFoundException - { + public String getString(String key) throws ParameterNotFoundException { List list = getList(key); if (list.isEmpty()) @@ -111,8 +107,7 @@ public final class Parameters { return list.get(0); } - public String getString(String key, String def) - { + public String getString(String key, String def) { List params = map.get(key); if (params == null || params.isEmpty()) diff --git a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java index 6e882387..99df70c3 100644 --- a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java @@ -52,7 +52,8 @@ public final class ReflectionUtils { private static final Logger LOGGER = Logger.getLogger("ReflectionUtils"); - private ReflectionUtils() {} + private ReflectionUtils() { + } /** * Instantiate an applet class by name @@ -67,8 +68,7 @@ public final class ReflectionUtils { * method handles * @throws Throwable any exceptions from the class's constructor */ - public static Applet createAppletClass(String appletClassName) throws Throwable - { + public static Applet createAppletClass(String appletClassName) throws Throwable { Class appletClass = ClassLoader.getSystemClassLoader().loadClass(appletClassName); MethodHandle appletConstructor = MethodHandles.lookup().findConstructor(appletClass, @@ -83,8 +83,7 @@ public final class ReflectionUtils { * * @return The found field. */ - public static Field getMinecraftGameDirField(Class minecraftMainClass) - { + public static Field getMinecraftGameDirField(Class minecraftMainClass) { LOGGER.fine("Resolving minecraft game directory field"); // Field we're looking for is always // private static File obfuscatedName = null; @@ -141,8 +140,7 @@ public final class ReflectionUtils { * @throws IllegalAccessException If method handles cannot access the entrypoint */ public static MethodHandle findMainEntrypoint(Class entrypointClass) - throws NoSuchMethodException, IllegalAccessException - { + throws NoSuchMethodException, IllegalAccessException { return MethodHandles.lookup().findStatic(entrypointClass, "main", MethodType.methodType(void.class, String[].class)); } @@ -168,7 +166,8 @@ public final class ReflectionUtils { * @throws IllegalAccessException If method handles cannot access the entrypoint */ public static MethodHandle findMainMethod(String entrypointClassName) - throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException - { return findMainEntrypoint(ClassLoader.getSystemClassLoader().loadClass(entrypointClassName)); } + throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException { + return findMainEntrypoint(ClassLoader.getSystemClassLoader().loadClass(entrypointClassName)); + } } diff --git a/libraries/launcher/org/prismlauncher/utils/StringUtils.java b/libraries/launcher/org/prismlauncher/utils/StringUtils.java index 08e6770e..a371b0cb 100644 --- a/libraries/launcher/org/prismlauncher/utils/StringUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/StringUtils.java @@ -38,10 +38,10 @@ package org.prismlauncher.utils; public final class StringUtils { - private StringUtils() {} + private StringUtils() { + } - public static String[] splitStringPair(char splitChar, String input) - { + public static String[] splitStringPair(char splitChar, String input) { int splitPoint = input.indexOf(splitChar); if (splitPoint == -1) return null; From 56d5035c63fc3146832b1159fe4686d552da763d Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Fri, 4 Nov 2022 10:31:31 +0000 Subject: [PATCH 28/52] Fix the warnings properly Signed-off-by: TheKodeToad --- libraries/launcher/CMakeLists.txt | 2 +- libraries/launcher/org/prismlauncher/EntryPoint.java | 2 +- .../org/prismlauncher/launcher/impl/legacy/LegacyFrame.java | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/launcher/CMakeLists.txt b/libraries/launcher/CMakeLists.txt index 297ea27f..7aabefa1 100644 --- a/libraries/launcher/CMakeLists.txt +++ b/libraries/launcher/CMakeLists.txt @@ -4,7 +4,7 @@ find_package(Java 1.7 REQUIRED COMPONENTS Development) include(UseJava) set(CMAKE_JAVA_JAR_ENTRY_POINT org.prismlauncher.EntryPoint) -set(CMAKE_JAVA_COMPILE_FLAGS -target 7 -source 7 -Xlint:deprecation -Xlint:unchecked) +set(CMAKE_JAVA_COMPILE_FLAGS -target 7 -source 7) set(SRC org/prismlauncher/EntryPoint.java diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index 5332bfc7..eab31cb1 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -70,6 +70,7 @@ import java.util.logging.Level; import java.util.logging.Logger; public final class EntryPoint { + private static final Logger LOGGER = Logger.getLogger("EntryPoint"); private EntryPoint() { @@ -116,7 +117,6 @@ public final class EntryPoint { String line; while (preLaunchAction == PreLaunchAction.PROCEED) { - // noinspection NestedAssignment if ((line = reader.readLine()) != null) preLaunchAction = parseLine(line, parameters); else diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java index d2496fa9..5b43f7b2 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java @@ -80,6 +80,7 @@ import java.util.logging.Logger; public final class LegacyFrame extends JFrame { private static final Logger LOGGER = Logger.getLogger("LegacyFrame"); + private static final long serialVersionUID = 1L; private final Launcher launcher; From 922220c11e3081c6d3aaa6c664379ea398f1d67f Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Fri, 4 Nov 2022 11:00:20 +0000 Subject: [PATCH 29/52] More consistent logging text Signed-off-by: TheKodeToad --- libraries/launcher/org/prismlauncher/EntryPoint.java | 4 ++-- .../org/prismlauncher/launcher/impl/legacy/LegacyFrame.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index eab31cb1..875c14cd 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -130,7 +130,7 @@ public final class EntryPoint { // Main loop if (preLaunchAction == PreLaunchAction.ABORT) { - LOGGER.info("Launch aborted by the launcher."); + LOGGER.info("Launch aborted by the launcher"); return ExitCode.ABORT; } @@ -154,7 +154,7 @@ public final class EntryPoint { return ExitCode.NORMAL; } catch (IllegalArgumentException e) { - LOGGER.log(Level.SEVERE, "Wrong argument.", e); + LOGGER.log(Level.SEVERE, "Wrong argument", e); return ExitCode.ILLEGAL_ARGUMENT; } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException e) { diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java index 5b43f7b2..f27405b5 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java @@ -94,7 +94,7 @@ public final class LegacyFrame extends JFrame { try { setIconImage(ImageIO.read(new File("icon.png"))); } catch (IOException e) { - LOGGER.log(Level.WARNING, "Unable to read Minecraft icon!", e); + LOGGER.log(Level.WARNING, "Unable to read Minecraft icon", e); } addWindowListener(new ForceExitHandler()); From 4a2df30f92262304c63876c6428c81b70a2f4558 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Fri, 4 Nov 2022 16:11:43 +0000 Subject: [PATCH 30/52] Try to use more standard exit codes Signed-off-by: TheKodeToad --- libraries/launcher/org/prismlauncher/EntryPoint.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index 875c14cd..0fa3691d 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -160,7 +160,7 @@ public final class EntryPoint { } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException e) { LOGGER.log(Level.SEVERE, "Caught reflection exception from launcher", e); - return ExitCode.REFLECTION_EXCEPTION; + return ExitCode.ERROR; } catch (Throwable e) { LOGGER.log(Level.SEVERE, "Exception caught from launcher", e); @@ -173,7 +173,7 @@ public final class EntryPoint { } private enum ExitCode { - NORMAL(0), ABORT(1), ERROR(2), ILLEGAL_ARGUMENT(3), REFLECTION_EXCEPTION(4); + NORMAL(0), ABORT(1), ERROR(2), ILLEGAL_ARGUMENT(65); private final int numericalCode; From 1ea2e854156820ee5ba3c59d0c99fe4465566b9c Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Fri, 4 Nov 2022 16:29:19 +0000 Subject: [PATCH 31/52] Implicit is generally prefered Signed-off-by: TheKodeToad --- libraries/launcher/org/prismlauncher/EntryPoint.java | 2 +- .../launcher/org/prismlauncher/exception/ParseException.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index 0fa3691d..512b01a9 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -157,7 +157,7 @@ public final class EntryPoint { LOGGER.log(Level.SEVERE, "Wrong argument", e); return ExitCode.ILLEGAL_ARGUMENT; - } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException e) { + } catch (ReflectiveOperationException e) { LOGGER.log(Level.SEVERE, "Caught reflection exception from launcher", e); return ExitCode.ERROR; diff --git a/libraries/launcher/org/prismlauncher/exception/ParseException.java b/libraries/launcher/org/prismlauncher/exception/ParseException.java index 2fd693e7..49f5b006 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParseException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParseException.java @@ -57,7 +57,6 @@ public final class ParseException extends IllegalArgumentException { } public ParseException() { - super(); } public static ParseException forInputString(String inputString) { From 745c331311837471971152ef75f3ac12809217b6 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Fri, 4 Nov 2022 17:10:45 +0000 Subject: [PATCH 32/52] Remove last case of printStackTrace Signed-off-by: TheKodeToad --- .../org/prismlauncher/launcher/impl/legacy/LegacyFrame.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java index f27405b5..28f85aa2 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java @@ -172,7 +172,7 @@ public final class LegacyFrame extends JFrame { try { Thread.sleep(30000L); } catch (InterruptedException e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "Thread interrupted", e); } LOGGER.info("Forcing exit!"); From e6dc34fe102f183e6857744283ee86c620091d08 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Fri, 4 Nov 2022 17:18:17 +0000 Subject: [PATCH 33/52] More license fixing Signed-off-by: TheKodeToad --- .../exception/ParameterNotFoundException.java | 2 -- .../exception/ParseException.java | 2 -- .../org/prismlauncher/launcher/Launcher.java | 2 -- .../launcher/impl/AbstractLauncher.java | 1 - .../launcher/impl/legacy/LegacyFrame.java | 2 -- .../org/prismlauncher/utils/Parameters.java | 2 -- .../prismlauncher/utils/ReflectionUtils.java | 19 ++++++++++++++++++- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java index ad973ace..52c2a368 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java @@ -3,8 +3,6 @@ * Prism Launcher * * Copyright (C) 2022 icelimetea - * Copyright (C) 2022 Sefa Eyeoglu - * Copyright (C) 2022 Samisafool * Copyright (C) 2022 solonovamax * Copyright (C) 2022 TheKodeToad * diff --git a/libraries/launcher/org/prismlauncher/exception/ParseException.java b/libraries/launcher/org/prismlauncher/exception/ParseException.java index 49f5b006..80709c56 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParseException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParseException.java @@ -3,8 +3,6 @@ * Prism Launcher * * Copyright (C) 2022 icelimetea - * Copyright (C) 2022 Sefa Eyeoglu - * Copyright (C) 2022 Samisafool * Copyright (C) 2022 solonovamax * Copyright (C) 2022 TheKodeToad * diff --git a/libraries/launcher/org/prismlauncher/launcher/Launcher.java b/libraries/launcher/org/prismlauncher/launcher/Launcher.java index d54cfd5c..1a6577e0 100644 --- a/libraries/launcher/org/prismlauncher/launcher/Launcher.java +++ b/libraries/launcher/org/prismlauncher/launcher/Launcher.java @@ -3,8 +3,6 @@ * Prism Launcher * * Copyright (C) 2022 icelimetea - * Copyright (C) 2022 Sefa Eyeoglu - * Copyright (C) 2022 Samisafool * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax * diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java index 938e3403..7ae7568c 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java @@ -3,7 +3,6 @@ * Prism Launcher * * Copyright (C) 2022 icelimetea - * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax * diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java index 28f85aa2..15da0371 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java @@ -3,9 +3,7 @@ * Prism Launcher * * Copyright (C) 2022 icelimetea - * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 flow - * Copyright (C) 2022 Samisafool * Copyright (C) 2022 TheKodeToad * * This program is free software: you can redistribute it and/or modify diff --git a/libraries/launcher/org/prismlauncher/utils/Parameters.java b/libraries/launcher/org/prismlauncher/utils/Parameters.java index d019aa41..8286bd70 100644 --- a/libraries/launcher/org/prismlauncher/utils/Parameters.java +++ b/libraries/launcher/org/prismlauncher/utils/Parameters.java @@ -3,8 +3,6 @@ * Prism Launcher * * Copyright (C) 2022 icelimetea - * Copyright (C) 2022 Sefa Eyeoglu - * Copyright (C) 2022 Samisafool * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax * diff --git a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java index 99df70c3..1d2383a4 100644 --- a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java @@ -2,9 +2,9 @@ /* * Prism Launcher * + * Copyright (C) 2022 icelimetea * Copyright (C) 2022 solonovamax * Copyright (C) 2022 TheKodeToad - * Copyright (C) 2022 icelimetea * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,6 +34,23 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.prismlauncher.utils; From d90eff64d06a668e730e8af33cec325a5bac94de Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Fri, 4 Nov 2022 17:45:33 +0000 Subject: [PATCH 34/52] Add StringUtils to CMakeLists.txt Signed-off-by: TheKodeToad --- libraries/launcher/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/launcher/CMakeLists.txt b/libraries/launcher/CMakeLists.txt index 7aabefa1..d176b1d4 100644 --- a/libraries/launcher/CMakeLists.txt +++ b/libraries/launcher/CMakeLists.txt @@ -17,6 +17,7 @@ set(SRC org/prismlauncher/exception/ParseException.java org/prismlauncher/utils/Parameters.java org/prismlauncher/utils/ReflectionUtils.java + org/prismlauncher/utils/StringUtils.java net/minecraft/Launcher.java ) add_jar(NewLaunch ${SRC}) From 50d40257fe8631338f9b6c278cc18c8ca9cab1a1 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sat, 5 Nov 2022 09:10:52 +0000 Subject: [PATCH 35/52] Always use this for consistency Signed-off-by: TheKodeToad --- .../launcher/net/minecraft/Launcher.java | 36 ++++++------- .../launcher/impl/StandardLauncher.java | 18 +++---- .../launcher/impl/legacy/LegacyFrame.java | 54 +++++++++---------- .../launcher/impl/legacy/LegacyLauncher.java | 18 +++---- .../org/prismlauncher/utils/Parameters.java | 12 ++--- 5 files changed, 69 insertions(+), 69 deletions(-) diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java index 3bd38e77..b895d5b7 100644 --- a/libraries/launcher/net/minecraft/Launcher.java +++ b/libraries/launcher/net/minecraft/Launcher.java @@ -113,28 +113,28 @@ public final class Launcher extends Applet implements AppletStub { wrappedApplet = applet; applet.setStub(this); - applet.setSize(getWidth(), getHeight()); + applet.setSize(this.getWidth(), this.getHeight()); setLayout(new BorderLayout()); this.add(applet, "Center"); applet.init(); - active = true; + this.active = true; applet.start(); - validate(); + this.validate(); } @Override public boolean isActive() { - return active; + return this.active; } @Override public URL getDocumentBase() { - return documentBase; + return this.documentBase; } @Override @@ -149,7 +149,7 @@ public final class Launcher extends Applet implements AppletStub { @Override public String getParameter(String name) { - String param = params.get(name); + String param = this.params.get(name); if (param != null) return param; @@ -164,49 +164,49 @@ public final class Launcher extends Applet implements AppletStub { @Override public void resize(int width, int height) { - wrappedApplet.resize(width, height); + this.wrappedApplet.resize(width, height); } @Override public void resize(Dimension size) { - wrappedApplet.resize(size); + this.wrappedApplet.resize(size); } @Override public void init() { - if (wrappedApplet != null) - wrappedApplet.init(); + if (this.wrappedApplet != null) + this.wrappedApplet.init(); } @Override public void start() { - wrappedApplet.start(); + this.wrappedApplet.start(); - active = true; + this.active = true; } @Override public void stop() { - wrappedApplet.stop(); + this.wrappedApplet.stop(); - active = false; + this.active = false; } @Override public void destroy() { - wrappedApplet.destroy(); + this.wrappedApplet.destroy(); } @Override public void appletResize(int width, int height) { - wrappedApplet.resize(width, height); + this.wrappedApplet.resize(width, height); } @Override public void setVisible(boolean visible) { super.setVisible(visible); - wrappedApplet.setVisible(visible); + this.wrappedApplet.setVisible(visible); } @Override @@ -218,7 +218,7 @@ public final class Launcher extends Applet implements AppletStub { } public void setParameter(String name, String value) { - params.put(name, value); + this.params.put(name, value); } } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java index 0652cbae..0f6fcf34 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java @@ -75,21 +75,21 @@ public final class StandardLauncher extends AbstractLauncher { // mcparams.add("--fullscreen"); if (!this.maximize) { - mcParams.add("--width"); - mcParams.add(Integer.toString(width)); - mcParams.add("--height"); - mcParams.add(Integer.toString(height)); + this.mcParams.add("--width"); + this.mcParams.add(Integer.toString(this.width)); + this.mcParams.add("--height"); + this.mcParams.add(Integer.toString(this.height)); } if (this.serverAddress != null) { - mcParams.add("--server"); - mcParams.add(serverAddress); - mcParams.add("--port"); - mcParams.add(serverPort); + this.mcParams.add("--server"); + this.mcParams.add(this.serverAddress); + this.mcParams.add("--port"); + this.mcParams.add(this.serverPort); } MethodHandle method = ReflectionUtils.findMainMethod(this.mainClassName); - method.invokeExact(mcParams.toArray(new String[0])); + method.invokeExact(this.mcParams.toArray(new String[0])); } } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java index 15da0371..eafc984a 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java @@ -85,17 +85,17 @@ public final class LegacyFrame extends JFrame { public LegacyFrame(String title, Applet applet) { super(title); - launcher = new Launcher(applet); + this.launcher = new Launcher(applet); - applet.setStub(launcher); + applet.setStub(this.launcher); try { - setIconImage(ImageIO.read(new File("icon.png"))); + this.setIconImage(ImageIO.read(new File("icon.png"))); } catch (IOException e) { LOGGER.log(Level.WARNING, "Unable to read Minecraft icon", e); } - addWindowListener(new ForceExitHandler()); + this.addWindowListener(new ForceExitHandler()); } public void start(String user, String session, int width, int height, boolean maximize, String serverAddress, @@ -119,9 +119,9 @@ public final class LegacyFrame extends JFrame { LOGGER.warning("Mpticket file is corrupted!"); } else { // Assumes parameters are valid and in the correct order - launcher.setParameter("server", lines.get(0)); - launcher.setParameter("port", lines.get(1)); - launcher.setParameter("mppass", lines.get(2)); + this.launcher.setParameter("server", lines.get(0)); + this.launcher.setParameter("port", lines.get(1)); + this.launcher.setParameter("mppass", lines.get(2)); } } catch (IOException e) { LOGGER.log(Level.WARNING, "Unable to read mpticket file!", e); @@ -129,35 +129,35 @@ public final class LegacyFrame extends JFrame { } if (serverAddress != null) { - launcher.setParameter("server", serverAddress); - launcher.setParameter("port", serverPort); + this.launcher.setParameter("server", serverAddress); + this.launcher.setParameter("port", serverPort); } - launcher.setParameter("username", user); - launcher.setParameter("sessionid", session); - launcher.setParameter("stand-alone", "true"); // Show the quit button. TODO: why won't this work? - launcher.setParameter("haspaid", "true"); // Some old versions need this for world saves to work. - launcher.setParameter("demo", isDemo ? "true" : "false"); - launcher.setParameter("fullscreen", "false"); + this.launcher.setParameter("username", user); + this.launcher.setParameter("sessionid", session); + this.launcher.setParameter("stand-alone", "true"); // Show the quit button. TODO: why won't this work? + this.launcher.setParameter("haspaid", "true"); // Some old versions need this for world saves to work. + this.launcher.setParameter("demo", isDemo ? "true" : "false"); + this.launcher.setParameter("fullscreen", "false"); - add(launcher); + this.add(this.launcher); - launcher.setPreferredSize(new Dimension(width, height)); + this.launcher.setPreferredSize(new Dimension(width, height)); - pack(); + this.pack(); - setLocationRelativeTo(null); - setResizable(true); + this.setLocationRelativeTo(null); + this.setResizable(true); if (maximize) setExtendedState(MAXIMIZED_BOTH); - validate(); + this.validate(); - launcher.init(); - launcher.start(); + this.launcher.init(); + this.launcher.start(); - setVisible(true); + this.setVisible(true); } private final class ForceExitHandler extends WindowAdapter { @@ -179,9 +179,9 @@ public final class LegacyFrame extends JFrame { } }).start(); - if (launcher != null) { - launcher.stop(); - launcher.destroy(); + if (LegacyFrame.this.launcher != null) { + LegacyFrame.this.launcher.stop(); + LegacyFrame.this.launcher.destroy(); } // old minecraft versions can hang without this >_< diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java index 953f83d9..9f76944f 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java @@ -84,15 +84,15 @@ public final class LegacyLauncher extends AbstractLauncher { public LegacyLauncher(Parameters params) { super(params); - user = params.getString("userName"); - session = params.getString("sessionId"); - title = params.getString("windowTitle", "Minecraft"); - appletClass = params.getString("appletClass", "net.minecraft.client.MinecraftApplet"); + this.user = params.getString("userName"); + this.session = params.getString("sessionId"); + this.title = params.getString("windowTitle", "Minecraft"); + this.appletClass = params.getString("appletClass", "net.minecraft.client.MinecraftApplet"); List traits = params.getList("traits", Collections.emptyList()); - usesApplet = !traits.contains("noapplet"); + this.usesApplet = !traits.contains("noapplet"); - cwd = System.getProperty("user.dir"); + this.cwd = System.getProperty("user.dir"); } @Override @@ -104,14 +104,14 @@ public final class LegacyLauncher extends AbstractLauncher { LOGGER.warning("Could not find Minecraft path field"); else { gameDirField.setAccessible(true); - gameDirField.set(null /* field is static, so instance is null */, new File(cwd)); + gameDirField.set(null /* field is static, so instance is null */, new File(this.cwd)); } if (this.usesApplet) { LOGGER.info("Launching legacy minecraft using applet wrapper..."); try { - LegacyFrame window = new LegacyFrame(title, ReflectionUtils.createAppletClass(this.appletClass)); + LegacyFrame window = new LegacyFrame(this.title, ReflectionUtils.createAppletClass(this.appletClass)); window.start(this.user, this.session, this.width, this.height, this.maximize, this.serverAddress, this.serverPort, this.mcParams.contains("--demo")); @@ -123,7 +123,7 @@ public final class LegacyLauncher extends AbstractLauncher { } MethodHandle method = ReflectionUtils.findMainEntrypoint(main); - method.invokeExact(mcParams.toArray(new String[0])); + method.invokeExact(this.mcParams.toArray(new String[0])); } } diff --git a/libraries/launcher/org/prismlauncher/utils/Parameters.java b/libraries/launcher/org/prismlauncher/utils/Parameters.java index 8286bd70..7af3c5e8 100644 --- a/libraries/launcher/org/prismlauncher/utils/Parameters.java +++ b/libraries/launcher/org/prismlauncher/utils/Parameters.java @@ -67,19 +67,19 @@ public final class Parameters { private final Map> map = new HashMap<>(); public void add(String key, String value) { - List params = map.get(key); + List params = this.map.get(key); if (params == null) { params = new ArrayList<>(); - map.put(key, params); + this.map.put(key, params); } params.add(value); } public List getList(String key) throws ParameterNotFoundException { - List params = map.get(key); + List params = this.map.get(key); if (params == null) throw ParameterNotFoundException.forParameterName(key); @@ -88,7 +88,7 @@ public final class Parameters { } public List getList(String key, List def) { - List params = map.get(key); + List params = this.map.get(key); if (params == null || params.isEmpty()) return def; @@ -97,7 +97,7 @@ public final class Parameters { } public String getString(String key) throws ParameterNotFoundException { - List list = getList(key); + List list = this.getList(key); if (list.isEmpty()) throw ParameterNotFoundException.forParameterName(key); @@ -106,7 +106,7 @@ public final class Parameters { } public String getString(String key, String def) { - List params = map.get(key); + List params = this.map.get(key); if (params == null || params.isEmpty()) return def; From f2ca9a6b319ad0ade04837f6830e682bc86c01a2 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sat, 5 Nov 2022 17:14:12 +0000 Subject: [PATCH 36/52] Revert switch to JUL for better colours Signed-off-by: TheKodeToad --- libraries/launcher/CMakeLists.txt | 2 + .../org/prismlauncher/EntryPoint.java | 30 ++-- .../launcher/impl/legacy/LegacyFrame.java | 16 +-- .../launcher/impl/legacy/LegacyLauncher.java | 12 +- .../prismlauncher/utils/ReflectionUtils.java | 17 +-- .../prismlauncher/utils/logging/Level.java | 54 +++++++ .../org/prismlauncher/utils/logging/Log.java | 134 ++++++++++++++++++ 7 files changed, 223 insertions(+), 42 deletions(-) create mode 100644 libraries/launcher/org/prismlauncher/utils/logging/Level.java create mode 100644 libraries/launcher/org/prismlauncher/utils/logging/Log.java diff --git a/libraries/launcher/CMakeLists.txt b/libraries/launcher/CMakeLists.txt index d176b1d4..90adcd3d 100644 --- a/libraries/launcher/CMakeLists.txt +++ b/libraries/launcher/CMakeLists.txt @@ -18,6 +18,8 @@ set(SRC org/prismlauncher/utils/Parameters.java org/prismlauncher/utils/ReflectionUtils.java org/prismlauncher/utils/StringUtils.java + org/prismlauncher/utils/logging/Level.java + org/prismlauncher/utils/logging/Log.java net/minecraft/Launcher.java ) add_jar(NewLaunch ${SRC}) diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index 512b01a9..34e65672 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -55,24 +55,21 @@ package org.prismlauncher; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; + import org.prismlauncher.exception.ParseException; import org.prismlauncher.launcher.Launcher; import org.prismlauncher.launcher.impl.StandardLauncher; import org.prismlauncher.launcher.impl.legacy.LegacyLauncher; import org.prismlauncher.utils.Parameters; import org.prismlauncher.utils.StringUtils; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.logging.Level; -import java.util.logging.Logger; +import org.prismlauncher.utils.logging.Log; public final class EntryPoint { - private static final Logger LOGGER = Logger.getLogger("EntryPoint"); - private EntryPoint() { } @@ -80,7 +77,7 @@ public final class EntryPoint { ExitCode exitCode = listen(); if (exitCode != ExitCode.NORMAL) { - LOGGER.warning("Exiting with " + exitCode); + Log.fatal("Exiting with " + exitCode); System.exit(exitCode.numericalCode); } @@ -123,14 +120,14 @@ public final class EntryPoint { preLaunchAction = PreLaunchAction.ABORT; } } catch (IOException | ParseException e) { - LOGGER.log(Level.SEVERE, "Launcher abort due to exception", e); + Log.fatal("Launcher abort due to exception", e); return ExitCode.ILLEGAL_ARGUMENT; } // Main loop if (preLaunchAction == PreLaunchAction.ABORT) { - LOGGER.info("Launch aborted by the launcher"); + Log.fatal("Launch aborted by the launcher"); return ExitCode.ABORT; } @@ -150,19 +147,22 @@ public final class EntryPoint { throw new IllegalArgumentException("Invalid launcher type: " + type); } + Log.launcher("Using " + type + " launcher"); + Log.blankLine(); + launcher.launch(); return ExitCode.NORMAL; } catch (IllegalArgumentException e) { - LOGGER.log(Level.SEVERE, "Wrong argument", e); + Log.fatal("Wrong argument", e); return ExitCode.ILLEGAL_ARGUMENT; } catch (ReflectiveOperationException e) { - LOGGER.log(Level.SEVERE, "Caught reflection exception from launcher", e); + Log.fatal("Caught reflection exception from launcher", e); return ExitCode.ERROR; } catch (Throwable e) { - LOGGER.log(Level.SEVERE, "Exception caught from launcher", e); + Log.fatal("Exception caught from launcher", e); return ExitCode.ERROR; } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java index eafc984a..8ff64ced 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java @@ -60,6 +60,8 @@ import net.minecraft.Launcher; import javax.imageio.ImageIO; import javax.swing.JFrame; +import org.prismlauncher.utils.logging.Log; + import java.applet.Applet; import java.awt.Dimension; import java.awt.event.WindowAdapter; @@ -72,12 +74,9 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; public final class LegacyFrame extends JFrame { - private static final Logger LOGGER = Logger.getLogger("LegacyFrame"); private static final long serialVersionUID = 1L; private final Launcher launcher; @@ -92,7 +91,7 @@ public final class LegacyFrame extends JFrame { try { this.setIconImage(ImageIO.read(new File("icon.png"))); } catch (IOException e) { - LOGGER.log(Level.WARNING, "Unable to read Minecraft icon", e); + Log.error("Unable to read Minecraft icon", e); } this.addWindowListener(new ForceExitHandler()); @@ -116,7 +115,7 @@ public final class LegacyFrame extends JFrame { if (lines.size() < 3) { Files.move(mpticketFile, mpticketFileCorrupt, StandardCopyOption.REPLACE_EXISTING); - LOGGER.warning("Mpticket file is corrupted!"); + Log.warning("Mpticket file is corrupted!"); } else { // Assumes parameters are valid and in the correct order this.launcher.setParameter("server", lines.get(0)); @@ -124,7 +123,7 @@ public final class LegacyFrame extends JFrame { this.launcher.setParameter("mppass", lines.get(2)); } } catch (IOException e) { - LOGGER.log(Level.WARNING, "Unable to read mpticket file!", e); + Log.error("Unable to read mpticket file", e); } } @@ -170,11 +169,10 @@ public final class LegacyFrame extends JFrame { try { Thread.sleep(30000L); } catch (InterruptedException e) { - LOGGER.log(Level.SEVERE, "Thread interrupted", e); + Log.error("Thread interrupted", e); } - LOGGER.info("Forcing exit!"); - + Log.warning("Forcing exit"); System.exit(0); } }).start(); diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java index 9f76944f..5ffa9ec5 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java @@ -59,22 +59,19 @@ package org.prismlauncher.launcher.impl.legacy; import org.prismlauncher.launcher.impl.AbstractLauncher; import org.prismlauncher.utils.Parameters; import org.prismlauncher.utils.ReflectionUtils; +import org.prismlauncher.utils.logging.Log; import java.io.File; import java.lang.invoke.MethodHandle; import java.lang.reflect.Field; import java.util.Collections; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; /** * Used to launch old versions that support applets. */ public final class LegacyLauncher extends AbstractLauncher { - private static final Logger LOGGER = Logger.getLogger("LegacyLauncher"); - private final String user, session; private final String title; private final String appletClass; @@ -101,24 +98,23 @@ public final class LegacyLauncher extends AbstractLauncher { Field gameDirField = ReflectionUtils.getMinecraftGameDirField(main); if (gameDirField == null) - LOGGER.warning("Could not find Minecraft path field"); + Log.warning("Could not find Minecraft path field"); else { gameDirField.setAccessible(true); gameDirField.set(null /* field is static, so instance is null */, new File(this.cwd)); } if (this.usesApplet) { - LOGGER.info("Launching legacy minecraft using applet wrapper..."); + Log.launcher("Launching with applet wrapper..."); try { LegacyFrame window = new LegacyFrame(this.title, ReflectionUtils.createAppletClass(this.appletClass)); window.start(this.user, this.session, this.width, this.height, this.maximize, this.serverAddress, this.serverPort, this.mcParams.contains("--demo")); - return; } catch (Throwable e) { - LOGGER.log(Level.SEVERE, "Running applet wrapper failed with exception; falling back to main class", e); + Log.error("Running applet wrapper failed with exception; falling back to main class", e); } } diff --git a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java index 1d2383a4..3b299615 100644 --- a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java @@ -62,13 +62,11 @@ import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import java.util.logging.Level; -import java.util.logging.Logger; + +import org.prismlauncher.utils.logging.Log; public final class ReflectionUtils { - private static final Logger LOGGER = Logger.getLogger("ReflectionUtils"); - private ReflectionUtils() { } @@ -101,7 +99,7 @@ public final class ReflectionUtils { * @return The found field. */ public static Field getMinecraftGameDirField(Class minecraftMainClass) { - LOGGER.fine("Resolving minecraft game directory field"); + Log.debug("Resolving minecraft game directory field"); // Field we're looking for is always // private static File obfuscatedName = null; for (Field field : minecraftMainClass.getDeclaredFields()) { @@ -114,24 +112,23 @@ public final class ReflectionUtils { // Must be static if (!Modifier.isStatic(fieldModifiers)) { - LOGGER.log(Level.FINE, "Rejecting field {0} because it is not static", field.getName()); + Log.debug("Rejecting field " + field.getName() + " because it is not static"); continue; } // Must be private if (!Modifier.isPrivate(fieldModifiers)) { - LOGGER.log(Level.FINE, "Rejecting field {0} because it is not private", field.getName()); + Log.debug("Rejecting field " + field.getName() + " because it is not private"); continue; } // Must not be final if (Modifier.isFinal(fieldModifiers)) { - LOGGER.log(Level.FINE, "Rejecting field {0} because it is final", field.getName()); + Log.debug("Rejecting field " + field.getName() + " because it is final"); continue; } - LOGGER.log(Level.FINE, "Identified field {0} to match conditions for minecraft game directory field", - field.getName()); + Log.debug("Identified field " + field.getName() + " to match conditions for minecraft game directory field"); return field; } diff --git a/libraries/launcher/org/prismlauncher/utils/logging/Level.java b/libraries/launcher/org/prismlauncher/utils/logging/Level.java new file mode 100644 index 00000000..330cec28 --- /dev/null +++ b/libraries/launcher/org/prismlauncher/utils/logging/Level.java @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 TheKodeToad + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give + * you permission to link this library with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also meet, + * for each linked independent module, the terms and conditions of the + * license of that module. An independent module is a module which is + * not derived from or based on this library. If you modify this + * library, you may extend this exception to your version of the + * library, but you are not obliged to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.prismlauncher.utils.logging; + +public enum Level { + LAUNCHER("Launcher"), DEBUG("Debug"), INFO("Info"), MESSAGE("Message"), + WARNING("Warning"), ERROR("Error", true), FATAL("Fatal", true); + + String name; + boolean stderr; + + Level(String name) { + this(name, false); + } + + Level(String name, boolean stderr) { + this.name = name; + this.stderr = stderr; + } + +} diff --git a/libraries/launcher/org/prismlauncher/utils/logging/Log.java b/libraries/launcher/org/prismlauncher/utils/logging/Log.java new file mode 100644 index 00000000..e1961991 --- /dev/null +++ b/libraries/launcher/org/prismlauncher/utils/logging/Log.java @@ -0,0 +1,134 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 TheKodeToad + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give + * you permission to link this library with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also meet, + * for each linked independent module, the terms and conditions of the + * license of that module. An independent module is a module which is + * not derived from or based on this library. If you modify this + * library, you may extend this exception to your version of the + * library, but you are not obliged to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.prismlauncher.utils.logging; + +import java.io.PrintStream; + +/** + * Used to print messages with different levels used to colourise the output. + * Used instead of a logging framework, as the launcher knows how to parse these + * messages. + */ +public final class Log { + + private static final PrintStream ERROR_PREFIX = new PrintStream(System.err) { + @Override + public void println(String x) { + error(x); + } + + @Override + public void println(Object x) { + error(String.valueOf(x)); + } + }, FATAL_PREFIX = new PrintStream(System.err) { + @Override + public void println(String x) { + fatal(x); + } + + @Override + public void println(Object x) { + fatal(String.valueOf(x)); + } + }; + + private static final boolean DEBUG = Boolean.getBoolean("org.prismlauncher.debug"); + + private Log() { + } + + public static void blankLine() { + System.out.println(); + } + + public static void launcher(String message) { + log(message, Level.LAUNCHER); + } + + public static void error(String message) { + log(message, Level.ERROR); + } + + public static void debug(String message) { + if (!DEBUG) + return; + + log(message, Level.DEBUG); + } + + public static void info(String message) { + log(message, Level.INFO); + } + + public static void warning(String message) { + log(message, Level.WARNING); + } + + public static void error(String message, Throwable e) { + error(message); + e.printStackTrace(ERROR_PREFIX); + } + + public static void fatal(String message) { + log(message, Level.FATAL); + } + + public static void fatal(String message, Throwable e) { + fatal(message); + e.printStackTrace(FATAL_PREFIX); + } + + /** + * Logs a message with the prefix !![LEVEL]!. + * + * @param message The message + * @param level The level + */ + public static void log(String message, Level level) { + String prefix = "!![" + level.name + "]!"; + // prefix first line + message = prefix + message; + // prefix subsequent lines + message = message.replace("\n", "\n" + prefix); + + if (level.stderr) + System.err.println(message); + else + System.out.println(message); + } + +} From 32c2ad2bbd087b83fe5e1cfe03926410ec95bcca Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Tue, 8 Nov 2022 17:51:18 +0000 Subject: [PATCH 37/52] A lot more cleanup Signed-off-by: TheKodeToad --- launcher/minecraft/MinecraftInstance.cpp | 25 +- launcher/minecraft/MinecraftInstance.h | 4 +- libraries/README.md | 66 +-- libraries/launcher/CMakeLists.txt | 4 +- libraries/launcher/formatting-profile.xml | 399 ------------------ .../launcher/net/minecraft/Launcher.java | 87 ++-- .../org/prismlauncher/EntryPoint.java | 105 +++-- .../exception/ParameterNotFoundException.java | 22 +- .../exception/ParseException.java | 26 +- .../org/prismlauncher/launcher/Launcher.java | 3 +- .../launcher/impl/AbstractLauncher.java | 48 +-- .../launcher/impl/StandardLauncher.java | 38 +- .../launcher/impl/legacy/LegacyFrame.java | 99 +++-- .../launcher/impl/legacy/LegacyLauncher.java | 53 +-- .../org/prismlauncher/utils/Parameters.java | 23 +- .../prismlauncher/utils/ReflectionUtils.java | 103 ++--- .../org/prismlauncher/utils/StringUtils.java | 11 +- .../prismlauncher/utils/logging/Level.java | 11 +- .../org/prismlauncher/utils/logging/Log.java | 52 +-- .../utils/logging/LogPrintStream.java | 99 +++++ 20 files changed, 417 insertions(+), 861 deletions(-) delete mode 100644 libraries/launcher/formatting-profile.xml create mode 100644 libraries/launcher/org/prismlauncher/utils/logging/LogPrintStream.java diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index 39a7198c..a5b19f09 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Jamie Mansfield * Copyright (C) 2022 TheKodeToad @@ -438,6 +438,17 @@ QStringList MinecraftInstance::javaArguments() return args; } +QString MinecraftInstance::getLauncher() +{ + auto profile = m_components->getProfile(); + + // use legacy launcher if the traits are set + if (profile->getTraits().contains("legacyLaunch") || profile->getTraits().contains("alphaLaunch")) + return "legacy"; + + return "standard"; +} + QMap MinecraftInstance::getVariables() { QMap out; @@ -634,15 +645,7 @@ QString MinecraftInstance::createLaunchScript(AuthSessionPtr session, MinecraftS launchScript += "traits " + trait + "\n"; } - launchScript += "launcher "; - - // use legacy launcher if the traits are set - if (profile->getTraits().contains("legacyLaunch") || profile->getTraits().contains("alphaLaunch")) - launchScript += "legacy"; - else - launchScript += "standard"; - - launchScript += "\n"; + launchScript += "launcher " + getLauncher() + "\n"; // qDebug() << "Generated launch script:" << launchScript; return launchScript; @@ -779,6 +782,8 @@ QStringList MinecraftInstance::verboseDescription(AuthSessionPtr session, Minecr out << "Window size: " + QString::number(width) + " x " + QString::number(height); } out << ""; + out << "Launcher: " + getLauncher(); + out << ""; return out; } diff --git a/launcher/minecraft/MinecraftInstance.h b/launcher/minecraft/MinecraftInstance.h index 1895d187..1bbd7b83 100644 --- a/launcher/minecraft/MinecraftInstance.h +++ b/launcher/minecraft/MinecraftInstance.h @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu + * Copyright (C) 2022 TheKodeToad * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -130,6 +131,7 @@ public: QString createLaunchScript(AuthSessionPtr session, MinecraftServerTargetPtr serverToJoin); /// get arguments passed to java QStringList javaArguments(); + QString getLauncher(); /// get variables for launch command variable substitution/environment QMap getVariables() override; diff --git a/libraries/README.md b/libraries/README.md index 2971e32b..ac5a3618 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -42,19 +42,20 @@ MIT licensed. Java launcher part for Minecraft. -It: +It does the following: -- Starts a process -- Waits for a launch script on stdin -- Consumes the launch script you feed it -- Proceeds with launch when it gets the `launcher` command +- Waits for a launch script on stdin. +- Consumes the launch script you feed it. +- Proceeds with launch when it gets the `launcher` command. + +If "abort" is sent, the process will exit. This means the process is essentially idle until the final command is sent. You can, for example, attach a profiler before you send it. -A `legacy` and `standard` launchers are available. +The `standard` and `legacy` launchers are available. -- `legacy` is intended for use with Minecraft versions < 1.6 and is deprecated. - `standard` can handle launching any Minecraft version, at the cost of some extra features `legacy` enables (custom window icon and title). +- `legacy` is intended for use with Minecraft versions < 1.6 and is deprecated. Example (some parts have been censored): @@ -64,7 +65,7 @@ mainClass net.minecraft.launchwrapper.Launch param --username param CENSORED param --version -param MultiMC5 +param Prism Launcher param --gameDir param /home/peterix/minecraft/FTB/17ForgeTest/minecraft param --assetsDir @@ -81,57 +82,10 @@ param --userType param mojang param --tweakClass param cpw.mods.fml.common.launcher.FMLTweaker -windowTitle MultiMC: 172ForgeTest +windowTitle Prism Launcher: 172ForgeTest windowParams 854x480 userName CENSORED sessionId token:CENSORED:CENSORED -cp /home/peterix/minecraft/FTB/libraries/com/mojang/realms/1.3.5/realms-1.3.5.jar -cp /home/peterix/minecraft/FTB/libraries/org/apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.jar -cp /home/peterix/minecraft/FTB/libraries/org/apache/httpcomponents/httpclient/4.3.3/httpclient-4.3.3.jar -cp /home/peterix/minecraft/FTB/libraries/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3.jar -cp /home/peterix/minecraft/FTB/libraries/org/apache/httpcomponents/httpcore/4.3.2/httpcore-4.3.2.jar -cp /home/peterix/minecraft/FTB/libraries/java3d/vecmath/1.3.1/vecmath-1.3.1.jar -cp /home/peterix/minecraft/FTB/libraries/net/sf/trove4j/trove4j/3.0.3/trove4j-3.0.3.jar -cp /home/peterix/minecraft/FTB/libraries/com/ibm/icu/icu4j-core-mojang/51.2/icu4j-core-mojang-51.2.jar -cp /home/peterix/minecraft/FTB/libraries/net/sf/jopt-simple/jopt-simple/4.5/jopt-simple-4.5.jar -cp /home/peterix/minecraft/FTB/libraries/com/paulscode/codecjorbis/20101023/codecjorbis-20101023.jar -cp /home/peterix/minecraft/FTB/libraries/com/paulscode/codecwav/20101023/codecwav-20101023.jar -cp /home/peterix/minecraft/FTB/libraries/com/paulscode/libraryjavasound/20101123/libraryjavasound-20101123.jar -cp /home/peterix/minecraft/FTB/libraries/com/paulscode/librarylwjglopenal/20100824/librarylwjglopenal-20100824.jar -cp /home/peterix/minecraft/FTB/libraries/com/paulscode/soundsystem/20120107/soundsystem-20120107.jar -cp /home/peterix/minecraft/FTB/libraries/io/netty/netty-all/4.0.10.Final/netty-all-4.0.10.Final.jar -cp /home/peterix/minecraft/FTB/libraries/com/google/guava/guava/16.0/guava-16.0.jar -cp /home/peterix/minecraft/FTB/libraries/org/apache/commons/commons-lang3/3.2.1/commons-lang3-3.2.1.jar -cp /home/peterix/minecraft/FTB/libraries/commons-io/commons-io/2.4/commons-io-2.4.jar -cp /home/peterix/minecraft/FTB/libraries/commons-codec/commons-codec/1.9/commons-codec-1.9.jar -cp /home/peterix/minecraft/FTB/libraries/net/java/jinput/jinput/2.0.5/jinput-2.0.5.jar -cp /home/peterix/minecraft/FTB/libraries/net/java/jutils/jutils/1.0.0/jutils-1.0.0.jar -cp /home/peterix/minecraft/FTB/libraries/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar -cp /home/peterix/minecraft/FTB/libraries/com/mojang/authlib/1.5.16/authlib-1.5.16.jar -cp /home/peterix/minecraft/FTB/libraries/org/apache/logging/log4j/log4j-api/2.0-beta9/log4j-api-2.0-beta9.jar -cp /home/peterix/minecraft/FTB/libraries/org/apache/logging/log4j/log4j-core/2.0-beta9/log4j-core-2.0-beta9.jar -cp /home/peterix/minecraft/FTB/libraries/org/lwjgl/lwjgl/lwjgl/2.9.1/lwjgl-2.9.1.jar -cp /home/peterix/minecraft/FTB/libraries/org/lwjgl/lwjgl/lwjgl_util/2.9.1/lwjgl_util-2.9.1.jar -cp /home/peterix/minecraft/FTB/libraries/tv/twitch/twitch/5.16/twitch-5.16.jar -cp /home/peterix/minecraft/FTB/libraries/net/minecraftforge/forge/1.7.10-10.13.0.1178/forge-1.7.10-10.13.0.1178.jar -cp /home/peterix/minecraft/FTB/libraries/net/minecraft/launchwrapper/1.9/launchwrapper-1.9.jar -cp /home/peterix/minecraft/FTB/libraries/org/ow2/asm/asm-all/4.1/asm-all-4.1.jar -cp /home/peterix/minecraft/FTB/libraries/com/typesafe/akka/akka-actor_2.11/2.3.3/akka-actor_2.11-2.3.3.jar -cp /home/peterix/minecraft/FTB/libraries/com/typesafe/config/1.2.1/config-1.2.1.jar -cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-actors-migration_2.11/1.1.0/scala-actors-migration_2.11-1.1.0.jar -cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-compiler/2.11.1/scala-compiler-2.11.1.jar -cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/plugins/scala-continuations-library_2.11/1.0.2/scala-continuations-library_2.11-1.0.2.jar -cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/plugins/scala-continuations-plugin_2.11.1/1.0.2/scala-continuations-plugin_2.11.1-1.0.2.jar -cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-library/2.11.1/scala-library-2.11.1.jar -cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-parser-combinators_2.11/1.0.1/scala-parser-combinators_2.11-1.0.1.jar -cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-reflect/2.11.1/scala-reflect-2.11.1.jar -cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-swing_2.11/1.0.1/scala-swing_2.11-1.0.1.jar -cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-xml_2.11/1.0.2/scala-xml_2.11-1.0.2.jar -cp /home/peterix/minecraft/FTB/libraries/lzma/lzma/0.0.1/lzma-0.0.1.jar -ext /home/peterix/minecraft/FTB/libraries/org/lwjgl/lwjgl/lwjgl-platform/2.9.1/lwjgl-platform-2.9.1-natives-linux.jar -ext /home/peterix/minecraft/FTB/libraries/net/java/jinput/jinput-platform/2.0.5/jinput-platform-2.0.5-natives-linux.jar -natives /home/peterix/minecraft/FTB/17ForgeTest/natives -cp /home/peterix/minecraft/FTB/versions/1.7.10/1.7.10.jar launcher standard ``` diff --git a/libraries/launcher/CMakeLists.txt b/libraries/launcher/CMakeLists.txt index 90adcd3d..1d22a93e 100644 --- a/libraries/launcher/CMakeLists.txt +++ b/libraries/launcher/CMakeLists.txt @@ -9,10 +9,10 @@ set(CMAKE_JAVA_COMPILE_FLAGS -target 7 -source 7) set(SRC org/prismlauncher/EntryPoint.java org/prismlauncher/launcher/Launcher.java - org/prismlauncher/launcher/impl/legacy/LegacyFrame.java - org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java org/prismlauncher/launcher/impl/AbstractLauncher.java org/prismlauncher/launcher/impl/StandardLauncher.java + org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java + org/prismlauncher/launcher/impl/legacy/LegacyFrame.java org/prismlauncher/exception/ParameterNotFoundException.java org/prismlauncher/exception/ParseException.java org/prismlauncher/utils/Parameters.java diff --git a/libraries/launcher/formatting-profile.xml b/libraries/launcher/formatting-profile.xml deleted file mode 100644 index 1b334838..00000000 --- a/libraries/launcher/formatting-profile.xml +++ /dev/null @@ -1,399 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java index b895d5b7..a721495a 100644 --- a/libraries/launcher/net/minecraft/Launcher.java +++ b/libraries/launcher/net/minecraft/Launcher.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax @@ -62,8 +61,10 @@ import java.awt.Dimension; import java.awt.Graphics; import java.net.MalformedURLException; import java.net.URL; +import java.util.HashMap; import java.util.Map; -import java.util.TreeMap; + +import org.prismlauncher.utils.logging.Log; /** * WARNING: This class is reflectively accessed by legacy Forge versions. @@ -75,7 +76,7 @@ public final class Launcher extends Applet implements AppletStub { private static final long serialVersionUID = 1L; - private final Map params = new TreeMap<>(); + private final Map params = new HashMap<>(); private Applet wrappedApplet; private final URL documentBase; @@ -88,75 +89,75 @@ public final class Launcher extends Applet implements AppletStub { public Launcher(Applet applet, URL documentBase) { setLayout(new BorderLayout()); - this.add(applet, "Center"); + add(applet, "Center"); wrappedApplet = applet; try { - if (documentBase != null) { - this.documentBase = documentBase; - } else if (applet.getClass().getPackage().getName().startsWith("com.mojang.")) { - // Special case only for Classic versions - - // TODO: 2022-10-27 Can this be changed to https - this.documentBase = new URL("http", "www.minecraft.net", 80, "/game/"); - } else { - // TODO: 2022-10-27 Can this be changed to https? - this.documentBase = new URL("http://www.minecraft.net/game/"); + if (documentBase == null) { + if (applet.getClass().getPackage().getName().startsWith("com.mojang.")) { + // Special case only for Classic versions + documentBase = new URL("http", "www.minecraft.net", 80, "/game/"); + } else { + documentBase = new URL("http://www.minecraft.net/game/"); + } } } catch (MalformedURLException e) { - throw new RuntimeException(e); + // handle gracefully - it won't happen, but Java requires that it is caught + Log.error("Failed to parse document base URL", e); } + + this.documentBase = documentBase; } public void replace(Applet applet) { wrappedApplet = applet; applet.setStub(this); - applet.setSize(this.getWidth(), this.getHeight()); + applet.setSize(getWidth(), getHeight()); setLayout(new BorderLayout()); - this.add(applet, "Center"); + add(applet, "Center"); applet.init(); - this.active = true; + active = true; applet.start(); - this.validate(); + validate(); } @Override public boolean isActive() { - return this.active; + return active; } @Override public URL getDocumentBase() { - return this.documentBase; + return documentBase; } @Override public URL getCodeBase() { try { - // TODO: 2022-10-27 Can this be changed to https? return new URL("http://www.minecraft.net/game/"); } catch (MalformedURLException e) { - throw new RuntimeException(e); + Log.error("Failed to parse codebase URL", e); + return null; } } @Override - public String getParameter(String name) { - String param = this.params.get(name); + public String getParameter(String key) { + String param = params.get(key); if (param != null) return param; try { - return super.getParameter(name); - } catch (Exception ignored) { + return super.getParameter(key); + } catch (Throwable ignored) { } return null; @@ -164,49 +165,49 @@ public final class Launcher extends Applet implements AppletStub { @Override public void resize(int width, int height) { - this.wrappedApplet.resize(width, height); + wrappedApplet.resize(width, height); } @Override public void resize(Dimension size) { - this.wrappedApplet.resize(size); + wrappedApplet.resize(size); } @Override public void init() { - if (this.wrappedApplet != null) - this.wrappedApplet.init(); + if (wrappedApplet != null) + wrappedApplet.init(); } @Override public void start() { - this.wrappedApplet.start(); + wrappedApplet.start(); - this.active = true; + active = true; } @Override public void stop() { - this.wrappedApplet.stop(); + wrappedApplet.stop(); - this.active = false; + active = false; } @Override public void destroy() { - this.wrappedApplet.destroy(); + wrappedApplet.destroy(); } @Override public void appletResize(int width, int height) { - this.wrappedApplet.resize(width, height); + wrappedApplet.resize(width, height); } @Override public void setVisible(boolean visible) { super.setVisible(visible); - this.wrappedApplet.setVisible(visible); + wrappedApplet.setVisible(visible); } @Override @@ -217,8 +218,12 @@ public final class Launcher extends Applet implements AppletStub { public void update(Graphics graphics) { } - public void setParameter(String name, String value) { - this.params.put(name, value); + public void setParameter(String key, String value) { + params.put(key, value); + } + + public void setParameter(String key, boolean value) { + setParameter(key, value ? "true" : "false"); } } diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index 34e65672..f6567468 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax @@ -56,7 +55,6 @@ package org.prismlauncher; import java.io.BufferedReader; -import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; @@ -70,63 +68,40 @@ import org.prismlauncher.utils.logging.Log; public final class EntryPoint { - private EntryPoint() { - } - public static void main(String[] args) { - ExitCode exitCode = listen(); + ExitCode code = listen(); - if (exitCode != ExitCode.NORMAL) { - Log.fatal("Exiting with " + exitCode); + if (code != ExitCode.NORMAL) { + Log.fatal("Exiting with " + code); - System.exit(exitCode.numericalCode); - } - } - - private static PreLaunchAction parseLine(String input, Parameters params) throws ParseException { - if (input.isEmpty()) - return PreLaunchAction.PROCEED; - - if ("launch".equalsIgnoreCase(input)) - return PreLaunchAction.LAUNCH; - else if ("abort".equalsIgnoreCase(input)) - return PreLaunchAction.ABORT; - else { - String[] pair = StringUtils.splitStringPair(' ', input); - - if (pair == null) - throw new ParseException(String.format( - "Could not split input string '%s' by space. All input provided from stdin must be either 'launch', 'abort', or " - + "in the format '[param name] [param]'.", - input)); - - params.add(pair[0], pair[1]); - - return PreLaunchAction.PROCEED; + System.exit(code.numeric); } } private static ExitCode listen() { - Parameters parameters = new Parameters(); - PreLaunchAction preLaunchAction = PreLaunchAction.PROCEED; + Parameters params = new Parameters(); + PreLaunchAction action = PreLaunchAction.PROCEED; try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8))) { String line; - while (preLaunchAction == PreLaunchAction.PROCEED) { + while (action == PreLaunchAction.PROCEED) { if ((line = reader.readLine()) != null) - preLaunchAction = parseLine(line, parameters); + action = parseLine(line, params); else - preLaunchAction = PreLaunchAction.ABORT; + action = PreLaunchAction.ABORT; } - } catch (IOException | ParseException e) { - Log.fatal("Launcher abort due to exception", e); + } catch (IllegalArgumentException e) { + Log.fatal("Aborting due to wrong argument", e); return ExitCode.ILLEGAL_ARGUMENT; + } catch (Throwable e) { + Log.fatal("Aborting due to exception", e); + + return ExitCode.ABORT; } - // Main loop - if (preLaunchAction == PreLaunchAction.ABORT) { + if (action == PreLaunchAction.ABORT) { Log.fatal("Launch aborted by the launcher"); return ExitCode.ABORT; @@ -134,33 +109,28 @@ public final class EntryPoint { try { Launcher launcher; - String type = parameters.getString("launcher"); + String type = params.getString("launcher"); switch (type) { case "standard": - launcher = new StandardLauncher(parameters); + launcher = new StandardLauncher(params); break; + case "legacy": - launcher = new LegacyLauncher(parameters); + launcher = new LegacyLauncher(params); break; + default: throw new IllegalArgumentException("Invalid launcher type: " + type); } - Log.launcher("Using " + type + " launcher"); - Log.blankLine(); - launcher.launch(); return ExitCode.NORMAL; } catch (IllegalArgumentException e) { - Log.fatal("Wrong argument", e); + Log.fatal("Illegal argument", e); return ExitCode.ILLEGAL_ARGUMENT; - } catch (ReflectiveOperationException e) { - Log.fatal("Caught reflection exception from launcher", e); - - return ExitCode.ERROR; } catch (Throwable e) { Log.fatal("Exception caught from launcher", e); @@ -168,6 +138,29 @@ public final class EntryPoint { } } + private static PreLaunchAction parseLine(String input, Parameters params) throws ParseException { + switch (input) { + case "": + break; + + case "launch": + return PreLaunchAction.LAUNCH; + + case "abort": + return PreLaunchAction.ABORT; + + default: + String[] pair = StringUtils.splitStringPair(' ', input); + + if (pair == null) + throw new ParseException(input, "[key] [value]"); + + params.add(pair[0], pair[1]); + } + + return PreLaunchAction.PROCEED; + } + private enum PreLaunchAction { PROCEED, LAUNCH, ABORT } @@ -175,10 +168,10 @@ public final class EntryPoint { private enum ExitCode { NORMAL(0), ABORT(1), ERROR(2), ILLEGAL_ARGUMENT(65); - private final int numericalCode; + private final int numeric; - ExitCode(int numericalCode) { - this.numericalCode = numericalCode; + ExitCode(int numeric) { + this.numeric = numeric; } } diff --git a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java index 52c2a368..524076ff 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 solonovamax * Copyright (C) 2022 TheKodeToad @@ -42,23 +41,8 @@ public final class ParameterNotFoundException extends IllegalArgumentException { private static final long serialVersionUID = 1L; - public ParameterNotFoundException(String message, Throwable cause) { - super(message, cause); - } - - public ParameterNotFoundException(Throwable cause) { - super(cause); - } - - public ParameterNotFoundException(String message) { - super(message); - } - - public ParameterNotFoundException() { - } - - public static ParameterNotFoundException forParameterName(String parameterName) { - return new ParameterNotFoundException(String.format("Unknown parameter name '%s'", parameterName)); + public ParameterNotFoundException(String key) { + super(String.format("Required parameter '%s' was not found", key)); } } diff --git a/libraries/launcher/org/prismlauncher/exception/ParseException.java b/libraries/launcher/org/prismlauncher/exception/ParseException.java index 80709c56..4608fdd1 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParseException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParseException.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 solonovamax * Copyright (C) 2022 TheKodeToad @@ -42,27 +41,8 @@ public final class ParseException extends IllegalArgumentException { private static final long serialVersionUID = 1L; - public ParseException(String message) { - super(message); - } - - public ParseException(String message, Throwable cause) { - super(message, cause); - } - - public ParseException(Throwable cause) { - super(cause); - } - - public ParseException() { - } - - public static ParseException forInputString(String inputString) { - return new ParseException(String.format("Could not parse input string '%s'", inputString)); - } - - public static ParseException forInputString(String inputString, Throwable cause) { - return new ParseException(String.format("Could not parse input string '%s'", inputString), cause); + public ParseException(String input, String format) { + super(String.format("For input '%s' - should match '%s'", input, format)); } } diff --git a/libraries/launcher/org/prismlauncher/launcher/Launcher.java b/libraries/launcher/org/prismlauncher/launcher/Launcher.java index 1a6577e0..049a83d8 100644 --- a/libraries/launcher/org/prismlauncher/launcher/Launcher.java +++ b/libraries/launcher/org/prismlauncher/launcher/Launcher.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java index 7ae7568c..585d55f1 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax @@ -55,21 +54,20 @@ package org.prismlauncher.launcher.impl; +import java.util.ArrayList; +import java.util.List; + import org.prismlauncher.exception.ParseException; import org.prismlauncher.launcher.Launcher; import org.prismlauncher.utils.Parameters; import org.prismlauncher.utils.StringUtils; -import java.util.ArrayList; -import java.util.List; - public abstract class AbstractLauncher implements Launcher { - private static final int DEFAULT_WINDOW_WIDTH = 854; - private static final int DEFAULT_WINDOW_HEIGHT = 480; + private static final int DEFAULT_WINDOW_WIDTH = 854, DEFAULT_WINDOW_HEIGHT = 480; // parameters, separated from ParamBucket - protected final List mcParams; + protected final List gameArgs; // secondary parameters protected final int width, height; @@ -79,34 +77,34 @@ public abstract class AbstractLauncher implements Launcher { protected final String mainClassName; protected AbstractLauncher(Parameters params) { - this.mcParams = params.getList("param", new ArrayList()); - this.mainClassName = params.getString("mainClass", "net.minecraft.client.Minecraft"); + gameArgs = params.getList("param", new ArrayList()); + mainClassName = params.getString("mainClass", "net.minecraft.client.Minecraft"); - this.serverAddress = params.getString("serverAddress", null); - this.serverPort = params.getString("serverPort", null); + serverAddress = params.getString("serverAddress", null); + serverPort = params.getString("serverPort", null); String windowParams = params.getString("windowParams", null); - this.maximize = "max".equalsIgnoreCase(windowParams); + if ("max".equals(windowParams) || windowParams == null) { + maximize = windowParams != null; + + width = DEFAULT_WINDOW_WIDTH; + height = DEFAULT_WINDOW_HEIGHT; + } else { + maximize = false; - if (windowParams != null && !"max".equalsIgnoreCase(windowParams)) { String[] sizePair = StringUtils.splitStringPair('x', windowParams); if (sizePair != null) { try { - this.width = Integer.parseInt(sizePair[0]); - this.height = Integer.parseInt(sizePair[1]); - } catch (NumberFormatException e) { - throw new ParseException(String.format("Could not parse window parameters from '%s'", windowParams), - e); + width = Integer.parseInt(sizePair[0]); + height = Integer.parseInt(sizePair[1]); + return; + } catch (NumberFormatException ignored) { } - } else { - throw new ParseException( - String.format("Invalid window size parameters '%s'. Format: [height]x[width]", windowParams)); } - } else { - this.width = DEFAULT_WINDOW_WIDTH; - this.height = DEFAULT_WINDOW_HEIGHT; + + throw new ParseException(windowParams, "[width]x[height]"); } } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java index 0f6fcf34..9436ff15 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax @@ -55,11 +54,11 @@ package org.prismlauncher.launcher.impl; +import java.lang.invoke.MethodHandle; + import org.prismlauncher.utils.Parameters; import org.prismlauncher.utils.ReflectionUtils; -import java.lang.invoke.MethodHandle; - public final class StandardLauncher extends AbstractLauncher { public StandardLauncher(Parameters params) { @@ -69,27 +68,24 @@ public final class StandardLauncher extends AbstractLauncher { @Override public void launch() throws Throwable { // window size, title and state - - // FIXME: there is no good way to maximize the minecraft window from here. - // the following often breaks linux screen setups - // mcparams.add("--fullscreen"); - - if (!this.maximize) { - this.mcParams.add("--width"); - this.mcParams.add(Integer.toString(this.width)); - this.mcParams.add("--height"); - this.mcParams.add(Integer.toString(this.height)); + // FIXME doesn't support maximisation + if (!maximize) { + gameArgs.add("--width"); + gameArgs.add(Integer.toString(width)); + gameArgs.add("--height"); + gameArgs.add(Integer.toString(height)); } - if (this.serverAddress != null) { - this.mcParams.add("--server"); - this.mcParams.add(this.serverAddress); - this.mcParams.add("--port"); - this.mcParams.add(this.serverPort); + if (serverAddress != null) { + gameArgs.add("--server"); + gameArgs.add(serverAddress); + gameArgs.add("--port"); + gameArgs.add(serverPort); } - MethodHandle method = ReflectionUtils.findMainMethod(this.mainClassName); - method.invokeExact(this.mcParams.toArray(new String[0])); + // find and invoke the main method + MethodHandle method = ReflectionUtils.findMainMethod(mainClassName); + method.invokeExact(gameArgs.toArray(new String[0])); } } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java index 8ff64ced..c215e7fe 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 flow * Copyright (C) 2022 TheKodeToad @@ -55,13 +54,6 @@ package org.prismlauncher.launcher.impl.legacy; -import net.minecraft.Launcher; - -import javax.imageio.ImageIO; -import javax.swing.JFrame; - -import org.prismlauncher.utils.logging.Log; - import java.applet.Applet; import java.awt.Dimension; import java.awt.event.WindowAdapter; @@ -75,6 +67,13 @@ import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.List; +import javax.imageio.ImageIO; +import javax.swing.JFrame; + +import org.prismlauncher.utils.logging.Log; + +import net.minecraft.Launcher; + public final class LegacyFrame extends JFrame { private static final long serialVersionUID = 1L; @@ -84,85 +83,85 @@ public final class LegacyFrame extends JFrame { public LegacyFrame(String title, Applet applet) { super(title); - this.launcher = new Launcher(applet); + launcher = new Launcher(applet); - applet.setStub(this.launcher); + applet.setStub(launcher); try { - this.setIconImage(ImageIO.read(new File("icon.png"))); + setIconImage(ImageIO.read(new File("icon.png"))); } catch (IOException e) { - Log.error("Unable to read Minecraft icon", e); + Log.error("Failed to read window icon", e); } - this.addWindowListener(new ForceExitHandler()); + addWindowListener(new ForceExitHandler()); } public void start(String user, String session, int width, int height, boolean maximize, String serverAddress, - String serverPort, boolean isDemo) { + String serverPort, boolean demo) { // Implements support for launching in to multiplayer on classic servers using a - // mpticket - // file generated by an external program and stored in the instance's root - // folder. + // mpticket file generated by an external program and stored in the instance's + // root folder. + Path instanceFolder = Paths.get(".."); + Path mpticket = instanceFolder.resolve("mpticket"); + Path mpticketCorrupt = instanceFolder.resolve("mpticket.corrupt"); - Path mpticketFile = Paths.get(System.getProperty("user.dir"), "..", "mpticket"); - - Path mpticketFileCorrupt = Paths.get(System.getProperty("user.dir"), "..", "mpticket.corrupt"); - - if (Files.exists(mpticketFile)) { + if (Files.exists(mpticket)) { try { - List lines = Files.readAllLines(mpticketFile, StandardCharsets.UTF_8); + List lines = Files.readAllLines(mpticket, StandardCharsets.UTF_8); if (lines.size() < 3) { - Files.move(mpticketFile, mpticketFileCorrupt, StandardCopyOption.REPLACE_EXISTING); + Files.move(mpticket, mpticketCorrupt, StandardCopyOption.REPLACE_EXISTING); - Log.warning("Mpticket file is corrupted!"); + Log.warning("mpticket file is corrupted"); } else { // Assumes parameters are valid and in the correct order - this.launcher.setParameter("server", lines.get(0)); - this.launcher.setParameter("port", lines.get(1)); - this.launcher.setParameter("mppass", lines.get(2)); + launcher.setParameter("server", lines.get(0)); + launcher.setParameter("port", lines.get(1)); + launcher.setParameter("mppass", lines.get(2)); } } catch (IOException e) { - Log.error("Unable to read mpticket file", e); + Log.error("Failed to read mpticket file", e); } } if (serverAddress != null) { - this.launcher.setParameter("server", serverAddress); - this.launcher.setParameter("port", serverPort); + launcher.setParameter("server", serverAddress); + launcher.setParameter("port", serverPort); } - this.launcher.setParameter("username", user); - this.launcher.setParameter("sessionid", session); - this.launcher.setParameter("stand-alone", "true"); // Show the quit button. TODO: why won't this work? - this.launcher.setParameter("haspaid", "true"); // Some old versions need this for world saves to work. - this.launcher.setParameter("demo", isDemo ? "true" : "false"); - this.launcher.setParameter("fullscreen", "false"); + launcher.setParameter("username", user); + launcher.setParameter("sessionid", session); + launcher.setParameter("stand-alone", true); // Show the quit button. TODO: why won't this work? + launcher.setParameter("haspaid", true); // Some old versions need this for world saves to work. + launcher.setParameter("demo", demo); + launcher.setParameter("fullscreen", false); - this.add(this.launcher); + add(launcher); - this.launcher.setPreferredSize(new Dimension(width, height)); + launcher.setPreferredSize(new Dimension(width, height)); - this.pack(); + pack(); - this.setLocationRelativeTo(null); - this.setResizable(true); + setLocationRelativeTo(null); + setResizable(true); if (maximize) setExtendedState(MAXIMIZED_BOTH); - this.validate(); + validate(); - this.launcher.init(); - this.launcher.start(); + launcher.init(); + launcher.start(); - this.setVisible(true); + setVisible(true); } private final class ForceExitHandler extends WindowAdapter { @Override public void windowClosing(WindowEvent event) { + // FIXME better solution + new Thread(new Runnable() { @Override public void run() { @@ -177,9 +176,9 @@ public final class LegacyFrame extends JFrame { } }).start(); - if (LegacyFrame.this.launcher != null) { - LegacyFrame.this.launcher.stop(); - LegacyFrame.this.launcher.destroy(); + if (launcher != null) { + launcher.stop(); + launcher.destroy(); } // old minecraft versions can hang without this >_< diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java index 5ffa9ec5..d349177b 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 flow * Copyright (C) 2022 TheKodeToad @@ -56,17 +55,17 @@ package org.prismlauncher.launcher.impl.legacy; -import org.prismlauncher.launcher.impl.AbstractLauncher; -import org.prismlauncher.utils.Parameters; -import org.prismlauncher.utils.ReflectionUtils; -import org.prismlauncher.utils.logging.Log; - import java.io.File; import java.lang.invoke.MethodHandle; import java.lang.reflect.Field; import java.util.Collections; import java.util.List; +import org.prismlauncher.launcher.impl.AbstractLauncher; +import org.prismlauncher.utils.Parameters; +import org.prismlauncher.utils.ReflectionUtils; +import org.prismlauncher.utils.logging.Log; + /** * Used to launch old versions that support applets. */ @@ -75,51 +74,53 @@ public final class LegacyLauncher extends AbstractLauncher { private final String user, session; private final String title; private final String appletClass; - private final boolean usesApplet; - private final String cwd; + private final boolean useApplet; + private final String gameDir; public LegacyLauncher(Parameters params) { super(params); - this.user = params.getString("userName"); - this.session = params.getString("sessionId"); - this.title = params.getString("windowTitle", "Minecraft"); - this.appletClass = params.getString("appletClass", "net.minecraft.client.MinecraftApplet"); + user = params.getString("userName"); + session = params.getString("sessionId"); + title = params.getString("windowTitle", "Minecraft"); + appletClass = params.getString("appletClass", "net.minecraft.client.MinecraftApplet"); List traits = params.getList("traits", Collections.emptyList()); - this.usesApplet = !traits.contains("noapplet"); + useApplet = !traits.contains("noapplet"); - this.cwd = System.getProperty("user.dir"); + gameDir = System.getProperty("user.dir"); } @Override public void launch() throws Throwable { - Class main = ClassLoader.getSystemClassLoader().loadClass(this.mainClassName); - Field gameDirField = ReflectionUtils.getMinecraftGameDirField(main); + Class main = ClassLoader.getSystemClassLoader().loadClass(mainClassName); + Field gameDirField = ReflectionUtils.findMinecraftGameDirField(main); if (gameDirField == null) - Log.warning("Could not find Minecraft path field"); + Log.warning("Could not find Minecraft folder field"); else { gameDirField.setAccessible(true); - gameDirField.set(null /* field is static, so instance is null */, new File(this.cwd)); + gameDirField.set(null, new File(gameDir)); } - if (this.usesApplet) { - Log.launcher("Launching with applet wrapper..."); + if (useApplet) { + System.setProperty("minecraft.applet.TargetDirectory", gameDir); try { - LegacyFrame window = new LegacyFrame(this.title, ReflectionUtils.createAppletClass(this.appletClass)); + LegacyFrame window = new LegacyFrame(title, ReflectionUtils.createAppletClass(appletClass)); - window.start(this.user, this.session, this.width, this.height, this.maximize, this.serverAddress, - this.serverPort, this.mcParams.contains("--demo")); + window.start(user, session, width, height, maximize, serverAddress, serverPort, + gameArgs.contains("--demo")); return; } catch (Throwable e) { Log.error("Running applet wrapper failed with exception; falling back to main class", e); } } - MethodHandle method = ReflectionUtils.findMainEntrypoint(main); - method.invokeExact(this.mcParams.toArray(new String[0])); + // find and invoke the main method, this time without size parameters + // in all versions that support applets, these are ignored + MethodHandle method = ReflectionUtils.findMainMethod(main); + method.invokeExact(gameArgs.toArray(new String[0])); } } diff --git a/libraries/launcher/org/prismlauncher/utils/Parameters.java b/libraries/launcher/org/prismlauncher/utils/Parameters.java index 7af3c5e8..6365753e 100644 --- a/libraries/launcher/org/prismlauncher/utils/Parameters.java +++ b/libraries/launcher/org/prismlauncher/utils/Parameters.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax @@ -55,40 +54,40 @@ package org.prismlauncher.utils; -import org.prismlauncher.exception.ParameterNotFoundException; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.prismlauncher.exception.ParameterNotFoundException; + public final class Parameters { private final Map> map = new HashMap<>(); public void add(String key, String value) { - List params = this.map.get(key); + List params = map.get(key); if (params == null) { params = new ArrayList<>(); - this.map.put(key, params); + map.put(key, params); } params.add(value); } public List getList(String key) throws ParameterNotFoundException { - List params = this.map.get(key); + List params = map.get(key); if (params == null) - throw ParameterNotFoundException.forParameterName(key); + throw new ParameterNotFoundException(key); return params; } public List getList(String key, List def) { - List params = this.map.get(key); + List params = map.get(key); if (params == null || params.isEmpty()) return def; @@ -97,16 +96,16 @@ public final class Parameters { } public String getString(String key) throws ParameterNotFoundException { - List list = this.getList(key); + List list = getList(key); if (list.isEmpty()) - throw ParameterNotFoundException.forParameterName(key); + throw new ParameterNotFoundException(key); return list.get(0); } public String getString(String key, String def) { - List params = this.map.get(key); + List params = map.get(key); if (params == null || params.isEmpty()) return def; diff --git a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java index 3b299615..dd212ef9 100644 --- a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 solonovamax * Copyright (C) 2022 TheKodeToad @@ -67,68 +66,57 @@ import org.prismlauncher.utils.logging.Log; public final class ReflectionUtils { - private ReflectionUtils() { - } + private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); + private static final ClassLoader LOADER = ClassLoader.getSystemClassLoader(); /** - * Instantiate an applet class by name + * Construct a Java applet by its class name. * - * @param appletClassName The name of the applet class to resolve - * - * @return The instantiated applet class - * - * @throws ClassNotFoundException if the provided class name cannot be found - * @throws NoSuchMethodException if the no-args constructor cannot be found - * @throws IllegalAccessException if the constructor cannot be accessed via - * method handles - * @throws Throwable any exceptions from the class's constructor + * @param clazz The class name + * @return The applet instance + * @throws Throwable */ - public static Applet createAppletClass(String appletClassName) throws Throwable { - Class appletClass = ClassLoader.getSystemClassLoader().loadClass(appletClassName); + public static Applet createAppletClass(String clazz) throws Throwable { + Class appletClass = LOADER.loadClass(clazz); - MethodHandle appletConstructor = MethodHandles.lookup().findConstructor(appletClass, - MethodType.methodType(void.class)); + MethodHandle appletConstructor = LOOKUP.findConstructor(appletClass, MethodType.methodType(void.class)); return (Applet) appletConstructor.invoke(); } /** - * Finds a field that looks like a Minecraft base folder in a supplied class + * Best guess of the game directory field within net.minecraft.client.Minecraft. + * Designed for legacy versions - newer versions do not use a static field. * - * @param minecraftMainClass the class to scan - * - * @return The found field. + * @param clazz The class + * @return The first field matching criteria */ - public static Field getMinecraftGameDirField(Class minecraftMainClass) { + public static Field findMinecraftGameDirField(Class clazz) { Log.debug("Resolving minecraft game directory field"); - // Field we're looking for is always - // private static File obfuscatedName = null; - for (Field field : minecraftMainClass.getDeclaredFields()) { - // Has to be File + + // search for private static File + for (Field field : clazz.getDeclaredFields()) { if (field.getType() != File.class) { continue; } int fieldModifiers = field.getModifiers(); - // Must be static if (!Modifier.isStatic(fieldModifiers)) { Log.debug("Rejecting field " + field.getName() + " because it is not static"); continue; } - // Must be private if (!Modifier.isPrivate(fieldModifiers)) { Log.debug("Rejecting field " + field.getName() + " because it is not private"); continue; } - // Must not be final if (Modifier.isFinal(fieldModifiers)) { Log.debug("Rejecting field " + field.getName() + " because it is final"); continue; } - Log.debug("Identified field " + field.getName() + " to match conditions for minecraft game directory field"); + Log.debug("Identified field " + field.getName() + " to match conditions for game directory field"); return field; } @@ -137,51 +125,30 @@ public final class ReflectionUtils { } /** - * Resolve main entrypoint and returns method handle for it. - *

- * Resolves a method that matches the following signature - * public static void main(String[] args) { - *

- * } - * + * Gets the main method within a class. * - * @param entrypointClass The entrypoint class to resolve the method from - * - * @return The method handle for the resolved entrypoint - * - * @throws NoSuchMethodException If no method matching the correct signature - * can be found - * @throws IllegalAccessException If method handles cannot access the entrypoint + * @param clazz The class + * @return A method matching the descriptor of a main method + * @throws ClassNotFoundException + * @throws NoSuchMethodException + * @throws IllegalAccessException */ - public static MethodHandle findMainEntrypoint(Class entrypointClass) - throws NoSuchMethodException, IllegalAccessException { - return MethodHandles.lookup().findStatic(entrypointClass, "main", - MethodType.methodType(void.class, String[].class)); + public static MethodHandle findMainMethod(Class clazz) throws NoSuchMethodException, IllegalAccessException { + return LOOKUP.findStatic(clazz, "main", MethodType.methodType(void.class, String[].class)); } /** - * Resolve main entrypoint and returns method handle for it. - *

- * Resolves a method that matches the following signature - * public static void main(String[] args) { - *

- * } - * + * Gets the main method within a class by its name. * - * @param entrypointClassName The name of the entrypoint class to resolve the - * method from - * - * @return The method handle for the resolved entrypoint - * - * @throws ClassNotFoundException If a class cannot be found with the provided - * name - * @throws NoSuchMethodException If no method matching the correct signature - * can be found - * @throws IllegalAccessException If method handles cannot access the entrypoint + * @param clazz The class name + * @return A method matching the descriptor of a main method + * @throws ClassNotFoundException + * @throws NoSuchMethodException + * @throws IllegalAccessException */ - public static MethodHandle findMainMethod(String entrypointClassName) + public static MethodHandle findMainMethod(String clazz) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException { - return findMainEntrypoint(ClassLoader.getSystemClassLoader().loadClass(entrypointClassName)); + return findMainMethod(LOADER.loadClass(clazz)); } } diff --git a/libraries/launcher/org/prismlauncher/utils/StringUtils.java b/libraries/launcher/org/prismlauncher/utils/StringUtils.java index a371b0cb..dfd1634b 100644 --- a/libraries/launcher/org/prismlauncher/utils/StringUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/StringUtils.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 solonovamax * * This program is free software: you can redistribute it and/or modify @@ -38,15 +37,13 @@ package org.prismlauncher.utils; public final class StringUtils { - private StringUtils() { - } + public static String[] splitStringPair(char splitChar, String str) { + int splitPoint = str.indexOf(splitChar); - public static String[] splitStringPair(char splitChar, String input) { - int splitPoint = input.indexOf(splitChar); if (splitPoint == -1) return null; - return new String[] { input.substring(0, splitPoint), input.substring(splitPoint + 1) }; + return new String[] { str.substring(0, splitPoint), str.substring(splitPoint + 1) }; } } diff --git a/libraries/launcher/org/prismlauncher/utils/logging/Level.java b/libraries/launcher/org/prismlauncher/utils/logging/Level.java index 330cec28..552b0b55 100644 --- a/libraries/launcher/org/prismlauncher/utils/logging/Level.java +++ b/libraries/launcher/org/prismlauncher/utils/logging/Level.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 TheKodeToad * * This program is free software: you can redistribute it and/or modify @@ -36,8 +36,13 @@ package org.prismlauncher.utils.logging; public enum Level { - LAUNCHER("Launcher"), DEBUG("Debug"), INFO("Info"), MESSAGE("Message"), - WARNING("Warning"), ERROR("Error", true), FATAL("Fatal", true); + LAUNCHER("Launcher"), + DEBUG("Debug"), + INFO("Info"), + MESSAGE("Message"), + WARNING("Warning"), + ERROR("Error", true), + FATAL("Fatal", true); String name; boolean stderr; diff --git a/libraries/launcher/org/prismlauncher/utils/logging/Log.java b/libraries/launcher/org/prismlauncher/utils/logging/Log.java index e1961991..374a8107 100644 --- a/libraries/launcher/org/prismlauncher/utils/logging/Log.java +++ b/libraries/launcher/org/prismlauncher/utils/logging/Log.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 TheKodeToad * * This program is free software: you can redistribute it and/or modify @@ -44,37 +44,12 @@ import java.io.PrintStream; */ public final class Log { - private static final PrintStream ERROR_PREFIX = new PrintStream(System.err) { - @Override - public void println(String x) { - error(x); - } - - @Override - public void println(Object x) { - error(String.valueOf(x)); - } - }, FATAL_PREFIX = new PrintStream(System.err) { - @Override - public void println(String x) { - fatal(x); - } - - @Override - public void println(Object x) { - fatal(String.valueOf(x)); - } - }; - + // original before overridden + private static final PrintStream OUT = new PrintStream(System.out), ERR = new PrintStream(System.err); + private static final PrintStream ERROR_PREFIX = new LogPrintStream(System.err, Level.ERROR), + FATAL_PREFIX = new LogPrintStream(System.err, Level.FATAL); private static final boolean DEBUG = Boolean.getBoolean("org.prismlauncher.debug"); - private Log() { - } - - public static void blankLine() { - System.out.println(); - } - public static void launcher(String message) { log(message, Level.LAUNCHER); } @@ -84,16 +59,9 @@ public final class Log { } public static void debug(String message) { - if (!DEBUG) - return; - log(message, Level.DEBUG); } - public static void info(String message) { - log(message, Level.INFO); - } - public static void warning(String message) { log(message, Level.WARNING); } @@ -113,12 +81,16 @@ public final class Log { } /** - * Logs a message with the prefix !![LEVEL]!. + * Logs a message with the prefix !![LEVEL]!. This is picked up by + * the log viewer to give it nice colours. * * @param message The message * @param level The level */ public static void log(String message, Level level) { + if (!DEBUG && level == Level.DEBUG) + return; + String prefix = "!![" + level.name + "]!"; // prefix first line message = prefix + message; @@ -126,9 +98,9 @@ public final class Log { message = message.replace("\n", "\n" + prefix); if (level.stderr) - System.err.println(message); + ERR.println(message); else - System.out.println(message); + OUT.println(message); } } diff --git a/libraries/launcher/org/prismlauncher/utils/logging/LogPrintStream.java b/libraries/launcher/org/prismlauncher/utils/logging/LogPrintStream.java new file mode 100644 index 00000000..8a182817 --- /dev/null +++ b/libraries/launcher/org/prismlauncher/utils/logging/LogPrintStream.java @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2022 TheKodeToad + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give + * you permission to link this library with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also meet, + * for each linked independent module, the terms and conditions of the + * license of that module. An independent module is a module which is + * not derived from or based on this library. If you modify this + * library, you may extend this exception to your version of the + * library, but you are not obliged to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.prismlauncher.utils.logging; + +import java.io.OutputStream; +import java.io.PrintStream; + +/** + * Used to create a print stream that redirects to Log. + */ +final class LogPrintStream extends PrintStream { + + private final Level level; + + public LogPrintStream(OutputStream out, Level level) { + super(out); + + this.level = level; + } + + @Override + public void println(String x) { + Log.log(x, level); + } + + @Override + public void println(Object x) { + println(String.valueOf(x)); + } + + @Override + public void println(boolean x) { + println(String.valueOf(x)); + } + + @Override + public void println(char x) { + println(String.valueOf(x)); + } + + @Override + public void println(int x) { + println(String.valueOf(x)); + } + + @Override + public void println(long x) { + println(String.valueOf(x)); + } + + @Override + public void println(float x) { + println(String.valueOf(x)); + } + + @Override + public void println(double x) { + println(String.valueOf(x)); + } + + @Override + public void println(char[] x) { + println(String.valueOf(x)); + } + +} \ No newline at end of file From ddfb449b28fb24f1c3e4ed3802ee4415206f96f1 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sat, 22 Oct 2022 20:01:39 +0200 Subject: [PATCH 38/52] fix: remove PolyMC data paths Signed-off-by: Sefa Eyeoglu --- launcher/Application.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 45cd9422..e2fdcd63 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -301,22 +301,6 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) dataPath = foo.absolutePath(); adjustedBy = "Persistent data path"; - QDir polymcData(FS::PathCombine(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation), "PolyMC")); - if (polymcData.exists()) { - dataPath = polymcData.absolutePath(); - adjustedBy = "PolyMC data path"; - } - -#ifdef Q_OS_LINUX - // TODO: this should be removed in a future version - // TODO: provide a migration path similar to macOS migration - QDir bar(FS::PathCombine(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation), "polymc")); - if (bar.exists()) { - dataPath = bar.absolutePath(); - adjustedBy = "Legacy data path"; - } -#endif - #ifndef Q_OS_MACOS if (QFile::exists(FS::PathCombine(m_rootPath, "portable.txt"))) { dataPath = m_rootPath; From e048bce13ea4bd56ef96ba7a1a4699142d09600a Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sat, 22 Oct 2022 23:25:14 +0200 Subject: [PATCH 39/52] refactor: allow copy operation with whitelist Signed-off-by: Sefa Eyeoglu --- launcher/FileSystem.cpp | 2 +- launcher/FileSystem.h | 12 +++++++++--- launcher/InstanceCopyTask.cpp | 2 +- tests/FileSystem_test.cpp | 37 ++++++++++++++++++++++++++++++++++- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 4a8f4bd3..a3b9fe1f 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -174,7 +174,7 @@ bool copy::operator()(const QString& offset) // Function that'll do the actual copying auto copy_file = [&](QString src_path, QString relative_dst_path) { - if (m_blacklist && m_blacklist->matches(relative_dst_path)) + if (m_matcher && (m_matcher->matches(relative_dst_path) == !m_whitelist)) return; auto dst_path = PathCombine(dst, relative_dst_path); diff --git a/launcher/FileSystem.h b/launcher/FileSystem.h index b7e175fd..e239984e 100644 --- a/launcher/FileSystem.h +++ b/launcher/FileSystem.h @@ -88,9 +88,14 @@ class copy { m_followSymlinks = follow; return *this; } - copy& blacklist(const IPathMatcher* filter) + copy& matcher(const IPathMatcher* filter) { - m_blacklist = filter; + m_matcher = filter; + return *this; + } + copy& whitelist(bool whitelist) + { + m_whitelist = whitelist; return *this; } bool operator()() { return operator()(QString()); } @@ -100,7 +105,8 @@ class copy { private: bool m_followSymlinks = true; - const IPathMatcher* m_blacklist = nullptr; + const IPathMatcher* m_matcher = nullptr; + bool m_whitelist = false; QDir m_src; QDir m_dst; }; diff --git a/launcher/InstanceCopyTask.cpp b/launcher/InstanceCopyTask.cpp index a4ea947d..fb118353 100644 --- a/launcher/InstanceCopyTask.cpp +++ b/launcher/InstanceCopyTask.cpp @@ -26,7 +26,7 @@ void InstanceCopyTask::executeTask() setStatus(tr("Copying instance %1").arg(m_origInstance->name())); FS::copy folderCopy(m_origInstance->instanceRoot(), m_stagingPath); - folderCopy.followSymlinks(false).blacklist(m_matcher.get()); + folderCopy.followSymlinks(false).matcher(m_matcher.get()); m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), folderCopy); connect(&m_copyFutureWatcher, &QFutureWatcher::finished, this, &InstanceCopyTask::copyFinished); diff --git a/tests/FileSystem_test.cpp b/tests/FileSystem_test.cpp index 21270f6f..3a5c38d0 100644 --- a/tests/FileSystem_test.cpp +++ b/tests/FileSystem_test.cpp @@ -126,7 +126,7 @@ slots: qDebug() << tempDir.path(); qDebug() << target_dir.path(); FS::copy c(folder, target_dir.path()); - c.blacklist(new RegexpMatcher("[.]?mcmeta")); + c.matcher(new RegexpMatcher("[.]?mcmeta")); c(); for(auto entry: target_dir.entryList()) @@ -147,6 +147,41 @@ slots: f(); } + void test_copy_with_whitelist() + { + QString folder = QFINDTESTDATA("testdata/FileSystem/test_folder"); + auto f = [&folder]() + { + QTemporaryDir tempDir; + tempDir.setAutoRemove(true); + qDebug() << "From:" << folder << "To:" << tempDir.path(); + + QDir target_dir(FS::PathCombine(tempDir.path(), "test_folder")); + qDebug() << tempDir.path(); + qDebug() << target_dir.path(); + FS::copy c(folder, target_dir.path()); + c.matcher(new RegexpMatcher("[.]?mcmeta")); + c.whitelist(true); + c(); + + for(auto entry: target_dir.entryList()) + { + qDebug() << entry; + } + QVERIFY(target_dir.entryList().contains("pack.mcmeta")); + QVERIFY(!target_dir.entryList().contains("assets")); + }; + + // first try variant without trailing / + QVERIFY(!folder.endsWith('/')); + f(); + + // then variant with trailing / + folder.append('/'); + QVERIFY(folder.endsWith('/')); + f(); + } + void test_copy_with_dot_hidden() { QString folder = QFINDTESTDATA("testdata/FileSystem/test_folder"); From 15aaff7c1ce8d709c444d891bf640ee39494d10e Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sat, 22 Oct 2022 23:36:47 +0200 Subject: [PATCH 40/52] feat: add dryRun to copy operation Signed-off-by: Sefa Eyeoglu --- launcher/FileSystem.cpp | 10 ++++++---- launcher/FileSystem.h | 18 ++++++++++++++---- launcher/InstanceCopyTask.cpp | 4 +++- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index a3b9fe1f..06691fbf 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -152,9 +152,10 @@ bool ensureFolderPathExists(QString foldernamepath) /// @brief Copies a directory and it's contents from src to dest /// @param offset subdirectory form src to copy to dest /// @return if there was an error during the filecopy -bool copy::operator()(const QString& offset) +bool copy::operator()(const QString& offset, bool dryRun) { using copy_opts = fs::copy_options; + m_copied = 0; // reset counter // NOTE always deep copy on windows. the alternatives are too messy. #if defined Q_OS_WIN32 @@ -178,9 +179,10 @@ bool copy::operator()(const QString& offset) return; auto dst_path = PathCombine(dst, relative_dst_path); - ensureFilePathExists(dst_path); - - fs::copy(StringUtils::toStdString(src_path), StringUtils::toStdString(dst_path), opt, err); + if (!dryRun) { + ensureFilePathExists(dst_path); + fs::copy(StringUtils::toStdString(src_path), StringUtils::toStdString(dst_path), opt, err); + } if (err) { qWarning() << "Failed to copy files:" << QString::fromStdString(err.message()); qDebug() << "Source file:" << src_path; diff --git a/launcher/FileSystem.h b/launcher/FileSystem.h index e239984e..a9a81123 100644 --- a/launcher/FileSystem.h +++ b/launcher/FileSystem.h @@ -40,6 +40,7 @@ #include #include +#include namespace FS { @@ -76,9 +77,10 @@ bool ensureFilePathExists(QString filenamepath); bool ensureFolderPathExists(QString filenamepath); /// @brief Copies a directory and it's contents from src to dest -class copy { +class copy : public QObject { + Q_OBJECT public: - copy(const QString& src, const QString& dst) + copy(const QString& src, const QString& dst, QObject* parent = nullptr) : QObject(parent) { m_src.setPath(src); m_dst.setPath(dst); @@ -98,10 +100,17 @@ class copy { m_whitelist = whitelist; return *this; } - bool operator()() { return operator()(QString()); } + + bool operator()(bool dryRun = false) { return operator()(QString(), dryRun); } + + int totalCopied() { return m_copied; } + + signals: + void fileCopied(const QString& relativeName); + // TODO: maybe add a "shouldCopy" signal in the future? private: - bool operator()(const QString& offset); + bool operator()(const QString& offset, bool dryRun = false); private: bool m_followSymlinks = true; @@ -109,6 +118,7 @@ class copy { bool m_whitelist = false; QDir m_src; QDir m_dst; + int m_copied; }; /** diff --git a/launcher/InstanceCopyTask.cpp b/launcher/InstanceCopyTask.cpp index fb118353..0a83ed9c 100644 --- a/launcher/InstanceCopyTask.cpp +++ b/launcher/InstanceCopyTask.cpp @@ -28,7 +28,9 @@ void InstanceCopyTask::executeTask() FS::copy folderCopy(m_origInstance->instanceRoot(), m_stagingPath); folderCopy.followSymlinks(false).matcher(m_matcher.get()); - m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), folderCopy); + m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), [&folderCopy]{ + return folderCopy(); + }); connect(&m_copyFutureWatcher, &QFutureWatcher::finished, this, &InstanceCopyTask::copyFinished); connect(&m_copyFutureWatcher, &QFutureWatcher::canceled, this, &InstanceCopyTask::copyAborted); m_copyFutureWatcher.setFuture(m_copyFuture); From bd7065eece443de59adbe47dd7d9bd16e1d35ff5 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sun, 23 Oct 2022 00:44:57 +0200 Subject: [PATCH 41/52] feat: add SimplePrefixMatcher Signed-off-by: Sefa Eyeoglu --- launcher/CMakeLists.txt | 1 + launcher/pathmatcher/SimplePrefixMatcher.h | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 launcher/pathmatcher/SimplePrefixMatcher.h diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 8db93429..45d197ef 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -97,6 +97,7 @@ set(PATHMATCHER_SOURCES pathmatcher/IPathMatcher.h pathmatcher/MultiMatcher.h pathmatcher/RegexpMatcher.h + pathmatcher/SimplePrefixMatcher.h ) set(NET_SOURCES diff --git a/launcher/pathmatcher/SimplePrefixMatcher.h b/launcher/pathmatcher/SimplePrefixMatcher.h new file mode 100644 index 00000000..191d010c --- /dev/null +++ b/launcher/pathmatcher/SimplePrefixMatcher.h @@ -0,0 +1,21 @@ +#include +#include "IPathMatcher.h" + +class SimplePrefixMatcher : public IPathMatcher { + public: + virtual ~SimplePrefixMatcher(){}; + SimplePrefixMatcher(const QString& prefix) + { + m_prefix = prefix; + m_isPrefix = prefix.endsWith('/'); + } + + virtual bool matches(const QString& string) const override + { + if (m_isPrefix) + return string.startsWith(m_prefix); + return string == m_prefix; + } + QString m_prefix; + bool m_isPrefix = false; +}; From 086304f7f24e70bfa35b26a7406930b0840f699b Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sun, 23 Oct 2022 01:45:32 +0200 Subject: [PATCH 42/52] feat: add initial Migration dialog Signed-off-by: Sefa Eyeoglu --- launcher/Application.cpp | 99 ++++++++++++++++++++++++++++++++++ launcher/Application.h | 1 + launcher/CMakeLists.txt | 2 + launcher/DataMigrationTask.cpp | 79 +++++++++++++++++++++++++++ launcher/DataMigrationTask.h | 38 +++++++++++++ 5 files changed, 219 insertions(+) create mode 100644 launcher/DataMigrationTask.cpp create mode 100644 launcher/DataMigrationTask.h diff --git a/launcher/Application.cpp b/launcher/Application.cpp index e2fdcd63..2a7d6f22 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -38,10 +38,14 @@ #include "Application.h" #include "BuildConfig.h" +#include "DataMigrationTask.h" #include "net/PasteUpload.h" +#include "pathmatcher/MultiMatcher.h" +#include "pathmatcher/SimplePrefixMatcher.h" #include "ui/MainWindow.h" #include "ui/InstanceWindow.h" +#include "ui/dialogs/ProgressDialog.h" #include "ui/instanceview/AccessibleInstanceView.h" #include "ui/pages/BasePageProvider.h" @@ -423,6 +427,15 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) qDebug() << "<> Log initialized."; } + { + bool migrated = false; + + if (!migrated) + migrated = handleDataMigration(dataPath, FS::PathCombine(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation), "../../PolyMC"), "PolyMC", "polymc.cfg"); + if (!migrated) + migrated = handleDataMigration(dataPath, FS::PathCombine(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation), "../../multimc"), "MultiMC", "multimc.cfg"); + } + { qDebug() << BuildConfig.LAUNCHER_DISPLAYNAME << ", (c) 2013-2021 " << BuildConfig.LAUNCHER_COPYRIGHT; @@ -1589,3 +1602,89 @@ int Application::suitableMaxMem() return maxMemoryAlloc; } + +bool Application::handleDataMigration(const QString& currentData, + const QString& oldData, + const QString& name, + const QString& configFile) const +{ + QString nomigratePath = FS::PathCombine(oldData, BuildConfig.LAUNCHER_NAME + "_nomigrate.txt"); + QStringList configPaths = { FS::PathCombine(oldData, configFile), FS::PathCombine(oldData, BuildConfig.LAUNCHER_CONFIGFILE) }; + + QDir dir; // helper for QDir::exists + QLocale locale; + + // Is there a valid config at the old location? + bool configExists = false; + for (QString configPath : configPaths) { + configExists |= QFileInfo::exists(configPath); + } + + if (!configExists || QFileInfo::exists(nomigratePath)) { + qDebug() << "<> No migration needed from" << name; + return false; + } + + QString message; + bool currentExists = QFileInfo::exists(FS::PathCombine(currentData, BuildConfig.LAUNCHER_CONFIGFILE)); + + if (currentExists) { + message = tr("Old data from %1 was found, but you already have existing data for %2. Sadly you will need to migrate yourself. Do " + "you want to be reminded of the pending data migration next time you start %2?") + .arg(name, BuildConfig.LAUNCHER_DISPLAYNAME); + } else { + message = tr("It looks like you used %1 before. Do you want to migrate your data to the new location of %2?") + .arg(name, BuildConfig.LAUNCHER_DISPLAYNAME); + + QFileInfo logInfo(FS::PathCombine(oldData, name + "-0.log")); + if (logInfo.exists()) { + QString lastModified = logInfo.lastModified().toString(locale.dateFormat()); + message = tr("It looks like you used %1 on %2 before. Do you want to migrate your data to the new location of %3?") + .arg(name, lastModified, BuildConfig.LAUNCHER_DISPLAYNAME); + } + } + + QMessageBox::StandardButton askMoveDialogue = + QMessageBox::question(nullptr, BuildConfig.LAUNCHER_DISPLAYNAME, message, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); + + auto setDoNotMigrate = [&nomigratePath] { + QFile file(nomigratePath); + file.open(QIODevice::WriteOnly); + }; + + // create no-migrate file if user doesn't want to migrate + if (askMoveDialogue != QMessageBox::Yes) { + qDebug() << "<> Migration declined for" << name; + setDoNotMigrate(); + return currentExists; // cancel further migrations, if we already have a data directory + } + + if (!currentExists) { + // Migrate! + auto matcher = std::make_shared(); + matcher->add(std::make_shared(configFile)); + matcher->add(std::make_shared( + BuildConfig.LAUNCHER_CONFIGFILE)); // it's possible that we already used that directory before + matcher->add(std::make_shared("accounts.json")); + matcher->add(std::make_shared("accounts/")); + matcher->add(std::make_shared("assets/")); + matcher->add(std::make_shared("icons/")); + matcher->add(std::make_shared("instances/")); + matcher->add(std::make_shared("libraries/")); + matcher->add(std::make_shared("mods/")); + matcher->add(std::make_shared("themes/")); + + ProgressDialog diag = ProgressDialog(); + DataMigrationTask task(nullptr, oldData, currentData, matcher); + if (diag.execWithTask(&task)) { + qDebug() << "<> Migration succeeded"; + setDoNotMigrate(); + } else { + QString reason = task.failReason(); + QMessageBox::critical(nullptr, BuildConfig.LAUNCHER_DISPLAYNAME, tr("Migration failed! Reason: %1").arg(reason)); + } + } else { + qWarning() << "<> Migration was skipped, due to existing data"; + } + return true; +} diff --git a/launcher/Application.h b/launcher/Application.h index 4c2f62d4..7884227a 100644 --- a/launcher/Application.h +++ b/launcher/Application.h @@ -231,6 +231,7 @@ private slots: void setupWizardFinished(int status); private: + bool handleDataMigration(const QString & currentData, const QString & oldData, const QString & name, const QString & configFile) const; bool createSetupWizard(); void performMainStartupAction(); diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 45d197ef..7a577935 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -576,6 +576,8 @@ SET(LAUNCHER_SOURCES # Application base Application.h Application.cpp + DataMigrationTask.h + DataMigrationTask.cpp UpdateController.cpp UpdateController.h ApplicationMessage.h diff --git a/launcher/DataMigrationTask.cpp b/launcher/DataMigrationTask.cpp new file mode 100644 index 00000000..8e7f4579 --- /dev/null +++ b/launcher/DataMigrationTask.cpp @@ -0,0 +1,79 @@ +#include "DataMigrationTask.h" + +#include "FileSystem.h" + +#include +#include +#include + +#include + +DataMigrationTask::DataMigrationTask(QObject* parent, + const QString& sourcePath, + const QString& targetPath, + const IPathMatcher::Ptr pathMatcher) + : Task(parent), m_sourcePath(sourcePath), m_targetPath(targetPath), m_pathMatcher(pathMatcher), m_copy(sourcePath, targetPath) +{ + m_copy.matcher(m_pathMatcher.get()).whitelist(true); +} + +void DataMigrationTask::executeTask() +{ + setStatus(tr("Scanning files...")); + + // 1. Scan + // Check how many files we gotta copy + m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), [&] { + return m_copy(true); // dry run to collect amount of files + }); + connect(&m_copyFutureWatcher, &QFutureWatcher::finished, this, &DataMigrationTask::dryRunFinished); + connect(&m_copyFutureWatcher, &QFutureWatcher::canceled, this, &DataMigrationTask::dryRunAborted); + m_copyFutureWatcher.setFuture(m_copyFuture); +} + +void DataMigrationTask::dryRunFinished() +{ + disconnect(&m_copyFutureWatcher, &QFutureWatcher::finished, this, &DataMigrationTask::dryRunFinished); + disconnect(&m_copyFutureWatcher, &QFutureWatcher::canceled, this, &DataMigrationTask::dryRunAborted); + + if (!m_copyFuture.result()) { + emitFailed("Some error"); // FIXME + return; + } + + setStatus(tr("Migrating...")); + + // 2. Copy + // Actually copy all files now. + m_toCopy = m_copy.totalCopied(); + connect(&m_copy, &FS::copy::fileCopied, [&, this] { setProgress(m_copy.totalCopied(), m_toCopy); }); + m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), [&] { + return m_copy(false); // actually copy now + }); + connect(&m_copyFutureWatcher, &QFutureWatcher::finished, this, &DataMigrationTask::copyFinished); + connect(&m_copyFutureWatcher, &QFutureWatcher::canceled, this, &DataMigrationTask::copyAborted); + m_copyFutureWatcher.setFuture(m_copyFuture); +} + +void DataMigrationTask::dryRunAborted() +{ + emitFailed(tr("Aborted")); +} + +void DataMigrationTask::copyFinished() +{ + disconnect(&m_copyFutureWatcher, &QFutureWatcher::finished, this, &DataMigrationTask::copyFinished); + disconnect(&m_copyFutureWatcher, &QFutureWatcher::canceled, this, &DataMigrationTask::copyAborted); + + if (!m_copyFuture.result()) { + emitFailed("Some paths could not be copied!"); + return; + } + + emitSucceeded(); +} + +void DataMigrationTask::copyAborted() +{ + emitFailed(tr("Aborted")); +} diff --git a/launcher/DataMigrationTask.h b/launcher/DataMigrationTask.h new file mode 100644 index 00000000..105a9493 --- /dev/null +++ b/launcher/DataMigrationTask.h @@ -0,0 +1,38 @@ +#pragma once + +#include "FileSystem.h" +#include "pathmatcher/IPathMatcher.h" +#include "tasks/Task.h" + +#include +#include + +/* + * Migrate existing data from other MMC-like launchers. + */ + +class DataMigrationTask : public Task { + Q_OBJECT + public: + explicit DataMigrationTask(QObject* parent, const QString& sourcePath, const QString& targetPath, const IPathMatcher::Ptr pathmatcher); + ~DataMigrationTask() override = default; + + protected: + virtual void executeTask() override; + + protected slots: + void dryRunFinished(); + void dryRunAborted(); + void copyFinished(); + void copyAborted(); + + private: + const QString& m_sourcePath; + const QString& m_targetPath; + const IPathMatcher::Ptr m_pathMatcher; + + FS::copy m_copy; + int m_toCopy = 0; + QFuture m_copyFuture; + QFutureWatcher m_copyFutureWatcher; +}; From bbb7e9f5c722039ba8b4fbd00fba78f65613b0a9 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sun, 23 Oct 2022 14:24:11 +0200 Subject: [PATCH 43/52] feat: show current copy operation in migration dialog Signed-off-by: Sefa Eyeoglu --- launcher/DataMigrationTask.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/launcher/DataMigrationTask.cpp b/launcher/DataMigrationTask.cpp index 8e7f4579..fb2907fb 100644 --- a/launcher/DataMigrationTask.cpp +++ b/launcher/DataMigrationTask.cpp @@ -41,12 +41,17 @@ void DataMigrationTask::dryRunFinished() return; } - setStatus(tr("Migrating...")); - // 2. Copy // Actually copy all files now. m_toCopy = m_copy.totalCopied(); - connect(&m_copy, &FS::copy::fileCopied, [&, this] { setProgress(m_copy.totalCopied(), m_toCopy); }); + connect(&m_copy, &FS::copy::fileCopied, [&, this](const QString& relativeName) { + QString shortenedName = relativeName; + // shorten the filename to hopefully fit into one line + if (shortenedName.length() > 50) + shortenedName = relativeName.left(20) + "…" + relativeName.right(29); + setProgress(m_copy.totalCopied(), m_toCopy); + setStatus(tr("Copying %1…").arg(shortenedName)); + }); m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), [&] { return m_copy(false); // actually copy now }); From 335bec68fb803f0a06400585b1dc4c2341951c7c Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sun, 23 Oct 2022 14:27:46 +0200 Subject: [PATCH 44/52] fix: prevent abort for un-abortable tasks Signed-off-by: Sefa Eyeoglu --- launcher/ui/dialogs/ProgressDialog.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/launcher/ui/dialogs/ProgressDialog.cpp b/launcher/ui/dialogs/ProgressDialog.cpp index 05269f62..da73a449 100644 --- a/launcher/ui/dialogs/ProgressDialog.cpp +++ b/launcher/ui/dialogs/ProgressDialog.cpp @@ -44,7 +44,8 @@ void ProgressDialog::setSkipButton(bool present, QString label) void ProgressDialog::on_skipButton_clicked(bool checked) { Q_UNUSED(checked); - task->abort(); + if (ui->skipButton->isEnabled()) // prevent other triggers from aborting + task->abort(); } ProgressDialog::~ProgressDialog() From 173aed7fd8e73b9e6a6055981ce284ea9cf5d33a Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Mon, 24 Oct 2022 21:50:35 +0200 Subject: [PATCH 45/52] chore: add REUSE headers Signed-off-by: Sefa Eyeoglu --- launcher/Application.cpp | 5 ++++- launcher/DataMigrationTask.cpp | 4 ++++ launcher/DataMigrationTask.h | 4 ++++ launcher/pathmatcher/SimplePrefixMatcher.h | 4 ++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 2a7d6f22..8955e297 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -1,4 +1,7 @@ -// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: 2022 Sefa Eyeoglu +// +// SPDX-License-Identifier: GPL-3.0-only AND Apache-2.0 + /* * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu diff --git a/launcher/DataMigrationTask.cpp b/launcher/DataMigrationTask.cpp index fb2907fb..8de3158e 100644 --- a/launcher/DataMigrationTask.cpp +++ b/launcher/DataMigrationTask.cpp @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2022 Sefa Eyeoglu +// +// SPDX-License-Identifier: GPL-3.0-only + #include "DataMigrationTask.h" #include "FileSystem.h" diff --git a/launcher/DataMigrationTask.h b/launcher/DataMigrationTask.h index 105a9493..6cc23b1a 100644 --- a/launcher/DataMigrationTask.h +++ b/launcher/DataMigrationTask.h @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2022 Sefa Eyeoglu +// +// SPDX-License-Identifier: GPL-3.0-only + #pragma once #include "FileSystem.h" diff --git a/launcher/pathmatcher/SimplePrefixMatcher.h b/launcher/pathmatcher/SimplePrefixMatcher.h index 191d010c..fc1f5ced 100644 --- a/launcher/pathmatcher/SimplePrefixMatcher.h +++ b/launcher/pathmatcher/SimplePrefixMatcher.h @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2022 Sefa Eyeoglu +// +// SPDX-License-Identifier: GPL-3.0-only + #include #include "IPathMatcher.h" From fe94c3609ef875166b71b9f6c540c45eff97a5ab Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Thu, 10 Nov 2022 19:04:42 +0100 Subject: [PATCH 46/52] fix: implement code review suggestions Signed-off-by: Sefa Eyeoglu --- launcher/Application.cpp | 5 ++--- launcher/DataMigrationTask.cpp | 12 ++++++++++-- launcher/FileSystem.cpp | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 8955e297..537e3903 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -1611,10 +1611,9 @@ bool Application::handleDataMigration(const QString& currentData, const QString& name, const QString& configFile) const { - QString nomigratePath = FS::PathCombine(oldData, BuildConfig.LAUNCHER_NAME + "_nomigrate.txt"); + QString nomigratePath = FS::PathCombine(currentData, name + "_nomigrate.txt"); QStringList configPaths = { FS::PathCombine(oldData, configFile), FS::PathCombine(oldData, BuildConfig.LAUNCHER_CONFIGFILE) }; - QDir dir; // helper for QDir::exists QLocale locale; // Is there a valid config at the old location? @@ -1677,7 +1676,7 @@ bool Application::handleDataMigration(const QString& currentData, matcher->add(std::make_shared("mods/")); matcher->add(std::make_shared("themes/")); - ProgressDialog diag = ProgressDialog(); + ProgressDialog diag; DataMigrationTask task(nullptr, oldData, currentData, matcher); if (diag.execWithTask(&task)) { qDebug() << "<> Migration succeeded"; diff --git a/launcher/DataMigrationTask.cpp b/launcher/DataMigrationTask.cpp index 8de3158e..27ce5f01 100644 --- a/launcher/DataMigrationTask.cpp +++ b/launcher/DataMigrationTask.cpp @@ -40,8 +40,12 @@ void DataMigrationTask::dryRunFinished() disconnect(&m_copyFutureWatcher, &QFutureWatcher::finished, this, &DataMigrationTask::dryRunFinished); disconnect(&m_copyFutureWatcher, &QFutureWatcher::canceled, this, &DataMigrationTask::dryRunAborted); +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + if (!m_copyFuture.isValid() || !m_copyFuture.result()) { +#else if (!m_copyFuture.result()) { - emitFailed("Some error"); // FIXME +#endif + emitFailed(tr("Failed to scan source path.")); return; } @@ -74,8 +78,12 @@ void DataMigrationTask::copyFinished() disconnect(&m_copyFutureWatcher, &QFutureWatcher::finished, this, &DataMigrationTask::copyFinished); disconnect(&m_copyFutureWatcher, &QFutureWatcher::canceled, this, &DataMigrationTask::copyAborted); +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + if (!m_copyFuture.isValid() || !m_copyFuture.result()) { +#else if (!m_copyFuture.result()) { - emitFailed("Some paths could not be copied!"); +#endif + emitFailed(tr("Some paths could not be copied!")); return; } diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 06691fbf..0c6527b1 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -175,7 +175,7 @@ bool copy::operator()(const QString& offset, bool dryRun) // Function that'll do the actual copying auto copy_file = [&](QString src_path, QString relative_dst_path) { - if (m_matcher && (m_matcher->matches(relative_dst_path) == !m_whitelist)) + if (m_matcher && (m_matcher->matches(relative_dst_path) != m_whitelist)) return; auto dst_path = PathCombine(dst, relative_dst_path); From 669eef92eb426ea500c3bdaf5ec5b07d98e7c637 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sat, 19 Nov 2022 08:54:17 +0000 Subject: [PATCH 47/52] Make requested changes and utilise AssertionError Signed-off-by: TheKodeToad --- libraries/launcher/CMakeLists.txt | 1 - .../launcher/net/minecraft/Launcher.java | 10 ++-- .../org/prismlauncher/EntryPoint.java | 5 +- .../launcher/impl/AbstractLauncher.java | 5 +- .../org/prismlauncher/utils/StringUtils.java | 49 ------------------- 5 files changed, 7 insertions(+), 63 deletions(-) delete mode 100644 libraries/launcher/org/prismlauncher/utils/StringUtils.java diff --git a/libraries/launcher/CMakeLists.txt b/libraries/launcher/CMakeLists.txt index 1d22a93e..55ed5875 100644 --- a/libraries/launcher/CMakeLists.txt +++ b/libraries/launcher/CMakeLists.txt @@ -17,7 +17,6 @@ set(SRC org/prismlauncher/exception/ParseException.java org/prismlauncher/utils/Parameters.java org/prismlauncher/utils/ReflectionUtils.java - org/prismlauncher/utils/StringUtils.java org/prismlauncher/utils/logging/Level.java org/prismlauncher/utils/logging/Log.java net/minecraft/Launcher.java diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java index a721495a..646e2e3e 100644 --- a/libraries/launcher/net/minecraft/Launcher.java +++ b/libraries/launcher/net/minecraft/Launcher.java @@ -64,8 +64,6 @@ import java.net.URL; import java.util.HashMap; import java.util.Map; -import org.prismlauncher.utils.logging.Log; - /** * WARNING: This class is reflectively accessed by legacy Forge versions. *

@@ -97,14 +95,13 @@ public final class Launcher extends Applet implements AppletStub { if (documentBase == null) { if (applet.getClass().getPackage().getName().startsWith("com.mojang.")) { // Special case only for Classic versions - documentBase = new URL("http", "www.minecraft.net", 80, "/game/"); + documentBase = new URL("http://www.minecraft.net:80/game/"); } else { documentBase = new URL("http://www.minecraft.net/game/"); } } } catch (MalformedURLException e) { - // handle gracefully - it won't happen, but Java requires that it is caught - Log.error("Failed to parse document base URL", e); + throw new AssertionError(e); } this.documentBase = documentBase; @@ -143,8 +140,7 @@ public final class Launcher extends Applet implements AppletStub { try { return new URL("http://www.minecraft.net/game/"); } catch (MalformedURLException e) { - Log.error("Failed to parse codebase URL", e); - return null; + throw new AssertionError(e); } } diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index f6567468..78804b3e 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -63,7 +63,6 @@ import org.prismlauncher.launcher.Launcher; import org.prismlauncher.launcher.impl.StandardLauncher; import org.prismlauncher.launcher.impl.legacy.LegacyLauncher; import org.prismlauncher.utils.Parameters; -import org.prismlauncher.utils.StringUtils; import org.prismlauncher.utils.logging.Log; public final class EntryPoint { @@ -150,9 +149,9 @@ public final class EntryPoint { return PreLaunchAction.ABORT; default: - String[] pair = StringUtils.splitStringPair(' ', input); + String[] pair = input.split(" ", 2); - if (pair == null) + if (pair.length != 2) throw new ParseException(input, "[key] [value]"); params.add(pair[0], pair[1]); diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java index 585d55f1..0c2153a9 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java @@ -60,7 +60,6 @@ import java.util.List; import org.prismlauncher.exception.ParseException; import org.prismlauncher.launcher.Launcher; import org.prismlauncher.utils.Parameters; -import org.prismlauncher.utils.StringUtils; public abstract class AbstractLauncher implements Launcher { @@ -93,9 +92,9 @@ public abstract class AbstractLauncher implements Launcher { } else { maximize = false; - String[] sizePair = StringUtils.splitStringPair('x', windowParams); + String[] sizePair = windowParams.split("x", 2); - if (sizePair != null) { + if (sizePair.length == 2) { try { width = Integer.parseInt(sizePair[0]); height = Integer.parseInt(sizePair[1]); diff --git a/libraries/launcher/org/prismlauncher/utils/StringUtils.java b/libraries/launcher/org/prismlauncher/utils/StringUtils.java deleted file mode 100644 index dfd1634b..00000000 --- a/libraries/launcher/org/prismlauncher/utils/StringUtils.java +++ /dev/null @@ -1,49 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -/* - * Prism Launcher - Minecraft Launcher - * Copyright (C) 2022 solonovamax - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Linking this library statically or dynamically with other modules is - * making a combined work based on this library. Thus, the terms and - * conditions of the GNU General Public License cover the whole - * combination. - * - * As a special exception, the copyright holders of this library give - * you permission to link this library with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also meet, - * for each linked independent module, the terms and conditions of the - * license of that module. An independent module is a module which is - * not derived from or based on this library. If you modify this - * library, you may extend this exception to your version of the - * library, but you are not obliged to do so. If you do not wish to do - * so, delete this exception statement from your version. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.prismlauncher.utils; - -public final class StringUtils { - - public static String[] splitStringPair(char splitChar, String str) { - int splitPoint = str.indexOf(splitChar); - - if (splitPoint == -1) - return null; - - return new String[] { str.substring(0, splitPoint), str.substring(splitPoint + 1) }; - } - -} From 70fa92f22ca8d013e7e101645d4ef60a21a52223 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sat, 19 Nov 2022 13:58:35 +0000 Subject: [PATCH 48/52] Remove dirty printStackTrace hacks Signed-off-by: TheKodeToad --- libraries/launcher/.gitignore | 1 + .../org/prismlauncher/utils/logging/Log.java | 10 +- .../utils/logging/LogPrintStream.java | 99 ------------------- 3 files changed, 5 insertions(+), 105 deletions(-) delete mode 100644 libraries/launcher/org/prismlauncher/utils/logging/LogPrintStream.java diff --git a/libraries/launcher/.gitignore b/libraries/launcher/.gitignore index cc1c52bf..dda456e3 100644 --- a/libraries/launcher/.gitignore +++ b/libraries/launcher/.gitignore @@ -4,3 +4,4 @@ out .classpath .idea .project +bin/ diff --git a/libraries/launcher/org/prismlauncher/utils/logging/Log.java b/libraries/launcher/org/prismlauncher/utils/logging/Log.java index 374a8107..e3aa538b 100644 --- a/libraries/launcher/org/prismlauncher/utils/logging/Log.java +++ b/libraries/launcher/org/prismlauncher/utils/logging/Log.java @@ -44,10 +44,8 @@ import java.io.PrintStream; */ public final class Log { - // original before overridden - private static final PrintStream OUT = new PrintStream(System.out), ERR = new PrintStream(System.err); - private static final PrintStream ERROR_PREFIX = new LogPrintStream(System.err, Level.ERROR), - FATAL_PREFIX = new LogPrintStream(System.err, Level.FATAL); + // original before possibly overridden by MC + private static final PrintStream OUT = new PrintStream(System.out), ERR = new PrintStream(System.err); private static final boolean DEBUG = Boolean.getBoolean("org.prismlauncher.debug"); public static void launcher(String message) { @@ -68,7 +66,7 @@ public final class Log { public static void error(String message, Throwable e) { error(message); - e.printStackTrace(ERROR_PREFIX); + e.printStackTrace(ERR); } public static void fatal(String message) { @@ -77,7 +75,7 @@ public final class Log { public static void fatal(String message, Throwable e) { fatal(message); - e.printStackTrace(FATAL_PREFIX); + e.printStackTrace(ERR); } /** diff --git a/libraries/launcher/org/prismlauncher/utils/logging/LogPrintStream.java b/libraries/launcher/org/prismlauncher/utils/logging/LogPrintStream.java deleted file mode 100644 index 8a182817..00000000 --- a/libraries/launcher/org/prismlauncher/utils/logging/LogPrintStream.java +++ /dev/null @@ -1,99 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -/* - * Prism Launcher - Minecraft Launcher - * Copyright (C) 2022 TheKodeToad - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Linking this library statically or dynamically with other modules is - * making a combined work based on this library. Thus, the terms and - * conditions of the GNU General Public License cover the whole - * combination. - * - * As a special exception, the copyright holders of this library give - * you permission to link this library with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also meet, - * for each linked independent module, the terms and conditions of the - * license of that module. An independent module is a module which is - * not derived from or based on this library. If you modify this - * library, you may extend this exception to your version of the - * library, but you are not obliged to do so. If you do not wish to do - * so, delete this exception statement from your version. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.prismlauncher.utils.logging; - -import java.io.OutputStream; -import java.io.PrintStream; - -/** - * Used to create a print stream that redirects to Log. - */ -final class LogPrintStream extends PrintStream { - - private final Level level; - - public LogPrintStream(OutputStream out, Level level) { - super(out); - - this.level = level; - } - - @Override - public void println(String x) { - Log.log(x, level); - } - - @Override - public void println(Object x) { - println(String.valueOf(x)); - } - - @Override - public void println(boolean x) { - println(String.valueOf(x)); - } - - @Override - public void println(char x) { - println(String.valueOf(x)); - } - - @Override - public void println(int x) { - println(String.valueOf(x)); - } - - @Override - public void println(long x) { - println(String.valueOf(x)); - } - - @Override - public void println(float x) { - println(String.valueOf(x)); - } - - @Override - public void println(double x) { - println(String.valueOf(x)); - } - - @Override - public void println(char[] x) { - println(String.valueOf(x)); - } - -} \ No newline at end of file From c27ebde575e4b12aa38da962b18bb261bbe676b4 Mon Sep 17 00:00:00 2001 From: DioEgizio <83089242+DioEgizio@users.noreply.github.com> Date: Sat, 19 Nov 2022 17:14:19 +0100 Subject: [PATCH 49/52] fix(actions): fix cache on flatpak currently there's a [bug](https://github.com/flatpak/flatpak-github-actions/issues/80) on the stable version of the flatpak action which causes the cache key to be wrong. this commit work arounds it Signed-off-by: DioEgizio <83089242+DioEgizio@users.noreply.github.com> --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 20fe66dd..c0e5b50a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -487,6 +487,7 @@ jobs: runs-on: ubuntu-20.04 steps: - name: Checkout + if: inputs.build_type == 'Debug' uses: actions/checkout@v3 with: submodules: 'true' @@ -524,3 +525,4 @@ jobs: with: bundle: "Prism Launcher.flatpak" manifest-path: flatpak/org.prismlauncher.PrismLauncher.yml + cache-key: flatpak-${{ github.sha }}-x86_64 From d1db7a0e23d90546f6b7ee5d1894fb3c60e41ef7 Mon Sep 17 00:00:00 2001 From: jopejoe1 <34899572+jopejoe1@users.noreply.github.com> Date: Sat, 19 Nov 2022 16:28:27 +0000 Subject: [PATCH 50/52] Fix New Zealand English display Signed-off-by: jopejoe1 <34899572+jopejoe1@users.noreply.github.com> --- launcher/translations/TranslationsModel.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/launcher/translations/TranslationsModel.cpp b/launcher/translations/TranslationsModel.cpp index 84778d32..38f48296 100644 --- a/launcher/translations/TranslationsModel.cpp +++ b/launcher/translations/TranslationsModel.cpp @@ -83,6 +83,9 @@ struct Language else if(key == "es_UY") { result = u8"español de Latinoamérica"; } + else if(key == "en_NZ") { + result = u8"New Zealand English"; // No idea why qt translates this to just english and not to New Zealand English + } else if(key == "en@pirate") { result = u8"Tongue of the High Seas"; } From bb7a321c6ed91709ff208efbbef19e05d7dfb220 Mon Sep 17 00:00:00 2001 From: Tayou Date: Sun, 20 Nov 2022 02:51:12 +0100 Subject: [PATCH 51/52] add breeze themes Signed-off-by: Tayou --- launcher/CMakeLists.txt | 4 ++ launcher/main.cpp | 2 + .../resources/breeze_dark/breeze_dark.qrc | 43 ++++++++++++++ launcher/resources/breeze_dark/index.theme | 11 ++++ .../resources/breeze_dark/scalable/about.svg | 12 ++++ .../breeze_dark/scalable/accounts.svg | 17 ++++++ .../resources/breeze_dark/scalable/bug.svg | 13 +++++ .../breeze_dark/scalable/centralmods.svg | 1 + .../breeze_dark/scalable/checkupdate.svg | 14 +++++ .../resources/breeze_dark/scalable/copy.svg | 11 ++++ .../breeze_dark/scalable/coremods.svg | 1 + .../breeze_dark/scalable/custom-commands.svg | 13 +++++ .../resources/breeze_dark/scalable/delete.svg | 13 +++++ .../breeze_dark/scalable/discord.svg | 1 + .../resources/breeze_dark/scalable/export.svg | 11 ++++ .../breeze_dark/scalable/externaltools.svg | 13 +++++ .../resources/breeze_dark/scalable/help.svg | 13 +++++ .../scalable/instance-settings.svg | 13 +++++ .../breeze_dark/scalable/jarmods.svg | 1 + .../resources/breeze_dark/scalable/java.svg | 10 ++++ .../breeze_dark/scalable/language.svg | 13 +++++ .../resources/breeze_dark/scalable/launch.svg | 8 +++ .../breeze_dark/scalable/launcher.svg | 57 +++++++++++++++++++ .../breeze_dark/scalable/loadermods.svg | 13 +++++ .../resources/breeze_dark/scalable/log.svg | 13 +++++ .../resources/breeze_dark/scalable/matrix.svg | 9 +++ .../breeze_dark/scalable/minecraft.svg | 13 +++++ .../resources/breeze_dark/scalable/new.svg | 18 ++++++ .../resources/breeze_dark/scalable/news.svg | 13 +++++ .../resources/breeze_dark/scalable/notes.svg | 13 +++++ .../breeze_dark/scalable/patreon.svg | 3 + .../resources/breeze_dark/scalable/proxy.svg | 14 +++++ .../breeze_dark/scalable/reddit-alien.svg | 3 + .../breeze_dark/scalable/refresh.svg | 8 +++ .../resources/breeze_dark/scalable/rename.svg | 13 +++++ .../breeze_dark/scalable/resourcepacks.svg | 11 ++++ .../breeze_dark/scalable/screenshots.svg | 13 +++++ .../breeze_dark/scalable/settings.svg | 17 ++++++ .../breeze_dark/scalable/shaderpacks.svg | 13 +++++ .../breeze_dark/scalable/status-bad.svg | 9 +++ .../breeze_dark/scalable/status-good.svg | 10 ++++ .../breeze_dark/scalable/status-yellow.svg | 9 +++ .../resources/breeze_dark/scalable/tag.svg | 17 ++++++ .../breeze_dark/scalable/viewfolder.svg | 13 +++++ .../resources/breeze_dark/scalable/worlds.svg | 16 ++++++ .../resources/breeze_light/breeze_light.qrc | 43 ++++++++++++++ launcher/resources/breeze_light/index.theme | 11 ++++ .../resources/breeze_light/scalable/about.svg | 12 ++++ .../breeze_light/scalable/accounts.svg | 17 ++++++ .../resources/breeze_light/scalable/bug.svg | 13 +++++ .../breeze_light/scalable/centralmods.svg | 1 + .../breeze_light/scalable/checkupdate.svg | 14 +++++ .../resources/breeze_light/scalable/copy.svg | 11 ++++ .../breeze_light/scalable/coremods.svg | 1 + .../breeze_light/scalable/custom-commands.svg | 13 +++++ .../breeze_light/scalable/delete.svg | 13 +++++ .../breeze_light/scalable/discord.svg | 1 + .../breeze_light/scalable/export.svg | 11 ++++ .../breeze_light/scalable/externaltools.svg | 13 +++++ .../resources/breeze_light/scalable/help.svg | 13 +++++ .../scalable/instance-settings.svg | 13 +++++ .../breeze_light/scalable/jarmods.svg | 1 + .../resources/breeze_light/scalable/java.svg | 10 ++++ .../breeze_light/scalable/language.svg | 13 +++++ .../breeze_light/scalable/launch.svg | 8 +++ .../breeze_light/scalable/loadermods.svg | 13 +++++ .../resources/breeze_light/scalable/log.svg | 13 +++++ .../breeze_light/scalable/matrix.svg | 9 +++ .../breeze_light/scalable/minecraft.svg | 13 +++++ .../resources/breeze_light/scalable/new.svg | 18 ++++++ .../resources/breeze_light/scalable/news.svg | 13 +++++ .../resources/breeze_light/scalable/notes.svg | 13 +++++ .../breeze_light/scalable/patreon.svg | 3 + .../resources/breeze_light/scalable/proxy.svg | 14 +++++ .../breeze_light/scalable/reddit-alien.svg | 3 + .../breeze_light/scalable/refresh.svg | 8 +++ .../breeze_light/scalable/rename.svg | 13 +++++ .../breeze_light/scalable/resourcepacks.svg | 11 ++++ .../breeze_light/scalable/screenshots.svg | 13 +++++ .../breeze_light/scalable/settings.svg | 17 ++++++ .../breeze_light/scalable/shaderpacks.svg | 13 +++++ .../breeze_light/scalable/status-bad.svg | 9 +++ .../breeze_light/scalable/status-good.svg | 10 ++++ .../breeze_light/scalable/status-yellow.svg | 9 +++ .../resources/breeze_light/scalable/tag.svg | 17 ++++++ .../breeze_light/scalable/viewfolder.svg | 13 +++++ .../breeze_light/scalable/worlds.svg | 16 ++++++ launcher/ui/pages/global/LauncherPage.cpp | 29 ++++++++-- launcher/ui/pages/global/LauncherPage.ui | 10 ++++ 89 files changed, 1082 insertions(+), 6 deletions(-) create mode 100644 launcher/resources/breeze_dark/breeze_dark.qrc create mode 100644 launcher/resources/breeze_dark/index.theme create mode 100644 launcher/resources/breeze_dark/scalable/about.svg create mode 100644 launcher/resources/breeze_dark/scalable/accounts.svg create mode 100644 launcher/resources/breeze_dark/scalable/bug.svg create mode 100644 launcher/resources/breeze_dark/scalable/centralmods.svg create mode 100644 launcher/resources/breeze_dark/scalable/checkupdate.svg create mode 100644 launcher/resources/breeze_dark/scalable/copy.svg create mode 100644 launcher/resources/breeze_dark/scalable/coremods.svg create mode 100644 launcher/resources/breeze_dark/scalable/custom-commands.svg create mode 100644 launcher/resources/breeze_dark/scalable/delete.svg create mode 100644 launcher/resources/breeze_dark/scalable/discord.svg create mode 100644 launcher/resources/breeze_dark/scalable/export.svg create mode 100644 launcher/resources/breeze_dark/scalable/externaltools.svg create mode 100644 launcher/resources/breeze_dark/scalable/help.svg create mode 100644 launcher/resources/breeze_dark/scalable/instance-settings.svg create mode 100644 launcher/resources/breeze_dark/scalable/jarmods.svg create mode 100644 launcher/resources/breeze_dark/scalable/java.svg create mode 100644 launcher/resources/breeze_dark/scalable/language.svg create mode 100644 launcher/resources/breeze_dark/scalable/launch.svg create mode 100644 launcher/resources/breeze_dark/scalable/launcher.svg create mode 100644 launcher/resources/breeze_dark/scalable/loadermods.svg create mode 100644 launcher/resources/breeze_dark/scalable/log.svg create mode 100644 launcher/resources/breeze_dark/scalable/matrix.svg create mode 100644 launcher/resources/breeze_dark/scalable/minecraft.svg create mode 100644 launcher/resources/breeze_dark/scalable/new.svg create mode 100644 launcher/resources/breeze_dark/scalable/news.svg create mode 100644 launcher/resources/breeze_dark/scalable/notes.svg create mode 100644 launcher/resources/breeze_dark/scalable/patreon.svg create mode 100644 launcher/resources/breeze_dark/scalable/proxy.svg create mode 100644 launcher/resources/breeze_dark/scalable/reddit-alien.svg create mode 100644 launcher/resources/breeze_dark/scalable/refresh.svg create mode 100644 launcher/resources/breeze_dark/scalable/rename.svg create mode 100644 launcher/resources/breeze_dark/scalable/resourcepacks.svg create mode 100644 launcher/resources/breeze_dark/scalable/screenshots.svg create mode 100644 launcher/resources/breeze_dark/scalable/settings.svg create mode 100644 launcher/resources/breeze_dark/scalable/shaderpacks.svg create mode 100644 launcher/resources/breeze_dark/scalable/status-bad.svg create mode 100644 launcher/resources/breeze_dark/scalable/status-good.svg create mode 100644 launcher/resources/breeze_dark/scalable/status-yellow.svg create mode 100644 launcher/resources/breeze_dark/scalable/tag.svg create mode 100644 launcher/resources/breeze_dark/scalable/viewfolder.svg create mode 100644 launcher/resources/breeze_dark/scalable/worlds.svg create mode 100644 launcher/resources/breeze_light/breeze_light.qrc create mode 100644 launcher/resources/breeze_light/index.theme create mode 100644 launcher/resources/breeze_light/scalable/about.svg create mode 100644 launcher/resources/breeze_light/scalable/accounts.svg create mode 100644 launcher/resources/breeze_light/scalable/bug.svg create mode 100644 launcher/resources/breeze_light/scalable/centralmods.svg create mode 100644 launcher/resources/breeze_light/scalable/checkupdate.svg create mode 100644 launcher/resources/breeze_light/scalable/copy.svg create mode 100644 launcher/resources/breeze_light/scalable/coremods.svg create mode 100644 launcher/resources/breeze_light/scalable/custom-commands.svg create mode 100644 launcher/resources/breeze_light/scalable/delete.svg create mode 100644 launcher/resources/breeze_light/scalable/discord.svg create mode 100644 launcher/resources/breeze_light/scalable/export.svg create mode 100644 launcher/resources/breeze_light/scalable/externaltools.svg create mode 100644 launcher/resources/breeze_light/scalable/help.svg create mode 100644 launcher/resources/breeze_light/scalable/instance-settings.svg create mode 100644 launcher/resources/breeze_light/scalable/jarmods.svg create mode 100644 launcher/resources/breeze_light/scalable/java.svg create mode 100644 launcher/resources/breeze_light/scalable/language.svg create mode 100644 launcher/resources/breeze_light/scalable/launch.svg create mode 100644 launcher/resources/breeze_light/scalable/loadermods.svg create mode 100644 launcher/resources/breeze_light/scalable/log.svg create mode 100644 launcher/resources/breeze_light/scalable/matrix.svg create mode 100644 launcher/resources/breeze_light/scalable/minecraft.svg create mode 100644 launcher/resources/breeze_light/scalable/new.svg create mode 100644 launcher/resources/breeze_light/scalable/news.svg create mode 100644 launcher/resources/breeze_light/scalable/notes.svg create mode 100644 launcher/resources/breeze_light/scalable/patreon.svg create mode 100644 launcher/resources/breeze_light/scalable/proxy.svg create mode 100644 launcher/resources/breeze_light/scalable/reddit-alien.svg create mode 100644 launcher/resources/breeze_light/scalable/refresh.svg create mode 100644 launcher/resources/breeze_light/scalable/rename.svg create mode 100644 launcher/resources/breeze_light/scalable/resourcepacks.svg create mode 100644 launcher/resources/breeze_light/scalable/screenshots.svg create mode 100644 launcher/resources/breeze_light/scalable/settings.svg create mode 100644 launcher/resources/breeze_light/scalable/shaderpacks.svg create mode 100644 launcher/resources/breeze_light/scalable/status-bad.svg create mode 100644 launcher/resources/breeze_light/scalable/status-good.svg create mode 100644 launcher/resources/breeze_light/scalable/status-yellow.svg create mode 100644 launcher/resources/breeze_light/scalable/tag.svg create mode 100644 launcher/resources/breeze_light/scalable/viewfolder.svg create mode 100644 launcher/resources/breeze_light/scalable/worlds.svg diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 8db93429..a92a235d 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -598,6 +598,8 @@ SET(LAUNCHER_SOURCES resources/pe_light/pe_light.qrc resources/pe_colored/pe_colored.qrc resources/pe_blue/pe_blue.qrc + resources/breeze_dark/breeze_dark.qrc + resources/breeze_light/breeze_light.qrc resources/OSX/OSX.qrc resources/iOS/iOS.qrc resources/flat/flat.qrc @@ -957,6 +959,8 @@ qt_add_resources(LAUNCHER_RESOURCES resources/pe_light/pe_light.qrc resources/pe_colored/pe_colored.qrc resources/pe_blue/pe_blue.qrc + resources/breeze_dark/breeze_dark.qrc + resources/breeze_light/breeze_light.qrc resources/OSX/OSX.qrc resources/iOS/iOS.qrc resources/flat/flat.qrc diff --git a/launcher/main.cpp b/launcher/main.cpp index df596449..b63f8bfd 100644 --- a/launcher/main.cpp +++ b/launcher/main.cpp @@ -81,6 +81,8 @@ int main(int argc, char *argv[]) Q_INIT_RESOURCE(pe_light); Q_INIT_RESOURCE(pe_blue); Q_INIT_RESOURCE(pe_colored); + Q_INIT_RESOURCE(breeze_dark); + Q_INIT_RESOURCE(breeze_light); Q_INIT_RESOURCE(OSX); Q_INIT_RESOURCE(iOS); Q_INIT_RESOURCE(flat); diff --git a/launcher/resources/breeze_dark/breeze_dark.qrc b/launcher/resources/breeze_dark/breeze_dark.qrc new file mode 100644 index 00000000..4d7a69b2 --- /dev/null +++ b/launcher/resources/breeze_dark/breeze_dark.qrc @@ -0,0 +1,43 @@ + + + index.theme + scalable/about.svg + scalable/accounts.svg + scalable/bug.svg + scalable/centralmods.svg + scalable/checkupdate.svg + scalable/copy.svg + scalable/coremods.svg + scalable/custom-commands.svg + scalable/discord.svg + scalable/externaltools.svg + scalable/help.svg + scalable/instance-settings.svg + scalable/jarmods.svg + scalable/java.svg + scalable/language.svg + scalable/loadermods.svg + scalable/log.svg + scalable/minecraft.svg + scalable/new.svg + scalable/news.svg + scalable/notes.svg + scalable/proxy.svg + scalable/reddit-alien.svg + scalable/refresh.svg + scalable/resourcepacks.svg + scalable/shaderpacks.svg + scalable/screenshots.svg + scalable/settings.svg + scalable/status-bad.svg + scalable/status-good.svg + scalable/status-yellow.svg + scalable/viewfolder.svg + scalable/worlds.svg + scalable/delete.svg + scalable/tag.svg + scalable/export.svg + scalable/rename.svg + scalable/launch.svg + + diff --git a/launcher/resources/breeze_dark/index.theme b/launcher/resources/breeze_dark/index.theme new file mode 100644 index 00000000..f9f6f4dc --- /dev/null +++ b/launcher/resources/breeze_dark/index.theme @@ -0,0 +1,11 @@ +[Icon Theme] +Name=Breeze Dark +Comment=Breeze Dark Icons +Inherits=multimc +Directories=scalable + +[scalable] +Size=48 +Type=Scalable +MinSize=16 +MaxSize=256 diff --git a/launcher/resources/breeze_dark/scalable/about.svg b/launcher/resources/breeze_dark/scalable/about.svg new file mode 100644 index 00000000..856d1b2b --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/about.svg @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/accounts.svg b/launcher/resources/breeze_dark/scalable/accounts.svg new file mode 100644 index 00000000..fbb51959 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/accounts.svg @@ -0,0 +1,17 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/bug.svg b/launcher/resources/breeze_dark/scalable/bug.svg new file mode 100644 index 00000000..6ddf482f --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/bug.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/centralmods.svg b/launcher/resources/breeze_dark/scalable/centralmods.svg new file mode 100644 index 00000000..4035e51c --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/centralmods.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/launcher/resources/breeze_dark/scalable/checkupdate.svg b/launcher/resources/breeze_dark/scalable/checkupdate.svg new file mode 100644 index 00000000..cc5dfc16 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/checkupdate.svg @@ -0,0 +1,14 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/copy.svg b/launcher/resources/breeze_dark/scalable/copy.svg new file mode 100644 index 00000000..fe4a36ac --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/copy.svg @@ -0,0 +1,11 @@ + + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/coremods.svg b/launcher/resources/breeze_dark/scalable/coremods.svg new file mode 100644 index 00000000..ec4ecea8 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/coremods.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/launcher/resources/breeze_dark/scalable/custom-commands.svg b/launcher/resources/breeze_dark/scalable/custom-commands.svg new file mode 100644 index 00000000..44efd39e --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/custom-commands.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/delete.svg b/launcher/resources/breeze_dark/scalable/delete.svg new file mode 100644 index 00000000..c7074585 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/delete.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/discord.svg b/launcher/resources/breeze_dark/scalable/discord.svg new file mode 100644 index 00000000..22ee27ba --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/discord.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/launcher/resources/breeze_dark/scalable/export.svg b/launcher/resources/breeze_dark/scalable/export.svg new file mode 100644 index 00000000..b1fe39d1 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/export.svg @@ -0,0 +1,11 @@ + + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/externaltools.svg b/launcher/resources/breeze_dark/scalable/externaltools.svg new file mode 100644 index 00000000..dd19fb90 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/externaltools.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/help.svg b/launcher/resources/breeze_dark/scalable/help.svg new file mode 100644 index 00000000..b273a8bc --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/help.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/instance-settings.svg b/launcher/resources/breeze_dark/scalable/instance-settings.svg new file mode 100644 index 00000000..c5f0504b --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/instance-settings.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/jarmods.svg b/launcher/resources/breeze_dark/scalable/jarmods.svg new file mode 100644 index 00000000..49a45d36 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/jarmods.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/launcher/resources/breeze_dark/scalable/java.svg b/launcher/resources/breeze_dark/scalable/java.svg new file mode 100644 index 00000000..7149981c --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/java.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/language.svg b/launcher/resources/breeze_dark/scalable/language.svg new file mode 100644 index 00000000..239cdf94 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/language.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/launch.svg b/launcher/resources/breeze_dark/scalable/launch.svg new file mode 100644 index 00000000..25c5fabc --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/launch.svg @@ -0,0 +1,8 @@ + + + + diff --git a/launcher/resources/breeze_dark/scalable/launcher.svg b/launcher/resources/breeze_dark/scalable/launcher.svg new file mode 100644 index 00000000..aeee8433 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/launcher.svg @@ -0,0 +1,57 @@ + + + + Prism Launcher Logo + + + + + + + + + + + + + + + + + + + + + + + Prism Launcher Logo + 19/10/2022 + + + Prism Launcher + + + + + AutiOne, Boba, ely, Fulmine, gon sawa, Pankakes, tobimori, Zeke + + + https://github.com/PrismLauncher/PrismLauncher + + + Prism Launcher + + + + + + + + + + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/loadermods.svg b/launcher/resources/breeze_dark/scalable/loadermods.svg new file mode 100644 index 00000000..7bd87188 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/loadermods.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/log.svg b/launcher/resources/breeze_dark/scalable/log.svg new file mode 100644 index 00000000..fcd83c4d --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/log.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/matrix.svg b/launcher/resources/breeze_dark/scalable/matrix.svg new file mode 100644 index 00000000..214f5708 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/matrix.svg @@ -0,0 +1,9 @@ + + + Matrix (protocol) logo + + + + + + \ No newline at end of file diff --git a/launcher/resources/breeze_dark/scalable/minecraft.svg b/launcher/resources/breeze_dark/scalable/minecraft.svg new file mode 100644 index 00000000..1d8d0167 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/minecraft.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/new.svg b/launcher/resources/breeze_dark/scalable/new.svg new file mode 100644 index 00000000..9ee910e7 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/new.svg @@ -0,0 +1,18 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/news.svg b/launcher/resources/breeze_dark/scalable/news.svg new file mode 100644 index 00000000..a2ff0c8d --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/news.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/notes.svg b/launcher/resources/breeze_dark/scalable/notes.svg new file mode 100644 index 00000000..6452d3c8 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/notes.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/patreon.svg b/launcher/resources/breeze_dark/scalable/patreon.svg new file mode 100644 index 00000000..7f98dd13 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/patreon.svg @@ -0,0 +1,3 @@ + + + diff --git a/launcher/resources/breeze_dark/scalable/proxy.svg b/launcher/resources/breeze_dark/scalable/proxy.svg new file mode 100644 index 00000000..c6efb171 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/proxy.svg @@ -0,0 +1,14 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/reddit-alien.svg b/launcher/resources/breeze_dark/scalable/reddit-alien.svg new file mode 100644 index 00000000..00f82bb3 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/reddit-alien.svg @@ -0,0 +1,3 @@ + + + diff --git a/launcher/resources/breeze_dark/scalable/refresh.svg b/launcher/resources/breeze_dark/scalable/refresh.svg new file mode 100644 index 00000000..7b486463 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/refresh.svg @@ -0,0 +1,8 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/rename.svg b/launcher/resources/breeze_dark/scalable/rename.svg new file mode 100644 index 00000000..6a844965 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/rename.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/resourcepacks.svg b/launcher/resources/breeze_dark/scalable/resourcepacks.svg new file mode 100644 index 00000000..0986c216 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/resourcepacks.svg @@ -0,0 +1,11 @@ + + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/screenshots.svg b/launcher/resources/breeze_dark/scalable/screenshots.svg new file mode 100644 index 00000000..a10ed713 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/screenshots.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/settings.svg b/launcher/resources/breeze_dark/scalable/settings.svg new file mode 100644 index 00000000..009d8154 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/settings.svg @@ -0,0 +1,17 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/shaderpacks.svg b/launcher/resources/breeze_dark/scalable/shaderpacks.svg new file mode 100644 index 00000000..b2887947 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/shaderpacks.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/status-bad.svg b/launcher/resources/breeze_dark/scalable/status-bad.svg new file mode 100644 index 00000000..6fc3137e --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/status-bad.svg @@ -0,0 +1,9 @@ + + + + + diff --git a/launcher/resources/breeze_dark/scalable/status-good.svg b/launcher/resources/breeze_dark/scalable/status-good.svg new file mode 100644 index 00000000..eb8bc03b --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/status-good.svg @@ -0,0 +1,10 @@ + + + + + diff --git a/launcher/resources/breeze_dark/scalable/status-yellow.svg b/launcher/resources/breeze_dark/scalable/status-yellow.svg new file mode 100644 index 00000000..1dc4d0f5 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/status-yellow.svg @@ -0,0 +1,9 @@ + + + + + diff --git a/launcher/resources/breeze_dark/scalable/tag.svg b/launcher/resources/breeze_dark/scalable/tag.svg new file mode 100644 index 00000000..b54b515f --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/tag.svg @@ -0,0 +1,17 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/viewfolder.svg b/launcher/resources/breeze_dark/scalable/viewfolder.svg new file mode 100644 index 00000000..0189b954 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/viewfolder.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_dark/scalable/worlds.svg b/launcher/resources/breeze_dark/scalable/worlds.svg new file mode 100644 index 00000000..0cff8266 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/worlds.svg @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/launcher/resources/breeze_light/breeze_light.qrc b/launcher/resources/breeze_light/breeze_light.qrc new file mode 100644 index 00000000..7d9d99f5 --- /dev/null +++ b/launcher/resources/breeze_light/breeze_light.qrc @@ -0,0 +1,43 @@ + + + index.theme + scalable/about.svg + scalable/accounts.svg + scalable/bug.svg + scalable/centralmods.svg + scalable/checkupdate.svg + scalable/copy.svg + scalable/coremods.svg + scalable/custom-commands.svg + scalable/discord.svg + scalable/externaltools.svg + scalable/help.svg + scalable/instance-settings.svg + scalable/jarmods.svg + scalable/java.svg + scalable/language.svg + scalable/loadermods.svg + scalable/log.svg + scalable/minecraft.svg + scalable/new.svg + scalable/news.svg + scalable/notes.svg + scalable/proxy.svg + scalable/reddit-alien.svg + scalable/refresh.svg + scalable/resourcepacks.svg + scalable/shaderpacks.svg + scalable/screenshots.svg + scalable/settings.svg + scalable/status-bad.svg + scalable/status-good.svg + scalable/status-yellow.svg + scalable/viewfolder.svg + scalable/worlds.svg + scalable/delete.svg + scalable/tag.svg + scalable/export.svg + scalable/rename.svg + scalable/launch.svg + + diff --git a/launcher/resources/breeze_light/index.theme b/launcher/resources/breeze_light/index.theme new file mode 100644 index 00000000..126d42d7 --- /dev/null +++ b/launcher/resources/breeze_light/index.theme @@ -0,0 +1,11 @@ +[Icon Theme] +Name=Breeze Light +Comment=Breeze Light Icons +Inherits=multimc +Directories=scalable + +[scalable] +Size=48 +Type=Scalable +MinSize=16 +MaxSize=256 diff --git a/launcher/resources/breeze_light/scalable/about.svg b/launcher/resources/breeze_light/scalable/about.svg new file mode 100644 index 00000000..ea1dc02c --- /dev/null +++ b/launcher/resources/breeze_light/scalable/about.svg @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/launcher/resources/breeze_light/scalable/accounts.svg b/launcher/resources/breeze_light/scalable/accounts.svg new file mode 100644 index 00000000..8a542f36 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/accounts.svg @@ -0,0 +1,17 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/bug.svg b/launcher/resources/breeze_light/scalable/bug.svg new file mode 100644 index 00000000..4f41ad6b --- /dev/null +++ b/launcher/resources/breeze_light/scalable/bug.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/centralmods.svg b/launcher/resources/breeze_light/scalable/centralmods.svg new file mode 100644 index 00000000..4035e51c --- /dev/null +++ b/launcher/resources/breeze_light/scalable/centralmods.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/launcher/resources/breeze_light/scalable/checkupdate.svg b/launcher/resources/breeze_light/scalable/checkupdate.svg new file mode 100644 index 00000000..06b31827 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/checkupdate.svg @@ -0,0 +1,14 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/copy.svg b/launcher/resources/breeze_light/scalable/copy.svg new file mode 100644 index 00000000..2557953b --- /dev/null +++ b/launcher/resources/breeze_light/scalable/copy.svg @@ -0,0 +1,11 @@ + + + + + + + diff --git a/launcher/resources/breeze_light/scalable/coremods.svg b/launcher/resources/breeze_light/scalable/coremods.svg new file mode 100644 index 00000000..ec4ecea8 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/coremods.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/launcher/resources/breeze_light/scalable/custom-commands.svg b/launcher/resources/breeze_light/scalable/custom-commands.svg new file mode 100644 index 00000000..b2ac78c5 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/custom-commands.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/delete.svg b/launcher/resources/breeze_light/scalable/delete.svg new file mode 100644 index 00000000..f2aea6e8 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/delete.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/discord.svg b/launcher/resources/breeze_light/scalable/discord.svg new file mode 100644 index 00000000..22ee27ba --- /dev/null +++ b/launcher/resources/breeze_light/scalable/discord.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/launcher/resources/breeze_light/scalable/export.svg b/launcher/resources/breeze_light/scalable/export.svg new file mode 100644 index 00000000..d6314bd7 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/export.svg @@ -0,0 +1,11 @@ + + + + + + + diff --git a/launcher/resources/breeze_light/scalable/externaltools.svg b/launcher/resources/breeze_light/scalable/externaltools.svg new file mode 100644 index 00000000..c965b6c3 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/externaltools.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/help.svg b/launcher/resources/breeze_light/scalable/help.svg new file mode 100644 index 00000000..bcd14e05 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/help.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/instance-settings.svg b/launcher/resources/breeze_light/scalable/instance-settings.svg new file mode 100644 index 00000000..69854d73 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/instance-settings.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/jarmods.svg b/launcher/resources/breeze_light/scalable/jarmods.svg new file mode 100644 index 00000000..49a45d36 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/jarmods.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/launcher/resources/breeze_light/scalable/java.svg b/launcher/resources/breeze_light/scalable/java.svg new file mode 100644 index 00000000..ff86c9cc --- /dev/null +++ b/launcher/resources/breeze_light/scalable/java.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/launcher/resources/breeze_light/scalable/language.svg b/launcher/resources/breeze_light/scalable/language.svg new file mode 100644 index 00000000..3d56d33e --- /dev/null +++ b/launcher/resources/breeze_light/scalable/language.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/launch.svg b/launcher/resources/breeze_light/scalable/launch.svg new file mode 100644 index 00000000..678fd098 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/launch.svg @@ -0,0 +1,8 @@ + + + + diff --git a/launcher/resources/breeze_light/scalable/loadermods.svg b/launcher/resources/breeze_light/scalable/loadermods.svg new file mode 100644 index 00000000..4fb0f96d --- /dev/null +++ b/launcher/resources/breeze_light/scalable/loadermods.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/log.svg b/launcher/resources/breeze_light/scalable/log.svg new file mode 100644 index 00000000..cf9c9b22 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/log.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/matrix.svg b/launcher/resources/breeze_light/scalable/matrix.svg new file mode 100644 index 00000000..4745efc1 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/matrix.svg @@ -0,0 +1,9 @@ + + + Matrix (protocol) logo + + + + + + \ No newline at end of file diff --git a/launcher/resources/breeze_light/scalable/minecraft.svg b/launcher/resources/breeze_light/scalable/minecraft.svg new file mode 100644 index 00000000..1ffb4565 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/minecraft.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + diff --git a/launcher/resources/breeze_light/scalable/new.svg b/launcher/resources/breeze_light/scalable/new.svg new file mode 100644 index 00000000..51babd76 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/new.svg @@ -0,0 +1,18 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/news.svg b/launcher/resources/breeze_light/scalable/news.svg new file mode 100644 index 00000000..3e3ebe95 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/news.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/notes.svg b/launcher/resources/breeze_light/scalable/notes.svg new file mode 100644 index 00000000..a8eaf279 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/notes.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/patreon.svg b/launcher/resources/breeze_light/scalable/patreon.svg new file mode 100644 index 00000000..e12f1f8d --- /dev/null +++ b/launcher/resources/breeze_light/scalable/patreon.svg @@ -0,0 +1,3 @@ + + + diff --git a/launcher/resources/breeze_light/scalable/proxy.svg b/launcher/resources/breeze_light/scalable/proxy.svg new file mode 100644 index 00000000..2e67ff6c --- /dev/null +++ b/launcher/resources/breeze_light/scalable/proxy.svg @@ -0,0 +1,14 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/reddit-alien.svg b/launcher/resources/breeze_light/scalable/reddit-alien.svg new file mode 100644 index 00000000..93b8eedc --- /dev/null +++ b/launcher/resources/breeze_light/scalable/reddit-alien.svg @@ -0,0 +1,3 @@ + + + diff --git a/launcher/resources/breeze_light/scalable/refresh.svg b/launcher/resources/breeze_light/scalable/refresh.svg new file mode 100644 index 00000000..ecd2b394 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/refresh.svg @@ -0,0 +1,8 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/rename.svg b/launcher/resources/breeze_light/scalable/rename.svg new file mode 100644 index 00000000..18ccc58a --- /dev/null +++ b/launcher/resources/breeze_light/scalable/rename.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/resourcepacks.svg b/launcher/resources/breeze_light/scalable/resourcepacks.svg new file mode 100644 index 00000000..913d3c1f --- /dev/null +++ b/launcher/resources/breeze_light/scalable/resourcepacks.svg @@ -0,0 +1,11 @@ + + + + + + + diff --git a/launcher/resources/breeze_light/scalable/screenshots.svg b/launcher/resources/breeze_light/scalable/screenshots.svg new file mode 100644 index 00000000..d984b330 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/screenshots.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/settings.svg b/launcher/resources/breeze_light/scalable/settings.svg new file mode 100644 index 00000000..19e86e26 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/settings.svg @@ -0,0 +1,17 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/shaderpacks.svg b/launcher/resources/breeze_light/scalable/shaderpacks.svg new file mode 100644 index 00000000..591c6af5 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/shaderpacks.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/status-bad.svg b/launcher/resources/breeze_light/scalable/status-bad.svg new file mode 100644 index 00000000..6fc3137e --- /dev/null +++ b/launcher/resources/breeze_light/scalable/status-bad.svg @@ -0,0 +1,9 @@ + + + + + diff --git a/launcher/resources/breeze_light/scalable/status-good.svg b/launcher/resources/breeze_light/scalable/status-good.svg new file mode 100644 index 00000000..eb8bc03b --- /dev/null +++ b/launcher/resources/breeze_light/scalable/status-good.svg @@ -0,0 +1,10 @@ + + + + + diff --git a/launcher/resources/breeze_light/scalable/status-yellow.svg b/launcher/resources/breeze_light/scalable/status-yellow.svg new file mode 100644 index 00000000..1dc4d0f5 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/status-yellow.svg @@ -0,0 +1,9 @@ + + + + + diff --git a/launcher/resources/breeze_light/scalable/tag.svg b/launcher/resources/breeze_light/scalable/tag.svg new file mode 100644 index 00000000..4887d126 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/tag.svg @@ -0,0 +1,17 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/viewfolder.svg b/launcher/resources/breeze_light/scalable/viewfolder.svg new file mode 100644 index 00000000..4a8498ce --- /dev/null +++ b/launcher/resources/breeze_light/scalable/viewfolder.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_light/scalable/worlds.svg b/launcher/resources/breeze_light/scalable/worlds.svg new file mode 100644 index 00000000..543cc55e --- /dev/null +++ b/launcher/resources/breeze_light/scalable/worlds.svg @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/launcher/ui/pages/global/LauncherPage.cpp b/launcher/ui/pages/global/LauncherPage.cpp index 6661bf0f..cae0635f 100644 --- a/launcher/ui/pages/global/LauncherPage.cpp +++ b/launcher/ui/pages/global/LauncherPage.cpp @@ -303,21 +303,27 @@ void LauncherPage::applySettings() s->set("IconTheme", "pe_blue"); break; case 4: - s->set("IconTheme", "OSX"); + s->set("IconTheme", "breeze_light"); break; case 5: - s->set("IconTheme", "iOS"); + s->set("IconTheme", "breeze_dark"); break; case 6: - s->set("IconTheme", "flat"); + s->set("IconTheme", "OSX"); break; case 7: - s->set("IconTheme", "flat_white"); + s->set("IconTheme", "iOS"); break; case 8: - s->set("IconTheme", "multimc"); + s->set("IconTheme", "flat"); break; case 9: + s->set("IconTheme", "flat_white"); + break; + case 10: + s->set("IconTheme", "multimc"); + break; + case 11: s->set("IconTheme", "custom"); break; } @@ -397,7 +403,18 @@ void LauncherPage::loadSettings() m_currentUpdateChannel = s->get("UpdateChannel").toString(); //FIXME: make generic auto theme = s->get("IconTheme").toString(); - QStringList iconThemeOptions{"pe_colored", "pe_light", "pe_dark", "pe_blue", "OSX", "iOS", "flat", "flat_white", "multimc", "custom"}; + QStringList iconThemeOptions{"pe_colored", + "pe_light", + "pe_dark", + "pe_blue", + "breeze_light", + "breeze_dark", + "OSX", + "iOS", + "flat", + "flat_white", + "multimc", + "custom"}; ui->themeComboBox->setCurrentIndex(iconThemeOptions.indexOf(theme)); auto cat = s->get("BackgroundCat").toString(); diff --git a/launcher/ui/pages/global/LauncherPage.ui b/launcher/ui/pages/global/LauncherPage.ui index 6de644ee..c44718a1 100644 --- a/launcher/ui/pages/global/LauncherPage.ui +++ b/launcher/ui/pages/global/LauncherPage.ui @@ -285,6 +285,16 @@ Simple (Blue Icons) + + + Breeze Light + + + + + Breeze Dark + + OSX From ffcbf97dcccb2e6cb081282a3e335ecb66d37ca5 Mon Sep 17 00:00:00 2001 From: DioEgizio <83089242+DioEgizio@users.noreply.github.com> Date: Sun, 20 Nov 2022 09:21:43 +0100 Subject: [PATCH 52/52] fix: add Breeze copyright notice to COPYING Signed-off-by: DioEgizio <83089242+DioEgizio@users.noreply.github.com> --- COPYING.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/COPYING.md b/COPYING.md index 3e35c579..dde3c727 100644 --- a/COPYING.md +++ b/COPYING.md @@ -398,3 +398,20 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +## Breeze icons + + Copyright (C) 2014 Uri Herrera and others + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see .