From 32ecc855f0c8fffcf386fda788f1c61250e2e3b2 Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Wed, 7 Nov 2018 16:45:28 +0100 Subject: [PATCH] fix bug in extensions --- .../ui/extensions/executer/ExecutionInfo.java | 12 +++++----- .../executer/NormalExtensionRunner.java | 22 ++++++++++++++----- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/G-Earth/src/main/java/gearth/ui/extensions/executer/ExecutionInfo.java b/G-Earth/src/main/java/gearth/ui/extensions/executer/ExecutionInfo.java index 43db6b1..428a82a 100644 --- a/G-Earth/src/main/java/gearth/ui/extensions/executer/ExecutionInfo.java +++ b/G-Earth/src/main/java/gearth/ui/extensions/executer/ExecutionInfo.java @@ -16,16 +16,16 @@ public class ExecutionInfo { static { extensionTypeToExecutionCommand = new HashMap<>(); - extensionTypeToExecutionCommand.put("*.jar","java -jar {path}"); - extensionTypeToExecutionCommand.put("*.py","python {path}"); - extensionTypeToExecutionCommand.put("*.py3","python3 {path}"); - extensionTypeToExecutionCommand.put("*.sh","{path}"); - extensionTypeToExecutionCommand.put("*.exe","{path}"); + 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} -c {cookie}" + extensionTypeToExecutionCommand.get(type) + " -p {port} -f \"{filename}\" -c {cookie}" ); } diff --git a/G-Earth/src/main/java/gearth/ui/extensions/executer/NormalExtensionRunner.java b/G-Earth/src/main/java/gearth/ui/extensions/executer/NormalExtensionRunner.java index 918991f..a1a49b1 100644 --- a/G-Earth/src/main/java/gearth/ui/extensions/executer/NormalExtensionRunner.java +++ b/G-Earth/src/main/java/gearth/ui/extensions/executer/NormalExtensionRunner.java @@ -5,6 +5,7 @@ import gearth.ui.extensions.authentication.Authenticator; import java.io.File; import java.io.IOException; +import java.net.URISyntaxException; import java.nio.file.*; import java.util.Arrays; import java.util.Random; @@ -14,7 +15,18 @@ import java.util.Random; */ public class NormalExtensionRunner implements ExtensionRunner { - public static final String JARPATH = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParent(); + public static final String JARPATH; + + static { + String value; + try { + value = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParent(); + } catch (URISyntaxException e) { + value = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParent(); + e.printStackTrace(); + } + JARPATH = value; + } @Override public void runAllExtensions(int port) { @@ -45,7 +57,6 @@ public class NormalExtensionRunner implements ExtensionRunner { String realname = String.join(".",Arrays.copyOf(split, split.length-1)); String newname = realname + "-" + getRandomString() + ext.substring(1); - Path originalPath = Paths.get(path); Path newPath = Paths.get( JARPATH, @@ -72,13 +83,12 @@ public class NormalExtensionRunner implements ExtensionRunner { public void tryRunExtension(String path, int port) { try { String filename = Paths.get(path).getFileName().toString(); - Runtime.getRuntime().exec( - ExecutionInfo.getExecutionCommand(getFileExtension(path)) + String execCommand = ExecutionInfo.getExecutionCommand(getFileExtension(path)) .replace("{path}", path) .replace("{port}", port+"") .replace("{filename}", filename) - .replace("{cookie}", Authenticator.generateCookieForExtension(filename)) - ); + .replace("{cookie}", Authenticator.generateCookieForExtension(filename)); + Runtime.getRuntime().exec(execCommand); } catch (IOException e) { e.printStackTrace(); }