1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.NsisTarget = void 0;
|
7 |
|
8 | function _bluebirdLst() {
|
9 | const data = _interopRequireWildcard(require("bluebird-lst"));
|
10 |
|
11 | _bluebirdLst = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | function _zipBin() {
|
19 | const data = require("7zip-bin");
|
20 |
|
21 | _zipBin = function () {
|
22 | return data;
|
23 | };
|
24 |
|
25 | return data;
|
26 | }
|
27 |
|
28 | function _builderUtil() {
|
29 | const data = require("builder-util");
|
30 |
|
31 | _builderUtil = function () {
|
32 | return data;
|
33 | };
|
34 |
|
35 | return data;
|
36 | }
|
37 |
|
38 | function _builderUtilRuntime() {
|
39 | const data = require("builder-util-runtime");
|
40 |
|
41 | _builderUtilRuntime = function () {
|
42 | return data;
|
43 | };
|
44 |
|
45 | return data;
|
46 | }
|
47 |
|
48 | function _binDownload() {
|
49 | const data = require("builder-util/out/binDownload");
|
50 |
|
51 | _binDownload = function () {
|
52 | return data;
|
53 | };
|
54 |
|
55 | return data;
|
56 | }
|
57 |
|
58 | function _fs() {
|
59 | const data = require("builder-util/out/fs");
|
60 |
|
61 | _fs = function () {
|
62 | return data;
|
63 | };
|
64 |
|
65 | return data;
|
66 | }
|
67 |
|
68 | function _hash() {
|
69 | const data = require("builder-util/out/hash");
|
70 |
|
71 | _hash = function () {
|
72 | return data;
|
73 | };
|
74 |
|
75 | return data;
|
76 | }
|
77 |
|
78 | var _debug2 = _interopRequireDefault(require("debug"));
|
79 |
|
80 | function _fsExtraP() {
|
81 | const data = require("fs-extra-p");
|
82 |
|
83 | _fsExtraP = function () {
|
84 | return data;
|
85 | };
|
86 |
|
87 | return data;
|
88 | }
|
89 |
|
90 | function _lazyVal() {
|
91 | const data = require("lazy-val");
|
92 |
|
93 | _lazyVal = function () {
|
94 | return data;
|
95 | };
|
96 |
|
97 | return data;
|
98 | }
|
99 |
|
100 | var path = _interopRequireWildcard(require("path"));
|
101 |
|
102 | function _core() {
|
103 | const data = require("../../core");
|
104 |
|
105 | _core = function () {
|
106 | return data;
|
107 | };
|
108 |
|
109 | return data;
|
110 | }
|
111 |
|
112 | function _CommonWindowsInstallerConfiguration() {
|
113 | const data = require("../../options/CommonWindowsInstallerConfiguration");
|
114 |
|
115 | _CommonWindowsInstallerConfiguration = function () {
|
116 | return data;
|
117 | };
|
118 |
|
119 | return data;
|
120 | }
|
121 |
|
122 | function _platformPackager() {
|
123 | const data = require("../../platformPackager");
|
124 |
|
125 | _platformPackager = function () {
|
126 | return data;
|
127 | };
|
128 |
|
129 | return data;
|
130 | }
|
131 |
|
132 | function _timer() {
|
133 | const data = require("../../util/timer");
|
134 |
|
135 | _timer = function () {
|
136 | return data;
|
137 | };
|
138 |
|
139 | return data;
|
140 | }
|
141 |
|
142 | function _archive() {
|
143 | const data = require("../archive");
|
144 |
|
145 | _archive = function () {
|
146 | return data;
|
147 | };
|
148 |
|
149 | return data;
|
150 | }
|
151 |
|
152 | function _differentialUpdateInfoBuilder() {
|
153 | const data = require("../differentialUpdateInfoBuilder");
|
154 |
|
155 | _differentialUpdateInfoBuilder = function () {
|
156 | return data;
|
157 | };
|
158 |
|
159 | return data;
|
160 | }
|
161 |
|
162 | function _targetUtil() {
|
163 | const data = require("../targetUtil");
|
164 |
|
165 | _targetUtil = function () {
|
166 | return data;
|
167 | };
|
168 |
|
169 | return data;
|
170 | }
|
171 |
|
172 | function _nsisLang() {
|
173 | const data = require("./nsisLang");
|
174 |
|
175 | _nsisLang = function () {
|
176 | return data;
|
177 | };
|
178 |
|
179 | return data;
|
180 | }
|
181 |
|
182 | function _nsisLicense() {
|
183 | const data = require("./nsisLicense");
|
184 |
|
185 | _nsisLicense = function () {
|
186 | return data;
|
187 | };
|
188 |
|
189 | return data;
|
190 | }
|
191 |
|
192 | function _nsisScriptGenerator() {
|
193 | const data = require("./nsisScriptGenerator");
|
194 |
|
195 | _nsisScriptGenerator = function () {
|
196 | return data;
|
197 | };
|
198 |
|
199 | return data;
|
200 | }
|
201 |
|
202 | function _nsisUtil() {
|
203 | const data = require("./nsisUtil");
|
204 |
|
205 | _nsisUtil = function () {
|
206 | return data;
|
207 | };
|
208 |
|
209 | return data;
|
210 | }
|
211 |
|
212 | let createPackageFileInfo = (() => {
|
213 | var _ref9 = (0, _bluebirdLst().coroutine)(function* (file) {
|
214 | return {
|
215 | path: file,
|
216 | size: (yield (0, _fsExtraP().stat)(file)).size,
|
217 | sha512: yield (0, _hash().hashFile)(file)
|
218 | };
|
219 | });
|
220 |
|
221 | return function createPackageFileInfo(_x2) {
|
222 | return _ref9.apply(this, arguments);
|
223 | };
|
224 | })(); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
225 |
|
226 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
227 |
|
228 | const debug = (0, _debug2.default)("electron-builder:nsis");
|
229 |
|
230 | const ELECTRON_BUILDER_NS_UUID = _builderUtilRuntime().UUID.parse("50e065bc-3134-11e6-9bab-38c9862bdaf3");
|
231 |
|
232 |
|
233 | const nsisResourcePathPromise = new (_lazyVal().Lazy)(() => (0, _binDownload().getBinFromGithub)("nsis-resources", "3.3.0", "4okc98BD0v9xDcSjhPVhAkBMqos+FvD/5/H72fTTIwoHTuWd2WdD7r+1j72hxd+ZXxq1y3FRW0x6Z3jR0VfpMw=="));
|
234 | const USE_NSIS_BUILT_IN_COMPRESSOR = false;
|
235 |
|
236 | class NsisTarget extends _core().Target {
|
237 | constructor(packager, outDir, targetName, packageHelper) {
|
238 | super(targetName);
|
239 | this.packager = packager;
|
240 | this.outDir = outDir;
|
241 | this.packageHelper = packageHelper;
|
242 |
|
243 |
|
244 | this.archs = new Map();
|
245 | this.packageHelper.refCount++;
|
246 | this.options = targetName === "portable" ? Object.create(null) : Object.assign({}, this.packager.config.nsis, {
|
247 | preCompressedFileExtensions: [".avi", ".mov", ".m4v", ".mp4", ".m4p", ".qt", ".mkv", ".webm", ".vmdk"]
|
248 | });
|
249 |
|
250 | if (targetName !== "nsis") {
|
251 | Object.assign(this.options, this.packager.config[targetName === "nsis-web" ? "nsisWeb" : targetName]);
|
252 | }
|
253 |
|
254 | const deps = packager.info.metadata.dependencies;
|
255 |
|
256 | if (deps != null && deps["electron-squirrel-startup"] != null) {
|
257 | _builderUtil().log.warn('"electron-squirrel-startup" dependency is not required for NSIS');
|
258 | }
|
259 | }
|
260 |
|
261 | build(appOutDir, arch) {
|
262 | var _this = this;
|
263 |
|
264 | return (0, _bluebirdLst().coroutine)(function* () {
|
265 | _this.archs.set(arch, appOutDir);
|
266 | })();
|
267 | }
|
268 |
|
269 | get isBuildDifferentialAware() {
|
270 | return !this.isPortable && this.options.differentialPackage !== false;
|
271 | }
|
272 |
|
273 | getPreCompressedFileExtensions() {
|
274 | const result = this.isWebInstaller ? null : this.options.preCompressedFileExtensions;
|
275 | return result == null ? null : (0, _builderUtil().asArray)(result).map(it => it.startsWith(".") ? it : `.${it}`);
|
276 | }
|
277 |
|
278 |
|
279 |
|
280 | buildAppPackage(appOutDir, arch) {
|
281 | var _this2 = this;
|
282 |
|
283 | return (0, _bluebirdLst().coroutine)(function* () {
|
284 | const options = _this2.options;
|
285 | const packager = _this2.packager;
|
286 | const isBuildDifferentialAware = _this2.isBuildDifferentialAware;
|
287 | const format = !isBuildDifferentialAware && options.useZip ? "zip" : "7z";
|
288 | const archiveFile = path.join(_this2.outDir, `${packager.appInfo.sanitizedName}-${packager.appInfo.version}-${_builderUtil().Arch[arch]}.nsis.${format}`);
|
289 |
|
290 | const preCompressedFileExtensions = _this2.getPreCompressedFileExtensions();
|
291 |
|
292 | const archiveOptions = {
|
293 | withoutDir: true,
|
294 | compression: packager.compression,
|
295 | excluded: preCompressedFileExtensions == null ? null : preCompressedFileExtensions.map(it => `*${it}`)
|
296 | };
|
297 | const timer = (0, _timer().time)(`nsis package, ${_builderUtil().Arch[arch]}`);
|
298 | yield (0, _archive().archive)(format, archiveFile, appOutDir, isBuildDifferentialAware ? (0, _differentialUpdateInfoBuilder().configureDifferentialAwareArchiveOptions)(archiveOptions) : archiveOptions);
|
299 | timer.end();
|
300 |
|
301 | if (isBuildDifferentialAware && _this2.isWebInstaller) {
|
302 | const data = yield (0, _differentialUpdateInfoBuilder().appendBlockmap)(archiveFile);
|
303 | return Object.assign({}, data, {
|
304 | size: data.size,
|
305 | path: archiveFile
|
306 | });
|
307 | } else {
|
308 | return yield createPackageFileInfo(archiveFile);
|
309 | }
|
310 | })();
|
311 | }
|
312 |
|
313 | finishBuild() {
|
314 | var _this3 = this;
|
315 |
|
316 | return (0, _bluebirdLst().coroutine)(function* () {
|
317 | try {
|
318 | yield _this3.buildInstaller();
|
319 | } finally {
|
320 | yield _this3.packageHelper.finishBuild();
|
321 | }
|
322 | })();
|
323 | }
|
324 |
|
325 | get installerFilenamePattern() {
|
326 |
|
327 | return "${productName} " + (this.isPortable ? "" : "Setup ") + "${version}.${ext}";
|
328 | }
|
329 |
|
330 | get isPortable() {
|
331 | return this.name === "portable";
|
332 | }
|
333 |
|
334 | buildInstaller() {
|
335 | var _this4 = this;
|
336 |
|
337 | return (0, _bluebirdLst().coroutine)(function* () {
|
338 | const packager = _this4.packager;
|
339 | const appInfo = packager.appInfo;
|
340 | const options = _this4.options;
|
341 | const installerFilename = packager.expandArtifactNamePattern(options, "exe", null, _this4.installerFilenamePattern);
|
342 | const oneClick = options.oneClick !== false;
|
343 | const installerPath = path.join(_this4.outDir, installerFilename);
|
344 | const logFields = {
|
345 | target: _this4.name,
|
346 | file: _builderUtil().log.filePath(installerPath),
|
347 | archs: Array.from(_this4.archs.keys()).map(it => _builderUtil().Arch[it]).join(", ")
|
348 | };
|
349 |
|
350 | if (!_this4.isPortable) {
|
351 | logFields.oneClick = oneClick;
|
352 | }
|
353 |
|
354 | _builderUtil().log.info(logFields, "building");
|
355 |
|
356 | const guid = options.guid || _builderUtilRuntime().UUID.v5(appInfo.id, ELECTRON_BUILDER_NS_UUID);
|
357 |
|
358 | const defines = {
|
359 | APP_ID: appInfo.id,
|
360 | APP_GUID: guid,
|
361 | PRODUCT_NAME: appInfo.productName,
|
362 | PRODUCT_FILENAME: appInfo.productFilename,
|
363 | APP_FILENAME: (0, _targetUtil().getWindowsInstallationDirName)(appInfo, !oneClick || options.perMachine === true),
|
364 | APP_DESCRIPTION: appInfo.description,
|
365 | VERSION: appInfo.version,
|
366 | PROJECT_DIR: packager.projectDir,
|
367 | BUILD_RESOURCES_DIR: packager.info.buildResourcesDir
|
368 | };
|
369 | const commands = {
|
370 | OutFile: `"${installerPath}"`,
|
371 | VIProductVersion: appInfo.versionInWeirdWindowsForm,
|
372 | VIAddVersionKey: _this4.computeVersionKey(),
|
373 | Unicode: _this4.isUnicodeEnabled
|
374 | };
|
375 | const isPortable = _this4.isPortable;
|
376 | const iconPath = (isPortable ? null : yield packager.getResource(options.installerIcon, "installerIcon.ico")) || (yield packager.getIconPath());
|
377 |
|
378 | if (iconPath != null) {
|
379 | if (isPortable) {
|
380 | commands.Icon = `"${iconPath}"`;
|
381 | } else {
|
382 | defines.MUI_ICON = iconPath;
|
383 | defines.MUI_UNICON = iconPath;
|
384 | }
|
385 | }
|
386 |
|
387 | const packageFiles = {};
|
388 | let estimatedSize = 0;
|
389 |
|
390 | if (_this4.isPortable && options.useZip) {
|
391 | for (const [arch, dir] of _this4.archs.entries()) {
|
392 | defines[arch === _builderUtil().Arch.x64 ? "APP_DIR_64" : "APP_DIR_32"] = dir;
|
393 | }
|
394 | } else if (USE_NSIS_BUILT_IN_COMPRESSOR && _this4.archs.size === 1) {
|
395 | defines.APP_BUILD_DIR = _this4.archs.get(_this4.archs.keys().next().value);
|
396 | } else {
|
397 | yield _bluebirdLst().default.map(_this4.archs.keys(), (() => {
|
398 | var _ref = (0, _bluebirdLst().coroutine)(function* (arch) {
|
399 | const fileInfo = yield _this4.packageHelper.packArch(arch, _this4);
|
400 | const file = fileInfo.path;
|
401 | const defineKey = arch === _builderUtil().Arch.x64 ? "APP_64" : "APP_32";
|
402 | defines[defineKey] = file;
|
403 | defines[`${defineKey}_NAME`] = path.basename(file);
|
404 |
|
405 | defines[`${defineKey}_HASH`] = Buffer.from(fileInfo.sha512, "base64").toString("hex").toUpperCase();
|
406 |
|
407 | if (_this4.isWebInstaller) {
|
408 | packager.dispatchArtifactCreated(file, _this4, arch);
|
409 | packageFiles[_builderUtil().Arch[arch]] = fileInfo;
|
410 | }
|
411 |
|
412 | const archiveInfo = (yield (0, _builderUtil().exec)(_zipBin().path7za, ["l", file])).trim();
|
413 |
|
414 | const match = archiveInfo.match(/(\d+)\s+\d+\s+\d+\s+files/);
|
415 |
|
416 | if (match == null) {
|
417 | _builderUtil().log.warn({
|
418 | output: archiveInfo
|
419 | }, "cannot compute size of app package");
|
420 | } else {
|
421 | estimatedSize += parseInt(match[1], 10);
|
422 | }
|
423 | });
|
424 |
|
425 | return function (_x) {
|
426 | return _ref.apply(this, arguments);
|
427 | };
|
428 | })());
|
429 | }
|
430 |
|
431 | _this4.configureDefinesForAllTypeOfInstaller(defines);
|
432 |
|
433 | if (isPortable) {
|
434 | defines.REQUEST_EXECUTION_LEVEL = options.requestExecutionLevel || "user";
|
435 | } else {
|
436 | yield _this4.configureDefines(oneClick, defines);
|
437 | }
|
438 |
|
439 | if (estimatedSize !== 0) {
|
440 |
|
441 | defines.ESTIMATED_SIZE = Math.round(estimatedSize / 1024);
|
442 | }
|
443 |
|
444 | if (packager.compression === "store") {
|
445 | commands.SetCompress = "off";
|
446 | } else {
|
447 |
|
448 |
|
449 |
|
450 | commands.SetCompressor = "zlib";
|
451 |
|
452 | if (!_this4.isWebInstaller) {
|
453 | defines.COMPRESS = "auto";
|
454 | }
|
455 | }
|
456 |
|
457 | debug(defines);
|
458 | debug(commands);
|
459 |
|
460 | if (packager.packagerOptions.effectiveOptionComputed != null && (yield packager.packagerOptions.effectiveOptionComputed([defines, commands]))) {
|
461 | return;
|
462 | }
|
463 |
|
464 | const sharedHeader = yield _this4.computeCommonInstallerScriptHeader();
|
465 | const script = isPortable ? yield (0, _fsExtraP().readFile)(path.join(_nsisUtil().nsisTemplatesDir, "portable.nsi"), "utf8") : yield _this4.computeScriptAndSignUninstaller(defines, commands, installerPath, sharedHeader);
|
466 | yield _this4.executeMakensis(defines, commands, sharedHeader + (yield _this4.computeFinalScript(script, true)));
|
467 | yield Promise.all([packager.sign(installerPath), defines.UNINSTALLER_OUT_FILE == null ? Promise.resolve() : (0, _fsExtraP().unlink)(defines.UNINSTALLER_OUT_FILE)]);
|
468 | const safeArtifactName = (0, _platformPackager().isSafeGithubName)(installerFilename) ? installerFilename : _this4.generateGitHubInstallerName();
|
469 | let updateInfo;
|
470 |
|
471 | if (_this4.isWebInstaller) {
|
472 | updateInfo = (0, _differentialUpdateInfoBuilder().createNsisWebDifferentialUpdateInfo)(installerPath, packageFiles);
|
473 | } else if (_this4.isBuildDifferentialAware) {
|
474 | updateInfo = yield (0, _differentialUpdateInfoBuilder().createBlockmap)(installerPath, _this4, packager, safeArtifactName);
|
475 | }
|
476 |
|
477 | packager.info.dispatchArtifactCreated({
|
478 | file: installerPath,
|
479 | updateInfo,
|
480 | target: _this4,
|
481 | packager,
|
482 | arch: _this4.archs.size === 1 ? _this4.archs.keys().next().value : null,
|
483 | safeArtifactName,
|
484 | isWriteUpdateInfo: !_this4.isPortable
|
485 | });
|
486 | })();
|
487 | }
|
488 |
|
489 | generateGitHubInstallerName() {
|
490 | const appInfo = this.packager.appInfo;
|
491 | const classifier = appInfo.name.toLowerCase() === appInfo.name ? "setup-" : "Setup-";
|
492 | return `${appInfo.name}-${this.isPortable ? "" : classifier}${appInfo.version}.exe`;
|
493 | }
|
494 |
|
495 | get isUnicodeEnabled() {
|
496 | return this.options.unicode !== false;
|
497 | }
|
498 |
|
499 | get isWebInstaller() {
|
500 | return false;
|
501 | }
|
502 |
|
503 | computeScriptAndSignUninstaller(defines, commands, installerPath, sharedHeader) {
|
504 | var _this5 = this;
|
505 |
|
506 | return (0, _bluebirdLst().coroutine)(function* () {
|
507 | const packager = _this5.packager;
|
508 | const customScriptPath = yield packager.getResource(_this5.options.script, "installer.nsi");
|
509 | const script = yield (0, _fsExtraP().readFile)(customScriptPath || path.join(_nsisUtil().nsisTemplatesDir, "installer.nsi"), "utf8");
|
510 |
|
511 | if (customScriptPath != null) {
|
512 | _builderUtil().log.info({
|
513 | reason: "custom NSIS script is used"
|
514 | }, "uninstaller is not signed by electron-builder");
|
515 |
|
516 | return script;
|
517 | }
|
518 |
|
519 |
|
520 |
|
521 | const uninstallerPath = path.join(_this5.outDir, `.__uninstaller-${_this5.name}-${_this5.packager.appInfo.sanitizedName}.exe`);
|
522 | const isWin = process.platform === "win32";
|
523 | defines.BUILD_UNINSTALLER = null;
|
524 | defines.UNINSTALLER_OUT_FILE = isWin ? uninstallerPath : path.win32.join("Z:", uninstallerPath);
|
525 | yield _this5.executeMakensis(defines, commands, sharedHeader + (yield _this5.computeFinalScript(script, false)));
|
526 | yield (0, _builderUtil().execWine)(installerPath, []);
|
527 | yield packager.sign(uninstallerPath, " Signing NSIS uninstaller");
|
528 | delete defines.BUILD_UNINSTALLER;
|
529 |
|
530 | defines.UNINSTALLER_OUT_FILE = uninstallerPath;
|
531 | return script;
|
532 | })();
|
533 | }
|
534 |
|
535 | computeVersionKey() {
|
536 |
|
537 |
|
538 | const localeId = this.options.language || "1033";
|
539 | const appInfo = this.packager.appInfo;
|
540 | const versionKey = [`/LANG=${localeId} ProductName "${appInfo.productName}"`, `/LANG=${localeId} ProductVersion "${appInfo.version}"`, `/LANG=${localeId} LegalCopyright "${appInfo.copyright}"`, `/LANG=${localeId} FileDescription "${appInfo.description}"`, `/LANG=${localeId} FileVersion "${appInfo.buildVersion}"`];
|
541 | (0, _builderUtil().use)(this.packager.platformSpecificBuildOptions.legalTrademarks, it => versionKey.push(`/LANG=${localeId} LegalTrademarks "${it}"`));
|
542 | (0, _builderUtil().use)(appInfo.companyName, it => versionKey.push(`/LANG=${localeId} CompanyName "${it}"`));
|
543 | return versionKey;
|
544 | }
|
545 |
|
546 | configureDefines(oneClick, defines) {
|
547 | const packager = this.packager;
|
548 | const options = this.options;
|
549 | const asyncTaskManager = new (_builderUtil().AsyncTaskManager)(packager.info.cancellationToken);
|
550 |
|
551 | if (oneClick) {
|
552 | defines.ONE_CLICK = null;
|
553 |
|
554 | if (options.runAfterFinish !== false) {
|
555 | defines.RUN_AFTER_FINISH = null;
|
556 | }
|
557 |
|
558 | asyncTaskManager.add((0, _bluebirdLst().coroutine)(function* () {
|
559 | const installerHeaderIcon = yield packager.getResource(options.installerHeaderIcon, "installerHeaderIcon.ico");
|
560 |
|
561 | if (installerHeaderIcon != null) {
|
562 | defines.HEADER_ICO = installerHeaderIcon;
|
563 | }
|
564 | }));
|
565 | } else {
|
566 | if (options.runAfterFinish === false) {
|
567 | defines.HIDE_RUN_AFTER_FINISH = null;
|
568 | }
|
569 |
|
570 | asyncTaskManager.add((0, _bluebirdLst().coroutine)(function* () {
|
571 | const installerHeader = yield packager.getResource(options.installerHeader, "installerHeader.bmp");
|
572 |
|
573 | if (installerHeader != null) {
|
574 | defines.MUI_HEADERIMAGE = null;
|
575 | defines.MUI_HEADERIMAGE_RIGHT = null;
|
576 | defines.MUI_HEADERIMAGE_BITMAP = installerHeader;
|
577 | }
|
578 | }));
|
579 | asyncTaskManager.add((0, _bluebirdLst().coroutine)(function* () {
|
580 | const bitmap = (yield packager.getResource(options.installerSidebar, "installerSidebar.bmp")) || "${NSISDIR}\\Contrib\\Graphics\\Wizard\\nsis3-metro.bmp";
|
581 | defines.MUI_WELCOMEFINISHPAGE_BITMAP = bitmap;
|
582 | defines.MUI_UNWELCOMEFINISHPAGE_BITMAP = (yield packager.getResource(options.uninstallerSidebar, "uninstallerSidebar.bmp")) || bitmap;
|
583 | }));
|
584 |
|
585 | if (options.allowElevation !== false) {
|
586 | defines.MULTIUSER_INSTALLMODE_ALLOW_ELEVATION = null;
|
587 | }
|
588 | }
|
589 |
|
590 | if (options.perMachine === true) {
|
591 | defines.INSTALL_MODE_PER_ALL_USERS = null;
|
592 | }
|
593 |
|
594 | if (!oneClick || options.perMachine === true) {
|
595 | defines.INSTALL_MODE_PER_ALL_USERS_REQUIRED = null;
|
596 | }
|
597 |
|
598 | if (options.allowToChangeInstallationDirectory) {
|
599 | if (oneClick) {
|
600 | throw new (_builderUtil().InvalidConfigurationError)("allowToChangeInstallationDirectory makes sense only for assisted installer (please set oneClick to false)");
|
601 | }
|
602 |
|
603 | defines.allowToChangeInstallationDirectory = null;
|
604 | }
|
605 |
|
606 | const commonOptions = (0, _CommonWindowsInstallerConfiguration().getEffectiveOptions)(options, packager);
|
607 |
|
608 | if (commonOptions.menuCategory != null) {
|
609 | defines.MENU_FILENAME = commonOptions.menuCategory;
|
610 | }
|
611 |
|
612 | defines.SHORTCUT_NAME = commonOptions.shortcutName;
|
613 |
|
614 | if (options.deleteAppDataOnUninstall) {
|
615 | defines.DELETE_APP_DATA_ON_UNINSTALL = null;
|
616 | }
|
617 |
|
618 | asyncTaskManager.add((0, _bluebirdLst().coroutine)(function* () {
|
619 | const uninstallerIcon = yield packager.getResource(options.uninstallerIcon, "uninstallerIcon.ico");
|
620 |
|
621 | if (uninstallerIcon != null) {
|
622 |
|
623 | defines.UNINSTALLER_ICON = uninstallerIcon;
|
624 | defines.MUI_UNICON = uninstallerIcon;
|
625 | }
|
626 | }));
|
627 | defines.UNINSTALL_DISPLAY_NAME = packager.expandMacro(options.uninstallDisplayName || "${productName} ${version}", null, {}, false);
|
628 |
|
629 | if (commonOptions.isCreateDesktopShortcut === _CommonWindowsInstallerConfiguration().DesktopShortcutCreationPolicy.NEVER) {
|
630 | defines.DO_NOT_CREATE_DESKTOP_SHORTCUT = null;
|
631 | }
|
632 |
|
633 | if (commonOptions.isCreateDesktopShortcut === _CommonWindowsInstallerConfiguration().DesktopShortcutCreationPolicy.ALWAYS) {
|
634 | defines.RECREATE_DESKTOP_SHORTCUT = null;
|
635 | }
|
636 |
|
637 | if (!commonOptions.isCreateStartMenuShortcut) {
|
638 | defines.DO_NOT_CREATE_START_MENU_SHORTCUT = null;
|
639 | }
|
640 |
|
641 | if (options.displayLanguageSelector === true) {
|
642 | defines.DISPLAY_LANG_SELECTOR = null;
|
643 | }
|
644 |
|
645 | return asyncTaskManager.awaitTasks();
|
646 | }
|
647 |
|
648 | configureDefinesForAllTypeOfInstaller(defines) {
|
649 | const appInfo = this.packager.appInfo;
|
650 | const companyName = appInfo.companyName;
|
651 |
|
652 | if (companyName != null) {
|
653 | defines.COMPANY_NAME = companyName;
|
654 | }
|
655 |
|
656 |
|
657 | if (defines.APP_FILENAME !== appInfo.productFilename) {
|
658 | defines.APP_PRODUCT_FILENAME = appInfo.productFilename;
|
659 | }
|
660 |
|
661 | if (this.isWebInstaller) {
|
662 | defines.APP_PACKAGE_STORE_FILE = `${appInfo.productFilename}\\${_builderUtilRuntime().CURRENT_APP_PACKAGE_FILE_NAME}`;
|
663 | } else {
|
664 | defines.APP_INSTALLER_STORE_FILE = `${appInfo.productFilename}\\${_builderUtilRuntime().CURRENT_APP_INSTALLER_FILE_NAME}`;
|
665 | }
|
666 |
|
667 | if (!this.isWebInstaller && defines.APP_BUILD_DIR == null) {
|
668 | const options = this.options;
|
669 |
|
670 | if (options.useZip) {
|
671 | defines.ZIP_COMPRESSION = null;
|
672 | }
|
673 |
|
674 | defines.COMPRESSION_METHOD = options.useZip ? "zip" : "7z";
|
675 | }
|
676 | }
|
677 |
|
678 | executeMakensis(defines, commands, script) {
|
679 | var _this6 = this;
|
680 |
|
681 | return (0, _bluebirdLst().coroutine)(function* () {
|
682 | const args = _this6.options.warningsAsErrors === false ? [] : ["-WX"];
|
683 |
|
684 | for (const name of Object.keys(defines)) {
|
685 | const value = defines[name];
|
686 |
|
687 | if (value == null) {
|
688 | args.push(`-D${name}`);
|
689 | } else {
|
690 | args.push(`-D${name}=${value}`);
|
691 | }
|
692 | }
|
693 |
|
694 | for (const name of Object.keys(commands)) {
|
695 | const value = commands[name];
|
696 |
|
697 | if (Array.isArray(value)) {
|
698 | for (const c of value) {
|
699 | args.push(`-X${name} ${c}`);
|
700 | }
|
701 | } else {
|
702 | args.push(`-X${name} ${value}`);
|
703 | }
|
704 | }
|
705 |
|
706 | args.push("-");
|
707 |
|
708 | if (_this6.packager.debugLogger.isEnabled) {
|
709 | _this6.packager.debugLogger.add("nsis.script", script);
|
710 | }
|
711 |
|
712 | const nsisPath = yield _nsisUtil().NSIS_PATH.value;
|
713 | const command = path.join(nsisPath, process.platform === "darwin" ? "mac" : process.platform === "win32" ? "Bin" : "linux", process.platform === "win32" ? "makensis.exe" : "makensis");
|
714 | yield (0, _builderUtil().spawnAndWrite)(command, args, script, {
|
715 |
|
716 | env: Object.assign({}, process.env, {
|
717 | NSISDIR: nsisPath
|
718 | }),
|
719 | cwd: _nsisUtil().nsisTemplatesDir
|
720 | });
|
721 | })();
|
722 | }
|
723 |
|
724 | computeCommonInstallerScriptHeader() {
|
725 | var _this7 = this;
|
726 |
|
727 | return (0, _bluebirdLst().coroutine)(function* () {
|
728 | const packager = _this7.packager;
|
729 | const options = _this7.options;
|
730 | const scriptGenerator = new (_nsisScriptGenerator().NsisScriptGenerator)();
|
731 | const langConfigurator = new (_nsisLang().LangConfigurator)(options);
|
732 | scriptGenerator.include(path.join(_nsisUtil().nsisTemplatesDir, "include", "StdUtils.nsh"));
|
733 | const includeDir = path.join(_nsisUtil().nsisTemplatesDir, "include");
|
734 | scriptGenerator.addIncludeDir(includeDir);
|
735 | scriptGenerator.flags(["updated", "force-run", "keep-shortcuts", "no-desktop-shortcut", "delete-app-data"]);
|
736 | (0, _nsisLang().createAddLangsMacro)(scriptGenerator, langConfigurator);
|
737 | const taskManager = new (_builderUtil().AsyncTaskManager)(packager.info.cancellationToken);
|
738 | const pluginArch = _this7.isUnicodeEnabled ? "x86-unicode" : "x86-ansi";
|
739 | taskManager.add((0, _bluebirdLst().coroutine)(function* () {
|
740 | scriptGenerator.addPluginDir(pluginArch, path.join((yield nsisResourcePathPromise.value), "plugins", pluginArch));
|
741 | }));
|
742 | taskManager.add((0, _bluebirdLst().coroutine)(function* () {
|
743 | const userPluginDir = path.join(packager.info.buildResourcesDir, pluginArch);
|
744 | const stat = yield (0, _fs().statOrNull)(userPluginDir);
|
745 |
|
746 | if (stat != null && stat.isDirectory()) {
|
747 | scriptGenerator.addPluginDir(pluginArch, userPluginDir);
|
748 | }
|
749 | }));
|
750 | taskManager.addTask((0, _nsisLang().addCustomMessageFileInclude)("messages.yml", packager, scriptGenerator, langConfigurator));
|
751 |
|
752 | if (!_this7.isPortable) {
|
753 | if (options.oneClick === false) {
|
754 | taskManager.addTask((0, _nsisLang().addCustomMessageFileInclude)("assistedMessages.yml", packager, scriptGenerator, langConfigurator));
|
755 | }
|
756 |
|
757 | taskManager.add((0, _bluebirdLst().coroutine)(function* () {
|
758 | const customInclude = yield packager.getResource(_this7.options.include, "installer.nsh");
|
759 |
|
760 | if (customInclude != null) {
|
761 | scriptGenerator.addIncludeDir(packager.info.buildResourcesDir);
|
762 | scriptGenerator.include(customInclude);
|
763 | }
|
764 | }));
|
765 | }
|
766 |
|
767 | yield taskManager.awaitTasks();
|
768 | return scriptGenerator.build();
|
769 | })();
|
770 | }
|
771 |
|
772 | computeFinalScript(originalScript, isInstaller) {
|
773 | var _this8 = this;
|
774 |
|
775 | return (0, _bluebirdLst().coroutine)(function* () {
|
776 | const packager = _this8.packager;
|
777 | const options = _this8.options;
|
778 | const langConfigurator = new (_nsisLang().LangConfigurator)(options);
|
779 | const scriptGenerator = new (_nsisScriptGenerator().NsisScriptGenerator)();
|
780 | const taskManager = new (_builderUtil().AsyncTaskManager)(packager.info.cancellationToken);
|
781 |
|
782 | if (isInstaller) {
|
783 |
|
784 | taskManager.add(() => (0, _nsisLicense().computeLicensePage)(packager, options, scriptGenerator, langConfigurator.langs));
|
785 | }
|
786 |
|
787 | yield taskManager.awaitTasks();
|
788 |
|
789 | if (_this8.isPortable) {
|
790 | return scriptGenerator.build() + originalScript;
|
791 | }
|
792 |
|
793 | const preCompressedFileExtensions = _this8.getPreCompressedFileExtensions();
|
794 |
|
795 | if (preCompressedFileExtensions != null) {
|
796 | for (const [arch, dir] of _this8.archs.entries()) {
|
797 | const preCompressedAssets = yield (0, _fs().walk)(path.join(dir, "resources"), (file, stat) => stat.isDirectory() || preCompressedFileExtensions.some(it => file.endsWith(it)));
|
798 |
|
799 | if (preCompressedAssets.length !== 0) {
|
800 | const macro = new (_nsisScriptGenerator().NsisScriptGenerator)();
|
801 |
|
802 | for (const file of preCompressedAssets) {
|
803 | macro.file(`$INSTDIR\\${path.relative(dir, file).replace(/\//g, "\\")}`, file);
|
804 | }
|
805 |
|
806 | scriptGenerator.macro(`customFiles_${_builderUtil().Arch[arch]}`, macro);
|
807 | }
|
808 | }
|
809 | }
|
810 |
|
811 | const fileAssociations = packager.fileAssociations;
|
812 |
|
813 | if (fileAssociations.length !== 0) {
|
814 | scriptGenerator.include(path.join(path.join(_nsisUtil().nsisTemplatesDir, "include"), "FileAssociation.nsh"));
|
815 |
|
816 | if (isInstaller) {
|
817 | const registerFileAssociationsScript = new (_nsisScriptGenerator().NsisScriptGenerator)();
|
818 |
|
819 | for (const item of fileAssociations) {
|
820 | const extensions = (0, _builderUtil().asArray)(item.ext).map(_platformPackager().normalizeExt);
|
821 |
|
822 | for (const ext of extensions) {
|
823 | const customIcon = yield packager.getResource((0, _builderUtil().getPlatformIconFileName)(item.icon, false), `${extensions[0]}.ico`);
|
824 | let installedIconPath = "$appExe,0";
|
825 |
|
826 | if (customIcon != null) {
|
827 | installedIconPath = `$INSTDIR\\resources\\${path.basename(customIcon)}`;
|
828 | registerFileAssociationsScript.file(installedIconPath, customIcon);
|
829 | }
|
830 |
|
831 | const icon = `"${installedIconPath}"`;
|
832 | const commandText = `"Open with ${packager.appInfo.productName}"`;
|
833 | const command = '"$appExe $\\"%1$\\""';
|
834 | registerFileAssociationsScript.insertMacro("APP_ASSOCIATE", `"${ext}" "${item.name || ext}" "${item.description || ""}" ${icon} ${commandText} ${command}`);
|
835 | }
|
836 | }
|
837 |
|
838 | scriptGenerator.macro("registerFileAssociations", registerFileAssociationsScript);
|
839 | } else {
|
840 | const unregisterFileAssociationsScript = new (_nsisScriptGenerator().NsisScriptGenerator)();
|
841 |
|
842 | for (const item of fileAssociations) {
|
843 | for (const ext of (0, _builderUtil().asArray)(item.ext)) {
|
844 | unregisterFileAssociationsScript.insertMacro("APP_UNASSOCIATE", `"${(0, _platformPackager().normalizeExt)(ext)}" "${item.name || ext}"`);
|
845 | }
|
846 | }
|
847 |
|
848 | scriptGenerator.macro("unregisterFileAssociations", unregisterFileAssociationsScript);
|
849 | }
|
850 | }
|
851 |
|
852 | return scriptGenerator.build() + originalScript;
|
853 | })();
|
854 | }
|
855 |
|
856 | }
|
857 |
|
858 | exports.NsisTarget = NsisTarget;
|
859 |
|
\ | No newline at end of file |