From 87f08391fd2d12f31d4d40d7feb250dfee36879d Mon Sep 17 00:00:00 2001 From: Lawrence Date: Thu, 25 Jan 2018 22:32:32 -0500 Subject: [PATCH] reverting, able to extract without changing code, however Payload holds the binary and is compressed in different format, need additional work --- install.js | 91 +++++++++++++++++++++++++++++++--------------------- package.json | 4 +-- 2 files changed, 56 insertions(+), 39 deletions(-) diff --git a/install.js b/install.js index 8dd17ca..67d6347 100644 --- a/install.js +++ b/install.js @@ -1,11 +1,10 @@ var fs = require('fs-extra'); // testing needed to move the files, having issues all other ways var path = require('path'); var decompress = require('inly'); -if (process.platform == "darwin") var macunpack = require('xar'); + // will use zip binary 7za.exe on windows to extract 7z var winfilezip = '7za920.zip'; -var macunpack = require('xar'); -var xar = require( 'xarchive' ); + const _7zipData = getDataForPlatform(); const whattocopy = _7zipData.binaryfiles; const cwd = process.cwd(); @@ -16,37 +15,28 @@ fs.mkdir(destination, (err) => { if (err) {}}); wget({ url: _7zipData.url + _7zipData.filename, dest: source }) .then(function () { - console.log('Decompressing ' + _7zipData.filename); - var buffer = fs.createWriteStream(source); - macunpack.unpack(fs.readFileSync(source), function (err, file, content) { - if (err) return console.error(err) - if (file.type[0] === 'directory') { - fs.mkdirSync(file.path) - } else { - fs.writeFileSync(file.path, content) - } - }); - }); - /* -wget({ url: _7zipData.url + _7zipData.filename, dest: source }) - .then(function () { - console.log('Decompressing ' + _7zipData.filename); - const extract = decompress(source, destination); - extract.on('file', (name) => { - if (whattocopy.indexOf(path.basename(name)) > 0) console.log(name); - }); - extract.on('error', (error) => { - console.error(error); - }); - extract.on('end', () => { - fs.move(path.join(destination, _7zipData.extractfolder, _7zipData.applocation), path.join(__dirname,'binaries',process.platform), { overwrite: true }, (err) => { if (err) return console.error(err); + console.log('Decompressing ' + _7zipData.filename); + platformUnpacker(source, destination) + .then(function (extract){ + extract.on('file', (name) => { + if (whattocopy.indexOf(path.basename(name)) > 0) console.log(name); + }); + extract.on('error', (error) => { + console.error(error); + }); + extract.on('end', () => { + fs.move(path.join(destination, _7zipData.extractfolder, _7zipData.applocation), path.join(__dirname,'binaries',process.platform), { overwrite: true }, (err) => { if (err) return console.error(err); console.log('Binaries copied successfully!'); - // fs.unlink(source, (err) => { if (err) console.error(err); }); - // fs.remove(destination, (err) => { if (err) console.error(err); }); - }); - }); + fs.unlink(source, (err) => { if (err) console.error(err); }); + fs.remove(destination, (err) => { if (err) console.error(err); }); + }); + }); + }); + }) + .catch(function (err) { + console.log(err); }); - */ + function getDataForPlatform(){ if (process.platform == "win32") var macos = '10.6';//require('macos-release').version; switch (process.platform) { @@ -59,8 +49,7 @@ function getDataForPlatform(){ binaryfiles: ['7za.dll','7za.exe','7zxa.dll','7zr.exe'], sfxmodules: ['7zS2.sfx','7zS2con.sfx','7zSD.sfx'] }; // Linux version - case "linux": return { - url: 'http://cfhcable.dl.sourceforge.net/project/p7zip/p7zip/16.02/', + case "linux": return { url: 'http://cfhcable.dl.sourceforge.net/project/p7zip/p7zip/16.02/', filename: 'p7zip_16.02_x86_linux_bin.tar.bz2', extraname: 'lzma1604.7z', extractfolder: 'p7zip_16.02', @@ -83,11 +72,39 @@ function wget(path) { return new Promise(function (resolve, reject) { require('node-wget')(path, function (err) { if (err) { - console.error('Error downloading file: '); - console.error(err); - return reject(); + console.error('Error downloading file: ' + err); + return reject(err); } resolve(); }); }); } + +function platformUnpacker(source, destination){ + return new Promise(function (resolve, reject) { + if (process.platform == "win32"){ + macunpacker(source, destination) + .then(function() { + const extract = decompress(path.join(destination,'p7zipinstall.pkg','Payload'), destination); + resolve(extract); + }); + } else { + const extract = decompress(source, destination); + resolve(extract); + } + }); +} + +function macunpacker(source,destination){ + var data = fs.readFileSync(source) + return new Promise(function (resolve, reject) { + require('xar').unpack(data, function (err, file, content) { + if (file.type[0] === 'directory'){ + fs.mkdirSync(path.join(destination, file.path)); + } else { + fs.writeFileSync(path.join(destination, file.path), content); + resolve(content); + } + }); + }); +} diff --git a/package.json b/package.json index 2e9399b..9a7ed20 100644 --- a/package.json +++ b/package.json @@ -51,14 +51,14 @@ "fs-extra": "^5.0.0", "node-wget": "^0.4.2", "inly": "^1.2.3", - "xar": "github:techno-express/xar", + "xar": "^1.1.1", "macos-release": "^1.1.0" }, "optionalDependencies": { "fs-extra": "^5.0.0", "node-wget": "^0.4.2", "inly": "^1.2.3", - "xar": "github:techno-express/xar", + "xar": "^1.1.1", "macos-release": "^1.1.0" }, "devDependencies": {