39 import java.io.IOException;
40 import java.io.InputStream;
41 import java.io.OutputStream;
42 import java.io.OutputStreamWriter;
43 import java.io.UncheckedIOException;
44 import java.io.Writer;
45 import java.io.BufferedWriter;
46 import java.io.FileWriter;
47 import java.nio.file.Files;
48 import java.nio.file.Path;
49 import java.nio.file.attribute.PosixFilePermission;
50 import java.text.MessageFormat;
51 import java.util.HashMap;
52 import java.util.List;
53 import java.util.Map;
54 import java.util.Objects;
55 import java.util.ResourceBundle;
56 import java.util.Set;
57 import java.util.concurrent.atomic.AtomicReference;
58 import java.util.regex.Pattern;
59
60 import static com.oracle.tools.packager.StandardBundlerParam.*;
61
62 /**
63 *
64 */
65 public class WindowsAppImageBuilder extends AbstractAppImageBuilder {
66
67 private static final ResourceBundle I18N =
68 ResourceBundle.getBundle(WindowsAppImageBuilder.class.getName());
69
70 protected static final String WINDOWS_BUNDLER_PREFIX =
71 BUNDLER_PREFIX + "windows" + File.separator;
72
73 private final static String EXECUTABLE_NAME = "WinLauncher.exe";
74 private final static String LIBRARY_NAME = "packager.dll";
75
76 private final static String[] VS_VERS = {"100", "110", "120"};
77 private final static String REDIST_MSVCR = "msvcrVS_VER.dll";
78 private final static String REDIST_MSVCP = "msvcpVS_VER.dll";
272 }
273
274 }
275
276 private void copyMSVCDLLs() throws IOException {
277 String vsVer = null;
278
279 // first copy the ones needed for the launcher
280 for (String thisVer : VS_VERS) {
281 if (copyMSVCDLLs(thisVer)) {
282 vsVer = thisVer;
283 break;
284 }
285 }
286 if (vsVer == null) {
287 throw new RuntimeException("Not found MSVC dlls");
288 }
289
290 AtomicReference<IOException> ioe = new AtomicReference<>();
291 final String finalVsVer = vsVer;
292 Files.list(runtimeDir.resolve("bin"))
293 .filter(p -> Pattern.matches("msvc(r|p)\\d\\d\\d.dll", p.toFile().getName().toLowerCase()))
294 .filter(p -> !p.toString().toLowerCase().endsWith(finalVsVer + ".dll"))
295 .forEach(p -> {
296 try {
297 Files.copy(p, root.resolve((p.toFile().getName())));
298 } catch (IOException e) {
299 ioe.set(e);
300 }
301 });
302
303 IOException e = ioe.get();
304 if (e != null) {
305 throw e;
306 }
307 }
308
309 private boolean copyMSVCDLLs(String VS_VER) throws IOException {
310 final InputStream REDIST_MSVCR_URL = WinResources.class.getResourceAsStream(
311 REDIST_MSVCR.replaceAll("VS_VER", VS_VER));
312 final InputStream REDIST_MSVCP_URL = WinResources.class.getResourceAsStream(
313 REDIST_MSVCP.replaceAll("VS_VER", VS_VER));
314
315 if (REDIST_MSVCR_URL != null && REDIST_MSVCP_URL != null) {
316 Files.copy(
317 REDIST_MSVCR_URL,
318 root.resolve(REDIST_MSVCR.replaceAll("VS_VER", VS_VER)));
319 Files.copy(
320 REDIST_MSVCP_URL,
321 root.resolve(REDIST_MSVCP.replaceAll("VS_VER", VS_VER)));
|
39 import java.io.IOException;
40 import java.io.InputStream;
41 import java.io.OutputStream;
42 import java.io.OutputStreamWriter;
43 import java.io.UncheckedIOException;
44 import java.io.Writer;
45 import java.io.BufferedWriter;
46 import java.io.FileWriter;
47 import java.nio.file.Files;
48 import java.nio.file.Path;
49 import java.nio.file.attribute.PosixFilePermission;
50 import java.text.MessageFormat;
51 import java.util.HashMap;
52 import java.util.List;
53 import java.util.Map;
54 import java.util.Objects;
55 import java.util.ResourceBundle;
56 import java.util.Set;
57 import java.util.concurrent.atomic.AtomicReference;
58 import java.util.regex.Pattern;
59 import java.util.stream.Stream;
60
61 import static com.oracle.tools.packager.StandardBundlerParam.*;
62
63 /**
64 *
65 */
66 public class WindowsAppImageBuilder extends AbstractAppImageBuilder {
67
68 private static final ResourceBundle I18N =
69 ResourceBundle.getBundle(WindowsAppImageBuilder.class.getName());
70
71 protected static final String WINDOWS_BUNDLER_PREFIX =
72 BUNDLER_PREFIX + "windows" + File.separator;
73
74 private final static String EXECUTABLE_NAME = "WinLauncher.exe";
75 private final static String LIBRARY_NAME = "packager.dll";
76
77 private final static String[] VS_VERS = {"100", "110", "120"};
78 private final static String REDIST_MSVCR = "msvcrVS_VER.dll";
79 private final static String REDIST_MSVCP = "msvcpVS_VER.dll";
273 }
274
275 }
276
277 private void copyMSVCDLLs() throws IOException {
278 String vsVer = null;
279
280 // first copy the ones needed for the launcher
281 for (String thisVer : VS_VERS) {
282 if (copyMSVCDLLs(thisVer)) {
283 vsVer = thisVer;
284 break;
285 }
286 }
287 if (vsVer == null) {
288 throw new RuntimeException("Not found MSVC dlls");
289 }
290
291 AtomicReference<IOException> ioe = new AtomicReference<>();
292 final String finalVsVer = vsVer;
293 try (Stream<Path> files = Files.list(runtimeDir.resolve("bin"))) {
294 files.filter(p -> Pattern.matches("msvc(r|p)\\d\\d\\d.dll", p.toFile().getName().toLowerCase()))
295 .filter(p -> !p.toString().toLowerCase().endsWith(finalVsVer + ".dll"))
296 .forEach(p -> {
297 try {
298 Files.copy(p, root.resolve((p.toFile().getName())));
299 } catch (IOException e) {
300 ioe.set(e);
301 }
302 });
303 }
304
305 IOException e = ioe.get();
306 if (e != null) {
307 throw e;
308 }
309 }
310
311 private boolean copyMSVCDLLs(String VS_VER) throws IOException {
312 final InputStream REDIST_MSVCR_URL = WinResources.class.getResourceAsStream(
313 REDIST_MSVCR.replaceAll("VS_VER", VS_VER));
314 final InputStream REDIST_MSVCP_URL = WinResources.class.getResourceAsStream(
315 REDIST_MSVCP.replaceAll("VS_VER", VS_VER));
316
317 if (REDIST_MSVCR_URL != null && REDIST_MSVCP_URL != null) {
318 Files.copy(
319 REDIST_MSVCR_URL,
320 root.resolve(REDIST_MSVCR.replaceAll("VS_VER", VS_VER)));
321 Files.copy(
322 REDIST_MSVCP_URL,
323 root.resolve(REDIST_MSVCP.replaceAll("VS_VER", VS_VER)));
|