aboutsummaryrefslogtreecommitdiff
path: root/libraries/launcher/org/multimc
diff options
context:
space:
mode:
authoricelimetea <fr3shtea@outlook.com>2022-05-05 07:14:32 +0100
committericelimetea <fr3shtea@outlook.com>2022-05-05 07:14:32 +0100
commitdcc41ef885cbb2a823313a95e48d069c63589a42 (patch)
tree36bb14ed1e72ef74d048321c832e4ebd61cce2c5 /libraries/launcher/org/multimc
parent9a87ae575ef58bb86d4bbd7bdb8ab7e026ad9a33 (diff)
downloadPrismLauncher-dcc41ef885cbb2a823313a95e48d069c63589a42.tar.gz
PrismLauncher-dcc41ef885cbb2a823313a95e48d069c63589a42.tar.bz2
PrismLauncher-dcc41ef885cbb2a823313a95e48d069c63589a42.zip
Improve mpticket file parsing code
Diffstat (limited to 'libraries/launcher/org/multimc')
-rw-r--r--libraries/launcher/org/multimc/applet/LegacyFrame.java46
1 files changed, 18 insertions, 28 deletions
diff --git a/libraries/launcher/org/multimc/applet/LegacyFrame.java b/libraries/launcher/org/multimc/applet/LegacyFrame.java
index c50995f6..e3bd5047 100644
--- a/libraries/launcher/org/multimc/applet/LegacyFrame.java
+++ b/libraries/launcher/org/multimc/applet/LegacyFrame.java
@@ -28,7 +28,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
-import java.util.Scanner;
+import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -51,7 +51,7 @@ public final class LegacyFrame extends Frame {
LOGGER.log(Level.WARNING, "Unable to read Minecraft icon!", e);
}
- this.addWindowListener(new ForceExitHandler());
+ addWindowListener(new ForceExitHandler());
}
public void start (
@@ -73,34 +73,24 @@ public final class LegacyFrame extends Frame {
Paths.get(System.getProperty("user.dir"), "..", "mpticket.corrupt");
if (Files.exists(mpticketFile)) {
- try (Scanner fileScanner = new Scanner(
- Files.newInputStream(mpticketFile),
- StandardCharsets.US_ASCII.name()
- )) {
- String[] mpticketParams = new String[3];
-
- for (int i = 0; i < mpticketParams.length; i++) {
- if (fileScanner.hasNextLine()) {
- mpticketParams[i] = fileScanner.nextLine();
- } else {
- Files.move(
- mpticketFile,
- mpticketFileCorrupt,
- StandardCopyOption.REPLACE_EXISTING
- );
-
- throw new IllegalArgumentException("Mpticket file is corrupted!");
- }
+ try {
+ List<String> lines = Files.readAllLines(mpticketFile, StandardCharsets.UTF_8);
+
+ if (lines.size() != 3) {
+ Files.move(
+ mpticketFile,
+ mpticketFileCorrupt,
+ StandardCopyOption.REPLACE_EXISTING
+ );
+
+ LOGGER.warning("Mpticket file is corrupted!");
+ } else {
+ appletWrap.setParameter("server", lines.get(0));
+ appletWrap.setParameter("port", lines.get(1));
+ appletWrap.setParameter("mppass", lines.get(2));
}
-
- Files.delete(mpticketFile);
-
- // Assumes parameters are valid and in the correct order
- appletWrap.setParameter("server", mpticketParams[0]);
- appletWrap.setParameter("port", mpticketParams[1]);
- appletWrap.setParameter("mppass", mpticketParams[2]);
} catch (IOException e) {
- LOGGER.log(Level.WARNING, "Unable to read mpticket file!", e);
+ LOGGER.log(Level.WARNING, "Unable to red mpticket file!", e);
}
}