Skip to content

Commit

Permalink
reverting, able to extract without changing code, however Payload hol…
Browse files Browse the repository at this point in the history
…ds the binary and is compressed in different format, need additional work
  • Loading branch information
TheTechsTech committed Jan 26, 2018
1 parent 408eb62 commit 87f0839
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 39 deletions.
91 changes: 54 additions & 37 deletions install.js
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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) {
Expand All @@ -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',
Expand All @@ -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);
}
});
});
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 87f0839

Please sign in to comment.