reconstruct code

This commit is contained in:
huangyuhui
2016-01-20 19:24:35 +08:00
parent ab08a8d3f5
commit 0da589374a
36 changed files with 662 additions and 337 deletions

1
HMCL/launch.sh Executable file

File diff suppressed because one or more lines are too long

View File

@@ -18,7 +18,7 @@
package org.jackhuang.hellominecraft.launcher.api;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.Profile;
import org.jackhuang.hellominecraft.launcher.settings.Profile;
import org.jackhuang.hellominecraft.launcher.core.auth.AuthenticationException;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;

View File

@@ -23,9 +23,6 @@ import java.io.IOException;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftAssetService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.assets.AssetsIndex;
import org.jackhuang.hellominecraft.launcher.core.assets.AssetsObject;
import org.jackhuang.hellominecraft.launcher.core.assets.IAssetsHandler;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.tasks.Task;
import org.jackhuang.hellominecraft.tasks.TaskWindow;
@@ -40,8 +37,8 @@ import rx.concurrency.Schedulers;
*/
public class MinecraftAssetService extends IMinecraftAssetService {
public MinecraftAssetService(IMinecraftService profile) {
super(profile);
public MinecraftAssetService(IMinecraftService service) {
super(service);
}
@Override
@@ -98,7 +95,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
@Override
public File getAssets() {
return new File(service.profile.getCanonicalGameDirFile(), "assets");
return new File(service.baseDirectory(), "assets");
}
@Override

View File

@@ -59,7 +59,7 @@ public final class OfflineAuthenticator extends IAuthenticator {
UserProfileProvider result = new UserProfileProvider();
result.setUserName(info.username);
String uuid = getUUIDFromUserName(info.username);
if (uuidMap != null && uuid.contains(uuid))
if (uuidMap != null && uuidMap.containsKey(uuid))
uuid = uuidMap.get(info.username);
else {
if (uuidMap == null)

View File

@@ -0,0 +1,37 @@
/*
* 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.core.download;
import java.io.File;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
/**
*
* @author huangyuhui
*/
public class DownloadLibraryJob {
public String url, name;
public File path;
public DownloadLibraryJob(String n, String u, File p) {
url = u;
name = n;
path = IOUtils.tryGetCanonicalFile(p);
}
}

View File

@@ -44,13 +44,13 @@ import rx.Observable;
*/
public class MinecraftDownloadService extends IMinecraftDownloadService {
public MinecraftDownloadService(IMinecraftService profile) {
super(profile);
public MinecraftDownloadService(IMinecraftService service) {
super(service);
}
@Override
public List<GameLauncher.DownloadLibraryJob> getDownloadLibraries(MinecraftVersion mv) throws GameException {
ArrayList<GameLauncher.DownloadLibraryJob> downloadLibraries = new ArrayList<>();
public List<DownloadLibraryJob> getDownloadLibraries(MinecraftVersion mv) throws GameException {
ArrayList<DownloadLibraryJob> downloadLibraries = new ArrayList<>();
if (mv == null)
return downloadLibraries;
MinecraftVersion v = mv.resolve(service.version());
@@ -58,12 +58,12 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
for (IMinecraftLibrary l : v.libraries) {
l.init();
if (l.allow()) {
File ff = l.getFilePath(service.baseFolder);
File ff = l.getFilePath(service.baseDirectory());
if (!ff.exists()) {
String libURL = service.getDownloadType().getProvider().getLibraryDownloadURL() + "/";
libURL = service.getDownloadType().getProvider().getParsedLibraryDownloadURL(l.getDownloadURL(libURL, service.getDownloadType()));
if (libURL != null)
downloadLibraries.add(new GameLauncher.DownloadLibraryJob(l.name, libURL, ff));
downloadLibraries.add(new DownloadLibraryJob(l.name, libURL, ff));
}
}
}
@@ -73,7 +73,7 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
@Override
public MinecraftVersion downloadMinecraft(String id) {
String vurl = service.getDownloadType().getProvider().getVersionsDownloadURL() + id + "/";
File vpath = new File(service.baseFolder, "versions/" + id);
File vpath = new File(service.baseDirectory(), "versions/" + id);
File mvt = new File(vpath, id + ".json");
File mvj = new File(vpath, id + ".jar");
vpath.mkdirs();
@@ -97,7 +97,7 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
@Override
public boolean downloadMinecraftJar(String id) {
String vurl = service.getDownloadType().getProvider().getVersionsDownloadURL() + id + "/";
File vpath = new File(service.baseFolder, "versions/" + id);
File vpath = new File(service.baseDirectory(), "versions/" + id);
File mvv = new File(vpath, id + ".jar"), moved = null;
if (mvv.exists()) {
moved = new File(vpath, id + "-renamed.jar");
@@ -122,7 +122,7 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
@Override
public boolean downloadMinecraftVersionJson(String id) {
String vurl = service.getDownloadType().getProvider().getVersionsDownloadURL() + id + "/";
File vpath = new File(service.baseFolder, "versions/" + id);
File vpath = new File(service.baseDirectory(), "versions/" + id);
File mvv = new File(vpath, id + ".json"), moved = null;
if (mvv.exists()) {
moved = new File(vpath, id + "-renamed.json");

View File

@@ -43,21 +43,21 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
}
@Override
public Task download(InstallerVersion v, InstallerType type) {
public Task download(String installId, InstallerVersion v, InstallerType type) {
switch (type) {
case Forge:
return downloadForge(v);
return downloadForge(installId, v);
case Optifine:
return downloadOptifine(v);
return downloadOptifine(installId, v);
case LiteLoader:
return downloadLiteLoader(v);
return downloadLiteLoader(installId, v);
default:
return null;
}
}
@Override
public Task downloadForge(InstallerVersion v) {
public Task downloadForge(String installId, InstallerVersion v) {
return new TaskInfo("Forge Downloader") {
@Override
public void executeTask() {
@@ -72,7 +72,7 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
}
@Override
public Task downloadOptifine(InstallerVersion v) {
public Task downloadOptifine(String installId, InstallerVersion v) {
return new TaskInfo("OptiFine Downloader") {
@Override
public void executeTask() {
@@ -81,7 +81,7 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
OptiFineDownloadFormatter task = new OptiFineDownloadFormatter(v.installer);
TaskWindow.getInstance().addTask(task)
.addTask(new FileDownloadTask(filepath).registerPreviousResult(task).setTag("optifine"))
.addTask(new OptiFineInstaller(service, v.selfVersion, filepath))
.addTask(new OptiFineInstaller(service, installId, v, filepath))
.start();
}
}
@@ -89,14 +89,14 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
}
@Override
public Task downloadLiteLoader(InstallerVersion v) {
public Task downloadLiteLoader(String installId, InstallerVersion v) {
return new TaskInfo("LiteLoader Downloader") {
@Override
public void executeTask() {
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "liteloader-universal.jar");
FileDownloadTask task = (FileDownloadTask) new FileDownloadTask(v.universal, filepath).setTag("LiteLoader");
TaskWindow.getInstance()
.addTask(task).addTask(new LiteLoaderInstaller(service, (LiteLoaderVersionList.LiteLoaderInstallerVersion) v).registerPreviousResult(task))
.addTask(task).addTask(new LiteLoaderInstaller(service, installId, (LiteLoaderVersionList.LiteLoaderInstallerVersion) v).registerPreviousResult(task))
.start();
}
};

View File

@@ -46,7 +46,7 @@ public class ForgeInstaller extends Task {
public InstallerVersion installerVersion;
public ForgeInstaller(IMinecraftService mp, File forgeInstaller, InstallerVersion installerVersion) {
this.gameDir = mp.baseFolder;
this.gameDir = mp.baseDirectory();
this.forgeInstaller = forgeInstaller;
this.mp = mp;
this.installerVersion = installerVersion;
@@ -64,7 +64,7 @@ public class ForgeInstaller extends Task {
File from = new File(gameDir, "versions" + File.separator + profile.install.minecraft);
if (!from.exists())
if (MessageBox.Show(C.i18n("install.no_version_if_intall")) == MessageBox.YES_OPTION) {
if (!mp.version().install(profile.install.minecraft))
if (!mp.version().install(profile.install.minecraft, null))
throw new IllegalStateException(C.i18n("install.no_version"));
} else
throw new IllegalStateException(C.i18n("install.no_version"));

View File

@@ -38,27 +38,29 @@ public class LiteLoaderInstaller extends Task implements PreviousResultRegistrar
public LiteLoaderVersionList.LiteLoaderInstallerVersion version;
public File installer;
public String installId;
public IMinecraftService service;
public LiteLoaderInstaller(IMinecraftService service, LiteLoaderVersionList.LiteLoaderInstallerVersion v) {
this(service, v, null);
public LiteLoaderInstaller(IMinecraftService service, String installId, LiteLoaderVersionList.LiteLoaderInstallerVersion v) {
this(service, installId, v, null);
}
public LiteLoaderInstaller(IMinecraftService service, LiteLoaderVersionList.LiteLoaderInstallerVersion v, File installer) {
public LiteLoaderInstaller(IMinecraftService service, String installId, LiteLoaderVersionList.LiteLoaderInstallerVersion v, File installer) {
this.service = service;
this.installId = installId;
this.version = v;
this.installer = installer;
}
@Override
public void executeTask() throws Exception {
if (service.version().getSelectedVersion() == null)
if (installId == null)
throw new IllegalStateException(C.i18n("install.no_version"));
if (pre.size() != 1 && installer == null)
throw new IllegalStateException("No registered previous task.");
if (installer == null)
installer = pre.get(pre.size() - 1).getResult();
MinecraftVersion mv = (MinecraftVersion) service.version().getSelectedVersion().clone();
MinecraftVersion mv = (MinecraftVersion) service.version().getVersionById(installId).clone();
mv.inheritsFrom = mv.id;
mv.jar = mv.jar == null ? mv.id : mv.jar;
mv.libraries = new ArrayList(Arrays.asList(version.libraries));
@@ -66,13 +68,13 @@ public class LiteLoaderInstaller extends Task implements PreviousResultRegistrar
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";
mv.libraries.add(0, ml);
FileUtils.copyFile(installer, new File(service.baseFolder, "libraries/com/mumfrey/liteloader/" + version.selfVersion + "/liteloader-" + version.selfVersion + ".jar"));
FileUtils.copyFile(installer, new File(service.baseDirectory(), "libraries/com/mumfrey/liteloader/" + version.selfVersion + "/liteloader-" + version.selfVersion + ".jar"));
mv.id += "-LiteLoader" + version.selfVersion;
mv.mainClass = "net.minecraft.launchwrapper.Launch";
mv.minecraftArguments += " --tweakClass " + version.tweakClass;
File folder = new File(service.baseFolder, "versions/" + mv.id);
File folder = new File(service.baseDirectory(), "versions/" + mv.id);
folder.mkdirs();
File json = new File(folder, mv.id + ".json");
HMCLog.log("Creating new version profile..." + mv.id + ".json");

View File

@@ -21,6 +21,7 @@ import java.io.File;
import java.util.ArrayList;
import java.util.zip.ZipFile;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.tasks.Task;
import org.jackhuang.hellominecraft.tasks.communication.PreviousResult;
@@ -37,30 +38,33 @@ public class OptiFineInstaller extends Task implements PreviousResultRegistrar<F
public File installer;
public IMinecraftService service;
public String version;
public InstallerVersionList.InstallerVersion version;
public String installId;
public OptiFineInstaller(IMinecraftService service, String version) {
this(service, version, null);
public OptiFineInstaller(IMinecraftService service, String installId, InstallerVersionList.InstallerVersion version) {
this(service, installId, version, null);
}
public OptiFineInstaller(IMinecraftService service, String version, File installer) {
public OptiFineInstaller(IMinecraftService service, String installId, InstallerVersionList.InstallerVersion version, File installer) {
this.service = service;
this.installId = installId;
this.installer = installer;
this.version = version;
}
@Override
public void executeTask() throws Exception {
if (service.version().getSelectedVersion() == null)
if (installId == null)
throw new Exception(C.i18n("install.no_version"));
MinecraftVersion mv = (MinecraftVersion) service.version().getSelectedVersion().clone();
String selfId = version.selfVersion;
MinecraftVersion mv = (MinecraftVersion) service.version().getVersionById(installId).clone();
mv.inheritsFrom = mv.id;
mv.jar = mv.jar == null ? mv.id : mv.jar;
mv.libraries.clear();
mv.libraries.add(0, new MinecraftLibrary("optifine:OptiFine:" + version));
FileUtils.copyFile(installer, new File(service.baseFolder, "libraries/optifine/OptiFine/" + version + "/OptiFine-" + version + ".jar"));
mv.libraries.add(0, new MinecraftLibrary("optifine:OptiFine:" + selfId));
FileUtils.copyFile(installer, new File(service.baseDirectory(), "libraries/optifine/OptiFine/" + selfId + "/OptiFine-" + selfId + ".jar"));
mv.id += "-" + version;
mv.id += "-" + selfId;
if (new ZipFile(installer).getEntry("optifine/OptiFineTweaker.class") != null) {
if (!mv.mainClass.startsWith("net.minecraft.launchwrapper.")) {
mv.mainClass = "net.minecraft.launchwrapper.Launch";
@@ -68,7 +72,7 @@ public class OptiFineInstaller extends Task implements PreviousResultRegistrar<F
}
mv.minecraftArguments += " --tweakClass optifine.OptiFineTweaker";
}
File loc = new File(service.baseFolder, "versions/" + mv.id);
File loc = new File(service.baseDirectory(), "versions/" + mv.id);
loc.mkdirs();
File json = new File(loc, mv.id + ".json");
FileUtils.writeStringToFile(json, C.gsonPrettyPrinting.toJson(mv, MinecraftVersion.class));

View File

@@ -20,7 +20,6 @@ package org.jackhuang.hellominecraft.launcher.core.launch;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftLoader;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -29,8 +28,6 @@ import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.Launcher;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.core.Profile;
import org.jackhuang.hellominecraft.launcher.settings.Settings;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.utils.system.JdkVersion;
import org.jackhuang.hellominecraft.utils.MathUtils;
@@ -46,19 +43,19 @@ import org.jackhuang.hellominecraft.utils.Utils;
*/
public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
protected Profile v;
protected LaunchOptions options;
protected UserProfileProvider lr;
protected File gameDir;
protected IMinecraftService service;
protected final MinecraftVersion version;
public AbstractMinecraftLoader(Profile ver, IMinecraftService provider, UserProfileProvider lr) throws GameException {
public AbstractMinecraftLoader(LaunchOptions options, IMinecraftService service, String versionId, UserProfileProvider lr) throws GameException {
this.lr = lr;
v = ver;
service = provider;
gameDir = v.getCanonicalGameDirFile();
version = service.version().getSelectedVersion().resolve(service.version());
this.options = options;
this.service = service;
this.gameDir = service.baseDirectory();
this.version = service.version().getVersionById(versionId).resolve(service.version());
}
@Override
@@ -69,30 +66,13 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
public void makeHeadCommand(List<String> res) {
HMCLog.log("On making head command.");
String str = v.getJavaDir();
if (!v.getJavaDirFile().exists()) {
MessageBox.Show(C.i18n("launch.wrong_javadir"));
v.setJava(null);
str = v.getJavaDir();
}
JdkVersion jv = new JdkVersion(str);
if (Settings.getInstance().getJava().contains(jv))
jv = Settings.getInstance().getJava().get(Settings.getInstance().getJava().indexOf(jv));
else
try {
jv = JdkVersion.getJavaVersionFromExecutable(str);
Settings.getInstance().getJava().add(jv);
Settings.save();
} catch (IOException ex) {
HMCLog.warn("Failed to get java version", ex);
jv = null;
}
res.add(str);
JdkVersion jv = options.getJava();
res.add(options.getJavaDir());
if (v.hasJavaArgs())
res.addAll(Arrays.asList(StrUtils.tokenize(v.getJavaArgs())));
if (options.hasJavaArgs())
res.addAll(Arrays.asList(StrUtils.tokenize(options.getJavaArgs())));
if (!v.isNoJVMArgs()) {
if (!options.isNoJVMArgs()) {
appendJVMArgs(res);
if (jv == null || !jv.isEarlyAccess()) {
@@ -105,11 +85,11 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
res.add("-Xmn128m");
}
if (!StrUtils.isBlank(v.getPermSize()))
if (!StrUtils.isBlank(options.getPermSize()))
if (jv == null || jv.getParsedVersion() < JdkVersion.JAVA_18)
res.add("-XX:PermSize=" + v.getPermSize() + "m");
res.add("-XX:PermSize=" + options.getPermSize() + "m");
else if (jv.getParsedVersion() >= JdkVersion.JAVA_18)
res.add("-XX:MetaspaceSize=" + v.getPermSize() + "m");
res.add("-XX:MetaspaceSize=" + options.getPermSize() + "m");
}
if (jv != null) {
@@ -121,8 +101,8 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
if (jv != null && jv.getPlatform() == Platform.BIT_32 && Platform.getPlatform() == Platform.BIT_64)
MessageBox.Show(C.i18n("advice.os64butjdk32"));
if (!StrUtils.isBlank(v.getMaxMemory())) {
int mem = MathUtils.parseMemory(v.getMaxMemory(), 2147483647);
if (!StrUtils.isBlank(options.getMaxMemory())) {
int mem = MathUtils.parseMemory(options.getMaxMemory(), 2147483647);
if (jv != null && jv.getPlatform() == Platform.BIT_32 && mem > 1024)
MessageBox.Show(C.i18n("launch.too_big_memory_alloc_64bit"));
else {
@@ -131,8 +111,8 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
if (a > 0 && a < mem)
MessageBox.Show(C.i18n("launch.too_big_memory_alloc_free_space_too_low", a));
}
String a = "-Xmx" + v.getMaxMemory();
if (MathUtils.canParseInt(v.getMaxMemory()))
String a = "-Xmx" + options.getMaxMemory();
if (MathUtils.canParseInt(options.getMaxMemory()))
a += "m";
res.add(a);
}
@@ -143,9 +123,8 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
if (OS.os() != OS.WINDOWS)
res.add("-Duser.home=" + gameDir.getParent());
res.add("-Dhellominecraftlauncher.gamedir=" + gameDir.getAbsolutePath());
if (!v.isCanceledWrapper()) {
if (!options.isCanceledWrapper()) {
res.add("-cp");
res.add(StrUtils.parseParams("", Utils.getURL(), File.pathSeparator));
res.add(Launcher.class.getCanonicalName());
@@ -163,14 +142,14 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
HMCLog.log("On making launcher args.");
if (StrUtils.isNotBlank(v.getHeight()) && StrUtils.isNotBlank(v.getWidth())) {
if (StrUtils.isNotBlank(options.getHeight()) && StrUtils.isNotBlank(options.getWidth())) {
res.add("--height");
res.add(v.getHeight());
res.add(options.getHeight());
res.add("--width");
res.add(v.getWidth());
res.add(options.getWidth());
}
String serverIp = v.getServerIp();
String serverIp = options.getServerIp();
if (lr.getServer() != null)
serverIp = lr.getServer().addr;
if (StrUtils.isNotBlank(serverIp)) {
@@ -181,23 +160,23 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
res.add(args.length > 1 ? args[1] : "25565");
}
if (v.isFullscreen())
if (options.isFullscreen())
res.add("--fullscreen");
if (v.isDebug() && !v.isCanceledWrapper())
if (options.isDebug() && !options.isCanceledWrapper())
res.add("-debug");
if (StrUtils.isNotBlank(Settings.getInstance().getProxyHost()) && StrUtils.isNotBlank(Settings.getInstance().getProxyPort()) && MathUtils.canParseInt(Settings.getInstance().getProxyPort())) {
res.add("-proxyHost=" + Settings.getInstance().getProxyHost());
res.add("-proxyPort=" + Settings.getInstance().getProxyPort());
if (StrUtils.isNotBlank(Settings.getInstance().getProxyUserName()) && StrUtils.isNotBlank(Settings.getInstance().getProxyPassword())) {
res.add("-proxyUsername=" + Settings.getInstance().getProxyUserName());
res.add("-proxyPassword=" + Settings.getInstance().getProxyPassword());
if (StrUtils.isNotBlank(options.getProxyHost()) && StrUtils.isNotBlank(options.getProxyPort()) && MathUtils.canParseInt(options.getProxyPort())) {
res.add("-proxyHost=" + options.getProxyHost());
res.add("-proxyPort=" + options.getProxyPort());
if (StrUtils.isNotBlank(options.getProxyUser()) && StrUtils.isNotBlank(options.getProxyPass())) {
res.add("-proxyUsername=" + options.getProxyUser());
res.add("-proxyPassword=" + options.getProxyPass());
}
}
if (StrUtils.isNotBlank(v.getMinecraftArgs()))
res.addAll(Arrays.asList(v.getMinecraftArgs().split(" ")));
if (StrUtils.isNotBlank(options.getMinecraftArgs()))
res.addAll(Arrays.asList(options.getMinecraftArgs().split(" ")));
return res;
}
@@ -216,8 +195,4 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
protected void appendJVMArgs(List<String> list) {
}
public Profile getUserVersion() {
return v;
}
}

View File

@@ -20,10 +20,10 @@ package org.jackhuang.hellominecraft.launcher.core.launch;
import java.io.IOException;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.launch.GameLauncher.DownloadLibraryJob;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.auth.LoginInfo;
import org.jackhuang.hellominecraft.launcher.core.Profile;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadLibraryJob;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.tasks.ParallelTask;
import org.jackhuang.hellominecraft.tasks.TaskWindow;
import org.jackhuang.hellominecraft.utils.system.Compressor;
@@ -31,8 +31,8 @@ import org.jackhuang.hellominecraft.utils.MessageBox;
public class DefaultGameLauncher extends GameLauncher {
public DefaultGameLauncher(Profile version, LoginInfo info, IAuthenticator lg) {
super(version, info, lg);
public DefaultGameLauncher(LaunchOptions options, IMinecraftService service, LoginInfo info, IAuthenticator lg) {
super(options, service, info, lg);
register();
}

View File

@@ -33,8 +33,9 @@ import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.auth.LoginInfo;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.core.Profile;
import org.jackhuang.hellominecraft.launcher.core.auth.AuthenticationException;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadLibraryJob;
import org.jackhuang.hellominecraft.launcher.core.version.DecompressLibraryJob;
import org.jackhuang.hellominecraft.utils.system.FileUtils;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
import org.jackhuang.hellominecraft.utils.system.JavaProcess;
@@ -47,8 +48,8 @@ import org.jackhuang.hellominecraft.utils.system.ProcessManager;
public class GameLauncher {
public static final ProcessManager PROCESS_MANAGER = new ProcessManager();
Profile get;
IMinecraftService provider;
LaunchOptions options;
IMinecraftService service;
LoginInfo info;
UserProfileProvider result;
IAuthenticator login;
@@ -57,15 +58,21 @@ public class GameLauncher {
public final EventHandler<JavaProcess> launchEvent = new EventHandler(this);
public final EventHandler<DecompressLibraryJob> decompressNativesEvent = new EventHandler(this);
public GameLauncher(Profile version, LoginInfo info, IAuthenticator lg) {
this.get = version;
this.provider = get.service();
public GameLauncher(LaunchOptions options, IMinecraftService version, LoginInfo info, IAuthenticator lg) {
this.options = options;
this.service = version;
this.info = info;
this.login = lg;
}
public Profile getProfile() {
return get;
private Object tag;
public Object getTag() {
return tag;
}
public void setTag(Object tag) {
this.tag = tag;
}
public IMinecraftLoader makeLaunchCommand() throws AuthenticationException, GameException {
@@ -79,18 +86,18 @@ public class GameLauncher {
throw new AuthenticationException("Result can not be null.");
PluginManager.NOW_PLUGIN.onProcessingLoginResult(result);
loader = provider.version().provideMinecraftLoader(result);
loader = service.launch(options, result);
File file = provider.version().getDecompressNativesToLocation(loader.getMinecraftVersion());
File file = service.version().getDecompressNativesToLocation(loader.getMinecraftVersion());
if (file != null)
FileUtils.cleanDirectoryQuietly(file);
HMCLog.log("Detecting libraries...");
if (!downloadLibrariesEvent.execute(provider.download().getDownloadLibraries(loader.getMinecraftVersion())))
if (!downloadLibrariesEvent.execute(service.download().getDownloadLibraries(loader.getMinecraftVersion())))
throw new GameException("Failed to download libraries");
HMCLog.log("Unpacking natives...");
DecompressLibraryJob job = provider.version().getDecompressLibraries(loader.getMinecraftVersion());
DecompressLibraryJob job = service.version().getDecompressLibraries(loader.getMinecraftVersion());
if (!decompressNativesEvent.execute(job))
throw new GameException("Failed to decompress natives");
@@ -106,10 +113,10 @@ public class GameLauncher {
* @throws IOException failed creating process
*/
public void launch(List str) throws IOException {
if (!provider.version().onLaunch())
if (!service.version().onLaunch())
return;
if (StrUtils.isNotBlank(getProfile().getPrecalledCommand())) {
Process p = Runtime.getRuntime().exec(getProfile().getPrecalledCommand());
if (StrUtils.isNotBlank(options.getPrecalledCommand())) {
Process p = Runtime.getRuntime().exec(options.getPrecalledCommand());
try {
if (p != null && p.isAlive())
p.waitFor();
@@ -119,10 +126,10 @@ public class GameLauncher {
}
HMCLog.log("Starting process");
ProcessBuilder builder = new ProcessBuilder(str);
if (get == null || provider.version().getSelectedVersion() == null || StrUtils.isBlank(get.getCanonicalGameDir()))
if (options.getLaunchVersion() == null || service.baseDirectory() == null)
throw new Error("Fucking bug!");
builder.directory(provider.version().getRunDirectory(provider.version().getSelectedVersion().id))
.environment().put("APPDATA", get.getCanonicalGameDir());
builder.directory(service.version().getRunDirectory(options.getLaunchVersion()))
.environment().put("APPDATA", service.baseDirectory().getAbsolutePath());
JavaProcess jp = new JavaProcess(str, builder.start(), PROCESS_MANAGER);
HMCLog.log("The game process have been started");
launchEvent.execute(jp);
@@ -140,7 +147,7 @@ public class GameLauncher {
*/
public File makeLauncher(String launcherName, List str) throws IOException {
HMCLog.log("Making shell launcher...");
provider.version().onLaunch();
service.version().onLaunch();
boolean isWin = OS.os() == OS.WINDOWS;
File f = new File(launcherName + (isWin ? ".bat" : ".sh"));
if (!f.exists())
@@ -155,14 +162,14 @@ public class GameLauncher {
if (isWin) {
writer.write("@echo off");
writer.newLine();
String appdata = IOUtils.tryGetCanonicalFilePath(get.getCanonicalGameDirFile());
String appdata = IOUtils.tryGetCanonicalFilePath(service.baseDirectory());
if (appdata != null) {
writer.write("set appdata=" + appdata);
writer.newLine();
}
}
if (StrUtils.isNotBlank(getProfile().getPrecalledCommand())) {
writer.write(getProfile().getPrecalledCommand());
if (StrUtils.isNotBlank(options.getPrecalledCommand())) {
writer.write(options.getPrecalledCommand());
writer.newLine();
}
writer.write(StrUtils.makeCommand(str));
@@ -179,29 +186,4 @@ public class GameLauncher {
return f;
}
public static class DownloadLibraryJob {
String url, name;
File path;
public DownloadLibraryJob(String n, String u, File p) {
url = u;
name = n;
path = IOUtils.tryGetCanonicalFile(p);
}
}
public static class DecompressLibraryJob {
File[] decompressFiles;
String[][] extractRules;
File decompressTo;
public DecompressLibraryJob(File[] decompressFiles, String[][] extractRules, File decompressTo) {
this.decompressFiles = decompressFiles;
this.extractRules = extractRules;
this.decompressTo = decompressTo;
}
}
}

View File

@@ -0,0 +1,240 @@
/*
* 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.core.launch;
import java.io.File;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.version.GameDirType;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.utils.system.JdkVersion;
/**
*
* @author huangyuhui
*/
public class LaunchOptions {
private String name, versionName, javaArgs, minecraftArgs, maxMemory, permSize, width, height, userProperties, serverIp;
private String proxyHost, proxyPort, proxyUser, proxyPass, javaDir, launchVersion;
private boolean fullscreen, debug, noJVMArgs, canceledWrapper;
private JdkVersion java;
private File gameDir;
private GameDirType gameDirType;
protected transient IMinecraftService service;
public String getVersionName() {
return versionName;
}
public void setVersionName(String versionName) {
this.versionName = versionName;
}
public File getGameDir() {
return gameDir;
}
public void setGameDir(File gameDir) {
this.gameDir = gameDir;
}
public void setJavaDir(String javaDir) {
this.javaDir = javaDir;
}
public String getJavaDir() {
return javaDir;
}
public JdkVersion getJava() {
return java;
}
public void setJava(JdkVersion java) {
this.java = java;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getJavaArgs() {
return javaArgs;
}
public void setJavaArgs(String javaArgs) {
this.javaArgs = javaArgs;
}
public boolean hasJavaArgs() {
return StrUtils.isNotBlank(getJavaArgs().trim());
}
public String getMaxMemory() {
return maxMemory;
}
public void setMaxMemory(String maxMemory) {
this.maxMemory = maxMemory;
}
public String getWidth() {
return width;
}
public void setWidth(String width) {
this.width = width;
}
public String getHeight() {
return height;
}
public void setHeight(String height) {
this.height = height;
}
public String getUserProperties() {
if (userProperties == null)
return "";
return userProperties;
}
public void setUserProperties(String userProperties) {
this.userProperties = userProperties;
}
public boolean isFullscreen() {
return fullscreen;
}
public void setFullscreen(boolean fullscreen) {
this.fullscreen = fullscreen;
}
public boolean isDebug() {
return debug;
}
public void setDebug(boolean debug) {
this.debug = debug;
}
public GameDirType getGameDirType() {
return gameDirType;
}
public void setGameDirType(GameDirType gameDirType) {
this.gameDirType = gameDirType;
}
public String getPermSize() {
return permSize;
}
public void setPermSize(String permSize) {
this.permSize = permSize;
}
public boolean isNoJVMArgs() {
return noJVMArgs;
}
public void setNoJVMArgs(boolean noJVMArgs) {
this.noJVMArgs = noJVMArgs;
}
public String getMinecraftArgs() {
return minecraftArgs;
}
public void setMinecraftArgs(String minecraftArgs) {
this.minecraftArgs = minecraftArgs;
}
public boolean isCanceledWrapper() {
return canceledWrapper;
}
public void setCanceledWrapper(boolean canceledWrapper) {
this.canceledWrapper = canceledWrapper;
}
public String getServerIp() {
return serverIp;
}
public void setServerIp(String serverIp) {
this.serverIp = serverIp;
}
public String getProxyHost() {
return proxyHost;
}
public void setProxyHost(String proxyHost) {
this.proxyHost = proxyHost;
}
public String getProxyPort() {
return proxyPort;
}
public void setProxyPort(String proxyPort) {
this.proxyPort = proxyPort;
}
public String getProxyUser() {
return proxyUser;
}
public void setProxyUser(String proxyUser) {
this.proxyUser = proxyUser;
}
public String getProxyPass() {
return proxyPass;
}
public void setProxyPass(String proxyPass) {
this.proxyPass = proxyPass;
}
private String precalledCommand;
public String getPrecalledCommand() {
return precalledCommand;
}
public void setPrecalledCommand(String precalledCommand) {
this.precalledCommand = precalledCommand;
}
public String getLaunchVersion() {
return launchVersion;
}
public void setLaunchVersion(String launchVersion) {
this.launchVersion = launchVersion;
}
}

View File

@@ -29,6 +29,7 @@ import java.util.jar.JarOutputStream;
import java.util.jar.Pack200;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadLibraryJob;
import org.jackhuang.hellominecraft.tasks.download.FileDownloadTask;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
import org.tukaani.xz.XZInputStream;
@@ -39,9 +40,9 @@ import org.tukaani.xz.XZInputStream;
*/
public class LibraryDownloadTask extends FileDownloadTask {
GameLauncher.DownloadLibraryJob job;
DownloadLibraryJob job;
public LibraryDownloadTask(GameLauncher.DownloadLibraryJob job) {
public LibraryDownloadTask(DownloadLibraryJob job) {
super();
this.job = job;
}

View File

@@ -49,28 +49,27 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
DownloadType dt;
String text;
public MinecraftLoader(IMinecraftService provider, UserProfileProvider lr) throws GameException {
super(provider.profile, provider, lr);
public MinecraftLoader(LaunchOptions p, IMinecraftService provider, UserProfileProvider lr) throws GameException {
super(p, provider, p.getLaunchVersion(), lr);
}
@Override
protected void makeSelf(List<String> res) {
String library = v.isCanceledWrapper() ? "" : "-cp=";
String library = options.isCanceledWrapper() ? "" : "-cp=";
for (MinecraftLibrary l : version.libraries) {
l.init();
if (l.allow() && !l.isRequiredToUnzip())
library += l.getFilePath(gameDir).getAbsolutePath() + File.pathSeparator;
}
library += IOUtils.tryGetCanonicalFilePath(version.getJar(v.getCanonicalGameDirFile())) + File.pathSeparator;
library += IOUtils.tryGetCanonicalFilePath(version.getJar(service.baseDirectory())) + File.pathSeparator;
library = library.substring(0, library.length() - File.pathSeparator.length());
if (v.isCanceledWrapper())
if (options.isCanceledWrapper())
res.add("-cp");
res.add(library);
String mainClass = version.mainClass;
res.add((v.isCanceledWrapper() ? "" : "-mainClass=") + mainClass);
res.add((options.isCanceledWrapper() ? "" : "-mainClass=") + mainClass);
String arg = service.version().getSelectedVersion().minecraftArguments;
String[] splitted = StrUtils.tokenize(arg);
String[] splitted = StrUtils.tokenize(version.minecraftArguments);
if (!checkAssetsExist())
if (MessageBox.Show(C.i18n("assets.no_assets"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
@@ -86,7 +85,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
t = t.replace("${auth_session}", lr.getSession());
t = t.replace("${auth_uuid}", lr.getUserId());
t = t.replace("${version_name}", Main.makeTitle());
t = t.replace("${profile_name}", v.getName());
t = t.replace("${profile_name}", options.getName());
t = t.replace("${game_directory}", service.version().getRunDirectory(version.id).getAbsolutePath());
t = t.replace("${game_assets}", game_assets);
t = t.replace("${assets_root}", service.asset().getAssets().getAbsolutePath());
@@ -118,7 +117,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
}
private boolean checkAssetsExist() {
File assetsDir = new File(service.baseFolder, "assets");
File assetsDir = new File(service.baseDirectory(), "assets");
File indexDir = new File(assetsDir, "indexes");
File objectDir = new File(assetsDir, "objects");
File indexFile = new File(indexDir, version.getAssets() + ".json");
@@ -141,7 +140,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
}
private File reconstructAssets() {
File assetsDir = new File(service.baseFolder, "assets");
File assetsDir = new File(service.baseDirectory(), "assets");
File indexDir = new File(assetsDir, "indexes");
File objectDir = new File(assetsDir, "objects");
String assetVersion = version.getAssets();

View File

@@ -27,8 +27,8 @@ import org.jackhuang.hellominecraft.tasks.Task;
*/
public abstract class IMinecraftAssetService extends IMinecraftBasicService {
public IMinecraftAssetService(IMinecraftService profile) {
super(profile);
public IMinecraftAssetService(IMinecraftService service) {
super(service);
}
public abstract Task downloadAssets(String mcVersion);

View File

@@ -19,8 +19,7 @@ package org.jackhuang.hellominecraft.launcher.core.service;
import java.util.List;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.launch.GameLauncher;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadLibraryJob;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.version.MinecraftRemoteVersion;
import rx.Observable;
@@ -31,8 +30,8 @@ import rx.Observable;
*/
public abstract class IMinecraftDownloadService extends IMinecraftBasicService {
public IMinecraftDownloadService(IMinecraftService profile) {
super(profile);
public IMinecraftDownloadService(IMinecraftService service) {
super(service);
}
public abstract MinecraftVersion downloadMinecraft(String id);
@@ -46,7 +45,7 @@ public abstract class IMinecraftDownloadService extends IMinecraftBasicService {
*
* @return the library collection
*/
public abstract List<GameLauncher.DownloadLibraryJob> getDownloadLibraries(MinecraftVersion mv) throws GameException;
public abstract List<DownloadLibraryJob> getDownloadLibraries(MinecraftVersion mv) throws GameException;
public abstract Observable<MinecraftRemoteVersion> getRemoteVersions();

View File

@@ -17,8 +17,6 @@
*/
package org.jackhuang.hellominecraft.launcher.core.service;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftBasicService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerType;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionList;
import org.jackhuang.hellominecraft.tasks.Task;
@@ -33,12 +31,12 @@ public abstract class IMinecraftInstallerService extends IMinecraftBasicService
super(service);
}
public abstract Task download(InstallerVersionList.InstallerVersion v, InstallerType type);
public abstract Task download(String installId, InstallerVersionList.InstallerVersion v, InstallerType type);
public abstract Task downloadForge(InstallerVersionList.InstallerVersion v);
public abstract Task downloadForge(String installId, InstallerVersionList.InstallerVersion v);
public abstract Task downloadOptifine(InstallerVersionList.InstallerVersion v);
public abstract Task downloadOptifine(String installId, InstallerVersionList.InstallerVersion v);
public abstract Task downloadLiteLoader(InstallerVersionList.InstallerVersion v);
public abstract Task downloadLiteLoader(String installId, InstallerVersionList.InstallerVersion v);
}

View File

@@ -18,6 +18,7 @@
package org.jackhuang.hellominecraft.launcher.core.service;
import java.util.List;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
/**
@@ -28,5 +29,5 @@ public interface IMinecraftLoader {
MinecraftVersion getMinecraftVersion();
List<String> makeLaunchingCommand();
List<String> makeLaunchingCommand() throws GameException;
}

View File

@@ -27,15 +27,15 @@ import org.jackhuang.hellominecraft.launcher.core.ModInfo;
*/
public abstract class IMinecraftModService extends IMinecraftBasicService {
public IMinecraftModService(IMinecraftService profile) {
super(profile);
public IMinecraftModService(IMinecraftService service) {
super(service);
}
public abstract List<ModInfo> getMods();
public abstract List<ModInfo> getMods(String id);
public abstract List<ModInfo> recacheMods();
public abstract List<ModInfo> recacheMods(String id);
public abstract boolean addMod(File f);
public abstract boolean addMod(String id, File f);
public abstract void removeMod(Object[] mods);
public abstract void removeMod(String id, Object[] mods);
}

View File

@@ -20,16 +20,16 @@ package org.jackhuang.hellominecraft.launcher.core.service;
import java.io.File;
import java.util.Collection;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.launch.GameLauncher;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.core.version.DecompressLibraryJob;
import org.jackhuang.hellominecraft.launcher.core.version.GameDirType;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.utils.functions.Consumer;
/**
* Provide everything of the Minecraft of a Profile.
*
* @see org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersionManager
* @see
* org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersionManager
* @author huangyuhui
*/
public abstract class IMinecraftProvider {
@@ -67,7 +67,7 @@ public abstract class IMinecraftProvider {
*
* @return Is the action successful?
*/
public abstract boolean install(String version);
public abstract boolean install(String version, Consumer<MinecraftVersion> callback);
/**
* Returns the thing like ".minecraft/resourcepacks".
@@ -82,31 +82,14 @@ public abstract class IMinecraftProvider {
*
* @return libraries of resolved minecraft version v.
*/
public abstract GameLauncher.DecompressLibraryJob getDecompressLibraries(MinecraftVersion v) throws GameException;
public abstract DecompressLibraryJob getDecompressLibraries(MinecraftVersion v) throws GameException;
public abstract File getDecompressNativesToLocation(MinecraftVersion v);
/**
* @return the Minecraft jar of selected version.
*/
public abstract File getMinecraftJar();
/**
* @return the base folder of the profile.
*/
public abstract File getBaseFolder();
/**
* Provide the Minecraft Loader to generate the launching command.
*
* @see org.jackhuang.hellominecraft.launcher.core.service.IMinecraftLoader
* @param p player informations, including username & auth_token
*
* @return what you want
*
* @throws GameException circular denpendency versions
*/
public abstract IMinecraftLoader provideMinecraftLoader(UserProfileProvider p) throws GameException;
public abstract File getMinecraftJar(String id);
protected GameDirType gameDirType = GameDirType.ROOT_FOLDER;
@@ -156,18 +139,6 @@ public abstract class IMinecraftProvider {
*/
public abstract MinecraftVersion getVersionById(String id);
public MinecraftVersion getSelectedVersion() {
String versionName = service.profile.getSelectedMinecraftVersionName();
MinecraftVersion v = null;
if (StrUtils.isNotBlank(versionName))
v = getVersionById(versionName);
if (v == null)
v = getOneVersion();
if (v != null)
service.profile.setSelectedMinecraftVersion(v.id);
return v;
}
/**
* getVersions().size()
*

View File

@@ -18,9 +18,10 @@
package org.jackhuang.hellominecraft.launcher.core.service;
import java.io.File;
import org.jackhuang.hellominecraft.launcher.core.Profile;
import org.jackhuang.hellominecraft.launcher.settings.Settings;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
import org.jackhuang.hellominecraft.launcher.core.launch.LaunchOptions;
/**
*
@@ -28,13 +29,7 @@ import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
*/
public abstract class IMinecraftService {
public final Profile profile;
public final File baseFolder;
public IMinecraftService(Profile profile) {
this.profile = profile;
this.baseFolder = profile.getCanonicalGameDirFile();
}
public abstract File baseDirectory();
public DownloadType getDownloadType() {
return DownloadType.getSuggestedDownloadType();
@@ -50,4 +45,16 @@ public abstract class IMinecraftService {
public abstract IMinecraftInstallerService install();
/**
* Provide the Minecraft Loader to generate the launching command.
*
* @see org.jackhuang.hellominecraft.launcher.core.service.IMinecraftLoader
* @param p player informations, including username & auth_token
*
* @return what you want
*
* @throws GameException circular denpendency versions
*/
public abstract IMinecraftLoader launch(LaunchOptions options, UserProfileProvider p) throws GameException;
}

View File

@@ -0,0 +1,38 @@
/*
* 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.core.version;
import java.io.File;
/**
*
* @author huangyuhui
*/
public class DecompressLibraryJob {
public File[] decompressFiles;
public String[][] extractRules;
public File decompressTo;
public DecompressLibraryJob(File[] decompressFiles, String[][] extractRules, File decompressTo) {
this.decompressFiles = decompressFiles;
this.extractRules = extractRules;
this.decompressTo = decompressTo;
}
}

View File

@@ -22,7 +22,9 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftModService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
@@ -36,25 +38,23 @@ import org.jackhuang.hellominecraft.utils.system.FileUtils;
*/
public class MinecraftModService extends IMinecraftModService {
List<ModInfo> modCache;
Map<String, List<ModInfo>> modCache = Collections.synchronizedMap(new HashMap<>());
public MinecraftModService(IMinecraftService profile) {
super(profile);
public MinecraftModService(IMinecraftService service) {
super(service);
}
@Override
public List<ModInfo> getMods() {
if (modCache == null)
return recacheMods();
public List<ModInfo> getMods(String id) {
if (modCache.containsKey(id))
return modCache.get(id);
else
return modCache;
return recacheMods(id);
}
@Override
public List<ModInfo> recacheMods() {
if (service.version().getSelectedVersion() == null)
return modCache = new ArrayList<>();
File modsFolder = service.version().getRunDirectory(service.version().getSelectedVersion().id, "mods");
public List<ModInfo> recacheMods(String id) {
File modsFolder = service.version().getRunDirectory(id, "mods");
ArrayList<ModInfo> mods = new ArrayList<>();
File[] fs = modsFolder.listFiles();
if (fs != null)
@@ -74,24 +74,22 @@ public class MinecraftModService extends IMinecraftModService {
}
}
Collections.sort(mods);
return modCache = mods;
return modCache.put(id, mods);
}
@Override
public boolean addMod(File f) {
public boolean addMod(String id, File f) {
try {
if (service.version().getSelectedVersion() == null)
return false;
if (!ModInfo.isFileMod(f))
return false;
File modsFolder = service.version().getRunDirectory(service.version().getSelectedVersion().id, "mods");
File modsFolder = service.version().getRunDirectory(id, "mods");
if (modsFolder == null)
return false;
modsFolder.mkdirs();
File newf = new File(modsFolder, f.getName());
FileUtils.copyFile(f, newf);
ModInfo i = ModInfo.readModInfo(f);
modCache.add(i);
modCache.get(id).add(i);
return true;
} catch (IOException ex) {
HMCLog.warn("Failed to copy mod", ex);
@@ -100,21 +98,21 @@ public class MinecraftModService extends IMinecraftModService {
}
@Override
public void removeMod(Object[] rows) {
public void removeMod(String id, Object[] rows) {
if (rows.length == 0)
return;
for (Object r : rows)
if (r instanceof ModInfo)
((ModInfo) r).location.delete();
else if (r instanceof Number)
getMods().get(((Number) r).intValue()).location.delete();
recacheMods();
getMods(id).get(((Number) r).intValue()).location.delete();
recacheMods(id);
}
public String[] checkMd5s() throws IOException {
String[] res = new String[getMods().size()];
public String[] checkMd5s(String id) throws IOException {
String[] res = new String[getMods(id).size()];
for (int i = 0; i < res.length; i++)
res[i] = DigestUtils.md5Hex(new FileInputStream(getMods().get(i).location));
res[i] = DigestUtils.md5Hex(new FileInputStream(getMods(id).get(i).location));
return res;
}

View File

@@ -35,7 +35,7 @@ import org.jackhuang.hellominecraft.utils.ArrayUtils;
public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion> {
public String minecraftArguments, mainClass, time, id, type, processArguments,
releaseTime, assets, jar, inheritsFrom;
releaseTime, assets, jar, inheritsFrom, runDir;
public int minimumLauncherVersion;
public boolean hidden;
@@ -44,7 +44,7 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
public MinecraftVersion() {
}
public MinecraftVersion(String minecraftArguments, String mainClass, String time, String id, String type, String processArguments, String releaseTime, String assets, String jar, String inheritsFrom, int minimumLauncherVersion, List<MinecraftLibrary> libraries, boolean hidden) {
public MinecraftVersion(String minecraftArguments, String mainClass, String time, String id, String type, String processArguments, String releaseTime, String assets, String jar, String inheritsFrom, String runDir, int minimumLauncherVersion, List<MinecraftLibrary> libraries, boolean hidden) {
this();
this.minecraftArguments = minecraftArguments;
this.mainClass = mainClass;
@@ -58,6 +58,7 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
this.inheritsFrom = inheritsFrom;
this.minimumLauncherVersion = minimumLauncherVersion;
this.hidden = hidden;
this.runDir = runDir;
if (libraries == null)
this.libraries = new ArrayList<>();
else {
@@ -69,7 +70,7 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
@Override
public Object clone() {
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, runDir, minimumLauncherVersion, libraries, hidden);
}
public MinecraftVersion resolve(IMinecraftProvider provider) throws GameException {
@@ -84,7 +85,7 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
MinecraftVersion parent = provider.getVersionById(inheritsFrom);
if (parent == null) {
if (!provider.install(inheritsFrom))
if (!provider.install(inheritsFrom, t -> t.hidden = true))
return this;
parent = provider.getVersionById(inheritsFrom);
}
@@ -95,7 +96,7 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
this.time, this.id, this.type, parent.processArguments, this.releaseTime,
this.assets != null ? this.assets : parent.assets,
this.jar != null ? this.jar : parent.jar,
null, parent.minimumLauncherVersion,
null, this.runDir, parent.minimumLauncherVersion,
this.libraries != null ? ArrayUtils.merge(this.libraries, parent.libraries) : parent.libraries, this.hidden);
return result;

View File

@@ -27,19 +27,16 @@ import java.util.TreeMap;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.launch.GameLauncher;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftLoader;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftProvider;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.launch.MinecraftLoader;
import org.jackhuang.hellominecraft.utils.system.FileUtils;
import org.jackhuang.hellominecraft.launcher.core.MCUtils;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.tasks.DecompressTask;
import org.jackhuang.hellominecraft.tasks.TaskWindow;
import org.jackhuang.hellominecraft.tasks.download.FileDownloadTask;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
import org.jackhuang.hellominecraft.utils.MessageBox;
import org.jackhuang.hellominecraft.utils.functions.Consumer;
import org.jackhuang.hellominecraft.views.SwingUtils;
/**
@@ -48,7 +45,6 @@ import org.jackhuang.hellominecraft.views.SwingUtils;
*/
public class MinecraftVersionManager extends IMinecraftProvider {
File baseFolder;
final Map<String, MinecraftVersion> versions = new TreeMap();
/**
@@ -59,10 +55,6 @@ public class MinecraftVersionManager extends IMinecraftProvider {
super(p);
}
public File getFolder() {
return baseFolder;
}
@Override
public Collection<MinecraftVersion> getVersions() {
return versions.values();
@@ -75,21 +67,20 @@ public class MinecraftVersionManager extends IMinecraftProvider {
@Override
public void refreshVersions() {
baseFolder = service.profile.getCanonicalGameDirFile();
try {
MCUtils.tryWriteProfile(baseFolder);
MCUtils.tryWriteProfile(service.baseDirectory());
} catch (IOException ex) {
HMCLog.warn("Failed to create launcher_profiles.json, Forge/LiteLoader installer will not work.", ex);
}
versions.clear();
File oldDir = new File(baseFolder, "bin");
File oldDir = new File(service.baseDirectory(), "bin");
if (oldDir.exists()) {
MinecraftClassicVersion v = new MinecraftClassicVersion();
versions.put(v.id, v);
}
File version = new File(baseFolder, "versions");
File version = new File(service.baseDirectory(), "versions");
File[] files = version.listFiles();
if (files == null || files.length == 0)
return;
@@ -156,7 +147,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
@Override
public boolean removeVersionFromDisk(String name) {
File version = new File(baseFolder, "versions/" + name);
File version = new File(service.baseDirectory(), "versions/" + name);
if (!version.exists())
return true;
@@ -167,12 +158,12 @@ public class MinecraftVersionManager extends IMinecraftProvider {
@Override
public boolean renameVersion(String from, String to) {
try {
File fromJson = new File(baseFolder, "versions/" + from + "/" + from + ".json");
File fromJson = new File(service.baseDirectory(), "versions/" + from + "/" + from + ".json");
MinecraftVersion mcVersion = C.gson.fromJson(FileUtils.readFileToString(fromJson), MinecraftVersion.class);
mcVersion.id = to;
FileUtils.writeQuietly(fromJson, C.gsonPrettyPrinting.toJson(mcVersion));
File toDir = new File(baseFolder, "versions/" + to);
new File(baseFolder, "versions/" + from).renameTo(toDir);
File toDir = new File(service.baseDirectory(), "versions/" + to);
new File(service.baseDirectory(), "versions/" + from).renameTo(toDir);
File toJson = new File(toDir, to + ".json");
File toJar = new File(toDir, to + ".jar");
new File(toDir, from + ".json").renameTo(toJson);
@@ -188,17 +179,24 @@ public class MinecraftVersionManager extends IMinecraftProvider {
@Override
public File getRunDirectory(String id) {
if ("version".equals(versions.get(id).runDir))
return new File(service.baseDirectory(), "versions/" + id + "/");
switch (gameDirType) {
case VERSION_FOLDER:
return new File(baseFolder, "versions/" + id + "/");
return new File(service.baseDirectory(), "versions/" + id + "/");
default:
return baseFolder;
return service.baseDirectory();
}
}
@Override
public boolean install(String id) {
public boolean install(String id, Consumer<MinecraftVersion> callback) {
MinecraftVersion v = service.download().downloadMinecraft(id);
if (callback != null) {
callback.accept(v);
File mvt = new File(service.baseDirectory(), "versions/" + id + "/" + id + ".json");
FileUtils.writeQuietly(mvt, C.gsonPrettyPrinting.toJson(v));
}
if (v != null) {
refreshVersions();
return true;
@@ -212,7 +210,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
}
@Override
public GameLauncher.DecompressLibraryJob getDecompressLibraries(MinecraftVersion v) throws GameException {
public DecompressLibraryJob getDecompressLibraries(MinecraftVersion v) throws GameException {
if (v.libraries == null)
throw new GameException("Wrong format: minecraft.json");
ArrayList<File> unzippings = new ArrayList<>();
@@ -220,27 +218,21 @@ public class MinecraftVersionManager extends IMinecraftProvider {
for (IMinecraftLibrary l : v.libraries) {
l.init();
if (l.isRequiredToUnzip() && v.isAllowedToUnpackNatives()) {
unzippings.add(IOUtils.tryGetCanonicalFile(l.getFilePath(baseFolder)));
unzippings.add(IOUtils.tryGetCanonicalFile(l.getFilePath(service.baseDirectory())));
extractRules.add(l.getDecompressExtractRules());
}
}
return new GameLauncher.DecompressLibraryJob(unzippings.toArray(new File[0]), extractRules.toArray(new String[0][]), getDecompressNativesToLocation(v));
return new DecompressLibraryJob(unzippings.toArray(new File[0]), extractRules.toArray(new String[0][]), getDecompressNativesToLocation(v));
}
@Override
public File getDecompressNativesToLocation(MinecraftVersion v) {
return v == null ? null : v.getNatives(baseFolder);
return v == null ? null : v.getNatives(service.baseDirectory());
}
@Override
public File getMinecraftJar() {
return getSelectedVersion().getJar(baseFolder);
}
@Override
public IMinecraftLoader provideMinecraftLoader(UserProfileProvider p)
throws GameException {
return new MinecraftLoader(service, p);
public File getMinecraftJar(String id) {
return versions.get(id).getJar(service.baseDirectory());
}
@Override
@@ -255,12 +247,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
@Override
public File getResourcePacks() {
return new File(baseFolder, "resourcepacks");
}
@Override
public File getBaseFolder() {
return baseFolder;
return new File(service.baseDirectory(), "resourcepacks");
}
@Override
@@ -274,7 +261,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
@Override
public void cleanFolder() {
for (MinecraftVersion s : getVersions()) {
FileUtils.deleteDirectoryQuietly(new File(baseFolder, "versions" + File.separator + s.id + File.separator + s.id + "-natives"));
FileUtils.deleteDirectoryQuietly(new File(service.baseDirectory(), "versions" + File.separator + s.id + File.separator + s.id + "-natives"));
File f = getRunDirectory(s.id);
String[] dir = { "logs", "asm", "NVIDIA", "crash-reports", "server-resource-packs", "natives", "native" };
for (String str : dir)
@@ -292,6 +279,6 @@ public class MinecraftVersionManager extends IMinecraftProvider {
private void downloadModpack(String url) throws IOException {
File tmp = File.createTempFile("hmcl", ".zip");
TaskWindow.getInstance().addTask(new FileDownloadTask(url, tmp)).addTask(new DecompressTask(tmp, baseFolder)).start();
TaskWindow.getInstance().addTask(new FileDownloadTask(url, tmp)).addTask(new DecompressTask(tmp, service.baseDirectory())).start();
}
}

View File

@@ -17,7 +17,6 @@
*/
package org.jackhuang.hellominecraft.launcher.settings;
import org.jackhuang.hellominecraft.launcher.core.Profile;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;

View File

@@ -17,10 +17,9 @@
*/
package org.jackhuang.hellominecraft.launcher.settings;
import org.jackhuang.hellominecraft.launcher.core.service.DefaultMinecraftService;
import org.jackhuang.hellominecraft.launcher.utils.DefaultMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.api.IPlugin;
import org.jackhuang.hellominecraft.launcher.core.Profile;
import org.jackhuang.hellominecraft.launcher.settings.Settings;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.auth.OfflineAuthenticator;

View File

@@ -15,10 +15,17 @@
* 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.core;
package org.jackhuang.hellominecraft.launcher.settings;
import java.io.File;
import java.io.IOException;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.Main;
import org.jackhuang.hellominecraft.launcher.api.PluginManager;
import org.jackhuang.hellominecraft.launcher.core.LauncherVisibility;
import org.jackhuang.hellominecraft.launcher.core.MCUtils;
import org.jackhuang.hellominecraft.launcher.core.launch.LaunchOptions;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
import org.jackhuang.hellominecraft.launcher.core.version.GameDirType;
@@ -26,6 +33,7 @@ import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.utils.Utils;
import org.jackhuang.hellominecraft.utils.EventHandler;
import org.jackhuang.hellominecraft.utils.system.Java;
import org.jackhuang.hellominecraft.utils.system.JdkVersion;
import org.jackhuang.hellominecraft.utils.system.OS;
/**
@@ -101,10 +109,20 @@ public final class Profile {
return service;
}
public String getSelectedMinecraftVersionName() {
public String getSettingsSelectedMinecraftVersion() {
return selectedMinecraftVersion;
}
public String getSelectedVersion() {
String v = selectedMinecraftVersion;
if (v == null) {
v = service.version().getOneVersion().id;
if (v != null)
setSelectedMinecraftVersion(v);
}
return v;
}
public transient final EventHandler<String> selectedVersionChangedEvent = new EventHandler<>(this);
public void setSelectedMinecraftVersion(String selectedMinecraftVersion) {
@@ -187,9 +205,9 @@ public final class Profile {
}
public File getFolder(String folder) {
if (service().version().getSelectedVersion() == null)
if (getSelectedVersion() == null)
return new File(getCanonicalGameDirFile(), folder);
return service().version().getRunDirectory(service().version().getSelectedVersion().id, folder);
return service().version().getRunDirectory(getSelectedVersion(), folder);
}
public String getName() {
@@ -356,4 +374,52 @@ public final class Profile {
public void checkFormat() {
gameDir = gameDir.replace('/', OS.os().fileSeparator).replace('\\', OS.os().fileSeparator);
}
public LaunchOptions createLaunchOptions() {
LaunchOptions x = new LaunchOptions();
x.setCanceledWrapper(isCanceledWrapper());
x.setDebug(isDebug());
x.setFullscreen(isFullscreen());
x.setGameDir(getCanonicalGameDirFile());
x.setGameDirType(getGameDirType());
x.setHeight(getHeight());
x.setJavaArgs(getJavaArgs());
x.setLaunchVersion(getSelectedVersion());
x.setMaxMemory(getMaxMemory());
x.setMinecraftArgs(getMinecraftArgs());
x.setName(getName());
x.setNoJVMArgs(isNoJVMArgs());
x.setPermSize(getPermSize());
x.setPrecalledCommand(getPrecalledCommand());
x.setProxyHost(Settings.getInstance().getProxyHost());
x.setProxyPort(Settings.getInstance().getProxyPort());
x.setProxyUser(Settings.getInstance().getProxyUserName());
x.setProxyPass(Settings.getInstance().getProxyPassword());
x.setServerIp(getServerIp());
x.setUserProperties(getUserProperties());
x.setVersionName(Main.makeTitle());
x.setWidth(getWidth());
String str = getJavaDir();
if (!getJavaDirFile().exists()) {
HMCLog.err(C.i18n("launch.wrong_javadir"));
setJava(null);
str = getJavaDir();
}
JdkVersion jv = new JdkVersion(str);
if (Settings.getInstance().getJava().contains(jv))
jv = Settings.getInstance().getJava().get(Settings.getInstance().getJava().indexOf(jv));
else
try {
jv = JdkVersion.getJavaVersionFromExecutable(str);
Settings.getInstance().getJava().add(jv);
Settings.save();
} catch (IOException ex) {
HMCLog.warn("Failed to get java version", ex);
jv = null;
}
x.setJava(jv);
x.setJavaDir(str);
return x;
}
}

View File

@@ -17,7 +17,6 @@
*/
package org.jackhuang.hellominecraft.launcher.settings;
import org.jackhuang.hellominecraft.launcher.core.Profile;
import com.google.gson.JsonSyntaxException;
import java.io.File;
import java.io.IOException;

View File

@@ -15,12 +15,24 @@
* 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.core.service;
package org.jackhuang.hellominecraft.launcher.utils;
import org.jackhuang.hellominecraft.launcher.core.Profile;
import java.io.File;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.settings.Profile;
import org.jackhuang.hellominecraft.launcher.core.installers.MinecraftInstallerService;
import org.jackhuang.hellominecraft.launcher.core.assets.MinecraftAssetService;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.core.download.MinecraftDownloadService;
import org.jackhuang.hellominecraft.launcher.core.launch.LaunchOptions;
import org.jackhuang.hellominecraft.launcher.core.launch.MinecraftLoader;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftAssetService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftDownloadService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftInstallerService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftLoader;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftModService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftProvider;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftModService;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersionManager;
@@ -30,8 +42,11 @@ import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersionManage
*/
public class DefaultMinecraftService extends IMinecraftService {
File base;
Profile p;
public DefaultMinecraftService(Profile p) {
super(p);
this.p = p;
this.provider = new MinecraftVersionManager(this);
provider.initializeMiencraft();
this.mms = new MinecraftModService(this);
@@ -40,6 +55,11 @@ public class DefaultMinecraftService extends IMinecraftService {
this.mis = new MinecraftInstallerService(this);
}
@Override
public File baseDirectory() {
return p.getCanonicalGameDirFile();
}
protected IMinecraftProvider provider;
@Override
@@ -75,4 +95,9 @@ public class DefaultMinecraftService extends IMinecraftService {
return mis;
}
@Override
public IMinecraftLoader launch(LaunchOptions options, UserProfileProvider p) throws GameException {
return new MinecraftLoader(options, this, p);
}
}

View File

@@ -44,7 +44,7 @@ import javax.swing.table.DefaultTableModel;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.LauncherVisibility;
import org.jackhuang.hellominecraft.launcher.core.Profile;
import org.jackhuang.hellominecraft.launcher.settings.Profile;
import org.jackhuang.hellominecraft.launcher.settings.Settings;
import org.jackhuang.hellominecraft.launcher.utils.FileNameFilter;
import org.jackhuang.hellominecraft.launcher.core.ModInfo;
@@ -174,7 +174,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
}
lstExternalMods.getSelectionModel().addListSelectionListener(e -> {
int row = lstExternalMods.getSelectedRow();
List<ModInfo> mods = getProfile().service().mod().getMods();
List<ModInfo> mods = getProfile().service().mod().getMods(getProfile().getSelectedVersion());
if (mods != null && 0 <= row && row < mods.size()) {
ModInfo m = mods.get(row);
boolean hasLink = m.url != null;
@@ -194,7 +194,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
((DefaultTableModel) lstExternalMods.getModel()).addTableModelListener(e -> {
if (e.getType() == TableModelEvent.UPDATE && e.getColumn() == 0) {
int row = lstExternalMods.getSelectedRow();
List<ModInfo> mods = getProfile().service().mod().getMods();
List<ModInfo> mods = getProfile().service().mod().getMods(getProfile().getSelectedVersion());
if (mods != null && mods.size() > row && row >= 0)
mods.get(row).reverseModState();
}
@@ -1061,14 +1061,14 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
return;
boolean flag = true;
for (File f : fc.getSelectedFiles())
flag &= getProfile().service().mod().addMod(f);
flag &= getProfile().service().mod().addMod(getProfile().getSelectedVersion(), f);
reloadMods();
if (!flag)
MessageBox.Show(C.I18N.getString("mods.failed"));
}//GEN-LAST:event_btnAddModActionPerformed
private void btnRemoveModActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveModActionPerformed
getProfile().service().mod().removeMod(SwingUtils.getValueBySelectedRow(lstExternalMods, lstExternalMods.getSelectedRows(), 1));
getProfile().service().mod().removeMod(getProfile().getSelectedVersion(), SwingUtils.getValueBySelectedRow(lstExternalMods, lstExternalMods.getSelectedRows(), 1));
reloadMods();
}//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
int idx = lstExternalMods.getSelectedRow();
if (idx > 0 && idx < getProfile().service().mod().getMods().size())
SwingUtils.openLink(getProfile().service().mod().getMods().get(idx).url);
if (idx > 0 && idx < getProfile().service().mod().getMods(getProfile().getSelectedVersion()).size())
SwingUtils.openLink(getProfile().service().mod().getMods(getProfile().getSelectedVersion()).get(idx).url);
}//GEN-LAST:event_lblModInfoMouseClicked
private void btnChoosingGameDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChoosingGameDirActionPerformed
@@ -1165,8 +1165,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
isLoading = true;
cboVersions.removeAllItems();
int index = 0, i = 0;
MinecraftVersion selVersion = getProfile().service().version().getSelectedVersion();
String selectedMC = selVersion == null ? null : selVersion.id;
String selectedMC = getProfile().getSelectedVersion();
for (MinecraftVersion each : getProfile().service().version().getVersions()) {
cboVersions.addItem(each.id);
if (StrUtils.isEquals(each.id, selectedMC))
@@ -1181,18 +1180,18 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
}
void loadMinecraftVersion() {
loadMinecraftVersion(getProfile().service().version().getSelectedVersion());
loadMinecraftVersion(getProfile().getSelectedVersion());
}
/**
* Anaylze the jar of selected minecraft version of current getProfile() to
* get the version.
*/
void loadMinecraftVersion(MinecraftVersion v) {
void loadMinecraftVersion(String id) {
txtMinecraftVersion.setText("");
if (v == null)
if (id == null)
return;
minecraftVersion = MinecraftVersionRequest.minecraftVersion(v.getJar(getProfile().getGameDirFile()));
minecraftVersion = MinecraftVersionRequest.minecraftVersion(getProfile().service().version().getMinecraftJar(id));
txtMinecraftVersion.setText(MinecraftVersionRequest.getResponse(minecraftVersion));
}
@@ -1210,7 +1209,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
Transferable tr = dtde.getTransferable();
List<File> files = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
for (File file : files)
getProfile().service().mod().addMod(file);
getProfile().service().mod().addMod(getProfile().getSelectedVersion(), file);
} catch (Exception ex) {
HMCLog.warn("Failed to drop file.", ex);
}
@@ -1247,7 +1246,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
reloadingMods = true;
DefaultTableModel model = SwingUtils.clearDefaultTable(lstExternalMods);
Observable.<List<ModInfo>>createWithEmptySubscription(
t -> t.onNext(getProfile().service().mod().recacheMods()))
t -> t.onNext(getProfile().service().mod().recacheMods(getProfile().getSelectedVersion())))
.subscribeOn(Schedulers.newThread()).observeOn(Schedulers.eventQueue())
.subscribe(t -> {
for (ModInfo x : t)

View File

@@ -139,7 +139,7 @@ public class InstallerPanel extends AnimatedPanel implements Selectable {
MessageBox.Show(C.i18n("install.not_refreshed"));
return;
}
gsp.getProfile().service().install().download(getVersion(idx), id).after(new TaskRunnable(this::refreshVersions)).run();
gsp.getProfile().service().install().download(gsp.getProfile().getSelectedVersion(), getVersion(idx), id).after(new TaskRunnable(this::refreshVersions)).run();
}
public void loadVersions() {

View File

@@ -33,7 +33,7 @@ import org.jackhuang.hellominecraft.launcher.core.launch.DefaultGameLauncher;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.auth.LoginInfo;
import org.jackhuang.hellominecraft.launcher.core.Profile;
import org.jackhuang.hellominecraft.launcher.settings.Profile;
import org.jackhuang.hellominecraft.utils.MessageBox;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
@@ -390,7 +390,7 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
return;
}
final String name = (String) cboProfiles.getSelectedItem();
if (StrUtils.isBlank(name) || getCurrentProfile().service().version().getSelectedVersion() == null) {
if (StrUtils.isBlank(name) || getCurrentProfile().getSelectedVersion() == null) {
HMCLog.warn("There's no selected version, rechoose a version.");
MessageBox.ShowLocalized("minecraft.no_selected_version");
return;
@@ -408,7 +408,8 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
@Override
public void run() {
Thread.currentThread().setName("Game Launcher");
DefaultGameLauncher gl = new DefaultGameLauncher(getCurrentProfile(), li, l);
DefaultGameLauncher gl = new DefaultGameLauncher(getCurrentProfile().createLaunchOptions(), getCurrentProfile().service(), li, l);
gl.setTag(getCurrentProfile().getLauncherVisibility());
gl.successEvent.register((sender, s) -> {
isLaunching = false;
return true;
@@ -479,8 +480,7 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
int index = 0, i = 0;
getCurrentProfile().selectedVersionChangedEvent.register(this);
getCurrentProfile().service().version().refreshVersions();
MinecraftVersion selVersion = getCurrentProfile().service().version().getSelectedVersion();
String selectedMC = selVersion == null ? null : selVersion.id;
String selVersion = getCurrentProfile().getSelectedVersion();
if (getCurrentProfile().service().version().getVersions().isEmpty()) {
if (!showedNoVersion)
SwingUtilities.invokeLater(() -> {
@@ -495,7 +495,7 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
if (mcVersion.hidden)
continue;
cboVersions.addItem(mcVersion.id);
if (mcVersion.id.equals(selectedMC))
if (mcVersion.id.equals(selVersion))
index = i;
i++;
}
@@ -567,10 +567,10 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
public boolean call(Object sender, List<String> str) {
final GameLauncher obj = (GameLauncher) sender;
obj.launchEvent.register((sender1, p) -> {
if (obj.getProfile().getLauncherVisibility() == LauncherVisibility.CLOSE && !LogWindow.INSTANCE.isVisible()) {
if ((LauncherVisibility) obj.getTag() == LauncherVisibility.CLOSE && !LogWindow.INSTANCE.isVisible()) {
HMCLog.log("Without the option of keeping the launcher visible, this application will exit and will NOT catch game logs, but you can turn on \"Debug Mode\".");
System.exit(0);
} else if (obj.getProfile().getLauncherVisibility() == LauncherVisibility.KEEP)
} else if ((LauncherVisibility) obj.getTag() == LauncherVisibility.KEEP)
MainFrame.INSTANCE.closeMessage();
else {
if (LogWindow.INSTANCE.isVisible())
@@ -589,7 +589,7 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
return true;
});
jpm.stoppedEvent.register((sender2, t) -> {
if (obj.getProfile().getLauncherVisibility() != LauncherVisibility.KEEP && !LogWindow.INSTANCE.isVisible()) {
if ((LauncherVisibility) obj.getTag() != LauncherVisibility.KEEP && !LogWindow.INSTANCE.isVisible()) {
HMCLog.log("Without the option of keeping the launcher visible, this application will exit and will NOT catch game logs, but you can turn on \"Debug Mode\".");
System.exit(0);
}

View File

@@ -18,7 +18,7 @@
package org.jackhuang.hellominecraft.launcher.views;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.launcher.core.Profile;
import org.jackhuang.hellominecraft.launcher.settings.Profile;
import org.jackhuang.hellominecraft.launcher.settings.Settings;
import org.jackhuang.hellominecraft.utils.StrUtils;