aboutsummaryrefslogtreecommitdiff
path: root/libraries/launcher/org/multimc/EntryPoint.java
diff options
context:
space:
mode:
authoricelimetea <fr3shtea@outlook.com>2022-05-02 22:36:55 +0100
committericelimetea <fr3shtea@outlook.com>2022-05-02 22:36:55 +0100
commit8de63b60b1a9d0ba16f5d45f3198c13637151749 (patch)
treeb9f0e9d98720c3535400828544f86e64efa15fc5 /libraries/launcher/org/multimc/EntryPoint.java
parentd29720fbcef633a5b292a16a5e8f121df75260ac (diff)
downloadPrismLauncher-8de63b60b1a9d0ba16f5d45f3198c13637151749.tar.gz
PrismLauncher-8de63b60b1a9d0ba16f5d45f3198c13637151749.tar.bz2
PrismLauncher-8de63b60b1a9d0ba16f5d45f3198c13637151749.zip
Refactor some parts of NewLaunch (part 2)
Diffstat (limited to 'libraries/launcher/org/multimc/EntryPoint.java')
-rw-r--r--libraries/launcher/org/multimc/EntryPoint.java55
1 files changed, 30 insertions, 25 deletions
diff --git a/libraries/launcher/org/multimc/EntryPoint.java b/libraries/launcher/org/multimc/EntryPoint.java
index b626d095..be06d1b4 100644
--- a/libraries/launcher/org/multimc/EntryPoint.java
+++ b/libraries/launcher/org/multimc/EntryPoint.java
@@ -14,7 +14,8 @@ package org.multimc;/*
* limitations under the License.
*/
-import org.multimc.onesix.OneSixLauncher;
+import org.multimc.exception.ParseException;
+import org.multimc.utils.ParamBucket;
import java.io.BufferedReader;
import java.io.IOException;
@@ -23,31 +24,27 @@ import java.nio.charset.StandardCharsets;
import java.util.logging.Level;
import java.util.logging.Logger;
-public class EntryPoint
-{
+public final class EntryPoint {
private static final Logger LOGGER = Logger.getLogger("EntryPoint");
private final ParamBucket params = new ParamBucket();
- private org.multimc.Launcher launcher;
+ private String launcherType;
- public static void main(String[] args)
- {
+ public static void main(String[] args) {
EntryPoint listener = new EntryPoint();
int retCode = listener.listen();
- if (retCode != 0)
- {
+ if (retCode != 0) {
LOGGER.info("Exiting with " + retCode);
System.exit(retCode);
}
}
- private Action parseLine(String inData) throws ParseException
- {
+ private Action parseLine(String inData) throws ParseException {
String[] tokens = inData.split("\\s+", 2);
if (tokens.length == 0)
@@ -66,15 +63,9 @@ public class EntryPoint
if (tokens.length != 2)
throw new ParseException("Expected 2 tokens, got " + tokens.length);
- if (tokens[1].equals("onesix")) {
- launcher = new OneSixLauncher();
+ launcherType = tokens[1];
- LOGGER.info("Using onesix launcher.");
-
- return Action.Proceed;
- } else {
- throw new ParseException("Invalid launcher type: " + tokens[1]);
- }
+ return Action.Proceed;
}
default: {
@@ -88,8 +79,7 @@ public class EntryPoint
}
}
- public int listen()
- {
+ public int listen() {
Action action = Action.Proceed;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(
@@ -112,16 +102,31 @@ public class EntryPoint
}
// Main loop
- if (action == Action.Abort)
- {
+ if (action == Action.Abort) {
LOGGER.info("Launch aborted by the launcher.");
return 1;
}
- if (launcher != null)
- {
- return launcher.launch(params);
+ if (launcherType != null) {
+ try {
+ Launcher launcher =
+ LauncherFactory
+ .getInstance()
+ .createLauncher(launcherType, params);
+
+ launcher.launch();
+
+ return 0;
+ } catch (IllegalArgumentException e) {
+ LOGGER.log(Level.SEVERE, "Wrong argument.", e);
+
+ return 1;
+ } catch (Exception e) {
+ LOGGER.log(Level.SEVERE, "Exception caught from launcher.", e);
+
+ return 1;
+ }
}
LOGGER.log(Level.SEVERE, "No valid launcher implementation specified.");