From 80eae94fe194bcf1f14c163dd021c5db392f9ad4 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 26 Jun 2021 17:29:07 +0200 Subject: [PATCH] Handle leading zeros in mod filenames It's possible to put leading zeroes in the names of mod zip files which cause the existing algorithm to find the mod zip from the mod version to fail. Fix by listing the mods directory and fixing the version numbers for any of the mods with leading zeros in them. --- packages/lib/factorio/export.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/lib/factorio/export.js b/packages/lib/factorio/export.js index 093e9be3..34ee2130 100644 --- a/packages/lib/factorio/export.js +++ b/packages/lib/factorio/export.js @@ -357,6 +357,28 @@ async function exportData(server) { throw new Error("No items got exported"); } + // Some mod authors put leading zeros into the versions of their zip files. + let splitter = /^(.*)_(\d+)\.(\d+)\.(\d+)\.zip?$/; + for (let entry of await fs.readdir(server.writePath("mods"))) { + let match = splitter.exec(entry); + if (!match) { + continue; + } + + let modVersion = `${match[2]}.${match[3]}.${match[4]}`; + let normalizedVersion = + `${Number.parseInt(match[2], 10)}.${Number.parseInt(match[3], 10)}.${Number.parseInt(match[4], 10)}` + ; + + if (modVersion === normalizedVersion) { + continue; + } + + if (modVersions.get(match[1]) === normalizedVersion) { + modVersions.set(match[1], modVersion); + } + } + let { iconSheet, itemData } = await exportItems(server, modVersions, items); let locale = await exportLocale(server, modVersions, modOrder, "en");