Support liteloader snapshots

This commit is contained in:
huangyuhui 2017-07-03 19:43:36 +08:00
parent b8591007cf
commit 6afcf8d0d7
6 changed files with 109 additions and 18 deletions

View File

@ -0,0 +1,35 @@
/*
* 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.hmcl.core.install.liteloader;
import com.google.gson.annotations.SerializedName;
import java.util.List;
import java.util.Map;
import org.jackhuang.hmcl.core.version.MinecraftLibrary;
/**
*
* @author huang
*/
public class LiteLoaderBranch {
@SerializedName("libraries")
public List<MinecraftLibrary> libraries;
@SerializedName("com.mumfrey:liteloader")
public Map<String, LiteLoaderVersion> liteLoader;
}

View File

@ -30,7 +30,7 @@ public class LiteLoaderInstallerVersion extends InstallerVersionList.InstallerVe
public MinecraftLibrary[] libraries;
public String tweakClass;
public LiteLoaderInstallerVersion(String selfVersion, String mcVersion) {
super(selfVersion, mcVersion);
}

View File

@ -18,14 +18,19 @@
package org.jackhuang.hmcl.core.install.liteloader;
import com.google.gson.annotations.SerializedName;
import java.util.Map;
/**
*
* @author huangyuhui
*/
public class LiteLoaderMCVersions {
@SerializedName("repo")
public LiteLoaderRepo repo;
@SerializedName("artefacts")
public Map<String, Map<String, LiteLoaderVersion>> artefacts;
public LiteLoaderBranch artefacts;
@SerializedName("snapshots")
public LiteLoaderBranch snapshots;
}

View File

@ -0,0 +1,35 @@
/*
* 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.hmcl.core.install.liteloader;
import com.google.gson.annotations.SerializedName;
/**
*
* @author huang
*/
public class LiteLoaderRepo {
@SerializedName("stream")
public String stream;
@SerializedName("type")
public String type;
@SerializedName("url")
public String url;
@SerializedName("classifier")
public String classifier;
}

View File

@ -18,6 +18,7 @@
package org.jackhuang.hmcl.core.install.liteloader;
import com.google.gson.annotations.SerializedName;
import java.util.List;
import org.jackhuang.hmcl.core.version.MinecraftLibrary;
/**
@ -36,6 +37,8 @@ public class LiteLoaderVersion {
public String md5;
@SerializedName("timestamp")
public String timestamp;
@SerializedName("lastSuccessfulBuild")
public int lastSuccessfulBuild;
@SerializedName("libraries")
public MinecraftLibrary[] libraries;
public List<MinecraftLibrary> libraries;
}

View File

@ -22,11 +22,14 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.jackhuang.hmcl.core.download.DownloadType;
import org.jackhuang.hmcl.util.C;
import org.jackhuang.hmcl.core.install.InstallerVersionList;
import org.jackhuang.hmcl.core.install.InstallerVersionNewerComparator;
import org.jackhuang.hmcl.core.version.MinecraftLibrary;
import org.jackhuang.hmcl.util.StrUtils;
import org.jackhuang.hmcl.util.task.Task;
import org.jackhuang.hmcl.util.task.TaskInfo;
@ -60,6 +63,27 @@ public class LiteLoaderVersionList extends InstallerVersionList {
return Arrays.asList(task.setTag("Official Liteloader Download Site"));
}
private void doBranch(String version, LiteLoaderRepo repo, LiteLoaderBranch branch, List<InstallerVersion> result, boolean snapshot) {
if (branch == null || branch.liteLoader == null)
return;
for (Map.Entry<String, LiteLoaderVersion> entry : branch.liteLoader.entrySet()) {
if ("latest".equals(entry.getKey()))
continue;
LiteLoaderVersion v = entry.getValue();
LiteLoaderInstallerVersion iv = new LiteLoaderInstallerVersion(v.version.replace("SNAPSHOT", "SNAPSHOT-" + v.lastSuccessfulBuild), StrUtils.formatVersion(version));
if (snapshot)
iv.universal = String.format("http://jenkins.liteloader.com/view/%s/job/LiteLoader %s/lastSuccessfulBuild/artifact/build/libs/liteloader-%s-release.jar", version, version, v.version);
else
iv.universal = DownloadType.getSuggestedDownloadType().getProvider().getParsedDownloadURL(repo.url + "com/mumfrey/liteloader/" + version + "/" + v.file);
iv.tweakClass = v.tweakClass;
HashSet<MinecraftLibrary> set = new HashSet<>();
if (v.libraries != null)
set.addAll(v.libraries);
iv.libraries = set.toArray(new MinecraftLibrary[set.size()]);
result.add(iv);
}
}
@Override
public void executeTask(boolean areDependTasksSucceeded) throws Exception {
if (!areDependTasksSucceeded)
@ -74,21 +98,10 @@ public class LiteLoaderVersionList extends InstallerVersionList {
for (Map.Entry<String, LiteLoaderMCVersions> arr : root.versions.entrySet()) {
ArrayList<InstallerVersion> al = new ArrayList<>();
LiteLoaderMCVersions mcv = arr.getValue();
if (mcv == null || mcv.artefacts == null || mcv.artefacts.get("com.mumfrey:liteloader") == null)
continue;
for (Map.Entry<String, LiteLoaderVersion> entry : mcv.artefacts.get("com.mumfrey:liteloader").entrySet()) {
if ("latest".equals(entry.getKey()))
continue;
LiteLoaderVersion v = entry.getValue();
LiteLoaderInstallerVersion iv = new LiteLoaderInstallerVersion(v.version, StrUtils.formatVersion(arr.getKey()));
iv.universal = DownloadType.getSuggestedDownloadType().getProvider().getParsedDownloadURL("http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + arr.getKey() + "/" + v.file);
iv.tweakClass = v.tweakClass;
iv.libraries = Arrays.copyOf(v.libraries, v.libraries.length);
iv.installer = "http://dl.liteloader.com/redist/" + iv.mcVersion + "/liteloader-installer-" + iv.selfVersion.replace("_", "-") + ".jar";
al.add(iv);
versions.add(iv);
}
doBranch(arr.getKey(), mcv.repo, mcv.artefacts, al, false);
doBranch(arr.getKey(), mcv.repo, mcv.snapshots, al, true);
Collections.sort(al, new InstallerVersionNewerComparator());
versions.addAll(al);
versionMap.put(StrUtils.formatVersion(arr.getKey()), al);
}