Skip to content

Commit

Permalink
Converts MAME DAT files
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmo0 committed Mar 7, 2021
1 parent f687f10 commit e090dce
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,21 @@ module.exports = class Csv extends events {
parseString(datContents, (err, datXml) => {
if (err) throw err;

if (!datXml.datafile || !datXml.datafile.game) {
throw 'DAT file needs to be in the CLR MAME PRO format';
let gameNode;

if (datXml.datafile && datXml.datafile.game) {
// CLR MAME Pro format
gameNode = 'game';
}
else if (datXml.datafile && datXml.datafile.machine) {
// MAME format
gameNode = 'machine';
}
else {
throw 'DAT file needs to be in the MAME or CLRMAMEPRO format';
}

this.emit('log', 'DAT file has ' + datXml.datafile.game.length + ' games');
this.emit('log', 'DAT file has ' + datXml.datafile[gameNode].length + ' games');

// create a file handler to write into
fs.ensureFileSync(target);
Expand All @@ -267,9 +277,9 @@ module.exports = class Csv extends events {
stream.write('name;description;year;manufacturer;is_parent;romof;is_clone;cloneof;sampleof\n');

// for each game in the DAT, write a line in the CSV
let requests = datXml.datafile.game.reduce((promisechain, game, index) => {
let requests = datXml.datafile[gameNode].reduce((promisechain, game, index) => {
return promisechain.then(() => new Promise((resolve) => {
this.emit('progress.convert', datXml.datafile.game.length, index + 1, game.$.name);
this.emit('progress.convert', datXml.datafile[gameNode].length, index + 1, game.$.name);

let line = '';
line += game.$.name + ';';
Expand Down

0 comments on commit e090dce

Please sign in to comment.