diff --git a/index.js b/index.js index b756745..f80947a 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,7 @@ async function moggify() { const files = await fs.promises.readdir('mogg_input'); for(const file of files) { - console.log(file); + console.log(`Converting ${file}...`); const from = path.join('mogg_input', file); const tmp = path.join('tmp', path.parse(file).name + '.mogg'); @@ -36,6 +36,30 @@ async function moggify() { } } +async function findOGG(name) { + const files = await fs.promises.readdir('mogg_output'); + + const found = []; + + for(const file of files) { + if (file.toLowerCase().includes(name.toLowerCase())) { + found.push(file); + } + } + + if (found.length === 0) { + console.error(`Couldn't find mogg with name "${name}".`); + return false; + } + + if (found.length > 1) { + console.error(`Found more than 1 mogg with name "${name}".`); + return false; + } + + return found[0]; +} + async function replace() { if (process.argv.length !== 4) { console.error('Usage: node replace.js '); @@ -43,15 +67,13 @@ async function replace() { return; } - const mogg_file = process.argv[2] + '.mogg'; + const mogg_file = await findOGG(process.argv[2]); const game_file = process.argv[3]; - const mogg_exists = await fileExists(`mogg_output/${mogg_file}`); const uexp_exists = await fileExists(`game_input/${game_file}.uexp`); const uasset_exists = await fileExists(`game_input/${game_file}.uasset`); - if (!mogg_exists) { - console.error(`Couldn't find the .mogg file '${mogg_file}'.`); + if (!mogg_file) { return; }