UNPKG

@shockpkg/dir-projector

Version:

Package for creating Shockwave Director projectors

106 lines (100 loc) 2.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BundleOttoWindows = void 0; var _promises = require("node:fs/promises"); var _nodePath = require("node:path"); var _util = require("../../util.js"); var _windows = require("../../util/windows.js"); var _windows2 = require("../../projector/otto/windows.js"); var _otto = require("../otto.js"); /** * BundleOttoWindows object. */ class BundleOttoWindows extends _otto.BundleOtto { /** * ProjectorOttoWindows instance. */ /** * BundleOttoWindows constructor. * * @param path Output path for the main application. * @param flat Flat bundle. */ constructor(path, flat = false) { super(path, flat); this.projector = this._createProjector(); } /** * @inheritdoc */ get extension() { return '.exe'; } /** * @inheritdoc */ _getProjectorPathNested() { const { path, extension } = this; const directory = (0, _util.trimExtension)(path, extension, true); if (directory === path) { throw new Error(`Output path must end with: ${extension}`); } return (0, _nodePath.join)(directory, (0, _nodePath.basename)(path)); } /** * @inheritdoc */ _createProjector() { return new _windows2.ProjectorOttoWindows(this._getProjectorPath()); } /** * @inheritdoc */ async _writeLauncher() { const { path, projector } = this; const d = new Uint8Array(4); const v = new DataView(d.buffer, d.byteOffset, d.byteLength); const f = await (0, _promises.open)(projector.path, 'r'); try { let r = await f.read(d, 0, 4, 60); if (r.bytesRead < 4) { throw new Error('Unknown format'); } r = await f.read(d, 0, 2, v.getUint32(0, true) + 4); if (r.bytesRead < 2) { throw new Error('Unknown format'); } } finally { await f.close(); } const machine = v.getUint16(0, true); // eslint-disable-next-line jsdoc/require-jsdoc const res = async () => (0, _promises.readFile)(projector.path); let launcher = null; switch (machine) { case 0x14c: { launcher = await (0, _windows.windowsLauncher)('i686', res); break; } default: { throw new Error(`Unknown machine type: ${machine}`); } } await (0, _promises.mkdir)((0, _nodePath.dirname)(path), { recursive: true }); await (0, _promises.writeFile)(path, launcher); } } exports.BundleOttoWindows = BundleOttoWindows; //# sourceMappingURL=windows.js.map