installers support common path

This commit is contained in:
huangyuhui
2017-02-13 21:04:23 +08:00
parent c1208563cd
commit 0a2129aeab
9 changed files with 49 additions and 29 deletions

View File

@@ -23,6 +23,8 @@ import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.launcher.api.event.version.MinecraftLibraryPathEvent;
import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
@@ -30,6 +32,7 @@ import org.jackhuang.hellominecraft.util.task.Task;
import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
import org.jackhuang.hellominecraft.util.MessageBox;
import org.jackhuang.hellominecraft.util.Wrapper;
import org.jackhuang.hellominecraft.util.sys.IOUtils;
/**
@@ -66,19 +69,24 @@ public class ForgeInstaller extends Task {
File to = new File(gameDir, "versions" + File.separator + profile.install.getTarget());
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");
FileUtils.copyFile(new File(from, profile.install.getMinecraft() + ".jar"),
new File(to, profile.install.getTarget() + ".jar"));
new File(to, profile.install.getTarget() + ".jar"));
HMCLog.log("Creating new version profile..." + profile.install.getTarget() + ".json");
FileUtils.write(new File(to, profile.install.getTarget() + ".json"), C.GSON.toJson(profile.versionInfo));
HMCLog.log("Extracting universal forge pack..." + profile.install.getFilePath());
entry = zipFile.getEntry(profile.install.getFilePath());
InputStream is = zipFile.getInputStream(entry);
MinecraftLibrary forge = new MinecraftLibrary(profile.install.getPath());
File file = new File(gameDir, "libraries/" + forge.getDownloadInfo().path);
String path = "libraries/" + forge.getDownloadInfo().path;
MinecraftLibraryPathEvent event = new MinecraftLibraryPathEvent(this, path, new Wrapper<>(new File(gameDir, path)));
HMCAPI.EVENT_BUS.fireChannel(event);
File file = event.getFile().getValue();
if (!FileUtils.makeDirectory(file.getParentFile()))
HMCLog.warn("Failed to make library directory " + file.getParent());
try (FileOutputStream fos = FileUtils.openOutputStream(file)) {

View File

@@ -20,6 +20,8 @@ package org.jackhuang.hellominecraft.launcher.core.install.liteloader;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.launcher.api.event.version.MinecraftLibraryPathEvent;
import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
@@ -29,6 +31,7 @@ import org.jackhuang.hellominecraft.util.task.comm.PreviousResultRegistrar;
import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.util.Wrapper;
/**
*
@@ -68,7 +71,11 @@ public class LiteLoaderInstaller extends Task implements PreviousResultRegistrar
MinecraftLibrary ml = new MinecraftLibrary("com.mumfrey:liteloader:" + version.selfVersion);
//ml.url = "http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + version.mcVersion + "/liteloader-" + version.selfVersion + ".jar";
mv.libraries.add(0, ml);
FileUtils.copyFile(installer, new File(service.baseDirectory(), "libraries/com/mumfrey/liteloader/" + version.selfVersion + "/liteloader-" + version.selfVersion + ".jar"));
String path = "libraries/com/mumfrey/liteloader/" + version.selfVersion + "/liteloader-" + version.selfVersion + ".jar";
MinecraftLibraryPathEvent event = new MinecraftLibraryPathEvent(this, path, new Wrapper<>(new File(service.baseDirectory(), path)));
HMCAPI.EVENT_BUS.fireChannel(event);
FileUtils.copyFile(installer, event.getFile().getValue());
mv.id += "-LiteLoader" + version.selfVersion;

View File

@@ -20,15 +20,20 @@ package org.jackhuang.hellominecraft.launcher.core.install.optifine;
import java.io.File;
import java.util.ArrayList;
import java.util.zip.ZipFile;
import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.launcher.api.event.version.MinecraftLibraryPathEvent;
import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.version.LibrariesDownloadInfo;
import org.jackhuang.hellominecraft.launcher.core.version.LibraryDownloadInfo;
import org.jackhuang.hellominecraft.util.task.Task;
import org.jackhuang.hellominecraft.util.task.comm.PreviousResult;
import org.jackhuang.hellominecraft.util.task.comm.PreviousResultRegistrar;
import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.util.Wrapper;
import org.jackhuang.hellominecraft.util.log.HMCLog;
/**
@@ -58,8 +63,18 @@ public class OptiFineInstaller extends Task implements PreviousResultRegistrar<F
mv.inheritsFrom = mv.id;
mv.jar = mv.jar == null ? mv.id : mv.jar;
mv.libraries.clear();
mv.libraries.add(0, new MinecraftLibrary("optifine:OptiFine:" + selfId));
FileUtils.copyFile(installer, new File(service.baseDirectory(), "libraries/optifine/OptiFine/" + selfId + "/OptiFine-" + selfId + ".jar"));
MinecraftLibrary library = new MinecraftLibrary("optifine:OptiFine:" + selfId);
library.downloads = new LibrariesDownloadInfo();
library.downloads.artifact = new LibraryDownloadInfo();
library.downloads.artifact.path = "optifine/OptiFine/" + selfId + "/OptiFine-" + selfId + ".jar";
library.downloads.artifact.url = version.universal;
library.downloads.artifact.sha1 = null;
library.downloads.artifact.size = 0;
mv.libraries.add(0, library);
MinecraftLibraryPathEvent event = new MinecraftLibraryPathEvent(this, "libraries/" + library.downloads.artifact.path, new Wrapper<>(new File(service.baseDirectory(), "libraries/" + library.downloads.artifact.path)));
HMCAPI.EVENT_BUS.fireChannel(event);
FileUtils.copyFile(installer, event.getFile().getValue());
mv.id += "-" + selfId;
try (ZipFile zipFile = new ZipFile(installer)) {

View File

@@ -31,7 +31,7 @@ public class GameDownloadInfo implements Cloneable {
@SerializedName("size")
public int size;
@SerializedName("url")
protected String url;
public String url;
/**
* Ready for AssetIndexDownloadInfo, and GameDownloadInfo also need this.

View File

@@ -27,7 +27,7 @@ import java.util.Map;
public class LibrariesDownloadInfo {
@SerializedName("classifiers")
Map<String, LibraryDownloadInfo> classifiers;
public Map<String, LibraryDownloadInfo> classifiers;
@SerializedName("artifact")
LibraryDownloadInfo artifact;
public LibraryDownloadInfo artifact;
}

View File

@@ -1,17 +0,0 @@
/*
* 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/}.
*/