findClient(ChannelHandlerContext ctx) {
+ return Optional.ofNullable(ctx.attr(CLIENT).get());
+ }
+ }
+}
diff --git a/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/NetworkExtensionsProducer.java b/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/NetworkExtensionsProducer.java
deleted file mode 100644
index d381e50..0000000
--- a/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/NetworkExtensionsProducer.java
+++ /dev/null
@@ -1,167 +0,0 @@
-package gearth.services.extension_handler.extensions.implementations.network;
-
-import gearth.protocol.HPacket;
-import gearth.services.extension_handler.extensions.extensionproducers.ExtensionProducer;
-import gearth.services.extension_handler.extensions.extensionproducers.ExtensionProducerFactory;
-import gearth.services.extension_handler.extensions.extensionproducers.ExtensionProducerObserver;
-import gearth.services.extension_handler.extensions.implementations.network.authentication.Authenticator;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.Socket;
-
-/**
- * Represents an {@link ExtensionProducer} that implements a server to which
- * remotely-ran extensions can connect.
- *
- * @see ExtensionProducerFactory#getAll() for instance creation.
- *
- * Created by Jonas on 21/06/18.
- */
-public final class NetworkExtensionsProducer implements ExtensionProducer {
-
- /**
- * Initial port server tries to listen at, if {@link ServerSocket} creation fails,
- * it tries next port.
- */
- private static final int PORT_ONSET = 9092;
-
- /**
- * Represents the number of bytes per boolean encoded in an incoming packet.
- */
- private static final int BOOLEAN_SIZE = 1;
-
- /**
- * Represents the maximum number of bytes per string encoded in an incoming packet.
- */
- private static final int MAX_STRING_SIZE = Character.BYTES * 4_000;
-
- /**
- * Length is encoded as an {@link Integer} and header id as an {@link Short}.
- */
- private static final int PACKET_HEADER_SIZE = Integer.BYTES + Short.BYTES;
-
- /**
- * Represents the maximum number of bytes in the body of an incoming packet.
- *
- * Used as a form of validation for packets, prevents other Apps that connect
- * with the server from sending unexpected data and inexplicably causing huge byte array allocations.
- *
- * Since the server only accepts {@link NetworkExtensionInfo.INCOMING_MESSAGES_IDS#EXTENSIONINFO} packets,
- * this value is calculated based on that packet.
- */
- private static final int MAX_PACKET_BODY_SIZE = (MAX_STRING_SIZE * 6) + (BOOLEAN_SIZE * 4);
-
- /**
- * The port at which the {@link #serverSocket} is listening for incoming connections.
- */
- public static int extensionPort = -1;
-
- private ServerSocket serverSocket;
-
- @Override
- public void startProducing(ExtensionProducerObserver observer) {
-
- /*
- Initialise the serverSocket at the argued port.
- */
- int port = PORT_ONSET;
- while (!createServer(port))
- ++port;
-
- /*
- Start connection listener thread.
- */
- new Thread(() -> {
-
- try {
-
- while (!serverSocket.isClosed()) {
-
- // accept a new connection
- final Socket extensionSocket = serverSocket.accept();
- extensionSocket.setTcpNoDelay(true);
-
- /*
- Start client session handler thread.
- */
- new Thread(() -> {
-
- try {
-
- // write INFOREQUEST packet to client
- synchronized (extensionSocket) {
- extensionSocket.getOutputStream().write((new HPacket(NetworkExtensionInfo.OUTGOING_MESSAGES_IDS.INFOREQUEST)).toBytes());
- }
-
- final DataInputStream dIn = new DataInputStream(extensionSocket.getInputStream());
-
- // listen to incoming data from client
- while (!extensionSocket.isClosed()) {
-
- final int bodyLength = dIn.readInt() - Short.BYTES;
- final short headerId = dIn.readShort();
-
- if (headerId == NetworkExtensionInfo.INCOMING_MESSAGES_IDS.EXTENSIONINFO) {
-
- if (bodyLength > MAX_PACKET_BODY_SIZE) {
- System.err.printf("Incoming packet(h=%d, l=%d) exceeds max packet body size %d.\n", headerId, bodyLength, MAX_PACKET_BODY_SIZE);
- break;
- }
-
- final HPacket packet = readPacket(dIn, bodyLength, headerId);
-
- final NetworkExtension gEarthExtension = new NetworkExtension(packet, extensionSocket);
-
- if (Authenticator.evaluate(gEarthExtension))
- observer.onExtensionProduced(gEarthExtension);
- else
- gEarthExtension.close();
-
- break;
- }
- }
- } catch (IOException ignored) {
- }
- }).start();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }).start();
- }
-
- private boolean createServer(int port) {
- try {
- serverSocket = new ServerSocket(port);
- extensionPort = port;
- return true;
- } catch (IOException e) {
- return false;
- }
- }
-
- private HPacket readPacket(DataInputStream dIn, int amountToRead, short id) throws IOException {
- final byte[] headerAndBody = new byte[amountToRead + PACKET_HEADER_SIZE];
-
- int amountRead = 0;
- while (amountRead < amountToRead)
- amountRead += dIn.read(headerAndBody, amountRead + PACKET_HEADER_SIZE, Math.min(dIn.available(), amountToRead - amountRead));
-
- final HPacket packet = new HPacket(headerAndBody);
- packet.fixLength();
- packet.replaceShort(4, id); // add header id
-
- return packet;
- }
-
- /**
- * Retrieves the {@link ServerSocket#getLocalPort()} of {@link #serverSocket}.
- *
- * @return the port number to which {@link #serverSocket} is listening or -1 if the socket is not bound yet.
- */
- public int getPort() {
- return serverSocket.getLocalPort();
- }
-}
diff --git a/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/authentication/Authenticator.java b/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/authentication/Authenticator.java
deleted file mode 100644
index 5f6b694..0000000
--- a/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/authentication/Authenticator.java
+++ /dev/null
@@ -1,116 +0,0 @@
-package gearth.services.extension_handler.extensions.implementations.network.authentication;
-
-import gearth.misc.ConfirmationDialog;
-import gearth.services.extension_handler.extensions.implementations.network.NetworkExtension;
-import gearth.ui.titlebar.TitleBarController;
-import javafx.application.Platform;
-import javafx.scene.control.Alert;
-import javafx.scene.control.ButtonType;
-import javafx.scene.control.Label;
-
-import java.io.IOException;
-import java.util.*;
-
-/**
- * Created by Jonas on 16/10/18.
- */
-public class Authenticator {
-
- private static Map cookies = new HashMap<>();
- private static Set perma_cookies = new HashSet<>();
-
- public static String generateCookieForExtension(String filename) {
- String cookie = getRandomCookie();
- cookies.put(filename, cookie);
- return cookie;
- }
- public static String generatePermanentCookie() {
- String cookie = getRandomCookie();
- perma_cookies.add(cookie);
- return cookie;
- }
-
- public static boolean evaluate(NetworkExtension extension) {
- if (extension.getCookie() != null && perma_cookies.contains(extension.getCookie())) {
- return true;
- }
-
- if (extension.isInstalledExtension()) {
- return claimSession(extension.getFileName(), extension.getCookie());
- }
- else {
- return askForPermission(extension);
- }
- }
-
- /**
- * authenticator: authenticate an extension and remove the cookie
- * @param filename
- * @param cookie
- * @return if the extension is authenticated
- */
- private static boolean claimSession(String filename, String cookie) {
- if (cookies.containsKey(filename) && cookies.get(filename).equals(cookie)) {
- cookies.remove(filename);
- return true;
- }
- return false;
- }
-
- private static volatile boolean rememberOption = false;
- //for not-installed extensions, popup a dialog
- private static boolean askForPermission(NetworkExtension extension) {
- boolean[] allowConnection = {true};
-
- final String connectExtensionKey = "allow_extension_connection";
-
- if (ConfirmationDialog.showDialog(connectExtensionKey)) {
- boolean[] done = {false};
- Platform.runLater(() -> {
- Alert alert = ConfirmationDialog.createAlertWithOptOut(Alert.AlertType.WARNING, connectExtensionKey
- ,"Confirmation Dialog", null,
- "", "Remember my choice",
- ButtonType.YES, ButtonType.NO
- );
-
- alert.getDialogPane().setContent(new Label("Extension \""+extension.getTitle()+"\" tries to connect but isn't known to G-Earth,\n" +
- "accept this connection?"));
-
- try {
- if (!(TitleBarController.create(alert).showAlertAndWait()
- .filter(t -> t == ButtonType.YES).isPresent())) {
- allowConnection[0] = false;
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- done[0] = true;
- if (!ConfirmationDialog.showDialog(connectExtensionKey)) {
- rememberOption = allowConnection[0];
- }
- });
-
- while (!done[0]) {
- try {
- Thread.sleep(1);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- return allowConnection[0];
- }
-
- return rememberOption;
- }
-
- private static String getRandomCookie() {
- StringBuilder builder = new StringBuilder();
- Random r = new Random();
- for (int i = 0; i < 40; i++) {
- builder.append(r.nextInt(40));
- }
-
- return builder.toString();
- }
-}
diff --git a/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/executer/ExecutionInfo.java b/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/executer/ExecutionInfo.java
index 6732de1..c2c7a2d 100644
--- a/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/executer/ExecutionInfo.java
+++ b/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/executer/ExecutionInfo.java
@@ -8,39 +8,39 @@ import java.util.Map;
/**
* Created by Jonas on 22/09/18.
*/
-public class ExecutionInfo {
+public final class ExecutionInfo {
- private static Map extensionTypeToExecutionCommand;
- public final static List ALLOWEDEXTENSIONTYPES;
- public final static String EXTENSIONSDIRECTORY = "Extensions";
+ private static final Map EXTENSION_TYPE_TO_EXECUTION_COMMAND;
+
+ public final static List ALLOWED_EXTENSION_TYPES;
+ public final static String EXTENSIONS_DIRECTORY = "Extensions";
static {
- extensionTypeToExecutionCommand = new HashMap<>();
- extensionTypeToExecutionCommand.put("*.jar", new String[]{"java", "-jar", "{path}"});
- extensionTypeToExecutionCommand.put("*.py", new String[]{"python", "{path}"});
- extensionTypeToExecutionCommand.put("*.py3", new String[]{"python3", "{path}"});
- extensionTypeToExecutionCommand.put("*.sh", new String[]{"{path}"});
- extensionTypeToExecutionCommand.put("*.exe", new String[]{"{path}"});
- extensionTypeToExecutionCommand.put("*.js", new String[]{"node", "{path}"});
- String[] extraArgs = {"-p", "{port}", "-f", "{filename}", "-c", "{cookie}"};
- for(String type : extensionTypeToExecutionCommand.keySet()) {
- String[] commandShort = extensionTypeToExecutionCommand.get(type);
- String[] combined = new String[extraArgs.length + commandShort.length];
+ EXTENSION_TYPE_TO_EXECUTION_COMMAND = new HashMap<>();
+ EXTENSION_TYPE_TO_EXECUTION_COMMAND.put("*.jar", new String[]{"java", "-jar", "{path}"});
+ EXTENSION_TYPE_TO_EXECUTION_COMMAND.put("*.py", new String[]{"python", "{path}"});
+ EXTENSION_TYPE_TO_EXECUTION_COMMAND.put("*.py3", new String[]{"python3", "{path}"});
+ EXTENSION_TYPE_TO_EXECUTION_COMMAND.put("*.sh", new String[]{"{path}"});
+ EXTENSION_TYPE_TO_EXECUTION_COMMAND.put("*.exe", new String[]{"{path}"});
+ EXTENSION_TYPE_TO_EXECUTION_COMMAND.put("*.js", new String[]{"node", "{path}"});
+
+ final String[] extraArgs = {"-p", "{port}", "-f", "{filename}", "-c", "{cookie}"};
+
+ for(String type : EXTENSION_TYPE_TO_EXECUTION_COMMAND.keySet()) {
+
+ final String[] commandShort = EXTENSION_TYPE_TO_EXECUTION_COMMAND.get(type);
+ final String[] combined = new String[extraArgs.length + commandShort.length];
System.arraycopy(commandShort, 0, combined, 0, commandShort.length);
System.arraycopy(extraArgs, 0, combined, commandShort.length, extraArgs.length);
- extensionTypeToExecutionCommand.put(
- type,
- combined
- );
+ EXTENSION_TYPE_TO_EXECUTION_COMMAND.put(type, combined);
}
- ALLOWEDEXTENSIONTYPES = new ArrayList<>(extensionTypeToExecutionCommand.keySet());
+ ALLOWED_EXTENSION_TYPES = new ArrayList<>(EXTENSION_TYPE_TO_EXECUTION_COMMAND.keySet());
}
public static String[] getExecutionCommand(String type) {
- return extensionTypeToExecutionCommand.get(type);
+ return EXTENSION_TYPE_TO_EXECUTION_COMMAND.get(type);
}
-
}
diff --git a/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/executer/ExtensionRunnerFactory.java b/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/executer/ExtensionRunnerFactory.java
index fd26dcb..2b569c2 100644
--- a/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/executer/ExtensionRunnerFactory.java
+++ b/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/executer/ExtensionRunnerFactory.java
@@ -3,9 +3,9 @@ package gearth.services.extension_handler.extensions.implementations.network.exe
/**
* Created by Jonas on 22/09/18.
*/
-public class ExtensionRunnerFactory {
+public final class ExtensionRunnerFactory {
- private static ExtensionRunner runner = new NormalExtensionRunner();
+ private static final ExtensionRunner runner = new NormalExtensionRunner();
public static ExtensionRunner get() {
return runner;
diff --git a/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/executer/NormalExtensionRunner.java b/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/executer/NormalExtensionRunner.java
index ba8bc29..4f3a113 100644
--- a/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/executer/NormalExtensionRunner.java
+++ b/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/executer/NormalExtensionRunner.java
@@ -1,207 +1,198 @@
package gearth.services.extension_handler.extensions.implementations.network.executer;
import gearth.GEarth;
-import gearth.services.extension_handler.extensions.implementations.network.authentication.Authenticator;
+import gearth.services.extension_handler.extensions.implementations.network.NetworkExtensionAuthenticator;
import gearth.services.internal_extensions.extensionstore.tools.StoreExtensionTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
-import java.nio.file.*;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Random;
/**
* Created by Jonas on 22/09/18.
*/
-public class NormalExtensionRunner implements ExtensionRunner {
+public final class NormalExtensionRunner implements ExtensionRunner {
- public static final String JARPATH;
+ private final static Logger LOGGER = LoggerFactory.getLogger(NormalExtensionRunner.class);
+
+ public static final String JAR_PATH;
static {
+ final URL url = getLocation();
String value;
try {
- value = new File(GEarth.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParent();
+ value = new File(url.toURI()).getParent();
} catch (URISyntaxException e) {
- value = new File(GEarth.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParent();
- e.printStackTrace();
+ value = new File(url.getPath()).getParent();
+ LOGGER.warn("Failed to load JAR_PATH from url {} as URI, using Path instead", url, e);
}
- JARPATH = value;
+ JAR_PATH = value;
+ LOGGER.debug("Set JAR_PATH as {}", JAR_PATH);
}
@Override
public void runAllExtensions(int port) {
- if (dirExists(ExecutionInfo.EXTENSIONSDIRECTORY)){
- File folder =
- new File(JARPATH +
- FileSystems.getDefault().getSeparator()+
- ExecutionInfo.EXTENSIONSDIRECTORY);
- File[] childs = folder.listFiles();
- for (File file : childs) {
- tryRunExtension(file.getPath(), port);
+ if (dirExists(ExecutionInfo.EXTENSIONS_DIRECTORY)) {
+
+ final File extensionsDirectory = Paths.get(JAR_PATH, ExecutionInfo.EXTENSIONS_DIRECTORY).toFile();
+ final File[] extensionFiles = extensionsDirectory.listFiles();
+
+ if (extensionFiles == null) {
+ LOGGER.error("Provided extensionsDirectory does not exist (extensionsDirectory={})", extensionsDirectory);
+ return;
}
- }
+
+ for (File file : extensionFiles)
+ tryRunExtension(file.getPath(), port);
+ } else
+ LOGGER.warn("Did not run extensions because extensions directory does not exist at {}", ExecutionInfo.EXTENSIONS_DIRECTORY);
}
@Override
- public void installAndRunExtension(String path, int port) {
- if (!dirExists(ExecutionInfo.EXTENSIONSDIRECTORY)) {
- createDirectory(ExecutionInfo.EXTENSIONSDIRECTORY);
- }
+ public void installAndRunExtension(String stringPath, int port) {
+ if (!dirExists(ExecutionInfo.EXTENSIONS_DIRECTORY))
+ tryCreateDirectory(ExecutionInfo.EXTENSIONS_DIRECTORY);
- String name = Paths.get(path).getFileName().toString();
- String[] split = name.split("\\.");
- String ext = "*." + split[split.length - 1];
+ final Path path = Paths.get(stringPath);
+ final String name = path.getFileName().toString();
+ final String[] split = name.split("\\.");
+ final String ext = "*." + split[split.length - 1];
- String realname = String.join(".",Arrays.copyOf(split, split.length-1));
- String newname = realname + "-" + getRandomString() + ext.substring(1);
+ final String realName = String.join(".", Arrays.copyOf(split, split.length - 1));
+ final String newName = realName + "-" + getRandomString() + ext.substring(1);
- Path originalPath = Paths.get(path);
- Path newPath = Paths.get(
- JARPATH,
- ExecutionInfo.EXTENSIONSDIRECTORY,
- newname
- );
+ final Path newPath = Paths.get(JAR_PATH, ExecutionInfo.EXTENSIONS_DIRECTORY, newName);
try {
- Files.copy(
- originalPath,
- newPath
- );
-// addExecPermission(newPath.toString());
+ Files.copy(path, newPath);
+
tryRunExtension(newPath.toString(), port);
} catch (IOException e) {
e.printStackTrace();
}
-
-
}
public void tryRunExtension(String path, int port) {
try {
+
if (new File(path).isDirectory()) {
- // this extension is installed from the extension store and requires
- // different behavior
+ // this extension is installed from the extension store and requires different behavior
StoreExtensionTools.executeExtension(path, port);
return;
}
- String filename = Paths.get(path).getFileName().toString();
-
- String[] execCommand = ExecutionInfo.getExecutionCommand(getFileExtension(path));
- execCommand = Arrays.copyOf(execCommand, execCommand.length);
- String cookie = Authenticator.generateCookieForExtension(filename);
+ final String filename = Paths.get(path).getFileName().toString();
+ final String[] execCommand = ExecutionInfo
+ .getExecutionCommand(getFileExtension(path))
+ .clone();
+ final String cookie = NetworkExtensionAuthenticator.generateCookieForExtension(filename);
for (int i = 0; i < execCommand.length; i++) {
execCommand[i] = execCommand[i]
.replace("{path}", path)
- .replace("{port}", port+"")
+ .replace("{port}", port + "")
.replace("{filename}", filename)
.replace("{cookie}", cookie);
}
- ProcessBuilder pb = new ProcessBuilder(execCommand);
-// Process proc = Runtime.getRuntime().exec(execCommand);
- Process proc = pb.start();
- maybeLogExtension(path, proc);
+ final ProcessBuilder processBuilder = new ProcessBuilder(execCommand);
+ final Process process = processBuilder.start();
+
+ maybeLogExtension(path, process);
+
} catch (IOException e) {
- e.printStackTrace();
+ LOGGER.error("Failed to run extension at path {} using port {}", path, port, e);
}
}
- public static void maybeLogExtension(String path, Process proc) {
+
+ public static void maybeLogExtension(String path, Process process) {
if (GEarth.hasFlag(ExtensionRunner.SHOW_EXTENSIONS_LOG)) {
- String sep = "" + System.lineSeparator();
- synchronized (System.out) {
- System.out.println(path + sep + "Launching" + sep + "----------" + sep);
- }
- BufferedReader stdInput = new BufferedReader(new
- InputStreamReader(proc.getInputStream()));
+ final Logger logger = LoggerFactory.getLogger(path);
+ logger.info("Launching...");
+
+ final BufferedReader processInputReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
new Thread(() -> {
try {
String line;
- while((line = stdInput.readLine()) != null) {
- synchronized (System.out) {
- System.out.println(path + sep + "Output" + sep + line + sep + "----------" + sep);
- }
- }
+ while ((line = processInputReader.readLine()) != null)
+ logger.info(line);
} catch (IOException e) {
- e.printStackTrace();
+ LOGGER.error("Failed to read input line from process {}", process, e);
}
- }).start();
-
- BufferedReader stdError = new BufferedReader(new
- InputStreamReader(proc.getErrorStream()));
+ }, path+"-input").start();
+ final BufferedReader processErrorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
new Thread(() -> {
try {
String line;
- while((line = stdError.readLine()) != null) {
- synchronized (System.out) {
- System.out.println(path + sep + "Error" + sep + line + sep + "----------" + sep);
- }
- }
+ while ((line = processErrorReader.readLine()) != null)
+ logger.error(line);
} catch (IOException e) {
- e.printStackTrace();
+ LOGGER.error("Failed to read error line from process {}", process, e);
}
}).start();
-
}
}
@Override
public void uninstallExtension(String filename) {
try {
- Path path = Paths.get(JARPATH, ExecutionInfo.EXTENSIONSDIRECTORY, filename);
+ final Path path = Paths.get(JAR_PATH, ExecutionInfo.EXTENSIONS_DIRECTORY, filename);
if (new File(path.toString()).isDirectory()) {
// is installed through extension store
StoreExtensionTools.removeExtension(path.toString());
- }
- else {
+ } else
Files.delete(path);
- }
-
} catch (IOException e) {
- e.printStackTrace();
+ LOGGER.error("Failed to uninstall extension at {}", filename, e);
}
}
-// private void addExecPermission(String path) {
-// //not needed at first sight
-// }
+ private static void tryCreateDirectory(String path) {
+ if (!dirExists(path)) {
+ try {
+ Files.createDirectories(Paths.get(JAR_PATH, path));
+ } catch (IOException e) {
+ LOGGER.error("Failed to create directory at {}", path, e);
+ }
+ }
+ }
- private String getFileExtension(String path) {
- String name = Paths.get(path).getFileName().toString();
- String[] split = name.split("\\.");
+ private static boolean dirExists(String dir) {
+ return Files.isDirectory(Paths.get(JAR_PATH, dir));
+ }
+
+ private static URL getLocation() {
+ return GEarth.class.getProtectionDomain().getCodeSource().getLocation();
+ }
+
+ private static String getFileExtension(String path) {
+ final String name = Paths.get(path).getFileName().toString();
+ final String[] split = name.split("\\.");
return "*." + split[split.length - 1];
}
- private boolean dirExists(String dir) {
- return Files.isDirectory(Paths.get(JARPATH, dir));
- }
- private void createDirectory(String dir) {
- if (!dirExists(dir)) {
- try {
- Files.createDirectories(Paths.get(JARPATH, dir));
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- private String getRandomString() {
- StringBuilder builder = new StringBuilder();
- Random r = new Random();
- for (int i = 0; i < 12; i++) {
- builder.append(r.nextInt(10));
- }
-
+ private static String getRandomString() {
+ final StringBuilder builder = new StringBuilder();
+ final Random random = new Random();
+ for (int i = 0; i < 12; i++)
+ builder.append(random.nextInt(10));
return builder.toString();
}
}
diff --git a/G-Earth/src/main/java/gearth/services/g_python/GPythonShell.java b/G-Earth/src/main/java/gearth/services/g_python/GPythonShell.java
index da92ac6..080ddb9 100644
--- a/G-Earth/src/main/java/gearth/services/g_python/GPythonShell.java
+++ b/G-Earth/src/main/java/gearth/services/g_python/GPythonShell.java
@@ -3,6 +3,7 @@ package gearth.services.g_python;
import gearth.GEarth;
import gearth.ui.subforms.extra.ExtraController;
import gearth.ui.titlebar.TitleBarController;
+import gearth.ui.translations.LanguageBundle;
import javafx.application.Platform;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
@@ -170,13 +171,11 @@ public class GPythonShell {
private void showError() {
Platform.runLater(() -> {
- Alert alert = new Alert(Alert.AlertType.ERROR, "G-Python error", ButtonType.OK);
- alert.setTitle("G-Python error");
+ Alert alert = new Alert(Alert.AlertType.ERROR, LanguageBundle.get("alert.gpythonerror.title"), ButtonType.OK);
+ alert.setTitle(LanguageBundle.get("alert.gpythonerror.title"));
FlowPane fp = new FlowPane();
- Label lbl = new Label("Something went wrong launching the G-Python shell," +
- System.lineSeparator() + "are you sure you followed the installation guide correctly?" +
- System.lineSeparator() + System.lineSeparator() + "More information here:");
+ Label lbl = new Label(LanguageBundle.get("alert.gpythonerror.content").replaceAll("\\\\n", System.lineSeparator()));
Hyperlink link = new Hyperlink(ExtraController.INFO_URL_GPYTHON);
fp.getChildren().addAll(lbl, link);
link.setOnAction(event -> {
diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/GExtensionStoreController.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/GExtensionStoreController.java
index 16f12da..4afa23d 100644
--- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/GExtensionStoreController.java
+++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/GExtensionStoreController.java
@@ -23,6 +23,7 @@ import java.util.*;
import java.util.function.Supplier;
public class GExtensionStoreController implements Initializable {
+ private static GExtensionStoreController instance;
private GExtensionStore extensionStore = null;
@@ -37,6 +38,8 @@ public class GExtensionStoreController implements Initializable {
@Override
public void initialize(URL location, ResourceBundle resources) {
+ instance = this;
+
webView = new WebView();
borderPane.setCenter(webView);
@@ -106,6 +109,7 @@ public class GExtensionStoreController implements Initializable {
});
webView.getEngine().load(GExtensionStoreController.class.getResource("webview/index.html").toString());
+
}
@@ -236,4 +240,8 @@ public class GExtensionStoreController implements Initializable {
public String getContentItemsContainer() {
return contentItemsContainer;
}
+
+ public static void reloadPage() {
+ instance.webView.getEngine().reload();
+ }
}
diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/WebUtils.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/WebUtils.java
index 7565b34..7e45109 100644
--- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/WebUtils.java
+++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/WebUtils.java
@@ -1,5 +1,7 @@
package gearth.services.internal_extensions.extensionstore.application;
+import gearth.GEarth;
+import gearth.ui.translations.LanguageBundle;
import org.w3c.dom.Element;
import java.time.LocalDateTime;
@@ -43,19 +45,19 @@ public class WebUtils {
}
public static String elapsedTime(long time) {
- if (time < 60) return time + (time == 1 ? " second" : " seconds");
+ if (time < 60) return time + " " + LanguageBundle.get("ext.store.elapsedtime.second." + (time == 1 ? "single": "multiple"));
time = time/60;
- if (time < 60) return time + (time == 1 ? " minute" : " minutes");
+ if (time < 60) return time + " " + LanguageBundle.get("ext.store.elapsedtime.minute." + (time == 1 ? "single": "multiple"));
time = time/60;
- if (time < 24) return time + (time == 1 ? " hour" : " hours");
+ if (time < 24) return time + " " + LanguageBundle.get("ext.store.elapsedtime.hour." + (time == 1 ? "single": "multiple"));
long days = time/24;
- if (days < 7) return days + (days == 1 ? " day" : " days");
+ if (days < 7) return days + " " + LanguageBundle.get("ext.store.elapsedtime.day." + (days == 1 ? "single": "multiple"));
long weeks = days/7;
- if (weeks < 6) return weeks + (weeks == 1 ? " week" : " weeks");
+ if (weeks < 6) return weeks + " " + LanguageBundle.get("ext.store.elapsedtime.week." + (weeks == 1 ? "single": "multiple"));
long months = days/31;
- if (months < 12) return months + (months == 1 ? " month" : " months");
+ if (months < 12) return months + " " + LanguageBundle.get("ext.store.elapsedtime.month." + (months == 1 ? "single": "multiple"));
long years = days/365;
- return years + (years == 1 ? " year" : " years");
+ return years + " " + LanguageBundle.get("ext.store.elapsedtime.year." + (years == 1 ? "single": "multiple"));
}
public static String escapeMessage(String text) {
diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/StoreExtensionItem.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/StoreExtensionItem.java
index a32516e..d859bbc 100644
--- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/StoreExtensionItem.java
+++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/StoreExtensionItem.java
@@ -1,11 +1,16 @@
package gearth.services.internal_extensions.extensionstore.application.entities;
+import gearth.GEarth;
+import gearth.protocol.HMessage;
+import gearth.protocol.HPacket;
import gearth.services.internal_extensions.extensionstore.GExtensionStore;
import gearth.services.internal_extensions.extensionstore.application.GExtensionStoreController;
import gearth.services.internal_extensions.extensionstore.application.WebUtils;
import gearth.services.internal_extensions.extensionstore.application.entities.extensiondetails.StoreExtensionDetailsOverview;
+import gearth.services.internal_extensions.extensionstore.application.entities.queriedoverviews.CategorizedOverview;
import gearth.services.internal_extensions.extensionstore.repository.StoreRepository;
import gearth.services.internal_extensions.extensionstore.repository.models.StoreExtension;
+import gearth.ui.translations.LanguageBundle;
import netscape.javascript.JSObject;
public class StoreExtensionItem implements ContentItem {
@@ -22,7 +27,7 @@ public class StoreExtensionItem implements ContentItem {
new StoreExtensionDetailsOverview(
gExtensionStore.getController().getCurrentOverview(),
0,
- GExtensionStore.MAX_PAGES,
+ GExtensionStore.PAGESIZE,
storeExtension,
gExtensionStore.getRepository()
)
@@ -53,12 +58,12 @@ public class StoreExtensionItem implements ContentItem {
.append("")
.append("
").append(WebUtils.escapeMessage(storeExtension.getTitle())).append("
")
- .append("
By ").append(storeExtension.getAuthors().get(0).getName()).append(", last updated ").append(WebUtils.elapsedSince(storeExtension.getUpdateDate())).append(" ago
")
+ .append("
").append(String.format(LanguageBundle.get("ext.store.extension.madeby"), storeExtension.getAuthors().get(0).getName())).append(", ").append(String.format(LanguageBundle.get("ext.store.extension.lastupdated"), WebUtils.elapsedSince(storeExtension.getUpdateDate()))).append("
")
.append("
")
.append("")
- .append("
").append("Version: ").append(displayVersion()).append("
")
- .append("
").append("Rating: ").append(storeExtension.getRating()).append("
")
+ .append("
").append(LanguageBundle.get("ext.store.extension.version")).append(": ").append(displayVersion()).append("
")
+ .append("
").append(LanguageBundle.get("ext.store.extension.rating")).append(": ").append(storeExtension.getRating()).append("
")
// .append("
").append(storeExtension.getFramework().getFramework().getName().replace("Native", "")).append("
")
.append("
")
diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/categories/CategoryItem.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/categories/CategoryItem.java
index 22af532..d7757ac 100644
--- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/categories/CategoryItem.java
+++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/categories/CategoryItem.java
@@ -8,6 +8,7 @@ import gearth.services.internal_extensions.extensionstore.application.entities.q
import gearth.services.internal_extensions.extensionstore.repository.StoreRepository;
import gearth.services.internal_extensions.extensionstore.repository.models.ExtCategory;
import gearth.services.internal_extensions.extensionstore.repository.querying.ExtensionOrdering;
+import gearth.ui.translations.LanguageBundle;
import netscape.javascript.JSObject;
import java.util.Collections;
@@ -57,7 +58,7 @@ public class CategoryItem implements ContentItem {
.append("")
.append("")
- .append("
").append(releasesCount).append(" releases").append("
")
+ .append("
").append(releasesCount).append(" ").append(LanguageBundle.get("ext.store.extension.author.releases")).append("
")
// .append("
").append(storeExtension.getFramework().getFramework().getName().replace("Native", "")).append("
")
.append("
")
diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/categories/CategoryOverview.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/categories/CategoryOverview.java
index c773b4f..4222c75 100644
--- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/categories/CategoryOverview.java
+++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/categories/CategoryOverview.java
@@ -1,10 +1,12 @@
package gearth.services.internal_extensions.extensionstore.application.entities.categories;
+import gearth.GEarth;
import gearth.services.internal_extensions.extensionstore.GExtensionStore;
import gearth.services.internal_extensions.extensionstore.application.entities.ContentItem;
import gearth.services.internal_extensions.extensionstore.application.entities.HOverview;
import gearth.services.internal_extensions.extensionstore.repository.StoreRepository;
import gearth.services.internal_extensions.extensionstore.repository.models.ExtCategory;
+import gearth.ui.translations.LanguageBundle;
import java.util.List;
import java.util.stream.Collectors;
@@ -57,17 +59,17 @@ public class CategoryOverview extends HOverview {
@Override
public String title() {
- return "Categories";
+ return LanguageBundle.get("ext.store.categories.title");
}
@Override
public String description() {
- return "Explore the different kinds of extensions G-Earth has to offer";
+ return LanguageBundle.get("ext.store.categories.description");
}
@Override
public String contentTitle() {
- return "Categories";
+ return LanguageBundle.get("ext.store.categories.contenttitle");
}
};
}
diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/extensiondetails/StoreExtensionDetailsItem.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/extensiondetails/StoreExtensionDetailsItem.java
index e4a335e..3668be0 100644
--- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/extensiondetails/StoreExtensionDetailsItem.java
+++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/extensiondetails/StoreExtensionDetailsItem.java
@@ -8,6 +8,7 @@ import gearth.services.internal_extensions.extensionstore.application.entities.H
import gearth.services.internal_extensions.extensionstore.repository.models.ExtCategory;
import gearth.services.internal_extensions.extensionstore.repository.models.StoreExtension;
import gearth.services.internal_extensions.extensionstore.tools.EncodingUtil;
+import gearth.ui.translations.LanguageBundle;
import netscape.javascript.JSObject;
import org.apache.commons.io.IOUtils;
import org.json.JSONObject;
@@ -45,32 +46,32 @@ public class StoreExtensionDetailsItem implements ContentItem {
contentBuilder
.append(String.format("*%s*", storeExtension.getTitle())).append(" - v").append(storeExtension.getVersion()).append("\n\n")
- .append("*Description*\n").append(descriptionQuoted).append("\n \n")
- .append("*Author(s):* ").append(storeExtension.getAuthors().stream().map(StoreExtension.Author::getName).collect(Collectors.joining(", "))).append("\n\n")
- .append("*Categories:* ").append(storeExtension.getCategories().stream().map(ExtCategory::getName).collect(Collectors.joining(", "))).append("\n\n");
+ .append("*").append(LanguageBundle.get("ext.store.extension.details.description")).append(":*\n").append(descriptionQuoted).append("\n \n")
+ .append("*").append(LanguageBundle.get("ext.store.extension.details.authors")).append(":* ").append(storeExtension.getAuthors().stream().map(StoreExtension.Author::getName).collect(Collectors.joining(", "))).append("\n\n")
+ .append("*").append(LanguageBundle.get("ext.store.extension.details.categories")).append(":* ").append(storeExtension.getCategories().stream().map(ExtCategory::getName).collect(Collectors.joining(", "))).append("\n\n");
- contentBuilder.append("*Technical information*").append("\n");
+ contentBuilder.append("*").append(LanguageBundle.get("ext.store.extension.details.technical_information")).append("*").append("\n");
if(storeExtension.getReleases() != null)
- contentBuilder.append("> Releases: --url:Click Here-").append(storeExtension.getReleases()).append("\n");
+ contentBuilder.append("> ").append(LanguageBundle.get("ext.store.extension.details.releases")).append(": --url:").append(LanguageBundle.get("ext.store.extension.details.click_here")).append("-").append(storeExtension.getReleases()).append("\n");
- contentBuilder.append("> Language: ").append(storeExtension.getLanguage()).append("\n")
- .append("> Source: --url:Click Here-").append(storeExtension.getSource()).append("\n")
- .append("> Framework: ").append(storeExtension.getFramework().getFramework().getName()).append(" - v").append(storeExtension.getFramework().getVersion()).append("\n")
- .append("> Systems: ").append(String.join(", ", storeExtension.getCompatibility().getSystems())).append("\n \n");
+ contentBuilder.append("> ").append(LanguageBundle.get("ext.store.extension.details.language")).append(": ").append(storeExtension.getLanguage()).append("\n")
+ .append("> ").append(LanguageBundle.get("ext.store.extension.details.source")).append(": --url:").append(LanguageBundle.get("ext.store.extension.details.click_here")).append("-").append(storeExtension.getSource()).append("\n")
+ .append("> ").append(LanguageBundle.get("ext.store.extension.details.framework")).append(": ").append(storeExtension.getFramework().getFramework().getName()).append(" - v").append(storeExtension.getFramework().getVersion()).append("\n")
+ .append("> ").append(LanguageBundle.get("ext.store.extension.details.systems")).append(": ").append(String.join(", ", storeExtension.getCompatibility().getSystems())).append("\n \n");
- contentBuilder.append("*Compatible clients:* ").append(String.join(", ", storeExtension.getCompatibility().getClients())).append("\n\n");
+ contentBuilder.append("*").append(LanguageBundle.get("ext.store.extension.details.clients")).append(":* ").append(String.join(", ", storeExtension.getCompatibility().getClients())).append("\n\n");
if (storeExtension.getFramework().getFramework().isInstallationRequired()) {
- contentBuilder.append("Warning: the framework requires --url:additional installations-")
+ contentBuilder.append(LanguageBundle.get("ext.store.extension.warning.requirement"))
.append(storeExtension.getFramework().getFramework().getInstallationInstructions()).append(" !\n\n");
}
if (!storeExtension.isStable()) {
- contentBuilder.append("Warning: this extension has been marked unstable!\n\n");
+ contentBuilder.append(LanguageBundle.get("ext.store.extension.warning.unstable")).append("\n\n");
}
contentBuilder.append("--startdiv--")
- .append("\n*Screenshot: *").append("\n")
+ .append("\n*").append(LanguageBundle.get("ext.store.extension.details.screenshot")).append(": *").append("\n")
.append("--img:").append(gExtensionStore.getRepository().getResourceUrl("store", "extensions", storeExtension.getTitle(), "screenshot.png"))
.append(" --enddiv--");
@@ -151,8 +152,8 @@ public class StoreExtensionDetailsItem implements ContentItem {
.append("")
.append("
")
.append("
").append(WebUtils.escapeMessage(mainAuthor.getName())).append("
")
- .append("
").append(mainAuthor.getReputation()).append(" reputation
")
- .append("
").append(mainAuthor.getExtensionsCount()).append(" releases
")
+ .append("
").append(mainAuthor.getReputation()).append(" ").append(LanguageBundle.get("ext.store.extension.author.reputation")).append("
")
+ .append("
").append(mainAuthor.getExtensionsCount()).append(" ").append(LanguageBundle.get("ext.store.extension.author.releases")).append("
")
.append("
") // todo look
.append("
")
.append("
").append(contentsInHtml()).append("
")
diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/extensiondetails/StoreExtensionDetailsOverview.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/extensiondetails/StoreExtensionDetailsOverview.java
index 7c06d56..7a98b65 100644
--- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/extensiondetails/StoreExtensionDetailsOverview.java
+++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/extensiondetails/StoreExtensionDetailsOverview.java
@@ -1,7 +1,6 @@
package gearth.services.internal_extensions.extensionstore.application.entities.extensiondetails;
-import gearth.services.extension_handler.extensions.implementations.network.NetworkExtensionsProducer;
-import gearth.services.extension_handler.extensions.implementations.network.executer.NormalExtensionRunner;
+import gearth.services.extension_handler.extensions.extensionproducers.ExtensionProducerFactory;
import gearth.services.internal_extensions.extensionstore.GExtensionStore;
import gearth.services.internal_extensions.extensionstore.application.GExtensionStoreController;
import gearth.services.internal_extensions.extensionstore.application.WebUtils;
@@ -12,15 +11,14 @@ import gearth.services.internal_extensions.extensionstore.repository.models.Stor
import gearth.services.internal_extensions.extensionstore.tools.InstalledExtension;
import gearth.services.internal_extensions.extensionstore.tools.StoreExtensionTools;
import gearth.ui.titlebar.TitleBarController;
+import gearth.ui.translations.LanguageBundle;
import javafx.application.Platform;
import javafx.scene.control.Alert;
-import javafx.scene.control.ButtonType;
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.w3c.dom.Element;
import java.io.IOException;
import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
import java.util.Optional;
@@ -62,7 +60,7 @@ public class StoreExtensionDetailsOverview extends HOverview {
public String buttonText() {
int mode = mode();
// return mode == 2 ? "Update" : "Install";
- return mode == 0 ? "Install" : (mode == 1 ? "Installed" : "Update");
+ return LanguageBundle.get("ext.store.button." + (mode == 0 ? "install" : (mode == 1 ? "installed" : "update")));
}
@Override
@@ -91,23 +89,23 @@ public class StoreExtensionDetailsOverview extends HOverview {
private void awaitPopup(String mode) {
popup(Alert.AlertType.WARNING,
- String.format("%s extension", mode),
- String.format("%s extension [%s]", mode, extension.getTitle()),
- String.format("Press \"OK\" and wait while the extension is being %sed", mode.toLowerCase()));
+ LanguageBundle.get(String.format("ext.store.extension.status.await.%s", mode)),
+ String.format("%s [%s]", LanguageBundle.get(String.format("ext.store.extension.status.await.%s", mode)), extension.getTitle()),
+ LanguageBundle.get(String.format("ext.store.extension.status.await.%s.message", mode)));
}
private void successPopup(String mode) {
popup(Alert.AlertType.INFORMATION,
- String.format("%s completed", mode),
- String.format("%s completed [%s]", mode, extension.getTitle()),
- String.format("Extension %s completed successfully", mode.toLowerCase()));
+ LanguageBundle.get(String.format("ext.store.extension.status.success.%s", mode)),
+ String.format("%s [%s]", LanguageBundle.get(String.format("ext.store.extension.status.success.%s", mode)), extension.getTitle()),
+ LanguageBundle.get(String.format("ext.store.extension.status.success.%s.message", mode)));
}
private void errorPopup(String mode, String error) {
popup(Alert.AlertType.ERROR,
- String.format("%s failed", mode),
- String.format("%s failed [%s]", mode, extension.getTitle()),
- String.format("%s failed with the following message: %s", mode, error));
+ LanguageBundle.get(String.format("ext.store.extension.status.success.%s", mode)),
+ String.format("%s [%s]", LanguageBundle.get(String.format("ext.store.extension.status.success.%s", mode)), extension.getTitle()),
+ String.format("%s: %s", LanguageBundle.get(String.format("ext.store.extension.status.success.%s.message", mode)), error));
}
private void popup(Alert.AlertType alertType, String title, String header, String context) {
@@ -128,14 +126,14 @@ public class StoreExtensionDetailsOverview extends HOverview {
int mode = mode();
if (mode == 1) return;
- String modeString = mode() == 0 ? "Install" : "Update";
+ String modeString = mode() == 0 ? "install" : "update";
HOverview selff = this;
StoreExtensionTools.InstallExtListener listener = new StoreExtensionTools.InstallExtListener() {
@Override
public void success(String installationFolder) {
Platform.runLater(() -> successPopup(modeString));
- StoreExtensionTools.executeExtension(installationFolder, NetworkExtensionsProducer.extensionPort);
+ StoreExtensionTools.executeExtension(installationFolder, ExtensionProducerFactory.getExtensionServer().getPort());
}
@Override
diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/installed/InstalledOverview.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/installed/InstalledOverview.java
index b64d1c2..4d0b10e 100644
--- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/installed/InstalledOverview.java
+++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/installed/InstalledOverview.java
@@ -7,6 +7,7 @@ import gearth.services.internal_extensions.extensionstore.repository.StoreReposi
import gearth.services.internal_extensions.extensionstore.repository.models.StoreExtension;
import gearth.services.internal_extensions.extensionstore.tools.InstalledExtension;
import gearth.services.internal_extensions.extensionstore.tools.StoreExtensionTools;
+import gearth.ui.translations.LanguageBundle;
import org.apache.maven.artifact.versioning.ComparableVersion;
import java.awt.*;
@@ -30,7 +31,7 @@ public class InstalledOverview extends HOverview {
@Override
public String buttonText() {
- return "Open folder";
+ return LanguageBundle.get("ext.store.overview.folder");
}
@Override
@@ -75,17 +76,17 @@ public class InstalledOverview extends HOverview {
@Override
public String title() {
- return "Installed Extensions";
+ return LanguageBundle.get("ext.store.overview.title");
}
@Override
public String description() {
- return "Extensions that are already installed into G-Earth";
+ return LanguageBundle.get("ext.store.overview.description");
}
@Override
public String contentTitle() {
- return "Installed extensions";
+ return LanguageBundle.get("ext.store.overview.contenttitle");
}
};
}
diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/installed/StoreExtensionInstalledItem.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/installed/StoreExtensionInstalledItem.java
index f5d6cda..84cb3ff 100644
--- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/installed/StoreExtensionInstalledItem.java
+++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/installed/StoreExtensionInstalledItem.java
@@ -6,6 +6,7 @@ import gearth.services.internal_extensions.extensionstore.application.WebUtils;
import gearth.services.internal_extensions.extensionstore.application.entities.StoreExtensionItem;
import gearth.services.internal_extensions.extensionstore.repository.models.StoreExtension;
import gearth.services.internal_extensions.extensionstore.tools.InstalledExtension;
+import gearth.ui.translations.LanguageBundle;
import org.apache.maven.artifact.versioning.ComparableVersion;
public class StoreExtensionInstalledItem extends StoreExtensionItem {
@@ -55,11 +56,11 @@ public class StoreExtensionInstalledItem extends StoreExtensionItem {
.append("
")
.append("
").append(WebUtils.escapeMessage(installedExtension.getName())).append("
")
- .append("
Not found in G-ExtensionStore
")
+ .append("
").append(LanguageBundle.get("ext.store.extension.notinstore")).append("
")
.append("
")
.append("
")
- .append("
").append("Version: ").append(displayVersion()).append("
")
+ .append("
").append(LanguageBundle.get("ext.store.extension.version")).append(": ").append(displayVersion()).append("
")
.append("
")
.append("
")
diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/ByDateOverview.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/ByDateOverview.java
index 1ea07db..acd0906 100644
--- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/ByDateOverview.java
+++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/ByDateOverview.java
@@ -1,11 +1,11 @@
package gearth.services.internal_extensions.extensionstore.application.entities.queriedoverviews;
import gearth.misc.OSValidator;
-import gearth.services.internal_extensions.extensionstore.application.GExtensionStoreController;
import gearth.services.internal_extensions.extensionstore.application.entities.HOverview;
import gearth.services.internal_extensions.extensionstore.repository.StoreRepository;
import gearth.services.internal_extensions.extensionstore.repository.models.StoreExtension;
import gearth.services.internal_extensions.extensionstore.repository.querying.ExtensionOrdering;
+import gearth.ui.translations.LanguageBundle;
import java.util.Collections;
import java.util.List;
@@ -32,17 +32,17 @@ public class ByDateOverview extends QueriedExtensionOverview {
@Override
public String title() {
- return "New Releases";
+ return LanguageBundle.get("ext.store.search.ordering.bydate.title");
}
@Override
public String description() {
- return "Extensions that were recently added to the G-ExtensionStore";
+ return LanguageBundle.get("ext.store.search.ordering.bydate.description");
}
@Override
public String contentTitle() {
- return "New Releases";
+ return LanguageBundle.get("ext.store.search.ordering.bydate.contenttitle");
}
};
}
diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/ByRatingOverview.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/ByRatingOverview.java
index bd080b9..de8d8d9 100644
--- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/ByRatingOverview.java
+++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/ByRatingOverview.java
@@ -1,11 +1,11 @@
package gearth.services.internal_extensions.extensionstore.application.entities.queriedoverviews;
import gearth.misc.OSValidator;
-import gearth.services.internal_extensions.extensionstore.application.GExtensionStoreController;
import gearth.services.internal_extensions.extensionstore.application.entities.HOverview;
import gearth.services.internal_extensions.extensionstore.repository.StoreRepository;
import gearth.services.internal_extensions.extensionstore.repository.models.StoreExtension;
import gearth.services.internal_extensions.extensionstore.repository.querying.ExtensionOrdering;
+import gearth.ui.translations.LanguageBundle;
import java.util.Collections;
import java.util.List;
@@ -32,17 +32,17 @@ public class ByRatingOverview extends QueriedExtensionOverview {
@Override
public String title() {
- return "Popular Extensions";
+ return LanguageBundle.get("ext.store.search.ordering.byrating.title");
}
@Override
public String description() {
- return "Extensions sorted by rating";
+ return LanguageBundle.get("ext.store.search.ordering.byrating.description");
}
@Override
public String contentTitle() {
- return "Popular Extensions";
+ return LanguageBundle.get("ext.store.search.ordering.byrating.contenttitle");
}
};
}
diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/ByUpdateOverview.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/ByUpdateOverview.java
index 36137ba..cb87d34 100644
--- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/ByUpdateOverview.java
+++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/ByUpdateOverview.java
@@ -5,6 +5,7 @@ import gearth.services.internal_extensions.extensionstore.application.entities.H
import gearth.services.internal_extensions.extensionstore.repository.StoreRepository;
import gearth.services.internal_extensions.extensionstore.repository.models.StoreExtension;
import gearth.services.internal_extensions.extensionstore.repository.querying.ExtensionOrdering;
+import gearth.ui.translations.LanguageBundle;
import java.util.Collections;
import java.util.List;
@@ -31,17 +32,17 @@ public class ByUpdateOverview extends QueriedExtensionOverview {
@Override
public String title() {
- return "Recently Updated";
+ return LanguageBundle.get("ext.store.search.ordering.byupdate.title");
}
@Override
public String description() {
- return "Extensions that were recently updated";
+ return LanguageBundle.get("ext.store.search.ordering.byupdate.description");
}
@Override
public String contentTitle() {
- return "Recently Updated";
+ return LanguageBundle.get("ext.store.search.ordering.byupdate.contenttitle");
}
};
}
diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/CategorizedOverview.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/CategorizedOverview.java
index e530256..3829d6c 100644
--- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/CategorizedOverview.java
+++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/CategorizedOverview.java
@@ -1,12 +1,12 @@
package gearth.services.internal_extensions.extensionstore.application.entities.queriedoverviews;
import gearth.misc.OSValidator;
-import gearth.services.internal_extensions.extensionstore.application.WebUtils;
import gearth.services.internal_extensions.extensionstore.application.entities.HOverview;
import gearth.services.internal_extensions.extensionstore.repository.StoreRepository;
import gearth.services.internal_extensions.extensionstore.repository.models.ExtCategory;
import gearth.services.internal_extensions.extensionstore.repository.models.StoreExtension;
import gearth.services.internal_extensions.extensionstore.repository.querying.ExtensionOrdering;
+import gearth.ui.translations.LanguageBundle;
import java.util.Collections;
import java.util.List;
@@ -47,7 +47,7 @@ public class CategorizedOverview extends QueriedExtensionOverview {
@Override
public String contentTitle() {
- return "Category: " + category.getName();
+ return LanguageBundle.get("ext.store.category") + ": " + category.getName();
}
};
}
diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/SearchedQueryOverview.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/SearchedQueryOverview.java
index 0709ced..cf951a9 100644
--- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/SearchedQueryOverview.java
+++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/SearchedQueryOverview.java
@@ -5,6 +5,7 @@ import gearth.services.internal_extensions.extensionstore.application.entities.H
import gearth.services.internal_extensions.extensionstore.repository.StoreRepository;
import gearth.services.internal_extensions.extensionstore.repository.models.StoreExtension;
import gearth.services.internal_extensions.extensionstore.repository.querying.ExtensionOrdering;
+import gearth.ui.translations.LanguageBundle;
import java.util.Collections;
import java.util.List;
@@ -48,17 +49,17 @@ public class SearchedQueryOverview extends QueriedExtensionOverview {
@Override
public String title() {
- return "Search";
+ return LanguageBundle.get("ext.store.search.title");
}
@Override
public String description() {
- return "Find the extension that fits your needs";
+ return LanguageBundle.get("ext.store.search.description");
}
@Override
public String contentTitle() {
- return "Search results";
+ return LanguageBundle.get("ext.store.search.results");
}
};
}
diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/search/SearchComponent.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/search/SearchComponent.java
index b53b3f1..a8f462f 100644
--- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/search/SearchComponent.java
+++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/search/SearchComponent.java
@@ -1,10 +1,12 @@
package gearth.services.internal_extensions.extensionstore.application.entities.search;
+import gearth.GEarth;
import gearth.services.internal_extensions.extensionstore.GExtensionStore;
import gearth.services.internal_extensions.extensionstore.application.GExtensionStoreController;
import gearth.services.internal_extensions.extensionstore.application.entities.ContentItem;
import gearth.services.internal_extensions.extensionstore.repository.StoreRepository;
import gearth.services.internal_extensions.extensionstore.repository.querying.ExtensionOrdering;
+import gearth.ui.translations.LanguageBundle;
import netscape.javascript.JSObject;
import java.util.ArrayList;
@@ -92,13 +94,13 @@ public class SearchComponent implements ContentItem {
.append("
")
.append("
")
- .append("")
+ .append("")
.append(String.format("", searchKeyword, id))
.append("
")
.append("
")
- .append("");
+ .append("");
// add ordering stuff
htmlBuilder.append(String.format("
")
- .append("
Info: you are automatically filtering on the OS you use
")
+ .append("
").append(LanguageBundle.get("ext.store.search.info.automaticosfiltering")).append("
")
.append("
")
.append("
");
diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/search/SearchOverview.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/search/SearchOverview.java
index ba5375c..a1219fc 100644
--- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/search/SearchOverview.java
+++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/search/SearchOverview.java
@@ -5,6 +5,7 @@ import gearth.services.internal_extensions.extensionstore.application.entities.C
import gearth.services.internal_extensions.extensionstore.application.entities.HOverview;
import gearth.services.internal_extensions.extensionstore.application.entities.queriedoverviews.SearchedQueryOverview;
import gearth.services.internal_extensions.extensionstore.repository.StoreRepository;
+import gearth.ui.translations.LanguageBundle;
import java.util.Collections;
import java.util.List;
@@ -26,7 +27,7 @@ public class SearchOverview extends HOverview {
@Override
public String buttonText() {
- return "Search";
+ return LanguageBundle.get("ext.store.button.search");
}
@Override
@@ -73,17 +74,17 @@ public class SearchOverview extends HOverview {
@Override
public String title() {
- return "Search";
+ return LanguageBundle.get("ext.store.search.title");
}
@Override
public String description() {
- return "Find the extension that fits your needs";
+ return LanguageBundle.get("ext.store.search.description");
}
@Override
public String contentTitle() {
- return "Search extensions";
+ return LanguageBundle.get("ext.store.search.contenttitle");
}
};
}
diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/querying/ExtensionOrdering.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/querying/ExtensionOrdering.java
index bf1f564..d7a200e 100644
--- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/querying/ExtensionOrdering.java
+++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/querying/ExtensionOrdering.java
@@ -1,27 +1,29 @@
package gearth.services.internal_extensions.extensionstore.repository.querying;
+import gearth.ui.translations.LanguageBundle;
+
public enum ExtensionOrdering {
- RATING("Rating"),
- ALPHABETICAL("Alphabetical"),
- LAST_UPDATED("Last updated"),
- NEW_RELEASES("New releases");
+ RATING("ext.store.ordering.rating"),
+ ALPHABETICAL("ext.store.ordering.alphabetical"),
+ LAST_UPDATED("ext.store.ordering.lastupdated"),
+ NEW_RELEASES("ext.store.ordering.newreleases");
- private String orderName;
+ private String orderKey;
- ExtensionOrdering(String orderName) {
- this.orderName = orderName;
+ ExtensionOrdering(String orderKey) {
+ this.orderKey = orderKey;
}
public String getOrderName() {
- return orderName;
+ return LanguageBundle.get(orderKey);
}
public static ExtensionOrdering fromString(String text) {
for (ExtensionOrdering b : ExtensionOrdering.values()) {
- if (b.orderName.equalsIgnoreCase(text)) {
+ if (LanguageBundle.get(b.orderKey).equalsIgnoreCase(text)) {
return b;
}
}
diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/tools/StoreExtensionTools.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/tools/StoreExtensionTools.java
index eb70240..9a8f1e6 100644
--- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/tools/StoreExtensionTools.java
+++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/tools/StoreExtensionTools.java
@@ -2,12 +2,13 @@ package gearth.services.internal_extensions.extensionstore.tools;
import gearth.GEarth;
import gearth.misc.OSValidator;
-import gearth.services.extension_handler.extensions.implementations.network.authentication.Authenticator;
+import gearth.services.extension_handler.extensions.implementations.network.NetworkExtensionAuthenticator;
import gearth.services.extension_handler.extensions.implementations.network.executer.ExecutionInfo;
import gearth.services.extension_handler.extensions.implementations.network.executer.NormalExtensionRunner;
import gearth.services.internal_extensions.extensionstore.repository.StoreFetch;
import gearth.services.internal_extensions.extensionstore.repository.StoreRepository;
import gearth.services.internal_extensions.extensionstore.repository.models.StoreExtension;
+import gearth.ui.translations.LanguageBundle;
import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.json.JSONArray;
@@ -33,7 +34,7 @@ public class StoreExtensionTools {
}
- public final static String EXTENSIONS_PATH = Paths.get(NormalExtensionRunner.JARPATH, ExecutionInfo.EXTENSIONSDIRECTORY).toString();
+ public final static String EXTENSIONS_PATH = Paths.get(NormalExtensionRunner.JAR_PATH, ExecutionInfo.EXTENSIONS_DIRECTORY).toString();
public static void executeExtension(String extensionPath, int port) {
@@ -41,7 +42,7 @@ public class StoreExtensionTools {
String installedExtensionId = Paths.get(extensionPath).getFileName().toString();
String commandPath = Paths.get(extensionPath, "command.txt").toString();
- String cookie = Authenticator.generateCookieForExtension(installedExtensionId);
+ String cookie = NetworkExtensionAuthenticator.generateCookieForExtension(installedExtensionId);
List command = new JSONArray(FileUtils.readFileToString(new File(commandPath), "UTF-8"))
.toList().stream().map(o -> (String)o).map(s -> s
.replace("{port}", port+"")
@@ -137,29 +138,29 @@ public class StoreExtensionTools {
} catch (IOException e) {
e.printStackTrace();
- listener.fail("Error while unzipping");
+ listener.fail(LanguageBundle.get("ext.store.fail.unzip"));
removeExtension(path);
}
} catch (MalformedURLException e) {
- listener.fail("Invalid extension URL");
+ listener.fail(LanguageBundle.get("ext.store.fail.invalidurl"));
try {
removeExtension(path); // cleanup
} catch (IOException ignore) { }
} catch (IOException e) {
- listener.fail("Extension not available in repository");
+ listener.fail(LanguageBundle.get("ext.store.fail.notavailable"));
try {
removeExtension(path); // cleanup
} catch (IOException ignore) { }
}
}
else {
- listener.fail("Something went wrong creating the extension directory, does the extension already exist?");
+ listener.fail(LanguageBundle.get("ext.store.fail.alreadyexists"));
// don't do cleanup since you might not want removal of current extension files
}
}
else {
- listener.fail("Extension wasn't found");
+ listener.fail(LanguageBundle.get("ext.store.fail.notfound"));
}
}).start();
@@ -233,8 +234,7 @@ public class StoreExtensionTools {
}
}
} catch (Exception e) {
- listener.fail("Something went wrong with uninstalling the extension, make sure to disconnect" +
- " the extension if it was still running.");
+ listener.fail(LanguageBundle.get("ext.store.fail.uninstall"));
return;
}
diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/uilogger/UiLoggerController.java b/G-Earth/src/main/java/gearth/services/internal_extensions/uilogger/UiLoggerController.java
index 26b6af0..bb1f5d7 100644
--- a/G-Earth/src/main/java/gearth/services/internal_extensions/uilogger/UiLoggerController.java
+++ b/G-Earth/src/main/java/gearth/services/internal_extensions/uilogger/UiLoggerController.java
@@ -7,7 +7,9 @@ package gearth.services.internal_extensions.uilogger;
import gearth.protocol.HMessage;
import gearth.protocol.HPacket;
import gearth.ui.subforms.logger.loggerdisplays.PacketLogger;
-import javafx.application.Platform;
+ import gearth.ui.translations.LanguageBundle;
+ import gearth.ui.translations.TranslatableString;
+ import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
@@ -39,7 +41,7 @@ public class UiLoggerController implements Initializable {
public CheckMenuItem chkViewIncoming;
public CheckMenuItem chkViewOutgoing;
public CheckMenuItem chkDisplayStructure;
- public Label lblAutoScrolll;
+ public Label lblAutoScroll;
public CheckMenuItem chkAutoscroll;
public CheckMenuItem chkSkipBigPackets;
public CheckMenuItem chkMessageName;
@@ -71,6 +73,7 @@ public class UiLoggerController implements Initializable {
public RadioMenuItem chkReprHex;
public RadioMenuItem chkReprRawHex;
public RadioMenuItem chkReprNone;
+ public MenuItem menuItem_clear, menuItem_exportAll;
private Map> filterTimestamps = new HashMap<>();
@@ -86,6 +89,11 @@ public class UiLoggerController implements Initializable {
private List