author | herrick |
Thu, 06 Jun 2019 19:51:17 -0400 | |
branch | JDK-8200758-branch |
changeset 57396 | 3944e4c2f779 |
parent 57391 | 970f28090a06 |
child 57397 | 89549ecec1c7 |
permissions | -rw-r--r-- |
57038 | 1 |
/* |
57106
ea870b9ce89a
8216492: Update copyright of all new jpackage fils to 2019
kcr
parents:
57103
diff
changeset
|
2 |
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. |
57038 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
57039 | 26 |
package jdk.jpackage.internal; |
57038 | 27 |
|
28 |
import java.io.*; |
|
29 |
import java.nio.charset.Charset; |
|
30 |
import java.nio.file.Files; |
|
31 |
import java.text.MessageFormat; |
|
32 |
import java.util.*; |
|
33 |
import java.util.regex.Pattern; |
|
34 |
||
57039 | 35 |
import static jdk.jpackage.internal.WindowsBundlerParam.*; |
57038 | 36 |
|
37 |
public class WinMsiBundler extends AbstractBundler { |
|
38 |
||
57059 | 39 |
private static final ResourceBundle I18N = ResourceBundle.getBundle( |
40 |
"jdk.jpackage.internal.resources.WinResources"); |
|
57038 | 41 |
|
42 |
public static final BundlerParamInfo<WinAppBundler> APP_BUNDLER = |
|
43 |
new WindowsBundlerParam<>( |
|
44 |
"win.app.bundler", |
|
45 |
WinAppBundler.class, |
|
46 |
params -> new WinAppBundler(), |
|
47 |
null); |
|
48 |
||
49 |
public static final BundlerParamInfo<Boolean> CAN_USE_WIX36 = |
|
50 |
new WindowsBundlerParam<>( |
|
51 |
"win.msi.canUseWix36", |
|
52 |
Boolean.class, |
|
53 |
params -> false, |
|
54 |
(s, p) -> Boolean.valueOf(s)); |
|
55 |
||
56 |
public static final BundlerParamInfo<File> MSI_IMAGE_DIR = |
|
57 |
new WindowsBundlerParam<>( |
|
58 |
"win.msi.imageDir", |
|
59 |
File.class, |
|
60 |
params -> { |
|
61 |
File imagesRoot = IMAGES_ROOT.fetchFrom(params); |
|
62 |
if (!imagesRoot.exists()) imagesRoot.mkdirs(); |
|
63 |
return new File(imagesRoot, "win-msi.image"); |
|
64 |
}, |
|
65 |
(s, p) -> null); |
|
66 |
||
67 |
public static final BundlerParamInfo<File> WIN_APP_IMAGE = |
|
68 |
new WindowsBundlerParam<>( |
|
69 |
"win.app.image", |
|
70 |
File.class, |
|
71 |
null, |
|
72 |
(s, p) -> null); |
|
73 |
||
74 |
public static final StandardBundlerParam<Boolean> MSI_SYSTEM_WIDE = |
|
75 |
new StandardBundlerParam<>( |
|
76 |
Arguments.CLIOptions.WIN_PER_USER_INSTALLATION.getId(), |
|
77 |
Boolean.class, |
|
78 |
params -> true, // MSIs default to system wide |
|
79 |
// valueOf(null) is false, |
|
80 |
// and we actually do want null |
|
81 |
(s, p) -> (s == null || "null".equalsIgnoreCase(s))? null |
|
82 |
: Boolean.valueOf(s) |
|
83 |
); |
|
84 |
||
85 |
||
86 |
public static final StandardBundlerParam<String> PRODUCT_VERSION = |
|
87 |
new StandardBundlerParam<>( |
|
88 |
"win.msi.productVersion", |
|
89 |
String.class, |
|
90 |
VERSION::fetchFrom, |
|
91 |
(s, p) -> s |
|
92 |
); |
|
93 |
||
94 |
public static final BundlerParamInfo<UUID> UPGRADE_UUID = |
|
95 |
new WindowsBundlerParam<>( |
|
57062
044e7a644ee3
8214575: Exe installers will install application to already existing instalation
herrick
parents:
57059
diff
changeset
|
96 |
Arguments.CLIOptions.WIN_UPGRADE_UUID.getId(), |
57038 | 97 |
UUID.class, |
57062
044e7a644ee3
8214575: Exe installers will install application to already existing instalation
herrick
parents:
57059
diff
changeset
|
98 |
params -> UUID.randomUUID(), |
57038 | 99 |
(s, p) -> UUID.fromString(s)); |
100 |
||
101 |
private static final String TOOL_CANDLE = "candle.exe"; |
|
102 |
private static final String TOOL_LIGHT = "light.exe"; |
|
103 |
// autodetect just v3.7, v3.8, 3.9, 3.10 and 3.11 |
|
104 |
private static final String AUTODETECT_DIRS = |
|
105 |
";C:\\Program Files (x86)\\WiX Toolset v3.11\\bin;" |
|
106 |
+ "C:\\Program Files\\WiX Toolset v3.11\\bin;" |
|
107 |
+ "C:\\Program Files (x86)\\WiX Toolset v3.10\\bin;" |
|
108 |
+ "C:\\Program Files\\WiX Toolset v3.10\\bin;" |
|
109 |
+ "C:\\Program Files (x86)\\WiX Toolset v3.9\\bin;" |
|
110 |
+ "C:\\Program Files\\WiX Toolset v3.9\\bin;" |
|
111 |
+ "C:\\Program Files (x86)\\WiX Toolset v3.8\\bin;" |
|
112 |
+ "C:\\Program Files\\WiX Toolset v3.8\\bin;" |
|
113 |
+ "C:\\Program Files (x86)\\WiX Toolset v3.7\\bin;" |
|
114 |
+ "C:\\Program Files\\WiX Toolset v3.7\\bin"; |
|
115 |
||
116 |
public static final BundlerParamInfo<String> TOOL_CANDLE_EXECUTABLE = |
|
117 |
new WindowsBundlerParam<>( |
|
118 |
"win.msi.candle.exe", |
|
119 |
String.class, |
|
120 |
params -> { |
|
121 |
for (String dirString : (System.getenv("PATH") + |
|
122 |
AUTODETECT_DIRS).split(";")) { |
|
123 |
File f = new File(dirString.replace("\"", ""), TOOL_CANDLE); |
|
124 |
if (f.isFile()) { |
|
125 |
return f.toString(); |
|
126 |
} |
|
127 |
} |
|
128 |
return null; |
|
129 |
}, |
|
130 |
null); |
|
131 |
||
132 |
public static final BundlerParamInfo<String> TOOL_LIGHT_EXECUTABLE = |
|
133 |
new WindowsBundlerParam<>( |
|
134 |
"win.msi.light.exe", |
|
135 |
String.class, |
|
136 |
params -> { |
|
137 |
for (String dirString : (System.getenv("PATH") + |
|
138 |
AUTODETECT_DIRS).split(";")) { |
|
139 |
File f = new File(dirString.replace("\"", ""), TOOL_LIGHT); |
|
140 |
if (f.isFile()) { |
|
141 |
return f.toString(); |
|
142 |
} |
|
143 |
} |
|
144 |
return null; |
|
145 |
}, |
|
146 |
null); |
|
147 |
||
148 |
public static final StandardBundlerParam<Boolean> MENU_HINT = |
|
149 |
new WindowsBundlerParam<>( |
|
150 |
Arguments.CLIOptions.WIN_MENU_HINT.getId(), |
|
151 |
Boolean.class, |
|
152 |
params -> false, |
|
153 |
// valueOf(null) is false, |
|
154 |
// and we actually do want null in some cases |
|
155 |
(s, p) -> (s == null || |
|
156 |
"null".equalsIgnoreCase(s))? true : Boolean.valueOf(s) |
|
157 |
); |
|
158 |
||
159 |
public static final StandardBundlerParam<Boolean> SHORTCUT_HINT = |
|
160 |
new WindowsBundlerParam<>( |
|
161 |
Arguments.CLIOptions.WIN_SHORTCUT_HINT.getId(), |
|
162 |
Boolean.class, |
|
163 |
params -> false, |
|
164 |
// valueOf(null) is false, |
|
165 |
// and we actually do want null in some cases |
|
166 |
(s, p) -> (s == null || |
|
167 |
"null".equalsIgnoreCase(s))? false : Boolean.valueOf(s) |
|
168 |
); |
|
169 |
||
170 |
@Override |
|
171 |
public String getName() { |
|
57059 | 172 |
return I18N.getString("msi.bundler.name"); |
57038 | 173 |
} |
174 |
||
175 |
@Override |
|
176 |
public String getDescription() { |
|
57059 | 177 |
return I18N.getString("msi.bundler.description"); |
57038 | 178 |
} |
179 |
||
180 |
@Override |
|
181 |
public String getID() { |
|
182 |
return "msi"; |
|
183 |
} |
|
184 |
||
185 |
@Override |
|
186 |
public String getBundleType() { |
|
187 |
return "INSTALLER"; |
|
188 |
} |
|
189 |
||
190 |
@Override |
|
191 |
public Collection<BundlerParamInfo<?>> getBundleParameters() { |
|
192 |
Collection<BundlerParamInfo<?>> results = new LinkedHashSet<>(); |
|
193 |
results.addAll(WinAppBundler.getAppBundleParameters()); |
|
194 |
results.addAll(getMsiBundleParameters()); |
|
195 |
return results; |
|
196 |
} |
|
197 |
||
198 |
public static Collection<BundlerParamInfo<?>> getMsiBundleParameters() { |
|
199 |
return Arrays.asList( |
|
200 |
DESCRIPTION, |
|
201 |
MENU_GROUP, |
|
202 |
MENU_HINT, |
|
203 |
PRODUCT_VERSION, |
|
204 |
SHORTCUT_HINT, |
|
205 |
MSI_SYSTEM_WIDE, |
|
206 |
VENDOR, |
|
207 |
LICENSE_FILE, |
|
208 |
INSTALLDIR_CHOOSER |
|
209 |
); |
|
210 |
} |
|
211 |
||
212 |
@Override |
|
57140 | 213 |
public File execute(Map<String, ? super Object> params, |
214 |
File outputParentDir) throws PackagerException { |
|
57038 | 215 |
return bundle(params, outputParentDir); |
216 |
} |
|
217 |
||
218 |
@Override |
|
57150 | 219 |
public boolean supported(boolean platformInstaller) { |
57038 | 220 |
return (Platform.getPlatform() == Platform.WINDOWS); |
221 |
} |
|
222 |
||
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
223 |
private static String findToolVersion(String toolName) { |
57038 | 224 |
try { |
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
225 |
if (toolName == null || "".equals(toolName)) return null; |
57038 | 226 |
|
227 |
ProcessBuilder pb = new ProcessBuilder( |
|
228 |
toolName, |
|
229 |
"/?"); |
|
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
230 |
VersionExtractor ve = new VersionExtractor("version (\\d+.\\d+)"); |
57038 | 231 |
// not interested in the output |
57391 | 232 |
IOUtils.exec(pb, true, ve); |
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
233 |
String version = ve.getVersion(); |
57038 | 234 |
Log.verbose(MessageFormat.format( |
235 |
I18N.getString("message.tool-version"), |
|
236 |
toolName, version)); |
|
237 |
return version; |
|
238 |
} catch (Exception e) { |
|
239 |
if (Log.isDebug()) { |
|
240 |
Log.verbose(e); |
|
241 |
} |
|
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
242 |
return null; |
57038 | 243 |
} |
244 |
} |
|
245 |
||
246 |
@Override |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
247 |
public boolean validate(Map<String, ? super Object> params) |
57038 | 248 |
throws UnsupportedPlatformException, ConfigException { |
249 |
try { |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
250 |
if (params == null) throw new ConfigException( |
57038 | 251 |
I18N.getString("error.parameters-null"), |
252 |
I18N.getString("error.parameters-null.advice")); |
|
253 |
||
254 |
// run basic validation to ensure requirements are met |
|
255 |
// we are not interested in return code, only possible exception |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
256 |
APP_BUNDLER.fetchFrom(params).validate(params); |
57038 | 257 |
|
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
258 |
String candleVersion = |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
259 |
findToolVersion(TOOL_CANDLE_EXECUTABLE.fetchFrom(params)); |
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
260 |
String lightVersion = |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
261 |
findToolVersion(TOOL_LIGHT_EXECUTABLE.fetchFrom(params)); |
57038 | 262 |
|
263 |
// WiX 3.0+ is required |
|
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
264 |
String minVersion = "3.0"; |
57038 | 265 |
boolean bad = false; |
266 |
||
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
267 |
if (VersionExtractor.isLessThan(candleVersion, minVersion)) { |
57038 | 268 |
Log.verbose(MessageFormat.format( |
269 |
I18N.getString("message.wrong-tool-version"), |
|
270 |
TOOL_CANDLE, candleVersion, minVersion)); |
|
271 |
bad = true; |
|
272 |
} |
|
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
273 |
if (VersionExtractor.isLessThan(lightVersion, minVersion)) { |
57038 | 274 |
Log.verbose(MessageFormat.format( |
275 |
I18N.getString("message.wrong-tool-version"), |
|
276 |
TOOL_LIGHT, lightVersion, minVersion)); |
|
277 |
bad = true; |
|
278 |
} |
|
279 |
||
280 |
if (bad){ |
|
281 |
throw new ConfigException( |
|
282 |
I18N.getString("error.no-wix-tools"), |
|
283 |
I18N.getString("error.no-wix-tools.advice")); |
|
284 |
} |
|
285 |
||
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
286 |
if (!VersionExtractor.isLessThan(lightVersion, "3.6")) { |
57038 | 287 |
Log.verbose(I18N.getString("message.use-wix36-features")); |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
288 |
params.put(CAN_USE_WIX36.getID(), Boolean.TRUE); |
57038 | 289 |
} |
290 |
||
291 |
/********* validate bundle parameters *************/ |
|
292 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
293 |
String version = PRODUCT_VERSION.fetchFrom(params); |
57038 | 294 |
if (!isVersionStringValid(version)) { |
295 |
throw new ConfigException( |
|
296 |
MessageFormat.format(I18N.getString( |
|
297 |
"error.version-string-wrong-format"), version), |
|
298 |
MessageFormat.format(I18N.getString( |
|
299 |
"error.version-string-wrong-format.advice"), |
|
300 |
PRODUCT_VERSION.getID())); |
|
301 |
} |
|
302 |
||
303 |
// only one mime type per association, at least one file extension |
|
304 |
List<Map<String, ? super Object>> associations = |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
305 |
FILE_ASSOCIATIONS.fetchFrom(params); |
57038 | 306 |
if (associations != null) { |
307 |
for (int i = 0; i < associations.size(); i++) { |
|
308 |
Map<String, ? super Object> assoc = associations.get(i); |
|
309 |
List<String> mimes = FA_CONTENT_TYPE.fetchFrom(assoc); |
|
310 |
if (mimes.size() > 1) { |
|
311 |
throw new ConfigException(MessageFormat.format( |
|
312 |
I18N.getString("error.too-many-content-" |
|
313 |
+ "types-for-file-association"), i), |
|
314 |
I18N.getString("error.too-many-content-" |
|
315 |
+ "types-for-file-association.advice")); |
|
316 |
} |
|
317 |
} |
|
318 |
} |
|
319 |
||
320 |
return true; |
|
321 |
} catch (RuntimeException re) { |
|
322 |
if (re.getCause() instanceof ConfigException) { |
|
323 |
throw (ConfigException) re.getCause(); |
|
324 |
} else { |
|
325 |
throw new ConfigException(re); |
|
326 |
} |
|
327 |
} |
|
328 |
} |
|
329 |
||
330 |
// http://msdn.microsoft.com/en-us/library/aa370859%28v=VS.85%29.aspx |
|
331 |
// The format of the string is as follows: |
|
332 |
// major.minor.build |
|
333 |
// The first field is the major version and has a maximum value of 255. |
|
334 |
// The second field is the minor version and has a maximum value of 255. |
|
335 |
// The third field is called the build version or the update version and |
|
336 |
// has a maximum value of 65,535. |
|
337 |
static boolean isVersionStringValid(String v) { |
|
338 |
if (v == null) { |
|
339 |
return true; |
|
340 |
} |
|
341 |
||
342 |
String p[] = v.split("\\."); |
|
343 |
if (p.length > 3) { |
|
344 |
Log.verbose(I18N.getString( |
|
345 |
"message.version-string-too-many-components")); |
|
346 |
return false; |
|
347 |
} |
|
348 |
||
349 |
try { |
|
350 |
int val = Integer.parseInt(p[0]); |
|
351 |
if (val < 0 || val > 255) { |
|
352 |
Log.verbose(I18N.getString( |
|
353 |
"error.version-string-major-out-of-range")); |
|
354 |
return false; |
|
355 |
} |
|
356 |
if (p.length > 1) { |
|
357 |
val = Integer.parseInt(p[1]); |
|
358 |
if (val < 0 || val > 255) { |
|
359 |
Log.verbose(I18N.getString( |
|
360 |
"error.version-string-minor-out-of-range")); |
|
361 |
return false; |
|
362 |
} |
|
363 |
} |
|
364 |
if (p.length > 2) { |
|
365 |
val = Integer.parseInt(p[2]); |
|
366 |
if (val < 0 || val > 65535) { |
|
367 |
Log.verbose(I18N.getString( |
|
368 |
"error.version-string-build-out-of-range")); |
|
369 |
return false; |
|
370 |
} |
|
371 |
} |
|
372 |
} catch (NumberFormatException ne) { |
|
373 |
Log.verbose(I18N.getString("error.version-string-part-not-number")); |
|
374 |
Log.verbose(ne); |
|
375 |
return false; |
|
376 |
} |
|
377 |
||
378 |
return true; |
|
379 |
} |
|
380 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
381 |
private boolean prepareProto(Map<String, ? super Object> params) |
57140 | 382 |
throws PackagerException, IOException { |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
383 |
File appImage = StandardBundlerParam.getPredefinedAppImage(params); |
57038 | 384 |
File appDir = null; |
385 |
||
386 |
// we either have an application image or need to build one |
|
387 |
if (appImage != null) { |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
388 |
appDir = new File(MSI_IMAGE_DIR.fetchFrom(params), |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
389 |
APP_NAME.fetchFrom(params)); |
57038 | 390 |
// copy everything from appImage dir into appDir/name |
391 |
IOUtils.copyRecursive(appImage.toPath(), appDir.toPath()); |
|
392 |
} else { |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
393 |
appDir = APP_BUNDLER.fetchFrom(params).doBundle(params, |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
394 |
MSI_IMAGE_DIR.fetchFrom(params), true); |
57038 | 395 |
} |
396 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
397 |
params.put(WIN_APP_IMAGE.getID(), appDir); |
57038 | 398 |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
399 |
String licenseFile = LICENSE_FILE.fetchFrom(params); |
57080 | 400 |
if (licenseFile != null) { |
401 |
// need to copy license file to the working directory and convert to rtf if needed |
|
402 |
File lfile = new File(licenseFile); |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
403 |
File destFile = new File(CONFIG_ROOT.fetchFrom(params), |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
404 |
lfile.getName()); |
57080 | 405 |
IOUtils.copyFile(lfile, destFile); |
406 |
ensureByMutationFileIsRTF(destFile); |
|
57038 | 407 |
} |
408 |
||
409 |
// copy file association icons |
|
410 |
List<Map<String, ? super Object>> fileAssociations = |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
411 |
FILE_ASSOCIATIONS.fetchFrom(params); |
57038 | 412 |
for (Map<String, ? super Object> fa : fileAssociations) { |
413 |
File icon = FA_ICON.fetchFrom(fa); // TODO FA_ICON_ICO |
|
414 |
if (icon == null) { |
|
415 |
continue; |
|
416 |
} |
|
417 |
||
418 |
File faIconFile = new File(appDir, icon.getName()); |
|
419 |
||
420 |
if (icon.exists()) { |
|
421 |
try { |
|
422 |
IOUtils.copyFile(icon, faIconFile); |
|
423 |
} catch (IOException e) { |
|
57140 | 424 |
Log.verbose(e); |
57038 | 425 |
} |
426 |
} |
|
427 |
} |
|
428 |
||
429 |
return appDir != null; |
|
430 |
} |
|
431 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
432 |
public File bundle(Map<String, ? super Object> params, File outdir) |
57140 | 433 |
throws PackagerException { |
57038 | 434 |
if (!outdir.isDirectory() && !outdir.mkdirs()) { |
57140 | 435 |
throw new PackagerException("error.cannot-create-output-dir", |
436 |
outdir.getAbsolutePath()); |
|
57038 | 437 |
} |
438 |
if (!outdir.canWrite()) { |
|
57140 | 439 |
throw new PackagerException("error.cannot-write-to-output-dir", |
440 |
outdir.getAbsolutePath()); |
|
57038 | 441 |
} |
442 |
||
443 |
// validate we have valid tools before continuing |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
444 |
String light = TOOL_LIGHT_EXECUTABLE.fetchFrom(params); |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
445 |
String candle = TOOL_CANDLE_EXECUTABLE.fetchFrom(params); |
57038 | 446 |
if (light == null || !new File(light).isFile() || |
447 |
candle == null || !new File(candle).isFile()) { |
|
448 |
Log.verbose(MessageFormat.format( |
|
449 |
I18N.getString("message.light-file-string"), light)); |
|
450 |
Log.verbose(MessageFormat.format( |
|
451 |
I18N.getString("message.candle-file-string"), candle)); |
|
57140 | 452 |
throw new PackagerException("error.no-wix-tools"); |
57038 | 453 |
} |
454 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
455 |
File imageDir = MSI_IMAGE_DIR.fetchFrom(params); |
57038 | 456 |
try { |
457 |
imageDir.mkdirs(); |
|
458 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
459 |
boolean menuShortcut = MENU_HINT.fetchFrom(params); |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
460 |
boolean desktopShortcut = SHORTCUT_HINT.fetchFrom(params); |
57038 | 461 |
if (!menuShortcut && !desktopShortcut) { |
462 |
// both can not be false - user will not find the app |
|
463 |
Log.verbose(I18N.getString("message.one-shortcut-required")); |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
464 |
params.put(MENU_HINT.getID(), true); |
57038 | 465 |
} |
466 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
467 |
if (prepareProto(params) && prepareWiXConfig(params) |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
468 |
&& prepareBasicProjectConfig(params)) { |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
469 |
File configScriptSrc = getConfig_Script(params); |
57038 | 470 |
if (configScriptSrc.exists()) { |
471 |
// we need to be running post script in the image folder |
|
472 |
||
473 |
// NOTE: Would it be better to generate it to the image |
|
474 |
// folder and save only if "verbose" is requested? |
|
475 |
||
476 |
// for now we replicate it |
|
477 |
File configScript = |
|
478 |
new File(imageDir, configScriptSrc.getName()); |
|
479 |
IOUtils.copyFile(configScriptSrc, configScript); |
|
480 |
Log.verbose(MessageFormat.format( |
|
481 |
I18N.getString("message.running-wsh-script"), |
|
482 |
configScript.getAbsolutePath())); |
|
57391 | 483 |
IOUtils.run("wscript", configScript); |
57038 | 484 |
} |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
485 |
return buildMSI(params, outdir); |
57038 | 486 |
} |
487 |
return null; |
|
488 |
} catch (IOException ex) { |
|
489 |
Log.verbose(ex); |
|
57140 | 490 |
throw new PackagerException(ex); |
57038 | 491 |
} |
492 |
} |
|
493 |
||
494 |
// name of post-image script |
|
495 |
private File getConfig_Script(Map<String, ? super Object> params) { |
|
496 |
return new File(CONFIG_ROOT.fetchFrom(params), |
|
57119 | 497 |
APP_NAME.fetchFrom(params) + "-post-image.wsf"); |
57038 | 498 |
} |
499 |
||
500 |
private boolean prepareBasicProjectConfig( |
|
501 |
Map<String, ? super Object> params) throws IOException { |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
502 |
fetchResource(getConfig_Script(params).getName(), |
57038 | 503 |
I18N.getString("resource.post-install-script"), |
504 |
(String) null, |
|
505 |
getConfig_Script(params), |
|
506 |
VERBOSE.fetchFrom(params), |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
507 |
RESOURCE_DIR.fetchFrom(params)); |
57038 | 508 |
return true; |
509 |
} |
|
510 |
||
511 |
private String relativePath(File basedir, File file) { |
|
512 |
return file.getAbsolutePath().substring( |
|
513 |
basedir.getAbsolutePath().length() + 1); |
|
514 |
} |
|
515 |
||
516 |
boolean prepareMainProjectFile( |
|
517 |
Map<String, ? super Object> params) throws IOException { |
|
518 |
Map<String, String> data = new HashMap<>(); |
|
519 |
||
520 |
UUID productGUID = UUID.randomUUID(); |
|
521 |
||
522 |
Log.verbose(MessageFormat.format( |
|
523 |
I18N.getString("message.generated-product-guid"), |
|
524 |
productGUID.toString())); |
|
525 |
||
526 |
// we use random GUID for product itself but |
|
527 |
// user provided for upgrade guid |
|
528 |
// Upgrade guid is important to decide whether it is an upgrade of |
|
529 |
// installed app. I.e. we need it to be the same for |
|
530 |
// 2 different versions of app if possible |
|
531 |
data.put("PRODUCT_GUID", productGUID.toString()); |
|
532 |
data.put("PRODUCT_UPGRADE_GUID", |
|
533 |
UPGRADE_UUID.fetchFrom(params).toString()); |
|
57181
d10b861e8d62
8214564: --win-upgrade-uuid does not work as expected
herrick
parents:
57150
diff
changeset
|
534 |
data.put("UPGRADE_BLOCK", getUpgradeBlock(params)); |
57038 | 535 |
|
536 |
data.put("APPLICATION_NAME", APP_NAME.fetchFrom(params)); |
|
537 |
data.put("APPLICATION_DESCRIPTION", DESCRIPTION.fetchFrom(params)); |
|
538 |
data.put("APPLICATION_VENDOR", VENDOR.fetchFrom(params)); |
|
539 |
data.put("APPLICATION_VERSION", PRODUCT_VERSION.fetchFrom(params)); |
|
540 |
||
541 |
// WinAppBundler will add application folder again => step out |
|
542 |
File imageRootDir = WIN_APP_IMAGE.fetchFrom(params); |
|
543 |
File launcher = new File(imageRootDir, |
|
544 |
WinAppBundler.getLauncherName(params)); |
|
545 |
||
546 |
String launcherPath = relativePath(imageRootDir, launcher); |
|
547 |
data.put("APPLICATION_LAUNCHER", launcherPath); |
|
548 |
||
549 |
String iconPath = launcherPath.replace(".exe", ".ico"); |
|
550 |
||
551 |
data.put("APPLICATION_ICON", iconPath); |
|
552 |
||
553 |
data.put("REGISTRY_ROOT", getRegistryRoot(params)); |
|
554 |
||
555 |
boolean canUseWix36Features = CAN_USE_WIX36.fetchFrom(params); |
|
556 |
data.put("WIX36_ONLY_START", |
|
557 |
canUseWix36Features ? "" : "<!--"); |
|
558 |
data.put("WIX36_ONLY_END", |
|
559 |
canUseWix36Features ? "" : "-->"); |
|
560 |
||
561 |
if (MSI_SYSTEM_WIDE.fetchFrom(params)) { |
|
562 |
data.put("INSTALL_SCOPE", "perMachine"); |
|
563 |
} else { |
|
564 |
data.put("INSTALL_SCOPE", "perUser"); |
|
565 |
} |
|
566 |
||
57213
8ff0a29bf9bc
8218055: Use ToolProvider instead of AppRuntimeImageBuilder.
herrick
parents:
57181
diff
changeset
|
567 |
data.put("PLATFORM", "x64"); |
8ff0a29bf9bc
8218055: Use ToolProvider instead of AppRuntimeImageBuilder.
herrick
parents:
57181
diff
changeset
|
568 |
data.put("WIN64", "yes"); |
57038 | 569 |
|
570 |
data.put("UI_BLOCK", getUIBlock(params)); |
|
571 |
||
57254
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
572 |
// Add CA to check install dir |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
573 |
if (INSTALLDIR_CHOOSER.fetchFrom(params)) { |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
574 |
data.put("CA_BLOCK", CA_BLOCK); |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
575 |
data.put("INVALID_INSTALL_DIR_DLG_BLOCK", INVALID_INSTALL_DIR_DLG_BLOCK); |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
576 |
} else { |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
577 |
data.put("CA_BLOCK", ""); |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
578 |
data.put("INVALID_INSTALL_DIR_DLG_BLOCK", ""); |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
579 |
} |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
580 |
|
57256 | 581 |
List<Map<String, ? super Object>> addLaunchers = |
582 |
ADD_LAUNCHERS.fetchFrom(params); |
|
57038 | 583 |
|
57256 | 584 |
StringBuilder addLauncherIcons = new StringBuilder(); |
585 |
for (int i = 0; i < addLaunchers.size(); i++) { |
|
586 |
Map<String, ? super Object> sl = addLaunchers.get(i); |
|
57038 | 587 |
// <Icon Id="DesktopIcon.exe" SourceFile="APPLICATION_ICON" /> |
588 |
if (SHORTCUT_HINT.fetchFrom(sl) || MENU_HINT.fetchFrom(sl)) { |
|
57256 | 589 |
File addLauncher = new File(imageRootDir, |
57038 | 590 |
WinAppBundler.getLauncherName(sl)); |
57256 | 591 |
String addLauncherPath = |
592 |
relativePath(imageRootDir, addLauncher); |
|
593 |
String addLauncherIconPath = |
|
594 |
addLauncherPath.replace(".exe", ".ico"); |
|
57038 | 595 |
|
57256 | 596 |
addLauncherIcons.append(" <Icon Id=\"Launcher"); |
597 |
addLauncherIcons.append(i); |
|
598 |
addLauncherIcons.append(".exe\" SourceFile=\""); |
|
599 |
addLauncherIcons.append(addLauncherIconPath); |
|
600 |
addLauncherIcons.append("\" />\r\n"); |
|
57038 | 601 |
} |
602 |
} |
|
57256 | 603 |
data.put("ADD_LAUNCHER_ICONS", addLauncherIcons.toString()); |
57038 | 604 |
|
57256 | 605 |
String wxs = StandardBundlerParam.isRuntimeInstaller(params) ? |
57038 | 606 |
MSI_PROJECT_TEMPLATE_SERVER_JRE : MSI_PROJECT_TEMPLATE; |
607 |
||
57390 | 608 |
try (Writer w = Files.newBufferedWriter( |
609 |
getConfig_ProjectFile(params).toPath())) { |
|
57038 | 610 |
|
57390 | 611 |
String content = preprocessTextResource( |
612 |
getConfig_ProjectFile(params).getName(), |
|
613 |
I18N.getString("resource.wix-config-file"), |
|
614 |
wxs, data, VERBOSE.fetchFrom(params), |
|
615 |
RESOURCE_DIR.fetchFrom(params)); |
|
616 |
w.write(content); |
|
617 |
} |
|
57038 | 618 |
return true; |
619 |
} |
|
620 |
private int id; |
|
621 |
private int compId; |
|
622 |
private final static String LAUNCHER_ID = "LauncherId"; |
|
623 |
||
57254
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
624 |
private static final String CA_BLOCK = |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
625 |
"<Binary Id=\"CustomActionDLL\" SourceFile=\"wixhelper.dll\" />\n" + |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
626 |
"<CustomAction Id=\"CHECK_INSTALLDIR\" BinaryKey=\"CustomActionDLL\" " + |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
627 |
"DllEntry=\"CheckInstallDir\" />"; |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
628 |
|
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
629 |
private static final String INVALID_INSTALL_DIR_DLG_BLOCK = |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
630 |
"<Dialog Id=\"InvalidInstallDir\" Width=\"300\" Height=\"85\" " + |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
631 |
"Title=\"[ProductName] Setup\" NoMinimize=\"yes\">\n" + |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
632 |
"<Control Id=\"InvalidInstallDirYes\" Type=\"PushButton\" X=\"100\" Y=\"55\" " + |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
633 |
"Width=\"50\" Height=\"15\" Default=\"no\" Cancel=\"no\" Text=\"Yes\">\n" + |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
634 |
"<Publish Event=\"NewDialog\" Value=\"VerifyReadyDlg\">1</Publish>\n" + |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
635 |
"</Control>\n" + |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
636 |
"<Control Id=\"InvalidInstallDirNo\" Type=\"PushButton\" X=\"150\" Y=\"55\" " + |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
637 |
"Width=\"50\" Height=\"15\" Default=\"yes\" Cancel=\"yes\" Text=\"No\">\n" + |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
638 |
"<Publish Event=\"NewDialog\" Value=\"InstallDirDlg\">1</Publish>\n" + |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
639 |
"</Control>\n" + |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
640 |
"<Control Id=\"Text\" Type=\"Text\" X=\"25\" Y=\"15\" Width=\"250\" Height=\"30\" " + |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
641 |
"TabSkip=\"no\">\n" + |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
642 |
"<Text>" + I18N.getString("message.install.dir.exist") + "</Text>\n" + |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
643 |
"</Control>\n" + |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
644 |
"</Dialog>"; |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
645 |
|
57038 | 646 |
/** |
647 |
* Overrides the dialog sequence in built-in dialog set "WixUI_InstallDir" |
|
648 |
* to exclude license dialog |
|
649 |
*/ |
|
650 |
private static final String TWEAK_FOR_EXCLUDING_LICENSE = |
|
651 |
" <Publish Dialog=\"WelcomeDlg\" Control=\"Next\"" |
|
652 |
+ " Event=\"NewDialog\" Value=\"InstallDirDlg\"" |
|
57254
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
653 |
+ " Order=\"2\">1</Publish>\n" |
57038 | 654 |
+ " <Publish Dialog=\"InstallDirDlg\" Control=\"Back\"" |
655 |
+ " Event=\"NewDialog\" Value=\"WelcomeDlg\"" |
|
57254
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
656 |
+ " Order=\"2\">1</Publish>\n"; |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
657 |
|
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
658 |
private static final String CHECK_INSTALL_DLG_CTRL = |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
659 |
" <Publish Dialog=\"InstallDirDlg\" Control=\"Next\"" |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
660 |
+ " Event=\"DoAction\" Value=\"CHECK_INSTALLDIR\"" |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
661 |
+ " Order=\"3\">1</Publish>\n" |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
662 |
+ " <Publish Dialog=\"InstallDirDlg\" Control=\"Next\"" |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
663 |
+ " Event=\"NewDialog\" Value=\"InvalidInstallDir\"" |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
664 |
+ " Order=\"5\">INSTALLDIR_VALID=\"0\"</Publish>\n" |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
665 |
+ " <Publish Dialog=\"InstallDirDlg\" Control=\"Next\"" |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
666 |
+ " Event=\"NewDialog\" Value=\"VerifyReadyDlg\"" |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
667 |
+ " Order=\"5\">INSTALLDIR_VALID=\"1\"</Publish>\n"; |
57038 | 668 |
|
57181
d10b861e8d62
8214564: --win-upgrade-uuid does not work as expected
herrick
parents:
57150
diff
changeset
|
669 |
// Required upgrade element for installers which support major upgrade (when user |
d10b861e8d62
8214564: --win-upgrade-uuid does not work as expected
herrick
parents:
57150
diff
changeset
|
670 |
// specifies --win-upgrade-uuid). We will allow downgrades. |
d10b861e8d62
8214564: --win-upgrade-uuid does not work as expected
herrick
parents:
57150
diff
changeset
|
671 |
private static final String UPGRADE_BLOCK = |
d10b861e8d62
8214564: --win-upgrade-uuid does not work as expected
herrick
parents:
57150
diff
changeset
|
672 |
"<MajorUpgrade AllowDowngrades=\"yes\"/>"; |
d10b861e8d62
8214564: --win-upgrade-uuid does not work as expected
herrick
parents:
57150
diff
changeset
|
673 |
|
d10b861e8d62
8214564: --win-upgrade-uuid does not work as expected
herrick
parents:
57150
diff
changeset
|
674 |
private String getUpgradeBlock(Map<String, ? super Object> params) { |
d10b861e8d62
8214564: --win-upgrade-uuid does not work as expected
herrick
parents:
57150
diff
changeset
|
675 |
if (UPGRADE_UUID.getIsDefaultValue()) { |
d10b861e8d62
8214564: --win-upgrade-uuid does not work as expected
herrick
parents:
57150
diff
changeset
|
676 |
return ""; |
d10b861e8d62
8214564: --win-upgrade-uuid does not work as expected
herrick
parents:
57150
diff
changeset
|
677 |
} else { |
d10b861e8d62
8214564: --win-upgrade-uuid does not work as expected
herrick
parents:
57150
diff
changeset
|
678 |
return UPGRADE_BLOCK; |
d10b861e8d62
8214564: --win-upgrade-uuid does not work as expected
herrick
parents:
57150
diff
changeset
|
679 |
} |
d10b861e8d62
8214564: --win-upgrade-uuid does not work as expected
herrick
parents:
57150
diff
changeset
|
680 |
} |
d10b861e8d62
8214564: --win-upgrade-uuid does not work as expected
herrick
parents:
57150
diff
changeset
|
681 |
|
57038 | 682 |
/** |
683 |
* Creates UI element using WiX built-in dialog sets |
|
684 |
* - WixUI_InstallDir/WixUI_Minimal. |
|
685 |
* The dialog sets are the closest to what we want to implement. |
|
686 |
* |
|
687 |
* WixUI_Minimal for license dialog only |
|
688 |
* WixUI_InstallDir for installdir dialog only or for both |
|
689 |
* installdir/license dialogs |
|
690 |
*/ |
|
57254
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
691 |
private String getUIBlock(Map<String, ? super Object> params) throws IOException { |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
692 |
String uiBlock = ""; // UI-less element |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
693 |
|
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
694 |
// Copy CA dll to include with installer |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
695 |
if (INSTALLDIR_CHOOSER.fetchFrom(params)) { |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
696 |
File helper = new File(CONFIG_ROOT.fetchFrom(params), "wixhelper.dll"); |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
697 |
try (InputStream is_lib = getResourceAsStream("wixhelper.dll")) { |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
698 |
Files.copy(is_lib, helper.toPath()); |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
699 |
} |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
700 |
} |
57038 | 701 |
|
702 |
if (INSTALLDIR_CHOOSER.fetchFrom(params)) { |
|
703 |
boolean enableTweakForExcludingLicense = |
|
704 |
(getLicenseFile(params) == null); |
|
57254
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
705 |
uiBlock = " <Property Id=\"WIXUI_INSTALLDIR\"" |
57038 | 706 |
+ " Value=\"APPLICATIONFOLDER\" />\n" |
707 |
+ " <UIRef Id=\"WixUI_InstallDir\" />\n" |
|
708 |
+ (enableTweakForExcludingLicense ? |
|
709 |
TWEAK_FOR_EXCLUDING_LICENSE : "") |
|
57254
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
710 |
+ CHECK_INSTALL_DLG_CTRL; |
57038 | 711 |
} else if (getLicenseFile(params) != null) { |
57254
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
712 |
uiBlock = " <UIRef Id=\"WixUI_Minimal\" />\n"; |
57038 | 713 |
} |
714 |
||
715 |
return uiBlock; |
|
716 |
} |
|
717 |
||
718 |
private void walkFileTree(Map<String, ? super Object> params, |
|
719 |
File root, PrintStream out, String prefix) { |
|
720 |
List<File> dirs = new ArrayList<>(); |
|
721 |
List<File> files = new ArrayList<>(); |
|
722 |
||
723 |
if (!root.isDirectory()) { |
|
724 |
throw new RuntimeException( |
|
725 |
MessageFormat.format( |
|
726 |
I18N.getString("error.cannot-walk-directory"), |
|
727 |
root.getAbsolutePath())); |
|
728 |
} |
|
729 |
||
730 |
// sort to files and dirs |
|
731 |
File[] children = root.listFiles(); |
|
732 |
if (children != null) { |
|
733 |
for (File f : children) { |
|
734 |
if (f.isDirectory()) { |
|
735 |
dirs.add(f); |
|
736 |
} else { |
|
737 |
files.add(f); |
|
738 |
} |
|
739 |
} |
|
740 |
} |
|
741 |
||
742 |
// have files => need to output component |
|
743 |
out.println(prefix + " <Component Id=\"comp" + (compId++) |
|
744 |
+ "\" DiskId=\"1\"" |
|
745 |
+ " Guid=\"" + UUID.randomUUID().toString() + "\"" |
|
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
746 |
+ " Win64=\"yes\"" |
57038 | 747 |
+ ">"); |
748 |
out.println(prefix + " <CreateFolder/>"); |
|
749 |
out.println(prefix + " <RemoveFolder Id=\"RemoveDir" |
|
750 |
+ (id++) + "\" On=\"uninstall\" />"); |
|
751 |
||
752 |
boolean needRegistryKey = !MSI_SYSTEM_WIDE.fetchFrom(params); |
|
753 |
File imageRootDir = WIN_APP_IMAGE.fetchFrom(params); |
|
754 |
File launcherFile = |
|
755 |
new File(imageRootDir, WinAppBundler.getLauncherName(params)); |
|
756 |
||
757 |
// Find out if we need to use registry. We need it if |
|
758 |
// - we doing user level install as file can not serve as KeyPath |
|
759 |
// - if we adding shortcut in this component |
|
760 |
||
761 |
for (File f: files) { |
|
762 |
boolean isLauncher = f.equals(launcherFile); |
|
763 |
if (isLauncher) { |
|
764 |
needRegistryKey = true; |
|
765 |
} |
|
766 |
} |
|
767 |
||
768 |
if (needRegistryKey) { |
|
769 |
// has to be under HKCU to make WiX happy |
|
770 |
out.println(prefix + " <RegistryKey Root=\"HKCU\" " |
|
771 |
+ " Key=\"Software\\" + VENDOR.fetchFrom(params) + "\\" |
|
772 |
+ APP_NAME.fetchFrom(params) + "\"" |
|
773 |
+ (CAN_USE_WIX36.fetchFrom(params) ? |
|
774 |
">" : " Action=\"createAndRemoveOnUninstall\">")); |
|
775 |
out.println(prefix |
|
776 |
+ " <RegistryValue Name=\"Version\" Value=\"" |
|
777 |
+ VERSION.fetchFrom(params) |
|
778 |
+ "\" Type=\"string\" KeyPath=\"yes\"/>"); |
|
779 |
out.println(prefix + " </RegistryKey>"); |
|
780 |
} |
|
781 |
||
782 |
boolean menuShortcut = MENU_HINT.fetchFrom(params); |
|
783 |
boolean desktopShortcut = SHORTCUT_HINT.fetchFrom(params); |
|
784 |
||
785 |
Map<String, String> idToFileMap = new TreeMap<>(); |
|
786 |
boolean launcherSet = false; |
|
787 |
||
788 |
for (File f : files) { |
|
789 |
boolean isLauncher = f.equals(launcherFile); |
|
790 |
||
791 |
launcherSet = launcherSet || isLauncher; |
|
792 |
||
793 |
boolean doShortcuts = |
|
794 |
isLauncher && (menuShortcut || desktopShortcut); |
|
795 |
||
796 |
String thisFileId = isLauncher ? LAUNCHER_ID : ("FileId" + (id++)); |
|
797 |
idToFileMap.put(f.getName(), thisFileId); |
|
798 |
||
799 |
out.println(prefix + " <File Id=\"" + |
|
800 |
thisFileId + "\"" |
|
801 |
+ " Name=\"" + f.getName() + "\" " |
|
802 |
+ " Source=\"" + relativePath(imageRootDir, f) + "\"" |
|
57213
8ff0a29bf9bc
8218055: Use ToolProvider instead of AppRuntimeImageBuilder.
herrick
parents:
57181
diff
changeset
|
803 |
+ " ProcessorArchitecture=\"x64\"" + ">"); |
57038 | 804 |
if (doShortcuts && desktopShortcut) { |
805 |
out.println(prefix |
|
806 |
+ " <Shortcut Id=\"desktopShortcut\" Directory=" |
|
807 |
+ "\"DesktopFolder\"" |
|
808 |
+ " Name=\"" + APP_NAME.fetchFrom(params) |
|
809 |
+ "\" WorkingDirectory=\"INSTALLDIR\"" |
|
810 |
+ " Advertise=\"no\" Icon=\"DesktopIcon.exe\"" |
|
811 |
+ " IconIndex=\"0\" />"); |
|
812 |
} |
|
813 |
if (doShortcuts && menuShortcut) { |
|
814 |
out.println(prefix |
|
815 |
+ " <Shortcut Id=\"ExeShortcut\" Directory=" |
|
816 |
+ "\"ProgramMenuDir\"" |
|
817 |
+ " Name=\"" + APP_NAME.fetchFrom(params) |
|
818 |
+ "\" Advertise=\"no\" Icon=\"StartMenuIcon.exe\"" |
|
819 |
+ " IconIndex=\"0\" />"); |
|
820 |
} |
|
821 |
||
57256 | 822 |
List<Map<String, ? super Object>> addLaunchers = |
823 |
ADD_LAUNCHERS.fetchFrom(params); |
|
824 |
for (int i = 0; i < addLaunchers.size(); i++) { |
|
825 |
Map<String, ? super Object> sl = addLaunchers.get(i); |
|
826 |
File addLauncherFile = new File(imageRootDir, |
|
57038 | 827 |
WinAppBundler.getLauncherName(sl)); |
57256 | 828 |
if (f.equals(addLauncherFile)) { |
57038 | 829 |
if (SHORTCUT_HINT.fetchFrom(sl)) { |
830 |
out.println(prefix |
|
831 |
+ " <Shortcut Id=\"desktopShortcut" |
|
832 |
+ i + "\" Directory=\"DesktopFolder\"" |
|
833 |
+ " Name=\"" + APP_NAME.fetchFrom(sl) |
|
834 |
+ "\" WorkingDirectory=\"INSTALLDIR\"" |
|
835 |
+ " Advertise=\"no\" Icon=\"Launcher" |
|
836 |
+ i + ".exe\" IconIndex=\"0\" />"); |
|
837 |
} |
|
838 |
if (MENU_HINT.fetchFrom(sl)) { |
|
839 |
out.println(prefix |
|
840 |
+ " <Shortcut Id=\"ExeShortcut" |
|
841 |
+ i + "\" Directory=\"ProgramMenuDir\"" |
|
842 |
+ " Name=\"" + APP_NAME.fetchFrom(sl) |
|
843 |
+ "\" Advertise=\"no\" Icon=\"Launcher" |
|
844 |
+ i + ".exe\" IconIndex=\"0\" />"); |
|
845 |
// Should we allow different menu groups? Not for now. |
|
846 |
} |
|
847 |
} |
|
848 |
} |
|
849 |
out.println(prefix + " </File>"); |
|
850 |
} |
|
851 |
||
852 |
if (launcherSet) { |
|
853 |
List<Map<String, ? super Object>> fileAssociations = |
|
854 |
FILE_ASSOCIATIONS.fetchFrom(params); |
|
855 |
String regName = APP_REGISTRY_NAME.fetchFrom(params); |
|
856 |
Set<String> defaultedMimes = new TreeSet<>(); |
|
857 |
int count = 0; |
|
858 |
for (Map<String, ? super Object> fa : fileAssociations) { |
|
859 |
String description = FA_DESCRIPTION.fetchFrom(fa); |
|
860 |
List<String> extensions = FA_EXTENSIONS.fetchFrom(fa); |
|
861 |
List<String> mimeTypes = FA_CONTENT_TYPE.fetchFrom(fa); |
|
862 |
File icon = FA_ICON.fetchFrom(fa); // TODO FA_ICON_ICO |
|
863 |
||
864 |
String mime = (mimeTypes == null || |
|
865 |
mimeTypes.isEmpty()) ? null : mimeTypes.get(0); |
|
866 |
||
867 |
if (extensions == null) { |
|
868 |
Log.verbose(I18N.getString( |
|
869 |
"message.creating-association-with-null-extension")); |
|
870 |
||
871 |
String entryName = regName + "File"; |
|
872 |
if (count > 0) { |
|
873 |
entryName += "." + count; |
|
874 |
} |
|
875 |
count++; |
|
876 |
out.print(prefix + " <ProgId Id='" + entryName |
|
877 |
+ "' Description='" + description + "'"); |
|
878 |
if (icon != null && icon.exists()) { |
|
879 |
out.print(" Icon='" + idToFileMap.get(icon.getName()) |
|
880 |
+ "' IconIndex='0'"); |
|
881 |
} |
|
882 |
out.println(" />"); |
|
883 |
} else { |
|
884 |
for (String ext : extensions) { |
|
885 |
String entryName = regName + "File"; |
|
886 |
if (count > 0) { |
|
887 |
entryName += "." + count; |
|
888 |
} |
|
889 |
count++; |
|
890 |
||
891 |
out.print(prefix + " <ProgId Id='" + entryName |
|
892 |
+ "' Description='" + description + "'"); |
|
893 |
if (icon != null && icon.exists()) { |
|
894 |
out.print(" Icon='" |
|
895 |
+ idToFileMap.get(icon.getName()) |
|
896 |
+ "' IconIndex='0'"); |
|
897 |
} |
|
898 |
out.println(">"); |
|
899 |
||
900 |
if (extensions == null) { |
|
901 |
Log.verbose(I18N.getString( |
|
902 |
"message.creating-association-with-null-extension")); |
|
903 |
} else { |
|
904 |
out.print(prefix + " <Extension Id='" |
|
905 |
+ ext + "' Advertise='no'"); |
|
906 |
if (mime == null) { |
|
907 |
out.println(">"); |
|
908 |
} else { |
|
909 |
out.println(" ContentType='" + mime + "'>"); |
|
910 |
if (!defaultedMimes.contains(mime)) { |
|
911 |
out.println(prefix |
|
912 |
+ " <MIME ContentType='" |
|
913 |
+ mime + "' Default='yes' />"); |
|
914 |
defaultedMimes.add(mime); |
|
915 |
} |
|
916 |
} |
|
917 |
out.println(prefix |
|
918 |
+ " <Verb Id='open' Command='Open' " |
|
919 |
+ "TargetFile='" + LAUNCHER_ID |
|
920 |
+ "' Argument='\"%1\"' />"); |
|
921 |
out.println(prefix + " </Extension>"); |
|
922 |
} |
|
923 |
out.println(prefix + " </ProgId>"); |
|
924 |
} |
|
925 |
} |
|
926 |
} |
|
927 |
} |
|
928 |
||
929 |
out.println(prefix + " </Component>"); |
|
930 |
||
931 |
for (File d : dirs) { |
|
932 |
out.println(prefix + " <Directory Id=\"dirid" + (id++) |
|
933 |
+ "\" Name=\"" + d.getName() + "\">"); |
|
934 |
walkFileTree(params, d, out, prefix + " "); |
|
935 |
out.println(prefix + " </Directory>"); |
|
936 |
} |
|
937 |
} |
|
938 |
||
939 |
String getRegistryRoot(Map<String, ? super Object> params) { |
|
940 |
if (MSI_SYSTEM_WIDE.fetchFrom(params)) { |
|
941 |
return "HKLM"; |
|
942 |
} else { |
|
943 |
return "HKCU"; |
|
944 |
} |
|
945 |
} |
|
946 |
||
947 |
boolean prepareContentList(Map<String, ? super Object> params) |
|
948 |
throws FileNotFoundException { |
|
949 |
File f = new File( |
|
950 |
CONFIG_ROOT.fetchFrom(params), MSI_PROJECT_CONTENT_FILE); |
|
57390 | 951 |
|
952 |
try (PrintStream out = new PrintStream(f)) { |
|
57038 | 953 |
|
57390 | 954 |
// opening |
955 |
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); |
|
956 |
out.println("<Include>"); |
|
57038 | 957 |
|
57390 | 958 |
out.println(" <Directory Id=\"TARGETDIR\" Name=\"SourceDir\">"); |
959 |
if (MSI_SYSTEM_WIDE.fetchFrom(params)) { |
|
960 |
// install to programfiles |
|
961 |
out.println(" <Directory Id=\"ProgramFiles64Folder\" " |
|
962 |
+ "Name=\"PFiles\">"); |
|
963 |
} else { |
|
964 |
// install to user folder |
|
965 |
out.println( |
|
57038 | 966 |
" <Directory Name=\"AppData\" Id=\"LocalAppDataFolder\">"); |
57390 | 967 |
} |
57283 | 968 |
|
57390 | 969 |
// We should get valid folder or subfolders |
970 |
String installDir = WINDOWS_INSTALL_DIR.fetchFrom(params); |
|
971 |
String [] installDirs = installDir.split(Pattern.quote("\\")); |
|
972 |
for (int i = 0; i < (installDirs.length - 1); i++) { |
|
973 |
out.println(" <Directory Id=\"SUBDIR" + i + "\" Name=\"" |
|
974 |
+ installDirs[i] + "\">"); |
|
975 |
} |
|
57283 | 976 |
|
57390 | 977 |
out.println(" <Directory Id=\"APPLICATIONFOLDER\" Name=\"" |
978 |
+ installDirs[installDirs.length - 1] + "\">"); |
|
57038 | 979 |
|
57390 | 980 |
// dynamic part |
981 |
id = 0; |
|
982 |
compId = 0; // reset counters |
|
983 |
walkFileTree(params, WIN_APP_IMAGE.fetchFrom(params), out, " "); |
|
57038 | 984 |
|
57390 | 985 |
// closing |
986 |
for (int i = 0; i < installDirs.length; i++) { |
|
987 |
out.println(" </Directory>"); |
|
988 |
} |
|
989 |
out.println(" </Directory>"); |
|
57038 | 990 |
|
57390 | 991 |
// for shortcuts |
992 |
if (SHORTCUT_HINT.fetchFrom(params)) { |
|
993 |
out.println(" <Directory Id=\"DesktopFolder\" />"); |
|
994 |
} |
|
995 |
if (MENU_HINT.fetchFrom(params)) { |
|
996 |
out.println(" <Directory Id=\"ProgramMenuFolder\">"); |
|
997 |
out.println(" <Directory Id=\"ProgramMenuDir\" Name=\"" |
|
998 |
+ MENU_GROUP.fetchFrom(params) + "\">"); |
|
999 |
out.println(" <Component Id=\"comp" + (compId++) + "\"" |
|
1000 |
+ " Guid=\"" + UUID.randomUUID().toString() + "\"" |
|
1001 |
+ " Win64=\"yes\"" |
|
1002 |
+ ">"); |
|
1003 |
out.println(" <RemoveFolder Id=\"ProgramMenuDir\" " |
|
1004 |
+ "On=\"uninstall\" />"); |
|
1005 |
// This has to be under HKCU to make WiX happy. |
|
1006 |
// There are numberous discussions on this amoung WiX users |
|
1007 |
// (if user A installs and user B uninstalls key is left behind) |
|
1008 |
// there are suggested workarounds but none are appealing. |
|
1009 |
// Leave it for now |
|
1010 |
out.println( |
|
1011 |
" <RegistryValue Root=\"HKCU\" Key=\"Software\\" |
|
1012 |
+ VENDOR.fetchFrom(params) + "\\" |
|
1013 |
+ APP_NAME.fetchFrom(params) |
|
1014 |
+ "\" Type=\"string\" Value=\"\" />"); |
|
1015 |
out.println(" </Component>"); |
|
1016 |
out.println(" </Directory>"); |
|
1017 |
out.println(" </Directory>"); |
|
1018 |
} |
|
1019 |
||
1020 |
out.println(" </Directory>"); |
|
1021 |
||
1022 |
out.println(" <Feature Id=\"DefaultFeature\" " |
|
1023 |
+ "Title=\"Main Feature\" Level=\"1\">"); |
|
1024 |
for (int j = 0; j < compId; j++) { |
|
1025 |
out.println(" <ComponentRef Id=\"comp" + j + "\" />"); |
|
1026 |
} |
|
1027 |
// component is defined in the template.wsx |
|
57038 | 1028 |
out.println( |
57390 | 1029 |
" <ComponentRef Id=\"CleanupMainApplicationFolder\" />"); |
1030 |
out.println(" </Feature>"); |
|
1031 |
out.println("</Include>"); |
|
57038 | 1032 |
|
1033 |
} |
|
1034 |
return true; |
|
1035 |
} |
|
1036 |
||
1037 |
private File getConfig_ProjectFile(Map<String, ? super Object> params) { |
|
1038 |
return new File(CONFIG_ROOT.fetchFrom(params), |
|
1039 |
APP_NAME.fetchFrom(params) + ".wxs"); |
|
1040 |
} |
|
1041 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
1042 |
private String getLicenseFile(Map<String, ? super Object> params) { |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
1043 |
String licenseFile = LICENSE_FILE.fetchFrom(params); |
57080 | 1044 |
if (licenseFile != null) { |
1045 |
File lfile = new File(licenseFile); |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
1046 |
File destFile = new File(CONFIG_ROOT.fetchFrom(params), |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
1047 |
lfile.getName()); |
57080 | 1048 |
String filePath = destFile.getAbsolutePath(); |
1049 |
if (filePath.contains(" ")) { |
|
1050 |
return "\"" + filePath + "\""; |
|
1051 |
} else { |
|
1052 |
return filePath; |
|
1053 |
} |
|
57038 | 1054 |
} |
57080 | 1055 |
|
1056 |
return null; |
|
57038 | 1057 |
} |
1058 |
||
1059 |
private boolean prepareWiXConfig( |
|
1060 |
Map<String, ? super Object> params) throws IOException { |
|
1061 |
return prepareMainProjectFile(params) && prepareContentList(params); |
|
1062 |
||
1063 |
} |
|
1064 |
private final static String MSI_PROJECT_TEMPLATE = "template.wxs"; |
|
1065 |
private final static String MSI_PROJECT_TEMPLATE_SERVER_JRE = |
|
1066 |
"template.jre.wxs"; |
|
1067 |
private final static String MSI_PROJECT_CONTENT_FILE = "bundle.wxi"; |
|
1068 |
||
1069 |
private File buildMSI(Map<String, ? super Object> params, File outdir) |
|
1070 |
throws IOException { |
|
57256 | 1071 |
File tmpDir = new File(TEMP_ROOT.fetchFrom(params), "tmp"); |
57038 | 1072 |
File candleOut = new File( |
1073 |
tmpDir, APP_NAME.fetchFrom(params) +".wixobj"); |
|
1074 |
File msiOut = new File( |
|
1075 |
outdir, INSTALLER_FILE_NAME.fetchFrom(params) + ".msi"); |
|
1076 |
||
1077 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
1078 |
"message.preparing-msi-config"), msiOut.getAbsolutePath())); |
|
1079 |
||
1080 |
msiOut.getParentFile().mkdirs(); |
|
1081 |
||
1082 |
// run candle |
|
1083 |
ProcessBuilder pb = new ProcessBuilder( |
|
1084 |
TOOL_CANDLE_EXECUTABLE.fetchFrom(params), |
|
1085 |
"-nologo", |
|
1086 |
getConfig_ProjectFile(params).getAbsolutePath(), |
|
1087 |
"-ext", "WixUtilExtension", |
|
1088 |
"-out", candleOut.getAbsolutePath()); |
|
1089 |
pb = pb.directory(WIN_APP_IMAGE.fetchFrom(params)); |
|
57391 | 1090 |
IOUtils.exec(pb); |
57038 | 1091 |
|
1092 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
1093 |
"message.generating-msi"), msiOut.getAbsolutePath())); |
|
1094 |
||
1095 |
boolean enableLicenseUI = (getLicenseFile(params) != null); |
|
1096 |
boolean enableInstalldirUI = INSTALLDIR_CHOOSER.fetchFrom(params); |
|
1097 |
||
1098 |
List<String> commandLine = new ArrayList<>(); |
|
1099 |
||
1100 |
commandLine.add(TOOL_LIGHT_EXECUTABLE.fetchFrom(params)); |
|
1101 |
if (enableLicenseUI) { |
|
1102 |
commandLine.add("-dWixUILicenseRtf="+getLicenseFile(params)); |
|
1103 |
} |
|
1104 |
commandLine.add("-nologo"); |
|
1105 |
commandLine.add("-spdb"); |
|
1106 |
commandLine.add("-sice:60"); |
|
1107 |
// ignore warnings due to "missing launcguage info" (ICE60) |
|
1108 |
commandLine.add(candleOut.getAbsolutePath()); |
|
1109 |
commandLine.add("-ext"); |
|
1110 |
commandLine.add("WixUtilExtension"); |
|
1111 |
if (enableLicenseUI || enableInstalldirUI) { |
|
1112 |
commandLine.add("-ext"); |
|
1113 |
commandLine.add("WixUIExtension.dll"); |
|
1114 |
} |
|
57254
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
1115 |
|
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
1116 |
// Only needed if we using CA dll, so Wix can find it |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
1117 |
if (enableInstalldirUI) { |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
1118 |
commandLine.add("-b"); |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
1119 |
commandLine.add(CONFIG_ROOT.fetchFrom(params).getAbsolutePath()); |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
1120 |
} |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
1121 |
|
57038 | 1122 |
commandLine.add("-out"); |
1123 |
commandLine.add(msiOut.getAbsolutePath()); |
|
1124 |
||
1125 |
// create .msi |
|
1126 |
pb = new ProcessBuilder(commandLine); |
|
1127 |
||
1128 |
pb = pb.directory(WIN_APP_IMAGE.fetchFrom(params)); |
|
57391 | 1129 |
IOUtils.exec(pb); |
57038 | 1130 |
|
1131 |
candleOut.delete(); |
|
1132 |
IOUtils.deleteRecursive(tmpDir); |
|
1133 |
||
1134 |
return msiOut; |
|
1135 |
} |
|
1136 |
||
1137 |
public static void ensureByMutationFileIsRTF(File f) { |
|
1138 |
if (f == null || !f.isFile()) return; |
|
1139 |
||
1140 |
try { |
|
1141 |
boolean existingLicenseIsRTF = false; |
|
1142 |
||
1143 |
try (FileInputStream fin = new FileInputStream(f)) { |
|
1144 |
byte[] firstBits = new byte[7]; |
|
1145 |
||
1146 |
if (fin.read(firstBits) == firstBits.length) { |
|
1147 |
String header = new String(firstBits); |
|
1148 |
existingLicenseIsRTF = "{\\rtf1\\".equals(header); |
|
1149 |
} |
|
1150 |
} |
|
1151 |
||
1152 |
if (!existingLicenseIsRTF) { |
|
1153 |
List<String> oldLicense = Files.readAllLines(f.toPath()); |
|
1154 |
try (Writer w = Files.newBufferedWriter( |
|
1155 |
f.toPath(), Charset.forName("Windows-1252"))) { |
|
1156 |
w.write("{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033" |
|
1157 |
+ "{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}}\n" |
|
1158 |
+ "\\viewkind4\\uc1\\pard\\sa200\\sl276" |
|
1159 |
+ "\\slmult1\\lang9\\fs20 "); |
|
1160 |
oldLicense.forEach(l -> { |
|
1161 |
try { |
|
1162 |
for (char c : l.toCharArray()) { |
|
1163 |
// 0x00 <= ch < 0x20 Escaped (\'hh) |
|
1164 |
// 0x20 <= ch < 0x80 Raw(non - escaped) char |
|
1165 |
// 0x80 <= ch <= 0xFF Escaped(\ 'hh) |
|
1166 |
// 0x5C, 0x7B, 0x7D (special RTF characters |
|
1167 |
// \,{,})Escaped(\'hh) |
|
1168 |
// ch > 0xff Escaped (\\ud###?) |
|
1169 |
if (c < 0x10) { |
|
1170 |
w.write("\\'0"); |
|
1171 |
w.write(Integer.toHexString(c)); |
|
1172 |
} else if (c > 0xff) { |
|
1173 |
w.write("\\ud"); |
|
1174 |
w.write(Integer.toString(c)); |
|
1175 |
// \\uc1 is in the header and in effect |
|
1176 |
// so we trail with a replacement char if |
|
1177 |
// the font lacks that character - '?' |
|
1178 |
w.write("?"); |
|
1179 |
} else if ((c < 0x20) || (c >= 0x80) || |
|
1180 |
(c == 0x5C) || (c == 0x7B) || |
|
1181 |
(c == 0x7D)) { |
|
1182 |
w.write("\\'"); |
|
1183 |
w.write(Integer.toHexString(c)); |
|
1184 |
} else { |
|
1185 |
w.write(c); |
|
1186 |
} |
|
1187 |
} |
|
1188 |
// blank lines are interpreted as paragraph breaks |
|
1189 |
if (l.length() < 1) { |
|
1190 |
w.write("\\par"); |
|
1191 |
} else { |
|
1192 |
w.write(" "); |
|
1193 |
} |
|
1194 |
w.write("\r\n"); |
|
1195 |
} catch (IOException e) { |
|
1196 |
Log.verbose(e); |
|
1197 |
} |
|
1198 |
}); |
|
1199 |
w.write("}\r\n"); |
|
1200 |
} |
|
1201 |
} |
|
1202 |
} catch (IOException e) { |
|
1203 |
Log.verbose(e); |
|
1204 |
} |
|
1205 |
||
1206 |
} |
|
1207 |
} |