Supported BMCL Liteloader downloads

This commit is contained in:
huangyuhui 2017-01-29 12:23:38 +08:00
parent 88c46ba9ee
commit 89efa71ced
17 changed files with 106 additions and 78 deletions

View File

@ -107,7 +107,7 @@ public abstract class IAssetsHandler {
String mark = assetsDownloadURLs.get(i);
String url = u + mark;
File location = assetsLocalNames.get(i);
if (!location.getParentFile().exists() && !location.getParentFile().mkdirs())
if (!FileUtils.makeDirectory(location.getParentFile()))
HMCLog.warn("Failed to make directories: " + location.getParent());
if (location.isDirectory())
continue;

View File

@ -71,7 +71,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
@Override
public Task downloadMinecraftAssetsIndex(AssetIndexDownloadInfo assetIndex) {
File assetsLocation = getAssets();
if (!assetsLocation.exists() && !assetsLocation.mkdirs())
if (!FileUtils.makeDirectory(assetsLocation))
HMCLog.warn("Failed to make directories: " + assetsLocation);
File assetsIndex = getIndexFile(assetIndex.getId());
File renamed = null;
@ -101,7 +101,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
@Override
public boolean downloadMinecraftAssetsIndexAsync(AssetIndexDownloadInfo assetIndex) {
File assetsDir = getAssets();
if (!assetsDir.mkdirs() && !assetsDir.isDirectory())
if (!FileUtils.makeDirectory(assetsDir))
HMCLog.warn("Failed to make directories: " + assetsDir);
File assetsIndex = getIndexFile(assetIndex.getId());
File renamed = null;

View File

@ -18,6 +18,7 @@
package org.jackhuang.hellominecraft.launcher.core.download;
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
import org.jackhuang.hellominecraft.util.C;
/**
*
@ -71,7 +72,9 @@ public class BMCLAPIDownloadProvider extends IDownloadProvider {
: str.replace("https://launchermeta.mojang.com", "http://bmclapi2.bangbang93.com")
.replace("https://launcher.mojang.com", "http://bmclapi2.bangbang93.com")
.replace("https://libraries.minecraft.net", "http://bmclapi2.bangbang93.com/libraries")
.replace("http://files.minecraftforge.net/maven", "http://bmclapi2.bangbang93.com/maven");
.replace("http://files.minecraftforge.net/maven", "http://bmclapi2.bangbang93.com/maven")
.replace(C.URL_LITELOADER_LIST, "http://bmclapi2.bangbang93.com/maven/com/mumfrey/liteloader/versions.json")
.replace("http://dl.liteloader.com/versions", "http://bmclapi2.bangbang93.com/maven");
}
@Override

View File

@ -144,7 +144,7 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
String jsonURL = currentVersion.getUrl(service.getDownloadType());
File vpath = new File(service.baseDirectory(), "versions/" + id);
File mvt = new File(vpath, id + ".json");
if (!vpath.exists() && !vpath.mkdirs())
if (!FileUtils.makeDirectory(vpath))
HMCLog.warn("Failed to make directories: " + vpath);
if (mvt.exists() && !mvt.delete())
HMCLog.warn("Failed to delete " + mvt);

View File

@ -23,7 +23,7 @@ import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList.InstallerVersion;
import org.jackhuang.hellominecraft.launcher.core.install.forge.ForgeInstaller;
import org.jackhuang.hellominecraft.launcher.core.install.liteloader.LiteLoaderInstaller;
import org.jackhuang.hellominecraft.launcher.core.install.liteloader.LiteLoaderVersionList;
import org.jackhuang.hellominecraft.launcher.core.install.liteloader.LiteLoaderInstallerVersion;
import org.jackhuang.hellominecraft.launcher.core.install.optifine.OptiFineInstaller;
import org.jackhuang.hellominecraft.launcher.core.install.optifine.vanilla.OptiFineDownloadFormatter;
import org.jackhuang.hellominecraft.util.tasks.Task;
@ -79,11 +79,11 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
@Override
public Task downloadLiteLoader(String installId, InstallerVersion v) {
if (!(v instanceof LiteLoaderVersionList.LiteLoaderInstallerVersion))
if (!(v instanceof LiteLoaderInstallerVersion))
throw new Error("Download lite loader but the version is not ll's.");
File filepath = IOUtils.tryGetCanonicalFile("liteloader-universal.jar");
FileDownloadTask task = (FileDownloadTask) new FileDownloadTask(v.universal, filepath).setTag("LiteLoader");
return task.with(new LiteLoaderInstaller(service, installId, (LiteLoaderVersionList.LiteLoaderInstallerVersion) v).registerPreviousResult(task))
return task.with(new LiteLoaderInstaller(service, installId, (LiteLoaderInstallerVersion) v).registerPreviousResult(task))
.with(new DeleteFileTask(filepath));
}
}

View File

@ -64,7 +64,7 @@ public class ForgeInstaller extends Task {
} else
throw new IllegalStateException(C.i18n("install.no_version"));
File to = new File(gameDir, "versions" + File.separator + profile.install.getTarget());
if (!to.exists() && !to.mkdirs())
if (!FileUtils.makeDirectory(to))
HMCLog.warn("Failed to make new version folder " + to);
HMCLog.log("Copying jar..." + profile.install.getMinecraft() + ".jar to " + profile.install.getTarget() + ".jar");
@ -79,7 +79,7 @@ public class ForgeInstaller extends Task {
InputStream is = zipFile.getInputStream(entry);
MinecraftLibrary forge = new MinecraftLibrary(profile.install.getPath());
File file = new File(gameDir, "libraries/" + forge.getDownloadInfo().path);
if (file.getParentFile().mkdirs())
if (!FileUtils.makeDirectory(file))
HMCLog.warn("Failed to make library directory " + file.getParent());
try (FileOutputStream fos = FileUtils.openOutputStream(file)) {
IOUtils.copyStream(is, fos);

View File

@ -36,16 +36,16 @@ import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
*/
public class LiteLoaderInstaller extends Task implements PreviousResultRegistrar<File> {
public LiteLoaderVersionList.LiteLoaderInstallerVersion version;
public LiteLoaderInstallerVersion version;
public File installer;
public String installId;
public IMinecraftService service;
public LiteLoaderInstaller(IMinecraftService service, String installId, LiteLoaderVersionList.LiteLoaderInstallerVersion v) {
public LiteLoaderInstaller(IMinecraftService service, String installId, LiteLoaderInstallerVersion v) {
this(service, installId, v, null);
}
public LiteLoaderInstaller(IMinecraftService service, String installId, LiteLoaderVersionList.LiteLoaderInstallerVersion v, File installer) {
public LiteLoaderInstaller(IMinecraftService service, String installId, LiteLoaderInstallerVersion v, File installer) {
this.service = service;
this.installId = installId;
this.version = v;
@ -75,7 +75,7 @@ public class LiteLoaderInstaller extends Task implements PreviousResultRegistrar
mv.mainClass = "net.minecraft.launchwrapper.Launch";
mv.minecraftArguments += " --tweakClass " + version.tweakClass;
File folder = new File(service.baseDirectory(), "versions/" + mv.id);
if (!folder.exists() && folder.mkdirs())
if (!FileUtils.makeDirectory(folder))
HMCLog.warn("Failed to create new liteloader version " + folder);
File json = new File(folder, mv.id + ".json");
HMCLog.log("Creating new version profile..." + mv.id + ".json");

View File

@ -0,0 +1,58 @@
/*
* 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.install.liteloader;
import java.util.Arrays;
import java.util.Objects;
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
/**
*
* @author huang
*/
public class LiteLoaderInstallerVersion extends InstallerVersionList.InstallerVersion {
public MinecraftLibrary[] libraries;
public String tweakClass;
public LiteLoaderInstallerVersion(String selfVersion, String mcVersion) {
super(selfVersion, mcVersion);
}
@Override
public int hashCode() {
int hash = 7;
hash = 13 * hash + Arrays.deepHashCode(this.libraries);
hash = 13 * hash + Objects.hashCode(this.tweakClass);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof LiteLoaderVersionList))
return false;
if (this == obj)
return true;
final LiteLoaderInstallerVersion other = (LiteLoaderInstallerVersion) obj;
if (!Objects.equals(this.tweakClass, other.tweakClass))
return false;
return Arrays.deepEquals(this.libraries, other.libraries);
}
}

View File

@ -23,9 +23,8 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionNewerComparator;
import org.jackhuang.hellominecraft.util.StrUtils;
@ -54,7 +53,7 @@ public class LiteLoaderVersionList extends InstallerVersionList {
if (root != null)
return null;
return new TaskInfo(C.i18n("install.liteloader.get_list")) {
HTTPGetTask task = new HTTPGetTask(C.URL_LITELOADER_LIST);
HTTPGetTask task = new HTTPGetTask(DownloadType.getSuggestedDownloadType().getProvider().getParsedDownloadURL(C.URL_LITELOADER_LIST));
@Override
public Collection<Task> getDependTasks() {
@ -82,7 +81,7 @@ public class LiteLoaderVersionList extends InstallerVersionList {
continue;
LiteLoaderVersion v = entry.getValue();
LiteLoaderInstallerVersion iv = new LiteLoaderInstallerVersion(v.version, StrUtils.formatVersion(arr.getKey()));
iv.universal = "http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + arr.getKey() + "/" + v.file;
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";
@ -103,37 +102,4 @@ public class LiteLoaderVersionList extends InstallerVersionList {
return "LiteLoader - LiteLoader Official Site(By: Mumfrey)";
}
public static class LiteLoaderInstallerVersion extends InstallerVersion {
public MinecraftLibrary[] libraries;
public String tweakClass;
public LiteLoaderInstallerVersion(String selfVersion, String mcVersion) {
super(selfVersion, mcVersion);
}
@Override
public int hashCode() {
int hash = 7;
hash = 13 * hash + Arrays.deepHashCode(this.libraries);
hash = 13 * hash + Objects.hashCode(this.tweakClass);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof LiteLoaderVersionList))
return false;
if (this == obj)
return true;
final LiteLoaderInstallerVersion other = (LiteLoaderInstallerVersion) obj;
if (!Objects.equals(this.tweakClass, other.tweakClass))
return false;
return Arrays.deepEquals(this.libraries, other.libraries);
}
}
}

View File

@ -73,7 +73,7 @@ public class OptiFineInstaller extends Task implements PreviousResultRegistrar<F
}
}
File loc = new File(service.baseDirectory(), "versions/" + mv.id);
if (!loc.exists() && loc.mkdirs())
if (!FileUtils.makeDirectory(loc))
HMCLog.warn("Failed to make directories: " + loc);
File json = new File(loc, mv.id + ".json");
FileUtils.write(json, C.GSON.toJson(mv, MinecraftVersion.class));

View File

@ -23,7 +23,8 @@ package org.jackhuang.hellominecraft.launcher.core.install.optifine;
*/
public class OptiFineVersion {
private String dl, ver, date, mirror, mcver;
private String dl, ver, date, mirror, mcversion;
public String patch, type; // For BMCLAPI2.
public String getDownloadLink() {
return dl;
@ -58,10 +59,10 @@ public class OptiFineVersion {
}
public String getMCVersion() {
return mcver;
return mcversion;
}
public void setMCVersion(String mcver) {
this.mcver = mcver;
this.mcversion = mcver;
}
}

View File

@ -24,9 +24,8 @@ 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.regex.Matcher;
import java.util.regex.Pattern;
import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.ArrayUtils;
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
@ -71,23 +70,22 @@ public class OptiFineBMCLVersionList extends InstallerVersionList {
versionMap = new HashMap<>();
versions = new ArrayList<>();
HashSet<String> duplicates = new HashSet<>();
if (s == null)
return;
root = C.GSON.fromJson(s, TYPE);
for (OptiFineVersion v : root) {
v.setMirror(v.getMirror().replace("http://optifine.net/http://optifine.net/", "http://optifine.net/"));
if (StrUtils.isBlank(v.getMCVersion())) {
Pattern p = Pattern.compile("OptiFine (.*) HD");
Matcher m = p.matcher(v.getVersion());
while (m.find())
v.setMCVersion(m.group(1));
}
v.setVersion(v.type + '_' + v.patch);
v.setMirror(String.format("http://bmclapi2.bangbang93.com/optifine/%s/%s/%s", v.getMCVersion(), v.type, v.patch));
if (duplicates.contains(v.getMirror()))
continue;
else
duplicates.add(v.getMirror());
InstallerVersion iv = new InstallerVersion(v.getVersion(), StrUtils.formatVersion(v.getMCVersion()));
List<InstallerVersion> al = ArrayUtils.tryGetMapWithList(versionMap, StrUtils.formatVersion(v.getMCVersion()));
//String url = "http://bmclapi.bangbang93.com/optifine/" + iv.selfVersion.replace(" ", "%20");
iv.installer = iv.universal = v.getMirror();
al.add(iv);
versions.add(iv);

View File

@ -78,7 +78,7 @@ public class MinecraftModService extends IMinecraftModService {
if (!modCache.containsKey(id))
recacheMods(id);
File modsFolder = service.version().getRunDirectory(id, "mods");
if (!modsFolder.exists() && !modsFolder.mkdirs())
if (!FileUtils.makeDirectory(modsFolder))
HMCLog.warn("Failed to make directories: " + modsFolder);
File newf = new File(modsFolder, f.getName());
FileUtils.copyFile(f, newf);

View File

@ -256,7 +256,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
@Override
public boolean onLaunch(String id) {
File resourcePacks = new File(getRunDirectory(id), "resourcepacks");
if (!resourcePacks.exists() && !resourcePacks.mkdirs())
if (!FileUtils.makeDirectory(resourcePacks))
HMCLog.warn("Failed to make resourcePacks: " + resourcePacks);
return true;
}

View File

@ -163,7 +163,7 @@ public class AppDataUpgrader extends IUpgrader {
public void executeTask(boolean areDependTasksSucceeded) throws Exception {
HashMap<String, String> json = new HashMap<>();
File f = getSelf(newestVersion);
if (!f.getParentFile().exists() && !f.getParentFile().mkdirs())
if (!FileUtils.makeDirectory(f.getParentFile()))
HMCLog.warn("Failed to make directories: " + f.getParent());
for (int i = 0; f.exists(); i++)

View File

@ -39,6 +39,10 @@ public final class FileUtils {
private FileUtils() {
}
public static boolean makeDirectory(File directory) {
return directory.isDirectory() || directory.mkdirs();
}
public static void deleteDirectory(File directory)
throws IOException {
@ -78,7 +82,7 @@ public final class FileUtils {
public static void cleanDirectory(File directory)
throws IOException {
if (!directory.exists()) {
if (!directory.mkdirs() && !directory.isDirectory())
if (!FileUtils.makeDirectory(directory))
throw new IOException("Failed to create directory: " + directory);
return;
}
@ -174,7 +178,7 @@ public final class FileUtils {
if (destDir.exists()) {
if (!destDir.isDirectory())
throw new IOException("Destination '" + destDir + "' exists but is not a directory");
} else if ((!destDir.mkdirs()) && (!destDir.isDirectory()))
} else if (!FileUtils.makeDirectory(destDir))
throw new IOException("Destination '" + destDir + "' directory cannot be created");
if (!destDir.canWrite())
@ -229,11 +233,9 @@ public final class FileUtils {
if (srcFile.getCanonicalPath().equals(destFile.getCanonicalPath()))
throw new IOException("Source '" + srcFile + "' and destination '" + destFile + "' are the same");
File parentFile = destFile.getParentFile();
if ((parentFile != null)
&& (!parentFile.mkdirs()) && (!parentFile.isDirectory()))
if (parentFile != null && !FileUtils.makeDirectory(parentFile))
throw new IOException("Destination '" + parentFile + "' directory cannot be created");
if ((destFile.exists()) && (!destFile.canWrite()))
if (destFile.exists() && !destFile.canWrite())
throw new IOException("Destination '" + destFile + "' exists but is read-only");
doCopyFile(srcFile, destFile);
}
@ -352,8 +354,7 @@ public final class FileUtils {
throw new IOException("File '" + file + "' cannot be written to");
} else {
File parent = file.getParentFile();
if ((parent != null)
&& (!parent.mkdirs()) && (!parent.isDirectory()))
if (parent != null && !FileUtils.makeDirectory(parent))
throw new IOException("Directory '" + parent + "' could not be created");
if (!file.createNewFile())
throw new IOException("File `" + file + "` cannot be created.");

View File

@ -30,6 +30,7 @@ import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.code.DigestUtils;
import org.jackhuang.hellominecraft.util.func.Function;
import org.jackhuang.hellominecraft.util.logging.HMCLog;
import org.jackhuang.hellominecraft.util.system.FileUtils;
import org.jackhuang.hellominecraft.util.tasks.Task;
import org.jackhuang.hellominecraft.util.tasks.comm.PreviousResult;
import org.jackhuang.hellominecraft.util.tasks.comm.PreviousResultRegistrar;
@ -137,7 +138,7 @@ public class FileDownloadTask extends Task implements PreviousResult<File>, Prev
if (contentLength < 1)
throw new IOException("The content length is invalid.");
if (!filePath.getParentFile().mkdirs() && !filePath.getParentFile().isDirectory())
if (!FileUtils.makeDirectory(filePath.getParentFile()))
throw new IOException("Could not make directory");
// We use temp file to prevent files from aborting downloading and broken.