(self.webpackJsonp=self.webpackJsonp||[]).push([[3],{1964:function(e,n,t){"use strict";t.r(n),t.d(n,"runOnlineUpdate",(function(){return x}));var r=t(4),o=t.n(r),i=t(1),a=t.n(i),c=window.require("fs"),s=window.require("path"),u=window.require("https"),f=window.require("http"),d=window.require("crypto"),p=window.require("os"),l=window.require("child_process").spawn,w=window.require("nw.gui"),h="win32"===p.platform();function m(e,n,t){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:5;return new Promise((function(o,i){var a=(e.startsWith("https")?u:f).get(e,(function(a){if([301,302,303,307,308].includes(a.statusCode)&&a.headers.location){if(r<=0)return void i(new Error("重定向次数过多"));var s=new URL(a.headers.location,e).toString();return a.resume(),void m(s,n,t,r-1).then(o,i)}if(200===a.statusCode){var u=parseInt(a.headers["content-length"]||"0",10),f=0,d=c.createWriteStream(n);a.on("data",(function(e){f+=e.length,u>0&&"function"==typeof t&&t(Math.min(99,Math.floor(f/u*100)))})),a.pipe(d),d.on("finish",(function(){d.close((function(){return o(n)}))})),a.on("error",(function(e){c.unlink(n,(function(){})),i(e)})),d.on("error",(function(e){c.unlink(n,(function(){})),i(e)}))}else i(new Error("下载失败，状态码：".concat(a.statusCode)))}));a.on("error",(function(e){i(e)})),a.setTimeout(18e5,(function(){a.abort(),i(new Error("下载超时"))}))}))}function g(e){var n=c.readFileSync(e);return d.createHash("sha256").update(n).digest("hex")}function k(e,n){return new Promise((function(t,r){var o,i;c.mkdirSync(n,{recursive:!0}),h?(o="powershell",i=["-NoProfile","-Command",'Expand-Archive -Force -Path "'.concat(e,'" -DestinationPath "').concat(n,'"')]):(o="unzip",i=["-o",e,"-d",n]);var a=l(o,i,{windowsHide:!0}),s="";a.stderr.on("data",(function(e){s+=e.toString()})),a.on("error",(function(e){return r(e)})),a.on("close",(function(e){0===e?t(n):r(new Error("解压失败（code ".concat(e,"）：").concat(s)))}))}))}function v(e,n,t){var r=s.join(e,"shenfu.exe"),o=function(e,n,t){var r=s.join(e,"package.nw");return{oldPkg:r,newPkg:n,bakPkg:s.join(s.dirname(r),"".concat("package.nw",".").concat(t||"bak")),pkgName:"package.nw"}}(e,n,t),i=o.oldPkg,a=o.newPkg,u=o.bakPkg,f=s.join(p.homedir(),"AppData","Local","shenfu"),d=p.tmpdir(),h=s.join(d,"shenfu-apply-update.bat"),m=s.join(d,"shenfu-apply-update.vbs"),g=["@echo off","chcp 65001 >nul","setlocal EnableExtensions",'set "EXE='.concat(r,'"'),'set "OLD='.concat(i,'"'),'set "NEW='.concat(a,'"'),'set "BAK='.concat(u,'"'),'set "USERDATA='.concat(f,'"'),"net session >nul 2>&1","if %errorlevel% neq 0 (","  powershell -NoProfile -Command \"Start-Process -FilePath 'cmd.exe' -ArgumentList '/c','\\\"%~dpnx0\\\"' -Verb RunAs -WindowStyle Hidden\"","  exit /b",")",":wait",'tasklist /fi "imagename eq '.concat("shenfu.exe",'" | find /i "').concat("shenfu.exe",'" >nul'),"if not errorlevel 1 (","  timeout /t 1 /nobreak >nul","  goto wait",")",'if exist "%OLD%" (','  if exist "%BAK%" ( rd /s /q "%BAK%" )','  robocopy "%OLD%" "%BAK%" /E /R:1 /W:1 >nul',")",'if exist "%NEW%" (','  robocopy "%NEW%" "%OLD%" /E /MOVE /R:1 /W:1 >nul || xcopy "%NEW%\\*" "%OLD%\\" /E /Y /I >nul',")",'start "" "%EXE%" --user-data-dir="%USERDATA%"',"endlocal","exit"].join("\r\n"),k=['Set WShell = CreateObject("WScript.Shell")','WShell.Run "cmd /c ""'.concat(h,'""", 0, False'),"Set WShell = Nothing"].join("\r\n");c.writeFileSync(h,g,"utf8"),c.writeFileSync(m,k,"utf8"),l("wscript.exe",["//B","//Nologo",m],{windowsHide:!0,detached:!0,stdio:"ignore"}).unref(),setTimeout((function(){return w.App.quit()}),500)}function x(e){return E.apply(this,arguments)}function E(){return(E=o()(a.a.mark((function e(n){var t,r,o,i,u,f,d,l,x=arguments;return a.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=x.length>1&&void 0!==x[1]?x[1]:{},h){e.next=3;break}throw new Error("一键在线升级仅支持 Windows");case 3:return r=t.hash,o=t.onProgress,i=c.mkdtempSync(s.join(p.tmpdir(),"shenfu-update-")),u=s.join(i,"app.zip"),f=s.join(i,"extracted"),e.prev=7,"function"==typeof o&&o(0),e.next=11,m(n,u,o);case 11:if("function"==typeof o&&o(100),!r){e.next=16;break}if(g(u).toLowerCase()===r.toLowerCase()){e.next=16;break}throw new Error("代码包校验失败（sha256 不匹配）");case 16:return e.next=18,k(u,f);case 18:return d=s.dirname(window.process.execPath),l=w.App.manifest&&w.App.manifest.version||"",h&&v(d,f,l),e.abrupt("return");case 24:e.prev=24,e.t0=e.catch(7);try{c.rmSync(i,{recursive:!0,force:!0})}catch(e){}throw e.t0;case 28:case"end":return e.stop()}}),e,null,[[7,24]])})))).apply(this,arguments)}n.default=x}}]);