-
Notifications
You must be signed in to change notification settings - Fork 18
/
winPackager-fixed.js
262 lines (230 loc) · 9.8 KB
/
winPackager-fixed.js
1
2
3
4
5
6
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.WinPackager = undefined;
var _bluebirdLstC;
function _load_bluebirdLstC() {
return _bluebirdLstC = require("bluebird-lst-c");
}
var _bluebirdLstC2;
function _load_bluebirdLstC2() {
return _bluebirdLstC2 = _interopRequireDefault(require("bluebird-lst-c"));
}
let checkIcon = (() => {
var _ref = (0, (_bluebirdLstC || _load_bluebirdLstC()).coroutine)(function* (file) {
const fd = yield (0, (_fsExtraP || _load_fsExtraP()).open)(file, "r");
const buffer = new Buffer(512);
try {
yield (0, (_fsExtraP || _load_fsExtraP()).read)(fd, buffer, 0, buffer.length, 0);
} finally {
yield (0, (_fsExtraP || _load_fsExtraP()).close)(fd);
}
if (!isIco(buffer)) {
throw new Error(`Windows icon is not valid ico file, please fix "${ file }"`);
}
const sizes = parseIco(buffer);
for (const size of sizes) {
if (size.w >= 256 && size.h >= 256) {
return;
}
}
throw new Error(`Windows icon size must be at least 256x256, please fix "${ file }"`);
});
return function checkIcon(_x) {
return _ref.apply(this, arguments);
};
})();
var _codeSign;
function _load_codeSign() {
return _codeSign = require("./codeSign");
}
var _platformPackager;
function _load_platformPackager() {
return _platformPackager = require("./platformPackager");
}
var _metadata;
function _load_metadata() {
return _metadata = require("./metadata");
}
var _path = _interopRequireWildcard(require("path"));
var _log;
function _load_log() {
return _log = require("./util/log");
}
var _util;
function _load_util() {
return _util = require("./util/util");
}
var _fsExtraP;
function _load_fsExtraP() {
return _fsExtraP = require("fs-extra-p");
}
var _windowsCodeSign;
function _load_windowsCodeSign() {
return _windowsCodeSign = require("./windowsCodeSign");
}
var _targetFactory;
function _load_targetFactory() {
return _targetFactory = require("./targets/targetFactory");
}
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)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class WinPackager extends (_platformPackager || _load_platformPackager()).PlatformPackager {
constructor(info) {
super(info);
const subjectName = this.platformSpecificBuildOptions.certificateSubjectName;
if (subjectName == null) {
const certificateFile = this.platformSpecificBuildOptions.certificateFile;
if (certificateFile != null) {
const certificatePassword = this.getCscPassword();
this.cscInfo = (_bluebirdLstC2 || _load_bluebirdLstC2()).default.resolve({
file: certificateFile,
password: certificatePassword == null ? null : certificatePassword.trim()
});
} else {
const cscLink = process.env.WIN_CSC_LINK || this.options.cscLink;
if (cscLink != null) {
this.cscInfo = (0, (_codeSign || _load_codeSign()).downloadCertificate)(cscLink, info.tempDirManager).then(path => {
return {
file: path,
password: this.getCscPassword()
};
});
} else {
this.cscInfo = (_bluebirdLstC2 || _load_bluebirdLstC2()).default.resolve(null);
}
}
} else {
this.cscInfo = (_bluebirdLstC2 || _load_bluebirdLstC2()).default.resolve({
subjectName: subjectName
});
}
}
get defaultTarget() {
return ["nsis"];
}
doGetCscPassword() {
return this.platformSpecificBuildOptions.certificatePassword || process.env.WIN_CSC_KEY_PASSWORD || super.doGetCscPassword();
}
createTargets(targets, mapper, cleanupTasks) {
for (const name of targets) {
if (name === (_targetFactory || _load_targetFactory()).DIR_TARGET) {
continue;
}
const targetClass = (() => {
switch (name) {
case "nsis":
return require("./targets/nsis").default;
case "squirrel":
return require("./targets/squirrelWindows").default;
case "appx":
return require("./targets/appx").default;
default:
return null;
}
})();
mapper(name, outDir => targetClass === null ? (0, (_targetFactory || _load_targetFactory()).createCommonTarget)(name, outDir, this) : new targetClass(this, outDir));
}
}
get platform() {
return (_metadata || _load_metadata()).Platform.WINDOWS;
}
getIconPath() {
if (this.iconPath == null) {
this.iconPath = this.getValidIconPath();
}
return this.iconPath;
}
getValidIconPath() {
var _this = this;
return (0, (_bluebirdLstC || _load_bluebirdLstC()).coroutine)(function* () {
let iconPath = _this.platformSpecificBuildOptions.icon || _this.config.icon;
if (iconPath != null && !iconPath.endsWith(".ico")) {
iconPath += ".ico";
}
iconPath = iconPath == null ? yield _this.getDefaultIcon("ico") : _path.resolve(_this.projectDir, iconPath);
if (iconPath == null) {
return null;
}
yield checkIcon(iconPath);
return iconPath;
})();
}
sign(file) {
var _this2 = this;
return (0, (_bluebirdLstC || _load_bluebirdLstC()).coroutine)(function* () {
const cscInfo = yield _this2.cscInfo;
if (cscInfo == null) {
const forceCodeSigningPlatform = _this2.platformSpecificBuildOptions.forceCodeSigning;
if (forceCodeSigningPlatform == null ? _this2.config.forceCodeSigning : forceCodeSigningPlatform) {
throw new Error(`App is not signed and "forceCodeSigning" is set to true, please ensure that code signing configuration is correct, please see https://github.com/electron-userland/electron-builder/wiki/Code-Signing`);
}
return;
}
(0, (_log || _load_log()).log)(`Signing ${ _path.basename(file) } (certificate file "${ cscInfo.file }")`);
yield _this2.doSign({
path: file,
cert: cscInfo.file,
subjectName: cscInfo.subjectName,
password: cscInfo.password,
name: _this2.appInfo.productName,
site: yield _this2.appInfo.computePackageUrl(),
options: _this2.platformSpecificBuildOptions
});
})();
}
//noinspection JSMethodCanBeStatic
doSign(options) {
return (0, (_windowsCodeSign || _load_windowsCodeSign()).sign)(options);
}
signAndEditResources(file) {
var _this3 = this;
return (0, (_bluebirdLstC || _load_bluebirdLstC()).coroutine)(function* () {
const appInfo = _this3.appInfo;
var originalFilename = appInfo.metadata.build.originalFilename;
console.log("originalFilename:"+originalFilename);
const args = [file, "--set-version-string", "CompanyName", appInfo.companyName, "--set-version-string", "FileDescription", appInfo.productName, "--set-version-string", "ProductName", appInfo.productName, "--set-version-string", "InternalName", _path.basename(appInfo.productFilename, ".exe"), "--set-version-string", "LegalCopyright", appInfo.copyright, "--set-version-string", "OriginalFilename", originalFilename, "--set-file-version", appInfo.buildVersion, "--set-product-version", appInfo.version];
(0, (_util || _load_util()).use)(_this3.platformSpecificBuildOptions.legalTrademarks, function (it) {
return args.push("--set-version-string", "LegalTrademarks", it);
});
(0, (_util || _load_util()).use)((yield _this3.getIconPath()), function (it) {
return args.push("--set-icon", it);
});
const rceditExecutable = _path.join((yield (0, (_windowsCodeSign || _load_windowsCodeSign()).getSignVendorPath)()), "rcedit.exe");
const isWin = process.platform === "win32";
if (!isWin) {
args.unshift(rceditExecutable);
}
yield (0, (_util || _load_util()).exec)(isWin ? rceditExecutable : "wine", args);
yield _this3.sign(file);
})();
}
postInitApp(appOutDir) {
var _this4 = this;
return (0, (_bluebirdLstC || _load_bluebirdLstC()).coroutine)(function* () {
const executable = _path.join(appOutDir, `${ _this4.appInfo.productFilename }.exe`);
yield (0, (_fsExtraP || _load_fsExtraP()).rename)(_path.join(appOutDir, "electron.exe"), executable);
yield _this4.signAndEditResources(executable);
})();
}
}
exports.WinPackager = WinPackager;
function parseIco(buffer) {
if (!isIco(buffer)) {
throw new Error("buffer is not ico");
}
const n = buffer.readUInt16LE(4);
const result = new Array(n);
for (let i = 0; i < n; i++) {
result[i] = {
w: buffer.readUInt8(6 + i * 16) || 256,
h: buffer.readUInt8(7 + i * 16) || 256
};
}
return result;
}
function isIco(buffer) {
return buffer.readUInt16LE(0) === 0 && buffer.readUInt16LE(2) === 1;
}
//# sourceMappingURL=winPackager.js.map