Add #111: wrapper launch options and login result processing event

This commit is contained in:
huangyuhui 2017-02-18 13:02:19 +08:00
parent 00143de42b
commit 9df351a2f0
4 changed files with 13 additions and 8 deletions

View File

@ -17,7 +17,6 @@
*/
package org.jackhuang.hmcl.util;
import java.io.File;
import org.jackhuang.hmcl.core.GameException;
import org.jackhuang.hmcl.api.auth.AuthenticationException;
import org.jackhuang.hmcl.core.auth.AbstractAuthenticator;
@ -35,6 +34,7 @@ import org.jackhuang.hmcl.api.event.launch.ProcessingLaunchOptionsEvent;
import org.jackhuang.hmcl.core.RuntimeGameException;
import org.jackhuang.hmcl.api.func.Consumer;
import org.jackhuang.hmcl.api.HMCLog;
import org.jackhuang.hmcl.api.Wrapper;
import org.jackhuang.hmcl.util.sys.JavaProcess;
import org.jackhuang.hmcl.api.auth.IAuthenticator;
@ -83,9 +83,9 @@ public class HMCLGameLauncher {
public void run() {
Thread.currentThread().setName("Game Launcher");
try {
LaunchOptions options = profile.getSelectedVersionSetting().createLaunchOptions(profile.getGameDir());
Wrapper<LaunchOptions> options = new Wrapper<>(profile.getSelectedVersionSetting().createLaunchOptions(profile.getGameDir()));
HMCLApi.EVENT_BUS.fireChannel(new ProcessingLaunchOptionsEvent(this, options));
DefaultGameLauncher gl = new DefaultGameLauncher(options, profile.service(), li, l);
DefaultGameLauncher gl = new DefaultGameLauncher(options.getValue(), profile.service(), li, l);
GameLauncherTag tag = new GameLauncherTag();
tag.launcherVisibility = profile.getSelectedVersionSetting().getLauncherVisibility();
gl.setTag(tag);

View File

@ -17,6 +17,7 @@
*/
package org.jackhuang.hmcl.api.event.launch;
import org.jackhuang.hmcl.api.Wrapper;
import org.jackhuang.hmcl.api.event.SimpleEvent;
import org.jackhuang.hmcl.api.game.LaunchOptions;
@ -31,9 +32,9 @@ import org.jackhuang.hmcl.api.game.LaunchOptions;
* @param LaunchOptions you can modify the value of this event to control the launching process.
* @author huang
*/
public class ProcessingLaunchOptionsEvent extends SimpleEvent<LaunchOptions> {
public class ProcessingLaunchOptionsEvent extends SimpleEvent<Wrapper<LaunchOptions>> {
public ProcessingLaunchOptionsEvent(Object source, LaunchOptions value) {
public ProcessingLaunchOptionsEvent(Object source, Wrapper<LaunchOptions> value) {
super(source, value);
}

View File

@ -17,6 +17,7 @@
*/
package org.jackhuang.hmcl.api.event.launch;
import org.jackhuang.hmcl.api.Wrapper;
import org.jackhuang.hmcl.api.auth.UserProfileProvider;
import org.jackhuang.hmcl.api.event.SimpleEvent;
@ -31,9 +32,9 @@ import org.jackhuang.hmcl.api.event.SimpleEvent;
* @param UserProfileProvider you can modify the value of this event to control the user profile.
* @author huangyuhui
*/
public class ProcessingLoginResultEvent extends SimpleEvent<UserProfileProvider> {
public class ProcessingLoginResultEvent extends SimpleEvent<Wrapper<UserProfileProvider>> {
public ProcessingLoginResultEvent(Object source, UserProfileProvider value) {
public ProcessingLoginResultEvent(Object source, Wrapper<UserProfileProvider> value) {
super(source, value);
}

View File

@ -44,6 +44,7 @@ import org.jackhuang.hmcl.util.C;
import org.jackhuang.hmcl.util.StrUtils;
import org.jackhuang.hmcl.util.code.Charsets;
import org.jackhuang.hmcl.api.HMCLog;
import org.jackhuang.hmcl.api.Wrapper;
import org.jackhuang.hmcl.util.sys.FileUtils;
import org.jackhuang.hmcl.util.sys.JavaProcess;
import org.jackhuang.hmcl.util.sys.OS;
@ -113,7 +114,9 @@ public class GameLauncher {
result = login.loginBySettings();
if (result == null)
throw new AuthenticationException("Result can not be null.");
HMCLApi.EVENT_BUS.fireChannel(new ProcessingLoginResultEvent(this, result));
Wrapper<UserProfileProvider> loginInfo = new Wrapper<>(result);
HMCLApi.EVENT_BUS.fireChannel(new ProcessingLoginResultEvent(this, loginInfo));
result = loginInfo.getValue();
HMCLApi.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, LaunchingState.GeneratingLaunchingCodes));
loader = service.launch(options, result);