import fs from "fs"; import fse from "fs-extra"; import os from "os"; import path from "path"; import { System } from "../common/system"; import { watch } from "../common/watch"; import { Sdk } from "../core/sdk"; import run from "../run"; export class FlashPlayer extends Sdk { static ID = "flashplayer"; static VERSION_24 = "24"; static VERSION_25 = "25"; static VERSION_26 = "26"; static VERSION_27 = "27"; static VERSION_28 = "28"; static VERSION_29 = "29"; static VERSION_30 = "30"; static VERSION_31 = "31"; static VERSION_32 = "32"; static VERSION = FlashPlayer.VERSION_32; BASE_URL = "https://fpdownload.macromedia.com/pub/flashplayer/updaters"; private debug: boolean; protected strip = 0; url = "https://fpdownload.macromedia.com/pub/flashplayer/updaters/" + "<%= version %>/" + "<%= {linux:'flash_player_sa_linux' + (debug ? '_debug' : '') +'.x86_64.tar.gz','win':'flashplayer_'+version+'_sa'+(debug ? '_debug' : '')+'.exe'}[os_name] %>"; constructor(debug: boolean = false, version?: string, playerId = FlashPlayer.ID) { super(playerId, version || FlashPlayer.VERSION); this.debug = debug; } get prepared() { try { return fs.existsSync(this.flashPlayerBin); } catch (e) { return false; } } get flashPlayerBin(): string { if (System.isWindows) { const playerName = `flashplayer_${this.version}_sa${this.debug ? "_debug" : ""}.exe`; return path.join(this.path, playerName); } else if (System.isLinux) { const binPath = path.join(this.path, `flashplayer${this.debug ? "debugger" : ""}`); fs.chmodSync(binPath, 0o755); return binPath; } else { throw `Unsupported os '${os.type()}'`; } } static get flashPlayerDir(): string { if (os.type() === "Windows_NT") { return path.join(process.env.APPDATA!, "Macromedia", "Flash Player"); } else if (os.type() === "Linux") { return path.join(os.homedir(), ".macromedia", "Flash_Player"); } else { throw `Unuspported os: ${os.type()}`; } } static get log() { return path.join(this.flashPlayerDir, "Logs", "flashlog.txt"); } static enableLog() { const filename = path.join(os.homedir(), "mm.cfg"); const value = "TraceOutputFileEnable=1"; if (fs.existsSync(filename)) { const data = fs.readFileSync(filename, "utf8"); if (data.indexOf(value) === -1) { fs.appendFileSync(filename, `${value}\n`); } } else { fs.writeFileSync(filename, `${value}\n`); } fse.ensureDirSync(path.join(this.flashPlayerDir, "Logs")); fs.writeFileSync(FlashPlayer.log, ""); } static trust(value: string) { const filename = path.join(this.flashPlayerDir, "#Security", "FlashPlayerTrust", "gulp.cfg"); if (fs.existsSync(filename)) { const data = fs.readFileSync(filename, "utf8"); if (data.indexOf(value) === -1) { fs.appendFileSync(filename, `${value}\n`); } } else { if (!fs.existsSync(path.dirname(filename))) { fse.ensureDirSync(path.dirname(filename)); } fs.writeFileSync(filename, `${value}\n`); } } run(filename: string, params: any) { this.log.i("_run_ *%s*", filename); FlashPlayer.trust(filename); FlashPlayer.enableLog(); return run(`${this.flashPlayerBin} ${filename}`, params).exec().pipe(watch(FlashPlayer.log)); } }