LiteLoader installing
This commit is contained in:
@@ -86,6 +86,8 @@ public final class Main extends Application {
|
||||
public static void stopWithoutPlatform() {
|
||||
JFXUtilities.runInFX(() -> {
|
||||
Controllers.getStage().close();
|
||||
|
||||
Logging.LOG.info("Shutting down executor services.");
|
||||
Schedulers.shutdown();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -368,6 +368,7 @@ public final class LauncherHelper {
|
||||
|
||||
logWindow.show();
|
||||
logWindow.onDone.register(() -> {
|
||||
logWindow.logLine("Commands: " + StringUtils.makeCommand(process.getCommands()), Log4jLevel.INFO);
|
||||
for (Map.Entry<String, Log4jLevel> entry : logs)
|
||||
logWindow.logLine(entry.getKey(), entry.getValue());
|
||||
});
|
||||
|
||||
@@ -20,6 +20,7 @@ package org.jackhuang.hmcl.ui;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import org.jackhuang.hmcl.download.MaintainTask;
|
||||
import org.jackhuang.hmcl.download.game.VersionJsonSaveTask;
|
||||
import org.jackhuang.hmcl.game.GameVersion;
|
||||
import org.jackhuang.hmcl.game.Library;
|
||||
@@ -60,7 +61,8 @@ public class InstallerController {
|
||||
Consumer<InstallerItem> removeAction = x -> {
|
||||
LinkedList<Library> newList = new LinkedList<>(version.getLibraries());
|
||||
newList.remove(library);
|
||||
new VersionJsonSaveTask(profile.getRepository(), version.setLibraries(newList))
|
||||
new MaintainTask(profile.getRepository(), version.setLibraries(newList))
|
||||
.then(variables -> new VersionJsonSaveTask(profile.getRepository(), variables.get(MaintainTask.ID)))
|
||||
.with(profile.getRepository().refreshVersionsAsync())
|
||||
.with(Task.of(Schedulers.javafx(), () -> loadVersion(this.profile, this.versionId)))
|
||||
.start();
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
border-style: solid;
|
||||
border-width: 0 0 1px 0;
|
||||
border-color: #dddddd;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.fatal { background-color: #F7A699; }
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Hello Minecraft! Launcher.
|
||||
* Copyright (C) 2017 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.hmcl.download;
|
||||
|
||||
import org.jackhuang.hmcl.download.game.VersionJsonSaveTask;
|
||||
import org.jackhuang.hmcl.game.GameRepository;
|
||||
import org.jackhuang.hmcl.game.Library;
|
||||
import org.jackhuang.hmcl.game.Version;
|
||||
import org.jackhuang.hmcl.task.Schedulers;
|
||||
import org.jackhuang.hmcl.task.Task;
|
||||
import org.jackhuang.hmcl.task.TaskResult;
|
||||
import org.jackhuang.hmcl.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class MaintainTask extends TaskResult<Version> {
|
||||
|
||||
private final GameRepository repository;
|
||||
private final Version version;
|
||||
private final String id;
|
||||
|
||||
public MaintainTask(GameRepository repository, Version version) {
|
||||
this(repository, version, ID);
|
||||
}
|
||||
|
||||
public MaintainTask(GameRepository repository, Version version, String id) {
|
||||
this.repository = repository;
|
||||
this.version = version;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws Exception {
|
||||
Version newVersion = version;
|
||||
Library forge = null, liteLoader = null, optiFine = null;
|
||||
List<String> args = new ArrayList<>(StringUtils.tokenize(newVersion.getMinecraftArguments().orElse("")));
|
||||
|
||||
for (Library library : version.getLibraries()) {
|
||||
if (library.getGroupId().equalsIgnoreCase("net.minecraftforge") && library.getArtifactId().equalsIgnoreCase("forge"))
|
||||
forge = library;
|
||||
|
||||
if (library.getGroupId().equalsIgnoreCase("com.mumfrey") && library.getArtifactId().equalsIgnoreCase("liteloader"))
|
||||
liteLoader = library;
|
||||
|
||||
if (library.getGroupId().equalsIgnoreCase("net.optifine") && library.getArtifactId().equalsIgnoreCase("optifine"))
|
||||
optiFine = library;
|
||||
|
||||
}
|
||||
|
||||
if (forge == null) {
|
||||
removeTweakClass(args, "forge");
|
||||
}
|
||||
|
||||
if (liteLoader == null) {
|
||||
removeTweakClass(args, "liteloader");
|
||||
}
|
||||
|
||||
if (optiFine == null) {
|
||||
removeTweakClass(args, "optifine");
|
||||
}
|
||||
|
||||
if (liteLoader == null && forge == null && optiFine != null) {
|
||||
if (!StringUtils.containsOne(args, "optifine.OptiFineTweaker")) {
|
||||
args.add("--tweakClass");
|
||||
args.add("optifine.OptiFineTweaker");
|
||||
}
|
||||
}
|
||||
|
||||
if ((liteLoader != null || forge != null) && optiFine != null) {
|
||||
// If forge or LiteLoader installed, OptiFine Tweaker will cause crash.
|
||||
removeTweakClass(args, "optifine");
|
||||
}
|
||||
|
||||
setResult(newVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
private static void removeTweakClass(List<String> args, String target) {
|
||||
for (int i = 0; i < args.size(); ++i) {
|
||||
if (args.get(i).toLowerCase().contains(target)) {
|
||||
if (i > 0 && args.get(i - 1).equals("--tweakClass")) {
|
||||
args.remove(i - 1);
|
||||
args.remove(i - 1);
|
||||
i -= 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final String ID = "version";
|
||||
}
|
||||
@@ -96,11 +96,16 @@ public final class LiteLoaderInstallTask extends TaskResult<Version> {
|
||||
);
|
||||
|
||||
Version tempVersion = version.setLibraries(Lang.merge(remote.getTag().getLibraries(), Collections.singleton(library)));
|
||||
|
||||
String mcArg = version.getMinecraftArguments().orElse("");
|
||||
if (mcArg.contains("--tweakClass optifine.OptiFineTweaker"))
|
||||
mcArg = mcArg.replace("--tweakClass optifine.OptiFineTweaker", "");
|
||||
|
||||
setResult(version
|
||||
.setMainClass("net.minecraft.launchwrapper.Launch")
|
||||
.setLibraries(Lang.merge(tempVersion.getLibraries(), version.getLibraries()))
|
||||
.setLogging(Collections.emptyMap())
|
||||
.setMinecraftArguments(version.getMinecraftArguments().orElse("") + " --tweakClass " + remote.getTag().getTweakClass())
|
||||
.setMinecraftArguments(mcArg + " --tweakClass " + remote.getTag().getTweakClass())
|
||||
//.setArguments(Arguments.addGameArguments(Lang.get(version.getArguments()), "--tweakClass", remote.getTag().getTweakClass()))
|
||||
);
|
||||
|
||||
|
||||
@@ -25,7 +25,16 @@ import org.jackhuang.hmcl.task.Task;
|
||||
import org.jackhuang.hmcl.util.Constants;
|
||||
import org.jackhuang.hmcl.util.NetworkUtils;
|
||||
import org.jackhuang.hmcl.util.VersionNumber;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
@@ -76,11 +85,18 @@ public final class LiteLoaderVersionList extends VersionList<LiteLoaderRemoteVer
|
||||
if ("latest".equals(branchName))
|
||||
continue;
|
||||
|
||||
String version = v.getVersion();
|
||||
String url = repository.getUrl() + "com/mumfrey/liteloader/" + gameVersion + "/" + v.getFile();
|
||||
if (snapshot) {
|
||||
try {
|
||||
version = version.replace("SNAPSHOT", getLatestSnapshotVersion(repository.getUrl() + "com/mumfrey/liteloader/" + v.getVersion() + "/"));
|
||||
url = repository.getUrl() + "com/mumfrey/liteloader/" + v.getVersion() + "/liteloader-" + version + "-release.jar";
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
versions.put(key, new RemoteVersion<>(gameVersion,
|
||||
v.getVersion().replace("SNAPSHOT", "SNAPSHOT-" + v.getLastSuccessfulBuild()),
|
||||
snapshot
|
||||
? "http://jenkins.liteloader.com/LiteLoader " + gameVersion + "/lastSuccessfulBuild/artifact/build/libs/liteloader-" + v.getVersion() + "-release.jar"
|
||||
: downloadProvider.injectURL(repository.getUrl() + "com/mumfrey/liteloader/" + gameVersion + "/" + v.getFile()),
|
||||
version, downloadProvider.injectURL(url),
|
||||
new LiteLoaderRemoteVersionTag(v.getTweakClass(), v.getLibraries())
|
||||
));
|
||||
}
|
||||
@@ -89,4 +105,15 @@ public final class LiteLoaderVersionList extends VersionList<LiteLoaderRemoteVer
|
||||
}
|
||||
|
||||
public static final String LITELOADER_LIST = "http://dl.liteloader.com/versions/versions.json";
|
||||
|
||||
private static String getLatestSnapshotVersion(String repo) throws Exception {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document doc = builder.parse(repo + "maven-metadata.xml");
|
||||
Element r = doc.getDocumentElement();
|
||||
Element snapshot = (Element) r.getElementsByTagName("snapshot").item(0);
|
||||
Node timestamp = snapshot.getElementsByTagName("timestamp").item(0);
|
||||
Node buildNumber = snapshot.getElementsByTagName("buildNumber").item(0);
|
||||
return timestamp.getTextContent() + "-" + buildNumber.getTextContent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ public abstract class Task {
|
||||
}
|
||||
|
||||
public static Task of(Scheduler scheduler, ExceptionalConsumer<AutoTypingMap<String>, ?> closure) {
|
||||
return of(null, scheduler, closure);
|
||||
return of(ReflectionHelper.getCaller().toString(), scheduler, closure);
|
||||
}
|
||||
|
||||
public static Task of(String name, Scheduler scheduler, ExceptionalRunnable<?> closure) {
|
||||
@@ -301,7 +301,7 @@ public abstract class Task {
|
||||
}
|
||||
|
||||
public static Task of(Scheduler scheduler, ExceptionalRunnable<?> closure) {
|
||||
return of(null, scheduler, closure);
|
||||
return of(ReflectionHelper.getCaller().toString(), scheduler, closure);
|
||||
}
|
||||
|
||||
public static <V> TaskResult<V> ofResult(String id, Callable<V> callable) {
|
||||
|
||||
@@ -36,6 +36,7 @@ public final class IOUtils {
|
||||
if (closeable != null)
|
||||
closeable.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -146,4 +146,14 @@ public final class ReflectionHelper {
|
||||
.filter(s -> checkParameter(s, args))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
public static StackTraceElement getCaller() {
|
||||
StackTraceElement[] elements = Thread.currentThread().getStackTrace();
|
||||
StackTraceElement caller = elements[2];
|
||||
for (int i = 3; i < elements.length; ++i) {
|
||||
if (!caller.getClassName().equals(elements[i].getClassName()))
|
||||
return elements[i];
|
||||
}
|
||||
return caller;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user