Export without the graphics directory when it has no matching install

If host.factorio_graphics_directory had no install matching the major and
minor version of the instance, or did not exist, findVersion threw and the
whole export failed. Without the setting the same instance exports everything
except the base game icons, so it now logs a warning that names the setting
and exports without it.
This commit is contained in:
Danielv123 committed 2026-11-01 18:33:10 +01:00
1 parent 46fd7fcad4
commit 46c6153201
3 files changed
+49 -3

No files matched your search

+27 -2
View File
@@ -523,6 +523,31 @@ async function exportLocale(
return mergedLocales;
}
/**
* Find the data dir to read builtin mod graphics from
*
* @param server - The server the export runs on.
* @param graphicsDirectory - Full Factorio install, or directory of installs.
* @returns
* Data dir of the install matching the major and minor version of the
* server, or undefined if there is none.
* @internal
*/
async function findGraphicsDataDir(server: FactorioServer, graphicsDirectory: string) {
const majorMinor = server.version!.replace(/\.\d+$/, "") as lib.MajorMinorVersion;
try {
const [dataDir] = await findVersion(graphicsDirectory, majorMinor);
return dataDir;
} catch (err: any) {
// Without it the export still has everything but the base game icons
server._logger.warn(
`Unable to use host.factorio_graphics_directory for Factorio ${majorMinor}, exporting without it: ` +
`${err.message}`
);
return undefined;
}
}
/**
* Export locale, icons and metadata for the given factorio server
*
@@ -535,8 +560,7 @@ async function exportLocale(
export async function exportData(server: FactorioServer, graphicsDirectory?: string | null) {
const files: ExportFiles = { zipCache: new Map() };
if (graphicsDirectory) {
const majorMinor = server.version!.replace(/\.\d+$/, "") as lib.MajorMinorVersion;
[files.graphicsDataDir] = await findVersion(graphicsDirectory, majorMinor);
files.graphicsDataDir = await findGraphicsDataDir(server, graphicsDirectory);
}
try {
return await buildExport(server, files);
@@ -700,6 +724,7 @@ async function buildExport(server: FactorioServer, files: ExportFiles) {
export const _createSheetState = createSheetState;
export const _exportIcons = exportIcons;
export const _exportLocale = exportLocale;
export const _findGraphicsDataDir = findGraphicsDataDir;
export const _loadSimpleIcon = loadSimpleIcon;
export const _loadLayeredIcon = loadLayeredIcon;
export const _warnMissingBuiltinIcons = warnMissingBuiltinIcons;