electron-updater 4.3.5 → 4.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/out/AppAdapter.js +19 -28
- package/out/AppAdapter.js.map +1 -1
- package/out/AppImageUpdater.js +103 -173
- package/out/AppImageUpdater.js.map +1 -1
- package/out/AppUpdater.d.ts +1 -3
- package/out/AppUpdater.js +517 -773
- package/out/AppUpdater.js.map +1 -1
- package/out/BaseUpdater.js +79 -103
- package/out/BaseUpdater.js.map +1 -1
- package/out/DownloadedUpdateHelper.js +150 -224
- package/out/DownloadedUpdateHelper.js.map +1 -1
- package/out/ElectronAppAdapter.js +35 -63
- package/out/ElectronAppAdapter.js.map +1 -1
- package/out/MacUpdater.d.ts +1 -1
- package/out/MacUpdater.js +132 -182
- package/out/MacUpdater.js.map +1 -1
- package/out/NoOpLogger.d.ts +6 -0
- package/out/NoOpLogger.js +19 -0
- package/out/NoOpLogger.js.map +1 -0
- package/out/NsisUpdater.js +199 -331
- package/out/NsisUpdater.js.map +1 -1
- package/out/differentialDownloader/DataSplitter.js +180 -252
- package/out/differentialDownloader/DataSplitter.js.map +1 -1
- package/out/differentialDownloader/DifferentialDownloader.d.ts +3 -0
- package/out/differentialDownloader/DifferentialDownloader.js +243 -308
- package/out/differentialDownloader/DifferentialDownloader.js.map +1 -1
- package/out/differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader.js +29 -65
- package/out/differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader.js.map +1 -1
- package/out/differentialDownloader/GenericDifferentialDownloader.js +7 -21
- package/out/differentialDownloader/GenericDifferentialDownloader.js.map +1 -1
- package/out/differentialDownloader/ProgressDifferentialDownloadCallbackTransform.d.ts +32 -0
- package/out/differentialDownloader/ProgressDifferentialDownloadCallbackTransform.js +90 -0
- package/out/differentialDownloader/ProgressDifferentialDownloadCallbackTransform.js.map +1 -0
- package/out/differentialDownloader/downloadPlanBuilder.js +99 -124
- package/out/differentialDownloader/downloadPlanBuilder.js.map +1 -1
- package/out/differentialDownloader/multipleRangeDownloader.js +99 -148
- package/out/differentialDownloader/multipleRangeDownloader.js.map +1 -1
- package/out/electronHttpExecutor.js +73 -106
- package/out/electronHttpExecutor.js.map +1 -1
- package/out/event.d.ts +35 -0
- package/out/event.js +39 -0
- package/out/event.js.map +1 -0
- package/out/log.d.ts +11 -0
- package/out/log.js +19 -0
- package/out/log.js.map +1 -0
- package/out/main.d.ts +1 -4
- package/out/main.js +60 -212
- package/out/main.js.map +1 -1
- package/out/providerFactory.js +49 -105
- package/out/providerFactory.js.map +1 -1
- package/out/providers/BintrayProvider.d.ts +2 -2
- package/out/providers/BintrayProvider.js +40 -95
- package/out/providers/BintrayProvider.js.map +1 -1
- package/out/providers/GenericProvider.d.ts +2 -2
- package/out/providers/GenericProvider.js +46 -80
- package/out/providers/GenericProvider.js.map +1 -1
- package/out/providers/GitHubProvider.d.ts +2 -2
- package/out/providers/GitHubProvider.js +122 -201
- package/out/providers/GitHubProvider.js.map +1 -1
- package/out/providers/PrivateGitHubProvider.js +87 -165
- package/out/providers/PrivateGitHubProvider.js.map +1 -1
- package/out/providers/Provider.js +122 -173
- package/out/providers/Provider.js.map +1 -1
- package/out/util.d.ts +5 -0
- package/out/util.js +42 -0
- package/out/util.js.map +1 -0
- package/out/windowsExecutableCodeSignatureVerifier.js +99 -139
- package/out/windowsExecutableCodeSignatureVerifier.js.map +1 -1
- package/package.json +33 -31
package/out/NsisUpdater.js
CHANGED
|
@@ -1,351 +1,219 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.NsisUpdater = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return data;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function _fsExtra() {
|
|
81
|
-
const data = require("fs-extra");
|
|
82
|
-
|
|
83
|
-
_fsExtra = function () {
|
|
84
|
-
return data;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
return data;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function _windowsExecutableCodeSignatureVerifier() {
|
|
91
|
-
const data = require("./windowsExecutableCodeSignatureVerifier");
|
|
92
|
-
|
|
93
|
-
_windowsExecutableCodeSignatureVerifier = function () {
|
|
94
|
-
return data;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
return data;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function _url() {
|
|
101
|
-
const data = require("url");
|
|
102
|
-
|
|
103
|
-
_url = function () {
|
|
104
|
-
return data;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
return data;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function _zlib() {
|
|
111
|
-
const data = require("zlib");
|
|
112
|
-
|
|
113
|
-
_zlib = function () {
|
|
114
|
-
return data;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
return data;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
121
|
-
|
|
122
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
123
|
-
|
|
124
|
-
class NsisUpdater extends _BaseUpdater().BaseUpdater {
|
|
125
|
-
constructor(options, app) {
|
|
126
|
-
super(options, app);
|
|
127
|
-
}
|
|
128
|
-
/*** @private */
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
doDownloadUpdate(downloadUpdateOptions) {
|
|
132
|
-
const provider = downloadUpdateOptions.updateInfoAndProvider.provider;
|
|
133
|
-
const fileInfo = (0, _Provider().findFile)(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), "exe");
|
|
134
|
-
return this.executeDownload({
|
|
135
|
-
fileExtension: "exe",
|
|
136
|
-
downloadUpdateOptions,
|
|
137
|
-
fileInfo,
|
|
138
|
-
task: async (destinationFile, downloadOptions, packageFile, removeTempDirIfAny) => {
|
|
139
|
-
const packageInfo = fileInfo.packageInfo;
|
|
140
|
-
const isWebInstaller = packageInfo != null && packageFile != null;
|
|
141
|
-
|
|
142
|
-
if (isWebInstaller || (await this.differentialDownloadInstaller(fileInfo, downloadUpdateOptions, destinationFile, provider))) {
|
|
143
|
-
await this.httpExecutor.download(fileInfo.url, destinationFile, downloadOptions);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const signatureVerificationStatus = await this.verifySignature(destinationFile);
|
|
147
|
-
|
|
148
|
-
if (signatureVerificationStatus != null) {
|
|
149
|
-
await removeTempDirIfAny(); // noinspection ThrowInsideFinallyBlockJS
|
|
150
|
-
|
|
151
|
-
throw (0, _builderUtilRuntime().newError)(`New version ${downloadUpdateOptions.updateInfoAndProvider.info.version} is not signed by the application owner: ${signatureVerificationStatus}`, "ERR_UPDATER_INVALID_SIGNATURE");
|
|
4
|
+
const builder_util_runtime_1 = require("builder-util-runtime");
|
|
5
|
+
const child_process_1 = require("child_process");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const BaseUpdater_1 = require("./BaseUpdater");
|
|
8
|
+
const FileWithEmbeddedBlockMapDifferentialDownloader_1 = require("./differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader");
|
|
9
|
+
const GenericDifferentialDownloader_1 = require("./differentialDownloader/GenericDifferentialDownloader");
|
|
10
|
+
const main_1 = require("./main");
|
|
11
|
+
const util_1 = require("./util");
|
|
12
|
+
const Provider_1 = require("./providers/Provider");
|
|
13
|
+
const fs_extra_1 = require("fs-extra");
|
|
14
|
+
const windowsExecutableCodeSignatureVerifier_1 = require("./windowsExecutableCodeSignatureVerifier");
|
|
15
|
+
const url_1 = require("url");
|
|
16
|
+
const zlib_1 = require("zlib");
|
|
17
|
+
class NsisUpdater extends BaseUpdater_1.BaseUpdater {
|
|
18
|
+
constructor(options, app) {
|
|
19
|
+
super(options, app);
|
|
20
|
+
}
|
|
21
|
+
/*** @private */
|
|
22
|
+
doDownloadUpdate(downloadUpdateOptions) {
|
|
23
|
+
const provider = downloadUpdateOptions.updateInfoAndProvider.provider;
|
|
24
|
+
const fileInfo = Provider_1.findFile(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), "exe");
|
|
25
|
+
return this.executeDownload({
|
|
26
|
+
fileExtension: "exe",
|
|
27
|
+
downloadUpdateOptions,
|
|
28
|
+
fileInfo,
|
|
29
|
+
task: async (destinationFile, downloadOptions, packageFile, removeTempDirIfAny) => {
|
|
30
|
+
const packageInfo = fileInfo.packageInfo;
|
|
31
|
+
const isWebInstaller = packageInfo != null && packageFile != null;
|
|
32
|
+
if (isWebInstaller || (await this.differentialDownloadInstaller(fileInfo, downloadUpdateOptions, destinationFile, provider))) {
|
|
33
|
+
await this.httpExecutor.download(fileInfo.url, destinationFile, downloadOptions);
|
|
34
|
+
}
|
|
35
|
+
const signatureVerificationStatus = await this.verifySignature(destinationFile);
|
|
36
|
+
if (signatureVerificationStatus != null) {
|
|
37
|
+
await removeTempDirIfAny();
|
|
38
|
+
// noinspection ThrowInsideFinallyBlockJS
|
|
39
|
+
throw builder_util_runtime_1.newError(`New version ${downloadUpdateOptions.updateInfoAndProvider.info.version} is not signed by the application owner: ${signatureVerificationStatus}`, "ERR_UPDATER_INVALID_SIGNATURE");
|
|
40
|
+
}
|
|
41
|
+
if (isWebInstaller) {
|
|
42
|
+
if (await this.differentialDownloadWebPackage(downloadUpdateOptions, packageInfo, packageFile, provider)) {
|
|
43
|
+
try {
|
|
44
|
+
await this.httpExecutor.download(new url_1.URL(packageInfo.path), packageFile, {
|
|
45
|
+
headers: downloadUpdateOptions.requestHeaders,
|
|
46
|
+
cancellationToken: downloadUpdateOptions.cancellationToken,
|
|
47
|
+
sha512: packageInfo.sha512,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
try {
|
|
52
|
+
await fs_extra_1.unlink(packageFile);
|
|
53
|
+
}
|
|
54
|
+
catch (ignored) {
|
|
55
|
+
// ignore
|
|
56
|
+
}
|
|
57
|
+
throw e;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
// $certificateInfo = (Get-AuthenticodeSignature 'xxx\yyy.exe'
|
|
65
|
+
// | where {$_.Status.Equals([System.Management.Automation.SignatureStatus]::Valid) -and $_.SignerCertificate.Subject.Contains("CN=siemens.com")})
|
|
66
|
+
// | Out-String ; if ($certificateInfo) { exit 0 } else { exit 1 }
|
|
67
|
+
async verifySignature(tempUpdateFile) {
|
|
68
|
+
let publisherName;
|
|
69
|
+
try {
|
|
70
|
+
publisherName = (await this.configOnDisk.value).publisherName;
|
|
71
|
+
if (publisherName == null) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
152
74
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
await this.httpExecutor.download(new (_url().URL)(packageInfo.path), packageFile, {
|
|
158
|
-
headers: downloadUpdateOptions.requestHeaders,
|
|
159
|
-
cancellationToken: downloadUpdateOptions.cancellationToken,
|
|
160
|
-
sha512: packageInfo.sha512
|
|
161
|
-
});
|
|
162
|
-
} catch (e) {
|
|
163
|
-
try {
|
|
164
|
-
await (0, _fsExtra().unlink)(packageFile);
|
|
165
|
-
} catch (ignored) {// ignore
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
throw e;
|
|
75
|
+
catch (e) {
|
|
76
|
+
if (e.code === "ENOENT") {
|
|
77
|
+
// no app-update.yml
|
|
78
|
+
return null;
|
|
169
79
|
}
|
|
170
|
-
|
|
80
|
+
throw e;
|
|
171
81
|
}
|
|
172
|
-
|
|
173
|
-
});
|
|
174
|
-
} // $certificateInfo = (Get-AuthenticodeSignature 'xxx\yyy.exe'
|
|
175
|
-
// | where {$_.Status.Equals([System.Management.Automation.SignatureStatus]::Valid) -and $_.SignerCertificate.Subject.Contains("CN=siemens.com")})
|
|
176
|
-
// | Out-String ; if ($certificateInfo) { exit 0 } else { exit 1 }
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
async verifySignature(tempUpdateFile) {
|
|
180
|
-
let publisherName;
|
|
181
|
-
|
|
182
|
-
try {
|
|
183
|
-
publisherName = (await this.configOnDisk.value).publisherName;
|
|
184
|
-
|
|
185
|
-
if (publisherName == null) {
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
} catch (e) {
|
|
189
|
-
if (e.code === "ENOENT") {
|
|
190
|
-
// no app-update.yml
|
|
191
|
-
return null;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
throw e;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return await (0, _windowsExecutableCodeSignatureVerifier().verifySignature)(Array.isArray(publisherName) ? publisherName : [publisherName], tempUpdateFile, this._logger);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
doInstall(options) {
|
|
201
|
-
const args = ["--updated"];
|
|
202
|
-
|
|
203
|
-
if (options.isSilent) {
|
|
204
|
-
args.push("/S");
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (options.isForceRunAfter) {
|
|
208
|
-
args.push("--force-run");
|
|
82
|
+
return await windowsExecutableCodeSignatureVerifier_1.verifySignature(Array.isArray(publisherName) ? publisherName : [publisherName], tempUpdateFile, this._logger);
|
|
209
83
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
84
|
+
doInstall(options) {
|
|
85
|
+
const args = ["--updated"];
|
|
86
|
+
if (options.isSilent) {
|
|
87
|
+
args.push("/S");
|
|
88
|
+
}
|
|
89
|
+
if (options.isForceRunAfter) {
|
|
90
|
+
args.push("--force-run");
|
|
91
|
+
}
|
|
92
|
+
const packagePath = this.downloadedUpdateHelper == null ? null : this.downloadedUpdateHelper.packageFile;
|
|
93
|
+
if (packagePath != null) {
|
|
94
|
+
// only = form is supported
|
|
95
|
+
args.push(`--package-file=${packagePath}`);
|
|
96
|
+
}
|
|
97
|
+
const callUsingElevation = () => {
|
|
98
|
+
_spawn(path.join(process.resourcesPath, "elevate.exe"), [options.installerPath].concat(args)).catch(e => this.dispatchError(e));
|
|
99
|
+
};
|
|
100
|
+
if (options.isAdminRightsRequired) {
|
|
101
|
+
this._logger.info("isAdminRightsRequired is set to true, run installer using elevate.exe");
|
|
102
|
+
callUsingElevation();
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
_spawn(options.installerPath, args).catch((e) => {
|
|
106
|
+
// https://github.com/electron-userland/electron-builder/issues/1129
|
|
107
|
+
// Node 8 sends errors: https://nodejs.org/dist/latest-v8.x/docs/api/errors.html#errors_common_system_errors
|
|
108
|
+
const errorCode = e.code;
|
|
109
|
+
this._logger.info(`Cannot run installer: error code: ${errorCode}, error message: "${e.message}", will be executed again using elevate if EACCES"`);
|
|
110
|
+
if (errorCode === "UNKNOWN" || errorCode === "EACCES") {
|
|
111
|
+
callUsingElevation();
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
this.dispatchError(e);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
return true;
|
|
216
118
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
119
|
+
async differentialDownloadInstaller(fileInfo, downloadUpdateOptions, installerPath, provider) {
|
|
120
|
+
try {
|
|
121
|
+
if (this._testOnlyOptions != null && !this._testOnlyOptions.isUseDifferentialDownload) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
const blockmapFileUrls = util_1.blockmapFiles(fileInfo.url, downloadUpdateOptions.updateInfoAndProvider.info.version, this.app.version);
|
|
125
|
+
this._logger.info(`Download block maps (old: "${blockmapFileUrls[0]}", new: ${blockmapFileUrls[1]})`);
|
|
126
|
+
const downloadBlockMap = async (url) => {
|
|
127
|
+
const data = await this.httpExecutor.downloadToBuffer(url, {
|
|
128
|
+
headers: downloadUpdateOptions.requestHeaders,
|
|
129
|
+
cancellationToken: downloadUpdateOptions.cancellationToken,
|
|
130
|
+
});
|
|
131
|
+
if (data == null || data.length === 0) {
|
|
132
|
+
throw new Error(`Blockmap "${url.href}" is empty`);
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
return JSON.parse(zlib_1.gunzipSync(data).toString());
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
throw new Error(`Cannot parse blockmap "${url.href}", error: ${e}, raw data: ${data}`);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const downloadOptions = {
|
|
142
|
+
newUrl: fileInfo.url,
|
|
143
|
+
oldFile: path.join(this.downloadedUpdateHelper.cacheDir, builder_util_runtime_1.CURRENT_APP_INSTALLER_FILE_NAME),
|
|
144
|
+
logger: this._logger,
|
|
145
|
+
newFile: installerPath,
|
|
146
|
+
isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest,
|
|
147
|
+
requestHeaders: downloadUpdateOptions.requestHeaders,
|
|
148
|
+
cancellationToken: downloadUpdateOptions.cancellationToken,
|
|
149
|
+
};
|
|
150
|
+
if (this.listenerCount(main_1.DOWNLOAD_PROGRESS) > 0) {
|
|
151
|
+
downloadOptions.onProgress = it => this.emit(main_1.DOWNLOAD_PROGRESS, it);
|
|
152
|
+
}
|
|
153
|
+
const blockMapDataList = await Promise.all(blockmapFileUrls.map(u => downloadBlockMap(u)));
|
|
154
|
+
await new GenericDifferentialDownloader_1.GenericDifferentialDownloader(fileInfo.info, this.httpExecutor, downloadOptions).download(blockMapDataList[0], blockMapDataList[1]);
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`);
|
|
159
|
+
if (this._testOnlyOptions != null) {
|
|
160
|
+
// test mode
|
|
161
|
+
throw e;
|
|
162
|
+
}
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
227
165
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
// Node 8 sends errors: https://nodejs.org/dist/latest-v8.x/docs/api/errors.html#errors_common_system_errors
|
|
232
|
-
const errorCode = e.code;
|
|
233
|
-
|
|
234
|
-
this._logger.info(`Cannot run installer: error code: ${errorCode}, error message: "${e.message}", will be executed again using elevate if EACCES"`);
|
|
235
|
-
|
|
236
|
-
if (errorCode === "UNKNOWN" || errorCode === "EACCES") {
|
|
237
|
-
callUsingElevation();
|
|
238
|
-
} else {
|
|
239
|
-
this.dispatchError(e);
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
return true;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
async differentialDownloadInstaller(fileInfo, downloadUpdateOptions, installerPath, provider) {
|
|
247
|
-
try {
|
|
248
|
-
if (this._testOnlyOptions != null && !this._testOnlyOptions.isUseDifferentialDownload) {
|
|
249
|
-
return true;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const newBlockMapUrl = (0, _main().newUrlFromBase)(`${fileInfo.url.pathname}.blockmap`, fileInfo.url);
|
|
253
|
-
const oldBlockMapUrl = (0, _main().newUrlFromBase)(`${fileInfo.url.pathname.replace(new RegExp(downloadUpdateOptions.updateInfoAndProvider.info.version, "g"), this.app.version)}.blockmap`, fileInfo.url);
|
|
254
|
-
|
|
255
|
-
this._logger.info(`Download block maps (old: "${oldBlockMapUrl.href}", new: ${newBlockMapUrl.href})`);
|
|
256
|
-
|
|
257
|
-
const downloadBlockMap = async url => {
|
|
258
|
-
const data = await this.httpExecutor.downloadToBuffer(url, {
|
|
259
|
-
headers: downloadUpdateOptions.requestHeaders,
|
|
260
|
-
cancellationToken: downloadUpdateOptions.cancellationToken
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
if (data == null || data.length === 0) {
|
|
264
|
-
throw new Error(`Blockmap "${url.href}" is empty`);
|
|
166
|
+
async differentialDownloadWebPackage(downloadUpdateOptions, packageInfo, packagePath, provider) {
|
|
167
|
+
if (packageInfo.blockMapSize == null) {
|
|
168
|
+
return true;
|
|
265
169
|
}
|
|
266
|
-
|
|
267
170
|
try {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
171
|
+
const downloadOptions = {
|
|
172
|
+
newUrl: new url_1.URL(packageInfo.path),
|
|
173
|
+
oldFile: path.join(this.downloadedUpdateHelper.cacheDir, builder_util_runtime_1.CURRENT_APP_PACKAGE_FILE_NAME),
|
|
174
|
+
logger: this._logger,
|
|
175
|
+
newFile: packagePath,
|
|
176
|
+
requestHeaders: this.requestHeaders,
|
|
177
|
+
isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest,
|
|
178
|
+
cancellationToken: downloadUpdateOptions.cancellationToken,
|
|
179
|
+
};
|
|
180
|
+
if (this.listenerCount(main_1.DOWNLOAD_PROGRESS) > 0) {
|
|
181
|
+
downloadOptions.onProgress = it => this.emit(main_1.DOWNLOAD_PROGRESS, it);
|
|
182
|
+
}
|
|
183
|
+
await new FileWithEmbeddedBlockMapDifferentialDownloader_1.FileWithEmbeddedBlockMapDifferentialDownloader(packageInfo, this.httpExecutor, downloadOptions).download();
|
|
271
184
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
logger: this._logger,
|
|
279
|
-
newFile: installerPath,
|
|
280
|
-
isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest,
|
|
281
|
-
requestHeaders: downloadUpdateOptions.requestHeaders
|
|
282
|
-
}).download(blockMapDataList[0], blockMapDataList[1]);
|
|
283
|
-
return false;
|
|
284
|
-
} catch (e) {
|
|
285
|
-
this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`);
|
|
286
|
-
|
|
287
|
-
if (this._testOnlyOptions != null) {
|
|
288
|
-
// test mode
|
|
289
|
-
throw e;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
return true;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
async differentialDownloadWebPackage(packageInfo, packagePath, provider) {
|
|
297
|
-
if (packageInfo.blockMapSize == null) {
|
|
298
|
-
return true;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
try {
|
|
302
|
-
await new (_FileWithEmbeddedBlockMapDifferentialDownloader().FileWithEmbeddedBlockMapDifferentialDownloader)(packageInfo, this.httpExecutor, {
|
|
303
|
-
newUrl: new (_url().URL)(packageInfo.path),
|
|
304
|
-
oldFile: path.join(this.downloadedUpdateHelper.cacheDir, _builderUtilRuntime().CURRENT_APP_PACKAGE_FILE_NAME),
|
|
305
|
-
logger: this._logger,
|
|
306
|
-
newFile: packagePath,
|
|
307
|
-
requestHeaders: this.requestHeaders,
|
|
308
|
-
isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest
|
|
309
|
-
}).download();
|
|
310
|
-
} catch (e) {
|
|
311
|
-
this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`); // during test (developer machine mac or linux) we must throw error
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
return process.platform === "win32";
|
|
185
|
+
catch (e) {
|
|
186
|
+
this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`);
|
|
187
|
+
// during test (developer machine mac or linux) we must throw error
|
|
188
|
+
return process.platform === "win32";
|
|
189
|
+
}
|
|
190
|
+
return false;
|
|
315
191
|
}
|
|
316
|
-
|
|
317
|
-
return false;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
192
|
}
|
|
193
|
+
exports.NsisUpdater = NsisUpdater;
|
|
321
194
|
/**
|
|
322
195
|
* This handles both node 8 and node 10 way of emitting error when spawning a process
|
|
323
196
|
* - node 8: Throws the error
|
|
324
197
|
* - node 10: Emit the error(Need to listen with on)
|
|
325
198
|
*/
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
exports.NsisUpdater = NsisUpdater;
|
|
329
|
-
|
|
330
199
|
async function _spawn(exe, args) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}
|
|
350
|
-
// __ts-babel@6.0.4
|
|
200
|
+
return new Promise((resolve, reject) => {
|
|
201
|
+
try {
|
|
202
|
+
const process = child_process_1.spawn(exe, args, {
|
|
203
|
+
detached: true,
|
|
204
|
+
stdio: "ignore",
|
|
205
|
+
});
|
|
206
|
+
process.on("error", error => {
|
|
207
|
+
reject(error);
|
|
208
|
+
});
|
|
209
|
+
process.unref();
|
|
210
|
+
if (process.pid !== undefined) {
|
|
211
|
+
resolve(true);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
reject(error);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
351
219
|
//# sourceMappingURL=NsisUpdater.js.map
|
package/out/NsisUpdater.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/NsisUpdater.ts"],"names":[],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;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sBAAL,CAA8B,QAAxC,EAAkD,mDAAlD,CAF8E;AAGvF,QAAA,MAAM,EAAE,KAAK,OAH0E;AAIvF,QAAA,OAAO,EAAE,WAJ8E;AAKvF,QAAA,cAAc,EAAE,KAAK,cALkE;AAMvF,QAAA,yBAAyB,EAAE,QAAQ,CAAC;AANmD,OAAnF,EAQH,QARG,EAAN;AASD,KAVD,CAWA,OAAO,CAAP,EAAU;AACR,WAAK,OAAL,CAAa,KAAb,CAAmB,8DAA8D,CAAC,CAAC,KAAF,IAAW,CAAC,EAA7F,EADQ,CAER;;;AACA,aAAO,OAAO,CAAC,QAAR,KAAqB,OAA5B;AACD;;AACD,WAAO,KAAP;AACD;;AA5LyC;AA+L5C;;;;;;;;;AAKA,eAAe,MAAf,CAAsB,GAAtB,EAAmC,IAAnC,EAAsD;AACpD,SAAO,IAAI,OAAJ,CAAY,CAAC,OAAD,EAAU,MAAV,KAAoB;AACrC,QAAI;AACF,YAAM,OAAO,GAAG,4BAAM,GAAN,EAAW,IAAX,EAAiB;AAC/B,QAAA,QAAQ,EAAE,IADqB;AAE/B,QAAA,KAAK,EAAE;AAFwB,OAAjB,CAAhB;AAIA,MAAA,OAAO,CAAC,EAAR,CAAW,OAAX,EAAoB,KAAK,IAAG;AAC1B,QAAA,MAAM,CAAC,KAAD,CAAN;AACD,OAFD;AAGA,MAAA,OAAO,CAAC,KAAR;;AAEA,UAAI,OAAO,CAAC,GAAR,KAAgB,SAApB,EAA+B;AAC7B,QAAA,OAAO,CAAC,IAAD,CAAP;AACD;AACF,KAbD,CAcA,OAAO,KAAP,EAAc;AACZ,MAAA,MAAM,CAAC,KAAD,CAAN;AACD;AACF,GAlBM,CAAP;AAmBD,C","sourcesContent":["import { AllPublishOptions, newError, PackageFileInfo, BlockMap, CURRENT_APP_PACKAGE_FILE_NAME, CURRENT_APP_INSTALLER_FILE_NAME } from \"builder-util-runtime\"\nimport { spawn } from \"child_process\"\nimport * as path from \"path\"\nimport { AppAdapter } from \"./AppAdapter\"\nimport { DownloadUpdateOptions } from \"./AppUpdater\"\nimport { BaseUpdater, InstallOptions } from \"./BaseUpdater\"\nimport { FileWithEmbeddedBlockMapDifferentialDownloader } from \"./differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader\"\nimport { GenericDifferentialDownloader } from \"./differentialDownloader/GenericDifferentialDownloader\"\nimport { newUrlFromBase, ResolvedUpdateFileInfo } from \"./main\"\nimport { findFile, Provider } from \"./providers/Provider\"\nimport { unlink } from \"fs-extra\"\nimport { verifySignature } from \"./windowsExecutableCodeSignatureVerifier\"\nimport { URL } from \"url\"\nimport { gunzipSync } from \"zlib\"\n\nexport class NsisUpdater extends BaseUpdater {\n constructor(options?: AllPublishOptions | null, app?: AppAdapter) {\n super(options, app)\n }\n\n /*** @private */\n protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>> {\n const provider = downloadUpdateOptions.updateInfoAndProvider.provider\n const fileInfo = findFile(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), \"exe\")!!\n return this.executeDownload({\n fileExtension: \"exe\",\n downloadUpdateOptions,\n fileInfo,\n task: async (destinationFile, downloadOptions, packageFile, removeTempDirIfAny) => {\n const packageInfo = fileInfo.packageInfo\n const isWebInstaller = packageInfo != null && packageFile != null\n if (isWebInstaller || await this.differentialDownloadInstaller(fileInfo, downloadUpdateOptions, destinationFile, provider)) {\n await this.httpExecutor.download(fileInfo.url, destinationFile, downloadOptions)\n }\n\n const signatureVerificationStatus = await this.verifySignature(destinationFile)\n if (signatureVerificationStatus != null) {\n await removeTempDirIfAny()\n // noinspection ThrowInsideFinallyBlockJS\n throw newError(`New version ${downloadUpdateOptions.updateInfoAndProvider.info.version} is not signed by the application owner: ${signatureVerificationStatus}`, \"ERR_UPDATER_INVALID_SIGNATURE\")\n }\n\n if (isWebInstaller) {\n if (await this.differentialDownloadWebPackage(packageInfo!!, packageFile!!, provider)) {\n try {\n await this.httpExecutor.download(new URL(packageInfo!!.path), packageFile!!, {\n headers: downloadUpdateOptions.requestHeaders,\n cancellationToken: downloadUpdateOptions.cancellationToken,\n sha512: packageInfo!!.sha512,\n })\n }\n catch (e) {\n try {\n await unlink(packageFile!!)\n }\n catch (ignored) {\n // ignore\n }\n\n throw e\n }\n }\n }\n },\n })\n }\n\n // $certificateInfo = (Get-AuthenticodeSignature 'xxx\\yyy.exe'\n // | where {$_.Status.Equals([System.Management.Automation.SignatureStatus]::Valid) -and $_.SignerCertificate.Subject.Contains(\"CN=siemens.com\")})\n // | Out-String ; if ($certificateInfo) { exit 0 } else { exit 1 }\n private async verifySignature(tempUpdateFile: string): Promise<string | null> {\n let publisherName: Array<string> | string | null\n try {\n publisherName = (await this.configOnDisk.value).publisherName\n if (publisherName == null) {\n return null\n }\n }\n catch (e) {\n if (e.code === \"ENOENT\") {\n // no app-update.yml\n return null\n }\n throw e\n }\n return await verifySignature(Array.isArray(publisherName) ? publisherName : [publisherName], tempUpdateFile, this._logger)\n }\n\n protected doInstall(options: InstallOptions): boolean {\n const args = [\"--updated\"]\n if (options.isSilent) {\n args.push(\"/S\")\n }\n\n if (options.isForceRunAfter) {\n args.push(\"--force-run\")\n }\n\n const packagePath = this.downloadedUpdateHelper == null ? null : this.downloadedUpdateHelper.packageFile\n if (packagePath != null) {\n // only = form is supported\n args.push(`--package-file=${packagePath}`)\n }\n\n const callUsingElevation = (): void => {\n _spawn(path.join(process.resourcesPath!!, \"elevate.exe\"), [options.installerPath].concat(args))\n .catch(e => this.dispatchError(e))\n }\n\n if (options.isAdminRightsRequired) {\n this._logger.info(\"isAdminRightsRequired is set to true, run installer using elevate.exe\")\n callUsingElevation()\n return true\n }\n\n _spawn(options.installerPath, args)\n .catch((e: Error) => {\n // https://github.com/electron-userland/electron-builder/issues/1129\n // Node 8 sends errors: https://nodejs.org/dist/latest-v8.x/docs/api/errors.html#errors_common_system_errors\n const errorCode = (e as NodeJS.ErrnoException).code\n this._logger.info(`Cannot run installer: error code: ${errorCode}, error message: \"${e.message}\", will be executed again using elevate if EACCES\"`)\n if (errorCode === \"UNKNOWN\" || errorCode === \"EACCES\") {\n callUsingElevation()\n }\n else {\n this.dispatchError(e)\n }\n })\n return true\n }\n\n private async differentialDownloadInstaller(fileInfo: ResolvedUpdateFileInfo, downloadUpdateOptions: DownloadUpdateOptions, installerPath: string, provider: Provider<any>): Promise<boolean> {\n try {\n if (this._testOnlyOptions != null && !this._testOnlyOptions.isUseDifferentialDownload) {\n return true\n }\n\n const newBlockMapUrl = newUrlFromBase(`${fileInfo.url.pathname}.blockmap`, fileInfo.url)\n const oldBlockMapUrl = newUrlFromBase(`${fileInfo.url.pathname.replace(new RegExp(downloadUpdateOptions.updateInfoAndProvider.info.version, \"g\"), this.app.version)}.blockmap`, fileInfo.url)\n this._logger.info(`Download block maps (old: \"${oldBlockMapUrl.href}\", new: ${newBlockMapUrl.href})`)\n\n const downloadBlockMap = async (url: URL): Promise<BlockMap> => {\n const data = await this.httpExecutor.downloadToBuffer(url, {\n headers: downloadUpdateOptions.requestHeaders,\n cancellationToken: downloadUpdateOptions.cancellationToken,\n })\n\n if (data == null || data.length === 0) {\n throw new Error(`Blockmap \"${url.href}\" is empty`)\n }\n\n try {\n return JSON.parse(gunzipSync(data).toString())\n }\n catch (e) {\n throw new Error(`Cannot parse blockmap \"${url.href}\", error: ${e}, raw data: ${data}`)\n }\n }\n\n const blockMapDataList = await Promise.all([downloadBlockMap(oldBlockMapUrl), downloadBlockMap(newBlockMapUrl)])\n await new GenericDifferentialDownloader(fileInfo.info, this.httpExecutor, {\n newUrl: fileInfo.url,\n oldFile: path.join(this.downloadedUpdateHelper!!.cacheDir, CURRENT_APP_INSTALLER_FILE_NAME),\n logger: this._logger,\n newFile: installerPath,\n isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest,\n requestHeaders: downloadUpdateOptions.requestHeaders,\n })\n .download(blockMapDataList[0], blockMapDataList[1])\n return false\n }\n catch (e) {\n this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`)\n if (this._testOnlyOptions != null) {\n // test mode\n throw e\n }\n return true\n }\n }\n\n private async differentialDownloadWebPackage(packageInfo: PackageFileInfo, packagePath: string, provider: Provider<any>): Promise<boolean> {\n if (packageInfo.blockMapSize == null) {\n return true\n }\n\n try {\n await new FileWithEmbeddedBlockMapDifferentialDownloader(packageInfo, this.httpExecutor, {\n newUrl: new URL(packageInfo.path),\n oldFile: path.join(this.downloadedUpdateHelper!!.cacheDir, CURRENT_APP_PACKAGE_FILE_NAME),\n logger: this._logger,\n newFile: packagePath,\n requestHeaders: this.requestHeaders,\n isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest,\n })\n .download()\n }\n catch (e) {\n this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`)\n // during test (developer machine mac or linux) we must throw error\n return process.platform === \"win32\"\n }\n return false\n }\n}\n\n/**\n * This handles both node 8 and node 10 way of emitting error when spawning a process\n * - node 8: Throws the error\n * - node 10: Emit the error(Need to listen with on)\n */\nasync function _spawn(exe: string, args: Array<string>): Promise<any> {\n return new Promise((resolve, reject) => {\n try {\n const process = spawn(exe, args, {\n detached: true,\n stdio: \"ignore\",\n })\n process.on(\"error\", error => {\n reject(error)\n })\n process.unref()\n\n if (process.pid !== undefined) {\n resolve(true)\n }\n }\n catch (error) {\n reject(error)\n }\n })\n}\n"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"NsisUpdater.js","sourceRoot":"","sources":["../src/NsisUpdater.ts"],"names":[],"mappings":";;;AAAA,+DAA6J;AAC7J,iDAAqC;AACrC,6BAA4B;AAG5B,+CAA2D;AAE3D,4IAAwI;AACxI,0GAAsG;AACtG,iCAAkE;AAClE,iCAAsC;AACtC,mDAAyD;AACzD,uCAAiC;AACjC,qGAA0E;AAC1E,6BAAyB;AACzB,+BAAiC;AAEjC,MAAa,WAAY,SAAQ,yBAAW;IAC1C,YAAY,OAAkC,EAAE,GAAgB;QAC9D,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;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AG,qBAAK,CAAC,GAAG,EAAE,IAAI,EAAE;gBAC/B,QAAQ,EAAE,IAAI;gBACd,KAAK,EAAE,QAAQ;aAChB,CAAC,CAAA;YACF,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE;gBAC1B,MAAM,CAAC,KAAK,CAAC,CAAA;YACf,CAAC,CAAC,CAAA;YACF,OAAO,CAAC,KAAK,EAAE,CAAA;YAEf,IAAI,OAAO,CAAC,GAAG,KAAK,SAAS,EAAE;gBAC7B,OAAO,CAAC,IAAI,CAAC,CAAA;aACd;SACF;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,CAAC,KAAK,CAAC,CAAA;SACd;IACH,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { AllPublishOptions, newError, PackageFileInfo, BlockMap, CURRENT_APP_PACKAGE_FILE_NAME, CURRENT_APP_INSTALLER_FILE_NAME } from \"builder-util-runtime\"\nimport { spawn } from \"child_process\"\nimport * as path from \"path\"\nimport { AppAdapter } from \"./AppAdapter\"\nimport { DownloadUpdateOptions } from \"./AppUpdater\"\nimport { BaseUpdater, InstallOptions } from \"./BaseUpdater\"\nimport { DifferentialDownloaderOptions } from \"./differentialDownloader/DifferentialDownloader\"\nimport { FileWithEmbeddedBlockMapDifferentialDownloader } from \"./differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader\"\nimport { GenericDifferentialDownloader } from \"./differentialDownloader/GenericDifferentialDownloader\"\nimport { DOWNLOAD_PROGRESS, ResolvedUpdateFileInfo } from \"./main\"\nimport { blockmapFiles } from \"./util\"\nimport { findFile, Provider } from \"./providers/Provider\"\nimport { unlink } from \"fs-extra\"\nimport { verifySignature } from \"./windowsExecutableCodeSignatureVerifier\"\nimport { URL } from \"url\"\nimport { gunzipSync } from \"zlib\"\n\nexport class NsisUpdater extends BaseUpdater {\n constructor(options?: AllPublishOptions | null, app?: AppAdapter) {\n super(options, app)\n }\n\n /*** @private */\n protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>> {\n const provider = downloadUpdateOptions.updateInfoAndProvider.provider\n const fileInfo = findFile(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), \"exe\")!\n return this.executeDownload({\n fileExtension: \"exe\",\n downloadUpdateOptions,\n fileInfo,\n task: async (destinationFile, downloadOptions, packageFile, removeTempDirIfAny) => {\n const packageInfo = fileInfo.packageInfo\n const isWebInstaller = packageInfo != null && packageFile != null\n if (isWebInstaller || (await this.differentialDownloadInstaller(fileInfo, downloadUpdateOptions, destinationFile, provider))) {\n await this.httpExecutor.download(fileInfo.url, destinationFile, downloadOptions)\n }\n\n const signatureVerificationStatus = await this.verifySignature(destinationFile)\n if (signatureVerificationStatus != null) {\n await removeTempDirIfAny()\n // noinspection ThrowInsideFinallyBlockJS\n throw newError(\n `New version ${downloadUpdateOptions.updateInfoAndProvider.info.version} is not signed by the application owner: ${signatureVerificationStatus}`,\n \"ERR_UPDATER_INVALID_SIGNATURE\"\n )\n }\n\n if (isWebInstaller) {\n if (await this.differentialDownloadWebPackage(downloadUpdateOptions, packageInfo!, packageFile!, provider)) {\n try {\n await this.httpExecutor.download(new URL(packageInfo!.path), packageFile!, {\n headers: downloadUpdateOptions.requestHeaders,\n cancellationToken: downloadUpdateOptions.cancellationToken,\n sha512: packageInfo!.sha512,\n })\n } catch (e) {\n try {\n await unlink(packageFile!)\n } catch (ignored) {\n // ignore\n }\n\n throw e\n }\n }\n }\n },\n })\n }\n\n // $certificateInfo = (Get-AuthenticodeSignature 'xxx\\yyy.exe'\n // | where {$_.Status.Equals([System.Management.Automation.SignatureStatus]::Valid) -and $_.SignerCertificate.Subject.Contains(\"CN=siemens.com\")})\n // | Out-String ; if ($certificateInfo) { exit 0 } else { exit 1 }\n private async verifySignature(tempUpdateFile: string): Promise<string | null> {\n let publisherName: Array<string> | string | null\n try {\n publisherName = (await this.configOnDisk.value).publisherName\n if (publisherName == null) {\n return null\n }\n } catch (e) {\n if (e.code === \"ENOENT\") {\n // no app-update.yml\n return null\n }\n throw e\n }\n return await verifySignature(Array.isArray(publisherName) ? publisherName : [publisherName], tempUpdateFile, this._logger)\n }\n\n protected doInstall(options: InstallOptions): boolean {\n const args = [\"--updated\"]\n if (options.isSilent) {\n args.push(\"/S\")\n }\n\n if (options.isForceRunAfter) {\n args.push(\"--force-run\")\n }\n\n const packagePath = this.downloadedUpdateHelper == null ? null : this.downloadedUpdateHelper.packageFile\n if (packagePath != null) {\n // only = form is supported\n args.push(`--package-file=${packagePath}`)\n }\n\n const callUsingElevation = (): void => {\n _spawn(path.join(process.resourcesPath!, \"elevate.exe\"), [options.installerPath].concat(args)).catch(e => this.dispatchError(e))\n }\n\n if (options.isAdminRightsRequired) {\n this._logger.info(\"isAdminRightsRequired is set to true, run installer using elevate.exe\")\n callUsingElevation()\n return true\n }\n\n _spawn(options.installerPath, args).catch((e: Error) => {\n // https://github.com/electron-userland/electron-builder/issues/1129\n // Node 8 sends errors: https://nodejs.org/dist/latest-v8.x/docs/api/errors.html#errors_common_system_errors\n const errorCode = (e as NodeJS.ErrnoException).code\n this._logger.info(`Cannot run installer: error code: ${errorCode}, error message: \"${e.message}\", will be executed again using elevate if EACCES\"`)\n if (errorCode === \"UNKNOWN\" || errorCode === \"EACCES\") {\n callUsingElevation()\n } else {\n this.dispatchError(e)\n }\n })\n return true\n }\n\n private async differentialDownloadInstaller(\n fileInfo: ResolvedUpdateFileInfo,\n downloadUpdateOptions: DownloadUpdateOptions,\n installerPath: string,\n provider: Provider<any>\n ): Promise<boolean> {\n try {\n if (this._testOnlyOptions != null && !this._testOnlyOptions.isUseDifferentialDownload) {\n return true\n }\n const blockmapFileUrls = blockmapFiles(fileInfo.url, downloadUpdateOptions.updateInfoAndProvider.info.version, this.app.version)\n this._logger.info(`Download block maps (old: \"${blockmapFileUrls[0]}\", new: ${blockmapFileUrls[1]})`)\n\n const downloadBlockMap = async (url: URL): Promise<BlockMap> => {\n const data = await this.httpExecutor.downloadToBuffer(url, {\n headers: downloadUpdateOptions.requestHeaders,\n cancellationToken: downloadUpdateOptions.cancellationToken,\n })\n\n if (data == null || data.length === 0) {\n throw new Error(`Blockmap \"${url.href}\" is empty`)\n }\n\n try {\n return JSON.parse(gunzipSync(data).toString())\n } catch (e) {\n throw new Error(`Cannot parse blockmap \"${url.href}\", error: ${e}, raw data: ${data}`)\n }\n }\n\n const downloadOptions: DifferentialDownloaderOptions = {\n newUrl: fileInfo.url,\n oldFile: path.join(this.downloadedUpdateHelper!.cacheDir, CURRENT_APP_INSTALLER_FILE_NAME),\n logger: this._logger,\n newFile: installerPath,\n isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest,\n requestHeaders: downloadUpdateOptions.requestHeaders,\n cancellationToken: downloadUpdateOptions.cancellationToken,\n }\n\n if (this.listenerCount(DOWNLOAD_PROGRESS) > 0) {\n downloadOptions.onProgress = it => this.emit(DOWNLOAD_PROGRESS, it)\n }\n\n const blockMapDataList = await Promise.all(blockmapFileUrls.map(u => downloadBlockMap(u)))\n await new GenericDifferentialDownloader(fileInfo.info, this.httpExecutor, downloadOptions).download(blockMapDataList[0], blockMapDataList[1])\n return false\n } catch (e) {\n this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`)\n if (this._testOnlyOptions != null) {\n // test mode\n throw e\n }\n return true\n }\n }\n\n private async differentialDownloadWebPackage(\n downloadUpdateOptions: DownloadUpdateOptions,\n packageInfo: PackageFileInfo,\n packagePath: string,\n provider: Provider<any>\n ): Promise<boolean> {\n if (packageInfo.blockMapSize == null) {\n return true\n }\n\n try {\n const downloadOptions: DifferentialDownloaderOptions = {\n newUrl: new URL(packageInfo.path),\n oldFile: path.join(this.downloadedUpdateHelper!.cacheDir, CURRENT_APP_PACKAGE_FILE_NAME),\n logger: this._logger,\n newFile: packagePath,\n requestHeaders: this.requestHeaders,\n isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest,\n cancellationToken: downloadUpdateOptions.cancellationToken,\n }\n\n if (this.listenerCount(DOWNLOAD_PROGRESS) > 0) {\n downloadOptions.onProgress = it => this.emit(DOWNLOAD_PROGRESS, it)\n }\n\n await new FileWithEmbeddedBlockMapDifferentialDownloader(packageInfo, this.httpExecutor, downloadOptions).download()\n } catch (e) {\n this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`)\n // during test (developer machine mac or linux) we must throw error\n return process.platform === \"win32\"\n }\n return false\n }\n}\n\n/**\n * This handles both node 8 and node 10 way of emitting error when spawning a process\n * - node 8: Throws the error\n * - node 10: Emit the error(Need to listen with on)\n */\nasync function _spawn(exe: string, args: Array<string>): Promise<any> {\n return new Promise((resolve, reject) => {\n try {\n const process = spawn(exe, args, {\n detached: true,\n stdio: \"ignore\",\n })\n process.on(\"error\", error => {\n reject(error)\n })\n process.unref()\n\n if (process.pid !== undefined) {\n resolve(true)\n }\n } catch (error) {\n reject(error)\n }\n })\n}\n"]}
|