mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-27 02:40:51 +01:00
potential fix executing extensions X-platform
This commit is contained in:
parent
e8f97e5a9f
commit
64af70e44a
@ -10,29 +10,35 @@ import java.util.Map;
|
||||
*/
|
||||
public class ExecutionInfo {
|
||||
|
||||
private static Map<String, String> extensionTypeToExecutionCommand;
|
||||
private static Map<String, String[]> extensionTypeToExecutionCommand;
|
||||
public final static List<String> ALLOWEDEXTENSIONTYPES;
|
||||
public final static String EXTENSIONSDIRECTORY = "Extensions";
|
||||
|
||||
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", 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}"});
|
||||
|
||||
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];
|
||||
System.arraycopy(commandShort, 0, combined, 0, commandShort.length);
|
||||
System.arraycopy(extraArgs, 0, combined, commandShort.length, extraArgs.length);
|
||||
|
||||
extensionTypeToExecutionCommand.put(
|
||||
type,
|
||||
extensionTypeToExecutionCommand.get(type) + " -p {port} -f \"{filename}\" -c {cookie}"
|
||||
combined
|
||||
);
|
||||
}
|
||||
|
||||
ALLOWEDEXTENSIONTYPES = new ArrayList<>(extensionTypeToExecutionCommand.keySet());
|
||||
}
|
||||
|
||||
public static String getExecutionCommand(String type) {
|
||||
public static String[] getExecutionCommand(String type) {
|
||||
return extensionTypeToExecutionCommand.get(type);
|
||||
}
|
||||
|
||||
|
@ -86,15 +86,19 @@ public class NormalExtensionRunner implements ExtensionRunner {
|
||||
public void tryRunExtension(String path, int port) {
|
||||
try {
|
||||
String filename = Paths.get(path).getFileName().toString();
|
||||
String execCommand = ExecutionInfo.getExecutionCommand(getFileExtension(path))
|
||||
String[] execCommand = ExecutionInfo.getExecutionCommand(getFileExtension(path));
|
||||
execCommand = Arrays.copyOf(execCommand, execCommand.length);
|
||||
String cookie = Authenticator.generateCookieForExtension(filename);
|
||||
for (int i = 0; i < execCommand.length; i++) {
|
||||
execCommand[i] = execCommand[i]
|
||||
.replace("{path}", path)
|
||||
.replace("{port}", port+"")
|
||||
.replace("{filename}", filename)
|
||||
.replace("{cookie}", Authenticator.generateCookieForExtension(filename));
|
||||
Process proc = Runtime.getRuntime().exec(execCommand);
|
||||
|
||||
|
||||
|
||||
.replace("{cookie}", cookie);
|
||||
}
|
||||
ProcessBuilder pb = new ProcessBuilder(execCommand);
|
||||
// Process proc = Runtime.getRuntime().exec(execCommand);
|
||||
Process proc = pb.start();
|
||||
|
||||
if (Main.hasFlag(ExtensionRunner.SHOW_EXTENSIONS_LOG)) {
|
||||
String sep = "" + System.lineSeparator();
|
||||
|
Loading…
Reference in New Issue
Block a user