Suppress image resource not found

This commit is contained in:
huanghongxun 2019-04-25 12:56:04 +08:00
parent a385265956
commit 06b67a4b9a
16 changed files with 108 additions and 59 deletions

View File

@ -31,6 +31,8 @@ import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
import static org.jackhuang.hmcl.ui.FXUtils.newImage;
public class HMCLGameRepository extends DefaultGameRepository { public class HMCLGameRepository extends DefaultGameRepository {
private final Profile profile; private final Profile profile;
private final Map<String, VersionSetting> versionSettings = new HashMap<>(); private final Map<String, VersionSetting> versionSettings = new HashMap<>();
@ -150,18 +152,18 @@ public class HMCLGameRepository extends DefaultGameRepository {
public Image getVersionIconImage(String id) { public Image getVersionIconImage(String id) {
if (id == null || !isLoaded()) if (id == null || !isLoaded())
return new Image("/assets/img/grass.png"); return newImage("/assets/img/grass.png");
Version version = getVersion(id); Version version = getVersion(id);
File iconFile = getVersionIconFile(id); File iconFile = getVersionIconFile(id);
if (iconFile.exists()) if (iconFile.exists())
return new Image("file:" + iconFile.getAbsolutePath()); return new Image("file:" + iconFile.getAbsolutePath());
else if ("net.minecraft.launchwrapper.Launch".equals(version.getMainClass())) else if ("net.minecraft.launchwrapper.Launch".equals(version.getMainClass()))
return new Image("/assets/img/furnace.png"); return newImage("/assets/img/furnace.png");
else if ("cpw.mods.modlauncher.Launcher".equals(version.getMainClass())) else if ("cpw.mods.modlauncher.Launcher".equals(version.getMainClass()))
return new Image("/assets/img/furnace.png"); return newImage("/assets/img/furnace.png");
else else
return new Image("/assets/img/grass.png"); return newImage("/assets/img/grass.png");
} }
public boolean saveVersionSetting(String id) { public boolean saveVersionSetting(String id) {

View File

@ -17,13 +17,21 @@
*/ */
package org.jackhuang.hmcl.game; package org.jackhuang.hmcl.game;
import static java.util.Collections.emptyMap; import javafx.beans.binding.Bindings;
import static java.util.Collections.singletonMap; import javafx.beans.binding.ObjectBinding;
import static java.util.Objects.requireNonNull; import javafx.embed.swing.SwingFXUtils;
import static org.jackhuang.hmcl.util.Lang.threadPool; import javafx.scene.image.Image;
import static org.jackhuang.hmcl.util.Logging.LOG; import org.jackhuang.hmcl.Metadata;
import org.jackhuang.hmcl.auth.Account;
import org.jackhuang.hmcl.auth.ServerResponseMalformedException;
import org.jackhuang.hmcl.auth.yggdrasil.*;
import org.jackhuang.hmcl.task.FileDownloadTask;
import org.jackhuang.hmcl.util.ResourceNotFoundError;
import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.javafx.BindingMapping;
import java.awt.Graphics2D; import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -40,24 +48,11 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
import javax.imageio.ImageIO; import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
import org.jackhuang.hmcl.Metadata; import static java.util.Objects.requireNonNull;
import org.jackhuang.hmcl.auth.Account; import static org.jackhuang.hmcl.util.Lang.threadPool;
import org.jackhuang.hmcl.auth.ServerResponseMalformedException; import static org.jackhuang.hmcl.util.Logging.LOG;
import org.jackhuang.hmcl.auth.yggdrasil.Texture;
import org.jackhuang.hmcl.auth.yggdrasil.TextureModel;
import org.jackhuang.hmcl.auth.yggdrasil.TextureType;
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount;
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilService;
import org.jackhuang.hmcl.task.FileDownloadTask;
import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.javafx.BindingMapping;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.ObjectBinding;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.image.Image;
/** /**
* @author yushijinhun * @author yushijinhun
@ -141,7 +136,7 @@ public final class TexturesLoader {
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) { } catch (UncheckedIOException e) {
throw new NoClassDefFoundError("Steve and alex default skin image is not found"); 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) {

View File

@ -19,7 +19,6 @@ package org.jackhuang.hmcl.ui;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.Region; import javafx.scene.layout.Region;
import javafx.stage.Stage; import javafx.stage.Stage;
import org.jackhuang.hmcl.Launcher; import org.jackhuang.hmcl.Launcher;
@ -60,6 +59,7 @@ import java.util.function.Consumer;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.jackhuang.hmcl.setting.ConfigHolder.config; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
import static org.jackhuang.hmcl.ui.FXUtils.newImage;
import static org.jackhuang.hmcl.ui.FXUtils.runInFX; import static org.jackhuang.hmcl.ui.FXUtils.runInFX;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
@ -213,7 +213,7 @@ public final class Controllers {
scene = new Scene(decorator.getDecorator(), 800, 519); scene = new Scene(decorator.getDecorator(), 800, 519);
scene.getStylesheets().setAll(config().getTheme().getStylesheets()); scene.getStylesheets().setAll(config().getTheme().getStylesheets());
stage.getIcons().add(new Image("/assets/img/icon.png")); stage.getIcons().add(newImage("/assets/img/icon.png"));
stage.setTitle(Metadata.TITLE); stage.setTitle(Metadata.TITLE);
} }

View File

@ -22,7 +22,6 @@ import javafx.scene.Scene;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.TextArea; import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
@ -30,6 +29,7 @@ import javafx.stage.Stage;
import org.jackhuang.hmcl.Metadata; import org.jackhuang.hmcl.Metadata;
import org.jackhuang.hmcl.upgrade.UpdateChecker; import org.jackhuang.hmcl.upgrade.UpdateChecker;
import static org.jackhuang.hmcl.ui.FXUtils.newImage;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
/** /**
@ -67,7 +67,7 @@ public class CrashWindow extends Stage {
Scene scene = new Scene(pane, 800, 480); Scene scene = new Scene(pane, 800, 480);
setScene(scene); setScene(scene);
getIcons().add(new Image("/assets/img/icon.png")); getIcons().add(newImage("/assets/img/icon.png"));
setTitle(i18n("message.error")); setTitle(i18n("message.error"));
setOnCloseRequest(e -> System.exit(1)); setOnCloseRequest(e -> System.exit(1));

View File

@ -34,6 +34,7 @@ import javafx.geometry.Insets;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.scene.input.ScrollEvent; import javafx.scene.input.ScrollEvent;
@ -45,6 +46,7 @@ import javafx.util.Callback;
import javafx.util.Duration; import javafx.util.Duration;
import javafx.util.StringConverter; import javafx.util.StringConverter;
import org.jackhuang.hmcl.util.Logging; import org.jackhuang.hmcl.util.Logging;
import org.jackhuang.hmcl.util.ResourceNotFoundError;
import org.jackhuang.hmcl.util.i18n.I18n; import org.jackhuang.hmcl.util.i18n.I18n;
import org.jackhuang.hmcl.util.io.FileUtils; import org.jackhuang.hmcl.util.io.FileUtils;
import org.jackhuang.hmcl.util.javafx.ExtendedProperties; import org.jackhuang.hmcl.util.javafx.ExtendedProperties;
@ -484,6 +486,21 @@ public final class FXUtils {
} }
} }
/**
* Suppress IllegalArgumentException since the url is supposed to be correct definitely.
* @param url the url of image. The image resource should be a file within the jar.
* @return the image resource within the jar.
* @see org.jackhuang.hmcl.util.CrashReporter
* @see ResourceNotFoundError
*/
public static Image newImage(String url) {
try {
return new Image(url);
} catch (IllegalArgumentException e) {
throw new ResourceNotFoundError("Cannot access image: " + url, e);
}
}
public static void applyDragListener(Node node, FileFilter filter, Consumer<List<File>> callback) { public static void applyDragListener(Node node, FileFilter filter, Consumer<List<File>> callback) {
applyDragListener(node, filter, callback, null); applyDragListener(node, filter, callback, null);
} }

View File

@ -18,7 +18,6 @@
package org.jackhuang.hmcl.ui; package org.jackhuang.hmcl.ui;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.scene.image.Image;
import javafx.scene.layout.Region; import javafx.scene.layout.Region;
import org.jackhuang.hmcl.event.EventBus; import org.jackhuang.hmcl.event.EventBus;
import org.jackhuang.hmcl.event.RefreshedVersionsEvent; import org.jackhuang.hmcl.event.RefreshedVersionsEvent;
@ -42,6 +41,7 @@ import org.jackhuang.hmcl.util.io.CompressingUtils;
import java.io.File; import java.io.File;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static org.jackhuang.hmcl.ui.FXUtils.newImage;
import static org.jackhuang.hmcl.ui.FXUtils.runInFX; import static org.jackhuang.hmcl.ui.FXUtils.runInFX;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
@ -70,12 +70,12 @@ public final class LeftPaneController extends AdvancedListBox {
profileListItem.profileProperty().bind(Profiles.selectedProfileProperty()); profileListItem.profileProperty().bind(Profiles.selectedProfileProperty());
AdvancedListItem gameItem = new AdvancedListItem(); AdvancedListItem gameItem = new AdvancedListItem();
gameItem.setImage(new Image("/assets/img/bookshelf.png")); gameItem.setImage(newImage("/assets/img/bookshelf.png"));
gameItem.setTitle(i18n("version.manage")); gameItem.setTitle(i18n("version.manage"));
gameItem.setOnAction(e -> Controllers.navigate(Controllers.getGameListPage())); gameItem.setOnAction(e -> Controllers.navigate(Controllers.getGameListPage()));
AdvancedListItem launcherSettingsItem = new AdvancedListItem(); AdvancedListItem launcherSettingsItem = new AdvancedListItem();
launcherSettingsItem.setImage(new Image("/assets/img/command.png")); launcherSettingsItem.setImage(newImage("/assets/img/command.png"));
launcherSettingsItem.setTitle(i18n("settings.launcher")); launcherSettingsItem.setTitle(i18n("settings.launcher"));
launcherSettingsItem.setOnAction(e -> Controllers.navigate(Controllers.getSettingsPage())); launcherSettingsItem.setOnAction(e -> Controllers.navigate(Controllers.getSettingsPage()));

View File

@ -25,7 +25,6 @@ import javafx.fxml.FXML;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.ComboBox; import javafx.scene.control.ComboBox;
import javafx.scene.control.ToggleButton; import javafx.scene.control.ToggleButton;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import javafx.scene.web.WebEngine; import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView; import javafx.scene.web.WebView;
@ -44,6 +43,7 @@ import org.w3c.dom.Node;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import static org.jackhuang.hmcl.setting.ConfigHolder.config; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
import static org.jackhuang.hmcl.ui.FXUtils.newImage;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
/** /**
@ -65,7 +65,7 @@ public final class LogWindow extends Stage {
setScene(new Scene(impl, 800, 480)); setScene(new Scene(impl, 800, 480));
getScene().getStylesheets().addAll(config().getTheme().getStylesheets()); getScene().getStylesheets().addAll(config().getTheme().getStylesheets());
setTitle(i18n("logwindow.title")); setTitle(i18n("logwindow.title"));
getIcons().add(new Image("/assets/img/icon.png")); getIcons().add(newImage("/assets/img/icon.png"));
} }
public LogWindow(String text) { public LogWindow(String text) {

View File

@ -18,11 +18,11 @@
package org.jackhuang.hmcl.ui; package org.jackhuang.hmcl.ui;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.web.WebView; import javafx.scene.web.WebView;
import javafx.stage.Stage; import javafx.stage.Stage;
import static org.jackhuang.hmcl.setting.ConfigHolder.config; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
import static org.jackhuang.hmcl.ui.FXUtils.newImage;
public class WebStage extends Stage { public class WebStage extends Stage {
private final WebView webView = new WebView(); private final WebView webView = new WebView();
@ -30,7 +30,7 @@ public class WebStage extends Stage {
public WebStage() { public WebStage() {
setScene(new Scene(webView, 800, 480)); setScene(new Scene(webView, 800, 480));
getScene().getStylesheets().addAll(config().getTheme().getStylesheets()); getScene().getStylesheets().addAll(config().getTheme().getStylesheets());
getIcons().add(new Image("/assets/img/icon.png")); getIcons().add(newImage("/assets/img/icon.png"));
} }
public WebView getWebView() { public WebView getWebView() {

View File

@ -20,7 +20,6 @@ package org.jackhuang.hmcl.ui.account;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
import javafx.beans.property.ObjectProperty; import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.image.Image;
import org.jackhuang.hmcl.auth.Account; import org.jackhuang.hmcl.auth.Account;
import org.jackhuang.hmcl.auth.offline.OfflineAccount; import org.jackhuang.hmcl.auth.offline.OfflineAccount;
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount; import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount;
@ -29,6 +28,7 @@ import org.jackhuang.hmcl.setting.Theme;
import org.jackhuang.hmcl.ui.SVG; import org.jackhuang.hmcl.ui.SVG;
import org.jackhuang.hmcl.ui.construct.AdvancedListItem; import org.jackhuang.hmcl.ui.construct.AdvancedListItem;
import static org.jackhuang.hmcl.ui.FXUtils.newImage;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
public class AccountAdvancedListItem extends AdvancedListItem { public class AccountAdvancedListItem extends AdvancedListItem {
@ -42,7 +42,7 @@ public class AccountAdvancedListItem extends AdvancedListItem {
setTitle(i18n("account.missing")); setTitle(i18n("account.missing"));
setSubtitle(i18n("account.missing.add")); setSubtitle(i18n("account.missing.add"));
imageProperty().unbind(); imageProperty().unbind();
setImage(new Image("/assets/img/craft_table.png")); setImage(newImage("/assets/img/craft_table.png"));
} else { } else {
titleProperty().bind(Bindings.createStringBinding(account::getCharacter, account)); titleProperty().bind(Bindings.createStringBinding(account::getCharacter, account));
setSubtitle(accountSubtitle(account)); setSubtitle(accountSubtitle(account));

View File

@ -45,7 +45,10 @@ import org.jackhuang.hmcl.setting.EnumBackgroundImage;
import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.Controllers;
import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.account.AddAuthlibInjectorServerPane; import org.jackhuang.hmcl.ui.account.AddAuthlibInjectorServerPane;
import org.jackhuang.hmcl.ui.construct.*; import org.jackhuang.hmcl.ui.construct.DialogAware;
import org.jackhuang.hmcl.ui.construct.DialogCloseEvent;
import org.jackhuang.hmcl.ui.construct.Navigator;
import org.jackhuang.hmcl.ui.construct.StackContainerPane;
import org.jackhuang.hmcl.ui.wizard.Refreshable; import org.jackhuang.hmcl.ui.wizard.Refreshable;
import org.jackhuang.hmcl.ui.wizard.WizardProvider; import org.jackhuang.hmcl.ui.wizard.WizardProvider;
@ -61,6 +64,7 @@ import java.util.logging.Level;
import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList;
import static org.jackhuang.hmcl.setting.ConfigHolder.config; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
import static org.jackhuang.hmcl.ui.FXUtils.newImage;
import static org.jackhuang.hmcl.util.Logging.LOG; import static org.jackhuang.hmcl.util.Logging.LOG;
public class DecoratorController { public class DecoratorController {
@ -92,7 +96,7 @@ public class DecoratorController {
decorator.onRefreshNavButtonActionProperty().set(e -> refresh()); decorator.onRefreshNavButtonActionProperty().set(e -> refresh());
welcomeView = new ImageView(); welcomeView = new ImageView();
welcomeView.setImage(new Image("/assets/img/welcome.png")); welcomeView.setImage(newImage("/assets/img/welcome.png"));
welcomeView.setCursor(Cursor.HAND); welcomeView.setCursor(Cursor.HAND);
FXUtils.limitSize(welcomeView, 796, 517); FXUtils.limitSize(welcomeView, 796, 517);
welcomeView.setOnMouseClicked(e -> { welcomeView.setOnMouseClicked(e -> {
@ -152,7 +156,7 @@ public class DecoratorController {
config().backgroundImageProperty())); config().backgroundImageProperty()));
} }
private Image defaultBackground = new Image("/assets/img/background.jpg"); private Image defaultBackground = newImage("/assets/img/background.jpg");
/** /**
* Load background image from bg/, background.png, background.jpg * Load background image from bg/, background.png, background.jpg

View File

@ -19,13 +19,14 @@ package org.jackhuang.hmcl.ui.profile;
import javafx.beans.property.ObjectProperty; import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.image.Image;
import org.jackhuang.hmcl.setting.Profile; import org.jackhuang.hmcl.setting.Profile;
import org.jackhuang.hmcl.setting.Profiles; import org.jackhuang.hmcl.setting.Profiles;
import org.jackhuang.hmcl.setting.Theme; import org.jackhuang.hmcl.setting.Theme;
import org.jackhuang.hmcl.ui.SVG; import org.jackhuang.hmcl.ui.SVG;
import org.jackhuang.hmcl.ui.construct.AdvancedListItem; import org.jackhuang.hmcl.ui.construct.AdvancedListItem;
import static org.jackhuang.hmcl.ui.FXUtils.newImage;
public class ProfileAdvancedListItem extends AdvancedListItem { public class ProfileAdvancedListItem extends AdvancedListItem {
private ObjectProperty<Profile> profile = new SimpleObjectProperty<Profile>() { private ObjectProperty<Profile> profile = new SimpleObjectProperty<Profile>() {
@ -41,7 +42,7 @@ public class ProfileAdvancedListItem extends AdvancedListItem {
}; };
public ProfileAdvancedListItem() { public ProfileAdvancedListItem() {
setImage(new Image("/assets/img/craft_table.png")); setImage(newImage("/assets/img/craft_table.png"));
setRightGraphic(SVG.viewList(Theme.blackFillBinding(), -1, -1)); setRightGraphic(SVG.viewList(Theme.blackFillBinding(), -1, -1));
} }

View File

@ -22,7 +22,6 @@ import com.jfoenix.controls.JFXRadioButton;
import com.jfoenix.effects.JFXDepthManager; import com.jfoenix.effects.JFXDepthManager;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.control.SkinBase; import javafx.scene.control.SkinBase;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
@ -31,6 +30,8 @@ import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.SVG; import org.jackhuang.hmcl.ui.SVG;
import org.jackhuang.hmcl.ui.construct.TwoLineListItem; import org.jackhuang.hmcl.ui.construct.TwoLineListItem;
import static org.jackhuang.hmcl.ui.FXUtils.newImage;
public class ProfileListItemSkin extends SkinBase<ProfileListItem> { public class ProfileListItemSkin extends SkinBase<ProfileListItem> {
public ProfileListItemSkin(ProfileListItem skinnable) { public ProfileListItemSkin(ProfileListItem skinnable) {
@ -54,7 +55,7 @@ public class ProfileListItemSkin extends SkinBase<ProfileListItem> {
ImageView imageView = new ImageView(); ImageView imageView = new ImageView();
FXUtils.limitSize(imageView, 32, 32); FXUtils.limitSize(imageView, 32, 32);
imageView.imageProperty().set(new Image("/assets/img/craft_table.png")); imageView.imageProperty().set(newImage("/assets/img/craft_table.png"));
TwoLineListItem item = new TwoLineListItem(); TwoLineListItem item = new TwoLineListItem();
BorderPane.setAlignment(item, Pos.CENTER); BorderPane.setAlignment(item, Pos.CENTER);

View File

@ -17,13 +17,13 @@
*/ */
package org.jackhuang.hmcl.ui.versions; package org.jackhuang.hmcl.ui.versions;
import javafx.scene.image.Image;
import org.jackhuang.hmcl.setting.Profiles; import org.jackhuang.hmcl.setting.Profiles;
import org.jackhuang.hmcl.setting.Theme; import org.jackhuang.hmcl.setting.Theme;
import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.SVG; import org.jackhuang.hmcl.ui.SVG;
import org.jackhuang.hmcl.ui.construct.AdvancedListItem; import org.jackhuang.hmcl.ui.construct.AdvancedListItem;
import static org.jackhuang.hmcl.ui.FXUtils.newImage;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
public class GameAdvancedListItem extends AdvancedListItem { public class GameAdvancedListItem extends AdvancedListItem {
@ -38,7 +38,7 @@ public class GameAdvancedListItem extends AdvancedListItem {
} else { } else {
setTitle(i18n("version.empty")); setTitle(i18n("version.empty"));
setSubtitle(i18n("version.empty.add")); setSubtitle(i18n("version.empty.add"));
setImage(new Image("/assets/img/grass.png")); setImage(newImage("/assets/img/grass.png"));
} }
}); });

View File

@ -34,11 +34,7 @@ import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
import org.jackhuang.hmcl.setting.EnumGameDirectory; import org.jackhuang.hmcl.setting.*;
import org.jackhuang.hmcl.setting.LauncherVisibility;
import org.jackhuang.hmcl.setting.Profile;
import org.jackhuang.hmcl.setting.Profiles;
import org.jackhuang.hmcl.setting.VersionSetting;
import org.jackhuang.hmcl.task.Schedulers; import org.jackhuang.hmcl.task.Schedulers;
import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.Controllers;
@ -61,6 +57,7 @@ import java.util.Optional;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.jackhuang.hmcl.ui.FXUtils.newImage;
import static org.jackhuang.hmcl.ui.FXUtils.stringConverter; import static org.jackhuang.hmcl.ui.FXUtils.stringConverter;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
@ -316,7 +313,7 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag
private void loadIcon() { private void loadIcon() {
if (versionId == null) { if (versionId == null) {
iconPickerItem.setImage(new Image("/assets/img/grass.png")); iconPickerItem.setImage(newImage("/assets/img/grass.png"));
return; return;
} }
@ -324,7 +321,7 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag
if (iconFile.exists()) if (iconFile.exists())
iconPickerItem.setImage(new Image("file:" + iconFile.getAbsolutePath())); iconPickerItem.setImage(new Image("file:" + iconFile.getAbsolutePath()));
else else
iconPickerItem.setImage(new Image("/assets/img/grass.png")); iconPickerItem.setImage(newImage("/assets/img/grass.png"));
FXUtils.limitSize(iconPickerItem.getImageView(), 32, 32); FXUtils.limitSize(iconPickerItem.getImageView(), 32, 32);
} }

View File

@ -20,7 +20,6 @@ package org.jackhuang.hmcl.util;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Alert.AlertType;
import org.jackhuang.hmcl.Metadata; import org.jackhuang.hmcl.Metadata;
import org.jackhuang.hmcl.ui.CrashWindow; import org.jackhuang.hmcl.ui.CrashWindow;
import org.jackhuang.hmcl.upgrade.IntegrityChecker; import org.jackhuang.hmcl.upgrade.IntegrityChecker;
@ -52,6 +51,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
put("Location is not set", i18n("crash.NoClassDefFound")); put("Location is not set", i18n("crash.NoClassDefFound"));
put("UnsatisfiedLinkError", i18n("crash.user_fault")); put("UnsatisfiedLinkError", i18n("crash.user_fault"));
put("java.lang.NoClassDefFoundError", i18n("crash.NoClassDefFound")); put("java.lang.NoClassDefFoundError", i18n("crash.NoClassDefFound"));
put("org.jackhuang.hmcl.util.ResourceNotFoundError", i18n("crash.NoClassDefFound"));
put("java.lang.VerifyError", i18n("crash.NoClassDefFound")); put("java.lang.VerifyError", i18n("crash.NoClassDefFound"));
put("java.lang.NoSuchMethodError", i18n("crash.NoClassDefFound")); put("java.lang.NoSuchMethodError", i18n("crash.NoClassDefFound"));
put("java.lang.NoSuchFieldError", i18n("crash.NoClassDefFound")); put("java.lang.NoSuchFieldError", i18n("crash.NoClassDefFound"));

View File

@ -0,0 +1,32 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2019 huangyuhui <huanghongxun2008@126.com> and contributors
*
* 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 <https://www.gnu.org/licenses/>.
*/
package org.jackhuang.hmcl.util;
/**
* Suppress the throwable when we make sure the resource cannot miss.
* @see CrashReporter
*/
public class ResourceNotFoundError extends Error {
public ResourceNotFoundError(String message) {
super(message);
}
public ResourceNotFoundError(String message, Throwable cause) {
super(message, cause);
}
}