mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-23 11:14:44 -04:00
修复模组详情页图标问题 (#3227)
* Update ModListPageSkin.java * Update ModListPageSkin.java * Update ModListPageSkin.java * Update ModListPageSkin.java * Update ModListPageSkin.java * Update ModListPageSkin.java * Update ModListPageSkin.java * Update ModListPageSkin.java * Update ModListPageSkin.java * Update ModListPageSkin.java * Update ModListPageSkin.java * update * 调整判断逻辑 * update * update --------- Co-authored-by: Glavo <zjx001202@gmail.com>
This commit is contained in:
parent
abf58b2c20
commit
9b5445b686
@ -59,15 +59,11 @@ import org.jackhuang.hmcl.util.io.FileUtils;
|
|||||||
import org.jackhuang.hmcl.util.io.NetworkUtils;
|
import org.jackhuang.hmcl.util.io.NetworkUtils;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.InputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.nio.file.FileSystem;
|
import java.nio.file.FileSystem;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -297,25 +293,65 @@ class ModListPageSkin extends SkinBase<ModListPage> {
|
|||||||
titleContainer.setSpacing(8);
|
titleContainer.setSpacing(8);
|
||||||
|
|
||||||
ImageView imageView = new ImageView();
|
ImageView imageView = new ImageView();
|
||||||
if (StringUtils.isNotBlank(modInfo.getModInfo().getLogoPath())) {
|
|
||||||
Task.supplyAsync(() -> {
|
Task.supplyAsync(() -> {
|
||||||
try (FileSystem fs = CompressingUtils.createReadOnlyZipFileSystem(modInfo.getModInfo().getFile())) {
|
try (FileSystem fs = CompressingUtils.createReadOnlyZipFileSystem(modInfo.getModInfo().getFile())) {
|
||||||
Path iconPath = fs.getPath(modInfo.getModInfo().getLogoPath());
|
String logoPath = modInfo.getModInfo().getLogoPath();
|
||||||
|
if (StringUtils.isNotBlank(logoPath)) {
|
||||||
|
Path iconPath = fs.getPath(logoPath);
|
||||||
if (Files.exists(iconPath)) {
|
if (Files.exists(iconPath)) {
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
try (InputStream stream = Files.newInputStream(iconPath)) {
|
||||||
Files.copy(iconPath, stream);
|
Image image = new Image(stream, 40, 40, true, true);
|
||||||
return new ByteArrayInputStream(stream.toByteArray());
|
if (!image.isError() && image.getWidth() == image.getHeight())
|
||||||
|
return image;
|
||||||
|
} catch (Throwable e) {
|
||||||
|
LOG.warning("Failed to load image " + logoPath, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> defaultPaths = new ArrayList<>(Arrays.asList(
|
||||||
|
"icon.png",
|
||||||
|
"logo.png",
|
||||||
|
"mod_logo.png",
|
||||||
|
"pack.png",
|
||||||
|
"logoFile.png"
|
||||||
|
));
|
||||||
|
|
||||||
|
String id = modInfo.getModInfo().getId();
|
||||||
|
if (StringUtils.isNotBlank(id)) {
|
||||||
|
defaultPaths.addAll(Arrays.asList(
|
||||||
|
"assets/" + id + "/icon.png",
|
||||||
|
"assets/" + id.replace("-", "") + "/icon.png",
|
||||||
|
id + ".png",
|
||||||
|
id + "-logo.png",
|
||||||
|
id + "-icon.png",
|
||||||
|
id + "_logo.png",
|
||||||
|
id + "_icon.png"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String path : defaultPaths) {
|
||||||
|
Path iconPath = fs.getPath(path);
|
||||||
|
if (Files.exists(iconPath)) {
|
||||||
|
try (InputStream stream = Files.newInputStream(iconPath)) {
|
||||||
|
Image image = new Image(stream, 40, 40, true, true);
|
||||||
|
if (!image.isError() && image.getWidth() == image.getHeight())
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.warning("Failed to load icon", e);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}).whenComplete(Schedulers.javafx(), (stream, exception) -> {
|
}).whenComplete(Schedulers.javafx(), (image, exception) -> {
|
||||||
if (stream != null) {
|
if (image != null) {
|
||||||
imageView.setImage(new Image(stream, 40, 40, true, true));
|
imageView.setImage(image);
|
||||||
} else {
|
} else {
|
||||||
imageView.setImage(FXUtils.newBuiltinImage("/assets/img/command.png", 40, 40, true, true));
|
imageView.setImage(FXUtils.newBuiltinImage("/assets/img/command.png", 40, 40, true, true));
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
|
||||||
|
|
||||||
TwoLineListItem title = new TwoLineListItem();
|
TwoLineListItem title = new TwoLineListItem();
|
||||||
title.setTitle(modInfo.getModInfo().getName());
|
title.setTitle(modInfo.getModInfo().getName());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user