import { lstatSync, readFileSync } from 'node:fs'; import { join } from 'node:path'; import { intField } from '../profile/blk-fields.ts'; import { readBackupBlk } from './import/backup-blk.ts'; // The same local settings files accepted by the launcher's online backup import. const SETTINGS_FILE_LIMIT = 32 * 1024 * 1024; export function cachedSettingsVersion(folders: readonly string[], fileName: string): number { let latest = 0; for (const folder of folders) { const path = join(folder, fileName); try { const stats = lstatSync(path); if (!stats.isFile() || stats.size > SETTINGS_FILE_LIMIT) continue; const version = intField(readBackupBlk(readFileSync(path)), 'version'); if (Number.isInteger(version)) latest = Math.max(latest, version); } catch { // A missing or unreadable cache does not have a version to supersede. } } return latest; }