mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 07:33:12 +09:00
Find a full install in host.factorio_directory instead of a setting
Per review, drop host.factorio_graphics_directory. findVersion takes a headless option that filters installs by build, telling them apart by data/base/graphics/icons. When the instance runs the headless build the export looks for a full install of the same major.minor version in the host's factorio directory. Server startup is unchanged. If none is found the export still runs, and the reason is included in the missing icons warning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
46c6153201
commit
37d74ca2a6
10 files changed
+132
-65
No files matched your search
@@ -262,15 +262,34 @@ export async function checkForUpdates(
|
||||
* @param targetVersion -
|
||||
* Version to look for, supports the special value "latest" for the
|
||||
* latest version available.
|
||||
* @param options - Optional parameters.
|
||||
* @param options.headless -
|
||||
* Only consider headless installs if true, or only full installs if
|
||||
* false.
|
||||
* @returns Array with path to data dir and version found.
|
||||
*/
|
||||
export async function findVersion(
|
||||
factorioDir: string,
|
||||
targetVersion: lib.TargetVersion,
|
||||
options: { headless?: boolean } = {},
|
||||
): Promise<[string, lib.FullVersion]> {
|
||||
let kind = "";
|
||||
if (options.headless !== undefined) {
|
||||
kind = options.headless ? "headless " : "full ";
|
||||
}
|
||||
const wrongKind = async (dir: string) => (
|
||||
options.headless !== undefined && await isHeadless(path.join(dir, "data")) !== options.headless
|
||||
);
|
||||
|
||||
// Check if this is a direct installation dir
|
||||
const directVersion = await getFactorioVersion(factorioDir);
|
||||
if (directVersion !== null) {
|
||||
if (await wrongKind(factorioDir)) {
|
||||
throw new Error(
|
||||
`Unable to find a ${kind}install of Factorio ${targetVersion}: ${factorioDir} is a direct ` +
|
||||
`(single-version) install of the ${options.headless ? "full" : "headless"} build.`
|
||||
);
|
||||
}
|
||||
if (targetVersion === "latest" || directVersion === targetVersion || directVersion.startsWith(targetVersion)) {
|
||||
return [path.join(factorioDir, "data"), directVersion];
|
||||
}
|
||||
@@ -287,7 +306,7 @@ export async function findVersion(
|
||||
// Avoid any fancy directory detection in order to follow symlinks
|
||||
const fullPath = path.join(factorioDir, name);
|
||||
const version = await getFactorioVersion(fullPath);
|
||||
if (version === null) {
|
||||
if (version === null || await wrongKind(fullPath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -299,7 +318,7 @@ export async function findVersion(
|
||||
}
|
||||
|
||||
if (!versions.size) {
|
||||
throw new Error(`Unable to find any Factorio install in ${factorioDir}`);
|
||||
throw new Error(`Unable to find any ${kind}Factorio install in ${factorioDir}`);
|
||||
}
|
||||
|
||||
if (lib.isPartialVersion(targetVersion)) {
|
||||
@@ -315,7 +334,26 @@ export async function findVersion(
|
||||
return [path.join(factorioDir, versions.get(latest)!, "data"), latest];
|
||||
}
|
||||
|
||||
throw new Error(`Unable to find Factorio version ${targetVersion}`);
|
||||
throw new Error(`Unable to find ${kind}Factorio version ${targetVersion}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a Factorio install is the headless build
|
||||
*
|
||||
* The headless build has no icons, which is what tells it apart.
|
||||
*
|
||||
* @param dataDir - Path to the data dir of the install.
|
||||
*/
|
||||
export async function isHeadless(dataDir: string) {
|
||||
try {
|
||||
await fs.access(path.join(dataDir, "base", "graphics", "icons"));
|
||||
return false;
|
||||
} catch (err: any) {
|
||||
if (err.code === "ENOENT" || err.code === "ENOTDIR") {
|
||||
return true;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user