57038
|
1 |
/*
|
|
2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
|
|
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 |
|
57039
|
28 |
import jdk.jpackage.internal.*;
|
|
29 |
import jdk.jpackage.internal.ConfigException;
|
|
30 |
import jdk.jpackage.internal.Arguments;
|
|
31 |
import jdk.jpackage.internal.UnsupportedPlatformException;
|
|
32 |
import jdk.jpackage.internal.resources.WinResources;
|
57038
|
33 |
|
|
34 |
import java.io.*;
|
|
35 |
import java.nio.charset.Charset;
|
|
36 |
import java.nio.file.Files;
|
|
37 |
import java.text.MessageFormat;
|
|
38 |
import java.util.*;
|
|
39 |
import java.util.regex.Matcher;
|
|
40 |
import java.util.regex.Pattern;
|
|
41 |
|
57039
|
42 |
import static jdk.jpackage.internal.WindowsBundlerParam.*;
|
57038
|
43 |
|
|
44 |
public class WinExeBundler extends AbstractBundler {
|
|
45 |
|
|
46 |
private static final ResourceBundle I18N = ResourceBundle.getBundle(
|
57039
|
47 |
"jdk.jpackage.internal.resources.WinExeBundler");
|
57038
|
48 |
|
|
49 |
public static final BundlerParamInfo<WinAppBundler> APP_BUNDLER =
|
|
50 |
new WindowsBundlerParam<>(
|
|
51 |
getString("param.app-bundler.name"),
|
|
52 |
getString("param.app-bundler.description"),
|
|
53 |
"win.app.bundler",
|
|
54 |
WinAppBundler.class,
|
|
55 |
params -> new WinAppBundler(),
|
|
56 |
null);
|
|
57 |
|
|
58 |
public static final BundlerParamInfo<File> CONFIG_ROOT =
|
|
59 |
new WindowsBundlerParam<>(
|
|
60 |
getString("param.config-root.name"),
|
|
61 |
getString("param.config-root.description"),
|
|
62 |
"configRoot",
|
|
63 |
File.class,
|
|
64 |
params -> {
|
|
65 |
File imagesRoot =
|
|
66 |
new File(BUILD_ROOT.fetchFrom(params), "windows");
|
|
67 |
imagesRoot.mkdirs();
|
|
68 |
return imagesRoot;
|
|
69 |
},
|
|
70 |
(s, p) -> null);
|
|
71 |
|
|
72 |
public static final BundlerParamInfo<File> EXE_IMAGE_DIR =
|
|
73 |
new WindowsBundlerParam<>(
|
|
74 |
getString("param.image-dir.name"),
|
|
75 |
getString("param.image-dir.description"),
|
|
76 |
"win.exe.imageDir",
|
|
77 |
File.class,
|
|
78 |
params -> {
|
|
79 |
File imagesRoot = IMAGES_ROOT.fetchFrom(params);
|
|
80 |
if (!imagesRoot.exists()) imagesRoot.mkdirs();
|
|
81 |
return new File(imagesRoot, "win-exe.image");
|
|
82 |
},
|
|
83 |
(s, p) -> null);
|
|
84 |
|
|
85 |
public static final BundlerParamInfo<File> WIN_APP_IMAGE =
|
|
86 |
new WindowsBundlerParam<>(
|
|
87 |
getString("param.app-dir.name"),
|
|
88 |
getString("param.app-dir.description"),
|
|
89 |
"win.app.image",
|
|
90 |
File.class,
|
|
91 |
null,
|
|
92 |
(s, p) -> null);
|
|
93 |
|
|
94 |
|
|
95 |
public static final StandardBundlerParam<Boolean> EXE_SYSTEM_WIDE =
|
|
96 |
new StandardBundlerParam<>(
|
|
97 |
getString("param.system-wide.name"),
|
|
98 |
getString("param.system-wide.description"),
|
|
99 |
Arguments.CLIOptions.WIN_PER_USER_INSTALLATION.getId(),
|
|
100 |
Boolean.class,
|
|
101 |
params -> true, // default to system wide
|
|
102 |
(s, p) -> (s == null || "null".equalsIgnoreCase(s))? null
|
|
103 |
: Boolean.valueOf(s)
|
|
104 |
);
|
|
105 |
public static final StandardBundlerParam<String> PRODUCT_VERSION =
|
|
106 |
new StandardBundlerParam<>(
|
|
107 |
getString("param.product-version.name"),
|
|
108 |
getString("param.product-version.description"),
|
|
109 |
"win.msi.productVersion",
|
|
110 |
String.class,
|
|
111 |
VERSION::fetchFrom,
|
|
112 |
(s, p) -> s
|
|
113 |
);
|
|
114 |
|
|
115 |
public static final StandardBundlerParam<Boolean> MENU_HINT =
|
|
116 |
new WindowsBundlerParam<>(
|
|
117 |
getString("param.menu-shortcut-hint.name"),
|
|
118 |
getString("param.menu-shortcut-hint.description"),
|
|
119 |
Arguments.CLIOptions.WIN_MENU_HINT.getId(),
|
|
120 |
Boolean.class,
|
|
121 |
params -> false,
|
|
122 |
(s, p) -> (s == null ||
|
|
123 |
"null".equalsIgnoreCase(s))? true : Boolean.valueOf(s)
|
|
124 |
);
|
|
125 |
|
|
126 |
public static final StandardBundlerParam<Boolean> SHORTCUT_HINT =
|
|
127 |
new WindowsBundlerParam<>(
|
|
128 |
getString("param.desktop-shortcut-hint.name"),
|
|
129 |
getString("param.desktop-shortcut-hint.description"),
|
|
130 |
Arguments.CLIOptions.WIN_SHORTCUT_HINT.getId(),
|
|
131 |
Boolean.class,
|
|
132 |
params -> false,
|
|
133 |
(s, p) -> (s == null ||
|
|
134 |
"null".equalsIgnoreCase(s))? false : Boolean.valueOf(s)
|
|
135 |
);
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
private final static String DEFAULT_EXE_PROJECT_TEMPLATE = "template.iss";
|
|
140 |
private final static String DEFAULT_JRE_EXE_TEMPLATE = "template.jre.iss";
|
|
141 |
private static final String TOOL_INNO_SETUP_COMPILER = "iscc.exe";
|
|
142 |
|
|
143 |
public static final BundlerParamInfo<String>
|
|
144 |
TOOL_INNO_SETUP_COMPILER_EXECUTABLE = new WindowsBundlerParam<>(
|
|
145 |
getString("param.iscc-path.name"),
|
|
146 |
getString("param.iscc-path.description"),
|
|
147 |
"win.exe.iscc.exe",
|
|
148 |
String.class,
|
|
149 |
params -> {
|
|
150 |
for (String dirString : (System.getenv("PATH")
|
|
151 |
+ ";C:\\Program Files (x86)\\Inno Setup 5;"
|
|
152 |
+ "C:\\Program Files\\Inno Setup 5").split(";")) {
|
|
153 |
File f = new File(dirString.replace("\"", ""),
|
|
154 |
TOOL_INNO_SETUP_COMPILER);
|
|
155 |
if (f.isFile()) {
|
|
156 |
return f.toString();
|
|
157 |
}
|
|
158 |
}
|
|
159 |
return null;
|
|
160 |
},
|
|
161 |
null);
|
|
162 |
|
|
163 |
public WinExeBundler() {
|
|
164 |
super();
|
|
165 |
baseResourceLoader = WinResources.class;
|
|
166 |
}
|
|
167 |
|
|
168 |
@Override
|
|
169 |
public String getName() {
|
|
170 |
return getString("bundler.name");
|
|
171 |
}
|
|
172 |
|
|
173 |
@Override
|
|
174 |
public String getDescription() {
|
|
175 |
return getString("bundler.description");
|
|
176 |
}
|
|
177 |
|
|
178 |
@Override
|
|
179 |
public String getID() {
|
|
180 |
return "exe";
|
|
181 |
}
|
|
182 |
|
|
183 |
@Override
|
|
184 |
public String getBundleType() {
|
|
185 |
return "INSTALLER";
|
|
186 |
}
|
|
187 |
|
|
188 |
@Override
|
|
189 |
public Collection<BundlerParamInfo<?>> getBundleParameters() {
|
|
190 |
Collection<BundlerParamInfo<?>> results = new LinkedHashSet<>();
|
|
191 |
results.addAll(WinAppBundler.getAppBundleParameters());
|
|
192 |
results.addAll(getExeBundleParameters());
|
|
193 |
return results;
|
|
194 |
}
|
|
195 |
|
|
196 |
public static Collection<BundlerParamInfo<?>> getExeBundleParameters() {
|
|
197 |
return Arrays.asList(
|
|
198 |
DESCRIPTION,
|
|
199 |
COPYRIGHT,
|
|
200 |
LICENSE_FILE,
|
|
201 |
MENU_GROUP,
|
|
202 |
MENU_HINT,
|
|
203 |
SHORTCUT_HINT,
|
|
204 |
EXE_SYSTEM_WIDE,
|
|
205 |
TITLE,
|
|
206 |
VENDOR,
|
|
207 |
INSTALLDIR_CHOOSER
|
|
208 |
);
|
|
209 |
}
|
|
210 |
|
|
211 |
@Override
|
|
212 |
public File execute(
|
|
213 |
Map<String, ? super Object> p, File outputParentDir) {
|
|
214 |
return bundle(p, outputParentDir);
|
|
215 |
}
|
|
216 |
|
|
217 |
@Override
|
|
218 |
public boolean supported() {
|
|
219 |
return (Platform.getPlatform() == Platform.WINDOWS);
|
|
220 |
}
|
|
221 |
|
|
222 |
static class VersionExtractor extends PrintStream {
|
|
223 |
double version = 0f;
|
|
224 |
|
|
225 |
public VersionExtractor() {
|
|
226 |
super(new ByteArrayOutputStream());
|
|
227 |
}
|
|
228 |
|
|
229 |
double getVersion() {
|
|
230 |
if (version == 0f) {
|
|
231 |
String content =
|
|
232 |
new String(((ByteArrayOutputStream) out).toByteArray());
|
|
233 |
Pattern pattern = Pattern.compile("Inno Setup (\\d+.?\\d*)");
|
|
234 |
Matcher matcher = pattern.matcher(content);
|
|
235 |
if (matcher.find()) {
|
|
236 |
String v = matcher.group(1);
|
|
237 |
version = Double.parseDouble(v);
|
|
238 |
}
|
|
239 |
}
|
|
240 |
return version;
|
|
241 |
}
|
|
242 |
}
|
|
243 |
|
|
244 |
private static double findToolVersion(String toolName) {
|
|
245 |
try {
|
|
246 |
if (toolName == null || "".equals(toolName)) return 0f;
|
|
247 |
|
|
248 |
ProcessBuilder pb = new ProcessBuilder(
|
|
249 |
toolName,
|
|
250 |
"/?");
|
|
251 |
VersionExtractor ve = new VersionExtractor();
|
|
252 |
IOUtils.exec(pb, Log.isDebug(), true, ve);
|
|
253 |
// not interested in the output
|
|
254 |
double version = ve.getVersion();
|
|
255 |
Log.verbose(MessageFormat.format(
|
|
256 |
getString("message.tool-version"), toolName, version));
|
|
257 |
return version;
|
|
258 |
} catch (Exception e) {
|
|
259 |
if (Log.isDebug()) {
|
|
260 |
Log.verbose(e);
|
|
261 |
}
|
|
262 |
return 0f;
|
|
263 |
}
|
|
264 |
}
|
|
265 |
|
|
266 |
@Override
|
|
267 |
public boolean validate(Map<String, ? super Object> p)
|
|
268 |
throws UnsupportedPlatformException, ConfigException {
|
|
269 |
try {
|
|
270 |
if (p == null) throw new ConfigException(
|
|
271 |
getString("error.parameters-null"),
|
|
272 |
getString("error.parameters-null.advice"));
|
|
273 |
|
|
274 |
// run basic validation to ensure requirements are met
|
|
275 |
// we are not interested in return code, only possible exception
|
|
276 |
APP_BUNDLER.fetchFrom(p).validate(p);
|
|
277 |
|
|
278 |
// make sure some key values don't have newlines
|
|
279 |
for (BundlerParamInfo<String> pi : Arrays.asList(
|
|
280 |
APP_NAME,
|
|
281 |
COPYRIGHT,
|
|
282 |
DESCRIPTION,
|
|
283 |
MENU_GROUP,
|
|
284 |
TITLE,
|
|
285 |
VENDOR,
|
|
286 |
VERSION)
|
|
287 |
) {
|
|
288 |
String v = pi.fetchFrom(p);
|
|
289 |
if (v.contains("\n") | v.contains("\r")) {
|
|
290 |
throw new ConfigException("Parmeter '" + pi.getID() +
|
|
291 |
"' cannot contain a newline.",
|
|
292 |
" Change the value of '" + pi.getID() +
|
|
293 |
" so that it does not contain any newlines");
|
|
294 |
}
|
|
295 |
}
|
|
296 |
|
|
297 |
// exe bundlers trim the copyright to 100 characters,
|
|
298 |
// tell them this will happen
|
|
299 |
if (COPYRIGHT.fetchFrom(p).length() > 100) {
|
|
300 |
throw new ConfigException(
|
|
301 |
getString("error.copyright-is-too-long"),
|
|
302 |
getString("error.copyright-is-too-long.advice"));
|
|
303 |
}
|
|
304 |
|
|
305 |
double innoVersion = findToolVersion(
|
|
306 |
TOOL_INNO_SETUP_COMPILER_EXECUTABLE.fetchFrom(p));
|
|
307 |
|
|
308 |
//Inno Setup 5+ is required
|
|
309 |
double minVersion = 5.0f;
|
|
310 |
|
|
311 |
if (innoVersion < minVersion) {
|
|
312 |
Log.error(MessageFormat.format(
|
|
313 |
getString("message.tool-wrong-version"),
|
|
314 |
TOOL_INNO_SETUP_COMPILER, innoVersion, minVersion));
|
|
315 |
throw new ConfigException(
|
|
316 |
getString("error.iscc-not-found"),
|
|
317 |
getString("error.iscc-not-found.advice"));
|
|
318 |
}
|
|
319 |
|
|
320 |
/********* validate bundle parameters *************/
|
|
321 |
|
|
322 |
// only one mime type per association, at least one file extension
|
|
323 |
List<Map<String, ? super Object>> associations =
|
|
324 |
FILE_ASSOCIATIONS.fetchFrom(p);
|
|
325 |
if (associations != null) {
|
|
326 |
for (int i = 0; i < associations.size(); i++) {
|
|
327 |
Map<String, ? super Object> assoc = associations.get(i);
|
|
328 |
List<String> mimes = FA_CONTENT_TYPE.fetchFrom(assoc);
|
|
329 |
if (mimes.size() > 1) {
|
|
330 |
throw new ConfigException(MessageFormat.format(
|
|
331 |
getString("error.too-many-content-"
|
|
332 |
+ "types-for-file-association"), i),
|
|
333 |
getString("error.too-many-content-"
|
|
334 |
+ "types-for-file-association.advice"));
|
|
335 |
}
|
|
336 |
}
|
|
337 |
}
|
|
338 |
|
|
339 |
// validate license file, if used, exists in the proper place
|
|
340 |
if (p.containsKey(LICENSE_FILE.getID())) {
|
|
341 |
List<RelativeFileSet> appResourcesList =
|
|
342 |
APP_RESOURCES_LIST.fetchFrom(p);
|
|
343 |
for (String license : LICENSE_FILE.fetchFrom(p)) {
|
|
344 |
boolean found = false;
|
|
345 |
for (RelativeFileSet appResources : appResourcesList) {
|
|
346 |
found = found || appResources.contains(license);
|
|
347 |
}
|
|
348 |
if (!found) {
|
|
349 |
throw new ConfigException(
|
|
350 |
MessageFormat.format(getString(
|
|
351 |
"error.license-missing"), license),
|
|
352 |
MessageFormat.format(getString(
|
|
353 |
"error.license-missing.advice"), license));
|
|
354 |
}
|
|
355 |
}
|
|
356 |
}
|
|
357 |
|
|
358 |
return true;
|
|
359 |
} catch (RuntimeException re) {
|
|
360 |
if (re.getCause() instanceof ConfigException) {
|
|
361 |
throw (ConfigException) re.getCause();
|
|
362 |
} else {
|
|
363 |
throw new ConfigException(re);
|
|
364 |
}
|
|
365 |
}
|
|
366 |
}
|
|
367 |
|
|
368 |
private boolean prepareProto(Map<String, ? super Object> p)
|
|
369 |
throws IOException {
|
|
370 |
File appImage = StandardBundlerParam.getPredefinedAppImage(p);
|
|
371 |
File appDir = null;
|
|
372 |
|
|
373 |
// we either have an application image or need to build one
|
|
374 |
if (appImage != null) {
|
|
375 |
appDir = new File(
|
|
376 |
EXE_IMAGE_DIR.fetchFrom(p), APP_NAME.fetchFrom(p));
|
|
377 |
// copy everything from appImage dir into appDir/name
|
|
378 |
IOUtils.copyRecursive(appImage.toPath(), appDir.toPath());
|
|
379 |
} else {
|
|
380 |
appDir = APP_BUNDLER.fetchFrom(p).doBundle(p,
|
|
381 |
EXE_IMAGE_DIR.fetchFrom(p), true);
|
|
382 |
}
|
|
383 |
|
|
384 |
if (appDir == null) {
|
|
385 |
return false;
|
|
386 |
}
|
|
387 |
|
|
388 |
p.put(WIN_APP_IMAGE.getID(), appDir);
|
|
389 |
|
|
390 |
List<String> licenseFiles = LICENSE_FILE.fetchFrom(p);
|
|
391 |
if (licenseFiles != null) {
|
|
392 |
// need to copy license file to the root of win.app.image
|
|
393 |
outerLoop:
|
|
394 |
for (RelativeFileSet rfs : APP_RESOURCES_LIST.fetchFrom(p)) {
|
|
395 |
for (String s : licenseFiles) {
|
|
396 |
if (rfs.contains(s)) {
|
|
397 |
File lfile = new File(rfs.getBaseDirectory(), s);
|
|
398 |
File destFile =
|
|
399 |
new File(appDir.getParentFile(), lfile.getName());
|
|
400 |
IOUtils.copyFile(lfile, destFile);
|
|
401 |
ensureByMutationFileIsRTF(destFile);
|
|
402 |
break outerLoop;
|
|
403 |
}
|
|
404 |
}
|
|
405 |
}
|
|
406 |
}
|
|
407 |
|
|
408 |
// copy file association icons
|
|
409 |
List<Map<String, ? super Object>> fileAssociations =
|
|
410 |
FILE_ASSOCIATIONS.fetchFrom(p);
|
|
411 |
|
|
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) {
|
|
424 |
e.printStackTrace();
|
|
425 |
}
|
|
426 |
}
|
|
427 |
}
|
|
428 |
|
|
429 |
return true;
|
|
430 |
}
|
|
431 |
|
|
432 |
public File bundle(Map<String, ? super Object> p, File outdir) {
|
|
433 |
if (!outdir.isDirectory() && !outdir.mkdirs()) {
|
|
434 |
throw new RuntimeException(MessageFormat.format(
|
|
435 |
getString("error.cannot-create-output-dir"),
|
|
436 |
outdir.getAbsolutePath()));
|
|
437 |
}
|
|
438 |
if (!outdir.canWrite()) {
|
|
439 |
throw new RuntimeException(MessageFormat.format(
|
|
440 |
getString("error.cannot-write-to-output-dir"),
|
|
441 |
outdir.getAbsolutePath()));
|
|
442 |
}
|
|
443 |
|
|
444 |
if (WindowsDefender.isThereAPotentialWindowsDefenderIssue()) {
|
|
445 |
Log.error(MessageFormat.format(
|
|
446 |
getString("message.potential.windows.defender.issue"),
|
|
447 |
WindowsDefender.getUserTempDirectory()));
|
|
448 |
}
|
|
449 |
|
|
450 |
// validate we have valid tools before continuing
|
|
451 |
String iscc = TOOL_INNO_SETUP_COMPILER_EXECUTABLE.fetchFrom(p);
|
|
452 |
if (iscc == null || !new File(iscc).isFile()) {
|
|
453 |
Log.error(getString("error.iscc-not-found"));
|
|
454 |
Log.error(MessageFormat.format(
|
|
455 |
getString("message.iscc-file-string"), iscc));
|
|
456 |
return null;
|
|
457 |
}
|
|
458 |
|
|
459 |
File imageDir = EXE_IMAGE_DIR.fetchFrom(p);
|
|
460 |
try {
|
|
461 |
imageDir.mkdirs();
|
|
462 |
|
|
463 |
boolean menuShortcut = MENU_HINT.fetchFrom(p);
|
|
464 |
boolean desktopShortcut = SHORTCUT_HINT.fetchFrom(p);
|
|
465 |
if (!menuShortcut && !desktopShortcut) {
|
|
466 |
// both can not be false - user will not find the app
|
|
467 |
Log.verbose(getString("message.one-shortcut-required"));
|
|
468 |
p.put(MENU_HINT.getID(), true);
|
|
469 |
}
|
|
470 |
|
|
471 |
if (prepareProto(p) && prepareProjectConfig(p)) {
|
|
472 |
File configScript = getConfig_Script(p);
|
|
473 |
if (configScript.exists()) {
|
|
474 |
Log.verbose(MessageFormat.format(
|
|
475 |
getString("message.running-wsh-script"),
|
|
476 |
configScript.getAbsolutePath()));
|
|
477 |
IOUtils.run("wscript", configScript, VERBOSE.fetchFrom(p));
|
|
478 |
}
|
|
479 |
return buildEXE(p, outdir);
|
|
480 |
}
|
|
481 |
return null;
|
|
482 |
} catch (IOException ex) {
|
|
483 |
ex.printStackTrace();
|
|
484 |
return null;
|
|
485 |
} finally {
|
|
486 |
try {
|
|
487 |
if (imageDir != null &&
|
|
488 |
PREDEFINED_APP_IMAGE.fetchFrom(p) == null &&
|
|
489 |
(PREDEFINED_RUNTIME_IMAGE.fetchFrom(p) == null ||
|
|
490 |
!Arguments.CREATE_JRE_INSTALLER.fetchFrom(p)) &&
|
|
491 |
!Log.isDebug() &&
|
|
492 |
!Log.isVerbose()) {
|
|
493 |
IOUtils.deleteRecursive(imageDir);
|
|
494 |
} else if (imageDir != null) {
|
|
495 |
Log.verbose(MessageFormat.format(
|
|
496 |
I18N.getString("message.debug-working-directory"),
|
|
497 |
imageDir.getAbsolutePath()));
|
|
498 |
}
|
|
499 |
} catch (IOException ex) {
|
|
500 |
// noinspection ReturnInsideFinallyBlock
|
|
501 |
Log.debug(ex.getMessage());
|
|
502 |
return null;
|
|
503 |
}
|
|
504 |
}
|
|
505 |
}
|
|
506 |
|
|
507 |
// name of post-image script
|
|
508 |
private File getConfig_Script(Map<String, ? super Object> p) {
|
|
509 |
return new File(EXE_IMAGE_DIR.fetchFrom(p),
|
|
510 |
APP_NAME.fetchFrom(p) + "-post-image.wsf");
|
|
511 |
}
|
|
512 |
|
|
513 |
private String getAppIdentifier(Map<String, ? super Object> p) {
|
|
514 |
String nm = IDENTIFIER.fetchFrom(p);
|
|
515 |
|
|
516 |
if (nm == null) {
|
|
517 |
nm = APP_NAME.fetchFrom(p);
|
|
518 |
}
|
|
519 |
|
|
520 |
// limitation of innosetup
|
|
521 |
if (nm.length() > 126) {
|
|
522 |
Log.error(getString("message-truncating-id"));
|
|
523 |
nm = nm.substring(0, 126);
|
|
524 |
}
|
|
525 |
|
|
526 |
return nm;
|
|
527 |
}
|
|
528 |
|
|
529 |
|
|
530 |
private String getLicenseFile(Map<String, ? super Object> p) {
|
|
531 |
List<String> licenseFiles = LICENSE_FILE.fetchFrom(p);
|
|
532 |
if (licenseFiles == null || licenseFiles.isEmpty()) {
|
|
533 |
return "";
|
|
534 |
} else {
|
|
535 |
return licenseFiles.get(0);
|
|
536 |
}
|
|
537 |
}
|
|
538 |
|
|
539 |
void validateValueAndPut(Map<String, String> data, String key,
|
|
540 |
BundlerParamInfo<String> param,
|
|
541 |
Map<String, ? super Object> p) throws IOException {
|
|
542 |
String value = param.fetchFrom(p);
|
|
543 |
if (value.contains("\r") || value.contains("\n")) {
|
|
544 |
throw new IOException("Configuration Parameter " +
|
|
545 |
param.getID() + " cannot contain multiple lines of text");
|
|
546 |
}
|
|
547 |
data.put(key, innosetupEscape(value));
|
|
548 |
}
|
|
549 |
|
|
550 |
private String innosetupEscape(String value) {
|
|
551 |
if (value.contains("\"") || !value.trim().equals(value)) {
|
|
552 |
value = "\"" + value.replace("\"", "\"\"") + "\"";
|
|
553 |
}
|
|
554 |
return value;
|
|
555 |
}
|
|
556 |
|
|
557 |
boolean prepareMainProjectFile(Map<String, ? super Object> p)
|
|
558 |
throws IOException {
|
|
559 |
Map<String, String> data = new HashMap<>();
|
|
560 |
data.put("PRODUCT_APP_IDENTIFIER",
|
|
561 |
innosetupEscape(getAppIdentifier(p)));
|
|
562 |
|
|
563 |
|
|
564 |
validateValueAndPut(data, "INSTALLER_NAME", APP_NAME, p);
|
|
565 |
validateValueAndPut(data, "APPLICATION_VENDOR", VENDOR, p);
|
|
566 |
validateValueAndPut(data, "APPLICATION_VERSION", VERSION, p);
|
|
567 |
validateValueAndPut(data, "INSTALLER_FILE_NAME",
|
|
568 |
INSTALLER_FILE_NAME, p);
|
|
569 |
|
|
570 |
data.put("LAUNCHER_NAME",
|
|
571 |
innosetupEscape(WinAppBundler.getAppName(p)));
|
|
572 |
|
|
573 |
data.put("APPLICATION_LAUNCHER_FILENAME",
|
|
574 |
innosetupEscape(WinAppBundler.getLauncherName(p)));
|
|
575 |
|
|
576 |
data.put("APPLICATION_DESKTOP_SHORTCUT",
|
|
577 |
SHORTCUT_HINT.fetchFrom(p) ? "returnTrue" : "returnFalse");
|
|
578 |
data.put("APPLICATION_MENU_SHORTCUT",
|
|
579 |
MENU_HINT.fetchFrom(p) ? "returnTrue" : "returnFalse");
|
|
580 |
validateValueAndPut(data, "APPLICATION_GROUP", MENU_GROUP, p);
|
|
581 |
validateValueAndPut(data, "APPLICATION_COMMENTS", TITLE, p);
|
|
582 |
validateValueAndPut(data, "APPLICATION_COPYRIGHT", COPYRIGHT, p);
|
|
583 |
|
|
584 |
data.put("APPLICATION_LICENSE_FILE",
|
|
585 |
innosetupEscape(getLicenseFile(p)));
|
|
586 |
data.put("DISABLE_DIR_PAGE",
|
|
587 |
INSTALLDIR_CHOOSER.fetchFrom(p) ? "No" : "Yes");
|
|
588 |
|
|
589 |
Boolean isSystemWide = EXE_SYSTEM_WIDE.fetchFrom(p);
|
|
590 |
|
|
591 |
if (isSystemWide) {
|
|
592 |
data.put("APPLICATION_INSTALL_ROOT", "{pf}");
|
|
593 |
data.put("APPLICATION_INSTALL_PRIVILEGE", "admin");
|
|
594 |
} else {
|
|
595 |
data.put("APPLICATION_INSTALL_ROOT", "{localappdata}");
|
|
596 |
data.put("APPLICATION_INSTALL_PRIVILEGE", "lowest");
|
|
597 |
}
|
|
598 |
|
|
599 |
if (BIT_ARCH_64.fetchFrom(p)) {
|
|
600 |
data.put("ARCHITECTURE_BIT_MODE", "x64");
|
|
601 |
} else {
|
|
602 |
data.put("ARCHITECTURE_BIT_MODE", "");
|
|
603 |
}
|
|
604 |
validateValueAndPut(data, "RUN_FILENAME", APP_NAME, p);
|
|
605 |
|
|
606 |
validateValueAndPut(data, "APPLICATION_DESCRIPTION",
|
|
607 |
DESCRIPTION, p);
|
|
608 |
|
|
609 |
data.put("APPLICATION_SERVICE", "returnFalse");
|
|
610 |
data.put("APPLICATION_NOT_SERVICE", "returnFalse");
|
|
611 |
data.put("APPLICATION_APP_CDS_INSTALL", "returnFalse");
|
|
612 |
data.put("START_ON_INSTALL", "");
|
|
613 |
data.put("STOP_ON_UNINSTALL", "");
|
|
614 |
data.put("RUN_AT_STARTUP", "");
|
|
615 |
|
|
616 |
StringBuilder secondaryLaunchersCfg = new StringBuilder();
|
|
617 |
for (Map<String, ? super Object>
|
|
618 |
launcher : SECONDARY_LAUNCHERS.fetchFrom(p)) {
|
|
619 |
String application_name = APP_NAME.fetchFrom(launcher);
|
|
620 |
if (MENU_HINT.fetchFrom(launcher)) {
|
|
621 |
// Name: "{group}\APPLICATION_NAME";
|
|
622 |
// Filename: "{app}\APPLICATION_NAME.exe";
|
|
623 |
// IconFilename: "{app}\APPLICATION_NAME.ico"
|
|
624 |
secondaryLaunchersCfg.append("Name: \"{group}\\");
|
|
625 |
secondaryLaunchersCfg.append(application_name);
|
|
626 |
secondaryLaunchersCfg.append("\"; Filename: \"{app}\\");
|
|
627 |
secondaryLaunchersCfg.append(application_name);
|
|
628 |
secondaryLaunchersCfg.append(".exe\"; IconFilename: \"{app}\\");
|
|
629 |
secondaryLaunchersCfg.append(application_name);
|
|
630 |
secondaryLaunchersCfg.append(".ico\"\r\n");
|
|
631 |
}
|
|
632 |
if (SHORTCUT_HINT.fetchFrom(launcher)) {
|
|
633 |
// Name: "{commondesktop}\APPLICATION_NAME";
|
|
634 |
// Filename: "{app}\APPLICATION_NAME.exe";
|
|
635 |
// IconFilename: "{app}\APPLICATION_NAME.ico"
|
|
636 |
secondaryLaunchersCfg.append("Name: \"{commondesktop}\\");
|
|
637 |
secondaryLaunchersCfg.append(application_name);
|
|
638 |
secondaryLaunchersCfg.append("\"; Filename: \"{app}\\");
|
|
639 |
secondaryLaunchersCfg.append(application_name);
|
|
640 |
secondaryLaunchersCfg.append(".exe\"; IconFilename: \"{app}\\");
|
|
641 |
secondaryLaunchersCfg.append(application_name);
|
|
642 |
secondaryLaunchersCfg.append(".ico\"\r\n");
|
|
643 |
}
|
|
644 |
}
|
|
645 |
data.put("SECONDARY_LAUNCHERS", secondaryLaunchersCfg.toString());
|
|
646 |
|
|
647 |
StringBuilder registryEntries = new StringBuilder();
|
|
648 |
String regName = APP_REGISTRY_NAME.fetchFrom(p);
|
|
649 |
List<Map<String, ? super Object>> fetchFrom =
|
|
650 |
FILE_ASSOCIATIONS.fetchFrom(p);
|
|
651 |
for (int i = 0; i < fetchFrom.size(); i++) {
|
|
652 |
Map<String, ? super Object> fileAssociation = fetchFrom.get(i);
|
|
653 |
String description = FA_DESCRIPTION.fetchFrom(fileAssociation);
|
|
654 |
File icon = FA_ICON.fetchFrom(fileAssociation); //TODO FA_ICON_ICO
|
|
655 |
|
|
656 |
List<String> extensions = FA_EXTENSIONS.fetchFrom(fileAssociation);
|
|
657 |
String entryName = regName + "File";
|
|
658 |
if (i > 0) {
|
|
659 |
entryName += "." + i;
|
|
660 |
}
|
|
661 |
|
|
662 |
if (extensions == null) {
|
|
663 |
Log.verbose(getString(
|
|
664 |
"message.creating-association-with-null-extension"));
|
|
665 |
} else {
|
|
666 |
for (String ext : extensions) {
|
|
667 |
if (isSystemWide) {
|
|
668 |
// "Root: HKCR; Subkey: \".myp\";
|
|
669 |
// ValueType: string; ValueName: \"\";
|
|
670 |
// ValueData: \"MyProgramFile\";
|
|
671 |
// Flags: uninsdeletevalue"
|
|
672 |
registryEntries.append("Root: HKCR; Subkey: \".")
|
|
673 |
.append(ext)
|
|
674 |
.append("\"; ValueType: string;"
|
|
675 |
+ " ValueName: \"\"; ValueData: \"")
|
|
676 |
.append(entryName)
|
|
677 |
.append("\"; Flags: uninsdeletevalue\r\n");
|
|
678 |
} else {
|
|
679 |
registryEntries.append(
|
|
680 |
"Root: HKCU; Subkey: \"Software\\Classes\\.")
|
|
681 |
.append(ext)
|
|
682 |
.append("\"; ValueType: string;"
|
|
683 |
+ " ValueName: \"\"; ValueData: \"")
|
|
684 |
.append(entryName)
|
|
685 |
.append("\"; Flags: uninsdeletevalue\r\n");
|
|
686 |
}
|
|
687 |
}
|
|
688 |
}
|
|
689 |
|
|
690 |
if (extensions != null && !extensions.isEmpty()) {
|
|
691 |
String ext = extensions.get(0);
|
|
692 |
List<String> mimeTypes =
|
|
693 |
FA_CONTENT_TYPE.fetchFrom(fileAssociation);
|
|
694 |
for (String mime : mimeTypes) {
|
|
695 |
if (isSystemWide) {
|
|
696 |
// "Root: HKCR;
|
|
697 |
// Subkey: HKCR\\Mime\\Database\\
|
|
698 |
// Content Type\\application/chaos;
|
|
699 |
// ValueType: string;
|
|
700 |
// ValueName: Extension;
|
|
701 |
// ValueData: .chaos;
|
|
702 |
// Flags: uninsdeletevalue"
|
|
703 |
registryEntries.append("Root: HKCR; Subkey: " +
|
|
704 |
"\"Mime\\Database\\Content Type\\")
|
|
705 |
.append(mime)
|
|
706 |
.append("\"; ValueType: string; ValueName: " +
|
|
707 |
"\"Extension\"; ValueData: \".")
|
|
708 |
.append(ext)
|
|
709 |
.append("\"; Flags: uninsdeletevalue\r\n");
|
|
710 |
} else {
|
|
711 |
registryEntries.append(
|
|
712 |
"Root: HKCU; Subkey: \"Software\\" +
|
|
713 |
"Classes\\Mime\\Database\\Content Type\\")
|
|
714 |
.append(mime)
|
|
715 |
.append("\"; ValueType: string; " +
|
|
716 |
"ValueName: \"Extension\"; ValueData: \".")
|
|
717 |
.append(ext)
|
|
718 |
.append("\"; Flags: uninsdeletevalue\r\n");
|
|
719 |
}
|
|
720 |
}
|
|
721 |
}
|
|
722 |
|
|
723 |
if (isSystemWide) {
|
|
724 |
// "Root: HKCR;
|
|
725 |
// Subkey: \"MyProgramFile\";
|
|
726 |
// ValueType: string;
|
|
727 |
// ValueName: \"\";
|
|
728 |
// ValueData: \"My Program File\";
|
|
729 |
// Flags: uninsdeletekey"
|
|
730 |
registryEntries.append("Root: HKCR; Subkey: \"")
|
|
731 |
.append(entryName)
|
|
732 |
.append(
|
|
733 |
"\"; ValueType: string; ValueName: \"\"; ValueData: \"")
|
|
734 |
.append(removeQuotes(description))
|
|
735 |
.append("\"; Flags: uninsdeletekey\r\n");
|
|
736 |
} else {
|
|
737 |
registryEntries.append(
|
|
738 |
"Root: HKCU; Subkey: \"Software\\Classes\\")
|
|
739 |
.append(entryName)
|
|
740 |
.append(
|
|
741 |
"\"; ValueType: string; ValueName: \"\"; ValueData: \"")
|
|
742 |
.append(removeQuotes(description))
|
|
743 |
.append("\"; Flags: uninsdeletekey\r\n");
|
|
744 |
}
|
|
745 |
|
|
746 |
if (icon != null && icon.exists()) {
|
|
747 |
if (isSystemWide) {
|
|
748 |
// "Root: HKCR;
|
|
749 |
// Subkey: \"MyProgramFile\\DefaultIcon\";
|
|
750 |
// ValueType: string;
|
|
751 |
// ValueName: \"\";
|
|
752 |
// ValueData: \"{app}\\MYPROG.EXE,0\"\n" +
|
|
753 |
registryEntries.append("Root: HKCR; Subkey: \"")
|
|
754 |
.append(entryName)
|
|
755 |
.append("\\DefaultIcon\"; ValueType: string; " +
|
|
756 |
"ValueName: \"\"; ValueData: \"{app}\\")
|
|
757 |
.append(icon.getName())
|
|
758 |
.append("\"\r\n");
|
|
759 |
} else {
|
|
760 |
registryEntries.append(
|
|
761 |
"Root: HKCU; Subkey: \"Software\\Classes\\")
|
|
762 |
.append(entryName)
|
|
763 |
.append("\\DefaultIcon\"; ValueType: string; " +
|
|
764 |
"ValueName: \"\"; ValueData: \"{app}\\")
|
|
765 |
.append(icon.getName())
|
|
766 |
.append("\"\r\n");
|
|
767 |
}
|
|
768 |
}
|
|
769 |
|
|
770 |
if (isSystemWide) {
|
|
771 |
// "Root: HKCR;
|
|
772 |
// Subkey: \"MyProgramFile\\shell\\open\\command\";
|
|
773 |
// ValueType: string;
|
|
774 |
// ValueName: \"\";
|
|
775 |
// ValueData: \"\"\"{app}\\MYPROG.EXE\"\" \"\"%1\"\"\"\n"
|
|
776 |
registryEntries.append("Root: HKCR; Subkey: \"")
|
|
777 |
.append(entryName)
|
|
778 |
.append("\\shell\\open\\command\"; ValueType: " +
|
|
779 |
"string; ValueName: \"\"; ValueData: \"\"\"{app}\\")
|
|
780 |
.append(APP_NAME.fetchFrom(p))
|
|
781 |
.append("\"\" \"\"%1\"\"\"\r\n");
|
|
782 |
} else {
|
|
783 |
registryEntries.append(
|
|
784 |
"Root: HKCU; Subkey: \"Software\\Classes\\")
|
|
785 |
.append(entryName)
|
|
786 |
.append("\\shell\\open\\command\"; ValueType: " +
|
|
787 |
"string; ValueName: \"\"; ValueData: \"\"\"{app}\\")
|
|
788 |
.append(APP_NAME.fetchFrom(p))
|
|
789 |
.append("\"\" \"\"%1\"\"\"\r\n");
|
|
790 |
}
|
|
791 |
}
|
|
792 |
if (registryEntries.length() > 0) {
|
|
793 |
data.put("FILE_ASSOCIATIONS",
|
|
794 |
"ChangesAssociations=yes\r\n\r\n[Registry]\r\n" +
|
|
795 |
registryEntries.toString());
|
|
796 |
} else {
|
|
797 |
data.put("FILE_ASSOCIATIONS", "");
|
|
798 |
}
|
|
799 |
|
|
800 |
// TODO - alternate template for JRE installer
|
|
801 |
String iss = Arguments.CREATE_JRE_INSTALLER.fetchFrom(p) ?
|
|
802 |
DEFAULT_JRE_EXE_TEMPLATE : DEFAULT_EXE_PROJECT_TEMPLATE;
|
|
803 |
|
|
804 |
Writer w = new BufferedWriter(new FileWriter(
|
|
805 |
getConfig_ExeProjectFile(p)));
|
|
806 |
|
|
807 |
String content = preprocessTextResource(
|
|
808 |
WinAppBundler.WIN_BUNDLER_PREFIX +
|
|
809 |
getConfig_ExeProjectFile(p).getName(),
|
|
810 |
getString("resource.inno-setup-project-file"),
|
|
811 |
iss, data, VERBOSE.fetchFrom(p),
|
|
812 |
DROP_IN_RESOURCES_ROOT.fetchFrom(p));
|
|
813 |
w.write(content);
|
|
814 |
w.close();
|
|
815 |
return true;
|
|
816 |
}
|
|
817 |
|
|
818 |
private final static String removeQuotes(String s) {
|
|
819 |
if (s.length() > 2 && s.startsWith("\"") && s.endsWith("\"")) {
|
|
820 |
// special case for '"XXX"' return 'XXX' not '-XXX-'
|
|
821 |
// note '"' and '""' are excluded from this special case
|
|
822 |
s = s.substring(1, s.length() - 1);
|
|
823 |
}
|
|
824 |
// if there interior double quotes replace them with '-'
|
|
825 |
return s.replaceAll("\"", "-");
|
|
826 |
}
|
|
827 |
|
|
828 |
private final static String DEFAULT_INNO_SETUP_ICON =
|
|
829 |
"icon_inno_setup.bmp";
|
|
830 |
|
|
831 |
private boolean prepareProjectConfig(Map<String, ? super Object> p)
|
|
832 |
throws IOException {
|
|
833 |
prepareMainProjectFile(p);
|
|
834 |
|
|
835 |
// prepare installer icon
|
|
836 |
File iconTarget = getConfig_SmallInnoSetupIcon(p);
|
|
837 |
fetchResource(WinAppBundler.WIN_BUNDLER_PREFIX + iconTarget.getName(),
|
|
838 |
getString("resource.setup-icon"),
|
|
839 |
DEFAULT_INNO_SETUP_ICON,
|
|
840 |
iconTarget,
|
|
841 |
VERBOSE.fetchFrom(p),
|
|
842 |
DROP_IN_RESOURCES_ROOT.fetchFrom(p));
|
|
843 |
|
|
844 |
fetchResource(WinAppBundler.WIN_BUNDLER_PREFIX +
|
|
845 |
getConfig_Script(p).getName(),
|
|
846 |
getString("resource.post-install-script"),
|
|
847 |
(String) null,
|
|
848 |
getConfig_Script(p),
|
|
849 |
VERBOSE.fetchFrom(p),
|
|
850 |
DROP_IN_RESOURCES_ROOT.fetchFrom(p));
|
|
851 |
return true;
|
|
852 |
}
|
|
853 |
|
|
854 |
private File getConfig_SmallInnoSetupIcon(
|
|
855 |
Map<String, ? super Object> p) {
|
|
856 |
return new File(EXE_IMAGE_DIR.fetchFrom(p),
|
|
857 |
APP_NAME.fetchFrom(p) + "-setup-icon.bmp");
|
|
858 |
}
|
|
859 |
|
|
860 |
private File getConfig_ExeProjectFile(Map<String, ? super Object> p) {
|
|
861 |
return new File(EXE_IMAGE_DIR.fetchFrom(p),
|
|
862 |
APP_NAME.fetchFrom(p) + ".iss");
|
|
863 |
}
|
|
864 |
|
|
865 |
|
|
866 |
private File buildEXE(Map<String, ? super Object> p, File outdir)
|
|
867 |
throws IOException {
|
|
868 |
Log.verbose(MessageFormat.format(
|
|
869 |
getString("message.outputting-to-location"),
|
|
870 |
outdir.getAbsolutePath()));
|
|
871 |
|
|
872 |
outdir.mkdirs();
|
|
873 |
|
|
874 |
// run Inno Setup
|
|
875 |
ProcessBuilder pb = new ProcessBuilder(
|
|
876 |
TOOL_INNO_SETUP_COMPILER_EXECUTABLE.fetchFrom(p),
|
|
877 |
"/q", // turn off inno setup output
|
|
878 |
"/o"+outdir.getAbsolutePath(),
|
|
879 |
getConfig_ExeProjectFile(p).getAbsolutePath());
|
|
880 |
pb = pb.directory(EXE_IMAGE_DIR.fetchFrom(p));
|
|
881 |
IOUtils.exec(pb, VERBOSE.fetchFrom(p));
|
|
882 |
|
|
883 |
Log.verbose(MessageFormat.format(
|
|
884 |
getString("message.output-location"),
|
|
885 |
outdir.getAbsolutePath()));
|
|
886 |
|
|
887 |
// presume the result is the ".exe" file with the newest modified time
|
|
888 |
// not the best solution, but it is the most reliable
|
|
889 |
File result = null;
|
|
890 |
long lastModified = 0;
|
|
891 |
File[] list = outdir.listFiles();
|
|
892 |
if (list != null) {
|
|
893 |
for (File f : list) {
|
|
894 |
if (f.getName().endsWith(".exe") &&
|
|
895 |
f.lastModified() > lastModified) {
|
|
896 |
result = f;
|
|
897 |
lastModified = f.lastModified();
|
|
898 |
}
|
|
899 |
}
|
|
900 |
}
|
|
901 |
|
|
902 |
return result;
|
|
903 |
}
|
|
904 |
|
|
905 |
public static void ensureByMutationFileIsRTF(File f) {
|
|
906 |
if (f == null || !f.isFile()) return;
|
|
907 |
|
|
908 |
try {
|
|
909 |
boolean existingLicenseIsRTF = false;
|
|
910 |
|
|
911 |
try (FileInputStream fin = new FileInputStream(f)) {
|
|
912 |
byte[] firstBits = new byte[7];
|
|
913 |
|
|
914 |
if (fin.read(firstBits) == firstBits.length) {
|
|
915 |
String header = new String(firstBits);
|
|
916 |
existingLicenseIsRTF = "{\\rtf1\\".equals(header);
|
|
917 |
}
|
|
918 |
}
|
|
919 |
|
|
920 |
if (!existingLicenseIsRTF) {
|
|
921 |
List<String> oldLicense = Files.readAllLines(f.toPath());
|
|
922 |
try (Writer w = Files.newBufferedWriter(
|
|
923 |
f.toPath(), Charset.forName("Windows-1252"))) {
|
|
924 |
w.write("{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033"
|
|
925 |
+ "{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}}\n"
|
|
926 |
+ "\\viewkind4\\uc1\\pard\\sa200\\sl276"
|
|
927 |
+ "\\slmult1\\lang9\\fs20 ");
|
|
928 |
oldLicense.forEach(l -> {
|
|
929 |
try {
|
|
930 |
for (char c : l.toCharArray()) {
|
|
931 |
if (c < 0x10) {
|
|
932 |
w.write("\\'0");
|
|
933 |
w.write(Integer.toHexString(c));
|
|
934 |
} else if (c > 0xff) {
|
|
935 |
w.write("\\ud");
|
|
936 |
w.write(Integer.toString(c));
|
|
937 |
w.write("?");
|
|
938 |
} else if ((c < 0x20) || (c >= 0x80) ||
|
|
939 |
(c == 0x5C) || (c == 0x7B) ||
|
|
940 |
(c == 0x7D)) {
|
|
941 |
w.write("\\'");
|
|
942 |
w.write(Integer.toHexString(c));
|
|
943 |
} else {
|
|
944 |
w.write(c);
|
|
945 |
}
|
|
946 |
}
|
|
947 |
if (l.length() < 1) {
|
|
948 |
w.write("\\par");
|
|
949 |
} else {
|
|
950 |
w.write(" ");
|
|
951 |
}
|
|
952 |
w.write("\r\n");
|
|
953 |
} catch (IOException e) {
|
|
954 |
Log.verbose(e);
|
|
955 |
}
|
|
956 |
});
|
|
957 |
w.write("}\r\n");
|
|
958 |
}
|
|
959 |
}
|
|
960 |
} catch (IOException e) {
|
|
961 |
Log.verbose(e);
|
|
962 |
}
|
|
963 |
}
|
|
964 |
|
|
965 |
private static String getString(String key)
|
|
966 |
throws MissingResourceException {
|
|
967 |
return I18N.getString(key);
|
|
968 |
}
|
|
969 |
}
|