aboutsummaryrefslogtreecommitdiff
path: root/libraries/launcher/org/prismlauncher/EntryPoint.java
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/launcher/org/prismlauncher/EntryPoint.java')
-rw-r--r--libraries/launcher/org/prismlauncher/EntryPoint.java160
1 files changed, 87 insertions, 73 deletions
diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java
index 9144e1f1..78804b3e 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, <fr3shtea@outlook.com>
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2022 icelimetea <fr3shtea@outlook.com>
+ * Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
+ * Copyright (C) 2022 solonovamax <solonovamax@12oclockpoint.com>
*
* 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
@@ -52,113 +54,125 @@
package org.prismlauncher;
-import org.prismlauncher.exception.ParseException;
-import org.prismlauncher.utils.Parameters;
-
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;
-
-public final class EntryPoint {
- private static final Logger LOGGER = Logger.getLogger("EntryPoint");
+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.logging.Log;
- private final Parameters params = new Parameters();
+public final class EntryPoint {
public static void main(String[] args) {
- EntryPoint listener = new EntryPoint();
-
- int retCode = listener.listen();
+ ExitCode code = listen();
- if (retCode != 0) {
- LOGGER.info("Exiting with " + retCode);
+ if (code != ExitCode.NORMAL) {
+ Log.fatal("Exiting with " + code);
- System.exit(retCode);
+ System.exit(code.numeric);
}
}
- private Action parseLine(String inData) throws ParseException {
- String[] tokens = inData.split("\\s+", 2);
+ private static ExitCode listen() {
+ Parameters params = new Parameters();
+ PreLaunchAction action = PreLaunchAction.PROCEED;
- if (tokens.length == 0)
- throw new ParseException("Unexpected empty string!");
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8))) {
+ String line;
- switch (tokens[0]) {
- case "launch": {
- return Action.Launch;
+ while (action == PreLaunchAction.PROCEED) {
+ if ((line = reader.readLine()) != null)
+ action = parseLine(line, params);
+ else
+ action = PreLaunchAction.ABORT;
}
+ } catch (IllegalArgumentException e) {
+ Log.fatal("Aborting due to wrong argument", e);
- case "abort": {
- return Action.Abort;
- }
+ return ExitCode.ILLEGAL_ARGUMENT;
+ } catch (Throwable e) {
+ Log.fatal("Aborting due to exception", e);
- default: {
- if (tokens.length != 2)
- throw new ParseException("Error while parsing:" + inData);
+ return ExitCode.ABORT;
+ }
- params.add(tokens[0], tokens[1]);
+ if (action == PreLaunchAction.ABORT) {
+ Log.fatal("Launch aborted by the launcher");
- return Action.Proceed;
- }
+ return ExitCode.ABORT;
}
- }
- public int listen() {
- Action action = Action.Proceed;
+ try {
+ Launcher launcher;
+ String type = params.getString("launcher");
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(
- System.in,
- StandardCharsets.UTF_8
- ))) {
- String line;
+ switch (type) {
+ case "standard":
+ launcher = new StandardLauncher(params);
+ break;
- while (action == Action.Proceed) {
- if ((line = reader.readLine()) != null) {
- action = parseLine(line);
- } else {
- action = Action.Abort;
- }
+ case "legacy":
+ launcher = new LegacyLauncher(params);
+ break;
+
+ default:
+ throw new IllegalArgumentException("Invalid launcher type: " + type);
}
- } catch (IOException | ParseException e) {
- LOGGER.log(Level.SEVERE, "Launcher ABORT due to exception:", e);
- return 1;
- }
+ launcher.launch();
+
+ return ExitCode.NORMAL;
+ } catch (IllegalArgumentException e) {
+ Log.fatal("Illegal argument", e);
- // Main loop
- if (action == Action.Abort) {
- LOGGER.info("Launch aborted by the launcher.");
+ return ExitCode.ILLEGAL_ARGUMENT;
+ } catch (Throwable e) {
+ Log.fatal("Exception caught from launcher", e);
- return 1;
+ return ExitCode.ERROR;
}
+ }
- try {
- Launcher launcher =
- LauncherFactory
- .getInstance()
- .createLauncher(params);
+ private static PreLaunchAction parseLine(String input, Parameters params) throws ParseException {
+ switch (input) {
+ case "":
+ break;
- launcher.launch();
+ case "launch":
+ return PreLaunchAction.LAUNCH;
- return 0;
- } catch (IllegalArgumentException e) {
- LOGGER.log(Level.SEVERE, "Wrong argument.", e);
+ case "abort":
+ return PreLaunchAction.ABORT;
- return 1;
- } catch (Exception e) {
- LOGGER.log(Level.SEVERE, "Exception caught from launcher.", e);
+ default:
+ String[] pair = input.split(" ", 2);
- return 1;
+ if (pair.length != 2)
+ throw new ParseException(input, "[key] [value]");
+
+ params.add(pair[0], pair[1]);
}
+
+ return PreLaunchAction.PROCEED;
+ }
+
+ private enum PreLaunchAction {
+ PROCEED, LAUNCH, ABORT
}
- private enum Action {
- Proceed,
- Launch,
- Abort
+ private enum ExitCode {
+ NORMAL(0), ABORT(1), ERROR(2), ILLEGAL_ARGUMENT(65);
+
+ private final int numeric;
+
+ ExitCode(int numeric) {
+ this.numeric = numeric;
+ }
+
}
}