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IAAI,KAAK,CAAC,+CAA+C,OAAO,EAAE,CAAC,CAAA;KAC1E;IAED,0DAA0D;IAC1D,IAAI,OAAO,KAAK,aAAa,EAAE;QAC7B,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,aAAa,CAAC,CAAA;KACxC;IACD,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA;AAED,SAAwB,YAAY,CAAC,OAAgD,EAAE,gBAAwB;IAC7G,IAAI,OAAO,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,IAAI,OAAO,CAAC,YAAY,KAAK,QAAQ,EAAE;QACrC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,oFAAoF,CAAC,CAAA;KAChI;IAED,OAAO,cAAc,CAAC,gBAAgB,EAAE,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAA;AAC7H,CAAC;AAPD,+BAOC","sourcesContent":["import * as fs from \"fs\"\nimport * as path from \"path\"\nimport { ElectronPlatformName } from \"./ElectronFramework\"\n\nimport { log } from \"builder-util\"\nimport { getBin } from \"../binDownload\"\nimport { PrepareApplicationStageDirectoryOptions } from \"../Framework\"\n\n// NOTE: Adapted from https://github.com/MarshallOfSound/electron-packager-plugin-non-proprietary-codecs-ffmpeg to resolve dependency vulnerabilities\nconst downloadFFMPEG = async (electronVersion: string, platform: ElectronPlatformName, arch: string) => {\n const ffmpegFileName = `ffmpeg-v${electronVersion}-${platform}-${arch}.zip`\n const url = `https://github.com/electron/electron/releases/download/v${electronVersion}/${ffmpegFileName}`\n\n log.info({ file: ffmpegFileName }, \"downloading non-proprietary FFMPEG\")\n return getBin(ffmpegFileName, url)\n}\n\nconst copyFFMPEG = (targetPath: string, platform: ElectronPlatformName) => (sourcePath: string) => {\n let fileName = \"ffmpeg.dll\"\n if ([\"darwin\", \"mas\"].includes(platform)) {\n fileName = \"libffmpeg.dylib\"\n } else if (platform === \"linux\") {\n fileName = \"libffmpeg.so\"\n }\n\n const libPath = path.resolve(sourcePath, fileName)\n const libTargetPath = path.resolve(targetPath, fileName)\n log.info({ lib: libPath, target: libTargetPath }, \"copying non-proprietary FFMPEG\")\n\n // If the source doesn't exist we have a problem\n if (!fs.existsSync(libPath)) {\n throw new Error(`Failed to find FFMPEG library file at path: ${libPath}`)\n }\n\n // If we are copying to the source we can stop immediately\n if (libPath !== libTargetPath) {\n fs.copyFileSync(libPath, libTargetPath)\n }\n return libTargetPath\n}\n\nexport default function injectFFMPEG(options: PrepareApplicationStageDirectoryOptions, electrionVersion: string) {\n let libPath = options.appOutDir\n if (options.platformName === \"darwin\") {\n libPath = path.resolve(options.appOutDir, \"Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries\")\n }\n\n return downloadFFMPEG(electrionVersion, options.platformName, options.arch).then(copyFFMPEG(libPath, options.platformName))\n}\n"]}