Suppress NPE in LogWindow
This commit is contained in:
@@ -132,15 +132,12 @@ public final class TexturesLoader {
|
|||||||
// ==== Skins ====
|
// ==== Skins ====
|
||||||
private final static Map<TextureModel, LoadedTexture> DEFAULT_SKINS = new EnumMap<>(TextureModel.class);
|
private final static Map<TextureModel, LoadedTexture> DEFAULT_SKINS = new EnumMap<>(TextureModel.class);
|
||||||
static {
|
static {
|
||||||
try {
|
loadDefaultSkin("/assets/img/steve.png", TextureModel.STEVE);
|
||||||
loadDefaultSkin("/assets/img/steve.png", TextureModel.STEVE);
|
loadDefaultSkin("/assets/img/alex.png", TextureModel.ALEX);
|
||||||
loadDefaultSkin("/assets/img/alex.png", TextureModel.ALEX);
|
|
||||||
} catch (UncheckedIOException e) {
|
|
||||||
throw new ResourceNotFoundError("Steve and alex default skin image is not found");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadDefaultSkin(String path, TextureModel model) {
|
private static void loadDefaultSkin(String path, TextureModel model) {
|
||||||
try (InputStream in = TexturesLoader.class.getResourceAsStream(path)) {
|
try (InputStream in = ResourceNotFoundError.getResourceAsStream(path)) {
|
||||||
DEFAULT_SKINS.put(model, new LoadedTexture(ImageIO.read(in), singletonMap("model", model.modelName)));
|
DEFAULT_SKINS.put(model, new LoadedTexture(ImageIO.read(in), singletonMap("model", model.modelName)));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new UncheckedIOException(e);
|
throw new UncheckedIOException(e);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import javafx.beans.binding.ObjectBinding;
|
|||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
import org.jackhuang.hmcl.util.Logging;
|
import org.jackhuang.hmcl.util.Logging;
|
||||||
|
import org.jackhuang.hmcl.util.ResourceNotFoundError;
|
||||||
import org.jackhuang.hmcl.util.io.FileUtils;
|
import org.jackhuang.hmcl.util.io.FileUtils;
|
||||||
import org.jackhuang.hmcl.util.io.IOUtils;
|
import org.jackhuang.hmcl.util.io.IOUtils;
|
||||||
import org.jackhuang.hmcl.util.javafx.BindingMapping;
|
import org.jackhuang.hmcl.util.javafx.BindingMapping;
|
||||||
@@ -81,7 +82,7 @@ public class Theme {
|
|||||||
String css;
|
String css;
|
||||||
try {
|
try {
|
||||||
File temp = File.createTempFile("hmcl", ".css");
|
File temp = File.createTempFile("hmcl", ".css");
|
||||||
FileUtils.writeText(temp, IOUtils.readFullyAsString(Theme.class.getResourceAsStream("/assets/css/custom.css"))
|
FileUtils.writeText(temp, IOUtils.readFullyAsString(ResourceNotFoundError.getResourceAsStream("/assets/css/custom.css"))
|
||||||
.replace("%base-color%", color)
|
.replace("%base-color%", color)
|
||||||
.replace("%font-color%", getColorDisplayName(getForegroundColor())));
|
.replace("%font-color%", getColorDisplayName(getForegroundColor())));
|
||||||
css = temp.toURI().toString();
|
css = temp.toURI().toString();
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import org.jackhuang.hmcl.event.EventManager;
|
|||||||
import org.jackhuang.hmcl.game.LauncherHelper;
|
import org.jackhuang.hmcl.game.LauncherHelper;
|
||||||
import org.jackhuang.hmcl.util.Lang;
|
import org.jackhuang.hmcl.util.Lang;
|
||||||
import org.jackhuang.hmcl.util.Log4jLevel;
|
import org.jackhuang.hmcl.util.Log4jLevel;
|
||||||
|
import org.jackhuang.hmcl.util.ResourceNotFoundError;
|
||||||
import org.jackhuang.hmcl.util.StringUtils;
|
import org.jackhuang.hmcl.util.StringUtils;
|
||||||
import org.jackhuang.hmcl.util.io.IOUtils;
|
import org.jackhuang.hmcl.util.io.IOUtils;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
@@ -174,7 +175,7 @@ public final class LogWindow extends Stage {
|
|||||||
FXUtils.loadFXML(this, "/assets/fxml/log.fxml");
|
FXUtils.loadFXML(this, "/assets/fxml/log.fxml");
|
||||||
|
|
||||||
engine = webView.getEngine();
|
engine = webView.getEngine();
|
||||||
engine.loadContent(Lang.ignoringException(() -> IOUtils.readFullyAsString(getClass().getResourceAsStream("/assets/log-window-content.html")))
|
engine.loadContent(Lang.ignoringException(() -> IOUtils.readFullyAsString(ResourceNotFoundError.getResourceAsStream("/assets/log-window-content.html")))
|
||||||
.replace("${FONT}", config().getFontSize() + "px \"" + config().getFontFamily() + "\""));
|
.replace("${FONT}", config().getFontSize() + "px \"" + config().getFontFamily() + "\""));
|
||||||
engine.getLoadWorker().stateProperty().addListener((a, b, newValue) -> {
|
engine.getLoadWorker().stateProperty().addListener((a, b, newValue) -> {
|
||||||
if (newValue == Worker.State.SUCCEEDED) {
|
if (newValue == Worker.State.SUCCEEDED) {
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.util;
|
package org.jackhuang.hmcl.util;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Suppress the throwable when we make sure the resource cannot miss.
|
* Suppress the throwable when we make sure the resource cannot miss.
|
||||||
* @see CrashReporter
|
* @see CrashReporter
|
||||||
@@ -29,4 +31,11 @@ public class ResourceNotFoundError extends Error {
|
|||||||
public ResourceNotFoundError(String message, Throwable cause) {
|
public ResourceNotFoundError(String message, Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static InputStream getResourceAsStream(String url) {
|
||||||
|
InputStream stream = ResourceNotFoundError.class.getResourceAsStream(url);
|
||||||
|
if (stream == null)
|
||||||
|
throw new ResourceNotFoundError("Resource not found: " + url);
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user