@shockpkg/dir-projector
Version:
Package for creating Shockwave Director projectors
238 lines (182 loc) • 4.52 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ProjectorWindows = void 0;
var _path = require("path");
var _fsExtra = _interopRequireDefault(require("fs-extra"));
var _archiveFiles = require("@shockpkg/archive-files");
var _util = require("../util");
var _windows = require("../util/windows");
var _projector = require("../projector");
/**
* ProjectorWindows constructor.
*
* @param path Output path.
*/
class ProjectorWindows extends _projector.Projector {
/**
* Icon file.
*/
/**
* Icon data.
*/
/**
* Version strings.
*/
constructor(path) {
super(path);
this.iconFile = null;
this.iconData = null;
this.versionStrings = null;
}
/**
* Projector file extension.
*
* @returns File extension.
*/
get extension() {
return '.exe';
}
/**
* Config file newline characters.
*
* @returns Newline characters.
*/
get configNewline() {
return '\r\n';
}
/**
* Lingo file newline characters.
*
* @returns Newline characters.
*/
get lingoNewline() {
return '\r\n';
}
/**
* Splash image file extension.
*
* @returns File extension.
*/
get splashImageExtension() {
return '.BMP';
}
/**
* Get the SKL name.
*
* @returns File name.
*/
get sklName() {
return 'Projec32.skl';
}
/**
* Get icon data if any specified, from data or file.
*
* @returns Icon data or null.
*/
async getIconData() {
const {
iconData,
iconFile
} = this;
return iconData || (iconFile ? _fsExtra.default.readFile(iconFile) : null);
}
/**
* Write the projector skeleton from archive.
*
* @param skeleton Skeleton path.
*/
async _writeSkeleton(skeleton) {
const {
path,
shockwave,
sklName,
xtrasName,
xtrasPath
} = this;
const xtrasMappings = this.getIncludeXtrasMappings();
let foundProjectorSkl = false;
let foundXtras = false;
const xtrasHandler = async entry => {
// Check if Xtras path.
const xtrasRel = (0, _util.pathRelativeBase)(entry.volumePath, xtrasName, true);
if (xtrasRel === null) {
return false;
}
foundXtras = true; // Find output path if being included, else skip.
const dest = this.includeXtrasMappingsDest(xtrasMappings, xtrasRel);
if (!dest) {
return true;
}
await entry.extract((0, _path.join)(xtrasPath, dest));
return true;
};
const projectorSklHandler = async entry => {
const entryPath = entry.volumePath; // Should not be in sub directory.
if (entryPath.includes('/')) {
return false;
} // Check if skl path.
if (!(0, _util.pathRelativeBaseMatch)(entryPath, sklName, true)) {
return false;
}
foundProjectorSkl = true;
await entry.extract(path);
return true;
};
const projectorDllHandler = async entry => {
const entryPath = entry.volumePath; // Should not be in sub directory.
if (entryPath.includes('/')) {
return false;
} // Check if dll path.
if (!/\.dll$/i.test(entryPath)) {
return false;
} // Exclude if shockwave projector.
if (shockwave) {
return true;
}
await entry.extract((0, _path.join)((0, _path.dirname)(path), entryPath));
return true;
};
const archive = await this.getSkeletonArchive(skeleton);
await archive.read(async entry => {
if (entry.type === _archiveFiles.PathType.RESOURCE_FORK) {
return;
}
if (await xtrasHandler(entry)) {
return;
}
if (await projectorSklHandler(entry)) {
return;
}
if (await projectorDllHandler(entry)) {
return;
}
});
if (!foundProjectorSkl) {
throw new Error(`Failed to locate: ${sklName}`);
}
if (!foundXtras) {
throw new Error(`Failed to locate: ${xtrasName}`);
}
}
/**
* Modify the projector skeleton.
*/
async _modifySkeleton() {
const iconData = await this.getIconData();
const {
versionStrings
} = this;
if (!(iconData || versionStrings)) {
return;
}
await (0, _windows.peResourceReplace)(this.path, {
iconData,
versionStrings
});
}
}
exports.ProjectorWindows = ProjectorWindows;
//# sourceMappingURL=windows.js.map