1 | import { join as pathJoin, dirname } from 'path';
|
2 | import fse from 'fs-extra';
|
3 | import { PathType } from "@shockpkg/archive-files/module.mjs";
|
4 | import { pathRelativeBase, pathRelativeBaseMatch } from "../util.mjs";
|
5 | import { peResourceReplace } from "../util/windows.mjs";
|
6 | import { Projector } from "../projector.mjs";
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | export class ProjectorWindows extends Projector {
|
14 | |
15 |
|
16 |
|
17 |
|
18 | |
19 |
|
20 |
|
21 |
|
22 | |
23 |
|
24 |
|
25 | constructor(path) {
|
26 | super(path);
|
27 | this.iconFile = null;
|
28 | this.iconData = null;
|
29 | this.versionStrings = null;
|
30 | }
|
31 | |
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | get extension() {
|
39 | return '.exe';
|
40 | }
|
41 | |
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | get configNewline() {
|
49 | return '\r\n';
|
50 | }
|
51 | |
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | get lingoNewline() {
|
59 | return '\r\n';
|
60 | }
|
61 | |
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | get splashImageExtension() {
|
69 | return '.BMP';
|
70 | }
|
71 | |
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | get sklName() {
|
79 | return 'Projec32.skl';
|
80 | }
|
81 | |
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | async getIconData() {
|
89 | const {
|
90 | iconData,
|
91 | iconFile
|
92 | } = this;
|
93 | return iconData || (iconFile ? fse.readFile(iconFile) : null);
|
94 | }
|
95 | |
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 | async _writeSkeleton(skeleton) {
|
103 | const {
|
104 | path,
|
105 | shockwave,
|
106 | sklName,
|
107 | xtrasName,
|
108 | xtrasPath
|
109 | } = this;
|
110 | const xtrasMappings = this.getIncludeXtrasMappings();
|
111 | let foundProjectorSkl = false;
|
112 | let foundXtras = false;
|
113 |
|
114 | const xtrasHandler = async entry => {
|
115 |
|
116 | const xtrasRel = pathRelativeBase(entry.volumePath, xtrasName, true);
|
117 |
|
118 | if (xtrasRel === null) {
|
119 | return false;
|
120 | }
|
121 |
|
122 | foundXtras = true;
|
123 |
|
124 | const dest = this.includeXtrasMappingsDest(xtrasMappings, xtrasRel);
|
125 |
|
126 | if (!dest) {
|
127 | return true;
|
128 | }
|
129 |
|
130 | await entry.extract(pathJoin(xtrasPath, dest));
|
131 | return true;
|
132 | };
|
133 |
|
134 | const projectorSklHandler = async entry => {
|
135 | const entryPath = entry.volumePath;
|
136 |
|
137 | if (entryPath.includes('/')) {
|
138 | return false;
|
139 | }
|
140 |
|
141 |
|
142 | if (!pathRelativeBaseMatch(entryPath, sklName, true)) {
|
143 | return false;
|
144 | }
|
145 |
|
146 | foundProjectorSkl = true;
|
147 | await entry.extract(path);
|
148 | return true;
|
149 | };
|
150 |
|
151 | const projectorDllHandler = async entry => {
|
152 | const entryPath = entry.volumePath;
|
153 |
|
154 | if (entryPath.includes('/')) {
|
155 | return false;
|
156 | }
|
157 |
|
158 |
|
159 | if (!/\.dll$/i.test(entryPath)) {
|
160 | return false;
|
161 | }
|
162 |
|
163 |
|
164 | if (shockwave) {
|
165 | return true;
|
166 | }
|
167 |
|
168 | await entry.extract(pathJoin(dirname(path), entryPath));
|
169 | return true;
|
170 | };
|
171 |
|
172 | const archive = await this.getSkeletonArchive(skeleton);
|
173 | await archive.read(async entry => {
|
174 | if (entry.type === PathType.RESOURCE_FORK) {
|
175 | return;
|
176 | }
|
177 |
|
178 | if (await xtrasHandler(entry)) {
|
179 | return;
|
180 | }
|
181 |
|
182 | if (await projectorSklHandler(entry)) {
|
183 | return;
|
184 | }
|
185 |
|
186 | if (await projectorDllHandler(entry)) {
|
187 | return;
|
188 | }
|
189 | });
|
190 |
|
191 | if (!foundProjectorSkl) {
|
192 | throw new Error(`Failed to locate: ${sklName}`);
|
193 | }
|
194 |
|
195 | if (!foundXtras) {
|
196 | throw new Error(`Failed to locate: ${xtrasName}`);
|
197 | }
|
198 | }
|
199 | |
200 |
|
201 |
|
202 |
|
203 |
|
204 | async _modifySkeleton() {
|
205 | const iconData = await this.getIconData();
|
206 | const {
|
207 | versionStrings
|
208 | } = this;
|
209 |
|
210 | if (!(iconData || versionStrings)) {
|
211 | return;
|
212 | }
|
213 |
|
214 | await peResourceReplace(this.path, {
|
215 | iconData,
|
216 | versionStrings
|
217 | });
|
218 | }
|
219 |
|
220 | }
|
221 |
|