1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.Projector = void 0;
|
9 |
|
10 | var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11 |
|
12 | var _archiveFiles = require("@shockpkg/archive-files");
|
13 |
|
14 | var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | class Projector extends Object {
|
22 | |
23 |
|
24 |
|
25 |
|
26 | |
27 |
|
28 |
|
29 | constructor(path) {
|
30 | super();
|
31 | (0, _defineProperty2.default)(this, "hdiutil", null);
|
32 | (0, _defineProperty2.default)(this, "path", void 0);
|
33 | this.path = path;
|
34 | }
|
35 | |
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | get movieAppendMarker() {
|
43 | return '563412FA';
|
44 | }
|
45 | |
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | async openAsArchive(path) {
|
54 | const stat = await _fsExtra.default.stat(path);
|
55 |
|
56 | if (stat.isDirectory()) {
|
57 | return new _archiveFiles.ArchiveDir(path);
|
58 | }
|
59 |
|
60 | if (!stat.isFile()) {
|
61 | throw new Error(`Archive path not file or directory: ${path}`);
|
62 | }
|
63 |
|
64 | const r = (0, _archiveFiles.createArchiveByFileExtension)(path);
|
65 |
|
66 | if (!r) {
|
67 | throw new Error(`Archive file type unknown: ${path}`);
|
68 | }
|
69 |
|
70 | if (r instanceof _archiveFiles.ArchiveHdi) {
|
71 | const {
|
72 | hdiutil
|
73 | } = this;
|
74 |
|
75 | if (hdiutil) {
|
76 | r.mounterMac.hdiutil = hdiutil;
|
77 | }
|
78 |
|
79 | r.nobrowse = true;
|
80 | }
|
81 |
|
82 | return r;
|
83 | }
|
84 | |
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 | async withFile(player, movieFile) {
|
93 | const movieData = movieFile ? await _fsExtra.default.readFile(movieFile) : null;
|
94 | await this.withData(player, movieData);
|
95 | }
|
96 | |
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 | async withData(player, movieData) {
|
105 | await this._checkOutput();
|
106 | await this._writePlayer(player);
|
107 | await this._modifyPlayer();
|
108 | await this._writeMovie(movieData);
|
109 | }
|
110 | |
111 |
|
112 |
|
113 |
|
114 |
|
115 | async _checkOutput() {
|
116 | if (await _fsExtra.default.pathExists(this.path)) {
|
117 | throw new Error(`Output path already exists: ${this.path}`);
|
118 | }
|
119 | }
|
120 | |
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 | async _appendMovieData(file, data, format) {
|
137 | const buffers = [];
|
138 |
|
139 | for (const c of format) {
|
140 | switch (c) {
|
141 | case 'd':
|
142 | {
|
143 | buffers.push(data);
|
144 | break;
|
145 | }
|
146 |
|
147 | case 'm':
|
148 | {
|
149 | buffers.push(Buffer.from(this.movieAppendMarker, 'hex'));
|
150 | break;
|
151 | }
|
152 |
|
153 | case 's':
|
154 | {
|
155 | const b = Buffer.alloc(4);
|
156 | b.writeUInt32LE(data.length, 0);
|
157 | buffers.push(b);
|
158 | break;
|
159 | }
|
160 |
|
161 | case 'S':
|
162 | {
|
163 | const b = Buffer.alloc(4);
|
164 | b.writeUInt32BE(data.length, 0);
|
165 | buffers.push(b);
|
166 | break;
|
167 | }
|
168 |
|
169 | case 'l':
|
170 | {
|
171 |
|
172 | const b = Buffer.alloc(8, 0);
|
173 | b.writeUInt32LE(data.length, 0);
|
174 | buffers.push(b);
|
175 | break;
|
176 | }
|
177 |
|
178 | case 'L':
|
179 | {
|
180 |
|
181 | const b = Buffer.alloc(8, 0);
|
182 | b.writeUInt32BE(data.length, 4);
|
183 | buffers.push(b);
|
184 | break;
|
185 | }
|
186 |
|
187 | default:
|
188 | {
|
189 | throw new Error(`Unknown format string character: ${c}`);
|
190 | }
|
191 | }
|
192 | }
|
193 |
|
194 | const stat = await _fsExtra.default.stat(file);
|
195 |
|
196 | if (!stat.isFile()) {
|
197 | throw new Error(`Path not a file: ${file}`);
|
198 | }
|
199 |
|
200 | const fd = await _fsExtra.default.open(file, 'a');
|
201 |
|
202 | try {
|
203 | for (const b of buffers) {
|
204 |
|
205 | await _fsExtra.default.appendFile(fd, b);
|
206 | }
|
207 | } finally {
|
208 | await _fsExtra.default.close(fd);
|
209 | }
|
210 | }
|
211 | |
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 | }
|
219 |
|
220 | exports.Projector = Projector;
|
221 |
|