add: allow customize LWJGL path (runs on M1)

This commit is contained in:
yaoxi-std
2021-05-27 22:58:55 +08:00
committed by Yuhui Huang
parent b7da21e5ce
commit 7cbe24b35b
14 changed files with 131 additions and 16 deletions

View File

@@ -0,0 +1,12 @@
package org.jackhuang.hmcl.game;
public enum NativesDirectoryType {
/**
* .minecraft/versions/<version name&gt/natives;
*/
VERSION_FOLDER,
/**
* user customized directory.
*/
CUSTOM
}

View File

@@ -66,11 +66,15 @@ public class DefaultLauncher extends Launcher {
}
public DefaultLauncher(GameRepository repository, Version version, AuthInfo authInfo, LaunchOptions options, ProcessListener listener) {
this(repository, version, authInfo, options, listener, true);
this(repository, version, authInfo, options, listener, false, null, true);
}
public DefaultLauncher(GameRepository repository, Version version, AuthInfo authInfo, LaunchOptions options, ProcessListener listener, boolean daemon) {
super(repository, version, authInfo, options, listener, daemon);
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);
}
private CommandBuilder generateCommandLine(File nativeFolder) throws IOException {
@@ -299,8 +303,10 @@ public class DefaultLauncher extends Launcher {
@Override
public ManagedProcess launch() throws IOException, InterruptedException {
File nativeFolder = repository.getNativeDirectory(version.getId());
File nativeFolder = null;
if (!customized_natives) nativeFolder = repository.getNativeDirectory(version.getId());
else nativeFolder = new File(customized_natives_path);
// To guarantee that when failed to generate launch command line, we will not call pre-launch command
List<String> rawCommandLine = generateCommandLine(nativeFolder).asList();
@@ -308,7 +314,7 @@ public class DefaultLauncher extends Launcher {
throw new IllegalStateException("Illegal command line " + rawCommandLine);
}
decompressNatives(nativeFolder);
if (!customized_natives) decompressNatives(nativeFolder);
File runDirectory = repository.getRunDirectory(version.getId());
@@ -348,8 +354,11 @@ public class DefaultLauncher extends Launcher {
public void makeLaunchScript(File scriptFile) throws IOException {
boolean isWindows = OperatingSystem.WINDOWS == OperatingSystem.CURRENT_OS;
File nativeFolder = repository.getNativeDirectory(version.getId());
decompressNatives(nativeFolder);
File nativeFolder = null;
if (!customized_natives) nativeFolder = repository.getNativeDirectory(version.getId());
else nativeFolder = new File(customized_natives_path);
if (!customized_natives) decompressNatives(nativeFolder);
if (isWindows && !FileUtils.getExtension(scriptFile).equals("bat"))
throw new IllegalArgumentException("The extension of " + scriptFile + " is not 'bat' in Windows");

View File

@@ -38,22 +38,30 @@ 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, true);
this(repository, version, authInfo, options, listener, false, null, true);
}
public Launcher(GameRepository repository, Version version, AuthInfo authInfo, LaunchOptions options, ProcessListener listener, boolean daemon) {
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) {
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;
}
/**