"use strict";var configMgr=require("../../common/js/ConfigMgr");var configMgrIns=new configMgr;var upgrade=require("../../common/js/upgrade");var upgradeIns=new upgrade.Upgrade;var jsUtil=require("../../common/js/jsUtil");var debug=0;var info=0;var set_page_info={setLoad:false,auto_upgrade:true,upg_tip_show:false,upgradeFlag:false,curUpgFlag:false,upgrade_finish_flag:true,upgrade_error_flag:false,set_auto_upg_show:true,localVer:"",curRemoteVer:"",versionToolName:"",upg_url:"",toolImageUrl:"",verInfo:null,setAutoRunShow:true,auto_run:false,auto_upload:true,isFirst:true,isAutoUpdateVersion:true};function getSetInfoFromFile(e){var o=configMgrIns.readConfig("auto_upgrade");var r=configMgrIns.readConfig("auto_run");var a=configMgrIns.readConfig("auto_upload");var t=configMgrIns.readConfig("upg_url");var n=configMgrIns.readConfig("is_auto_update_version");if(n==undefined){configMgrIns.writeConfig("auto_upgrade",set_page_info.auto_upgrade);configMgrIns.writeConfig("is_auto_update_version",set_page_info.isAutoUpdateVersion)}else{if(o==undefined){configMgrIns.writeConfig("auto_upgrade",set_page_info.auto_upgrade)}else{set_page_info.auto_upgrade=o}}if(r==undefined){configMgrIns.writeConfig("auto_run",set_page_info.auto_run)}else{set_page_info.auto_run=r}if(a==undefined){configMgrIns.writeConfig("auto_upload",set_page_info.auto_upload)}else{set_page_info.auto_upload=a}if(t==undefined||t==""||t.indexOf("cloud.ruijie.com.cn")!=-1){configMgrIns.writeConfig("upg_url",e);set_page_info.upg_url=e}else{set_page_info.upg_url=t}if(info){console.info("getSetInfoFromFile ...")}if(debug){console.log("auto_upgrade auto_run auto_upload upg_url ...",o,r,a,t)}}function upgradeFun(){var e;var o=set_page_info.upg_url+"version.json";var r=set_page_info.upg_url+"app.zip";var a=jsUtil.uuidByMac();console.log("toolkitId:",a);console.log("getRootPath():",jsUtil.getRootPath());console.log("getWorkPath():",jsUtil.getWorkPath());console.log("getDataPath():",jsUtil.getDataPath());console.log("getDataRootPath():",jsUtil.getDataRootPath());upgradeIns.setUrl(o,r);e=upgradeIns.checkUpgradeFlag();set_page_info.upgradeFlag=e;if(e){var t=upgradeIns.getLocalVer();t=changeVerFormat(t);set_page_info.localVer=t;$("#set_tip").show()}if(info){console.info("upgradeFun ...")}if(debug){console.log("verUrl pkgUrl ret localVer ...",o,r,e,set_page_info.localVer)}}function checkNerVersion(){var e=upgradeIns.checkNewVer(function(o,r,a,t,n){var i=false;if(debug){console.log("checkNerVersion err isNewVer remoteVer localVer body ...",o,r,a,t,n)}if(o){setTimeout("checkNerVersion()",4*3600*1e3);return}if(!r){setTimeout("checkNerVersion()",4*3600*1e3);return}set_page_info.curUpgFlag=r;set_page_info.curRemoteVer=a;set_page_info.localVer="当前:"+changeVerFormat(t);try{set_page_info.verInfo=JSON.parse(n)}catch(o){if(debug){console.log("JSON.parse(verInfo) ...",o)}}if(set_page_info.auto_upgrade==true){if(set_page_info.upgrade_finish_flag==true){if(info){console.info("正在升级 ...")}set_page_info.upgrade_finish_flag=false;e=upgradeIns.upgradeNewVer(a,function(e,o,r,a){if(e){setTimeout("checkNerVersion()",4*3600*1e3);set_page_info.upgrade_error_flag=e;set_page_info.upgrade_finish_flag=true;if(set_page_info.setLoad)setParmHandler();return}if(o=="download"){$("#icon_toolUpgrade").attr("src","./image/icon-upgrade-n.gif");$(".toogle_menu").hide();$(".upgrade_menu").show();if(a==0){$("#progressText").text("正在升级新版本!下载进度: 0%")}else{var t=r/a*100;t=Math.round(t*100)/100;$("#progressText").text("正在升级新版本!下载进度: "+t+"%")}}else if(o=="download_end"){$("#progressText").text("下载进度: 100%")}else if(o=="upgrade"){if(a==0){$("#progressText").text("解压进度: 0%")}else{var t=r/a*100;t=Math.round(t*100)/100;$("#progressText").text("解压进度: "+t+"%")}}else if(o=="upgrade_end"){i=true;$("#icon_toolUpgrade").attr("src","./image/icon-upgrade-n.png");$("#progressText").text("已升级至最新版本,请重启工具使更新生效!");set_page_info.upgrade_finish_flag=true;if(!set_page_info.setLoad){$("#set_tip").show()}$(".toogle_menu").hide();$(".upgrade_menu").show()}})}}$("#set_tip").show();if(!i)setTimeout("checkNerVersion()",4*3600*1e3);if(set_page_info.setLoad)setParmHandler()});if(info){console.info("checkNerVersion ...")}}function changeVerFormat(e){var o="";if(e==undefined||e==null||e.length==0){return o}for(var r=0;r<e.length;++r){o=o+e[r]+"."}if(o.length>1){o=o.substr(0,o.length-1)}return o}function getInfos(){var e=jsUtil.getPkgInfo(),o=configMgrIns.readConfig("isFirst"),r=upgradeIns.getLocalVer();set_page_info.versionToolName=e["window"]["title"];set_page_info.toolImageUrl=jsUtil.getToolImage();set_page_info.localVer=changeVerFormat(r);if(o!=undefined)set_page_info.isFirst=o;if(debug){console.log("getInfos versionToolName,toolImageUrl,isFirst,localVer ...",set_page_info.versionToolName,set_page_info.toolImageUrl,o,r)}}getInfos();$(function(){if(set_page_info.localVer!="")$("#local_Version").text("v"+set_page_info.localVer)});