* 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 Command commandLine = generateCommandLine(nativeFolder);
|
||||||
final String command = usePowerShell ? null : commandLine.commandLine.toString();
|
final String command = usePowerShell ? null : commandLine.commandLine.toString();
|
||||||
|
Map<String, String> envVars = getEnvVars();
|
||||||
|
|
||||||
if (!usePowerShell && isWindows) {
|
if (!usePowerShell && isWindows) {
|
||||||
if (command.length() > 8192) { // maximum length of the command in cmd
|
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.write(CommandBuilder.pwshString(options.getGameDir().getAbsoluteFile().getParent()));
|
||||||
writer.newLine();
|
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("$Env:" + entry.getKey() + "=");
|
||||||
writer.write(CommandBuilder.pwshString(entry.getValue()));
|
writer.write(CommandBuilder.pwshString(entry.getValue()));
|
||||||
writer.newLine();
|
writer.newLine();
|
||||||
@@ -605,19 +606,38 @@ public class DefaultLauncher extends Launcher {
|
|||||||
writer.write(CommandBuilder.pwshString(repository.getRunDirectory(version.getId()).getAbsolutePath()));
|
writer.write(CommandBuilder.pwshString(repository.getRunDirectory(version.getId()).getAbsolutePath()));
|
||||||
writer.newLine();
|
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('&');
|
writer.write('&');
|
||||||
for (String rawCommand : commandLine.commandLine.asList()) {
|
for (String rawCommand : commandLine.commandLine.asList()) {
|
||||||
writer.write(' ');
|
writer.write(' ');
|
||||||
writer.write(CommandBuilder.pwshString(rawCommand));
|
writer.write(CommandBuilder.pwshString(rawCommand));
|
||||||
}
|
}
|
||||||
writer.newLine();
|
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 {
|
} else {
|
||||||
if (isWindows) {
|
if (isWindows) {
|
||||||
writer.write("@echo off");
|
writer.write("@echo off");
|
||||||
writer.newLine();
|
writer.newLine();
|
||||||
writer.write("set APPDATA=" + options.getGameDir().getAbsoluteFile().getParent());
|
writer.write("set APPDATA=" + options.getGameDir().getAbsoluteFile().getParent());
|
||||||
writer.newLine();
|
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.write("set " + entry.getKey() + "=" + CommandBuilder.toBatchStringLiteral(entry.getValue()));
|
||||||
writer.newLine();
|
writer.newLine();
|
||||||
}
|
}
|
||||||
@@ -626,7 +646,7 @@ public class DefaultLauncher extends Launcher {
|
|||||||
} else {
|
} else {
|
||||||
writer.write("#!/usr/bin/env bash");
|
writer.write("#!/usr/bin/env bash");
|
||||||
writer.newLine();
|
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.write("export " + entry.getKey() + "=" + CommandBuilder.toShellStringLiteral(entry.getValue()));
|
||||||
writer.newLine();
|
writer.newLine();
|
||||||
}
|
}
|
||||||
@@ -638,13 +658,14 @@ public class DefaultLauncher extends Launcher {
|
|||||||
}
|
}
|
||||||
writer.newLine();
|
writer.newLine();
|
||||||
if (StringUtils.isNotBlank(options.getPreLaunchCommand())) {
|
if (StringUtils.isNotBlank(options.getPreLaunchCommand())) {
|
||||||
writer.write(options.getPreLaunchCommand());
|
writer.write(new CommandBuilder().addAll(StringUtils.tokenize(options.getPreLaunchCommand(), envVars)).toString());
|
||||||
writer.newLine();
|
writer.newLine();
|
||||||
}
|
}
|
||||||
writer.write(command);
|
writer.write(command);
|
||||||
writer.newLine();
|
writer.newLine();
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(options.getPostExitCommand())) {
|
if (StringUtils.isNotBlank(options.getPostExitCommand())) {
|
||||||
writer.write(options.getPostExitCommand());
|
writer.write(new CommandBuilder().addAll(StringUtils.tokenize(options.getPostExitCommand(), envVars)).toString());
|
||||||
writer.newLine();
|
writer.newLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user