* Fix #2870: 导出脚本时预解析 PreLaunchCommand 与 PostExitCommand * fix checkstyle
This commit is contained in:
@@ -560,6 +560,7 @@ public class DefaultLauncher extends Launcher {
|
||||
|
||||
final Command commandLine = generateCommandLine(nativeFolder);
|
||||
final String command = usePowerShell ? null : commandLine.commandLine.toString();
|
||||
Map<String, String> envVars = getEnvVars();
|
||||
|
||||
if (!usePowerShell && isWindows) {
|
||||
if (command.length() > 8192) { // maximum length of the command in cmd
|
||||
@@ -596,7 +597,7 @@ public class DefaultLauncher extends Launcher {
|
||||
writer.write(CommandBuilder.pwshString(options.getGameDir().getAbsoluteFile().getParent()));
|
||||
writer.newLine();
|
||||
}
|
||||
for (Map.Entry<String, String> entry : getEnvVars().entrySet()) {
|
||||
for (Map.Entry<String, String> entry : envVars.entrySet()) {
|
||||
writer.write("$Env:" + entry.getKey() + "=");
|
||||
writer.write(CommandBuilder.pwshString(entry.getValue()));
|
||||
writer.newLine();
|
||||
@@ -605,19 +606,38 @@ public class DefaultLauncher extends Launcher {
|
||||
writer.write(CommandBuilder.pwshString(repository.getRunDirectory(version.getId()).getAbsolutePath()));
|
||||
writer.newLine();
|
||||
|
||||
|
||||
if (StringUtils.isNotBlank(options.getPreLaunchCommand())) {
|
||||
writer.write('&');
|
||||
for (String rawCommand : StringUtils.tokenize(options.getPreLaunchCommand(), envVars)) {
|
||||
writer.write(' ');
|
||||
writer.write(CommandBuilder.pwshString(rawCommand));
|
||||
}
|
||||
writer.newLine();
|
||||
}
|
||||
|
||||
writer.write('&');
|
||||
for (String rawCommand : commandLine.commandLine.asList()) {
|
||||
writer.write(' ');
|
||||
writer.write(CommandBuilder.pwshString(rawCommand));
|
||||
}
|
||||
writer.newLine();
|
||||
|
||||
if (StringUtils.isNotBlank(options.getPostExitCommand())) {
|
||||
writer.write('&');
|
||||
for (String rawCommand : StringUtils.tokenize(options.getPostExitCommand(), envVars)) {
|
||||
writer.write(' ');
|
||||
writer.write(CommandBuilder.pwshString(rawCommand));
|
||||
}
|
||||
writer.newLine();
|
||||
}
|
||||
} else {
|
||||
if (isWindows) {
|
||||
writer.write("@echo off");
|
||||
writer.newLine();
|
||||
writer.write("set APPDATA=" + options.getGameDir().getAbsoluteFile().getParent());
|
||||
writer.newLine();
|
||||
for (Map.Entry<String, String> entry : getEnvVars().entrySet()) {
|
||||
for (Map.Entry<String, String> entry : envVars.entrySet()) {
|
||||
writer.write("set " + entry.getKey() + "=" + CommandBuilder.toBatchStringLiteral(entry.getValue()));
|
||||
writer.newLine();
|
||||
}
|
||||
@@ -626,7 +646,7 @@ public class DefaultLauncher extends Launcher {
|
||||
} else {
|
||||
writer.write("#!/usr/bin/env bash");
|
||||
writer.newLine();
|
||||
for (Map.Entry<String, String> entry : getEnvVars().entrySet()) {
|
||||
for (Map.Entry<String, String> entry : envVars.entrySet()) {
|
||||
writer.write("export " + entry.getKey() + "=" + CommandBuilder.toShellStringLiteral(entry.getValue()));
|
||||
writer.newLine();
|
||||
}
|
||||
@@ -638,13 +658,14 @@ public class DefaultLauncher extends Launcher {
|
||||
}
|
||||
writer.newLine();
|
||||
if (StringUtils.isNotBlank(options.getPreLaunchCommand())) {
|
||||
writer.write(options.getPreLaunchCommand());
|
||||
writer.write(new CommandBuilder().addAll(StringUtils.tokenize(options.getPreLaunchCommand(), envVars)).toString());
|
||||
writer.newLine();
|
||||
}
|
||||
writer.write(command);
|
||||
writer.newLine();
|
||||
|
||||
if (StringUtils.isNotBlank(options.getPostExitCommand())) {
|
||||
writer.write(options.getPostExitCommand());
|
||||
writer.write(new CommandBuilder().addAll(StringUtils.tokenize(options.getPostExitCommand(), envVars)).toString());
|
||||
writer.newLine();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user