mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-17 07:47:57 -04:00
reconstruct codes
This commit is contained in:
parent
f32ce42af3
commit
d207fa3dfb
@ -17,7 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hellominecraft.launcher.api;
|
package org.jackhuang.hellominecraft.launcher.api;
|
||||||
|
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftService;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.AuthenticationException;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.AuthenticationException;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.IAuthenticator;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.IAuthenticator;
|
||||||
@ -38,7 +38,7 @@ public interface IPlugin {
|
|||||||
* @return For example, you can implement IMinecraftProvider to support
|
* @return For example, you can implement IMinecraftProvider to support
|
||||||
* MultiMC
|
* MultiMC
|
||||||
*/
|
*/
|
||||||
IMinecraftProvider provideMinecraftProvider(Profile profile);
|
IMinecraftService provideMinecraftService(Profile profile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register authenticators by calling IAuthenticator.LOGINS.add.
|
* Register authenticators by calling IAuthenticator.LOGINS.add.
|
||||||
|
@ -46,16 +46,16 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
|
|||||||
protected Profile v;
|
protected Profile v;
|
||||||
protected UserProfileProvider lr;
|
protected UserProfileProvider lr;
|
||||||
protected File gameDir;
|
protected File gameDir;
|
||||||
protected IMinecraftProvider provider;
|
protected IMinecraftService service;
|
||||||
protected final MinecraftVersion version;
|
protected final MinecraftVersion version;
|
||||||
|
|
||||||
public AbstractMinecraftLoader(Profile ver, IMinecraftProvider provider, UserProfileProvider lr) {
|
public AbstractMinecraftLoader(Profile ver, IMinecraftService provider, UserProfileProvider lr) throws GameException {
|
||||||
this.lr = lr;
|
this.lr = lr;
|
||||||
|
|
||||||
v = ver;
|
v = ver;
|
||||||
this.provider = provider;
|
service = provider;
|
||||||
gameDir = v.getCanonicalGameDirFile();
|
gameDir = v.getCanonicalGameDirFile();
|
||||||
version = provider.getSelectedVersion().resolve(provider);
|
version = service.version().getSelectedVersion().resolve(service.version());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -134,7 +134,7 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
|
|||||||
res.add(a);
|
res.add(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.add("-Djava.library.path=" + provider.getDecompressNativesToLocation(version).getPath());
|
res.add("-Djava.library.path=" + service.version().getDecompressNativesToLocation(version).getPath());
|
||||||
res.add("-Dfml.ignoreInvalidMinecraftCertificates=true");
|
res.add("-Dfml.ignoreInvalidMinecraftCertificates=true");
|
||||||
res.add("-Dfml.ignorePatchDiscrepancies=true");
|
res.add("-Dfml.ignorePatchDiscrepancies=true");
|
||||||
|
|
||||||
|
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Hello Minecraft! Launcher.
|
||||||
|
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||||||
|
*/
|
||||||
|
package org.jackhuang.hellominecraft.launcher.launch;
|
||||||
|
|
||||||
|
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.utils.installers.MinecraftInstallerService;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.version.MinecraftAssetService;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.version.MinecraftDownloadService;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.version.MinecraftModService;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersionManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author huangyuhui
|
||||||
|
*/
|
||||||
|
public class DefaultMinecraftService extends IMinecraftService {
|
||||||
|
|
||||||
|
public DefaultMinecraftService(Profile p) {
|
||||||
|
super(p);
|
||||||
|
this.provider = new MinecraftVersionManager(this);
|
||||||
|
provider.initializeMiencraft();
|
||||||
|
this.mms = new MinecraftModService(this);
|
||||||
|
this.mds = new MinecraftDownloadService(this);
|
||||||
|
this.mas = new MinecraftAssetService(this);
|
||||||
|
this.mis = new MinecraftInstallerService(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IMinecraftProvider provider;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMinecraftProvider version() {
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected MinecraftModService mms;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMinecraftModService mod() {
|
||||||
|
return mms;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected MinecraftDownloadService mds;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMinecraftDownloadService download() {
|
||||||
|
return mds;
|
||||||
|
}
|
||||||
|
|
||||||
|
final MinecraftAssetService mas;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMinecraftAssetService asset() {
|
||||||
|
return mas;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected MinecraftInstallerService mis;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMinecraftInstallerService install() {
|
||||||
|
return mis;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -25,7 +25,6 @@ import org.jackhuang.hellominecraft.launcher.utils.auth.OfflineAuthenticator;
|
|||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.SkinmeAuthenticator;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.SkinmeAuthenticator;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.YggdrasilAuthenticator;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.YggdrasilAuthenticator;
|
||||||
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersionManager;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.views.MainFrame;
|
import org.jackhuang.hellominecraft.launcher.views.MainFrame;
|
||||||
import org.jackhuang.hellominecraft.utils.functions.Consumer;
|
import org.jackhuang.hellominecraft.utils.functions.Consumer;
|
||||||
|
|
||||||
@ -40,8 +39,8 @@ public class DefaultPlugin implements IPlugin {
|
|||||||
protected static SkinmeAuthenticator SKINME_LOGIN;
|
protected static SkinmeAuthenticator SKINME_LOGIN;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMinecraftProvider provideMinecraftProvider(Profile profile) {
|
public IMinecraftService provideMinecraftService(Profile profile) {
|
||||||
return new MinecraftVersionManager(profile);
|
return new DefaultMinecraftService(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -23,8 +23,19 @@ package org.jackhuang.hellominecraft.launcher.launch;
|
|||||||
*/
|
*/
|
||||||
public class GameException extends Exception {
|
public class GameException extends Exception {
|
||||||
|
|
||||||
|
public GameException() {
|
||||||
|
}
|
||||||
|
|
||||||
public GameException(String message) {
|
public GameException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GameException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ import org.jackhuang.hellominecraft.launcher.utils.auth.IAuthenticator;
|
|||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.LoginInfo;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.LoginInfo;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.utils.auth.AuthenticationException;
|
||||||
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
||||||
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
||||||
import org.jackhuang.hellominecraft.utils.system.JavaProcess;
|
import org.jackhuang.hellominecraft.utils.system.JavaProcess;
|
||||||
@ -44,11 +45,10 @@ public class GameLauncher {
|
|||||||
|
|
||||||
public static final ProcessManager PROCESS_MANAGER = new ProcessManager();
|
public static final ProcessManager PROCESS_MANAGER = new ProcessManager();
|
||||||
Profile get;
|
Profile get;
|
||||||
IMinecraftProvider provider;
|
IMinecraftService provider;
|
||||||
LoginInfo info;
|
LoginInfo info;
|
||||||
UserProfileProvider result;
|
UserProfileProvider result;
|
||||||
IAuthenticator login;
|
IAuthenticator login;
|
||||||
public final EventHandler<String> failEvent = new EventHandler(this);
|
|
||||||
public final EventHandler<List<DownloadLibraryJob>> downloadLibrariesEvent = new EventHandler(this);
|
public final EventHandler<List<DownloadLibraryJob>> downloadLibrariesEvent = new EventHandler(this);
|
||||||
public final EventHandler<List<String>> successEvent = new EventHandler(this);
|
public final EventHandler<List<String>> successEvent = new EventHandler(this);
|
||||||
public final EventHandler<JavaProcess> launchEvent = new EventHandler(this);
|
public final EventHandler<JavaProcess> launchEvent = new EventHandler(this);
|
||||||
@ -56,7 +56,7 @@ public class GameLauncher {
|
|||||||
|
|
||||||
public GameLauncher(Profile version, LoginInfo info, IAuthenticator lg) {
|
public GameLauncher(Profile version, LoginInfo info, IAuthenticator lg) {
|
||||||
this.get = version;
|
this.get = version;
|
||||||
this.provider = get.getMinecraftProvider();
|
this.provider = get.service();
|
||||||
this.info = info;
|
this.info = info;
|
||||||
this.login = lg;
|
this.login = lg;
|
||||||
}
|
}
|
||||||
@ -65,63 +65,33 @@ public class GameLauncher {
|
|||||||
return get;
|
return get;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMinecraftLoader makeLaunchCommand() {
|
public IMinecraftLoader makeLaunchCommand() throws AuthenticationException, GameException {
|
||||||
HMCLog.log("Logging in...");
|
HMCLog.log("Logging in...");
|
||||||
IMinecraftLoader loader;
|
IMinecraftLoader loader;
|
||||||
try {
|
if (info != null)
|
||||||
if (info != null)
|
result = login.login(info);
|
||||||
result = login.login(info);
|
else
|
||||||
else
|
result = login.loginBySettings();
|
||||||
result = login.loginBySettings();
|
if (result == null)
|
||||||
if (result == null)
|
throw new AuthenticationException("Result can not be null.");
|
||||||
throw new GameException("Result can not be null.");
|
PluginManager.NOW_PLUGIN.onProcessingLoginResult(result);
|
||||||
PluginManager.NOW_PLUGIN.onProcessingLoginResult(result);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
String error = C.i18n("login.failed") + e.getMessage();
|
|
||||||
HMCLog.warn("Login failed by method: " + login.getName(), e);
|
|
||||||
failEvent.execute(error);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
loader = provider.version().provideMinecraftLoader(result);
|
||||||
loader = provider.provideMinecraftLoader(result);
|
|
||||||
} catch (GameException e) {
|
|
||||||
failEvent.execute(C.i18n("launch.failed") + ", " + e.getMessage());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
File file = provider.getDecompressNativesToLocation(loader.getMinecraftVersion());
|
File file = provider.version().getDecompressNativesToLocation(loader.getMinecraftVersion());
|
||||||
if (file != null)
|
if (file != null)
|
||||||
FileUtils.cleanDirectoryQuietly(file);
|
FileUtils.cleanDirectoryQuietly(file);
|
||||||
|
|
||||||
HMCLog.log("Detecting libraries...");
|
HMCLog.log("Detecting libraries...");
|
||||||
if (!downloadLibrariesEvent.execute(provider.getDownloadService().getDownloadLibraries())) {
|
if (!downloadLibrariesEvent.execute(provider.download().getDownloadLibraries(loader.getMinecraftVersion())))
|
||||||
failEvent.execute(C.i18n("launch.failed"));
|
throw new GameException("Failed to download libraries");
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
HMCLog.log("Unpacking natives...");
|
HMCLog.log("Unpacking natives...");
|
||||||
DecompressLibraryJob job = null;
|
DecompressLibraryJob job = provider.version().getDecompressLibraries(loader.getMinecraftVersion());
|
||||||
try {
|
if (!decompressNativesEvent.execute(job))
|
||||||
job = provider.getDecompressLibraries(loader.getMinecraftVersion());
|
throw new GameException("Failed to decompress natives");
|
||||||
} catch (GameException e) {
|
|
||||||
failEvent.execute(C.i18n("launch.failed") + ", " + e.getMessage());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (!decompressNativesEvent.execute(job)) {
|
|
||||||
failEvent.execute(C.i18n("launch.failed"));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> lst;
|
successEvent.execute(loader.makeLaunchingCommand());
|
||||||
try {
|
|
||||||
lst = loader.makeLaunchingCommand();
|
|
||||||
} catch (Exception e) {
|
|
||||||
failEvent.execute(C.i18n("launch.failed"));
|
|
||||||
HMCLog.err("Failed to launch game", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
successEvent.execute(lst);
|
|
||||||
return loader;
|
return loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,33 +99,30 @@ public class GameLauncher {
|
|||||||
* Launch the game "as soon as possible".
|
* Launch the game "as soon as possible".
|
||||||
*
|
*
|
||||||
* @param str launch command
|
* @param str launch command
|
||||||
|
*
|
||||||
|
* @throws IOException failed creating process
|
||||||
*/
|
*/
|
||||||
public void launch(List str) {
|
public void launch(List str) throws IOException {
|
||||||
try {
|
if (!provider.version().onLaunch())
|
||||||
if (!provider.onLaunch())
|
return;
|
||||||
return;
|
if (StrUtils.isNotBlank(getProfile().getPrecalledCommand())) {
|
||||||
if (StrUtils.isNotBlank(getProfile().getPrecalledCommand())) {
|
Process p = Runtime.getRuntime().exec(getProfile().getPrecalledCommand());
|
||||||
Process p = Runtime.getRuntime().exec(getProfile().getPrecalledCommand());
|
try {
|
||||||
try {
|
if (p != null && p.isAlive())
|
||||||
if (p != null && p.isAlive())
|
p.waitFor();
|
||||||
p.waitFor();
|
} catch (InterruptedException ex) {
|
||||||
} catch (InterruptedException ex) {
|
HMCLog.warn("Failed to invoke precalled command", ex);
|
||||||
HMCLog.warn("Failed to invoke precalled command", ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
HMCLog.log("Starting process");
|
|
||||||
ProcessBuilder builder = new ProcessBuilder(str);
|
|
||||||
if (get == null || provider.getSelectedVersion() == null || StrUtils.isBlank(get.getCanonicalGameDir()))
|
|
||||||
throw new Error("Fucking bug!");
|
|
||||||
builder.directory(provider.getRunDirectory(provider.getSelectedVersion().id))
|
|
||||||
.environment().put("APPDATA", get.getCanonicalGameDir());
|
|
||||||
JavaProcess jp = new JavaProcess(str, builder.start(), PROCESS_MANAGER);
|
|
||||||
HMCLog.log("The game process have been started");
|
|
||||||
launchEvent.execute(jp);
|
|
||||||
} catch (Exception e) {
|
|
||||||
failEvent.execute(C.i18n("launch.failed_creating_process") + "\n" + e.getMessage());
|
|
||||||
HMCLog.err("Failed to launch when creating a new process.", e);
|
|
||||||
}
|
}
|
||||||
|
HMCLog.log("Starting process");
|
||||||
|
ProcessBuilder builder = new ProcessBuilder(str);
|
||||||
|
if (get == null || provider.version().getSelectedVersion() == null || StrUtils.isBlank(get.getCanonicalGameDir()))
|
||||||
|
throw new Error("Fucking bug!");
|
||||||
|
builder.directory(provider.version().getRunDirectory(provider.version().getSelectedVersion().id))
|
||||||
|
.environment().put("APPDATA", get.getCanonicalGameDir());
|
||||||
|
JavaProcess jp = new JavaProcess(str, builder.start(), PROCESS_MANAGER);
|
||||||
|
HMCLog.log("The game process have been started");
|
||||||
|
launchEvent.execute(jp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -170,7 +137,7 @@ public class GameLauncher {
|
|||||||
*/
|
*/
|
||||||
public File makeLauncher(String launcherName, List str) throws IOException {
|
public File makeLauncher(String launcherName, List str) throws IOException {
|
||||||
HMCLog.log("Making shell launcher...");
|
HMCLog.log("Making shell launcher...");
|
||||||
provider.onLaunch();
|
provider.version().onLaunch();
|
||||||
boolean isWin = OS.os() == OS.WINDOWS;
|
boolean isWin = OS.os() == OS.WINDOWS;
|
||||||
File f = new File(launcherName + (isWin ? ".bat" : ".sh"));
|
File f = new File(launcherName + (isWin ? ".bat" : ".sh"));
|
||||||
if (!f.exists())
|
if (!f.exists())
|
||||||
|
@ -19,16 +19,15 @@ package org.jackhuang.hellominecraft.launcher.launch;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
|
||||||
import org.jackhuang.hellominecraft.tasks.Task;
|
import org.jackhuang.hellominecraft.tasks.Task;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author huangyuhui
|
* @author huangyuhui
|
||||||
*/
|
*/
|
||||||
public abstract class IMinecraftAssetService extends IMinecraftService {
|
public abstract class IMinecraftAssetService extends IMinecraftBasicService {
|
||||||
|
|
||||||
public IMinecraftAssetService(Profile profile) {
|
public IMinecraftAssetService(IMinecraftService profile) {
|
||||||
super(profile);
|
super(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Hello Minecraft! Launcher.
|
||||||
|
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||||||
|
*/
|
||||||
|
package org.jackhuang.hellominecraft.launcher.launch;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author huangyuhui
|
||||||
|
*/
|
||||||
|
public abstract class IMinecraftBasicService {
|
||||||
|
|
||||||
|
public IMinecraftService service;
|
||||||
|
|
||||||
|
public IMinecraftBasicService(IMinecraftService service) {
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -18,7 +18,7 @@
|
|||||||
package org.jackhuang.hellominecraft.launcher.launch;
|
package org.jackhuang.hellominecraft.launcher.launch;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
|
||||||
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
||||||
import org.jackhuang.hellominecraft.version.MinecraftRemoteVersion;
|
import org.jackhuang.hellominecraft.version.MinecraftRemoteVersion;
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
@ -27,9 +27,9 @@ import rx.Observable;
|
|||||||
*
|
*
|
||||||
* @author huangyuhui
|
* @author huangyuhui
|
||||||
*/
|
*/
|
||||||
public abstract class IMinecraftDownloadService extends IMinecraftService {
|
public abstract class IMinecraftDownloadService extends IMinecraftBasicService {
|
||||||
|
|
||||||
public IMinecraftDownloadService(Profile profile) {
|
public IMinecraftDownloadService(IMinecraftService profile) {
|
||||||
super(profile);
|
super(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,16 +44,7 @@ public abstract class IMinecraftDownloadService extends IMinecraftService {
|
|||||||
*
|
*
|
||||||
* @return the library collection
|
* @return the library collection
|
||||||
*/
|
*/
|
||||||
public abstract List<GameLauncher.DownloadLibraryJob> getDownloadLibraries();
|
public abstract List<GameLauncher.DownloadLibraryJob> getDownloadLibraries(MinecraftVersion mv) throws GameException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Install a new version to this profile.
|
|
||||||
*
|
|
||||||
* @param version the new version name
|
|
||||||
*
|
|
||||||
* @return Is the action successful?
|
|
||||||
*/
|
|
||||||
public abstract boolean install(String version);
|
|
||||||
|
|
||||||
public abstract Observable<MinecraftRemoteVersion> getRemoteVersions();
|
public abstract Observable<MinecraftRemoteVersion> getRemoteVersions();
|
||||||
|
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Hello Minecraft! Launcher.
|
||||||
|
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||||||
|
*/
|
||||||
|
package org.jackhuang.hellominecraft.launcher.launch;
|
||||||
|
|
||||||
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftBasicService;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftService;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerType;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList;
|
||||||
|
import org.jackhuang.hellominecraft.tasks.Task;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author huangyuhui
|
||||||
|
*/
|
||||||
|
public abstract class IMinecraftInstallerService extends IMinecraftBasicService {
|
||||||
|
|
||||||
|
public IMinecraftInstallerService(IMinecraftService service) {
|
||||||
|
super(service);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Task download(InstallerVersionList.InstallerVersion v, InstallerType type);
|
||||||
|
|
||||||
|
public abstract Task downloadForge(InstallerVersionList.InstallerVersion v);
|
||||||
|
|
||||||
|
public abstract Task downloadOptifine(InstallerVersionList.InstallerVersion v);
|
||||||
|
|
||||||
|
public abstract Task downloadLiteLoader(InstallerVersionList.InstallerVersion v);
|
||||||
|
|
||||||
|
}
|
@ -19,16 +19,15 @@ package org.jackhuang.hellominecraft.launcher.launch;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.ModInfo;
|
import org.jackhuang.hellominecraft.launcher.utils.ModInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author huangyuhui
|
* @author huangyuhui
|
||||||
*/
|
*/
|
||||||
public abstract class IMinecraftModService extends IMinecraftService {
|
public abstract class IMinecraftModService extends IMinecraftBasicService {
|
||||||
|
|
||||||
public IMinecraftModService(Profile profile) {
|
public IMinecraftModService(IMinecraftService profile) {
|
||||||
super(profile);
|
super(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ package org.jackhuang.hellominecraft.launcher.launch;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
import org.jackhuang.hellominecraft.launcher.version.GameDirType;
|
||||||
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
||||||
import org.jackhuang.hellominecraft.utils.StrUtils;
|
import org.jackhuang.hellominecraft.utils.StrUtils;
|
||||||
|
|
||||||
@ -32,10 +32,10 @@ import org.jackhuang.hellominecraft.utils.StrUtils;
|
|||||||
*/
|
*/
|
||||||
public abstract class IMinecraftProvider {
|
public abstract class IMinecraftProvider {
|
||||||
|
|
||||||
protected Profile profile;
|
protected IMinecraftService service;
|
||||||
|
|
||||||
public IMinecraftProvider(Profile profile) {
|
public IMinecraftProvider(IMinecraftService service) {
|
||||||
this.profile = profile;
|
this.service = service;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,16 +53,19 @@ public abstract class IMinecraftProvider {
|
|||||||
public abstract File getRunDirectory(String id);
|
public abstract File getRunDirectory(String id);
|
||||||
|
|
||||||
public File getRunDirectory(String id, String subFolder) {
|
public File getRunDirectory(String id, String subFolder) {
|
||||||
return new File(getRunDirectory(getSelectedVersion().id), subFolder);
|
return new File(getRunDirectory(id), subFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void open(String version, String folder);
|
public abstract void open(String version, String folder);
|
||||||
|
|
||||||
public abstract IMinecraftModService getModService();
|
/**
|
||||||
|
* Install a new version to this profile.
|
||||||
public abstract IMinecraftDownloadService getDownloadService();
|
*
|
||||||
|
* @param version the new version name
|
||||||
public abstract IMinecraftAssetService getAssetService();
|
*
|
||||||
|
* @return Is the action successful?
|
||||||
|
*/
|
||||||
|
public abstract boolean install(String version);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the thing like ".minecraft/resourcepacks".
|
* Returns the thing like ".minecraft/resourcepacks".
|
||||||
@ -103,6 +106,12 @@ public abstract class IMinecraftProvider {
|
|||||||
*/
|
*/
|
||||||
public abstract IMinecraftLoader provideMinecraftLoader(UserProfileProvider p) throws GameException;
|
public abstract IMinecraftLoader provideMinecraftLoader(UserProfileProvider p) throws GameException;
|
||||||
|
|
||||||
|
protected GameDirType gameDirType = GameDirType.ROOT_FOLDER;
|
||||||
|
|
||||||
|
public void setGameDirType(GameDirType gameDirType) {
|
||||||
|
this.gameDirType = gameDirType;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rename version
|
* Rename version
|
||||||
*
|
*
|
||||||
@ -122,17 +131,6 @@ public abstract class IMinecraftProvider {
|
|||||||
*/
|
*/
|
||||||
public abstract boolean removeVersionFromDisk(String a);
|
public abstract boolean removeVersionFromDisk(String a);
|
||||||
|
|
||||||
/**
|
|
||||||
* Redownload the Minecraft json of the given version.
|
|
||||||
*
|
|
||||||
* @param id the given version name
|
|
||||||
*
|
|
||||||
* @return Is the action successful?
|
|
||||||
*/
|
|
||||||
public boolean refreshJson(String id) {
|
|
||||||
return getDownloadService().downloadMinecraftVersionJson(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Choose a version randomly.
|
* Choose a version randomly.
|
||||||
*
|
*
|
||||||
@ -157,14 +155,14 @@ public abstract class IMinecraftProvider {
|
|||||||
public abstract MinecraftVersion getVersionById(String id);
|
public abstract MinecraftVersion getVersionById(String id);
|
||||||
|
|
||||||
public MinecraftVersion getSelectedVersion() {
|
public MinecraftVersion getSelectedVersion() {
|
||||||
String versionName = profile.getSelectedMinecraftVersionName();
|
String versionName = service.profile.getSelectedMinecraftVersionName();
|
||||||
MinecraftVersion v = null;
|
MinecraftVersion v = null;
|
||||||
if (StrUtils.isNotBlank(versionName))
|
if (StrUtils.isNotBlank(versionName))
|
||||||
v = getVersionById(versionName);
|
v = getVersionById(versionName);
|
||||||
if (v == null)
|
if (v == null)
|
||||||
v = getOneVersion();
|
v = getOneVersion();
|
||||||
if (v != null)
|
if (v != null)
|
||||||
profile.setSelectedMinecraftVersion(v.id);
|
service.profile.setSelectedMinecraftVersion(v.id);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/launch/IMinecraftService.java
Executable file → Normal file
21
HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/launch/IMinecraftService.java
Executable file → Normal file
@ -17,7 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hellominecraft.launcher.launch;
|
package org.jackhuang.hellominecraft.launcher.launch;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.settings.Settings;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -25,10 +28,26 @@ import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
|||||||
*/
|
*/
|
||||||
public abstract class IMinecraftService {
|
public abstract class IMinecraftService {
|
||||||
|
|
||||||
public Profile profile;
|
public final Profile profile;
|
||||||
|
public final File baseFolder;
|
||||||
|
|
||||||
public IMinecraftService(Profile profile) {
|
public IMinecraftService(Profile profile) {
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
|
this.baseFolder = profile.getCanonicalGameDirFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DownloadType getDownloadType() {
|
||||||
|
return Settings.getInstance().getDownloadSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract IMinecraftAssetService asset();
|
||||||
|
|
||||||
|
public abstract IMinecraftDownloadService download();
|
||||||
|
|
||||||
|
public abstract IMinecraftModService mod();
|
||||||
|
|
||||||
|
public abstract IMinecraftProvider version();
|
||||||
|
|
||||||
|
public abstract IMinecraftInstallerService install();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ import org.jackhuang.hellominecraft.C;
|
|||||||
import org.jackhuang.hellominecraft.HMCLog;
|
import org.jackhuang.hellominecraft.HMCLog;
|
||||||
import org.jackhuang.hellominecraft.launcher.Main;
|
import org.jackhuang.hellominecraft.launcher.Main;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
|
||||||
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.assets.AssetsIndex;
|
import org.jackhuang.hellominecraft.launcher.utils.assets.AssetsIndex;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.assets.AssetsObject;
|
import org.jackhuang.hellominecraft.launcher.utils.assets.AssetsObject;
|
||||||
@ -48,8 +47,8 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
|||||||
DownloadType dt;
|
DownloadType dt;
|
||||||
String text;
|
String text;
|
||||||
|
|
||||||
public MinecraftLoader(Profile ver, IMinecraftProvider provider, UserProfileProvider lr) throws GameException {
|
public MinecraftLoader(IMinecraftService provider, UserProfileProvider lr) throws GameException {
|
||||||
super(ver, provider, lr);
|
super(provider.profile, provider, lr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -60,7 +59,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
|||||||
if (l.allow() && !l.isRequiredToUnzip())
|
if (l.allow() && !l.isRequiredToUnzip())
|
||||||
library += l.getFilePath(gameDir).getAbsolutePath() + File.pathSeparator;
|
library += l.getFilePath(gameDir).getAbsolutePath() + File.pathSeparator;
|
||||||
}
|
}
|
||||||
library += IOUtils.tryGetCanonicalFilePath(version.getJar(provider.getBaseFolder())) + File.pathSeparator;
|
library += IOUtils.tryGetCanonicalFilePath(version.getJar(v.getCanonicalGameDirFile())) + File.pathSeparator;
|
||||||
library = library.substring(0, library.length() - File.pathSeparator.length());
|
library = library.substring(0, library.length() - File.pathSeparator.length());
|
||||||
if (v.isCanceledWrapper())
|
if (v.isCanceledWrapper())
|
||||||
res.add("-cp");
|
res.add("-cp");
|
||||||
@ -68,14 +67,14 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
|||||||
String mainClass = version.mainClass;
|
String mainClass = version.mainClass;
|
||||||
res.add((v.isCanceledWrapper() ? "" : "-mainClass=") + mainClass);
|
res.add((v.isCanceledWrapper() ? "" : "-mainClass=") + mainClass);
|
||||||
|
|
||||||
String arg = provider.getSelectedVersion().minecraftArguments;
|
String arg = service.version().getSelectedVersion().minecraftArguments;
|
||||||
String[] splitted = StrUtils.tokenize(arg);
|
String[] splitted = StrUtils.tokenize(arg);
|
||||||
|
|
||||||
if (!checkAssetsExist())
|
if (!checkAssetsExist())
|
||||||
if (MessageBox.Show(C.i18n("assets.no_assets"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
|
if (MessageBox.Show(C.i18n("assets.no_assets"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
|
||||||
IAssetsHandler.ASSETS_HANDLER.getList(version, provider).subscribe(a -> {
|
IAssetsHandler.ASSETS_HANDLER.getList(version, service.asset()).subscribe(a -> {
|
||||||
});
|
});
|
||||||
TaskWindow.getInstance().addTask(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(provider.profile.getDownloadType().getProvider())).start();
|
TaskWindow.getInstance().addTask(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(service.getDownloadType().getProvider())).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
String game_assets = reconstructAssets().getAbsolutePath();
|
String game_assets = reconstructAssets().getAbsolutePath();
|
||||||
@ -85,10 +84,10 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
|||||||
t = t.replace("${auth_session}", lr.getSession());
|
t = t.replace("${auth_session}", lr.getSession());
|
||||||
t = t.replace("${auth_uuid}", lr.getUserId());
|
t = t.replace("${auth_uuid}", lr.getUserId());
|
||||||
t = t.replace("${version_name}", Main.makeTitle());
|
t = t.replace("${version_name}", Main.makeTitle());
|
||||||
t = t.replace("${profile_name}", provider.profile.getName());
|
t = t.replace("${profile_name}", v.getName());
|
||||||
t = t.replace("${game_directory}", provider.getRunDirectory(version.id).getAbsolutePath());
|
t = t.replace("${game_directory}", service.version().getRunDirectory(version.id).getAbsolutePath());
|
||||||
t = t.replace("${game_assets}", game_assets);
|
t = t.replace("${game_assets}", game_assets);
|
||||||
t = t.replace("${assets_root}", provider.getAssetService().getAssets().getAbsolutePath());
|
t = t.replace("${assets_root}", service.asset().getAssets().getAbsolutePath());
|
||||||
t = t.replace("${auth_access_token}", lr.getAccessToken());
|
t = t.replace("${auth_access_token}", lr.getAccessToken());
|
||||||
t = t.replace("${user_type}", lr.getUserType());
|
t = t.replace("${user_type}", lr.getUserType());
|
||||||
t = t.replace("${assets_index_name}", version.getAssets());
|
t = t.replace("${assets_index_name}", version.getAssets());
|
||||||
@ -108,7 +107,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (OS.os() == OS.OSX) {
|
if (OS.os() == OS.OSX) {
|
||||||
list.add("-Xdock:icon=" + provider.getAssetService().getAssetObject(version.assets, "icons/minecraft.icns").getAbsolutePath());
|
list.add("-Xdock:icon=" + service.asset().getAssetObject(version.assets, "icons/minecraft.icns").getAbsolutePath());
|
||||||
list.add("-Xdock:name=Minecraft");
|
list.add("-Xdock:name=Minecraft");
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -117,7 +116,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkAssetsExist() {
|
private boolean checkAssetsExist() {
|
||||||
File assetsDir = new File(provider.getBaseFolder(), "assets");
|
File assetsDir = new File(service.baseFolder, "assets");
|
||||||
File indexDir = new File(assetsDir, "indexes");
|
File indexDir = new File(assetsDir, "indexes");
|
||||||
File objectDir = new File(assetsDir, "objects");
|
File objectDir = new File(assetsDir, "objects");
|
||||||
File indexFile = new File(indexDir, version.getAssets() + ".json");
|
File indexFile = new File(indexDir, version.getAssets() + ".json");
|
||||||
@ -140,7 +139,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private File reconstructAssets() {
|
private File reconstructAssets() {
|
||||||
File assetsDir = new File(provider.getBaseFolder(), "assets");
|
File assetsDir = new File(service.baseFolder, "assets");
|
||||||
File indexDir = new File(assetsDir, "indexes");
|
File indexDir = new File(assetsDir, "indexes");
|
||||||
File objectDir = new File(assetsDir, "objects");
|
File objectDir = new File(assetsDir, "objects");
|
||||||
String assetVersion = version.getAssets();
|
String assetVersion = version.getAssets();
|
||||||
|
@ -60,6 +60,7 @@ public final class Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public transient final EventHandler<Theme> themeChangedEvent = new EventHandler<>(this);
|
public transient final EventHandler<Theme> themeChangedEvent = new EventHandler<>(this);
|
||||||
|
public transient final EventHandler<DownloadType> downloadTypeChangedEvent = new EventHandler<>(this);
|
||||||
|
|
||||||
public Theme getTheme() {
|
public Theme getTheme() {
|
||||||
return Theme.values()[theme];
|
return Theme.values()[theme];
|
||||||
@ -140,6 +141,7 @@ public final class Config {
|
|||||||
|
|
||||||
public void setDownloadType(int downloadtype) {
|
public void setDownloadType(int downloadtype) {
|
||||||
this.downloadtype = downloadtype;
|
this.downloadtype = downloadtype;
|
||||||
|
downloadTypeChangedEvent.execute(getDownloadSource());
|
||||||
Settings.save();
|
Settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,11 +19,9 @@ package org.jackhuang.hellominecraft.launcher.settings;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import org.jackhuang.hellominecraft.launcher.api.PluginManager;
|
import org.jackhuang.hellominecraft.launcher.api.PluginManager;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftService;
|
||||||
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.MCUtils;
|
import org.jackhuang.hellominecraft.launcher.utils.MCUtils;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerService;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.version.GameDirType;
|
import org.jackhuang.hellominecraft.launcher.version.GameDirType;
|
||||||
import org.jackhuang.hellominecraft.utils.StrUtils;
|
import org.jackhuang.hellominecraft.utils.StrUtils;
|
||||||
import org.jackhuang.hellominecraft.utils.Utils;
|
import org.jackhuang.hellominecraft.utils.Utils;
|
||||||
@ -54,7 +52,7 @@ public final class Profile {
|
|||||||
*/
|
*/
|
||||||
private int gameDirType;
|
private int gameDirType;
|
||||||
|
|
||||||
protected transient IMinecraftProvider minecraftProvider;
|
protected transient IMinecraftService service;
|
||||||
|
|
||||||
public Profile() {
|
public Profile() {
|
||||||
this("Default");
|
this("Default");
|
||||||
@ -97,12 +95,10 @@ public final class Profile {
|
|||||||
serverIp = v.serverIp;
|
serverIp = v.serverIp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMinecraftProvider getMinecraftProvider() {
|
public IMinecraftService service() {
|
||||||
if (minecraftProvider == null) {
|
if (service == null)
|
||||||
minecraftProvider = PluginManager.NOW_PLUGIN.provideMinecraftProvider(this);
|
service = PluginManager.NOW_PLUGIN.provideMinecraftService(this);
|
||||||
minecraftProvider.initializeMiencraft();
|
return service;
|
||||||
}
|
|
||||||
return minecraftProvider;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSelectedMinecraftVersionName() {
|
public String getSelectedMinecraftVersionName() {
|
||||||
@ -137,7 +133,7 @@ public final class Profile {
|
|||||||
|
|
||||||
public Profile setGameDir(String gameDir) {
|
public Profile setGameDir(String gameDir) {
|
||||||
this.gameDir = gameDir;
|
this.gameDir = gameDir;
|
||||||
getMinecraftProvider().refreshVersions();
|
service().version().refreshVersions();
|
||||||
Settings.save();
|
Settings.save();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -191,9 +187,9 @@ public final class Profile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public File getFolder(String folder) {
|
public File getFolder(String folder) {
|
||||||
if (getMinecraftProvider().getSelectedVersion() == null)
|
if (service().version().getSelectedVersion() == null)
|
||||||
return new File(getCanonicalGameDirFile(), folder);
|
return new File(getCanonicalGameDirFile(), folder);
|
||||||
return getMinecraftProvider().getRunDirectory(getMinecraftProvider().getSelectedVersion().id, folder);
|
return service().version().getRunDirectory(service().version().getSelectedVersion().id, folder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@ -296,6 +292,7 @@ public final class Profile {
|
|||||||
|
|
||||||
public void setGameDirType(GameDirType gameDirType) {
|
public void setGameDirType(GameDirType gameDirType) {
|
||||||
this.gameDirType = gameDirType.ordinal();
|
this.gameDirType = gameDirType.ordinal();
|
||||||
|
service().version().setGameDirType(getGameDirType());
|
||||||
Settings.save();
|
Settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,14 +352,4 @@ public final class Profile {
|
|||||||
public void checkFormat() {
|
public void checkFormat() {
|
||||||
gameDir = gameDir.replace('/', OS.os().fileSeparator).replace('\\', OS.os().fileSeparator);
|
gameDir = gameDir.replace('/', OS.os().fileSeparator).replace('\\', OS.os().fileSeparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
transient final InstallerService is = new InstallerService(this);
|
|
||||||
|
|
||||||
public InstallerService getInstallerService() {
|
|
||||||
return is;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DownloadType getDownloadType() {
|
|
||||||
return Settings.getInstance().getDownloadSource();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.jackhuang.hellominecraft.C;
|
import org.jackhuang.hellominecraft.C;
|
||||||
import org.jackhuang.hellominecraft.HMCLog;
|
import org.jackhuang.hellominecraft.HMCLog;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftAssetService;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
||||||
import org.jackhuang.hellominecraft.tasks.Task;
|
import org.jackhuang.hellominecraft.tasks.Task;
|
||||||
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
||||||
@ -45,17 +46,17 @@ public class AssetsMojangLoader extends IAssetsHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Observable<String[]> getList(MinecraftVersion mv, IMinecraftProvider mp) {
|
public Observable<String[]> getList(MinecraftVersion mv, IMinecraftAssetService mp) {
|
||||||
return Observable.<String[]>createWithEmptySubscription((Observer<String[]> t1) -> {
|
return Observable.<String[]>createWithEmptySubscription((Observer<String[]> t1) -> {
|
||||||
if (mv == null) {
|
if (mv == null) {
|
||||||
t1.onError(null);
|
t1.onError(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String assetsId = mv.assets == null ? "legacy" : mv.assets;
|
String assetsId = mv.assets == null ? "legacy" : mv.assets;
|
||||||
File assets = mp.getAssetService().getAssets();
|
File assets = mp.getAssets();
|
||||||
HMCLog.log("Get index: " + assetsId);
|
HMCLog.log("Get index: " + assetsId);
|
||||||
File f = IOUtils.tryGetCanonicalFile(new File(assets, "indexes/" + assetsId + ".json"));
|
File f = IOUtils.tryGetCanonicalFile(new File(assets, "indexes/" + assetsId + ".json"));
|
||||||
if (!f.exists() && !mp.getAssetService().downloadMinecraftAssetsIndex(assetsId)) {
|
if (!f.exists() && !mp.downloadMinecraftAssetsIndex(assetsId)) {
|
||||||
t1.onError(null);
|
t1.onError(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,11 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.jackhuang.hellominecraft.C;
|
import org.jackhuang.hellominecraft.C;
|
||||||
import org.jackhuang.hellominecraft.HMCLog;
|
import org.jackhuang.hellominecraft.HMCLog;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftAssetService;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.download.IDownloadProvider;
|
import org.jackhuang.hellominecraft.launcher.utils.download.IDownloadProvider;
|
||||||
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
||||||
import org.jackhuang.hellominecraft.tasks.Task;
|
import org.jackhuang.hellominecraft.tasks.Task;
|
||||||
import org.jackhuang.hellominecraft.tasks.download.FileDownloadTask;
|
import org.jackhuang.hellominecraft.tasks.download.FileDownloadTask;
|
||||||
import org.jackhuang.hellominecraft.utils.functions.Consumer;
|
|
||||||
import org.jackhuang.hellominecraft.utils.code.DigestUtils;
|
import org.jackhuang.hellominecraft.utils.code.DigestUtils;
|
||||||
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
||||||
import org.jackhuang.hellominecraft.utils.NetUtils;
|
import org.jackhuang.hellominecraft.utils.NetUtils;
|
||||||
@ -71,10 +70,10 @@ public abstract class IAssetsHandler {
|
|||||||
* All the files assets needed
|
* All the files assets needed
|
||||||
*
|
*
|
||||||
* @param mv The version that needs assets
|
* @param mv The version that needs assets
|
||||||
* @param mp The Minecraft Provider
|
* @param mp Asset Service
|
||||||
* @param x finished event
|
* @param x finished event
|
||||||
*/
|
*/
|
||||||
public abstract Observable<String[]> getList(MinecraftVersion mv, IMinecraftProvider mp);
|
public abstract Observable<String[]> getList(MinecraftVersion mv, IMinecraftAssetService mp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will be invoked when the user invoked "Download all assets".
|
* Will be invoked when the user invoked "Download all assets".
|
||||||
|
@ -17,8 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hellominecraft.launcher.utils.installers;
|
package org.jackhuang.hellominecraft.launcher.utils.installers;
|
||||||
|
|
||||||
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftInstallerService;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftBasicService;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftService;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList.InstallerVersion;
|
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList.InstallerVersion;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.installers.forge.ForgeInstaller;
|
import org.jackhuang.hellominecraft.launcher.utils.installers.forge.ForgeInstaller;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.installers.liteloader.LiteLoaderInstaller;
|
import org.jackhuang.hellominecraft.launcher.utils.installers.liteloader.LiteLoaderInstaller;
|
||||||
@ -35,14 +37,13 @@ import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
|||||||
*
|
*
|
||||||
* @author huangyuhui
|
* @author huangyuhui
|
||||||
*/
|
*/
|
||||||
public final class InstallerService {
|
public final class MinecraftInstallerService extends IMinecraftInstallerService {
|
||||||
|
|
||||||
Profile p;
|
public MinecraftInstallerService(IMinecraftService service) {
|
||||||
|
super(service);
|
||||||
public InstallerService(Profile p) {
|
|
||||||
this.p = p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Task download(InstallerVersion v, InstallerType type) {
|
public Task download(InstallerVersion v, InstallerType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Forge:
|
case Forge:
|
||||||
@ -56,6 +57,7 @@ public final class InstallerService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Task downloadForge(InstallerVersion v) {
|
public Task downloadForge(InstallerVersion v) {
|
||||||
return new TaskInfo("Forge Downloader") {
|
return new TaskInfo("Forge Downloader") {
|
||||||
@Override
|
@Override
|
||||||
@ -63,13 +65,14 @@ public final class InstallerService {
|
|||||||
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "forge-installer.jar");
|
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "forge-installer.jar");
|
||||||
if (v.installer != null)
|
if (v.installer != null)
|
||||||
TaskWindow.getInstance()
|
TaskWindow.getInstance()
|
||||||
.addTask(new FileDownloadTask(p.getDownloadType().getProvider().getParsedLibraryDownloadURL(v.installer), filepath).setTag("forge"))
|
.addTask(new FileDownloadTask(service.getDownloadType().getProvider().getParsedLibraryDownloadURL(v.installer), filepath).setTag("forge"))
|
||||||
.addTask(new ForgeInstaller(p.getMinecraftProvider(), filepath, v))
|
.addTask(new ForgeInstaller(service, filepath, v))
|
||||||
.start();
|
.start();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Task downloadOptifine(InstallerVersion v) {
|
public Task downloadOptifine(InstallerVersion v) {
|
||||||
return new TaskInfo("OptiFine Downloader") {
|
return new TaskInfo("OptiFine Downloader") {
|
||||||
@Override
|
@Override
|
||||||
@ -79,13 +82,14 @@ public final class InstallerService {
|
|||||||
OptiFineDownloadFormatter task = new OptiFineDownloadFormatter(v.installer);
|
OptiFineDownloadFormatter task = new OptiFineDownloadFormatter(v.installer);
|
||||||
TaskWindow.getInstance().addTask(task)
|
TaskWindow.getInstance().addTask(task)
|
||||||
.addTask(new FileDownloadTask(filepath).registerPreviousResult(task).setTag("optifine"))
|
.addTask(new FileDownloadTask(filepath).registerPreviousResult(task).setTag("optifine"))
|
||||||
.addTask(new OptiFineInstaller(p, v.selfVersion, filepath))
|
.addTask(new OptiFineInstaller(service, v.selfVersion, filepath))
|
||||||
.start();
|
.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Task downloadLiteLoader(InstallerVersion v) {
|
public Task downloadLiteLoader(InstallerVersion v) {
|
||||||
return new TaskInfo("LiteLoader Downloader") {
|
return new TaskInfo("LiteLoader Downloader") {
|
||||||
@Override
|
@Override
|
||||||
@ -93,7 +97,7 @@ public final class InstallerService {
|
|||||||
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "liteloader-universal.jar");
|
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "liteloader-universal.jar");
|
||||||
FileDownloadTask task = (FileDownloadTask) new FileDownloadTask(v.universal, filepath).setTag("LiteLoader");
|
FileDownloadTask task = (FileDownloadTask) new FileDownloadTask(v.universal, filepath).setTag("LiteLoader");
|
||||||
TaskWindow.getInstance()
|
TaskWindow.getInstance()
|
||||||
.addTask(task).addTask(new LiteLoaderInstaller(p, (LiteLoaderVersionList.LiteLoaderInstallerVersion) v).registerPreviousResult(task))
|
.addTask(task).addTask(new LiteLoaderInstaller(service, (LiteLoaderVersionList.LiteLoaderInstallerVersion) v).registerPreviousResult(task))
|
||||||
.start();
|
.start();
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -26,7 +26,7 @@ import java.util.zip.ZipEntry;
|
|||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
import org.jackhuang.hellominecraft.C;
|
import org.jackhuang.hellominecraft.C;
|
||||||
import org.jackhuang.hellominecraft.HMCLog;
|
import org.jackhuang.hellominecraft.HMCLog;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftService;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList.InstallerVersion;
|
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList.InstallerVersion;
|
||||||
import org.jackhuang.hellominecraft.tasks.Task;
|
import org.jackhuang.hellominecraft.tasks.Task;
|
||||||
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
||||||
@ -42,11 +42,11 @@ public class ForgeInstaller extends Task {
|
|||||||
|
|
||||||
public File gameDir;
|
public File gameDir;
|
||||||
public File forgeInstaller;
|
public File forgeInstaller;
|
||||||
public IMinecraftProvider mp;
|
public IMinecraftService mp;
|
||||||
public InstallerVersion installerVersion;
|
public InstallerVersion installerVersion;
|
||||||
|
|
||||||
public ForgeInstaller(IMinecraftProvider mp, File forgeInstaller, InstallerVersion installerVersion) {
|
public ForgeInstaller(IMinecraftService mp, File forgeInstaller, InstallerVersion installerVersion) {
|
||||||
this.gameDir = mp.getBaseFolder();
|
this.gameDir = mp.baseFolder;
|
||||||
this.forgeInstaller = forgeInstaller;
|
this.forgeInstaller = forgeInstaller;
|
||||||
this.mp = mp;
|
this.mp = mp;
|
||||||
this.installerVersion = installerVersion;
|
this.installerVersion = installerVersion;
|
||||||
@ -64,7 +64,7 @@ public class ForgeInstaller extends Task {
|
|||||||
File from = new File(gameDir, "versions" + File.separator + profile.install.minecraft);
|
File from = new File(gameDir, "versions" + File.separator + profile.install.minecraft);
|
||||||
if (!from.exists())
|
if (!from.exists())
|
||||||
if (MessageBox.Show(C.i18n("install.no_version_if_intall")) == MessageBox.YES_OPTION) {
|
if (MessageBox.Show(C.i18n("install.no_version_if_intall")) == MessageBox.YES_OPTION) {
|
||||||
if (!mp.getDownloadService().install(profile.install.minecraft))
|
if (!mp.version().install(profile.install.minecraft))
|
||||||
throw new IllegalStateException(C.i18n("install.no_version"));
|
throw new IllegalStateException(C.i18n("install.no_version"));
|
||||||
} else
|
} else
|
||||||
throw new IllegalStateException(C.i18n("install.no_version"));
|
throw new IllegalStateException(C.i18n("install.no_version"));
|
||||||
|
@ -22,10 +22,10 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import org.jackhuang.hellominecraft.C;
|
import org.jackhuang.hellominecraft.C;
|
||||||
import org.jackhuang.hellominecraft.HMCLog;
|
import org.jackhuang.hellominecraft.HMCLog;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftService;
|
||||||
import org.jackhuang.hellominecraft.tasks.Task;
|
import org.jackhuang.hellominecraft.tasks.Task;
|
||||||
import org.jackhuang.hellominecraft.tasks.communication.PreviousResult;
|
import org.jackhuang.hellominecraft.tasks.communication.PreviousResult;
|
||||||
import org.jackhuang.hellominecraft.tasks.communication.PreviousResultRegistrar;
|
import org.jackhuang.hellominecraft.tasks.communication.PreviousResultRegistrar;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
|
||||||
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
||||||
import org.jackhuang.hellominecraft.launcher.version.MinecraftLibrary;
|
import org.jackhuang.hellominecraft.launcher.version.MinecraftLibrary;
|
||||||
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
||||||
@ -38,27 +38,27 @@ public class LiteLoaderInstaller extends Task implements PreviousResultRegistrar
|
|||||||
|
|
||||||
public LiteLoaderVersionList.LiteLoaderInstallerVersion version;
|
public LiteLoaderVersionList.LiteLoaderInstallerVersion version;
|
||||||
public File installer;
|
public File installer;
|
||||||
public Profile profile;
|
public IMinecraftService service;
|
||||||
|
|
||||||
public LiteLoaderInstaller(Profile profile, LiteLoaderVersionList.LiteLoaderInstallerVersion v) {
|
public LiteLoaderInstaller(IMinecraftService service, LiteLoaderVersionList.LiteLoaderInstallerVersion v) {
|
||||||
this(profile, v, null);
|
this(service, v, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiteLoaderInstaller(Profile profile, LiteLoaderVersionList.LiteLoaderInstallerVersion v, File installer) {
|
public LiteLoaderInstaller(IMinecraftService service, LiteLoaderVersionList.LiteLoaderInstallerVersion v, File installer) {
|
||||||
this.profile = profile;
|
this.service = service;
|
||||||
this.version = v;
|
this.version = v;
|
||||||
this.installer = installer;
|
this.installer = installer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executeTask() throws Exception {
|
public void executeTask() throws Exception {
|
||||||
if (profile == null || profile.getMinecraftProvider().getSelectedVersion() == null)
|
if (service.version().getSelectedVersion() == null)
|
||||||
throw new IllegalStateException(C.i18n("install.no_version"));
|
throw new IllegalStateException(C.i18n("install.no_version"));
|
||||||
if (pre.size() != 1 && installer == null)
|
if (pre.size() != 1 && installer == null)
|
||||||
throw new IllegalStateException("No registered previous task.");
|
throw new IllegalStateException("No registered previous task.");
|
||||||
if (installer == null)
|
if (installer == null)
|
||||||
installer = pre.get(pre.size() - 1).getResult();
|
installer = pre.get(pre.size() - 1).getResult();
|
||||||
MinecraftVersion mv = (MinecraftVersion) profile.getMinecraftProvider().getSelectedVersion().clone();
|
MinecraftVersion mv = (MinecraftVersion) service.version().getSelectedVersion().clone();
|
||||||
mv.inheritsFrom = mv.id;
|
mv.inheritsFrom = mv.id;
|
||||||
mv.jar = mv.jar == null ? mv.id : mv.jar;
|
mv.jar = mv.jar == null ? mv.id : mv.jar;
|
||||||
mv.libraries = new ArrayList(Arrays.asList(version.libraries));
|
mv.libraries = new ArrayList(Arrays.asList(version.libraries));
|
||||||
@ -66,13 +66,13 @@ public class LiteLoaderInstaller extends Task implements PreviousResultRegistrar
|
|||||||
MinecraftLibrary ml = new MinecraftLibrary("com.mumfrey:liteloader:" + version.selfVersion);
|
MinecraftLibrary ml = new MinecraftLibrary("com.mumfrey:liteloader:" + version.selfVersion);
|
||||||
//ml.url = "http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + version.mcVersion + "/liteloader-" + version.selfVersion + ".jar";
|
//ml.url = "http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + version.mcVersion + "/liteloader-" + version.selfVersion + ".jar";
|
||||||
mv.libraries.add(0, ml);
|
mv.libraries.add(0, ml);
|
||||||
FileUtils.copyFile(installer, new File(profile.getCanonicalGameDir(), "libraries/com/mumfrey/liteloader/" + version.selfVersion + "/liteloader-" + version.selfVersion + ".jar"));
|
FileUtils.copyFile(installer, new File(service.baseFolder, "libraries/com/mumfrey/liteloader/" + version.selfVersion + "/liteloader-" + version.selfVersion + ".jar"));
|
||||||
|
|
||||||
mv.id += "-LiteLoader" + version.selfVersion;
|
mv.id += "-LiteLoader" + version.selfVersion;
|
||||||
|
|
||||||
mv.mainClass = "net.minecraft.launchwrapper.Launch";
|
mv.mainClass = "net.minecraft.launchwrapper.Launch";
|
||||||
mv.minecraftArguments += " --tweakClass " + version.tweakClass;
|
mv.minecraftArguments += " --tweakClass " + version.tweakClass;
|
||||||
File folder = new File(profile.getCanonicalGameDir(), "versions/" + mv.id);
|
File folder = new File(service.baseFolder, "versions/" + mv.id);
|
||||||
folder.mkdirs();
|
folder.mkdirs();
|
||||||
File json = new File(folder, mv.id + ".json");
|
File json = new File(folder, mv.id + ".json");
|
||||||
HMCLog.log("Creating new version profile..." + mv.id + ".json");
|
HMCLog.log("Creating new version profile..." + mv.id + ".json");
|
||||||
|
@ -21,7 +21,7 @@ import java.io.File;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
import org.jackhuang.hellominecraft.C;
|
import org.jackhuang.hellominecraft.C;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftService;
|
||||||
import org.jackhuang.hellominecraft.tasks.Task;
|
import org.jackhuang.hellominecraft.tasks.Task;
|
||||||
import org.jackhuang.hellominecraft.tasks.communication.PreviousResult;
|
import org.jackhuang.hellominecraft.tasks.communication.PreviousResult;
|
||||||
import org.jackhuang.hellominecraft.tasks.communication.PreviousResultRegistrar;
|
import org.jackhuang.hellominecraft.tasks.communication.PreviousResultRegistrar;
|
||||||
@ -36,29 +36,29 @@ import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
|||||||
public class OptiFineInstaller extends Task implements PreviousResultRegistrar<File> {
|
public class OptiFineInstaller extends Task implements PreviousResultRegistrar<File> {
|
||||||
|
|
||||||
public File installer;
|
public File installer;
|
||||||
public Profile profile;
|
public IMinecraftService service;
|
||||||
public String version;
|
public String version;
|
||||||
|
|
||||||
public OptiFineInstaller(Profile profile, String version) {
|
public OptiFineInstaller(IMinecraftService service, String version) {
|
||||||
this(profile, version, null);
|
this(service, version, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OptiFineInstaller(Profile profile, String version, File installer) {
|
public OptiFineInstaller(IMinecraftService service, String version, File installer) {
|
||||||
this.profile = profile;
|
this.service = service;
|
||||||
this.installer = installer;
|
this.installer = installer;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executeTask() throws Exception {
|
public void executeTask() throws Exception {
|
||||||
if (profile == null || profile.getMinecraftProvider().getSelectedVersion() == null)
|
if (service.version().getSelectedVersion() == null)
|
||||||
throw new Exception(C.i18n("install.no_version"));
|
throw new Exception(C.i18n("install.no_version"));
|
||||||
MinecraftVersion mv = (MinecraftVersion) profile.getMinecraftProvider().getSelectedVersion().clone();
|
MinecraftVersion mv = (MinecraftVersion) service.version().getSelectedVersion().clone();
|
||||||
mv.inheritsFrom = mv.id;
|
mv.inheritsFrom = mv.id;
|
||||||
mv.jar = mv.jar == null ? mv.id : mv.jar;
|
mv.jar = mv.jar == null ? mv.id : mv.jar;
|
||||||
mv.libraries.clear();
|
mv.libraries.clear();
|
||||||
mv.libraries.add(0, new MinecraftLibrary("optifine:OptiFine:" + version));
|
mv.libraries.add(0, new MinecraftLibrary("optifine:OptiFine:" + version));
|
||||||
FileUtils.copyFile(installer, new File(profile.getCanonicalGameDir(), "libraries/optifine/OptiFine/" + version + "/OptiFine-" + version + ".jar"));
|
FileUtils.copyFile(installer, new File(service.baseFolder, "libraries/optifine/OptiFine/" + version + "/OptiFine-" + version + ".jar"));
|
||||||
|
|
||||||
mv.id += "-" + version;
|
mv.id += "-" + version;
|
||||||
if (new ZipFile(installer).getEntry("optifine/OptiFineTweaker.class") != null) {
|
if (new ZipFile(installer).getEntry("optifine/OptiFineTweaker.class") != null) {
|
||||||
@ -68,7 +68,7 @@ public class OptiFineInstaller extends Task implements PreviousResultRegistrar<F
|
|||||||
}
|
}
|
||||||
mv.minecraftArguments += " --tweakClass optifine.OptiFineTweaker";
|
mv.minecraftArguments += " --tweakClass optifine.OptiFineTweaker";
|
||||||
}
|
}
|
||||||
File loc = new File(profile.getCanonicalGameDir(), "versions/" + mv.id);
|
File loc = new File(service.baseFolder, "versions/" + mv.id);
|
||||||
loc.mkdirs();
|
loc.mkdirs();
|
||||||
File json = new File(loc, mv.id + ".json");
|
File json = new File(loc, mv.id + ".json");
|
||||||
FileUtils.writeStringToFile(json, C.gsonPrettyPrinting.toJson(mv, MinecraftVersion.class));
|
FileUtils.writeStringToFile(json, C.gsonPrettyPrinting.toJson(mv, MinecraftVersion.class));
|
||||||
|
@ -22,7 +22,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.jackhuang.hellominecraft.C;
|
import org.jackhuang.hellominecraft.C;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftAssetService;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftAssetService;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftService;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.assets.AssetsIndex;
|
import org.jackhuang.hellominecraft.launcher.utils.assets.AssetsIndex;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.assets.AssetsObject;
|
import org.jackhuang.hellominecraft.launcher.utils.assets.AssetsObject;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.assets.IAssetsHandler;
|
import org.jackhuang.hellominecraft.launcher.utils.assets.IAssetsHandler;
|
||||||
@ -39,12 +39,8 @@ import rx.concurrency.Schedulers;
|
|||||||
*/
|
*/
|
||||||
public class MinecraftAssetService extends IMinecraftAssetService {
|
public class MinecraftAssetService extends IMinecraftAssetService {
|
||||||
|
|
||||||
MinecraftVersionManager mgr;
|
public MinecraftAssetService(IMinecraftService profile) {
|
||||||
|
|
||||||
public MinecraftAssetService(Profile profile, MinecraftVersionManager mvm) {
|
|
||||||
super(profile);
|
super(profile);
|
||||||
|
|
||||||
mgr = mvm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -54,10 +50,10 @@ public class MinecraftAssetService extends IMinecraftAssetService {
|
|||||||
@Override
|
@Override
|
||||||
public void executeTask() throws Throwable {
|
public void executeTask() throws Throwable {
|
||||||
IAssetsHandler type = IAssetsHandler.ASSETS_HANDLER;
|
IAssetsHandler type = IAssetsHandler.ASSETS_HANDLER;
|
||||||
type.getList(profile.getMinecraftProvider().getVersionById(mcVersion), profile.getMinecraftProvider())
|
type.getList(service.version().getVersionById(mcVersion), service.asset())
|
||||||
.subscribeOn(Schedulers.newThread())
|
.subscribeOn(Schedulers.newThread())
|
||||||
.observeOn(Schedulers.eventQueue())
|
.observeOn(Schedulers.eventQueue())
|
||||||
.subscribe((value) -> TaskWindow.getInstance().addTask(type.getDownloadTask(profile.getDownloadType().getProvider())).start());
|
.subscribe((t) -> TaskWindow.getInstance().addTask(type.getDownloadTask(service.getDownloadType().getProvider())).start());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -69,7 +65,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean refreshAssetsIndex(String id) {
|
public boolean refreshAssetsIndex(String id) {
|
||||||
MinecraftVersion mv = mgr.getVersionById(id);
|
MinecraftVersion mv = service.version().getVersionById(id);
|
||||||
if (mv == null)
|
if (mv == null)
|
||||||
return false;
|
return false;
|
||||||
return downloadMinecraftAssetsIndex(mv.assets);
|
return downloadMinecraftAssetsIndex(mv.assets);
|
||||||
@ -77,7 +73,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean downloadMinecraftAssetsIndex(String assetsId) {
|
public boolean downloadMinecraftAssetsIndex(String assetsId) {
|
||||||
String aurl = profile.getDownloadType().getProvider().getIndexesDownloadURL();
|
String aurl = service.getDownloadType().getProvider().getIndexesDownloadURL();
|
||||||
|
|
||||||
File assetsLocation = getAssets();
|
File assetsLocation = getAssets();
|
||||||
assetsLocation.mkdirs();
|
assetsLocation.mkdirs();
|
||||||
@ -101,7 +97,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getAssets() {
|
public File getAssets() {
|
||||||
return new File(profile.getCanonicalGameDirFile(), "assets");
|
return new File(service.profile.getCanonicalGameDirFile(), "assets");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -24,8 +24,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.jackhuang.hellominecraft.C;
|
import org.jackhuang.hellominecraft.C;
|
||||||
import org.jackhuang.hellominecraft.HMCLog;
|
import org.jackhuang.hellominecraft.HMCLog;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.launch.GameException;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.GameLauncher;
|
import org.jackhuang.hellominecraft.launcher.launch.GameLauncher;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftService;
|
||||||
import org.jackhuang.hellominecraft.tasks.TaskWindow;
|
import org.jackhuang.hellominecraft.tasks.TaskWindow;
|
||||||
import org.jackhuang.hellominecraft.tasks.download.FileDownloadTask;
|
import org.jackhuang.hellominecraft.tasks.download.FileDownloadTask;
|
||||||
import org.jackhuang.hellominecraft.utils.NetUtils;
|
import org.jackhuang.hellominecraft.utils.NetUtils;
|
||||||
@ -41,27 +42,24 @@ import rx.Observable;
|
|||||||
*/
|
*/
|
||||||
public class MinecraftDownloadService extends IMinecraftDownloadService {
|
public class MinecraftDownloadService extends IMinecraftDownloadService {
|
||||||
|
|
||||||
MinecraftVersionManager mgr;
|
public MinecraftDownloadService(IMinecraftService profile) {
|
||||||
|
super(profile);
|
||||||
public MinecraftDownloadService(Profile p, MinecraftVersionManager mgr) {
|
|
||||||
super(p);
|
|
||||||
this.mgr = mgr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GameLauncher.DownloadLibraryJob> getDownloadLibraries() {
|
public List<GameLauncher.DownloadLibraryJob> getDownloadLibraries(MinecraftVersion mv) throws GameException {
|
||||||
ArrayList<GameLauncher.DownloadLibraryJob> downloadLibraries = new ArrayList<>();
|
ArrayList<GameLauncher.DownloadLibraryJob> downloadLibraries = new ArrayList<>();
|
||||||
if (mgr.getSelectedVersion() == null)
|
if (mv == null)
|
||||||
return downloadLibraries;
|
return downloadLibraries;
|
||||||
MinecraftVersion v = mgr.getSelectedVersion().resolve(mgr);
|
MinecraftVersion v = mv.resolve(service.version());
|
||||||
if (v.libraries != null)
|
if (v.libraries != null)
|
||||||
for (IMinecraftLibrary l : v.libraries) {
|
for (IMinecraftLibrary l : v.libraries) {
|
||||||
l.init();
|
l.init();
|
||||||
if (l.allow()) {
|
if (l.allow()) {
|
||||||
File ff = l.getFilePath(profile.getCanonicalGameDirFile());
|
File ff = l.getFilePath(service.baseFolder);
|
||||||
if (!ff.exists()) {
|
if (!ff.exists()) {
|
||||||
String libURL = profile.getDownloadType().getProvider().getLibraryDownloadURL() + "/";
|
String libURL = service.getDownloadType().getProvider().getLibraryDownloadURL() + "/";
|
||||||
libURL = profile.getDownloadType().getProvider().getParsedLibraryDownloadURL(l.getDownloadURL(libURL, profile.getDownloadType()));
|
libURL = service.getDownloadType().getProvider().getParsedLibraryDownloadURL(l.getDownloadURL(libURL, service.getDownloadType()));
|
||||||
if (libURL != null)
|
if (libURL != null)
|
||||||
downloadLibraries.add(new GameLauncher.DownloadLibraryJob(l.name, libURL, ff));
|
downloadLibraries.add(new GameLauncher.DownloadLibraryJob(l.name, libURL, ff));
|
||||||
}
|
}
|
||||||
@ -70,20 +68,10 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
|
|||||||
return downloadLibraries;
|
return downloadLibraries;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean install(String id) {
|
|
||||||
MinecraftVersion v = downloadMinecraft(id);
|
|
||||||
if (v != null) {
|
|
||||||
mgr.versions.put(v.id, v);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MinecraftVersion downloadMinecraft(String id) {
|
public MinecraftVersion downloadMinecraft(String id) {
|
||||||
String vurl = profile.getDownloadType().getProvider().getVersionsDownloadURL() + id + "/";
|
String vurl = service.getDownloadType().getProvider().getVersionsDownloadURL() + id + "/";
|
||||||
File vpath = new File(profile.getCanonicalGameDirFile(), "versions/" + id);
|
File vpath = new File(service.baseFolder, "versions/" + id);
|
||||||
File mvt = new File(vpath, id + ".json");
|
File mvt = new File(vpath, id + ".json");
|
||||||
File mvj = new File(vpath, id + ".jar");
|
File mvj = new File(vpath, id + ".jar");
|
||||||
vpath.mkdirs();
|
vpath.mkdirs();
|
||||||
@ -106,8 +94,8 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean downloadMinecraftJar(String id) {
|
public boolean downloadMinecraftJar(String id) {
|
||||||
String vurl = profile.getDownloadType().getProvider().getVersionsDownloadURL() + id + "/";
|
String vurl = service.getDownloadType().getProvider().getVersionsDownloadURL() + id + "/";
|
||||||
File vpath = new File(profile.getCanonicalGameDirFile(), "versions/" + id);
|
File vpath = new File(service.baseFolder, "versions/" + id);
|
||||||
File mvv = new File(vpath, id + ".jar"), moved = null;
|
File mvv = new File(vpath, id + ".jar"), moved = null;
|
||||||
if (mvv.exists()) {
|
if (mvv.exists()) {
|
||||||
moved = new File(vpath, id + "-renamed.jar");
|
moved = new File(vpath, id + "-renamed.jar");
|
||||||
@ -131,8 +119,8 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean downloadMinecraftVersionJson(String id) {
|
public boolean downloadMinecraftVersionJson(String id) {
|
||||||
String vurl = profile.getDownloadType().getProvider().getVersionsDownloadURL() + id + "/";
|
String vurl = service.getDownloadType().getProvider().getVersionsDownloadURL() + id + "/";
|
||||||
File vpath = new File(profile.getCanonicalGameDirFile(), "versions/" + id);
|
File vpath = new File(service.baseFolder, "versions/" + id);
|
||||||
File mvv = new File(vpath, id + ".json"), moved = null;
|
File mvv = new File(vpath, id + ".json"), moved = null;
|
||||||
if (mvv.exists()) {
|
if (mvv.exists()) {
|
||||||
moved = new File(vpath, id + "-renamed.json");
|
moved = new File(vpath, id + "-renamed.json");
|
||||||
@ -156,7 +144,7 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Observable<MinecraftRemoteVersion> getRemoteVersions() {
|
public Observable<MinecraftRemoteVersion> getRemoteVersions() {
|
||||||
return NetUtils.getRx(profile.getDownloadType().getProvider().getVersionsListDownloadURL())
|
return NetUtils.getRx(service.getDownloadType().getProvider().getVersionsListDownloadURL())
|
||||||
.map(r -> C.gson.fromJson(r, MinecraftRemoteVersions.class))
|
.map(r -> C.gson.fromJson(r, MinecraftRemoteVersions.class))
|
||||||
.filter(r -> r != null && r.versions != null)
|
.filter(r -> r != null && r.versions != null)
|
||||||
.flatMap(r -> Observable.from(r.versions));
|
.flatMap(r -> Observable.from(r.versions));
|
||||||
|
@ -25,7 +25,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.jackhuang.hellominecraft.HMCLog;
|
import org.jackhuang.hellominecraft.HMCLog;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftModService;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftModService;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftService;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.ModInfo;
|
import org.jackhuang.hellominecraft.launcher.utils.ModInfo;
|
||||||
import org.jackhuang.hellominecraft.utils.code.DigestUtils;
|
import org.jackhuang.hellominecraft.utils.code.DigestUtils;
|
||||||
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
||||||
@ -36,15 +36,12 @@ import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
|||||||
*/
|
*/
|
||||||
public class MinecraftModService extends IMinecraftModService {
|
public class MinecraftModService extends IMinecraftModService {
|
||||||
|
|
||||||
MinecraftVersionManager mgr;
|
|
||||||
|
|
||||||
public MinecraftModService(Profile p, MinecraftVersionManager mgr) {
|
|
||||||
super(p);
|
|
||||||
this.mgr = mgr;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ModInfo> modCache;
|
List<ModInfo> modCache;
|
||||||
|
|
||||||
|
public MinecraftModService(IMinecraftService profile) {
|
||||||
|
super(profile);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ModInfo> getMods() {
|
public List<ModInfo> getMods() {
|
||||||
if (modCache == null)
|
if (modCache == null)
|
||||||
@ -55,9 +52,9 @@ public class MinecraftModService extends IMinecraftModService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ModInfo> recacheMods() {
|
public List<ModInfo> recacheMods() {
|
||||||
if (mgr.getSelectedVersion() == null)
|
if (service.version().getSelectedVersion() == null)
|
||||||
return modCache = new ArrayList<>();
|
return modCache = new ArrayList<>();
|
||||||
File modsFolder = mgr.getRunDirectory(mgr.getSelectedVersion().id, "mods");
|
File modsFolder = service.version().getRunDirectory(service.version().getSelectedVersion().id, "mods");
|
||||||
ArrayList<ModInfo> mods = new ArrayList<>();
|
ArrayList<ModInfo> mods = new ArrayList<>();
|
||||||
File[] fs = modsFolder.listFiles();
|
File[] fs = modsFolder.listFiles();
|
||||||
if (fs != null)
|
if (fs != null)
|
||||||
@ -83,11 +80,11 @@ public class MinecraftModService extends IMinecraftModService {
|
|||||||
@Override
|
@Override
|
||||||
public boolean addMod(File f) {
|
public boolean addMod(File f) {
|
||||||
try {
|
try {
|
||||||
if (mgr.getSelectedVersion() == null)
|
if (service.version().getSelectedVersion() == null)
|
||||||
return false;
|
return false;
|
||||||
if (!ModInfo.isFileMod(f))
|
if (!ModInfo.isFileMod(f))
|
||||||
return false;
|
return false;
|
||||||
File modsFolder = mgr.getRunDirectory(mgr.getSelectedVersion().id, "mods");
|
File modsFolder = service.version().getRunDirectory(service.version().getSelectedVersion().id, "mods");
|
||||||
if (modsFolder == null)
|
if (modsFolder == null)
|
||||||
return false;
|
return false;
|
||||||
modsFolder.mkdirs();
|
modsFolder.mkdirs();
|
||||||
|
@ -72,23 +72,23 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
|
|||||||
return new MinecraftVersion(minecraftArguments, mainClass, time, id, type, processArguments, releaseTime, assets, jar, inheritsFrom, minimumLauncherVersion, libraries, hidden);
|
return new MinecraftVersion(minecraftArguments, mainClass, time, id, type, processArguments, releaseTime, assets, jar, inheritsFrom, minimumLauncherVersion, libraries, hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MinecraftVersion resolve(IMinecraftProvider manager) throws GameException {
|
public MinecraftVersion resolve(IMinecraftProvider provider) throws GameException {
|
||||||
return resolve(manager, new HashSet<>());
|
return resolve(provider, new HashSet<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MinecraftVersion resolve(IMinecraftProvider manager, Set<String> resolvedSoFar) throws GameException {
|
protected MinecraftVersion resolve(IMinecraftProvider provider, Set<String> resolvedSoFar) throws GameException {
|
||||||
if (inheritsFrom == null)
|
if (inheritsFrom == null)
|
||||||
return this;
|
return this;
|
||||||
if (!resolvedSoFar.add(id))
|
if (!resolvedSoFar.add(id))
|
||||||
throw new GameException(C.i18n("launch.circular_dependency_versions"));
|
throw new GameException(C.i18n("launch.circular_dependency_versions"));
|
||||||
|
|
||||||
MinecraftVersion parent = manager.getVersionById(inheritsFrom);
|
MinecraftVersion parent = provider.getVersionById(inheritsFrom);
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
if (!manager.getDownloadService().install(inheritsFrom))
|
if (!provider.install(inheritsFrom))
|
||||||
return this;
|
return this;
|
||||||
parent = manager.getVersionById(inheritsFrom);
|
parent = provider.getVersionById(inheritsFrom);
|
||||||
}
|
}
|
||||||
parent = parent.resolve(manager, resolvedSoFar);
|
parent = parent.resolve(provider, resolvedSoFar);
|
||||||
MinecraftVersion result = new MinecraftVersion(
|
MinecraftVersion result = new MinecraftVersion(
|
||||||
this.minecraftArguments != null ? this.minecraftArguments : parent.minecraftArguments,
|
this.minecraftArguments != null ? this.minecraftArguments : parent.minecraftArguments,
|
||||||
this.mainClass != null ? this.mainClass : parent.mainClass,
|
this.mainClass != null ? this.mainClass : parent.mainClass,
|
||||||
|
@ -28,16 +28,13 @@ import org.jackhuang.hellominecraft.C;
|
|||||||
import org.jackhuang.hellominecraft.HMCLog;
|
import org.jackhuang.hellominecraft.HMCLog;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.GameException;
|
import org.jackhuang.hellominecraft.launcher.launch.GameException;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.GameLauncher;
|
import org.jackhuang.hellominecraft.launcher.launch.GameLauncher;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftAssetService;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftDownloadService;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftLoader;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftLoader;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftModService;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftService;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.MinecraftLoader;
|
import org.jackhuang.hellominecraft.launcher.launch.MinecraftLoader;
|
||||||
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.MCUtils;
|
import org.jackhuang.hellominecraft.launcher.utils.MCUtils;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
|
||||||
import org.jackhuang.hellominecraft.tasks.DecompressTask;
|
import org.jackhuang.hellominecraft.tasks.DecompressTask;
|
||||||
import org.jackhuang.hellominecraft.tasks.TaskWindow;
|
import org.jackhuang.hellominecraft.tasks.TaskWindow;
|
||||||
import org.jackhuang.hellominecraft.tasks.download.FileDownloadTask;
|
import org.jackhuang.hellominecraft.tasks.download.FileDownloadTask;
|
||||||
@ -58,11 +55,8 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
|||||||
*
|
*
|
||||||
* @param p
|
* @param p
|
||||||
*/
|
*/
|
||||||
public MinecraftVersionManager(Profile p) {
|
public MinecraftVersionManager(IMinecraftService p) {
|
||||||
super(p);
|
super(p);
|
||||||
mms = new MinecraftModService(p, this);
|
|
||||||
mds = new MinecraftDownloadService(p, this);
|
|
||||||
mas = new MinecraftAssetService(p, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getFolder() {
|
public File getFolder() {
|
||||||
@ -81,7 +75,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refreshVersions() {
|
public void refreshVersions() {
|
||||||
baseFolder = profile.getCanonicalGameDirFile();
|
baseFolder = service.profile.getCanonicalGameDirFile();
|
||||||
try {
|
try {
|
||||||
MCUtils.tryWriteProfile(baseFolder);
|
MCUtils.tryWriteProfile(baseFolder);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
@ -131,7 +125,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
|||||||
} catch (IOException | GameException e) {
|
} catch (IOException | GameException e) {
|
||||||
HMCLog.warn("Found wrong format json, try to fix it.", e);
|
HMCLog.warn("Found wrong format json, try to fix it.", e);
|
||||||
if (MessageBox.Show(C.i18n("launcher.versions_json_not_formatted", id), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
|
if (MessageBox.Show(C.i18n("launcher.versions_json_not_formatted", id), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
|
||||||
refreshJson(id);
|
service.download().downloadMinecraftVersionJson(id);
|
||||||
try {
|
try {
|
||||||
mcVersion = C.gson.fromJson(FileUtils.readFileToString(jsonFile), MinecraftVersion.class);
|
mcVersion = C.gson.fromJson(FileUtils.readFileToString(jsonFile), MinecraftVersion.class);
|
||||||
if (mcVersion == null)
|
if (mcVersion == null)
|
||||||
@ -194,7 +188,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getRunDirectory(String id) {
|
public File getRunDirectory(String id) {
|
||||||
switch (profile.getGameDirType()) {
|
switch (gameDirType) {
|
||||||
case VERSION_FOLDER:
|
case VERSION_FOLDER:
|
||||||
return new File(baseFolder, "versions/" + id + "/");
|
return new File(baseFolder, "versions/" + id + "/");
|
||||||
default:
|
default:
|
||||||
@ -202,6 +196,16 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean install(String id) {
|
||||||
|
MinecraftVersion v = service.download().downloadMinecraft(id);
|
||||||
|
if (v != null) {
|
||||||
|
refreshVersions();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void open(String mv, String name) {
|
public void open(String mv, String name) {
|
||||||
SwingUtils.openFolder((name == null) ? getRunDirectory(mv) : new File(getRunDirectory(mv), name));
|
SwingUtils.openFolder((name == null) ? getRunDirectory(mv) : new File(getRunDirectory(mv), name));
|
||||||
@ -225,7 +229,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getDecompressNativesToLocation(MinecraftVersion v) {
|
public File getDecompressNativesToLocation(MinecraftVersion v) {
|
||||||
return v == null ? null : v.getNatives(profile.getCanonicalGameDirFile());
|
return v == null ? null : v.getNatives(baseFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -236,7 +240,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
|||||||
@Override
|
@Override
|
||||||
public IMinecraftLoader provideMinecraftLoader(UserProfileProvider p)
|
public IMinecraftLoader provideMinecraftLoader(UserProfileProvider p)
|
||||||
throws GameException {
|
throws GameException {
|
||||||
return new MinecraftLoader(profile, this, p);
|
return new MinecraftLoader(service, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -251,7 +255,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getResourcePacks() {
|
public File getResourcePacks() {
|
||||||
return new File(profile.getCanonicalGameDirFile(), "resourcepacks");
|
return new File(baseFolder, "resourcepacks");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -270,7 +274,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
|||||||
@Override
|
@Override
|
||||||
public void cleanFolder() {
|
public void cleanFolder() {
|
||||||
for (MinecraftVersion s : getVersions()) {
|
for (MinecraftVersion s : getVersions()) {
|
||||||
FileUtils.deleteDirectoryQuietly(new File(profile.getGameDirFile(), "versions" + File.separator + s.id + File.separator + s.id + "-natives"));
|
FileUtils.deleteDirectoryQuietly(new File(baseFolder, "versions" + File.separator + s.id + File.separator + s.id + "-natives"));
|
||||||
File f = getRunDirectory(s.id);
|
File f = getRunDirectory(s.id);
|
||||||
String[] dir = { "logs", "asm", "NVIDIA", "crash-reports", "server-resource-packs", "natives", "native" };
|
String[] dir = { "logs", "asm", "NVIDIA", "crash-reports", "server-resource-packs", "natives", "native" };
|
||||||
for (String str : dir)
|
for (String str : dir)
|
||||||
@ -281,27 +285,6 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final MinecraftModService mms;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IMinecraftModService getModService() {
|
|
||||||
return mms;
|
|
||||||
}
|
|
||||||
|
|
||||||
final MinecraftDownloadService mds;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IMinecraftDownloadService getDownloadService() {
|
|
||||||
return mds;
|
|
||||||
}
|
|
||||||
|
|
||||||
final MinecraftAssetService mas;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IMinecraftAssetService getAssetService() {
|
|
||||||
return mas;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initializeMiencraft() {
|
public void initializeMiencraft() {
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ public class GameDownloadPanel extends AnimatedPanel implements Selectable {
|
|||||||
|
|
||||||
public void refreshDownloads() {
|
public void refreshDownloads() {
|
||||||
DefaultTableModel model = SwingUtils.clearDefaultTable(lstDownloads);
|
DefaultTableModel model = SwingUtils.clearDefaultTable(lstDownloads);
|
||||||
gsp.getProfile().getMinecraftProvider().getDownloadService().getRemoteVersions()
|
gsp.getProfile().service().download().getRemoteVersions()
|
||||||
.observeOn(Schedulers.eventQueue()).subscribeOn(Schedulers.newThread())
|
.observeOn(Schedulers.eventQueue()).subscribeOn(Schedulers.newThread())
|
||||||
.subscribe((ver) -> model.addRow(new Object[] { ver.id, ver.time,
|
.subscribe((ver) -> model.addRow(new Object[] { ver.id, ver.time,
|
||||||
StrUtils.equalsOne(ver.type, "old_beta", "old_alpha", "release", "snapshot") ? C.i18n("versions." + ver.type) : ver.type }),
|
StrUtils.equalsOne(ver.type, "old_beta", "old_alpha", "release", "snapshot") ? C.i18n("versions." + ver.type) : ver.type }),
|
||||||
@ -123,7 +123,7 @@ public class GameDownloadPanel extends AnimatedPanel implements Selectable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String id = (String) lstDownloads.getModel().getValueAt(lstDownloads.getSelectedRow(), 0);
|
String id = (String) lstDownloads.getModel().getValueAt(lstDownloads.getSelectedRow(), 0);
|
||||||
gsp.getProfile().getMinecraftProvider().getDownloadService().downloadMinecraft(id);
|
gsp.getProfile().service().download().downloadMinecraft(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
|
@ -109,7 +109,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
getProfile().getMinecraftProvider().open(mcVersion, a);
|
getProfile().service().version().open(mcVersion, a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JMenuItem itm;
|
JMenuItem itm;
|
||||||
@ -140,7 +140,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
|||||||
if (mcVersion != null) {
|
if (mcVersion != null) {
|
||||||
String newName = JOptionPane.showInputDialog(C.i18n("versions.manage.rename.message"), mcVersion);
|
String newName = JOptionPane.showInputDialog(C.i18n("versions.manage.rename.message"), mcVersion);
|
||||||
if (newName != null)
|
if (newName != null)
|
||||||
if (getProfile().getMinecraftProvider().renameVersion(mcVersion, newName))
|
if (getProfile().service().version().renameVersion(mcVersion, newName))
|
||||||
refreshVersions();
|
refreshVersions();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -148,20 +148,20 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
|||||||
itm = new JMenuItem(C.i18n("versions.manage.remove"));
|
itm = new JMenuItem(C.i18n("versions.manage.remove"));
|
||||||
itm.addActionListener((e) -> {
|
itm.addActionListener((e) -> {
|
||||||
if (mcVersion != null && MessageBox.Show(C.i18n("versions.manage.remove.confirm") + mcVersion, MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
|
if (mcVersion != null && MessageBox.Show(C.i18n("versions.manage.remove.confirm") + mcVersion, MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
|
||||||
if (getProfile().getMinecraftProvider().removeVersionFromDisk(mcVersion))
|
if (getProfile().service().version().removeVersionFromDisk(mcVersion))
|
||||||
refreshVersions();
|
refreshVersions();
|
||||||
});
|
});
|
||||||
ppmManage.add(itm);
|
ppmManage.add(itm);
|
||||||
itm = new JMenuItem(C.i18n("versions.manage.redownload_json"));
|
itm = new JMenuItem(C.i18n("versions.manage.redownload_json"));
|
||||||
itm.addActionListener((e) -> {
|
itm.addActionListener((e) -> {
|
||||||
if (mcVersion != null)
|
if (mcVersion != null)
|
||||||
getProfile().getMinecraftProvider().refreshJson(mcVersion);
|
getProfile().service().download().downloadMinecraftVersionJson(mcVersion);
|
||||||
});
|
});
|
||||||
ppmManage.add(itm);
|
ppmManage.add(itm);
|
||||||
itm = new JMenuItem(C.i18n("versions.manage.redownload_assets_index"));
|
itm = new JMenuItem(C.i18n("versions.manage.redownload_assets_index"));
|
||||||
itm.addActionListener((e) -> {
|
itm.addActionListener((e) -> {
|
||||||
if (mcVersion != null)
|
if (mcVersion != null)
|
||||||
getProfile().getMinecraftProvider().getAssetService().refreshAssetsIndex(mcVersion);
|
getProfile().service().asset().refreshAssetsIndex(mcVersion);
|
||||||
});
|
});
|
||||||
ppmManage.add(itm);
|
ppmManage.add(itm);
|
||||||
}
|
}
|
||||||
@ -174,7 +174,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
|||||||
}
|
}
|
||||||
lstExternalMods.getSelectionModel().addListSelectionListener(e -> {
|
lstExternalMods.getSelectionModel().addListSelectionListener(e -> {
|
||||||
int row = lstExternalMods.getSelectedRow();
|
int row = lstExternalMods.getSelectedRow();
|
||||||
List<ModInfo> mods = getProfile().getMinecraftProvider().getModService().getMods();
|
List<ModInfo> mods = getProfile().service().mod().getMods();
|
||||||
if (mods != null && 0 <= row && row < mods.size()) {
|
if (mods != null && 0 <= row && row < mods.size()) {
|
||||||
ModInfo m = mods.get(row);
|
ModInfo m = mods.get(row);
|
||||||
boolean hasLink = m.url != null;
|
boolean hasLink = m.url != null;
|
||||||
@ -194,7 +194,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
|||||||
((DefaultTableModel) lstExternalMods.getModel()).addTableModelListener(e -> {
|
((DefaultTableModel) lstExternalMods.getModel()).addTableModelListener(e -> {
|
||||||
if (e.getType() == TableModelEvent.UPDATE && e.getColumn() == 0) {
|
if (e.getType() == TableModelEvent.UPDATE && e.getColumn() == 0) {
|
||||||
int row = lstExternalMods.getSelectedRow();
|
int row = lstExternalMods.getSelectedRow();
|
||||||
List<ModInfo> mods = getProfile().getMinecraftProvider().getModService().getMods();
|
List<ModInfo> mods = getProfile().service().mod().getMods();
|
||||||
if (mods != null && mods.size() > row && row >= 0)
|
if (mods != null && mods.size() > row && row >= 0)
|
||||||
mods.get(row).reverseModState();
|
mods.get(row).reverseModState();
|
||||||
}
|
}
|
||||||
@ -885,7 +885,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
|||||||
// <editor-fold defaultstate="collapsed" desc="UI Events">
|
// <editor-fold defaultstate="collapsed" desc="UI Events">
|
||||||
private void cboProfilesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboProfilesItemStateChanged
|
private void cboProfilesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboProfilesItemStateChanged
|
||||||
if (!isLoading) {
|
if (!isLoading) {
|
||||||
if (getProfile().getMinecraftProvider().getVersionCount() <= 0)
|
if (getProfile().service().version().getVersionCount() <= 0)
|
||||||
versionChanged(null);
|
versionChanged(null);
|
||||||
prepare(getProfile());
|
prepare(getProfile());
|
||||||
}
|
}
|
||||||
@ -989,7 +989,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
|||||||
|
|
||||||
private void btnDownloadAllAssetsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadAllAssetsActionPerformed
|
private void btnDownloadAllAssetsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadAllAssetsActionPerformed
|
||||||
if (mcVersion != null)
|
if (mcVersion != null)
|
||||||
getProfile().getMinecraftProvider().getAssetService().downloadAssets(mcVersion).run();
|
getProfile().service().asset().downloadAssets(mcVersion).run();
|
||||||
}//GEN-LAST:event_btnDownloadAllAssetsActionPerformed
|
}//GEN-LAST:event_btnDownloadAllAssetsActionPerformed
|
||||||
|
|
||||||
private void txtMaxMemoryFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMaxMemoryFocusLost
|
private void txtMaxMemoryFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMaxMemoryFocusLost
|
||||||
@ -1061,14 +1061,14 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
|||||||
return;
|
return;
|
||||||
boolean flag = true;
|
boolean flag = true;
|
||||||
for (File f : fc.getSelectedFiles())
|
for (File f : fc.getSelectedFiles())
|
||||||
flag &= getProfile().getMinecraftProvider().getModService().addMod(f);
|
flag &= getProfile().service().mod().addMod(f);
|
||||||
reloadMods();
|
reloadMods();
|
||||||
if (!flag)
|
if (!flag)
|
||||||
MessageBox.Show(C.I18N.getString("mods.failed"));
|
MessageBox.Show(C.I18N.getString("mods.failed"));
|
||||||
}//GEN-LAST:event_btnAddModActionPerformed
|
}//GEN-LAST:event_btnAddModActionPerformed
|
||||||
|
|
||||||
private void btnRemoveModActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveModActionPerformed
|
private void btnRemoveModActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveModActionPerformed
|
||||||
getProfile().getMinecraftProvider().getModService().removeMod(SwingUtils.getValueBySelectedRow(lstExternalMods, lstExternalMods.getSelectedRows(), 1));
|
getProfile().service().mod().removeMod(SwingUtils.getValueBySelectedRow(lstExternalMods, lstExternalMods.getSelectedRows(), 1));
|
||||||
reloadMods();
|
reloadMods();
|
||||||
}//GEN-LAST:event_btnRemoveModActionPerformed
|
}//GEN-LAST:event_btnRemoveModActionPerformed
|
||||||
|
|
||||||
@ -1079,8 +1079,8 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
|||||||
|
|
||||||
private void lblModInfoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblModInfoMouseClicked
|
private void lblModInfoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblModInfoMouseClicked
|
||||||
int idx = lstExternalMods.getSelectedRow();
|
int idx = lstExternalMods.getSelectedRow();
|
||||||
if (idx > 0 && idx < getProfile().getMinecraftProvider().getModService().getMods().size())
|
if (idx > 0 && idx < getProfile().service().mod().getMods().size())
|
||||||
getProfile().getMinecraftProvider().getModService().getMods().get(idx).showURL();
|
getProfile().service().mod().getMods().get(idx).showURL();
|
||||||
}//GEN-LAST:event_lblModInfoMouseClicked
|
}//GEN-LAST:event_lblModInfoMouseClicked
|
||||||
|
|
||||||
private void btnChoosingGameDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChoosingGameDirActionPerformed
|
private void btnChoosingGameDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChoosingGameDirActionPerformed
|
||||||
@ -1102,7 +1102,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
|||||||
}//GEN-LAST:event_btnChoosingGameDirActionPerformed
|
}//GEN-LAST:event_btnChoosingGameDirActionPerformed
|
||||||
|
|
||||||
private void btnCleanGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCleanGameActionPerformed
|
private void btnCleanGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCleanGameActionPerformed
|
||||||
getProfile().getMinecraftProvider().cleanFolder();
|
getProfile().service().version().cleanFolder();
|
||||||
}//GEN-LAST:event_btnCleanGameActionPerformed
|
}//GEN-LAST:event_btnCleanGameActionPerformed
|
||||||
|
|
||||||
// </editor-fold>
|
// </editor-fold>
|
||||||
@ -1165,9 +1165,9 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
|||||||
isLoading = true;
|
isLoading = true;
|
||||||
cboVersions.removeAllItems();
|
cboVersions.removeAllItems();
|
||||||
int index = 0, i = 0;
|
int index = 0, i = 0;
|
||||||
MinecraftVersion selVersion = getProfile().getMinecraftProvider().getSelectedVersion();
|
MinecraftVersion selVersion = getProfile().service().version().getSelectedVersion();
|
||||||
String selectedMC = selVersion == null ? null : selVersion.id;
|
String selectedMC = selVersion == null ? null : selVersion.id;
|
||||||
for (MinecraftVersion each : getProfile().getMinecraftProvider().getVersions()) {
|
for (MinecraftVersion each : getProfile().service().version().getVersions()) {
|
||||||
cboVersions.addItem(each.id);
|
cboVersions.addItem(each.id);
|
||||||
if (StrUtils.isEquals(each.id, selectedMC))
|
if (StrUtils.isEquals(each.id, selectedMC))
|
||||||
index = i;
|
index = i;
|
||||||
@ -1181,7 +1181,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loadMinecraftVersion() {
|
void loadMinecraftVersion() {
|
||||||
loadMinecraftVersion(getProfile().getMinecraftProvider().getSelectedVersion());
|
loadMinecraftVersion(getProfile().service().version().getSelectedVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1210,7 +1210,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
|||||||
Transferable tr = dtde.getTransferable();
|
Transferable tr = dtde.getTransferable();
|
||||||
List<File> files = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
|
List<File> files = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
|
||||||
for (File file : files)
|
for (File file : files)
|
||||||
getProfile().getMinecraftProvider().getModService().addMod(file);
|
getProfile().service().mod().addMod(file);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
HMCLog.warn("Failed to drop file.", ex);
|
HMCLog.warn("Failed to drop file.", ex);
|
||||||
}
|
}
|
||||||
@ -1233,7 +1233,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
|||||||
}
|
}
|
||||||
|
|
||||||
void refreshVersions() {
|
void refreshVersions() {
|
||||||
getProfile().getMinecraftProvider().refreshVersions();
|
getProfile().service().version().refreshVersions();
|
||||||
loadVersions();
|
loadVersions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1247,7 +1247,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
|||||||
reloadingMods = true;
|
reloadingMods = true;
|
||||||
DefaultTableModel model = SwingUtils.clearDefaultTable(lstExternalMods);
|
DefaultTableModel model = SwingUtils.clearDefaultTable(lstExternalMods);
|
||||||
Observable.<List<ModInfo>>createWithEmptySubscription(
|
Observable.<List<ModInfo>>createWithEmptySubscription(
|
||||||
t -> t.onNext(getProfile().getMinecraftProvider().getModService().recacheMods()))
|
t -> t.onNext(getProfile().service().mod().recacheMods()))
|
||||||
.subscribeOn(Schedulers.newThread()).observeOn(Schedulers.eventQueue())
|
.subscribeOn(Schedulers.newThread()).observeOn(Schedulers.eventQueue())
|
||||||
.subscribe(t -> {
|
.subscribe(t -> {
|
||||||
for (ModInfo x : t)
|
for (ModInfo x : t)
|
||||||
@ -1266,7 +1266,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
|||||||
@Override
|
@Override
|
||||||
public void onSelected() {
|
public void onSelected() {
|
||||||
loadProfiles();
|
loadProfiles();
|
||||||
if (getProfile().getMinecraftProvider().getVersionCount() <= 0)
|
if (getProfile().service().version().getVersionCount() <= 0)
|
||||||
versionChanged(null);
|
versionChanged(null);
|
||||||
else
|
else
|
||||||
versionChanged((String) cboVersions.getSelectedItem());
|
versionChanged((String) cboVersions.getSelectedItem());
|
||||||
|
@ -139,7 +139,7 @@ public class InstallerPanel extends AnimatedPanel implements Selectable {
|
|||||||
MessageBox.Show(C.i18n("install.not_refreshed"));
|
MessageBox.Show(C.i18n("install.not_refreshed"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gsp.getProfile().getInstallerService().download(getVersion(idx), id).after(new TaskRunnable(this::refreshVersions)).run();
|
gsp.getProfile().service().install().download(getVersion(idx), id).after(new TaskRunnable(this::refreshVersions)).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadVersions() {
|
public void loadVersions() {
|
||||||
|
@ -30,6 +30,7 @@ import javax.swing.SwingUtilities;
|
|||||||
import org.jackhuang.hellominecraft.C;
|
import org.jackhuang.hellominecraft.C;
|
||||||
import org.jackhuang.hellominecraft.HMCLog;
|
import org.jackhuang.hellominecraft.HMCLog;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.DefaultGameLauncher;
|
import org.jackhuang.hellominecraft.launcher.launch.DefaultGameLauncher;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.launch.GameException;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.IAuthenticator;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.IAuthenticator;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.LoginInfo;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.LoginInfo;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
||||||
@ -39,6 +40,7 @@ import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
|||||||
import org.jackhuang.hellominecraft.launcher.launch.GameLauncher;
|
import org.jackhuang.hellominecraft.launcher.launch.GameLauncher;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.LauncherVisibility;
|
import org.jackhuang.hellominecraft.launcher.settings.LauncherVisibility;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Settings;
|
import org.jackhuang.hellominecraft.launcher.settings.Settings;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.utils.auth.AuthenticationException;
|
||||||
import org.jackhuang.hellominecraft.lookandfeel.GraphicsUtils;
|
import org.jackhuang.hellominecraft.lookandfeel.GraphicsUtils;
|
||||||
import org.jackhuang.hellominecraft.utils.Event;
|
import org.jackhuang.hellominecraft.utils.Event;
|
||||||
import org.jackhuang.hellominecraft.lookandfeel.components.ConstomButton;
|
import org.jackhuang.hellominecraft.lookandfeel.components.ConstomButton;
|
||||||
@ -388,7 +390,7 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final String name = (String) cboProfiles.getSelectedItem();
|
final String name = (String) cboProfiles.getSelectedItem();
|
||||||
if (StrUtils.isBlank(name) || getCurrentProfile().getMinecraftProvider().getSelectedVersion() == null) {
|
if (StrUtils.isBlank(name) || getCurrentProfile().service().version().getSelectedVersion() == null) {
|
||||||
HMCLog.warn("There's no selected version, rechoose a version.");
|
HMCLog.warn("There's no selected version, rechoose a version.");
|
||||||
MessageBox.ShowLocalized("minecraft.no_selected_version");
|
MessageBox.ShowLocalized("minecraft.no_selected_version");
|
||||||
return;
|
return;
|
||||||
@ -407,19 +409,18 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
|||||||
public void run() {
|
public void run() {
|
||||||
Thread.currentThread().setName("Game Launcher");
|
Thread.currentThread().setName("Game Launcher");
|
||||||
DefaultGameLauncher gl = new DefaultGameLauncher(getCurrentProfile(), li, l);
|
DefaultGameLauncher gl = new DefaultGameLauncher(getCurrentProfile(), li, l);
|
||||||
gl.failEvent.register((sender, s) -> {
|
|
||||||
if (s != null)
|
|
||||||
MessageBox.Show(s);
|
|
||||||
MainFrame.INSTANCE.closeMessage();
|
|
||||||
isLaunching = false;
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
gl.successEvent.register((sender, s) -> {
|
gl.successEvent.register((sender, s) -> {
|
||||||
isLaunching = false;
|
isLaunching = false;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
listener.accept(gl);
|
listener.accept(gl);
|
||||||
gl.makeLaunchCommand();
|
try {
|
||||||
|
gl.makeLaunchCommand();
|
||||||
|
} catch (GameException e) {
|
||||||
|
failed(C.i18n("launch.failed") + ", " + e.getMessage());
|
||||||
|
} catch (AuthenticationException e) {
|
||||||
|
failed(C.i18n("login.failed") + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
@ -477,10 +478,10 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
|||||||
cboVersions.removeAllItems();
|
cboVersions.removeAllItems();
|
||||||
int index = 0, i = 0;
|
int index = 0, i = 0;
|
||||||
getCurrentProfile().selectedVersionChangedEvent.register(this);
|
getCurrentProfile().selectedVersionChangedEvent.register(this);
|
||||||
getCurrentProfile().getMinecraftProvider().refreshVersions();
|
getCurrentProfile().service().version().refreshVersions();
|
||||||
MinecraftVersion selVersion = getCurrentProfile().getMinecraftProvider().getSelectedVersion();
|
MinecraftVersion selVersion = getCurrentProfile().service().version().getSelectedVersion();
|
||||||
String selectedMC = selVersion == null ? null : selVersion.id;
|
String selectedMC = selVersion == null ? null : selVersion.id;
|
||||||
if (getCurrentProfile().getMinecraftProvider().getVersions().isEmpty()) {
|
if (getCurrentProfile().service().version().getVersions().isEmpty()) {
|
||||||
if (!showedNoVersion)
|
if (!showedNoVersion)
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
if (MessageBox.Show(C.i18n("mainwindow.no_version"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
|
if (MessageBox.Show(C.i18n("mainwindow.no_version"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
|
||||||
@ -490,7 +491,7 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
|||||||
showedNoVersion = true;
|
showedNoVersion = true;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
for (MinecraftVersion mcVersion : getCurrentProfile().getMinecraftProvider().getVersions()) {
|
for (MinecraftVersion mcVersion : getCurrentProfile().service().version().getVersions()) {
|
||||||
if (mcVersion.hidden)
|
if (mcVersion.hidden)
|
||||||
continue;
|
continue;
|
||||||
cboVersions.addItem(mcVersion.id);
|
cboVersions.addItem(mcVersion.id);
|
||||||
@ -553,6 +554,13 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void failed(String s) {
|
||||||
|
if (s != null)
|
||||||
|
MessageBox.Show(s);
|
||||||
|
MainFrame.INSTANCE.closeMessage();
|
||||||
|
isLaunching = false;
|
||||||
|
}
|
||||||
|
|
||||||
public class LaunchFinisher implements Event<List<String>> {
|
public class LaunchFinisher implements Event<List<String>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -590,7 +598,12 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
|||||||
jpm.start();
|
jpm.start();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
obj.launch(str);
|
try {
|
||||||
|
obj.launch(str);
|
||||||
|
} catch (IOException e) {
|
||||||
|
failed(C.i18n("launch.failed_creating_process") + "\n" + e.getMessage());
|
||||||
|
HMCLog.err("Failed to launch when creating a new process.", e);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ public final class JdkVersion {
|
|||||||
if (StrUtils.isBlank(javaVersion))
|
if (StrUtils.isBlank(javaVersion))
|
||||||
return UNKOWN;
|
return UNKOWN;
|
||||||
int a = UNKOWN;
|
int a = UNKOWN;
|
||||||
if (javaVersion.contains("1.9."))
|
if (javaVersion.contains("1.9.") || javaVersion.startsWith("9"))
|
||||||
a = JAVA_19;
|
a = JAVA_19;
|
||||||
else if (javaVersion.contains("1.8."))
|
else if (javaVersion.contains("1.8."))
|
||||||
a = JAVA_18;
|
a = JAVA_18;
|
||||||
|
@ -18,9 +18,9 @@
|
|||||||
package org.jackhuang.hellominecraft.launcher.servers;
|
package org.jackhuang.hellominecraft.launcher.servers;
|
||||||
|
|
||||||
import org.jackhuang.hellominecraft.launcher.api.IPlugin;
|
import org.jackhuang.hellominecraft.launcher.api.IPlugin;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftService;
|
||||||
import org.jackhuang.hellominecraft.launcher.servers.mfcraft.CheckModsMinecraftProvider;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.servers.mfcraft.MFCraftAuthenticator;
|
import org.jackhuang.hellominecraft.launcher.servers.mfcraft.MFCraftAuthenticator;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.servers.mfcraft.MFCraftMinecraftService;
|
||||||
import org.jackhuang.hellominecraft.launcher.servers.mfcraft.Servers;
|
import org.jackhuang.hellominecraft.launcher.servers.mfcraft.Servers;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Settings;
|
import org.jackhuang.hellominecraft.launcher.settings.Settings;
|
||||||
@ -44,8 +44,8 @@ public class ServerPlugin implements IPlugin {
|
|||||||
protected static MFCraftAuthenticator MFCRAFT_LOGIN;
|
protected static MFCraftAuthenticator MFCRAFT_LOGIN;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMinecraftProvider provideMinecraftProvider(Profile profile) {
|
public IMinecraftService provideMinecraftService(Profile profile) {
|
||||||
return new CheckModsMinecraftProvider(profile);
|
return new MFCraftMinecraftService(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,6 +19,7 @@ package org.jackhuang.hellominecraft.launcher.servers.mfcraft;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.jackhuang.hellominecraft.HMCLog;
|
import org.jackhuang.hellominecraft.HMCLog;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftService;
|
||||||
import org.jackhuang.hellominecraft.launcher.servers.ServerPlugin;
|
import org.jackhuang.hellominecraft.launcher.servers.ServerPlugin;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
||||||
import org.jackhuang.hellominecraft.launcher.version.MinecraftModService;
|
import org.jackhuang.hellominecraft.launcher.version.MinecraftModService;
|
||||||
@ -31,7 +32,7 @@ import org.jackhuang.hellominecraft.utils.ArrayUtils;
|
|||||||
*/
|
*/
|
||||||
public class CheckModsMinecraftProvider extends MinecraftVersionManager {
|
public class CheckModsMinecraftProvider extends MinecraftVersionManager {
|
||||||
|
|
||||||
public CheckModsMinecraftProvider(Profile p) {
|
public CheckModsMinecraftProvider(IMinecraftService p) {
|
||||||
super(p);
|
super(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +40,7 @@ public class CheckModsMinecraftProvider extends MinecraftVersionManager {
|
|||||||
public boolean onLaunch() {
|
public boolean onLaunch() {
|
||||||
try {
|
try {
|
||||||
super.onLaunch();
|
super.onLaunch();
|
||||||
String[] md5s = ((MinecraftModService) getModService()).checkMd5s();
|
String[] md5s = ((MinecraftModService) service.mod()).checkMd5s();
|
||||||
String[] md5 = ServerPlugin.lastServerInfo.md5;
|
String[] md5 = ServerPlugin.lastServerInfo.md5;
|
||||||
return ArrayUtils.equals(md5s, md5);
|
return ArrayUtils.equals(md5s, md5);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user