add log lines limitation
This commit is contained in:
@@ -31,9 +31,7 @@ public final class C {
|
||||
|
||||
//http://repo1.maven.org/maven2
|
||||
public static final String URL_PUBLISH = "http://www.mcbbs.net/thread-142335-1-1.html";
|
||||
public static final String URL_TIEBA = "http://tieba.baidu.com/f?kw=hellominecraftlauncher";
|
||||
public static final String URL_GITHUB = "https://github.com/huanghongxun/HMCL/issues";
|
||||
public static final String URL_MINECRAFTFORUM = "http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-tools/1265720-hello-minecraft-launcher-1-9-3-mc-1-7-4-auto";
|
||||
public static final String URL_CONTACT = "http://huangyuhui.duapp.com/hmcl.php";
|
||||
|
||||
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";
|
||||
|
||||
@@ -51,10 +51,8 @@ public enum Level {
|
||||
public static final Pattern MINECRAFT_LOGGER_CATEGORY = Pattern.compile("\\[(?<timestamp>[0-9:]+)\\] \\[[^/]+/(?<level>[^\\]]+)\\] \\[(?<category>[^\\]]+)\\]");
|
||||
public static final String JAVA_SYMBOL = "([a-zA-Z_$][a-zA-Z\\d_$]*\\.)+[a-zA-Z_$][a-zA-Z\\d_$]*";
|
||||
|
||||
public static Level guessLevel(String line, Level preLevel) {
|
||||
if (line.startsWith("MC:"))
|
||||
line = line.substring("MC:".length());
|
||||
Level level = preLevel;
|
||||
public static Level guessLevel(String line) {
|
||||
Level level = null;
|
||||
Matcher m = MINECRAFT_LOGGER.matcher(line);
|
||||
if (m.find()) {
|
||||
// New style logs from log4j
|
||||
@@ -109,13 +107,23 @@ public enum Level {
|
||||
if (line.contains("overwriting existing"))
|
||||
return FATAL;
|
||||
|
||||
if (line.contains("Exception in thread")
|
||||
/*if (line.contains("Exception in thread")
|
||||
|| line.matches("\\s+at " + JAVA_SYMBOL)
|
||||
|| line.matches("Caused by: " + JAVA_SYMBOL)
|
||||
|| line.matches("([a-zA-Z_$][a-zA-Z\\d_$]*\\.)+[a-zA-Z_$]?[a-zA-Z\\d_$]*(Exception|Error|Throwable)")
|
||||
|| line.matches("... \\d+ more$"))
|
||||
return ERROR;
|
||||
return preLevel.level < level.level ? preLevel : level;
|
||||
return ERROR;*/
|
||||
return level;
|
||||
}
|
||||
|
||||
public static boolean isError(Level a) {
|
||||
return a == null ? false : a.lessOrEqual(Level.ERROR);
|
||||
}
|
||||
|
||||
public static Level mergeLevel(Level a, Level b) {
|
||||
if (a == null) return b;
|
||||
else if (b == null) return a;
|
||||
else return a.level < b.level ? a : b;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.jackhuang.hmcl.util.ui.SwingUtils;
|
||||
public class WebFrame extends JDialog {
|
||||
|
||||
public WebFrame(String... strs) {
|
||||
this(("<html>" + StrUtils.parseParams(t -> ("<font color='#" + GraphicsUtils.getColor(Level.guessLevel((String) t, Level.INFO).COLOR) + "'>"), strs, t -> "</font><br />") + "</html>")
|
||||
this(("<html>" + StrUtils.parseParams(t -> ("<font color='#" + GraphicsUtils.getColor(Level.mergeLevel(Level.INFO, Level.guessLevel((String) t)).COLOR) + "'>"), strs, t -> "</font><br />") + "</html>")
|
||||
.replace(" ", " ").replace("\t", " "));
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,9 @@ public class ProcessMonitor {
|
||||
public static final HashSet<ProcessMonitor> MONITORS = new HashSet<>();
|
||||
|
||||
private final CountDownLatch latch = new CountDownLatch(2);
|
||||
ProcessThread inputThread, errorThread;
|
||||
ProcessThread inputThread;
|
||||
ProcessThread errorThread;
|
||||
WaitForThread waitForThread;
|
||||
private final IProcess p;
|
||||
|
||||
public ProcessMonitor(IProcess p) {
|
||||
@@ -83,10 +85,15 @@ public class ProcessMonitor {
|
||||
private void threadStopped(SimpleEvent<IProcess> event) {
|
||||
latch.countDown();
|
||||
ProcessThread t = (ProcessThread) event.getSource();
|
||||
HMCLog.log("Process exit code: " + p.getExitCode());
|
||||
int exitCode = Integer.MAX_VALUE;
|
||||
try {
|
||||
exitCode = p.getExitCode();
|
||||
} catch(IllegalThreadStateException e) {
|
||||
HMCLog.err("Failed to ");
|
||||
}
|
||||
if (p.getExitCode() != 0 || StrUtils.containsOne(t.getLines(),
|
||||
Arrays.asList("Unable to launch"),
|
||||
x -> Level.guessLevel(x, Level.INFO).lessOrEqual(Level.ERROR)))
|
||||
Arrays.asList("Unable to launch"), // LaunchWrapper will terminate the application returning exit code 0, but this is an error state.
|
||||
x -> Level.isError(Level.guessLevel(x))))
|
||||
synchronized (this) {
|
||||
if (!hasFired) {
|
||||
hasFired = true;
|
||||
@@ -98,7 +105,7 @@ public class ProcessMonitor {
|
||||
"Error occurred during initialization of VM",
|
||||
"A fatal exception has occurred. Program will exit.",
|
||||
"Unable to launch"),
|
||||
x -> Level.guessLevel(x, Level.INFO).lessOrEqual(Level.ERROR)))
|
||||
x -> Level.isError(Level.guessLevel(x))))
|
||||
synchronized (this) {
|
||||
if (!hasFired) {
|
||||
hasFired = true;
|
||||
@@ -127,7 +134,6 @@ public class ProcessMonitor {
|
||||
try {
|
||||
latch.await();
|
||||
} catch (InterruptedException ignore) {
|
||||
HMCLog.warn("Thread has been interrupted.", ignore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class ProcessThread extends Thread {
|
||||
|
||||
protected void println(String line) {
|
||||
printlnEvent.fire(new PrintlnEvent(monitor, line, readError));
|
||||
(readError ? System.err : System.out).println("MC: " + line);
|
||||
(readError ? System.err : System.out).println(line);
|
||||
lines.add(line);
|
||||
p.getStdOutLines().add(line);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.sys;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import org.jackhuang.hmcl.api.HMCLog;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huang
|
||||
*/
|
||||
public class WaitForThread extends Thread {
|
||||
|
||||
CountDownLatch latch;
|
||||
Runnable done;
|
||||
|
||||
public WaitForThread(CountDownLatch latch, Runnable done) {
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
latch.await();
|
||||
} catch (InterruptedException ex) {
|
||||
HMCLog.err("Interrupted latch waiting");
|
||||
}
|
||||
done.run();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -123,10 +123,9 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
public InstructionsPanelImpl(BufferedImage img, Wizard wizard) {
|
||||
if (img == null)
|
||||
try {
|
||||
img = ImageIO.read(InstructionsPanelImpl.class.getResourceAsStream(
|
||||
"/org/jackhuang/hmcl/wizard.jpg"));
|
||||
} catch (IOException ioe) {
|
||||
HMCLog.err("Failed to load wizard.jpg, maybe you fucking modified the launcher", ioe);
|
||||
img = ImageIO.read(InstructionsPanelImpl.class.getResourceAsStream("/org/jackhuang/hmcl/wizard.jpg"));
|
||||
} catch (IOException | NullPointerException ioe) {
|
||||
HMCLog.err("Failed to load wizard.jpg, maybe you have fuckingly modified the launcher file", ioe);
|
||||
}
|
||||
this.img = img;
|
||||
this.wizard = wizard;
|
||||
|
||||
@@ -433,3 +433,4 @@ wizard.steps=Steps
|
||||
|
||||
lang=English
|
||||
lang.default=Belong to OS language.
|
||||
logwindow.contact=Contact Us
|
||||
|
||||
Reference in New Issue
Block a user