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; package org.jackhuang.hellominecraft.launcher.api;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService; 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.AuthenticationException;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator; import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider; 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.C;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftAssetService; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftAssetService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService; 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.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.tasks.Task; import org.jackhuang.hellominecraft.tasks.Task;
import org.jackhuang.hellominecraft.tasks.TaskWindow; import org.jackhuang.hellominecraft.tasks.TaskWindow;
@@ -40,8 +37,8 @@ import rx.concurrency.Schedulers;
*/ */
public class MinecraftAssetService extends IMinecraftAssetService { public class MinecraftAssetService extends IMinecraftAssetService {
public MinecraftAssetService(IMinecraftService profile) { public MinecraftAssetService(IMinecraftService service) {
super(profile); super(service);
} }
@Override @Override
@@ -98,7 +95,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
@Override @Override
public File getAssets() { public File getAssets() {
return new File(service.profile.getCanonicalGameDirFile(), "assets"); return new File(service.baseDirectory(), "assets");
} }
@Override @Override

View File

@@ -59,7 +59,7 @@ public final class OfflineAuthenticator extends IAuthenticator {
UserProfileProvider result = new UserProfileProvider(); UserProfileProvider result = new UserProfileProvider();
result.setUserName(info.username); result.setUserName(info.username);
String uuid = getUUIDFromUserName(info.username); String uuid = getUUIDFromUserName(info.username);
if (uuidMap != null && uuid.contains(uuid)) if (uuidMap != null && uuidMap.containsKey(uuid))
uuid = uuidMap.get(info.username); uuid = uuidMap.get(info.username);
else { else {
if (uuidMap == null) 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 class MinecraftDownloadService extends IMinecraftDownloadService {
public MinecraftDownloadService(IMinecraftService profile) { public MinecraftDownloadService(IMinecraftService service) {
super(profile); super(service);
} }
@Override @Override
public List<GameLauncher.DownloadLibraryJob> getDownloadLibraries(MinecraftVersion mv) throws GameException { public List<DownloadLibraryJob> getDownloadLibraries(MinecraftVersion mv) throws GameException {
ArrayList<GameLauncher.DownloadLibraryJob> downloadLibraries = new ArrayList<>(); ArrayList<DownloadLibraryJob> downloadLibraries = new ArrayList<>();
if (mv == null) if (mv == null)
return downloadLibraries; return downloadLibraries;
MinecraftVersion v = mv.resolve(service.version()); MinecraftVersion v = mv.resolve(service.version());
@@ -58,12 +58,12 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
for (IMinecraftLibrary l : v.libraries) { for (IMinecraftLibrary l : v.libraries) {
l.init(); l.init();
if (l.allow()) { if (l.allow()) {
File ff = l.getFilePath(service.baseFolder); File ff = l.getFilePath(service.baseDirectory());
if (!ff.exists()) { if (!ff.exists()) {
String libURL = service.getDownloadType().getProvider().getLibraryDownloadURL() + "/"; String libURL = service.getDownloadType().getProvider().getLibraryDownloadURL() + "/";
libURL = service.getDownloadType().getProvider().getParsedLibraryDownloadURL(l.getDownloadURL(libURL, service.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 DownloadLibraryJob(l.name, libURL, ff));
} }
} }
} }
@@ -73,7 +73,7 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
@Override @Override
public MinecraftVersion downloadMinecraft(String id) { public MinecraftVersion downloadMinecraft(String id) {
String vurl = service.getDownloadType().getProvider().getVersionsDownloadURL() + 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 mvt = new File(vpath, id + ".json");
File mvj = new File(vpath, id + ".jar"); File mvj = new File(vpath, id + ".jar");
vpath.mkdirs(); vpath.mkdirs();
@@ -97,7 +97,7 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
@Override @Override
public boolean downloadMinecraftJar(String id) { public boolean downloadMinecraftJar(String id) {
String vurl = service.getDownloadType().getProvider().getVersionsDownloadURL() + 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; 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");
@@ -122,7 +122,7 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
@Override @Override
public boolean downloadMinecraftVersionJson(String id) { public boolean downloadMinecraftVersionJson(String id) {
String vurl = service.getDownloadType().getProvider().getVersionsDownloadURL() + 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; 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");

View File

@@ -43,21 +43,21 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
} }
@Override @Override
public Task download(InstallerVersion v, InstallerType type) { public Task download(String installId, InstallerVersion v, InstallerType type) {
switch (type) { switch (type) {
case Forge: case Forge:
return downloadForge(v); return downloadForge(installId, v);
case Optifine: case Optifine:
return downloadOptifine(v); return downloadOptifine(installId, v);
case LiteLoader: case LiteLoader:
return downloadLiteLoader(v); return downloadLiteLoader(installId, v);
default: default:
return null; return null;
} }
} }
@Override @Override
public Task downloadForge(InstallerVersion v) { public Task downloadForge(String installId, InstallerVersion v) {
return new TaskInfo("Forge Downloader") { return new TaskInfo("Forge Downloader") {
@Override @Override
public void executeTask() { public void executeTask() {
@@ -72,7 +72,7 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
} }
@Override @Override
public Task downloadOptifine(InstallerVersion v) { public Task downloadOptifine(String installId, InstallerVersion v) {
return new TaskInfo("OptiFine Downloader") { return new TaskInfo("OptiFine Downloader") {
@Override @Override
public void executeTask() { public void executeTask() {
@@ -81,7 +81,7 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
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(service, v.selfVersion, filepath)) .addTask(new OptiFineInstaller(service, installId, v, filepath))
.start(); .start();
} }
} }
@@ -89,14 +89,14 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
} }
@Override @Override
public Task downloadLiteLoader(InstallerVersion v) { public Task downloadLiteLoader(String installId, InstallerVersion v) {
return new TaskInfo("LiteLoader Downloader") { return new TaskInfo("LiteLoader Downloader") {
@Override @Override
public void executeTask() { public void executeTask() {
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(service, (LiteLoaderVersionList.LiteLoaderInstallerVersion) v).registerPreviousResult(task)) .addTask(task).addTask(new LiteLoaderInstaller(service, installId, (LiteLoaderVersionList.LiteLoaderInstallerVersion) v).registerPreviousResult(task))
.start(); .start();
} }
}; };

View File

@@ -46,7 +46,7 @@ public class ForgeInstaller extends Task {
public InstallerVersion installerVersion; public InstallerVersion installerVersion;
public ForgeInstaller(IMinecraftService mp, File forgeInstaller, InstallerVersion installerVersion) { public ForgeInstaller(IMinecraftService mp, File forgeInstaller, InstallerVersion installerVersion) {
this.gameDir = mp.baseFolder; this.gameDir = mp.baseDirectory();
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.version().install(profile.install.minecraft)) if (!mp.version().install(profile.install.minecraft, null))
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"));

View File

@@ -38,27 +38,29 @@ public class LiteLoaderInstaller extends Task implements PreviousResultRegistrar
public LiteLoaderVersionList.LiteLoaderInstallerVersion version; public LiteLoaderVersionList.LiteLoaderInstallerVersion version;
public File installer; public File installer;
public String installId;
public IMinecraftService service; public IMinecraftService service;
public LiteLoaderInstaller(IMinecraftService service, LiteLoaderVersionList.LiteLoaderInstallerVersion v) { public LiteLoaderInstaller(IMinecraftService service, String installId, LiteLoaderVersionList.LiteLoaderInstallerVersion v) {
this(service, v, null); 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.service = service;
this.installId = installId;
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 (service.version().getSelectedVersion() == null) if (installId == 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) service.version().getSelectedVersion().clone(); MinecraftVersion mv = (MinecraftVersion) service.version().getVersionById(installId).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 +68,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(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.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(service.baseFolder, "versions/" + mv.id); File folder = new File(service.baseDirectory(), "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");

View File

@@ -21,6 +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.core.installers.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService; import org.jackhuang.hellominecraft.launcher.core.service.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;
@@ -37,30 +38,33 @@ public class OptiFineInstaller extends Task implements PreviousResultRegistrar<F
public File installer; public File installer;
public IMinecraftService service; public IMinecraftService service;
public String version; public InstallerVersionList.InstallerVersion version;
public String installId;
public OptiFineInstaller(IMinecraftService service, String version) { public OptiFineInstaller(IMinecraftService service, String installId, InstallerVersionList.InstallerVersion version) {
this(service, version, null); 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.service = service;
this.installId = installId;
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 (service.version().getSelectedVersion() == null) if (installId == null)
throw new Exception(C.i18n("install.no_version")); 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.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:" + selfId));
FileUtils.copyFile(installer, new File(service.baseFolder, "libraries/optifine/OptiFine/" + version + "/OptiFine-" + version + ".jar")); 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 (new ZipFile(installer).getEntry("optifine/OptiFineTweaker.class") != null) {
if (!mv.mainClass.startsWith("net.minecraft.launchwrapper.")) { if (!mv.mainClass.startsWith("net.minecraft.launchwrapper.")) {
mv.mainClass = "net.minecraft.launchwrapper.Launch"; mv.mainClass = "net.minecraft.launchwrapper.Launch";
@@ -68,7 +72,7 @@ public class OptiFineInstaller extends Task implements PreviousResultRegistrar<F
} }
mv.minecraftArguments += " --tweakClass optifine.OptiFineTweaker"; 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(); 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));

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.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftLoader; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftLoader;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -29,8 +28,6 @@ import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.Launcher; import org.jackhuang.hellominecraft.launcher.Launcher;
import org.jackhuang.hellominecraft.launcher.core.GameException; import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider; 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.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.utils.system.JdkVersion; import org.jackhuang.hellominecraft.utils.system.JdkVersion;
import org.jackhuang.hellominecraft.utils.MathUtils; import org.jackhuang.hellominecraft.utils.MathUtils;
@@ -46,19 +43,19 @@ import org.jackhuang.hellominecraft.utils.Utils;
*/ */
public abstract class AbstractMinecraftLoader implements IMinecraftLoader { public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
protected Profile v; protected LaunchOptions options;
protected UserProfileProvider lr; protected UserProfileProvider lr;
protected File gameDir; protected File gameDir;
protected IMinecraftService service; protected IMinecraftService service;
protected final MinecraftVersion version; 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; this.lr = lr;
v = ver; this.options = options;
service = provider; this.service = service;
gameDir = v.getCanonicalGameDirFile(); this.gameDir = service.baseDirectory();
version = service.version().getSelectedVersion().resolve(service.version()); this.version = service.version().getVersionById(versionId).resolve(service.version());
} }
@Override @Override
@@ -69,30 +66,13 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
public void makeHeadCommand(List<String> res) { public void makeHeadCommand(List<String> res) {
HMCLog.log("On making head command."); HMCLog.log("On making head command.");
String str = v.getJavaDir(); JdkVersion jv = options.getJava();
if (!v.getJavaDirFile().exists()) { res.add(options.getJavaDir());
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);
if (v.hasJavaArgs()) if (options.hasJavaArgs())
res.addAll(Arrays.asList(StrUtils.tokenize(v.getJavaArgs()))); res.addAll(Arrays.asList(StrUtils.tokenize(options.getJavaArgs())));
if (!v.isNoJVMArgs()) { if (!options.isNoJVMArgs()) {
appendJVMArgs(res); appendJVMArgs(res);
if (jv == null || !jv.isEarlyAccess()) { if (jv == null || !jv.isEarlyAccess()) {
@@ -105,11 +85,11 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
res.add("-Xmn128m"); res.add("-Xmn128m");
} }
if (!StrUtils.isBlank(v.getPermSize())) if (!StrUtils.isBlank(options.getPermSize()))
if (jv == null || jv.getParsedVersion() < JdkVersion.JAVA_18) 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) else if (jv.getParsedVersion() >= JdkVersion.JAVA_18)
res.add("-XX:MetaspaceSize=" + v.getPermSize() + "m"); res.add("-XX:MetaspaceSize=" + options.getPermSize() + "m");
} }
if (jv != null) { 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) if (jv != null && jv.getPlatform() == Platform.BIT_32 && Platform.getPlatform() == Platform.BIT_64)
MessageBox.Show(C.i18n("advice.os64butjdk32")); MessageBox.Show(C.i18n("advice.os64butjdk32"));
if (!StrUtils.isBlank(v.getMaxMemory())) { if (!StrUtils.isBlank(options.getMaxMemory())) {
int mem = MathUtils.parseMemory(v.getMaxMemory(), 2147483647); int mem = MathUtils.parseMemory(options.getMaxMemory(), 2147483647);
if (jv != null && jv.getPlatform() == Platform.BIT_32 && mem > 1024) if (jv != null && jv.getPlatform() == Platform.BIT_32 && mem > 1024)
MessageBox.Show(C.i18n("launch.too_big_memory_alloc_64bit")); MessageBox.Show(C.i18n("launch.too_big_memory_alloc_64bit"));
else { else {
@@ -131,8 +111,8 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
if (a > 0 && a < mem) if (a > 0 && a < mem)
MessageBox.Show(C.i18n("launch.too_big_memory_alloc_free_space_too_low", a)); MessageBox.Show(C.i18n("launch.too_big_memory_alloc_free_space_too_low", a));
} }
String a = "-Xmx" + v.getMaxMemory(); String a = "-Xmx" + options.getMaxMemory();
if (MathUtils.canParseInt(v.getMaxMemory())) if (MathUtils.canParseInt(options.getMaxMemory()))
a += "m"; a += "m";
res.add(a); res.add(a);
} }
@@ -143,9 +123,8 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
if (OS.os() != OS.WINDOWS) if (OS.os() != OS.WINDOWS)
res.add("-Duser.home=" + gameDir.getParent()); res.add("-Duser.home=" + gameDir.getParent());
res.add("-Dhellominecraftlauncher.gamedir=" + gameDir.getAbsolutePath());
if (!v.isCanceledWrapper()) { if (!options.isCanceledWrapper()) {
res.add("-cp"); res.add("-cp");
res.add(StrUtils.parseParams("", Utils.getURL(), File.pathSeparator)); res.add(StrUtils.parseParams("", Utils.getURL(), File.pathSeparator));
res.add(Launcher.class.getCanonicalName()); res.add(Launcher.class.getCanonicalName());
@@ -163,14 +142,14 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
HMCLog.log("On making launcher args."); 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("--height");
res.add(v.getHeight()); res.add(options.getHeight());
res.add("--width"); res.add("--width");
res.add(v.getWidth()); res.add(options.getWidth());
} }
String serverIp = v.getServerIp(); String serverIp = options.getServerIp();
if (lr.getServer() != null) if (lr.getServer() != null)
serverIp = lr.getServer().addr; serverIp = lr.getServer().addr;
if (StrUtils.isNotBlank(serverIp)) { if (StrUtils.isNotBlank(serverIp)) {
@@ -181,23 +160,23 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
res.add(args.length > 1 ? args[1] : "25565"); res.add(args.length > 1 ? args[1] : "25565");
} }
if (v.isFullscreen()) if (options.isFullscreen())
res.add("--fullscreen"); res.add("--fullscreen");
if (v.isDebug() && !v.isCanceledWrapper()) if (options.isDebug() && !options.isCanceledWrapper())
res.add("-debug"); res.add("-debug");
if (StrUtils.isNotBlank(Settings.getInstance().getProxyHost()) && StrUtils.isNotBlank(Settings.getInstance().getProxyPort()) && MathUtils.canParseInt(Settings.getInstance().getProxyPort())) { if (StrUtils.isNotBlank(options.getProxyHost()) && StrUtils.isNotBlank(options.getProxyPort()) && MathUtils.canParseInt(options.getProxyPort())) {
res.add("-proxyHost=" + Settings.getInstance().getProxyHost()); res.add("-proxyHost=" + options.getProxyHost());
res.add("-proxyPort=" + Settings.getInstance().getProxyPort()); res.add("-proxyPort=" + options.getProxyPort());
if (StrUtils.isNotBlank(Settings.getInstance().getProxyUserName()) && StrUtils.isNotBlank(Settings.getInstance().getProxyPassword())) { if (StrUtils.isNotBlank(options.getProxyUser()) && StrUtils.isNotBlank(options.getProxyPass())) {
res.add("-proxyUsername=" + Settings.getInstance().getProxyUserName()); res.add("-proxyUsername=" + options.getProxyUser());
res.add("-proxyPassword=" + Settings.getInstance().getProxyPassword()); res.add("-proxyPassword=" + options.getProxyPass());
} }
} }
if (StrUtils.isNotBlank(v.getMinecraftArgs())) if (StrUtils.isNotBlank(options.getMinecraftArgs()))
res.addAll(Arrays.asList(v.getMinecraftArgs().split(" "))); res.addAll(Arrays.asList(options.getMinecraftArgs().split(" ")));
return res; return res;
} }
@@ -216,8 +195,4 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
protected void appendJVMArgs(List<String> list) { 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 java.io.IOException;
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.core.launch.GameLauncher.DownloadLibraryJob;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator; import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.auth.LoginInfo; 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.ParallelTask;
import org.jackhuang.hellominecraft.tasks.TaskWindow; import org.jackhuang.hellominecraft.tasks.TaskWindow;
import org.jackhuang.hellominecraft.utils.system.Compressor; import org.jackhuang.hellominecraft.utils.system.Compressor;
@@ -31,8 +31,8 @@ import org.jackhuang.hellominecraft.utils.MessageBox;
public class DefaultGameLauncher extends GameLauncher { public class DefaultGameLauncher extends GameLauncher {
public DefaultGameLauncher(Profile version, LoginInfo info, IAuthenticator lg) { public DefaultGameLauncher(LaunchOptions options, IMinecraftService service, LoginInfo info, IAuthenticator lg) {
super(version, info, lg); super(options, service, info, lg);
register(); 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.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.auth.LoginInfo; import org.jackhuang.hellominecraft.launcher.core.auth.LoginInfo;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider; 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.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.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;
@@ -47,8 +48,8 @@ import org.jackhuang.hellominecraft.utils.system.ProcessManager;
public class GameLauncher { public class GameLauncher {
public static final ProcessManager PROCESS_MANAGER = new ProcessManager(); public static final ProcessManager PROCESS_MANAGER = new ProcessManager();
Profile get; LaunchOptions options;
IMinecraftService provider; IMinecraftService service;
LoginInfo info; LoginInfo info;
UserProfileProvider result; UserProfileProvider result;
IAuthenticator login; IAuthenticator login;
@@ -57,15 +58,21 @@ public class GameLauncher {
public final EventHandler<JavaProcess> launchEvent = new EventHandler(this); public final EventHandler<JavaProcess> launchEvent = new EventHandler(this);
public final EventHandler<DecompressLibraryJob> decompressNativesEvent = new EventHandler(this); public final EventHandler<DecompressLibraryJob> decompressNativesEvent = new EventHandler(this);
public GameLauncher(Profile version, LoginInfo info, IAuthenticator lg) { public GameLauncher(LaunchOptions options, IMinecraftService version, LoginInfo info, IAuthenticator lg) {
this.get = version; this.options = options;
this.provider = get.service(); this.service = version;
this.info = info; this.info = info;
this.login = lg; this.login = lg;
} }
public Profile getProfile() { private Object tag;
return get;
public Object getTag() {
return tag;
}
public void setTag(Object tag) {
this.tag = tag;
} }
public IMinecraftLoader makeLaunchCommand() throws AuthenticationException, GameException { public IMinecraftLoader makeLaunchCommand() throws AuthenticationException, GameException {
@@ -79,18 +86,18 @@ public class GameLauncher {
throw new AuthenticationException("Result can not be null."); throw new AuthenticationException("Result can not be null.");
PluginManager.NOW_PLUGIN.onProcessingLoginResult(result); 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) if (file != null)
FileUtils.cleanDirectoryQuietly(file); FileUtils.cleanDirectoryQuietly(file);
HMCLog.log("Detecting libraries..."); 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"); throw new GameException("Failed to download libraries");
HMCLog.log("Unpacking natives..."); HMCLog.log("Unpacking natives...");
DecompressLibraryJob job = provider.version().getDecompressLibraries(loader.getMinecraftVersion()); DecompressLibraryJob job = service.version().getDecompressLibraries(loader.getMinecraftVersion());
if (!decompressNativesEvent.execute(job)) if (!decompressNativesEvent.execute(job))
throw new GameException("Failed to decompress natives"); throw new GameException("Failed to decompress natives");
@@ -106,10 +113,10 @@ public class GameLauncher {
* @throws IOException failed creating process * @throws IOException failed creating process
*/ */
public void launch(List str) throws IOException { public void launch(List str) throws IOException {
if (!provider.version().onLaunch()) if (!service.version().onLaunch())
return; return;
if (StrUtils.isNotBlank(getProfile().getPrecalledCommand())) { if (StrUtils.isNotBlank(options.getPrecalledCommand())) {
Process p = Runtime.getRuntime().exec(getProfile().getPrecalledCommand()); Process p = Runtime.getRuntime().exec(options.getPrecalledCommand());
try { try {
if (p != null && p.isAlive()) if (p != null && p.isAlive())
p.waitFor(); p.waitFor();
@@ -119,10 +126,10 @@ public class GameLauncher {
} }
HMCLog.log("Starting process"); HMCLog.log("Starting process");
ProcessBuilder builder = new ProcessBuilder(str); 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!"); throw new Error("Fucking bug!");
builder.directory(provider.version().getRunDirectory(provider.version().getSelectedVersion().id)) builder.directory(service.version().getRunDirectory(options.getLaunchVersion()))
.environment().put("APPDATA", get.getCanonicalGameDir()); .environment().put("APPDATA", service.baseDirectory().getAbsolutePath());
JavaProcess jp = new JavaProcess(str, builder.start(), PROCESS_MANAGER); JavaProcess jp = new JavaProcess(str, builder.start(), PROCESS_MANAGER);
HMCLog.log("The game process have been started"); HMCLog.log("The game process have been started");
launchEvent.execute(jp); launchEvent.execute(jp);
@@ -140,7 +147,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.version().onLaunch(); service.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())
@@ -155,14 +162,14 @@ public class GameLauncher {
if (isWin) { if (isWin) {
writer.write("@echo off"); writer.write("@echo off");
writer.newLine(); writer.newLine();
String appdata = IOUtils.tryGetCanonicalFilePath(get.getCanonicalGameDirFile()); String appdata = IOUtils.tryGetCanonicalFilePath(service.baseDirectory());
if (appdata != null) { if (appdata != null) {
writer.write("set appdata=" + appdata); writer.write("set appdata=" + appdata);
writer.newLine(); writer.newLine();
} }
} }
if (StrUtils.isNotBlank(getProfile().getPrecalledCommand())) { if (StrUtils.isNotBlank(options.getPrecalledCommand())) {
writer.write(getProfile().getPrecalledCommand()); writer.write(options.getPrecalledCommand());
writer.newLine(); writer.newLine();
} }
writer.write(StrUtils.makeCommand(str)); writer.write(StrUtils.makeCommand(str));
@@ -179,29 +186,4 @@ public class GameLauncher {
return f; 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 java.util.jar.Pack200;
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.core.download.DownloadLibraryJob;
import org.jackhuang.hellominecraft.tasks.download.FileDownloadTask; import org.jackhuang.hellominecraft.tasks.download.FileDownloadTask;
import org.jackhuang.hellominecraft.utils.system.IOUtils; import org.jackhuang.hellominecraft.utils.system.IOUtils;
import org.tukaani.xz.XZInputStream; import org.tukaani.xz.XZInputStream;
@@ -39,9 +40,9 @@ import org.tukaani.xz.XZInputStream;
*/ */
public class LibraryDownloadTask extends FileDownloadTask { public class LibraryDownloadTask extends FileDownloadTask {
GameLauncher.DownloadLibraryJob job; DownloadLibraryJob job;
public LibraryDownloadTask(GameLauncher.DownloadLibraryJob job) { public LibraryDownloadTask(DownloadLibraryJob job) {
super(); super();
this.job = job; this.job = job;
} }

View File

@@ -49,28 +49,27 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
DownloadType dt; DownloadType dt;
String text; String text;
public MinecraftLoader(IMinecraftService provider, UserProfileProvider lr) throws GameException { public MinecraftLoader(LaunchOptions p, IMinecraftService provider, UserProfileProvider lr) throws GameException {
super(provider.profile, provider, lr); super(p, provider, p.getLaunchVersion(), lr);
} }
@Override @Override
protected void makeSelf(List<String> res) { protected void makeSelf(List<String> res) {
String library = v.isCanceledWrapper() ? "" : "-cp="; String library = options.isCanceledWrapper() ? "" : "-cp=";
for (MinecraftLibrary l : version.libraries) { for (MinecraftLibrary l : version.libraries) {
l.init(); l.init();
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(v.getCanonicalGameDirFile())) + File.pathSeparator; library += IOUtils.tryGetCanonicalFilePath(version.getJar(service.baseDirectory())) + File.pathSeparator;
library = library.substring(0, library.length() - File.pathSeparator.length()); library = library.substring(0, library.length() - File.pathSeparator.length());
if (v.isCanceledWrapper()) if (options.isCanceledWrapper())
res.add("-cp"); res.add("-cp");
res.add(library); res.add(library);
String mainClass = version.mainClass; 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(version.minecraftArguments);
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) {
@@ -86,7 +85,7 @@ 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}", v.getName()); t = t.replace("${profile_name}", options.getName());
t = t.replace("${game_directory}", service.version().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}", service.asset().getAssets().getAbsolutePath()); t = t.replace("${assets_root}", service.asset().getAssets().getAbsolutePath());
@@ -118,7 +117,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
} }
private boolean checkAssetsExist() { private boolean checkAssetsExist() {
File assetsDir = new File(service.baseFolder, "assets"); File assetsDir = new File(service.baseDirectory(), "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");
@@ -141,7 +140,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
} }
private File reconstructAssets() { private File reconstructAssets() {
File assetsDir = new File(service.baseFolder, "assets"); File assetsDir = new File(service.baseDirectory(), "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();

View File

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

View File

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

View File

@@ -17,8 +17,6 @@
*/ */
package org.jackhuang.hellominecraft.launcher.core.service; 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.InstallerType;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionList; import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionList;
import org.jackhuang.hellominecraft.tasks.Task; import org.jackhuang.hellominecraft.tasks.Task;
@@ -33,12 +31,12 @@ public abstract class IMinecraftInstallerService extends IMinecraftBasicService
super(service); 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; package org.jackhuang.hellominecraft.launcher.core.service;
import java.util.List; import java.util.List;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
/** /**
@@ -28,5 +29,5 @@ public interface IMinecraftLoader {
MinecraftVersion getMinecraftVersion(); 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 abstract class IMinecraftModService extends IMinecraftBasicService {
public IMinecraftModService(IMinecraftService profile) { public IMinecraftModService(IMinecraftService service) {
super(profile); 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.io.File;
import java.util.Collection; import java.util.Collection;
import org.jackhuang.hellominecraft.launcher.core.GameException; import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.launch.GameLauncher; import org.jackhuang.hellominecraft.launcher.core.version.DecompressLibraryJob;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.core.version.GameDirType; import org.jackhuang.hellominecraft.launcher.core.version.GameDirType;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion; 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. * 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 * @author huangyuhui
*/ */
public abstract class IMinecraftProvider { public abstract class IMinecraftProvider {
@@ -67,7 +67,7 @@ public abstract class IMinecraftProvider {
* *
* @return Is the action successful? * @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". * Returns the thing like ".minecraft/resourcepacks".
@@ -82,31 +82,14 @@ public abstract class IMinecraftProvider {
* *
* @return libraries of resolved minecraft version v. * @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); public abstract File getDecompressNativesToLocation(MinecraftVersion v);
/** /**
* @return the Minecraft jar of selected version. * @return the Minecraft jar of selected version.
*/ */
public abstract File getMinecraftJar(); public abstract File getMinecraftJar(String id);
/**
* @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;
protected GameDirType gameDirType = GameDirType.ROOT_FOLDER; protected GameDirType gameDirType = GameDirType.ROOT_FOLDER;
@@ -156,18 +139,6 @@ public abstract class IMinecraftProvider {
*/ */
public abstract MinecraftVersion getVersionById(String id); 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() * getVersions().size()
* *

View File

@@ -18,9 +18,10 @@
package org.jackhuang.hellominecraft.launcher.core.service; package org.jackhuang.hellominecraft.launcher.core.service;
import java.io.File; import java.io.File;
import org.jackhuang.hellominecraft.launcher.core.Profile; import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.settings.Settings; import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType; 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 abstract class IMinecraftService {
public final Profile profile; public abstract File baseDirectory();
public final File baseFolder;
public IMinecraftService(Profile profile) {
this.profile = profile;
this.baseFolder = profile.getCanonicalGameDirFile();
}
public DownloadType getDownloadType() { public DownloadType getDownloadType() {
return DownloadType.getSuggestedDownloadType(); return DownloadType.getSuggestedDownloadType();
@@ -50,4 +45,16 @@ public abstract class IMinecraftService {
public abstract IMinecraftInstallerService install(); 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.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.jackhuang.hellominecraft.HMCLog; import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftModService; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftModService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
@@ -36,25 +38,23 @@ import org.jackhuang.hellominecraft.utils.system.FileUtils;
*/ */
public class MinecraftModService extends IMinecraftModService { public class MinecraftModService extends IMinecraftModService {
List<ModInfo> modCache; Map<String, List<ModInfo>> modCache = Collections.synchronizedMap(new HashMap<>());
public MinecraftModService(IMinecraftService profile) { public MinecraftModService(IMinecraftService service) {
super(profile); super(service);
} }
@Override @Override
public List<ModInfo> getMods() { public List<ModInfo> getMods(String id) {
if (modCache == null) if (modCache.containsKey(id))
return recacheMods(); return modCache.get(id);
else else
return modCache; return recacheMods(id);
} }
@Override @Override
public List<ModInfo> recacheMods() { public List<ModInfo> recacheMods(String id) {
if (service.version().getSelectedVersion() == null) File modsFolder = service.version().getRunDirectory(id, "mods");
return modCache = new ArrayList<>();
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)
@@ -74,24 +74,22 @@ public class MinecraftModService extends IMinecraftModService {
} }
} }
Collections.sort(mods); Collections.sort(mods);
return modCache = mods; return modCache.put(id, mods);
} }
@Override @Override
public boolean addMod(File f) { public boolean addMod(String id, File f) {
try { try {
if (service.version().getSelectedVersion() == null)
return false;
if (!ModInfo.isFileMod(f)) if (!ModInfo.isFileMod(f))
return false; return false;
File modsFolder = service.version().getRunDirectory(service.version().getSelectedVersion().id, "mods"); File modsFolder = service.version().getRunDirectory(id, "mods");
if (modsFolder == null) if (modsFolder == null)
return false; return false;
modsFolder.mkdirs(); modsFolder.mkdirs();
File newf = new File(modsFolder, f.getName()); File newf = new File(modsFolder, f.getName());
FileUtils.copyFile(f, newf); FileUtils.copyFile(f, newf);
ModInfo i = ModInfo.readModInfo(f); ModInfo i = ModInfo.readModInfo(f);
modCache.add(i); modCache.get(id).add(i);
return true; return true;
} catch (IOException ex) { } catch (IOException ex) {
HMCLog.warn("Failed to copy mod", ex); HMCLog.warn("Failed to copy mod", ex);
@@ -100,21 +98,21 @@ public class MinecraftModService extends IMinecraftModService {
} }
@Override @Override
public void removeMod(Object[] rows) { public void removeMod(String id, Object[] rows) {
if (rows.length == 0) if (rows.length == 0)
return; return;
for (Object r : rows) for (Object r : rows)
if (r instanceof ModInfo) if (r instanceof ModInfo)
((ModInfo) r).location.delete(); ((ModInfo) r).location.delete();
else if (r instanceof Number) else if (r instanceof Number)
getMods().get(((Number) r).intValue()).location.delete(); getMods(id).get(((Number) r).intValue()).location.delete();
recacheMods(); recacheMods(id);
} }
public String[] checkMd5s() throws IOException { public String[] checkMd5s(String id) throws IOException {
String[] res = new String[getMods().size()]; String[] res = new String[getMods(id).size()];
for (int i = 0; i < res.length; i++) 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; return res;
} }

View File

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

View File

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

View File

@@ -17,10 +17,9 @@
*/ */
package org.jackhuang.hellominecraft.launcher.settings; 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.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.api.IPlugin; 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.settings.Settings;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator; import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.auth.OfflineAuthenticator; 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 * You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}. * 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.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.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.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.utils.system.IOUtils; import org.jackhuang.hellominecraft.utils.system.IOUtils;
import org.jackhuang.hellominecraft.launcher.core.version.GameDirType; 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.Utils;
import org.jackhuang.hellominecraft.utils.EventHandler; import org.jackhuang.hellominecraft.utils.EventHandler;
import org.jackhuang.hellominecraft.utils.system.Java; import org.jackhuang.hellominecraft.utils.system.Java;
import org.jackhuang.hellominecraft.utils.system.JdkVersion;
import org.jackhuang.hellominecraft.utils.system.OS; import org.jackhuang.hellominecraft.utils.system.OS;
/** /**
@@ -101,10 +109,20 @@ public final class Profile {
return service; return service;
} }
public String getSelectedMinecraftVersionName() { public String getSettingsSelectedMinecraftVersion() {
return selectedMinecraftVersion; 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 transient final EventHandler<String> selectedVersionChangedEvent = new EventHandler<>(this);
public void setSelectedMinecraftVersion(String selectedMinecraftVersion) { public void setSelectedMinecraftVersion(String selectedMinecraftVersion) {
@@ -187,9 +205,9 @@ public final class Profile {
} }
public File getFolder(String folder) { public File getFolder(String folder) {
if (service().version().getSelectedVersion() == null) if (getSelectedVersion() == null)
return new File(getCanonicalGameDirFile(), folder); return new File(getCanonicalGameDirFile(), folder);
return service().version().getRunDirectory(service().version().getSelectedVersion().id, folder); return service().version().getRunDirectory(getSelectedVersion(), folder);
} }
public String getName() { public String getName() {
@@ -356,4 +374,52 @@ 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);
} }
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; package org.jackhuang.hellominecraft.launcher.settings;
import org.jackhuang.hellominecraft.launcher.core.Profile;
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;

View File

@@ -15,12 +15,24 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}. * 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.installers.MinecraftInstallerService;
import org.jackhuang.hellominecraft.launcher.core.assets.MinecraftAssetService; 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.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.MinecraftModService;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersionManager; 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 { public class DefaultMinecraftService extends IMinecraftService {
File base;
Profile p;
public DefaultMinecraftService(Profile p) { public DefaultMinecraftService(Profile p) {
super(p); this.p = p;
this.provider = new MinecraftVersionManager(this); this.provider = new MinecraftVersionManager(this);
provider.initializeMiencraft(); provider.initializeMiencraft();
this.mms = new MinecraftModService(this); this.mms = new MinecraftModService(this);
@@ -40,6 +55,11 @@ public class DefaultMinecraftService extends IMinecraftService {
this.mis = new MinecraftInstallerService(this); this.mis = new MinecraftInstallerService(this);
} }
@Override
public File baseDirectory() {
return p.getCanonicalGameDirFile();
}
protected IMinecraftProvider provider; protected IMinecraftProvider provider;
@Override @Override
@@ -75,4 +95,9 @@ public class DefaultMinecraftService extends IMinecraftService {
return mis; 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.C;
import org.jackhuang.hellominecraft.HMCLog; import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.LauncherVisibility; 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.settings.Settings;
import org.jackhuang.hellominecraft.launcher.utils.FileNameFilter; import org.jackhuang.hellominecraft.launcher.utils.FileNameFilter;
import org.jackhuang.hellominecraft.launcher.core.ModInfo; import org.jackhuang.hellominecraft.launcher.core.ModInfo;
@@ -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().service().mod().getMods(); List<ModInfo> mods = getProfile().service().mod().getMods(getProfile().getSelectedVersion());
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().service().mod().getMods(); List<ModInfo> mods = getProfile().service().mod().getMods(getProfile().getSelectedVersion());
if (mods != null && mods.size() > row && row >= 0) if (mods != null && mods.size() > row && row >= 0)
mods.get(row).reverseModState(); mods.get(row).reverseModState();
} }
@@ -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().service().mod().addMod(f); flag &= getProfile().service().mod().addMod(getProfile().getSelectedVersion(), 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().service().mod().removeMod(SwingUtils.getValueBySelectedRow(lstExternalMods, lstExternalMods.getSelectedRows(), 1)); getProfile().service().mod().removeMod(getProfile().getSelectedVersion(), 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().service().mod().getMods().size()) if (idx > 0 && idx < getProfile().service().mod().getMods(getProfile().getSelectedVersion()).size())
SwingUtils.openLink(getProfile().service().mod().getMods().get(idx).url); SwingUtils.openLink(getProfile().service().mod().getMods(getProfile().getSelectedVersion()).get(idx).url);
}//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
@@ -1165,8 +1165,7 @@ 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().service().version().getSelectedVersion(); String selectedMC = getProfile().getSelectedVersion();
String selectedMC = selVersion == null ? null : selVersion.id;
for (MinecraftVersion each : getProfile().service().version().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))
@@ -1181,18 +1180,18 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
} }
void loadMinecraftVersion() { void loadMinecraftVersion() {
loadMinecraftVersion(getProfile().service().version().getSelectedVersion()); loadMinecraftVersion(getProfile().getSelectedVersion());
} }
/** /**
* Anaylze the jar of selected minecraft version of current getProfile() to * Anaylze the jar of selected minecraft version of current getProfile() to
* get the version. * get the version.
*/ */
void loadMinecraftVersion(MinecraftVersion v) { void loadMinecraftVersion(String id) {
txtMinecraftVersion.setText(""); txtMinecraftVersion.setText("");
if (v == null) if (id == null)
return; return;
minecraftVersion = MinecraftVersionRequest.minecraftVersion(v.getJar(getProfile().getGameDirFile())); minecraftVersion = MinecraftVersionRequest.minecraftVersion(getProfile().service().version().getMinecraftJar(id));
txtMinecraftVersion.setText(MinecraftVersionRequest.getResponse(minecraftVersion)); txtMinecraftVersion.setText(MinecraftVersionRequest.getResponse(minecraftVersion));
} }
@@ -1210,7 +1209,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().service().mod().addMod(file); getProfile().service().mod().addMod(getProfile().getSelectedVersion(), file);
} catch (Exception ex) { } catch (Exception ex) {
HMCLog.warn("Failed to drop file.", ex); HMCLog.warn("Failed to drop file.", ex);
} }
@@ -1247,7 +1246,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().service().mod().recacheMods())) t -> t.onNext(getProfile().service().mod().recacheMods(getProfile().getSelectedVersion())))
.subscribeOn(Schedulers.newThread()).observeOn(Schedulers.eventQueue()) .subscribeOn(Schedulers.newThread()).observeOn(Schedulers.eventQueue())
.subscribe(t -> { .subscribe(t -> {
for (ModInfo x : 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")); MessageBox.Show(C.i18n("install.not_refreshed"));
return; 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() { 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.GameException;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator; import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.auth.LoginInfo; 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.MessageBox;
import org.jackhuang.hellominecraft.utils.StrUtils; import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
@@ -390,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().service().version().getSelectedVersion() == null) { if (StrUtils.isBlank(name) || getCurrentProfile().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;
@@ -408,7 +408,8 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
@Override @Override
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().createLaunchOptions(), getCurrentProfile().service(), li, l);
gl.setTag(getCurrentProfile().getLauncherVisibility());
gl.successEvent.register((sender, s) -> { gl.successEvent.register((sender, s) -> {
isLaunching = false; isLaunching = false;
return true; return true;
@@ -479,8 +480,7 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
int index = 0, i = 0; int index = 0, i = 0;
getCurrentProfile().selectedVersionChangedEvent.register(this); getCurrentProfile().selectedVersionChangedEvent.register(this);
getCurrentProfile().service().version().refreshVersions(); getCurrentProfile().service().version().refreshVersions();
MinecraftVersion selVersion = getCurrentProfile().service().version().getSelectedVersion(); String selVersion = getCurrentProfile().getSelectedVersion();
String selectedMC = selVersion == null ? null : selVersion.id;
if (getCurrentProfile().service().version().getVersions().isEmpty()) { if (getCurrentProfile().service().version().getVersions().isEmpty()) {
if (!showedNoVersion) if (!showedNoVersion)
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
@@ -495,7 +495,7 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
if (mcVersion.hidden) if (mcVersion.hidden)
continue; continue;
cboVersions.addItem(mcVersion.id); cboVersions.addItem(mcVersion.id);
if (mcVersion.id.equals(selectedMC)) if (mcVersion.id.equals(selVersion))
index = i; index = i;
i++; i++;
} }
@@ -567,10 +567,10 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
public boolean call(Object sender, List<String> str) { public boolean call(Object sender, List<String> str) {
final GameLauncher obj = (GameLauncher) sender; final GameLauncher obj = (GameLauncher) sender;
obj.launchEvent.register((sender1, p) -> { 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\"."); 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); System.exit(0);
} else if (obj.getProfile().getLauncherVisibility() == LauncherVisibility.KEEP) } else if ((LauncherVisibility) obj.getTag() == LauncherVisibility.KEEP)
MainFrame.INSTANCE.closeMessage(); MainFrame.INSTANCE.closeMessage();
else { else {
if (LogWindow.INSTANCE.isVisible()) if (LogWindow.INSTANCE.isVisible())
@@ -589,7 +589,7 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
return true; return true;
}); });
jpm.stoppedEvent.register((sender2, t) -> { 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\"."); 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); System.exit(0);
} }

View File

@@ -18,7 +18,7 @@
package org.jackhuang.hellominecraft.launcher.views; package org.jackhuang.hellominecraft.launcher.views;
import org.jackhuang.hellominecraft.C; 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.launcher.settings.Settings;
import org.jackhuang.hellominecraft.utils.StrUtils; import org.jackhuang.hellominecraft.utils.StrUtils;