Support displaying Rift mod information
This commit is contained in:
@@ -26,6 +26,8 @@ import javafx.scene.layout.BorderPane;
|
|||||||
|
|
||||||
import org.jackhuang.hmcl.mod.ModInfo;
|
import org.jackhuang.hmcl.mod.ModInfo;
|
||||||
import org.jackhuang.hmcl.setting.Theme;
|
import org.jackhuang.hmcl.setting.Theme;
|
||||||
|
import org.jackhuang.hmcl.util.StringUtils;
|
||||||
|
|
||||||
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@@ -54,7 +56,14 @@ public final class ModItem extends BorderPane {
|
|||||||
setStyle("-fx-background-radius: 2; -fx-background-color: white; -fx-padding: 8;");
|
setStyle("-fx-background-radius: 2; -fx-background-color: white; -fx-padding: 8;");
|
||||||
JFXDepthManager.setDepth(this, 1);
|
JFXDepthManager.setDepth(this, 1);
|
||||||
modItem.setTitle(info.getFileName());
|
modItem.setTitle(info.getFileName());
|
||||||
modItem.setSubtitle(info.getName() + ", " + i18n("archive.version") + ": " + info.getVersion() + ", " + i18n("archive.game_version") + ": " + info.getGameVersion() + ", " + i18n("archive.author") + ": " + info.getAuthors());
|
StringBuilder message = new StringBuilder(info.getName());
|
||||||
|
if (StringUtils.isNotBlank(info.getVersion()))
|
||||||
|
message.append(", ").append(i18n("archive.version")).append(": ").append(info.getVersion());
|
||||||
|
if (StringUtils.isNotBlank(info.getGameVersion()))
|
||||||
|
message.append(", ").append(i18n("archive.game_version")).append(": ").append(info.getGameVersion());
|
||||||
|
if (StringUtils.isNotBlank(info.getAuthors()))
|
||||||
|
message.append(", ").append(i18n("archive.author")).append(": ").append(info.getAuthors());
|
||||||
|
modItem.setSubtitle(message.toString());
|
||||||
chkEnabled.setSelected(info.isActive());
|
chkEnabled.setSelected(info.isActive());
|
||||||
chkEnabled.selectedProperty().addListener((a, b, newValue) ->
|
chkEnabled.selectedProperty().addListener((a, b, newValue) ->
|
||||||
info.activeProperty().set(newValue));
|
info.activeProperty().set(newValue));
|
||||||
|
|||||||
@@ -152,14 +152,20 @@ public final class ModInfo implements Comparable<ModInfo> {
|
|||||||
try {
|
try {
|
||||||
return ForgeModMetadata.fromFile(modFile);
|
return ForgeModMetadata.fromFile(modFile);
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
description = "May be Forge mod";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return RiftModMetadata.fromFile(modFile);
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
}
|
||||||
|
|
||||||
|
description = "";
|
||||||
break;
|
break;
|
||||||
case "litemod":
|
case "litemod":
|
||||||
try {
|
try {
|
||||||
return LiteModMetadata.fromFile(modFile);
|
return LiteModMetadata.fromFile(modFile);
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
description = "May be LiteLoader mod";
|
description = "LiteLoader Mod";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* 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.mod;
|
||||||
|
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
|
import org.jackhuang.hmcl.util.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileSystem;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
public final class RiftModMetadata {
|
||||||
|
private final String id;
|
||||||
|
private final String name;
|
||||||
|
private final List<String> authors;
|
||||||
|
|
||||||
|
public RiftModMetadata() {
|
||||||
|
this("", "", Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public RiftModMetadata(String id, String name, List<String> authors) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.authors = authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getAuthors() {
|
||||||
|
return authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ModInfo fromFile(File modFile) throws IOException, JsonParseException {
|
||||||
|
try (FileSystem fs = CompressingUtils.createReadOnlyZipFileSystem(modFile.toPath())) {
|
||||||
|
Path mcmod = fs.getPath("riftmod.json");
|
||||||
|
if (Files.notExists(mcmod))
|
||||||
|
throw new IOException("File " + modFile + " is not a Forge mod.");
|
||||||
|
RiftModMetadata metadata = JsonUtils.fromNonNullJson(IOUtils.readFullyAsString(Files.newInputStream(mcmod)), RiftModMetadata.class);
|
||||||
|
String authors = metadata.getAuthors() == null ? "" : String.join(", ", metadata.getAuthors());
|
||||||
|
return new ModInfo(modFile, metadata.getName(), "",
|
||||||
|
authors, "", "", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user