change NativesDir into LaunchOptions

This commit is contained in:
yaoxi-std
2021-05-28 17:41:34 +08:00
committed by Yuhui Huang
parent 7cbe24b35b
commit d4f0a04ccd
8 changed files with 70 additions and 39 deletions

View File

@@ -53,6 +53,8 @@ public class LaunchOptions implements Serializable {
private String proxyPass;
private boolean noGeneratedJVMArgs;
private String preLaunchCommand;
private NativesDirectoryType nativesDirType;
private String nativesDir;
/**
* The game directory
@@ -200,6 +202,21 @@ public class LaunchOptions implements Serializable {
return preLaunchCommand;
}
/**
* 0 - ./minecraft/versions/<version>/natives
* 1 - custom natives directory
*/
public NativesDirectoryType getNativesDirType(){
return nativesDirType;
}
/**
* Path to the natives directory, optional
*/
public String getNativesDir(){
return nativesDir;
}
public static class Builder {
private final LaunchOptions options = new LaunchOptions();
@@ -352,6 +369,14 @@ public class LaunchOptions implements Serializable {
return options.preLaunchCommand;
}
public NativesDirectoryType getNativesDirType(){
return options.nativesDirType;
}
public String getNativesDir(){
return options.nativesDir;
}
public Builder setGameDir(File gameDir) {
options.gameDir = gameDir;
return this;
@@ -454,5 +479,15 @@ public class LaunchOptions implements Serializable {
return this;
}
public Builder setNativesDirType(NativesDirectoryType nativesDirType){
options.nativesDirType = nativesDirType;
return this;
}
public Builder setNativesDir(String nativesDir){
options.nativesDir = nativesDir;
return this;
}
}
}

View File

@@ -2,7 +2,7 @@ package org.jackhuang.hmcl.game;
public enum NativesDirectoryType {
/**
* .minecraft/versions/<version name&gt/natives;
* .minecraft/versions/<version name/natives>
*/
VERSION_FOLDER,
/**

View File

@@ -23,6 +23,7 @@ import org.jackhuang.hmcl.game.Arguments;
import org.jackhuang.hmcl.game.GameRepository;
import org.jackhuang.hmcl.game.LaunchOptions;
import org.jackhuang.hmcl.game.Library;
import org.jackhuang.hmcl.game.NativesDirectoryType;
import org.jackhuang.hmcl.game.Version;
import org.jackhuang.hmcl.util.Lang;
import org.jackhuang.hmcl.util.Log4jLevel;
@@ -66,15 +67,11 @@ public class DefaultLauncher extends Launcher {
}
public DefaultLauncher(GameRepository repository, Version version, AuthInfo authInfo, LaunchOptions options, ProcessListener listener) {
this(repository, version, authInfo, options, listener, false, null, true);
this(repository, version, authInfo, options, listener, true);
}
public DefaultLauncher(GameRepository repository, Version version, AuthInfo authInfo, LaunchOptions options, ProcessListener listener, boolean customized_natives, String customized_natives_path) {
this(repository, version, authInfo, options, listener, customized_natives, customized_natives_path, true);
}
public DefaultLauncher(GameRepository repository, Version version, AuthInfo authInfo, LaunchOptions options, ProcessListener listener, boolean customized_natives, String customized_natives_path, boolean daemon) {
super(repository, version, authInfo, options, listener, customized_natives, customized_natives_path, daemon);
public DefaultLauncher(GameRepository repository, Version version, AuthInfo authInfo, LaunchOptions options, ProcessListener listener, boolean daemon) {
super(repository, version, authInfo, options, listener, daemon);
}
private CommandBuilder generateCommandLine(File nativeFolder) throws IOException {
@@ -304,8 +301,12 @@ public class DefaultLauncher extends Launcher {
@Override
public ManagedProcess launch() throws IOException, InterruptedException {
File nativeFolder = null;
if (!customized_natives) nativeFolder = repository.getNativeDirectory(version.getId());
else nativeFolder = new File(customized_natives_path);
if (options.getNativesDirType() == NativesDirectoryType.VERSION_FOLDER) {
nativeFolder = repository.getNativeDirectory(version.getId());
}
else {
nativeFolder = new File(options.getNativesDir());
}
// To guarantee that when failed to generate launch command line, we will not call pre-launch command
List<String> rawCommandLine = generateCommandLine(nativeFolder).asList();
@@ -314,7 +315,9 @@ public class DefaultLauncher extends Launcher {
throw new IllegalStateException("Illegal command line " + rawCommandLine);
}
if (!customized_natives) decompressNatives(nativeFolder);
if (options.getNativesDirType() == NativesDirectoryType.VERSION_FOLDER) {
decompressNatives(nativeFolder);
}
File runDirectory = repository.getRunDirectory(version.getId());
@@ -355,10 +358,16 @@ public class DefaultLauncher extends Launcher {
boolean isWindows = OperatingSystem.WINDOWS == OperatingSystem.CURRENT_OS;
File nativeFolder = null;
if (!customized_natives) nativeFolder = repository.getNativeDirectory(version.getId());
else nativeFolder = new File(customized_natives_path);
if (options.getNativesDirType() == NativesDirectoryType.VERSION_FOLDER) {
nativeFolder = repository.getNativeDirectory(version.getId());
}
else {
nativeFolder = new File(options.getNativesDir());
}
if (!customized_natives) decompressNatives(nativeFolder);
if (options.getNativesDirType() == NativesDirectoryType.VERSION_FOLDER) {
decompressNatives(nativeFolder);
}
if (isWindows && !FileUtils.getExtension(scriptFile).equals("bat"))
throw new IllegalArgumentException("The extension of " + scriptFile + " is not 'bat' in Windows");

View File

@@ -38,30 +38,22 @@ public abstract class Launcher {
protected final LaunchOptions options;
protected final ProcessListener listener;
protected final boolean daemon;
protected final boolean customized_natives;
protected final String customized_natives_path;
public Launcher(GameRepository repository, Version version, AuthInfo authInfo, LaunchOptions options) {
this(repository, version, authInfo, options, null);
}
public Launcher(GameRepository repository, Version version, AuthInfo authInfo, LaunchOptions options, ProcessListener listener) {
this(repository, version, authInfo, options, listener, false, null, true);
this(repository, version, authInfo, options, listener, true);
}
public Launcher(GameRepository repository, Version version, AuthInfo authInfo, LaunchOptions options, ProcessListener listener, boolean customized_natives, String customized_natives_path) {
this(repository, version, authInfo, options, listener, customized_natives, customized_natives_path, true);
}
public Launcher(GameRepository repository, Version version, AuthInfo authInfo, LaunchOptions options, ProcessListener listener, boolean customized_natives, String customized_natives_path, boolean daemon) {
public Launcher(GameRepository repository, Version version, AuthInfo authInfo, LaunchOptions options, ProcessListener listener, boolean daemon) {
this.repository = repository;
this.version = version;
this.authInfo = authInfo;
this.options = options;
this.listener = listener;
this.daemon = daemon;
this.customized_natives = customized_natives;
this.customized_natives_path = customized_natives_path;
}
/**