mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-03-07 17:36:52 +08:00
Added event logs. Cloese #244
This commit is contained in:
parent
f83777e1d2
commit
1bcef2bab0
@ -202,8 +202,10 @@ public final class MainPage extends StackPane implements DecoratorPage {
|
||||
children.add(buildNode(repository, version, GameVersion.minecraftVersion(repository.getVersionJar(version.getId())).orElse("Unknown")));
|
||||
}
|
||||
JFXUtilities.runInFX(() -> {
|
||||
contentPane.getChildren().setAll(masonryPane);
|
||||
FXUtils.resetChildren(masonryPane, children);
|
||||
if (profile == repository.getProfile()) {
|
||||
contentPane.getChildren().setAll(masonryPane);
|
||||
FXUtils.resetChildren(masonryPane, children);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ public final class GameAssetDownloadTask extends Task {
|
||||
AssetObject assetObject = entry.getValue();
|
||||
String url = dependencyManager.getDownloadProvider().getAssetBaseURL() + assetObject.getLocation();
|
||||
if (!FileUtils.makeDirectory(file.getAbsoluteFile().getParentFile())) {
|
||||
Logging.LOG.log(Level.SEVERE, "Unable to create new file {0}, because parent directory cannot be created", file);
|
||||
Logging.LOG.log(Level.SEVERE, "Unable to create new file " + file + ", because parent directory cannot be created");
|
||||
continue;
|
||||
}
|
||||
if (file.isDirectory())
|
||||
|
@ -17,6 +17,8 @@
|
||||
*/
|
||||
package org.jackhuang.hmcl.event;
|
||||
|
||||
import org.jackhuang.hmcl.util.ToStringBuilder;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@ -28,13 +30,13 @@ public class Event {
|
||||
/**
|
||||
* The object on which the Event initially occurred.
|
||||
*/
|
||||
protected transient Object source;
|
||||
protected transient Object source;
|
||||
|
||||
/**
|
||||
* Constructs a prototypical Event.
|
||||
*
|
||||
* @param source The object on which the Event initially occurred.
|
||||
* @throws NullPointerException if source is null.
|
||||
* @throws NullPointerException if source is null.
|
||||
*/
|
||||
public Event(Object source) {
|
||||
Objects.requireNonNull(source);
|
||||
@ -54,10 +56,10 @@ public class Event {
|
||||
/**
|
||||
* Returns a String representation of this Event.
|
||||
*
|
||||
* @return A a String representation of this Event.
|
||||
* @return A a String representation of this Event.
|
||||
*/
|
||||
public String toString() {
|
||||
return getClass().getName() + "[source=" + source + "]";
|
||||
return new ToStringBuilder(this).append("source", source).toString();
|
||||
}
|
||||
|
||||
private boolean canceled;
|
||||
@ -72,7 +74,6 @@ public class Event {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param canceled new value
|
||||
* @throws UnsupportedOperationException if trying to cancel a non-cancelable event.
|
||||
*/
|
||||
|
@ -17,6 +17,8 @@
|
||||
*/
|
||||
package org.jackhuang.hmcl.event;
|
||||
|
||||
import org.jackhuang.hmcl.util.Logging;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
@ -36,6 +38,8 @@ public final class EventBus {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Event.Result fireEvent(Event obj) {
|
||||
Logging.LOG.info(obj + " gets fired");
|
||||
|
||||
return channel((Class<Event>) obj.getClass()).fireEvent(obj);
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
*/
|
||||
package org.jackhuang.hmcl.event;
|
||||
|
||||
import org.jackhuang.hmcl.util.ToStringBuilder;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
@ -49,4 +51,13 @@ public final class GameJsonParseFailedEvent extends Event {
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("source", source)
|
||||
.append("jsonFile", jsonFile)
|
||||
.append("version", version)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
package org.jackhuang.hmcl.event;
|
||||
|
||||
import org.jackhuang.hmcl.util.ManagedProcess;
|
||||
import org.jackhuang.hmcl.util.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* This event gets fired when we launch the JVM and it got crashed.
|
||||
@ -44,4 +45,12 @@ public class JVMLaunchFailedEvent extends Event {
|
||||
public ManagedProcess getProcess() {
|
||||
return process;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("source", source)
|
||||
.append("process", process)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
package org.jackhuang.hmcl.event;
|
||||
|
||||
import org.jackhuang.hmcl.game.Version;
|
||||
import org.jackhuang.hmcl.util.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* This event gets fired when a minecraft version has been loaded.
|
||||
@ -48,4 +49,12 @@ public final class LoadedOneVersionEvent extends Event {
|
||||
public boolean hasResult() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("source", source)
|
||||
.append("version", version)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
package org.jackhuang.hmcl.event;
|
||||
|
||||
import org.jackhuang.hmcl.util.ManagedProcess;
|
||||
import org.jackhuang.hmcl.util.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* This event gets fired when a JavaProcess exited abnormally and the exit code is not zero.
|
||||
@ -44,4 +45,12 @@ public final class ProcessExitedAbnormallyEvent extends Event {
|
||||
public ManagedProcess getProcess() {
|
||||
return process;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("source", source)
|
||||
.append("process", process)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
package org.jackhuang.hmcl.event;
|
||||
|
||||
import org.jackhuang.hmcl.util.ManagedProcess;
|
||||
import org.jackhuang.hmcl.util.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* This event gets fired when minecraft process exited successfully and the exit code is 0.
|
||||
@ -44,4 +45,12 @@ public class ProcessStoppedEvent extends Event {
|
||||
public ManagedProcess getProcess() {
|
||||
return process;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("source", source)
|
||||
.append("process", process)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
@ -35,4 +35,8 @@ public final class RefreshingVersionsEvent extends Event {
|
||||
super(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasResult() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Hello Minecraft! Launcher.
|
||||
* Copyright (C) 2018 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.event;
|
||||
|
||||
import org.jackhuang.hmcl.util.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* This event gets fired when a minecraft version is being removed.
|
||||
* <br>
|
||||
* This event is fired on the {@link org.jackhuang.hmcl.event.EventBus#EVENT_BUS}
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class RemoveVersionEvent extends Event {
|
||||
|
||||
private final String version;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param source {@link org.jackhuang.hmcl.game.GameRepository}
|
||||
* @param version the version id.
|
||||
*/
|
||||
public RemoveVersionEvent(Object source, String version) {
|
||||
super(source);
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasResult() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("source", source)
|
||||
.append("version", version)
|
||||
.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Hello Minecraft! Launcher.
|
||||
* Copyright (C) 2018 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.event;
|
||||
|
||||
import org.jackhuang.hmcl.util.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* This event gets fired when a minecraft version is being removed.
|
||||
* <br>
|
||||
* This event is fired on the {@link org.jackhuang.hmcl.event.EventBus#EVENT_BUS}
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class RenameVersionEvent extends Event {
|
||||
|
||||
private final String from, to;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param source {@link org.jackhuang.hmcl.game.GameRepository}
|
||||
* @param from the version id.
|
||||
*/
|
||||
public RenameVersionEvent(Object source, String from, String to) {
|
||||
super(source);
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public String getFromVersion() {
|
||||
return from;
|
||||
}
|
||||
|
||||
public String getToVersion() {
|
||||
return to;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasResult() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("source", source)
|
||||
.append("from", from)
|
||||
.append("to", to)
|
||||
.toString();
|
||||
}
|
||||
}
|
@ -24,6 +24,7 @@ import org.jackhuang.hmcl.task.Schedulers;
|
||||
import org.jackhuang.hmcl.util.Constants;
|
||||
import org.jackhuang.hmcl.util.FileUtils;
|
||||
import org.jackhuang.hmcl.util.Logging;
|
||||
import org.jackhuang.hmcl.util.ToStringBuilder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -116,6 +117,9 @@ public class DefaultGameRepository implements GameRepository {
|
||||
|
||||
@Override
|
||||
public boolean renameVersion(String from, String to) {
|
||||
if (EventBus.EVENT_BUS.fireEvent(new RenameVersionEvent(this, from, to)) == Event.Result.DENY)
|
||||
return false;
|
||||
|
||||
try {
|
||||
Version fromVersion = getVersion(from);
|
||||
File fromDir = getVersionRoot(from);
|
||||
@ -145,6 +149,8 @@ public class DefaultGameRepository implements GameRepository {
|
||||
public boolean removeVersionFromDisk(String id) {
|
||||
if (!versions.containsKey(id))
|
||||
return true;
|
||||
if (EventBus.EVENT_BUS.fireEvent(new RemoveVersionEvent(this, id)) == Event.Result.DENY)
|
||||
return false;
|
||||
File file = getVersionRoot(id);
|
||||
if (!file.exists())
|
||||
return true;
|
||||
@ -201,7 +207,7 @@ public class DefaultGameRepository implements GameRepository {
|
||||
try {
|
||||
FileUtils.writeText(json, Constants.GSON.toJson(version));
|
||||
} catch (Exception e) {
|
||||
Logging.LOG.log(Level.WARNING, "Ignoring version {0} because wrong id {1} is set and cannot correct it.", new Object[]{id, version.getId()});
|
||||
Logging.LOG.log(Level.WARNING, "Ignoring version " + id + " because wrong id " + version.getId() + " is set and cannot correct it.");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -217,7 +223,7 @@ public class DefaultGameRepository implements GameRepository {
|
||||
EventBus.EVENT_BUS.fireEvent(new LoadedOneVersionEvent(this, resolved)) != Event.Result.DENY)
|
||||
versions.put(version.getId(), version);
|
||||
} catch (VersionNotFoundException e) {
|
||||
Logging.LOG.log(Level.WARNING, "Ignoring version {0} because it inherits from a nonexistent version.", version.getId());
|
||||
Logging.LOG.log(Level.WARNING, "Ignoring version " + version.getId() + " because it inherits from a nonexistent version.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,7 +233,9 @@ public class DefaultGameRepository implements GameRepository {
|
||||
|
||||
@Override
|
||||
public void refreshVersions() {
|
||||
EventBus.EVENT_BUS.fireEvent(new RefreshingVersionsEvent(this));
|
||||
if (EventBus.EVENT_BUS.fireEvent(new RefreshingVersionsEvent(this)) == Event.Result.DENY)
|
||||
return;
|
||||
|
||||
Schedulers.newThread().schedule(() -> {
|
||||
refreshVersionsImpl();
|
||||
EventBus.EVENT_BUS.fireEvent(new RefreshedVersionsEvent(this));
|
||||
@ -337,4 +345,11 @@ public class DefaultGameRepository implements GameRepository {
|
||||
return getModpackConfiguration(version).exists();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("versions", versions == null ? null : versions.keySet())
|
||||
.append("baseDirectory", baseDirectory)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ public class Version implements Comparable<Version>, Validation {
|
||||
|
||||
// To maximize the compatibility.
|
||||
if (!resolvedSoFar.add(id)) {
|
||||
Logging.LOG.log(Level.WARNING, "Found circular dependency versions: {0}", resolvedSoFar);
|
||||
Logging.LOG.log(Level.WARNING, "Found circular dependency versions: " + resolvedSoFar);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -233,6 +233,11 @@ public class Version implements Comparable<Version>, Validation {
|
||||
return id.compareTo(o.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this).append("id", id).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws JsonParseException {
|
||||
if (StringUtils.isBlank(id))
|
||||
|
@ -119,7 +119,7 @@ public class FileDownloadTask extends Task {
|
||||
@Override
|
||||
public void execute() throws Exception {
|
||||
URL currentURL = url;
|
||||
Logging.LOG.log(Level.FINER, "Downloading {0} to {1}", new Object[] { currentURL, file });
|
||||
Logging.LOG.log(Level.FINER, "Downloading " + currentURL + " to " + file);
|
||||
Exception exception = null;
|
||||
|
||||
for (int repeat = 0; repeat < retry; repeat++) {
|
||||
|
@ -84,7 +84,7 @@ public final class GetTask extends TaskResult<String> {
|
||||
Exception exception = null;
|
||||
for (int time = 0; time < retry; ++time) {
|
||||
if (time > 0)
|
||||
Logging.LOG.log(Level.WARNING, "Failed to download, repeat times: {0}", time);
|
||||
Logging.LOG.log(Level.WARNING, "Failed to download, repeat times: " + time);
|
||||
try {
|
||||
updateProgress(0);
|
||||
HttpURLConnection conn = NetworkUtils.createConnection(url, proxy);
|
||||
|
@ -134,7 +134,7 @@ public final class TaskExecutor {
|
||||
task.setState(Task.TaskState.READY);
|
||||
|
||||
if (task.getSignificance().shouldLog())
|
||||
Logging.LOG.log(Level.FINE, "Executing task: {0}", task.getName());
|
||||
Logging.LOG.log(Level.FINE, "Executing task: " + task.getName());
|
||||
|
||||
taskListeners.forEach(it -> it.onReady(task));
|
||||
|
||||
@ -176,7 +176,7 @@ public final class TaskExecutor {
|
||||
|
||||
flag = true;
|
||||
if (task.getSignificance().shouldLog()) {
|
||||
Logging.LOG.log(Level.FINER, "Task finished: {0}", task.getName());
|
||||
Logging.LOG.log(Level.FINER, "Task finished: " + task.getName());
|
||||
}
|
||||
|
||||
task.onDone().fireEvent(new TaskEvent(this, task, false));
|
||||
|
@ -63,7 +63,7 @@ public final class Logging {
|
||||
String date = format.format(new Date(record.getMillis()));
|
||||
String log = String.format("[%s] [%s.%s/%s] %s%n",
|
||||
date, record.getSourceClassName(), record.getSourceMethodName(),
|
||||
record.getLevel().getName(), MessageFormat.format(record.getMessage(), record.getParameters())
|
||||
record.getLevel().getName(), record.getMessage()
|
||||
);
|
||||
ByteArrayOutputStream builder = new ByteArrayOutputStream();
|
||||
if (record.getThrown() != null)
|
||||
|
Loading…
Reference in New Issue
Block a user