< prev index next >

src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java

Print this page




 404     private boolean prepareProto(Map<String, ? super Object> params)
 405                 throws PackagerException, IOException {
 406         File appImage = StandardBundlerParam.getPredefinedAppImage(params);
 407         File appDir = null;
 408 
 409         // we either have an application image or need to build one
 410         if (appImage != null) {
 411             appDir = new File(MSI_IMAGE_DIR.fetchFrom(params),
 412                     APP_NAME.fetchFrom(params));
 413             // copy everything from appImage dir into appDir/name
 414             IOUtils.copyRecursive(appImage.toPath(), appDir.toPath());
 415         } else {
 416             appDir = APP_BUNDLER.fetchFrom(params).doBundle(params,
 417                     MSI_IMAGE_DIR.fetchFrom(params), true);
 418         }
 419 
 420         params.put(WIN_APP_IMAGE.getID(), appDir);
 421 
 422         String licenseFile = LICENSE_FILE.fetchFrom(params);
 423         if (licenseFile != null) {
 424             // need to copy license file to the working directory and convert to rtf if needed

 425             File lfile = new File(licenseFile);
 426             File destFile = new File(CONFIG_ROOT.fetchFrom(params),
 427                     lfile.getName());
 428 
 429             IOUtils.copyFile(lfile, destFile);
 430             destFile.setWritable(true);
 431             ensureByMutationFileIsRTF(destFile);
 432         }
 433 
 434         // copy file association icons
 435         List<Map<String, ? super Object>> fileAssociations =
 436                 FILE_ASSOCIATIONS.fetchFrom(params);
 437         for (Map<String, ? super Object> fa : fileAssociations) {
 438             File icon = FA_ICON.fetchFrom(fa);
 439             if (icon == null) {
 440                 continue;
 441             }
 442 
 443             File faIconFile = new File(appDir, icon.getName());
 444 


 537 
 538     private void prepareIconsFile(
 539             Map<String, ? super Object> params) throws IOException {
 540 
 541         File imageRootDir = WIN_APP_IMAGE.fetchFrom(params);
 542 
 543         List<Map<String, ? super Object>> addLaunchers =
 544                 ADD_LAUNCHERS.fetchFrom(params);
 545 
 546         XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance();
 547         try (Writer w = new BufferedWriter(new FileWriter(new File(
 548                 CONFIG_ROOT.fetchFrom(params), "icons.wxi")))) {
 549             XMLStreamWriter xml = xmlFactory.createXMLStreamWriter(w);
 550 
 551             xml.writeStartDocument();
 552             xml.writeStartElement("Include");
 553 
 554             File launcher = new File(imageRootDir,
 555                     WinAppBundler.getLauncherRelativePath(params));
 556             if (launcher.exists()) {
 557                 String iconPath = launcher.getAbsolutePath().replace(".exe", ".ico");

 558                 if (MENU_HINT.fetchFrom(params)) {
 559                     xml.writeStartElement("Icon");
 560                     xml.writeAttribute("Id", "StartMenuIcon.exe");
 561                     xml.writeAttribute("SourceFile", iconPath);
 562                     xml.writeEndElement();
 563                 }
 564                 if (SHORTCUT_HINT.fetchFrom(params)) {
 565                     xml.writeStartElement("Icon");
 566                     xml.writeAttribute("Id", "DesktopIcon.exe");
 567                     xml.writeAttribute("SourceFile", iconPath);
 568                     xml.writeEndElement();
 569                 }
 570             }
 571 
 572             for (int i = 0; i < addLaunchers.size(); i++) {
 573                 Map<String, ? super Object> sl = addLaunchers.get(i);
 574                 if (SHORTCUT_HINT.fetchFrom(sl) || MENU_HINT.fetchFrom(sl)) {
 575                     File addLauncher = new File(imageRootDir,
 576                             WinAppBundler.getLauncherRelativePath(sl));
 577                     String addLauncherPath


 611         // Upgrade guid is important to decide whether it is an upgrade of
 612         // installed app.  I.e. we need it to be the same for
 613         // 2 different versions of app if possible
 614         data.put("JpProductCode", productGUID.toString());
 615         data.put("JpProductUpgradeCode",
 616                 UPGRADE_UUID.fetchFrom(params).toString());
 617 
 618         if (!UPGRADE_UUID.getIsDefaultValue()) {
 619             data.put("JpAllowDowngrades", "yes");
 620         }
 621 
 622         if (CAN_USE_WIX36.fetchFrom(params)) {
 623             data.put("JpWixVersion36OrNewer", "yes");
 624         }
 625 
 626         data.put("JpAppName", APP_NAME.fetchFrom(params));
 627         data.put("JpAppDescription", DESCRIPTION.fetchFrom(params));
 628         data.put("JpAppVendor", VENDOR.fetchFrom(params));
 629         data.put("JpAppVersion", PRODUCT_VERSION.fetchFrom(params));
 630 
 631         data.put("JpConfigDir", CONFIG_ROOT.fetchFrom(params).getAbsolutePath());

 632 
 633         File imageRootDir = WIN_APP_IMAGE.fetchFrom(params);
 634 
 635         if (MSI_SYSTEM_WIDE.fetchFrom(params)) {
 636             data.put("JpIsSystemWide", "yes");
 637         }
 638 
 639         String licenseFile = LICENSE_FILE.fetchFrom(params);
 640         if (licenseFile != null) {
 641             String lname = new File(licenseFile).getName();
 642             File destFile = new File(CONFIG_ROOT.fetchFrom(params), lname);
 643             data.put("JpLicenseRtf", destFile.getAbsolutePath());
 644         }
 645 
 646         // Copy CA dll to include with installer
 647         if (INSTALLDIR_CHOOSER.fetchFrom(params)) {
 648             data.put("JpInstallDirChooser", "yes");
 649             String fname = "wixhelper.dll";
 650             try (InputStream is = getResourceAsStream(fname)) {
 651                 Files.copy(is, Paths.get(
 652                         CONFIG_ROOT.fetchFrom(params).getAbsolutePath(), fname));

 653             }
 654         }
 655 
 656         // Copy l10n files.
 657         for (String loc : Arrays.asList("en", "ja", "zh_CN")) {
 658             String fname = "MsiInstallerStrings_" + loc + ".wxl";
 659             try (InputStream is = getResourceAsStream(fname)) {
 660                 Files.copy(is, Paths.get(
 661                         CONFIG_ROOT.fetchFrom(params).getAbsolutePath(), fname));

 662             }
 663         }
 664 
 665         try (InputStream is = getResourceAsStream("main.wxs")) {
 666             Files.copy(is, Paths.get(
 667                     getConfig_ProjectFile(params).getAbsolutePath()));
 668         }
 669 
 670         return data;
 671     }
 672     private int id;
 673     private int compId;
 674     private final static String LAUNCHER_ID = "LauncherId";
 675 
 676     private void walkFileTree(Map<String, ? super Object> params,
 677             File root, PrintStream out, String prefix) {
 678         List<File> dirs = new ArrayList<>();
 679         List<File> files = new ArrayList<>();
 680 
 681         if (!root.isDirectory()) {




 404     private boolean prepareProto(Map<String, ? super Object> params)
 405                 throws PackagerException, IOException {
 406         File appImage = StandardBundlerParam.getPredefinedAppImage(params);
 407         File appDir = null;
 408 
 409         // we either have an application image or need to build one
 410         if (appImage != null) {
 411             appDir = new File(MSI_IMAGE_DIR.fetchFrom(params),
 412                     APP_NAME.fetchFrom(params));
 413             // copy everything from appImage dir into appDir/name
 414             IOUtils.copyRecursive(appImage.toPath(), appDir.toPath());
 415         } else {
 416             appDir = APP_BUNDLER.fetchFrom(params).doBundle(params,
 417                     MSI_IMAGE_DIR.fetchFrom(params), true);
 418         }
 419 
 420         params.put(WIN_APP_IMAGE.getID(), appDir);
 421 
 422         String licenseFile = LICENSE_FILE.fetchFrom(params);
 423         if (licenseFile != null) {
 424             // need to copy license file to the working directory
 425             // and convert to rtf if needed
 426             File lfile = new File(licenseFile);
 427             File destFile = new File(CONFIG_ROOT.fetchFrom(params),
 428                     lfile.getName());
 429 
 430             IOUtils.copyFile(lfile, destFile);
 431             destFile.setWritable(true);
 432             ensureByMutationFileIsRTF(destFile);
 433         }
 434 
 435         // copy file association icons
 436         List<Map<String, ? super Object>> fileAssociations =
 437                 FILE_ASSOCIATIONS.fetchFrom(params);
 438         for (Map<String, ? super Object> fa : fileAssociations) {
 439             File icon = FA_ICON.fetchFrom(fa);
 440             if (icon == null) {
 441                 continue;
 442             }
 443 
 444             File faIconFile = new File(appDir, icon.getName());
 445 


 538 
 539     private void prepareIconsFile(
 540             Map<String, ? super Object> params) throws IOException {
 541 
 542         File imageRootDir = WIN_APP_IMAGE.fetchFrom(params);
 543 
 544         List<Map<String, ? super Object>> addLaunchers =
 545                 ADD_LAUNCHERS.fetchFrom(params);
 546 
 547         XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance();
 548         try (Writer w = new BufferedWriter(new FileWriter(new File(
 549                 CONFIG_ROOT.fetchFrom(params), "icons.wxi")))) {
 550             XMLStreamWriter xml = xmlFactory.createXMLStreamWriter(w);
 551 
 552             xml.writeStartDocument();
 553             xml.writeStartElement("Include");
 554 
 555             File launcher = new File(imageRootDir,
 556                     WinAppBundler.getLauncherRelativePath(params));
 557             if (launcher.exists()) {
 558                 String iconPath = launcher.getAbsolutePath().replace(
 559                         ".exe", ".ico");
 560                 if (MENU_HINT.fetchFrom(params)) {
 561                     xml.writeStartElement("Icon");
 562                     xml.writeAttribute("Id", "StartMenuIcon.exe");
 563                     xml.writeAttribute("SourceFile", iconPath);
 564                     xml.writeEndElement();
 565                 }
 566                 if (SHORTCUT_HINT.fetchFrom(params)) {
 567                     xml.writeStartElement("Icon");
 568                     xml.writeAttribute("Id", "DesktopIcon.exe");
 569                     xml.writeAttribute("SourceFile", iconPath);
 570                     xml.writeEndElement();
 571                 }
 572             }
 573 
 574             for (int i = 0; i < addLaunchers.size(); i++) {
 575                 Map<String, ? super Object> sl = addLaunchers.get(i);
 576                 if (SHORTCUT_HINT.fetchFrom(sl) || MENU_HINT.fetchFrom(sl)) {
 577                     File addLauncher = new File(imageRootDir,
 578                             WinAppBundler.getLauncherRelativePath(sl));
 579                     String addLauncherPath


 613         // Upgrade guid is important to decide whether it is an upgrade of
 614         // installed app.  I.e. we need it to be the same for
 615         // 2 different versions of app if possible
 616         data.put("JpProductCode", productGUID.toString());
 617         data.put("JpProductUpgradeCode",
 618                 UPGRADE_UUID.fetchFrom(params).toString());
 619 
 620         if (!UPGRADE_UUID.getIsDefaultValue()) {
 621             data.put("JpAllowDowngrades", "yes");
 622         }
 623 
 624         if (CAN_USE_WIX36.fetchFrom(params)) {
 625             data.put("JpWixVersion36OrNewer", "yes");
 626         }
 627 
 628         data.put("JpAppName", APP_NAME.fetchFrom(params));
 629         data.put("JpAppDescription", DESCRIPTION.fetchFrom(params));
 630         data.put("JpAppVendor", VENDOR.fetchFrom(params));
 631         data.put("JpAppVersion", PRODUCT_VERSION.fetchFrom(params));
 632 
 633         data.put("JpConfigDir",
 634                 CONFIG_ROOT.fetchFrom(params).getAbsolutePath());
 635 
 636         File imageRootDir = WIN_APP_IMAGE.fetchFrom(params);
 637 
 638         if (MSI_SYSTEM_WIDE.fetchFrom(params)) {
 639             data.put("JpIsSystemWide", "yes");
 640         }
 641 
 642         String licenseFile = LICENSE_FILE.fetchFrom(params);
 643         if (licenseFile != null) {
 644             String lname = new File(licenseFile).getName();
 645             File destFile = new File(CONFIG_ROOT.fetchFrom(params), lname);
 646             data.put("JpLicenseRtf", destFile.getAbsolutePath());
 647         }
 648 
 649         // Copy CA dll to include with installer
 650         if (INSTALLDIR_CHOOSER.fetchFrom(params)) {
 651             data.put("JpInstallDirChooser", "yes");
 652             String fname = "wixhelper.dll";
 653             try (InputStream is = getResourceAsStream(fname)) {
 654                 Files.copy(is, Paths.get(
 655                         CONFIG_ROOT.fetchFrom(params).getAbsolutePath(),
 656                         fname));
 657             }
 658         }
 659 
 660         // Copy l10n files.
 661         for (String loc : Arrays.asList("en", "ja", "zh_CN")) {
 662             String fname = "MsiInstallerStrings_" + loc + ".wxl";
 663             try (InputStream is = getResourceAsStream(fname)) {
 664                 Files.copy(is, Paths.get(
 665                         CONFIG_ROOT.fetchFrom(params).getAbsolutePath(),
 666                         fname));
 667             }
 668         }
 669 
 670         try (InputStream is = getResourceAsStream("main.wxs")) {
 671             Files.copy(is, Paths.get(
 672                     getConfig_ProjectFile(params).getAbsolutePath()));
 673         }
 674 
 675         return data;
 676     }
 677     private int id;
 678     private int compId;
 679     private final static String LAUNCHER_ID = "LauncherId";
 680 
 681     private void walkFileTree(Map<String, ? super Object> params,
 682             File root, PrintStream out, String prefix) {
 683         List<File> dirs = new ArrayList<>();
 684         List<File> files = new ArrayList<>();
 685 
 686         if (!root.isDirectory()) {


< prev index next >