feat(launcher): use version-independent rules for space-saving copies

Replace the single-version 2.61.0.43 SHA-256 hardlink manifest with declarative read-only asset rules in packages/patcher/tuning/hardlink-resources.jsonc (content/ and content.hq/ .dxp.bin and .grp archives with no minimum size cutoff). Space-saving installs and conversions now work across minor updates, and updating a space-saving client from a same-volume source preserves or creates hard links instead of detaching them into full copies.
This commit is contained in:
N0VAN0M4LY committed 2026-12-02 17:04:36 +08:00
1 parent 3ed41bdd60
commit bf2ce539e7
14 files changed
+292 -2812

No files matched your search

@@ -0,0 +1,74 @@
/** Version-independent read-only asset rules for space-saving hardlink copies. */
import { readFileSync } from 'node:fs';
import { parseJsonc } from '@wto/jsonc';
import { GAME_FILES } from './game-copy.ts';
export interface HardlinkResourceRules {
readonly allowedDirectories: readonly string[];
readonly allowedExtensions: readonly string[];
readonly minBytes: number;
}
const TUNING_FILE = new URL('../tuning/hardlink-resources.jsonc', import.meta.url);
const PROTECTED_FILES = new Set(Object.values(GAME_FILES).map((path) => path.replaceAll('\\', '/').toLowerCase()));
let cached: HardlinkResourceRules | null = null;
export function hardlinkResourceRules(): HardlinkResourceRules {
if (cached) return cached;
const value = parseJsonc(readFileSync(TUNING_FILE, 'utf8'));
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
throw tuningError('the file is not an object');
}
const fields = value as Record<string, unknown>;
const allowedDirectories = readDirectories(fields, 'allowed_directories');
const allowedExtensions = readExtensions(fields, 'allowed_extensions');
const minBytes = readNonNegativeInteger(fields, 'min_bytes');
cached = { allowedDirectories, allowedExtensions, minBytes };
return cached;
}
/** Whether a relative path inside a stock client is a static read-only asset safe to hardlink. */
export function isHardlinkableResource(relativePath: string, bytes: number): boolean {
const rules = hardlinkResourceRules();
if (!Number.isFinite(bytes) || bytes < 0 || bytes < rules.minBytes) return false;
const normalized = relativePath.replaceAll('\\', '/').toLowerCase();
if (!normalized || normalized.startsWith('/') || normalized.includes('../') || normalized === '..') return false;
if (normalized.startsWith('wtoffline/') || PROTECTED_FILES.has(normalized)) return false;
return rules.allowedDirectories.some((dir) => normalized.startsWith(dir)) &&
rules.allowedExtensions.some((ext) => normalized.endsWith(ext));
}
function readDirectories(fields: Record<string, unknown>, key: string): readonly string[] {
const raw = fields[key];
if (!Array.isArray(raw) || raw.length === 0) throw tuningError(`"${key}" must be a non-empty string array`);
return raw.map((item) => {
if (typeof item !== 'string' || !item.endsWith('/') || item.startsWith('/') || item.includes('\\') || item.includes('..')) {
throw tuningError(`"${key}" entries must be lowercase relative prefixes ending with "/"`);
}
return item.toLowerCase();
});
}
function readExtensions(fields: Record<string, unknown>, key: string): readonly string[] {
const raw = fields[key];
if (!Array.isArray(raw) || raw.length === 0) throw tuningError(`"${key}" must be a non-empty string array`);
return raw.map((item) => {
if (typeof item !== 'string' || !item.startsWith('.') || item.length < 2 || item.includes('/') || item.includes('\\')) {
throw tuningError(`"${key}" entries must be file extensions starting with "."`);
}
return item.toLowerCase();
});
}
function readNonNegativeInteger(fields: Record<string, unknown>, key: string): number {
const value = fields[key];
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0) {
throw tuningError(`"${key}" must be a non-negative integer`);
}
return value;
}
function tuningError(detail: string): Error {
return new Error(`tuning/hardlink-resources.jsonc: ${detail}`);
}
+5
View File
@@ -18,6 +18,11 @@ export { blockingFailures, ESSENTIAL_FEATURES } from './essential-features.ts';
export { patchExecutable, type ExecutableResult } from './executable.ts';
export { assertWritableCopy, GAME_FILES, isInSteamLibrary, type WritableCopyOptions } from './game-copy.ts';
export { executableVersion } from './game-version.ts';
export {
hardlinkResourceRules,
isHardlinkableResource,
type HardlinkResourceRules,
} from './hardlink-resources.ts';
export { rebuildGuiPack, type AppliedGuiPatch, type GuiPackResult } from './gui-pack.ts';
export { loadGuiPatches, type GuiScriptEdit, type GuiScriptPatch, type GuiScriptVariant } from './gui-patch-definition.ts';
export { ENGINE_SETTINGS_PATH, EXTRA_STORE_BUNDLE_GUID_MAP, EXTRA_STORE_BUNDLE_GUIDS, rebuildMainPack, type MainPackResult } from './main-pack.ts';
@@ -0,0 +1,20 @@
// Rules for space-saving NTFS hardlink copies between the stock client and an offline client.
// Matching is version-independent so minor updates keep working without regenerating per-version
// hash lists. Only static read-only engine asset archives that the game process never writes to
// belong here; executables, vromfs archives, configs, metadata, and hotfix overlays stay copied.
{
// Relative directory prefixes (lowercase, trailing slash) containing read-only asset packs.
"allowed_directories": [
"content/",
"content.hq/"
],
// Lowercase file suffixes for static texture and model archives.
"allowed_extensions": [
".dxp.bin",
".grp"
],
// Minimum file size in bytes (0 links every matching archive regardless of size).
"min_bytes": 0
}