Skip to content

Commit

Permalink
testing additional extraction modulus and methods on MacOS Payload fi…
Browse files Browse the repository at this point in the history
…le on windows
  • Loading branch information
TheTechsTech committed Jan 26, 2018
1 parent 87f0839 commit ac156fe
Showing 1 changed file with 60 additions and 42 deletions.
102 changes: 60 additions & 42 deletions binaryinstaller.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var fs = require('fs-extra');
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';

const _7zipData = getDataForPlatform();
Expand All @@ -12,47 +12,52 @@ const destination = path.join(cwd, process.platform);
const source = path.join(cwd, _7zipData.filename);

fs.mkdir(destination, (err) => { if (err) {}});

wget({ url: _7zipData.url + _7zipData.filename, dest: source })
.then(function () {
console.log('Decompressing ' + _7zipData.filename);
const extract = decompress(source, destination);
extract.on('file', (name) => {
console.log(name);
if (whattocopy.indexOf(path.basename(name)) == 1){
fs.renameSync(path.join(destination, _7zipData.extractfolder, _7zipData.applocation,path.basename(name)), path.join(__dirname,'binaries',process.platform,path.basename(name)));
console.log('--->File copied!');
}
});
extract.on('error', (error) => {
console.error(error);
});
extract.on('end', (name) => {
console.log('done');
});
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); });
// });
//});
});
})
.catch(function (err) {
console.log(err);
});

function getDataForPlatform(){
if (process.platform == "darwin") var macos = require('macos-release').version;
if (process.platform == "win32") var macos = '10.6';//require('macos-release').version;
switch (process.platform) {
// Windows version
case "linux": return { url: 'http://d.7-zip.org/a/',
case "darwin": return { url: 'http://d.7-zip.org/a/',
filename: '7z1800-extra.7z',
extraname: 'lzma1800.7z',
extractfolder: '',
applocation: '',
binaryfiles: [ '7za.dll', '7za.exe', '7zxa.dll', 'x64', '7zr.exe' ],
binaryfiles: ['7za.dll','7za.exe','7zxa.dll','7zr.exe'],
sfxmodules: ['7zS2.sfx','7zS2con.sfx','7zSD.sfx'] };
// Linux version
case "win32": 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',
applocation: 'bin',
binaryfiles: ['7z','7z.so','7za','7zCon.sfx','7zr','Codecs','Rar.so'],
sfxmodules: ['7zS2.sfx','7zS2con.sfx','7zSD.sfx'] };
// Mac version
case "darwin": return { url: 'https://raw.githubusercontent.com/rudix-mac/packages/master/' + macos + '/',
case "win32": return { url: 'https://raw.githubusercontent.com/rudix-mac/packages/master/' + macos + '/',
filename: 'p7zip-9.20.1-1.pkg',
extraname: '7z920_extra.7z',
extractfolder: '',
Expand All @@ -67,29 +72,42 @@ 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 rmdir(dir) {
var filename, i, item, len, list, stat;
list = fs.readdirSync(dir);
for (i = 0, len = list.length; i < len; i++) {
item = list[i];
filename = path.join(dir, item);
stat = fs.statSync(filename);
if (filename === "." || filename === "..") {

} else if (stat.isDirectory()) {
rmdir(filename);
function platformUnpacker(source, destination){
return new Promise(function (resolve, reject) {
if (process.platform == "win32"){
macunpacker(source, destination)
.then(function() {
const decompressing = require('compressing');
//const extract = decompress(path.join(destination,'p7zipinstall.pkg','Payload'), destination);
decompressing.tgz.uncompress(path.join(destination,'p7zipinstall.pkg','Payload'),
path.join(destination) );
resolve(decompressing);
});
} else {
fs.unlinkSync(filename);
const extract = decompress(source, destination);
resolve(extract);
}
}
return fs.rmdirSync(dir);
}
});
}

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);
}
});
});
}

0 comments on commit ac156fe

Please sign in to comment.