-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_list.js
55 lines (43 loc) · 1.52 KB
/
gen_list.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
const fs = require('fs');
const path = require('path');
const iconvlite = require('iconv-lite');
function eachfile(av) {
const files = fs.readdirSync(av);
return files.filter(f => /\.pmd$/.test(f)).sort().map(f => {
const fn = path.join(av, f);
let allBuffer = fs.readFileSync(fn, {mode: 'r', encoding: null});
let headerOffset = 0;
if(allBuffer.readInt8(0) === 0) {
headerOffset = 1;
}
// zero.b?, part_num.b, part_ofs.h[6], drum_ofs.h, title_ofs.h, title2_ofs.h
const titleOffset = allBuffer.readInt16LE(headerOffset + 1 + 12 + 2);
const title2Offset = allBuffer.readInt16LE(headerOffset + 1 + 12 + 2 + 2);
let titleStr = "", title2Str = "";
let sliceString = (start) => {
let pos;
let char;
for(pos = start; char = allBuffer.readUInt8(pos), char !== 0; pos++) {
//
}
return iconvlite.decode(allBuffer.slice(start, pos), 'ShiftJIS');
};
if(titleOffset !== 0) {
titleStr = sliceString(titleOffset).replace(/;/, "\n");
}
if(titleOffset !== 0) {
title2Str = sliceString(title2Offset).replace(/;/, "\n");
}
return {
'href': fn,
'filename': f,
'name': path.basename(f, '.pmd'),
'title': titleStr,
'title2': title2Str,
}
});
}
for(let av of process.argv.slice(2)) {
console.log(JSON.stringify(eachfile(av)));
}