1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.ProjectorWindows = void 0;
|
9 |
|
10 | var _path = require("path");
|
11 |
|
12 | var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
13 |
|
14 | var _archiveFiles = require("@shockpkg/archive-files");
|
15 |
|
16 | var _util = require("../util");
|
17 |
|
18 | var _windows = require("../util/windows");
|
19 |
|
20 | var _projector = require("../projector");
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | class ProjectorWindows extends _projector.Projector {
|
28 | |
29 |
|
30 |
|
31 |
|
32 | |
33 |
|
34 |
|
35 |
|
36 | |
37 |
|
38 |
|
39 | constructor(path) {
|
40 | super(path);
|
41 | this.iconFile = null;
|
42 | this.iconData = null;
|
43 | this.versionStrings = null;
|
44 | }
|
45 | |
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | get extension() {
|
53 | return '.exe';
|
54 | }
|
55 | |
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | get configNewline() {
|
63 | return '\r\n';
|
64 | }
|
65 | |
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | get lingoNewline() {
|
73 | return '\r\n';
|
74 | }
|
75 | |
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | get splashImageExtension() {
|
83 | return '.BMP';
|
84 | }
|
85 | |
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 | get sklName() {
|
93 | return 'Projec32.skl';
|
94 | }
|
95 | |
96 |
|
97 |
|
98 |
|
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 |
|
111 |
|
112 |
|
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 |
|
130 | const xtrasRel = (0, _util.pathRelativeBase)(entry.volumePath, xtrasName, true);
|
131 |
|
132 | if (xtrasRel === null) {
|
133 | return false;
|
134 | }
|
135 |
|
136 | foundXtras = true;
|
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;
|
150 |
|
151 | if (entryPath.includes('/')) {
|
152 | return false;
|
153 | }
|
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;
|
167 |
|
168 | if (entryPath.includes('/')) {
|
169 | return false;
|
170 | }
|
171 |
|
172 |
|
173 | if (!/\.dll$/i.test(entryPath)) {
|
174 | return false;
|
175 | }
|
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 |
|
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 |
|
236 | exports.ProjectorWindows = ProjectorWindows;
|
237 |
|