diff --git a/src/main/Main.java b/src/main/Main.java index 343b389..aff2565 100644 --- a/src/main/Main.java +++ b/src/main/Main.java @@ -1,6 +1,7 @@ package main; import javafx.application.Application; +import javafx.application.Platform; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; @@ -32,6 +33,7 @@ public class Main extends Application { primaryStage.setOnCloseRequest( event -> { companion.abort(); + Platform.exit(); }); } diff --git a/src/main/extensions/Extension.java b/src/main/extensions/Extension.java index 1497d26..8b842ee 100644 --- a/src/main/extensions/Extension.java +++ b/src/main/extensions/Extension.java @@ -5,12 +5,11 @@ import main.protocol.HPacket; import main.ui.extensions.Extensions; import java.io.*; -import java.lang.annotation.Annotation; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.reflect.AnnotatedType; import java.net.Socket; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * Created by Jonas on 23/06/18. @@ -26,12 +25,23 @@ public abstract class Extension { private static final String[] PORT_FLAG = {"--port", "-p"}; + private static final String[] FILE_FLAG = {"--filename", "-f"}; private OutputStream out = null; private final Map> incomingMessageListeners = new HashMap<>(); private final Map> outgoingMessageListeners = new HashMap<>(); private FlagsCheckListener flagRequestCallback = null; + private String getArgument(String[] args, String... arg) { + for (int i = 0; i < args.length - 1; i++) { + for (String str : arg) { + if (args[i].toLowerCase().equals(str.toLowerCase())) { + return args[i+1]; + } + } + } + return null; + } /** * Makes the connection with G-Earth, pass the arguments given in the Main method "super(args)" @@ -52,17 +62,8 @@ public abstract class Extension { return; } - int port = 0; - - outerloop: - for (int i = 0; i < args.length - 1; i++) { - for (String str : PORT_FLAG) { - if (args[i].equals(str)) { - port = Integer.parseInt(args[i+1]); - break outerloop; - } - } - } + int port = Integer.parseInt(getArgument(args, PORT_FLAG)); + String file = getArgument(args, FILE_FLAG); Socket gEarthExtensionServer = null; try { @@ -102,7 +103,9 @@ public abstract class Extension { .appendString(info.Author()) .appendString(info.Version()) .appendString(info.Description()) - .appendBoolean(isOnClickMethodUsed()); + .appendBoolean(isOnClickMethodUsed()) + .appendBoolean(file == null) + .appendString(file == null ? "": file); writeToStream(response.toBytes()); } else if (packet.headerId() == Extensions.OUTGOING_MESSAGES_IDS.CONNECTIONSTART) { @@ -142,7 +145,7 @@ public abstract class Extension { incomingMessageListeners : outgoingMessageListeners; - Set correctListeners = new HashSet<>(); + List correctListeners = new ArrayList<>(); synchronized (incomingMessageListeners) { synchronized (outgoingMessageListeners) { diff --git a/src/main/extensions/ExtensionForm.java b/src/main/extensions/ExtensionForm.java index c4ffbbf..3c33741 100644 --- a/src/main/extensions/ExtensionForm.java +++ b/src/main/extensions/ExtensionForm.java @@ -2,16 +2,9 @@ package main.extensions; import javafx.application.Application; import javafx.application.Platform; -import javafx.event.EventHandler; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; import javafx.stage.Stage; -import javafx.stage.WindowEvent; import main.protocol.HMessage; import main.protocol.HPacket; -import main.ui.GEarthController; - -import java.net.URL; /** * Created by Jonas on 22/09/18. diff --git a/src/main/ui/extensions/GEarthExtension.java b/src/main/ui/extensions/GEarthExtension.java index 9d88dda..8d02fb8 100644 --- a/src/main/ui/extensions/GEarthExtension.java +++ b/src/main/ui/extensions/GEarthExtension.java @@ -1,16 +1,12 @@ package main.ui.extensions; import javafx.beans.InvalidationListener; -import main.protocol.HMessage; import main.protocol.HPacket; -import main.protocol.packethandler.PayloadBuffer; import java.io.DataInputStream; -import java.io.EOFException; import java.io.IOException; import java.io.InputStream; import java.net.Socket; -import java.net.SocketException; import java.util.ArrayList; import java.util.List; @@ -25,6 +21,9 @@ public class GEarthExtension { private String description; private boolean fireEventButtonVisible; + private boolean isInstalledExtension; // <- extension is in the extensions directory + private String fileName; + private Socket connection; //calls callback when the extension is creatd @@ -59,6 +58,8 @@ public class GEarthExtension { packet.readString(), packet.readString(), packet.readBoolean(), + packet.readBoolean(), + packet.readString(), connection, onDisconnectedCallback ); @@ -72,12 +73,16 @@ public class GEarthExtension { } - private GEarthExtension(String title, String author, String version, String description, boolean fireEventButtonVisible, Socket connection, OnDisconnectedCallback onDisconnectedCallback) { + private GEarthExtension(String title, String author, String version, String description, boolean fireEventButtonVisible, boolean isInstalledExtension, String fileName, Socket connection, OnDisconnectedCallback onDisconnectedCallback) { this.title = title; this.author = author; this.version = version; this.description = description; this.fireEventButtonVisible = fireEventButtonVisible; + + this.isInstalledExtension = isInstalledExtension; + this.fileName = fileName; + this.connection = connection; GEarthExtension selff = this; @@ -146,7 +151,13 @@ public class GEarthExtension { return fireEventButtonVisible; } + public String getFileName() { + return fileName; + } + public boolean isInstalledExtension() { + return isInstalledExtension; + } public boolean closeConnection() { try { diff --git a/src/main/ui/extensions/executer/ExecutionInfo.java b/src/main/ui/extensions/executer/ExecutionInfo.java index ef56945..e3b28da 100644 --- a/src/main/ui/extensions/executer/ExecutionInfo.java +++ b/src/main/ui/extensions/executer/ExecutionInfo.java @@ -16,11 +16,18 @@ public class ExecutionInfo { static { extensionTypeToExecutionCommand = new HashMap<>(); - extensionTypeToExecutionCommand.put("*.jar","java -jar {path} -p {port}"); - extensionTypeToExecutionCommand.put("*.py","python {path} -p {port}"); - extensionTypeToExecutionCommand.put("*.py3","python3 {path} -p {port}"); - extensionTypeToExecutionCommand.put("*.sh","{path} -p {port}"); - extensionTypeToExecutionCommand.put("*.exe","{path} -p {port}"); + extensionTypeToExecutionCommand.put("*.jar","java -jar {path}"); + extensionTypeToExecutionCommand.put("*.py","python {path}"); + extensionTypeToExecutionCommand.put("*.py3","python3 {path}"); + extensionTypeToExecutionCommand.put("*.sh","{path}"); + extensionTypeToExecutionCommand.put("*.exe","{path}"); + + for(String type : extensionTypeToExecutionCommand.keySet()) { + extensionTypeToExecutionCommand.put( + type, + extensionTypeToExecutionCommand.get(type) + " -p {port} -f {filename}" + ); + } ALLOWEDEXTENSIONTYPES = new ArrayList<>(extensionTypeToExecutionCommand.keySet()); } diff --git a/src/main/ui/extensions/executer/NormalExtensionRunner.java b/src/main/ui/extensions/executer/NormalExtensionRunner.java index 38dc8c4..4af272f 100644 --- a/src/main/ui/extensions/executer/NormalExtensionRunner.java +++ b/src/main/ui/extensions/executer/NormalExtensionRunner.java @@ -71,6 +71,7 @@ public class NormalExtensionRunner implements ExtensionRunner { ExecutionInfo.getExecutionCommand(getFileExtension(path)) .replace("{path}", path) .replace("{port}", port+"") + .replace("{filename}", Paths.get(path).getFileName().toString()) ); } catch (IOException e) { e.printStackTrace(); @@ -86,6 +87,7 @@ public class NormalExtensionRunner implements ExtensionRunner { String[] split = name.split("\\."); return "*." + split[split.length - 1]; } + private boolean dirExists(String dir) { return Files.isDirectory(Paths.get(FileSystems.getDefault().getPath(".").toString(), dir)); }