diff --git a/.gitignore b/.gitignore index 099f639..11fb8de 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ jspm_packages .vscode package-lock.json +apps/ \ No newline at end of file diff --git a/config.js b/config.js index 9c32b26..601b4bb 100644 --- a/config.js +++ b/config.js @@ -20,6 +20,7 @@ along with this program. If not, see . let fs = require('fs'); let argv = require('minimist')(process.argv.slice(2)); let utils = require('./libs/utils'); +let apps = require('./libs/apps'); const spawnSync = require('child_process').spawnSync; if (argv.help){ @@ -141,8 +142,8 @@ config.maxConcurrency = parseInt(argv.max_concurrency || fromConfigFile("maxConc config.maxRuntime = parseInt(argv.max_runtime || fromConfigFile("maxRuntime", -1)); // Detect 7z availability -config.has7z = spawnSync("7z", ['--help']).status === 0; -config.hasUnzip = spawnSync("unzip", ['--help']).status === 0; +config.has7z = spawnSync(apps.sevenZ, ['--help']).status === 0; +config.hasUnzip = spawnSync(apps.unzip, ['--help']).status === 0; module.exports = config; diff --git a/libs/apps.js b/libs/apps.js new file mode 100644 index 0000000..76fbbff --- /dev/null +++ b/libs/apps.js @@ -0,0 +1,34 @@ +/* +Node-OpenDroneMap Node.js App and REST API to access OpenDroneMap. +Copyright (C) 2016 Node-OpenDroneMap Contributors + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ +const fs = require('fs'); +const path = require('path'); + +let sevenZ = "7z"; +let unzip = "unzip"; + +if (fs.existsSync(path.join("apps", "7z", "7z.exe"))){ + sevenZ = path.resolve(path.join("apps", "7z", "7z.exe")); +} + +if (fs.existsSync(path.join("apps", "unzip", "unzip.exe"))){ + unzip = path.resolve(path.join("apps", "unzip", "unzip.exe")); +} + +module.exports = { + sevenZ, unzip +}; \ No newline at end of file diff --git a/libs/processRunner.js b/libs/processRunner.js index 7c356f2..84eec19 100644 --- a/libs/processRunner.js +++ b/libs/processRunner.js @@ -17,6 +17,7 @@ along with this program. If not, see . */ "use strict"; let fs = require('fs'); +let apps = require('./apps'); let path = require('path'); let assert = require('assert'); let spawn = require('child_process').spawn; @@ -92,14 +93,14 @@ module.exports = { }, ["projectFolderPath"]), - sevenZip: makeRunner("7z", function(options){ + sevenZip: makeRunner(apps.sevenZ, function(options){ return ["a", "-mx=0", "-y", "-r", "-bd", options.destination].concat(options.pathsToArchive); }, ["destination", "pathsToArchive", "cwd"], null, false), - sevenUnzip: makeRunner("7z", function(options){ + sevenUnzip: makeRunner(apps.sevenZ, function(options){ let cmd = "x"; // eXtract files with full paths if (options.noDirectories) cmd = "e"; //Extract files from archive (without using directory names) @@ -109,7 +110,7 @@ module.exports = { null, false), - unzip: makeRunner("unzip", function(options){ + unzip: makeRunner(apps.unzip, function(options){ const opts = options.noDirectories ? ["-j"] : []; return opts.concat(["-qq", "-o", options.file, "-d", options.destination]); },