From 61b065874353cdf13d7becd274426b0ca024d362 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Mon, 3 Oct 2016 22:03:32 -0600 Subject: [PATCH] Work on new archivers layout, short/long desc file discovery --- core/archive_util.js | 4 ++-- core/config.js | 54 ++++++++++++++++++++++++++++++++++++++++++-- core/file_area.js | 22 ++++++++++++++---- 3 files changed, 71 insertions(+), 9 deletions(-) diff --git a/core/archive_util.js b/core/archive_util.js index b84b8b98..c21bf4ce 100644 --- a/core/archive_util.js +++ b/core/archive_util.js @@ -214,9 +214,9 @@ module.exports = class ArchiveUtil { // } const entries = []; - const entryMatchRe = new RegExp(archiver.list.entryMatch, 'g'); + const entryMatchRe = new RegExp(archiver.list.entryMatch, 'gm'); let m; - while(null !== (m = entryMatchRe.exec(output))) { + while((m = entryMatchRe.exec(output))) { // :TODO: allow alternate ordering!!! entries.push({ size : m[1], diff --git a/core/config.js b/core/config.js index 8c2a89c5..96427624 100644 --- a/core/config.js +++ b/core/config.js @@ -226,12 +226,62 @@ function getDefaultConfig() { list : { cmd : '7z', args : [ 'l', '{archivePath}' ], - entryMatch : '^[0-9]{4}-[0-9]{2}-[0-9]{2}\\s[0-9]{2}:[0-9]{2}:[0-9]{2}\\s[A-Za-z\\.]{5}\\s+([0-9]+)\\s+[0-9]+\\s+([^\\n]+)$', + entryMatch : '^[0-9]{4}-[0-9]{2}-[0-9]{2}\\s[0-9]{2}:[0-9]{2}:[0-9]{2}\\s[A-Za-z\\.]{5}\\s+([0-9]+)\\s+[0-9]+\\s+([^\\r\\n]+)$', }, extract : { cmd : '7z', args : [ 'x', '-o{extractPath}', '{archivePath}', '{fileList}' ], - }, + }, + }, + }, + + archivers2 : { + tools : { + '7Zip' : { + compress : { + cmd : '7z', + args : [ 'a', '-tzip', '{archivePath}', '{fileList}' ], + }, + decompress : { + cmd : '7z', + args : [ 'e', '-o{extractPath}', '{archivePath}' ] + }, + list : { + cmd : '7z', + args : [ 'l', '{archivePath}' ], + entryMatch : '^[0-9]{4}-[0-9]{2}-[0-9]{2}\\s[0-9]{2}:[0-9]{2}:[0-9]{2}\\s[A-Za-z\\.]{5}\\s+([0-9]+)\\s+[0-9]+\\s+([^\\r\\n]+)$', + }, + extract : { + cmd : '7z', + args : [ 'x', '-o{extractPath}', '{archivePath}', '{fileList}' ], + }, + } + }, + formats : { + zip : { + sig : '504b0304', + offset : 0, + exts : [ 'zip' ], + tool : '7Zip', + }, + '7z' : { + sig : '377abcaf271c', + offset : 0, + exts : [ '7z' ], + tool : '7Zip', + }, + arj : { + sig : '60ea', + offset : 0, + exts : [ 'arj' ], + tool : '7Zip', + }, + rar : { + sig : '526172211a0700', + offset : 0, + exts : [ 'rar' ], + tool : '7Zip', + } } }, diff --git a/core/file_area.js b/core/file_area.js index 4f33d218..c6ae2f0e 100644 --- a/core/file_area.js +++ b/core/file_area.js @@ -143,13 +143,25 @@ function getExistingFileEntriesBySha1(sha1, cb) { function addNewArchiveFileEnty(fileEntry, filePath, archiveType, cb) { const archiveUtil = ArchiveUtil.getInstance(); - async.series( + async.waterfall( [ - function getArchiveFileList(callback) { - // :TODO: get list of files in archive + function getArchiveFileList(callback) { archiveUtil.listEntries(filePath, archiveType, (err, entries) => { - return callback(err); - }); + return callback(null, entries || []); // ignore any errors here + }); + }, + function extractDescFiles(entries, callback) { + + // :TODO: would be nice if these RegExp's were cached + const shortDescFile = entries.find( e => { + return Config.fileBase.fileNamePatterns.shortDesc.find( pat => new RegExp(pat, 'i').test(e.fileName) ); + }); + + const longDescFile = entries.find( e => { + return Config.fileBase.fileNamePatterns.longDesc.find( pat => new RegExp(pat, 'i').test(e.fileName) ); + }); + + return callback(null); } ], err => {