24 */ |
24 */ |
25 |
25 |
26 package jdk.jpackage.internal; |
26 package jdk.jpackage.internal; |
27 |
27 |
28 import java.io.IOException; |
28 import java.io.IOException; |
29 import java.nio.file.FileSystems; |
29 import java.nio.file.*; |
30 import java.nio.file.Files; |
|
31 import java.nio.file.Path; |
|
32 import java.nio.file.PathMatcher; |
|
33 import java.text.MessageFormat; |
30 import java.text.MessageFormat; |
34 import java.util.*; |
31 import java.util.*; |
35 import java.util.function.Supplier; |
32 import java.util.function.Supplier; |
36 import java.util.stream.Collectors; |
33 import java.util.stream.Collectors; |
37 import java.util.stream.Stream; |
34 import java.util.stream.Stream; |
117 })::validate; |
114 })::validate; |
118 } |
115 } |
119 |
116 |
120 private final static String MINIMAL_VERSION = "3.0"; |
117 private final static String MINIMAL_VERSION = "3.0"; |
121 |
118 |
122 private final static Path PROGRAM_FILES = Path.of("C:\\Program Files"); |
119 static Path getSystemDir(String envVar, String knownDir) { |
123 private final static Path PROGRAM_FILES_X86 = Path.of("C:\\Program Files (x86)"); |
120 return Optional |
|
121 .ofNullable(getEnvVariableAsPath(envVar)) |
|
122 .orElseGet(() -> Optional |
|
123 .ofNullable(getEnvVariableAsPath("SystemDrive")) |
|
124 .orElseGet(() -> Path.of("C:")).resolve(knownDir)); |
|
125 } |
|
126 |
|
127 private static Path getEnvVariableAsPath(String envVar) { |
|
128 String path = System.getenv(envVar); |
|
129 if (path != null) { |
|
130 try { |
|
131 return Path.of(path); |
|
132 } catch (InvalidPathException ex) { |
|
133 Log.error(MessageFormat.format(I18N.getString( |
|
134 "error.invalid-envvar"), envVar)); |
|
135 return null; |
|
136 } |
|
137 } |
|
138 return null; |
|
139 } |
124 |
140 |
125 private static List<Path> findWixInstallDirs() { |
141 private static List<Path> findWixInstallDirs() { |
126 PathMatcher wixInstallDirMatcher = FileSystems.getDefault().getPathMatcher( |
142 PathMatcher wixInstallDirMatcher = FileSystems.getDefault().getPathMatcher( |
127 "glob:WiX Toolset v*"); |
143 "glob:WiX Toolset v*"); |
128 |
144 |
|
145 Path programFiles = getSystemDir("ProgramFiles", "Program Files"); |
|
146 Path programFilesX86 = getSystemDir("ProgramFiles(X86)", |
|
147 "Program Files (x86)"); |
|
148 |
129 // Returns list of WiX install directories ordered by WiX version number. |
149 // Returns list of WiX install directories ordered by WiX version number. |
130 // Newer versions go first. |
150 // Newer versions go first. |
131 return Stream.of(PROGRAM_FILES, PROGRAM_FILES_X86).map(path -> { |
151 return Stream.of(programFiles, programFilesX86).map(path -> { |
132 List<Path> result; |
152 List<Path> result; |
133 try (var paths = Files.walk(path, 1)) { |
153 try (var paths = Files.walk(path, 1)) { |
134 result = paths.collect(Collectors.toList()); |
154 result = paths.collect(Collectors.toList()); |
135 } catch (IOException ex) { |
155 } catch (IOException ex) { |
136 Log.verbose(ex); |
156 Log.verbose(ex); |