Supported 'logging' item in minecraft.json

This commit is contained in:
huangyuhui
2017-07-02 13:12:41 +08:00
parent 7d8a66b71a
commit 38eff7e59c
28 changed files with 490 additions and 43 deletions

View File

@@ -32,10 +32,12 @@ import org.jackhuang.hmcl.core.version.AssetIndexDownloadInfo;
import org.jackhuang.hmcl.core.version.MinecraftVersion;
import org.jackhuang.hmcl.util.MessageBox;
import org.jackhuang.hmcl.api.HMCLog;
import org.jackhuang.hmcl.core.version.LoggingInfo;
import org.jackhuang.hmcl.util.task.Task;
import org.jackhuang.hmcl.util.task.TaskWindow;
import org.jackhuang.hmcl.util.net.FileDownloadTask;
import org.jackhuang.hmcl.util.sys.FileUtils;
import org.jackhuang.hmcl.util.task.ParallelTask;
import org.jackhuang.hmcl.util.task.TaskInfo;
/**
@@ -56,7 +58,21 @@ public class MinecraftAssetService extends IMinecraftAssetService {
public Task downloadAssets(final MinecraftVersion mv) throws GameException {
if (mv == null)
return null;
return IAssetsHandler.ASSETS_HANDLER.getList(mv.resolve(service.version()), service.asset()).with(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(service.getDownloadType().getProvider()));
Task task = IAssetsHandler.ASSETS_HANDLER.getList(mv.resolve(service.version()), service.asset())
.with(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(service.getDownloadType().getProvider()));
if (mv.logging != null && mv.logging.containsKey("client")) {
LoggingInfo info = mv.logging.get("client");
File file = getLoggingObject(mv.assetIndex.getId(), info);
if (!file.exists())
return new ParallelTask().addTask(task)
.addTask(new FileDownloadTask(info.file.url, file, info.file.sha1));
}
return task;
}
@Override
public File getLoggingObject(String assetId, LoggingInfo logging) {
return new File(getAssets(assetId), "log_configs/" + logging.file.getId());
}
@Override
@@ -143,7 +159,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
}
}
protected boolean checkAssetsExistance(AssetIndexDownloadInfo assetIndex) {
protected boolean checkAssetsExistance(AssetIndexDownloadInfo assetIndex, LoggingInfo info) {
String assetId = assetIndex.getId();
File indexFile = getIndexFile(assetId);
File assetDir = getAssets(assetId);
@@ -157,6 +173,10 @@ public class MinecraftAssetService extends IMinecraftAssetService {
if (index == null)
return false;
if (info != null && !getLoggingObject(assetId, info).exists())
return false;
for (Map.Entry<String, AssetsObject> entry : index.getFileMap().entrySet())
if (!assetObjectPath(assetDir, (AssetsObject) entry.getValue()).exists())
return false;
@@ -217,7 +237,10 @@ public class MinecraftAssetService extends IMinecraftAssetService {
}
public final IAssetProvider ASSET_PROVIDER_IMPL = (t, allow) -> {
if (allow && !checkAssetsExistance(t.getAssetsIndex()))
LoggingInfo logging = null;
if (t.logging != null)
logging = t.logging.get("client");
if (allow && !checkAssetsExistance(t.getAssetsIndex(), logging))
if (MessageBox.show(C.i18n("assets.no_assets"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
TaskWindow.factory().execute(downloadAssets(t));
return reconstructAssets(t.getAssetsIndex()).getAbsolutePath();

View File

@@ -30,6 +30,7 @@ import org.jackhuang.hmcl.core.GameException;
import org.jackhuang.hmcl.api.auth.UserProfileProvider;
import org.jackhuang.hmcl.core.version.MinecraftLibrary;
import org.jackhuang.hmcl.core.service.IMinecraftService;
import org.jackhuang.hmcl.core.version.LoggingInfo;
/**
*
@@ -111,6 +112,15 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
} catch (IOException e) {
HMCLog.err("Failed to append jvm arguments when searching for asset objects.", e);
}
list.add("-Dminecraft.client.jar=" + version.getJar(service.baseDirectory()).getAbsolutePath());
if (version.logging != null && version.logging.containsKey("client")) {
LoggingInfo logging = version.logging.get("client");
File file = service.asset().getLoggingObject(version.getAssetsIndex().getId(), logging);
if (file.exists())
list.add(logging.argument.replace("${path}", file.getAbsolutePath()));
}
}
private final IAssetProvider DEFAULT_ASSET_PROVIDER = (t, allow) -> {

View File

@@ -22,6 +22,7 @@ import java.io.IOException;
import org.jackhuang.hmcl.core.GameException;
import org.jackhuang.hmcl.core.asset.AssetsObject;
import org.jackhuang.hmcl.core.version.AssetIndexDownloadInfo;
import org.jackhuang.hmcl.core.version.LoggingInfo;
import org.jackhuang.hmcl.util.task.Task;
/**
@@ -56,4 +57,6 @@ public abstract class IMinecraftAssetService extends IMinecraftBasicService {
public abstract File getAssetObject(String assetVersion, String name) throws IOException;
public abstract File getAssetObject(String assetId, AssetsObject assetsObject);
public abstract File getLoggingObject(String assetId, LoggingInfo id);
}

View File

@@ -36,7 +36,9 @@ public class GameDownloadInfo implements Cloneable {
/**
* Ready for AssetIndexDownloadInfo, and GameDownloadInfo also need this.
* And LoggingInfo will have this field in json.
*/
@SerializedName("id")
protected String id;
/**

View File

@@ -0,0 +1,41 @@
/*
* 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.version;
/**
*
* @author huang
*/
public class LoggingInfo implements Cloneable {
public GameDownloadInfo file;
public String argument;
public String type;
@Override
public Object clone() {
try {
LoggingInfo info = (LoggingInfo) super.clone();
info.file = (GameDownloadInfo) file.clone();
return info;
} catch(CloneNotSupportedException e) {
throw new Error(e);
}
}
}

View File

@@ -73,11 +73,13 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
private Map<String, GameDownloadInfo> downloads;
@SerializedName("libraries")
public ArrayList<MinecraftLibrary> libraries;
@SerializedName("logging")
public Map<String, LoggingInfo> logging;
public MinecraftVersion() {
}
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, Map<String, GameDownloadInfo> downloads, AssetIndexDownloadInfo assetIndexDownloadInfo) {
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, Map<String, GameDownloadInfo> downloads, AssetIndexDownloadInfo assetIndexDownloadInfo, Map<String, LoggingInfo> logging) {
this();
this.minecraftArguments = minecraftArguments;
this.mainClass = mainClass;
@@ -111,6 +113,13 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
for (Map.Entry<String, GameDownloadInfo> entry : downloads.entrySet())
this.downloads.put(entry.getKey(), (GameDownloadInfo) entry.getValue().clone());
}
if (logging == null)
this.logging = null;
else {
this.logging = new HashMap<>(logging.size());
for (Map.Entry<String, LoggingInfo> entry : logging.entrySet())
this.logging.put(entry.getKey(), (LoggingInfo) entry.getValue().clone());
}
}
@Override
@@ -150,7 +159,8 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
null, this.runDir, parent.minimumLauncherVersion,
this.libraries != null ? ArrayUtils.merge(this.libraries, parent.libraries) : parent.libraries, this.hidden,
this.downloads != null ? this.downloads : parent.downloads,
this.assetIndex != null ? this.assetIndex : parent.assetIndex);
this.assetIndex != null ? this.assetIndex : parent.assetIndex,
this.logging != null ? this.logging : parent.logging);
return result;
}

View File

@@ -35,6 +35,8 @@ public final class C {
public static final String URL_FORGE_LIST = "http://files.minecraftforge.net/maven/net/minecraftforge/forge/json";
public static final String URL_LITELOADER_LIST = "http://dl.liteloader.com/versions/versions.json";
public static final String LINE_SEPARATOR = System.getProperty("line.separator");
private C() {
}

View File

@@ -0,0 +1,26 @@
/*
* 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.util.log;
/**
*
* @author huang
*/
public class Parser {
}

View File

@@ -86,7 +86,6 @@ public class ProcessThread extends Thread {
protected void println(String line) {
printlnEvent.fire(new PrintlnEvent(monitor, line, readError));
(readError ? System.err : System.out).println(line);
lines.add(line);
p.getStdOutLines().add(line);
}

View File

@@ -27,15 +27,21 @@ import java.util.Collection;
public class DoubleTask extends TaskInfo {
Task a, b;
boolean reliant;
public DoubleTask(Task a, Task b) {
this(a, b, "Double Task");
this(a, b, true);
}
public DoubleTask(Task a, Task b, String info) {
public DoubleTask(Task a, Task b, boolean reliant) {
this(a, b, "Double Task", reliant);
}
public DoubleTask(Task a, Task b, String info, boolean reliant) {
super(info);
this.a = a;
this.b = b;
this.reliant = reliant;
hidden = true;
}
@@ -51,7 +57,7 @@ public class DoubleTask extends TaskInfo {
@Override
public void executeTask(boolean areDependTasksSucceeded) throws IllegalStateException {
if (!areDependTasksSucceeded)
if (!areDependTasksSucceeded && reliant)
throw new IllegalStateException("Depend tasks failed.");
}

View File

@@ -48,8 +48,9 @@ public class ParallelTask extends Task {
return tasks;
}
public void addTask(Task t) {
public ParallelTask addTask(Task t) {
tasks.add(t);
return this;
}
}

View File

@@ -390,8 +390,8 @@ update.failed=Failed to check for updates.
update.found=(Found Update!)
logwindow.terminate_game=Terminate Game
logwindow.tieba=Baidu Tieba
logwindow.title=Log
logwindow.contact=Contact Us
selector.choose=Choose

View File

@@ -390,8 +390,8 @@ update.failed=Failed to check for updates.
update.found=(Found Update!)
logwindow.terminate_game=Terminate Game
logwindow.tieba=Baidu Tieba
logwindow.title=Log
logwindow.contact=Contact Us
selector.choose=Choose
@@ -433,4 +433,3 @@ wizard.steps=Steps
lang=English
lang.default=Belong to OS language.
logwindow.contact=Contact Us

View File

@@ -388,8 +388,8 @@ update.failed=Kiểm tra cập nhật thất bại.
update.found=(Đã tìm thấy bản cập nhật!)
logwindow.terminate_game=Tắt Game
logwindow.tieba=Baidu Tieba
logwindow.title=HMCL Error Log (Hãy đăng cái này lên forum!)
logwindow.contact=Contact Us
selector.choose=Chọn

View File

@@ -388,8 +388,8 @@ update.failed=Ki\u1ec3m tra c\u1eadp nh\u1eadt th\u1ea5t b\u1ea1i.
update.found=(\u0110\u00e3 t\u00ecm th\u1ea5y b\u1ea3n c\u1eadp nh\u1eadt!)
logwindow.terminate_game=T\u1eaft Game
logwindow.tieba=Baidu Tieba
logwindow.title=HMCL Error Log (H\u00e3y \u0111\u0103ng c\u00e1i n\u00e0y l\u00ean forum!)
logwindow.contact=Contact Us
selector.choose=Ch\u1ecdn

View File

@@ -390,8 +390,8 @@ update.failed=檢查更新失敗
update.found=(發現更新!)
logwindow.terminate_game=結束遊戲進程
logwindow.tieba=貼吧
logwindow.title=日誌
logwindow.contact=聯繫我們
selector.choose=選擇

View File

@@ -390,8 +390,8 @@ update.failed=\u6aa2\u67e5\u66f4\u65b0\u5931\u6557
update.found=(\u767c\u73fe\u66f4\u65b0!)
logwindow.terminate_game=\u7d50\u675f\u904a\u6232\u9032\u7a0b
logwindow.tieba=\u8cbc\u5427
logwindow.title=\u65e5\u8a8c
logwindow.contact=\u806f\u7e6b\u6211\u5011
selector.choose=\u9078\u64c7

View File

@@ -390,8 +390,8 @@ update.failed=检查更新失败
update.found=(发现更新!)
logwindow.terminate_game=结束游戏进程
logwindow.tieba=贴吧
logwindow.title=日志
logwindow.contact=联系我们
selector.choose=选择

View File

@@ -390,8 +390,8 @@ update.failed=\u68c0\u67e5\u66f4\u65b0\u5931\u8d25
update.found=(\u53d1\u73b0\u66f4\u65b0!)
logwindow.terminate_game=\u7ed3\u675f\u6e38\u620f\u8fdb\u7a0b
logwindow.tieba=\u8d34\u5427
logwindow.title=\u65e5\u5fd7
logwindow.contact=\u8054\u7cfb\u6211\u4eec
selector.choose=\u9009\u62e9