fix bug in extensions

This commit is contained in:
sirjonasxx 2018-11-07 16:45:28 +01:00
parent 0604b45572
commit 32ecc855f0
2 changed files with 22 additions and 12 deletions

View File

@ -16,16 +16,16 @@ public class ExecutionInfo {
static { static {
extensionTypeToExecutionCommand = new HashMap<>(); extensionTypeToExecutionCommand = new HashMap<>();
extensionTypeToExecutionCommand.put("*.jar","java -jar {path}"); extensionTypeToExecutionCommand.put("*.jar","java -jar \"{path}\"");
extensionTypeToExecutionCommand.put("*.py","python {path}"); extensionTypeToExecutionCommand.put("*.py","python \"{path}\"");
extensionTypeToExecutionCommand.put("*.py3","python3 {path}"); extensionTypeToExecutionCommand.put("*.py3","python3 \"{path}\"");
extensionTypeToExecutionCommand.put("*.sh","{path}"); extensionTypeToExecutionCommand.put("*.sh","\"{path}\"");
extensionTypeToExecutionCommand.put("*.exe","{path}"); extensionTypeToExecutionCommand.put("*.exe","\"{path}\"");
for(String type : extensionTypeToExecutionCommand.keySet()) { for(String type : extensionTypeToExecutionCommand.keySet()) {
extensionTypeToExecutionCommand.put( extensionTypeToExecutionCommand.put(
type, type,
extensionTypeToExecutionCommand.get(type) + " -p {port} -f {filename} -c {cookie}" extensionTypeToExecutionCommand.get(type) + " -p {port} -f \"{filename}\" -c {cookie}"
); );
} }

View File

@ -5,6 +5,7 @@ import gearth.ui.extensions.authentication.Authenticator;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.*; import java.nio.file.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.Random; import java.util.Random;
@ -14,7 +15,18 @@ import java.util.Random;
*/ */
public class NormalExtensionRunner implements ExtensionRunner { 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 @Override
public void runAllExtensions(int port) { 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 realname = String.join(".",Arrays.copyOf(split, split.length-1));
String newname = realname + "-" + getRandomString() + ext.substring(1); String newname = realname + "-" + getRandomString() + ext.substring(1);
Path originalPath = Paths.get(path); Path originalPath = Paths.get(path);
Path newPath = Paths.get( Path newPath = Paths.get(
JARPATH, JARPATH,
@ -72,13 +83,12 @@ public class NormalExtensionRunner implements ExtensionRunner {
public void tryRunExtension(String path, int port) { public void tryRunExtension(String path, int port) {
try { try {
String filename = Paths.get(path).getFileName().toString(); String filename = Paths.get(path).getFileName().toString();
Runtime.getRuntime().exec( String execCommand = ExecutionInfo.getExecutionCommand(getFileExtension(path))
ExecutionInfo.getExecutionCommand(getFileExtension(path))
.replace("{path}", path) .replace("{path}", path)
.replace("{port}", port+"") .replace("{port}", port+"")
.replace("{filename}", filename) .replace("{filename}", filename)
.replace("{cookie}", Authenticator.generateCookieForExtension(filename)) .replace("{cookie}", Authenticator.generateCookieForExtension(filename));
); Runtime.getRuntime().exec(execCommand);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }