Mark missing or missmatched checksum for mods in mod packs

Mark mods in the UI and the mod-pack show ctl command that are missing
with a question mark and mark mods with a missmatched checksum with an
exclamation mark.
This commit is contained in:
Hornwitser committed 2022-11-10 00:28:50 +01:00
1 parent e6add2f7e6
commit fb75e47eda
3 files changed
+36 -4

No files matched your search

+8 -1
View File
@@ -867,6 +867,9 @@ modPackCommands.add(new libCommand.Command({
yargs.positional("mod-pack", { describe: "Mod pack to show", type: "string" });
}],
handler: async function(args, control) {
let mods = new Map(
(await libLink.messages.listMods.send(control)).list.map(m => [`${m.name}_${m.version}`, m])
);
let response = await libLink.messages.getModPack.send(control, {
id: await libCommand.resolveModPack(control, args.modPack),
});
@@ -875,8 +878,12 @@ modPackCommands.add(new libCommand.Command({
if (field === "mods") {
print(`${field}:`);
for (let entry of value) {
const mod = mods.get(`${entry.name}_${entry.version}`);
const missing = !mod && "? ";
const badChecksum = mod && entry.sha1 && entry.sha1 !== mod.sha1 && "! ";
const warn = missing || badChecksum || "";
const enabled = entry.enabled ? "" : "(disabled) ";
print(` ${enabled}${entry.name} ${entry.version}${entry.sha1 ? ` (${entry.sha1})` : ""}`);
print(` ${warn}${enabled}${entry.name} ${entry.version}${entry.sha1 ? ` (${entry.sha1})` : ""}`);
}
} else if (field === "settings") {
print(`${field}:`);
@@ -1,5 +1,6 @@
import React, { Fragment } from "react";
import { Descriptions, Grid, Typography } from "antd";
import ExclamationCircleOutlined from "@ant-design/icons/ExclamationCircleOutlined";
import { libHelpers } from "@clusterio/lib";
@@ -11,6 +12,12 @@ export default function ModDetails(props) {
const mod = props.mod;
return <Descriptions className="borderless" bordered size="small" column={{ xs: 1, sm: 1, md: 1, lg: 2 }}>
{mod.error && <Descriptions.Item label={<><ExclamationCircleOutlined/> Error</>} span={2}>
{mod.error === "missing" && "The given version of this mod is missing from the master storage."}
{mod.error === "bad_checksum"
&& "Checksum of the mod in the master storage does not match the checksum provided by this mod pack."
}
</Descriptions.Item>}
{props.actions && !screens.lg
&& <Descriptions.Item label="Action">{props.actions(mod)}</Descriptions.Item>
}
@@ -6,6 +6,8 @@ import {
} from "antd";
import InfoCircleOutlined from "@ant-design/icons/InfoCircleOutlined";
import ExportOutlined from "@ant-design/icons/ExportOutlined";
import FileUnknownOutlined from "@ant-design/icons/FileUnknownOutlined";
import FileExclamationOutlined from "@ant-design/icons/FileExclamationOutlined";
import CloseOutlined from "@ant-design/icons/CloseOutlined";
import DeleteOutlined from "@ant-design/icons/DeleteOutlined";
import PlusOutlined from "@ant-design/icons/PlusOutlined";
@@ -213,8 +215,16 @@ function ModsTable(props) {
const mods = [...props.modPack.mods.values(), ...deletedMods.values()].map(
mod => {
const candidate = modListMap.get(`${mod.name}_${mod.version}`);
if (!candidate || mod.sha1 && candidate.sha1 !== mod.sha1) {
return mod;
if (!candidate) {
return {
...mod,
error: "missing",
};
} else if (mod.sha1 && candidate.sha1 !== mod.sha1) {
return {
...mod,
error: "bad_checksum",
};
}
return candidate;
}
@@ -289,7 +299,15 @@ function ModsTable(props) {
{
title: "Name",
key: "name",
render: mod => mod.title || mod.name,
render: mod => <>
{mod.error === "missing" && <Tooltip title="Mod is missing from storage.">
<FileUnknownOutlined style={{ color: "#a61d24" }} />{" "}
</Tooltip>}
{mod.error === "bad_checksum" && <Tooltip title="Mod checksum missmatch.">
<FileExclamationOutlined style={{ color: "#a61d24" }} />{" "}
</Tooltip>}
{mod.title || mod.name}
</>,
defaultSortOrder: "ascend",
sorter: (a, b) => strcmp(a.name, b.name),
},