/**********************************\*\*\*\*********************************** \*

-   ADOBE CONFIDENTIAL
-   ***
-
-   Copyright 2015-2019 Adobe Systems Incorporated
-   All Rights Reserved.
-
-   NOTICE: All information contained herein is, and remains
-   the property of Adobe Systems Incorporated and its suppliers,
-   if any. The intellectual and technical concepts contained
-   herein are proprietary to Adobe Systems Incorporated and its
-   suppliers and are protected by trade secret or copyright law.
-   Dissemination of this information or reproduction of this material
-   is strictly forbidden unless prior written permission is obtained
-   from Adobe Systems Incorporated.
    ************************************\*\*************************************/

!function(e){var t={};function o(i){if(t[i])return t[i].exports;var s=t[i]={i:i,l:!1,exports:{}};return e[i].call(s.exports,s,s.exports,o),s.l=!0,s.exports}o.m=e,o.c=t,o.d=function(e,t,i){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(o.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)o.d(i,s,function(t){return e[t]}.bind(null,s));return i},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=53)}({2:function(e,t){e.exports=require("fs-extra")},26:function(e,t){e.exports=require("child_process")},30:function(e,t){e.exports=require("ps-node")},53:function(e,t,o){e.exports=o(57)},57:function(e,t,o){"use strict";o.r(t);var i=o(6),s=o(2),n=o(9),l=o(30),r=o.n(l),a=o(26);let c=console.log;var p=new class{get config(){return{UXP:{MANIFEST_SUBPATH:"/manifest.json",MAC_EXT_PATH:"/Library/Application Support/Adobe/UXP/extensions",WIN_EXT_PATH:"/Common Files/Adobe/UXP/extensions"},CEP:{MANIFEST_SUBPATH:"/CSXS/manifest.xml",MAC_EXT_PATH:"/Library/Application Support/Adobe/CEP/extensions",WIN_EXT_PATH:"/Common Files/Adobe/CEP/extensions"},PANELS_FOLDER:"../Resources/panels"}}getExtensionFolder(e=!1){let t,o=this.config;if(0===process.platform.indexOf("win")){const i=(process.env["ProgramFiles(x86)"]||process.env.PROGRAMFILES).replace(/\\/g,"/"),s=(process.env.PROGRAMW6432||process.env.PROGRAMFILES).replace(/\\/g,"/");t=e?`${s}${o.UXP.WIN_EXT_PATH}`:`${i}${o.CEP.WIN_EXT_PATH}`}else t=e?o.UXP.MAC_EXT_PATH:o.CEP.MAC_EXT_PATH;return c(`Extension folder is ${t}`),t}getPanelsFolder(){let e=this.config.PANELS_FOLDER;const t=__dirname;return e=i.normalize(`${t}/${e}`)}async checkPanelNeedsUpdate(e,t){const o=await s.readFile(e,"utf-8").catch(e=>{e&&"ENOENT"!==e.code&&c(`Error reading existing panel: ${e}`)});if(o){const e=await s.readFile(t,"utf-8").catch(e=>{c(`Error reading bundled panel: ${e}`)});if(e&&o.trim()===e.trim())return!1}return!0}async deployPanel(e,t){let o,n,l;e=i.normalize(e);const r=this.config,a=`${e}/manifest.xml`,p=`${e}/manifest.json`,d=`${e}/Contents`,u=await s.pathExists(a),h=await s.pathExists(p);if(!u&&!h)return void c(`Did not find manifest path for ${t}`);if(u?(c(`Getting destFolder for ${t} -- cep panel`),o=a,n=i.normalize(this.getExtensionFolder(!1)),l=r.CEP.MANIFEST_SUBPATH):h&&(c(`Getting destFolder for ${t} -- uxp panel`),o=p,n=i.normalize(this.getExtensionFolder(!0)),l=r.UXP.MANIFEST_SUBPATH),c(`Destination folder for panel ${t} is ${n}`),!n)return void c(`Destination folder does not exist for ${t}`);if(n=`${n}/${t}`,await s.ensureDir(n),!o)return void c(`Panel manifest path did not get set for ${t}`);if(!d)return void c(`Panel contents path did not get set for ${t}`);const f=n+l;if(!await this.checkPanelNeedsUpdate(f,o))return void c(`Panel already exists at: ${n}`);await s.remove(n),c(`Upgrading Panel ${t} from ${d} to ${n}`),await s.copy(d,n),c("Copying of files to the destination folder complete");const g=`${f}.temp`;await s.copy(o,g),c("Copying temp manifest complete"),await s.rename(g,f),c("Renaming manifest complete")}async deployPanels(){const e=this.getPanelsFolder();if(!await s.pathExists(e))return void c("Could not find panels bundle.");const t=await s.readdir(e);await Promise.all(t.map(t=>this.deployPanel(`${e}/${t}`,t)))}setLoggerFunction(e){c=e||console.log}async checkAndDeploy(){c("Check and deploy panels."),await this.deployPanels().catch(e=>{throw c(e),e})}};function d(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}const u=process.argv.slice(2);const h=new class{constructor(){d(this,"PLATFORM_MAP",{darwin:{installPath:"/Library/Application Support/Adobe/Vulcan/specifiers/",appName:"CCXProcess.app",appFolder:"../../.."},win32:{installPath:i.join(process.env.CommonProgramFiles||"","Adobe","Vulcan","specifiers"),appName:"CCXProcess.exe",appFolder:".."},win64:{installPath:i.join(process.env.CommonProgramFiles||"","Adobe","Vulcan","specifiers"),appName:"CCXProcess.exe",appFolder:".."}}),d(this,"ERROR_PARAMETER_ERROR",100),d(this,"ERROR_CANT_CREATE_INSTALL_FOLDER",101),d(this,"ERROR_CANT_WRITE_SPECIFIER",102),d(this,"ERROR_INSTALLING_PANELS",103),d(this,"ERROR_REMOVING_SPECIFIER",104),d(this,"filePath",i.resolve(this.PLATFORM_MAP[process.platform].installPath)),d(this,"logFolder","/Library/Logs/CreativeCloud"),d(this,"logFile",i.resolve(this.logFolder,"./CCXProcessInstall.log")),p.setLoggerFunction(this.log.bind(this)),"win32"===process.platform&&(this.logFolder=i.join(process.env.TEMP,"CreativeCloud","CCX Welcome"),this.logFile=i.resolve(this.logFolder,"./CCXProcessInstall.log"));try{s.ensureDirSync(this.logFolder)}catch(e){console.log("Error with log directory permissions ",e)}const e=(new Date).valueOf(),t=(t,o)=>{let i=t?"Success ":"Failed ";i+=`(${(new Date).valueOf()-e}ms)`,this.log(i),process.exit(t?0:1)};if(u.includes("kill"))return this.log=(()=>{}),void this.killCCXProcess(()=>t(!0));if(process.on("unhandledRejection",(e,t)=>{this.log("Unhandled Rejection at:",t,"reason:",e)}),process.on("uncaughtException",e=>{this.log("Uncaught Exception:",e,e.stack)}),this.log("Version: ","3.3.0"," Build: ","39"),process.chdir(__dirname),u.includes("install")){const e='<SpecifierManifest Version="1.0"><Name>ccxprocess</Name><Version>1</Version><Locale></Locale><Group></Group><Path>{{path}}</Path></SpecifierManifest>'.replace("{{path}}",i.resolve(i.join(__dirname,this.PLATFORM_MAP[process.platform].appFolder,this.PLATFORM_MAP[process.platform].appName)));this.log("Installing..."),s.ensureDir(this.filePath,o=>{o&&(this.log("Unable to install: ",o),t(!1,this.ERROR_CANT_CREATE_INSTALL_FOLDER)),s.writeFile(i.join(this.filePath,"ccxprocess.xml"),e,{encoding:"utf8"},e=>{e&&(this.log("Unable to install: ",e),t(!1,this.ERROR_CANT_WRITE_SPECIFIER));try{s.utimesSync(this.filePath,new Date,new Date)}catch(e){}this.killCCXProcess(()=>{p.checkAndDeploy().then(()=>{this.log("Installed Succesfully"),t(!0)},e=>{this.log("Failed to install panels",e),t(!1,this.ERROR_INSTALLING_PANELS)})})})})}else u.includes("uninstall")?(this.log("Uninstalling..."),this.killCCXProcess(()=>{s.unlink(i.join(this.filePath,"ccxprocess.xml"),e=>{e?"ENOENT"===e.code?this.log("Vulcan specifier not installed. Nothing to remove."):(this.log("Unable to uninstall: ",e),t(!1,this.ERROR_REMOVING_SPECIFIER)):this.log("Removed vulcan specifier"),this.log("Uninstalled Succesfully"),t(!0)})})):(this.log("Expected to be invoked with argument: install or uninstall"),t(!1,this.ERROR_PARAMETER_ERROR))}log(...e){console.log.apply(console,arguments);try{const e=`${(new Date).toString()}:${Array.prototype.slice.call(arguments).join(" ")}${n.EOL}`;s.appendFileSync(this.logFile,e,"utf-8")}catch(e){console.log("Error writing to log file",e)}}killCCXProcess(e){"darwin"===process.platform?a.exec('pkill -f ".*CCXProcess.app/Contents/MacOS/../js/main.js$"',t=>{t?(this.log(`Error while killing CCXProcess process : ${t}`),e(!1)):(this.log("CCXProcess process successfully killed."),e(!0))}):(this.log("Killing CCXProcess..."),r.a.lookup({command:".*\\CCXProcess.exe"},(t,o)=>{if(t)this.log(`Error while looking up for CCXProcess : ${t}`),e(!1);else if(o&&o.length>0){let t,i=o.length;const s=o=>{t=t||o,0==--i&&e(!t)};this.log("Number of CCXProcess Instances: ",o.length),o.forEach(e=>{this.log(`CCXProcess is running, trying to kill now: ${e.pid}`),r.a.kill(e.pid,t=>{t?this.log(`Error while killing CCXProcess(${e.pid}): ${t}`):this.log(`Succesfully killed CCXProcess(${e.pid})`),s(t)})})}else this.log("CCXProcess is not running."),e(!1)}))}};t.default=h},6:function(e,t){e.exports=require("path")},9:function(e,t){e.exports=require("os")}});