137 lines
4.0 KiB
TypeScript
Executable File
137 lines
4.0 KiB
TypeScript
Executable File
import fs from "fs";
|
|
import fse from "fs-extra";
|
|
import os from "os";
|
|
import path from "path";
|
|
import through from "through2";
|
|
import { Env } from "../common/env";
|
|
import { System } from "../common/system";
|
|
import { TailVinyl } from "../common/tail";
|
|
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 baseUrl: string;
|
|
|
|
constructor(debug: boolean = false, version?: string, playerId = FlashPlayer.ID) {
|
|
super(playerId, version || FlashPlayer.VERSION);
|
|
this.debug = debug;
|
|
this.baseUrl = Env.get("FLASHPLAYER_URL") || this.BASE_URL;
|
|
}
|
|
|
|
prepare() {
|
|
return super.prepare(0);
|
|
}
|
|
|
|
get prepared() {
|
|
try {
|
|
return fs.existsSync(this.flashPlayerBin);
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
get link(): string {
|
|
const baseUrl = `${this.baseUrl}/${this.version}`;
|
|
if (System.isWindows) {
|
|
return baseUrl + `/flashplayer_${this.version}_sa${this.debug ? "_debug" : ""}.exe`;
|
|
} else if (System.isLinux) {
|
|
return baseUrl + `/flash_player_sa_linux${this.debug ? "_debug" : ""}.x86_64.tar.gz`;
|
|
} else {
|
|
throw `Unsupported os '${os.type()}'`;
|
|
}
|
|
}
|
|
|
|
get flashPlayerBin(): string {
|
|
if (System.isWindows) {
|
|
const v = this.version.split(".");
|
|
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);
|
|
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);
|
|
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(
|
|
through.obj(function (file: any, enc: string, callback: any) {
|
|
const log = new TailVinyl({
|
|
path: FlashPlayer.log,
|
|
});
|
|
this.on("end", () => log.dispose());
|
|
this.push(log);
|
|
callback();
|
|
}),
|
|
);
|
|
}
|
|
}
|