2024-05-30 02:02:47 +00:00
|
|
|
import * as fs from 'fs/promises';
|
|
|
|
import * as path from 'path';
|
|
|
|
|
|
|
|
let g_count = 0;
|
|
|
|
let g_countSkip = 0;
|
|
|
|
|
|
|
|
const readChart = async (fname: string) => {
|
|
|
|
const data = (await fs.readFile(fname)).toString().split('\n');
|
|
|
|
let res: string[] = [];
|
|
|
|
let isBPalette = false;
|
|
|
|
let isCorrectVersion = false;
|
2024-05-30 10:13:20 +00:00
|
|
|
for(let line of data) {
|
|
|
|
line = line.trimEnd();
|
2024-05-30 02:02:47 +00:00
|
|
|
if(line.startsWith('VERSION')) {
|
2024-05-30 10:13:20 +00:00
|
|
|
if(line === 'VERSION\t1\t6\t0') {
|
|
|
|
res.push('VERSION\t1\t7\t0');
|
2024-05-30 02:02:47 +00:00
|
|
|
isCorrectVersion = true;
|
|
|
|
}
|
|
|
|
} else if(line.startsWith('[')) {
|
2024-05-30 10:13:20 +00:00
|
|
|
isBPalette = line === '[B_PALETTE]';
|
2024-05-30 02:02:47 +00:00
|
|
|
res.push(line);
|
|
|
|
} else if(isBPalette) {
|
2024-05-30 10:13:20 +00:00
|
|
|
if(line.length > 0) {
|
|
|
|
res.push(`${line}\t0`);
|
2024-05-30 02:02:47 +00:00
|
|
|
} else {
|
|
|
|
res.push(line);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
res.push(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!isCorrectVersion) {
|
|
|
|
g_countSkip += 1;
|
|
|
|
console.log(`Skipped ${fname}`);
|
|
|
|
} else {
|
|
|
|
g_count += 1;
|
2024-05-30 10:13:20 +00:00
|
|
|
await fs.writeFile(fname, res.join('\r\n'));
|
2024-05-30 02:02:47 +00:00
|
|
|
console.log(`Updated ${fname}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
if(process.argv.length < 3) {
|
|
|
|
console.log(`Usage: ${process.argv[0]} ${process.argv[1]} <Axyz/music>`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const p = process.argv[2];
|
|
|
|
const dirs = (await fs.readdir(p));
|
|
|
|
|
|
|
|
const promises: Promise<void>[] = [];
|
|
|
|
for(const dir of dirs) {
|
|
|
|
const subpath = path.join(p, dir);
|
|
|
|
const subdir = await fs.readdir(subpath);
|
|
|
|
for(const file of subdir) {
|
|
|
|
if(file.endsWith("ogkr")) {
|
|
|
|
promises.push(readChart(path.join(p, dir, file)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
await Promise.all(promises);
|
|
|
|
|
|
|
|
console.log(`${g_count} files updated, ${g_countSkip} files skipped.`);
|
|
|
|
})();
|