UNPKG

4.52 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports.ProjectorWindows = void 0;
9
10var _path = require("path");
11
12var _fsExtra = _interopRequireDefault(require("fs-extra"));
13
14var _archiveFiles = require("@shockpkg/archive-files");
15
16var _util = require("../util");
17
18var _windows = require("../util/windows");
19
20var _projector = require("../projector");
21
22/**
23 * ProjectorWindows constructor.
24 *
25 * @param path Output path.
26 */
27class ProjectorWindows extends _projector.Projector {
28 /**
29 * Icon file.
30 */
31
32 /**
33 * Icon data.
34 */
35
36 /**
37 * Version strings.
38 */
39 constructor(path) {
40 super(path);
41 this.iconFile = null;
42 this.iconData = null;
43 this.versionStrings = null;
44 }
45 /**
46 * Projector file extension.
47 *
48 * @returns File extension.
49 */
50
51
52 get extension() {
53 return '.exe';
54 }
55 /**
56 * Config file newline characters.
57 *
58 * @returns Newline characters.
59 */
60
61
62 get configNewline() {
63 return '\r\n';
64 }
65 /**
66 * Lingo file newline characters.
67 *
68 * @returns Newline characters.
69 */
70
71
72 get lingoNewline() {
73 return '\r\n';
74 }
75 /**
76 * Splash image file extension.
77 *
78 * @returns File extension.
79 */
80
81
82 get splashImageExtension() {
83 return '.BMP';
84 }
85 /**
86 * Get the SKL name.
87 *
88 * @returns File name.
89 */
90
91
92 get sklName() {
93 return 'Projec32.skl';
94 }
95 /**
96 * Get icon data if any specified, from data or file.
97 *
98 * @returns Icon data or null.
99 */
100
101
102 async getIconData() {
103 const {
104 iconData,
105 iconFile
106 } = this;
107 return iconData || (iconFile ? _fsExtra.default.readFile(iconFile) : null);
108 }
109 /**
110 * Write the projector skeleton from archive.
111 *
112 * @param skeleton Skeleton path.
113 */
114
115
116 async _writeSkeleton(skeleton) {
117 const {
118 path,
119 shockwave,
120 sklName,
121 xtrasName,
122 xtrasPath
123 } = this;
124 const xtrasMappings = this.getIncludeXtrasMappings();
125 let foundProjectorSkl = false;
126 let foundXtras = false;
127
128 const xtrasHandler = async entry => {
129 // Check if Xtras path.
130 const xtrasRel = (0, _util.pathRelativeBase)(entry.volumePath, xtrasName, true);
131
132 if (xtrasRel === null) {
133 return false;
134 }
135
136 foundXtras = true; // Find output path if being included, else skip.
137
138 const dest = this.includeXtrasMappingsDest(xtrasMappings, xtrasRel);
139
140 if (!dest) {
141 return true;
142 }
143
144 await entry.extract((0, _path.join)(xtrasPath, dest));
145 return true;
146 };
147
148 const projectorSklHandler = async entry => {
149 const entryPath = entry.volumePath; // Should not be in sub directory.
150
151 if (entryPath.includes('/')) {
152 return false;
153 } // Check if skl path.
154
155
156 if (!(0, _util.pathRelativeBaseMatch)(entryPath, sklName, true)) {
157 return false;
158 }
159
160 foundProjectorSkl = true;
161 await entry.extract(path);
162 return true;
163 };
164
165 const projectorDllHandler = async entry => {
166 const entryPath = entry.volumePath; // Should not be in sub directory.
167
168 if (entryPath.includes('/')) {
169 return false;
170 } // Check if dll path.
171
172
173 if (!/\.dll$/i.test(entryPath)) {
174 return false;
175 } // Exclude if shockwave projector.
176
177
178 if (shockwave) {
179 return true;
180 }
181
182 await entry.extract((0, _path.join)((0, _path.dirname)(path), entryPath));
183 return true;
184 };
185
186 const archive = await this.getSkeletonArchive(skeleton);
187 await archive.read(async entry => {
188 if (entry.type === _archiveFiles.PathType.RESOURCE_FORK) {
189 return;
190 }
191
192 if (await xtrasHandler(entry)) {
193 return;
194 }
195
196 if (await projectorSklHandler(entry)) {
197 return;
198 }
199
200 if (await projectorDllHandler(entry)) {
201 return;
202 }
203 });
204
205 if (!foundProjectorSkl) {
206 throw new Error(`Failed to locate: ${sklName}`);
207 }
208
209 if (!foundXtras) {
210 throw new Error(`Failed to locate: ${xtrasName}`);
211 }
212 }
213 /**
214 * Modify the projector skeleton.
215 */
216
217
218 async _modifySkeleton() {
219 const iconData = await this.getIconData();
220 const {
221 versionStrings
222 } = this;
223
224 if (!(iconData || versionStrings)) {
225 return;
226 }
227
228 await (0, _windows.peResourceReplace)(this.path, {
229 iconData,
230 versionStrings
231 });
232 }
233
234}
235
236exports.ProjectorWindows = ProjectorWindows;
237//# sourceMappingURL=windows.js.map