From 5ed0236888748d7f0fe538ac39cc5d4a209fd093 Mon Sep 17 00:00:00 2001 From: Kristian Knarvik Date: Fri, 23 Feb 2018 21:38:42 +0100 Subject: [PATCH] Some fixes and additions Added log for GUI label. Removed quotes around jar path to make things work on linux. --- .../Minecraft-Server-Launcher/META-INF/MANIFEST.MF | 3 --- src/net/knarcraft/serverlauncher/Main.java | 11 ++++++++++- src/net/knarcraft/serverlauncher/profile/Profile.java | 11 ++++++++--- src/net/knarcraft/serverlauncher/server/Server.java | 6 +++--- .../knarcraft/serverlauncher/userinterface/GUI.java | 6 ++++++ 5 files changed, 27 insertions(+), 10 deletions(-) delete mode 100644 out/production/Minecraft-Server-Launcher/META-INF/MANIFEST.MF diff --git a/out/production/Minecraft-Server-Launcher/META-INF/MANIFEST.MF b/out/production/Minecraft-Server-Launcher/META-INF/MANIFEST.MF deleted file mode 100644 index 6fe61c6..0000000 --- a/out/production/Minecraft-Server-Launcher/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Main-Class: net.knarcraft.serverlauncher.Main - diff --git a/src/net/knarcraft/serverlauncher/Main.java b/src/net/knarcraft/serverlauncher/Main.java index 298a71f..ee2d0ba 100644 --- a/src/net/knarcraft/serverlauncher/Main.java +++ b/src/net/knarcraft/serverlauncher/Main.java @@ -27,7 +27,7 @@ import static net.knarcraft.serverlauncher.Shared.stringBetween; public class Main { @SuppressWarnings("CanBeFinal") - public static String appDir; + private static String appDir; private static boolean running = false; static { @@ -37,6 +37,11 @@ public class Main { e.printStackTrace(); System.exit(1); } + try (PrintWriter file = new PrintWriter(Main.getAppDir() + File.separator + "latestrun.log")) { + file.print(""); + } catch (IOException e ) { + e.printStackTrace(); + } } public static void main(String[] args) { @@ -63,6 +68,10 @@ public class Main { } } + public static String getAppDir() { + return appDir; + } + /** * Reads from server processes, and writes the output to consoles. */ diff --git a/src/net/knarcraft/serverlauncher/profile/Profile.java b/src/net/knarcraft/serverlauncher/profile/Profile.java index 37345f1..1c34eeb 100644 --- a/src/net/knarcraft/serverlauncher/profile/Profile.java +++ b/src/net/knarcraft/serverlauncher/profile/Profile.java @@ -32,9 +32,9 @@ public class Profile { private static final ArrayList profiles = new ArrayList<>(); private static Profile current; private static GUI gui; - private static final String profilesDir = Main.appDir + File.separator + "files"; - private static final String profilesFile = Main.appDir + File.separator + "files" + File.separator + "Profiles.txt"; - private static final String jarDir = Main.appDir + File.separator + "files" + File.separator + "Jars" + File.separator; + private static final String profilesDir = Main.getAppDir() + File.separator + "files"; + private static final String profilesFile = Main.getAppDir() + File.separator + "files" + File.separator + "Profiles.txt"; + private static final String jarDir = Main.getAppDir() + File.separator + "files" + File.separator + "Jars" + File.separator; private final ArrayList collections; private final String name; @@ -139,6 +139,11 @@ public class Profile { this.downloadJars = value; } + /** + * Set the current profile to the profile with a certain name. + * + * @param name The name of the profile + */ public static void setCurrent(String name) { for (Profile profile : profiles) { if (profile.name.equals(name)) { diff --git a/src/net/knarcraft/serverlauncher/server/Server.java b/src/net/knarcraft/serverlauncher/server/Server.java index 19da2c4..a61b6c8 100644 --- a/src/net/knarcraft/serverlauncher/server/Server.java +++ b/src/net/knarcraft/serverlauncher/server/Server.java @@ -25,7 +25,7 @@ public class Server { private static final String[] ramList = { "512M", "1G", "2G", "3G", "4G", "5G", "6G", "7G", "8G", "9G", "10G","11G", "12G", "13G", "14G", "15G", "16G" }; - private static final String jarDir = Main.appDir + File.separator + "files" + File.separator + "Jars" + File.separator; + private static final String jarDir = Main.getAppDir() + File.separator + "files" + File.separator + "Jars" + File.separator; private final String name; private String path; @@ -293,9 +293,9 @@ public class Server { ProcessBuilder builder; String serverPath; if (Profile.getCurrent().getDownloadJars() && !type.getName().equals("Custom")) { - serverPath = "\"" + jarDir + this.getType() + "\""; + serverPath = jarDir + this.getType(); } else { - serverPath = "\"" + this.path + File.separator + this.getType() + "\""; + serverPath = this.path + File.separator + this.getType(); } builder = new ProcessBuilder( "java", diff --git a/src/net/knarcraft/serverlauncher/userinterface/GUI.java b/src/net/knarcraft/serverlauncher/userinterface/GUI.java index b4db9fe..7c06e58 100644 --- a/src/net/knarcraft/serverlauncher/userinterface/GUI.java +++ b/src/net/knarcraft/serverlauncher/userinterface/GUI.java @@ -1,5 +1,6 @@ package net.knarcraft.serverlauncher.userinterface; +import net.knarcraft.serverlauncher.Main; import net.knarcraft.serverlauncher.profile.Collection; import net.knarcraft.serverlauncher.server.Server; import net.knarcraft.serverlauncher.profile.Profile; @@ -93,6 +94,11 @@ public class GUI implements ActionListener { */ public void setStatus(String text) { this.lblStatuslabel.setText(text); + try (PrintWriter file = new PrintWriter(new FileWriter(Main.getAppDir() + File.separator + "latestrun.log", true))) { + file.println(text); + } catch (IOException e ) { + e.printStackTrace(); + } } /**