ame-job-manager/test-remap.js

90 lines
3.1 KiB
JavaScript
Raw Permalink Normal View History

2026-03-31 15:29:50 -04:00
/**
* Test script for the .prproj remapper.
* Run: node test-remap.js <path-to-prproj>
*/
const fs = require('fs');
const path = require('path');
const { remapPrproj, analyzePrproj } = require('./prproj-remapper');
async function main() {
const inputFile = process.argv[2];
if (!inputFile) {
console.error('Usage: node test-remap.js <path-to-prproj>');
process.exit(1);
}
console.log(`\n=== .prproj Remapper Test ===\n`);
console.log(`Input: ${inputFile}\n`);
const buffer = fs.readFileSync(inputFile);
// Step 1: Analyze
console.log('--- Analysis ---');
const analysis = await analyzePrproj(buffer);
console.log(` Total media blocks: ${analysis.totalMediaBlocks}`);
console.log(` .gves references: ${analysis.gvesReferences}`);
console.log(` High-res references: ${analysis.hiresReferences}`);
console.log(` Mapped pairs: ${analysis.mappedPairs}`);
console.log(` Unmapped .gves: ${analysis.unmappedGves}`);
console.log(` High-res formats: ${analysis.hiresFormats.join(', ')}`);
console.log('');
console.log('--- Mappings ---');
for (const m of analysis.mappings) {
const gvesShort = m.gvesPath.split('\\').pop();
const hiresShort = m.hiresPath.split('\\').pop();
console.log(` ${gvesShort}`);
console.log(`${hiresShort} (.${m.hiresExtension})`);
}
console.log('');
// Step 2: Remap
console.log('--- Remapping ---');
const result = await remapPrproj(buffer);
console.log(` Swaps performed: ${result.report.swapsPerformed}`);
for (const s of result.report.swaps) {
console.log(` ${s.oldPath.split('\\').pop()}${s.newPath.split('\\').pop()}`);
}
if (result.report.unmappedGves.length) {
console.log(`\n ⚠ Unmapped .gves files:`);
for (const u of result.report.unmappedGves) {
console.log(` ${u.path}`);
}
}
// Step 3: Write output for verification
const outputFile = inputFile.replace('.prproj', '_remapped.prproj');
fs.writeFileSync(outputFile, result.buffer);
console.log(`\n--- Output ---`);
console.log(` Written to: ${outputFile}`);
console.log(` Size: ${(result.buffer.length / 1024).toFixed(1)} KB`);
// Step 4: Verify by decompressing output and checking for remaining .gves refs
const zlib = require('zlib');
const outputXml = zlib.gunzipSync(result.buffer).toString('utf-8');
const remainingGves = (outputXml.match(/\.gves/g) || []).length;
const hiresRefs = (outputXml.match(/\\\\172\.18\.210\.5/g) || []).length;
console.log(`\n--- Verification ---`);
console.log(` Remaining .gves references in output: ${remainingGves}`);
console.log(` High-res UNC path references in output: ${hiresRefs}`);
if (remainingGves > 0) {
// Check what still references .gves
const gvesLines = outputXml.split('\n').filter(l => l.includes('.gves'));
console.log(`\n Remaining .gves lines (may be in Name tags only - expected):`);
for (const line of gvesLines.slice(0, 5)) {
console.log(` ${line.trim()}`);
}
}
console.log(`\n=== Done ===\n`);
}
main().catch(err => {
console.error('Error:', err);
process.exit(1);
});