mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-27 02:40:51 +01:00
link filename to extension files
This commit is contained in:
parent
fdd75c142f
commit
260ebc5a4b
@ -1,6 +1,7 @@
|
|||||||
package main;
|
package main;
|
||||||
|
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
@ -32,6 +33,7 @@ public class Main extends Application {
|
|||||||
|
|
||||||
primaryStage.setOnCloseRequest( event -> {
|
primaryStage.setOnCloseRequest( event -> {
|
||||||
companion.abort();
|
companion.abort();
|
||||||
|
Platform.exit();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,11 @@ import main.protocol.HPacket;
|
|||||||
import main.ui.extensions.Extensions;
|
import main.ui.extensions.Extensions;
|
||||||
|
|
||||||
import java.io.*;
|
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.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.
|
* 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[] PORT_FLAG = {"--port", "-p"};
|
||||||
|
private static final String[] FILE_FLAG = {"--filename", "-f"};
|
||||||
|
|
||||||
private OutputStream out = null;
|
private OutputStream out = null;
|
||||||
private final Map<Integer, List<MessageListener>> incomingMessageListeners = new HashMap<>();
|
private final Map<Integer, List<MessageListener>> incomingMessageListeners = new HashMap<>();
|
||||||
private final Map<Integer, List<MessageListener>> outgoingMessageListeners = new HashMap<>();
|
private final Map<Integer, List<MessageListener>> outgoingMessageListeners = new HashMap<>();
|
||||||
private FlagsCheckListener flagRequestCallback = null;
|
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)"
|
* 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int port = 0;
|
int port = Integer.parseInt(getArgument(args, PORT_FLAG));
|
||||||
|
String file = getArgument(args, FILE_FLAG);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Socket gEarthExtensionServer = null;
|
Socket gEarthExtensionServer = null;
|
||||||
try {
|
try {
|
||||||
@ -102,7 +103,9 @@ public abstract class Extension {
|
|||||||
.appendString(info.Author())
|
.appendString(info.Author())
|
||||||
.appendString(info.Version())
|
.appendString(info.Version())
|
||||||
.appendString(info.Description())
|
.appendString(info.Description())
|
||||||
.appendBoolean(isOnClickMethodUsed());
|
.appendBoolean(isOnClickMethodUsed())
|
||||||
|
.appendBoolean(file == null)
|
||||||
|
.appendString(file == null ? "": file);
|
||||||
writeToStream(response.toBytes());
|
writeToStream(response.toBytes());
|
||||||
}
|
}
|
||||||
else if (packet.headerId() == Extensions.OUTGOING_MESSAGES_IDS.CONNECTIONSTART) {
|
else if (packet.headerId() == Extensions.OUTGOING_MESSAGES_IDS.CONNECTIONSTART) {
|
||||||
@ -142,7 +145,7 @@ public abstract class Extension {
|
|||||||
incomingMessageListeners :
|
incomingMessageListeners :
|
||||||
outgoingMessageListeners;
|
outgoingMessageListeners;
|
||||||
|
|
||||||
Set<MessageListener> correctListeners = new HashSet<>();
|
List<MessageListener> correctListeners = new ArrayList<>();
|
||||||
|
|
||||||
synchronized (incomingMessageListeners) {
|
synchronized (incomingMessageListeners) {
|
||||||
synchronized (outgoingMessageListeners) {
|
synchronized (outgoingMessageListeners) {
|
||||||
|
@ -2,16 +2,9 @@ package main.extensions;
|
|||||||
|
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.event.EventHandler;
|
|
||||||
import javafx.fxml.FXMLLoader;
|
|
||||||
import javafx.scene.Parent;
|
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import javafx.stage.WindowEvent;
|
|
||||||
import main.protocol.HMessage;
|
import main.protocol.HMessage;
|
||||||
import main.protocol.HPacket;
|
import main.protocol.HPacket;
|
||||||
import main.ui.GEarthController;
|
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Jonas on 22/09/18.
|
* Created by Jonas on 22/09/18.
|
||||||
|
@ -1,16 +1,12 @@
|
|||||||
package main.ui.extensions;
|
package main.ui.extensions;
|
||||||
|
|
||||||
import javafx.beans.InvalidationListener;
|
import javafx.beans.InvalidationListener;
|
||||||
import main.protocol.HMessage;
|
|
||||||
import main.protocol.HPacket;
|
import main.protocol.HPacket;
|
||||||
import main.protocol.packethandler.PayloadBuffer;
|
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.EOFException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -25,6 +21,9 @@ public class GEarthExtension {
|
|||||||
private String description;
|
private String description;
|
||||||
private boolean fireEventButtonVisible;
|
private boolean fireEventButtonVisible;
|
||||||
|
|
||||||
|
private boolean isInstalledExtension; // <- extension is in the extensions directory
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
private Socket connection;
|
private Socket connection;
|
||||||
|
|
||||||
//calls callback when the extension is creatd
|
//calls callback when the extension is creatd
|
||||||
@ -59,6 +58,8 @@ public class GEarthExtension {
|
|||||||
packet.readString(),
|
packet.readString(),
|
||||||
packet.readString(),
|
packet.readString(),
|
||||||
packet.readBoolean(),
|
packet.readBoolean(),
|
||||||
|
packet.readBoolean(),
|
||||||
|
packet.readString(),
|
||||||
connection,
|
connection,
|
||||||
onDisconnectedCallback
|
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.title = title;
|
||||||
this.author = author;
|
this.author = author;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.fireEventButtonVisible = fireEventButtonVisible;
|
this.fireEventButtonVisible = fireEventButtonVisible;
|
||||||
|
|
||||||
|
this.isInstalledExtension = isInstalledExtension;
|
||||||
|
this.fileName = fileName;
|
||||||
|
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
|
|
||||||
GEarthExtension selff = this;
|
GEarthExtension selff = this;
|
||||||
@ -146,7 +151,13 @@ public class GEarthExtension {
|
|||||||
return fireEventButtonVisible;
|
return fireEventButtonVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFileName() {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInstalledExtension() {
|
||||||
|
return isInstalledExtension;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean closeConnection() {
|
public boolean closeConnection() {
|
||||||
try {
|
try {
|
||||||
|
@ -16,11 +16,18 @@ public class ExecutionInfo {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
extensionTypeToExecutionCommand = new HashMap<>();
|
extensionTypeToExecutionCommand = new HashMap<>();
|
||||||
extensionTypeToExecutionCommand.put("*.jar","java -jar {path} -p {port}");
|
extensionTypeToExecutionCommand.put("*.jar","java -jar {path}");
|
||||||
extensionTypeToExecutionCommand.put("*.py","python {path} -p {port}");
|
extensionTypeToExecutionCommand.put("*.py","python {path}");
|
||||||
extensionTypeToExecutionCommand.put("*.py3","python3 {path} -p {port}");
|
extensionTypeToExecutionCommand.put("*.py3","python3 {path}");
|
||||||
extensionTypeToExecutionCommand.put("*.sh","{path} -p {port}");
|
extensionTypeToExecutionCommand.put("*.sh","{path}");
|
||||||
extensionTypeToExecutionCommand.put("*.exe","{path} -p {port}");
|
extensionTypeToExecutionCommand.put("*.exe","{path}");
|
||||||
|
|
||||||
|
for(String type : extensionTypeToExecutionCommand.keySet()) {
|
||||||
|
extensionTypeToExecutionCommand.put(
|
||||||
|
type,
|
||||||
|
extensionTypeToExecutionCommand.get(type) + " -p {port} -f {filename}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
ALLOWEDEXTENSIONTYPES = new ArrayList<>(extensionTypeToExecutionCommand.keySet());
|
ALLOWEDEXTENSIONTYPES = new ArrayList<>(extensionTypeToExecutionCommand.keySet());
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,7 @@ public class NormalExtensionRunner implements ExtensionRunner {
|
|||||||
ExecutionInfo.getExecutionCommand(getFileExtension(path))
|
ExecutionInfo.getExecutionCommand(getFileExtension(path))
|
||||||
.replace("{path}", path)
|
.replace("{path}", path)
|
||||||
.replace("{port}", port+"")
|
.replace("{port}", port+"")
|
||||||
|
.replace("{filename}", Paths.get(path).getFileName().toString())
|
||||||
);
|
);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -86,6 +87,7 @@ public class NormalExtensionRunner implements ExtensionRunner {
|
|||||||
String[] split = name.split("\\.");
|
String[] split = name.split("\\.");
|
||||||
return "*." + split[split.length - 1];
|
return "*." + split[split.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean dirExists(String dir) {
|
private boolean dirExists(String dir) {
|
||||||
return Files.isDirectory(Paths.get(FileSystems.getDefault().getPath(".").toString(), dir));
|
return Files.isDirectory(Paths.get(FileSystems.getDefault().getPath(".").toString(), dir));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user