"use strict";(function(){var e=0;var o=0;"use strict";var n=require("fs");var t=require("path");var i=require("child_process");var r=require("./Logger").getLogger("childToolMgr.js");var s=require("./jsUtil");var l="../third_apps";function f(){var e=this;e.childProcs={};e.toolsInfo=null;e.toolsInfoByTag=null}function a(e,o){var n={isExist:false,isThird:false};for(var t in e){for(var i in e[t]){if(i==o){n=e[t][i];n.isExist=true;n.isThird=e[t][i]["isThird"];return n}}}return n}f.prototype.startTool=function(o,n){var r=this;if(o===undefined||o===""||r.toolsInfo==={})return false;if(r.childProcs[o]!=undefined)return true;var l=a(r.toolsInfo,o);if(e){console.log("isExistInfo ...",l)}if(!l.isExist)return false;if(!l.isThird){var f=t.resolve(s.getWorkPath(),"../",o);if(!s.fsExistsSync(f))return false;var c=process.execPath;var u=[f,"--toolkit"].concat(l["argument"]);var d=i.spawn(c,u,{detached:true});if(n!==undefined){d.on("exit",function(){n(o,r.childProcs[o]);delete r.childProcs[o]})}}else{if(l["exe"].indexOf(".bat")>=0){var d=i.exec(l["exe"],{cwd:t.dirname(l["exe"])});if(n!==undefined){d.on("exit",function(){n(o,r.childProcs[o]);delete r.childProcs[o]})}}else{var d=i.spawn(l["exe"],l["argument"],{detached:true,cwd:t.dirname(l["exe"])});if(n!==undefined){d.on("exit",function(){n(o,r.childProcs[o]);delete r.childProcs[o]})}}}r.childProcs[o]=d;return true};f.prototype.isExist=function(e){var o=this;if(e==undefined||e===""){return false}if(o.childProcs[e]!=undefined){return true}return false};f.prototype.exitTool=function(e){var o=this;if(e==undefined||e===""){return false}var n=o.childProcs[e];if(n==undefined){return false}n.kill();return true};f.prototype.getToolsInfoByTag=function(){var e=this;if(!e.toolsInfo){e.getToolsInfo()}return e.toolsInfoByTag};function c(e,o,n,t){if(!e||!n||!o||!t)return false;for(var i in e){if(t[e[i]]==undefined){t[e[i]]={};t[e[i]].length=0}if(t[e[i]][o]==undefined){++t[e[i]].length;t[e[i]][o]={}}t[e[i]][o][n["name"]]=n}}f.prototype.getToolsInfo=function(){var o=this,i=null,r=null,f=null,a=null,u=null,d=null,h=null,g=null;try{i=s.getPkgInfo();r=i["spec"]["prjs"];f=i["spec"]["third_prjs"]}catch(v){if(e){console.log("err ...",v)}return false}if(!i||r==undefined)return false;o.toolsInfo={};o.toolsInfo.length=0;o.toolsInfoByTag={};for(var p in r){a=t.resolve(s.getWorkPath(),"../",r[p]);if(e){console.log("toolPath ....",a)}if(!s.fsExistsSync(a))continue;u=t.resolve(a,"package.json");if(e){console.log("toolCfgPath ...",u)}if(!s.fsExistsSync(u))continue;g={};try{d=JSON.parse(n.readFileSync(u,"utf-8"));h=d["spec"]["info"]["solutionCode"];g["title"]=d["window"]["title"];g["name"]=r[p];g["icon"]=t.resolve(a,d["window"]["icon"]);g["description"]=d["description"]}catch(v){continue}if(h=="")continue;if(o.toolsInfo[h]===undefined){o.toolsInfo[h]={};o.toolsInfo.length++}o.toolsInfo[h][g["name"]]=g;c(d["spec"]["info"]["tags"],h,g,o.toolsInfoByTag)}if(f!=undefined){for(var p in f){g={};a=t.resolve(s.getRootPath(),l,p);if(e){console.log("toolPath ....",a)}if(!s.fsExistsSync(a))continue;u=t.resolve(a,"package.json");if(e){console.log("toolCfgPath ...",u)}if(!s.fsExistsSync(u))continue;try{d=JSON.parse(n.readFileSync(u,"utf-8"));g=d["spec"]["info"];var x=t.resolve(a,"./",g["exe"]);if(e){console.log("toolExePath ...",x)}if(!s.fsExistsSync(x))continue;h=d["spec"]["info"]["solutionCode"];g["icon"]=t.resolve(a,g["icon"]);g["exe"]=x;g["name"]=p;g.isThird=true}catch(v){if(e){console.log("err ...",v)}continue}if(h==undefined)continue;if(o.toolsInfo[h]===undefined){o.toolsInfo[h]={};o.toolsInfo.length++}o.toolsInfo[h][p]=g;c(d["spec"]["info"]["tags"],h,g,o.toolsInfoByTag)}}o.toolsInfoByTag["all"]=o.toolsInfo;return o.toolsInfo};module.exports=f;if(o){var u=new f;u.startTool("ha_measure",function(){console.log("ha_measure exit ...")});u.isExist("ha_measure");u.exitTool("ha_measure");var d=u.getToolsInfo()}})();