src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java
branchJDK-8200758-branch
changeset 57390 1cb722a11ead
parent 57283 0b0be19f79e4
child 57391 970f28090a06
equal deleted inserted replaced
57389:cce526c681dc 57390:1cb722a11ead
   603         data.put("ADD_LAUNCHER_ICONS", addLauncherIcons.toString());
   603         data.put("ADD_LAUNCHER_ICONS", addLauncherIcons.toString());
   604 
   604 
   605         String wxs = StandardBundlerParam.isRuntimeInstaller(params) ?
   605         String wxs = StandardBundlerParam.isRuntimeInstaller(params) ?
   606                 MSI_PROJECT_TEMPLATE_SERVER_JRE : MSI_PROJECT_TEMPLATE;
   606                 MSI_PROJECT_TEMPLATE_SERVER_JRE : MSI_PROJECT_TEMPLATE;
   607 
   607 
   608         Writer w = new BufferedWriter(
   608         try (Writer w = Files.newBufferedWriter(
   609                 new FileWriter(getConfig_ProjectFile(params)));
   609                 getConfig_ProjectFile(params).toPath())) {
   610 
   610 
   611         String content = preprocessTextResource(
   611             String content = preprocessTextResource(
   612                 getConfig_ProjectFile(params).getName(),
   612                     getConfig_ProjectFile(params).getName(),
   613                 I18N.getString("resource.wix-config-file"),
   613                     I18N.getString("resource.wix-config-file"),
   614                 wxs, data, VERBOSE.fetchFrom(params),
   614                     wxs, data, VERBOSE.fetchFrom(params),
   615                 RESOURCE_DIR.fetchFrom(params));
   615                     RESOURCE_DIR.fetchFrom(params));
   616         w.write(content);
   616             w.write(content);
   617         w.close();
   617         }
   618         return true;
   618         return true;
   619     }
   619     }
   620     private int id;
   620     private int id;
   621     private int compId;
   621     private int compId;
   622     private final static String LAUNCHER_ID = "LauncherId";
   622     private final static String LAUNCHER_ID = "LauncherId";
   946 
   946 
   947     boolean prepareContentList(Map<String, ? super Object> params)
   947     boolean prepareContentList(Map<String, ? super Object> params)
   948             throws FileNotFoundException {
   948             throws FileNotFoundException {
   949         File f = new File(
   949         File f = new File(
   950                 CONFIG_ROOT.fetchFrom(params), MSI_PROJECT_CONTENT_FILE);
   950                 CONFIG_ROOT.fetchFrom(params), MSI_PROJECT_CONTENT_FILE);
   951         PrintStream out = new PrintStream(f);
   951 
   952 
   952         try (PrintStream out = new PrintStream(f)) {
   953         // opening
   953 
   954         out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
   954             // opening
   955         out.println("<Include>");
   955             out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
   956 
   956             out.println("<Include>");
   957         out.println(" <Directory Id=\"TARGETDIR\" Name=\"SourceDir\">");
   957 
   958         if (MSI_SYSTEM_WIDE.fetchFrom(params)) {
   958             out.println(" <Directory Id=\"TARGETDIR\" Name=\"SourceDir\">");
   959             // install to programfiles
   959             if (MSI_SYSTEM_WIDE.fetchFrom(params)) {
   960             out.println("  <Directory Id=\"ProgramFiles64Folder\" "
   960                 // install to programfiles
   961                         + "Name=\"PFiles\">");
   961                 out.println("  <Directory Id=\"ProgramFiles64Folder\" "
   962         } else {
   962                             + "Name=\"PFiles\">");
   963             // install to user folder
   963             } else {
       
   964                 // install to user folder
       
   965                 out.println(
       
   966                     "  <Directory Name=\"AppData\" Id=\"LocalAppDataFolder\">");
       
   967             }
       
   968 
       
   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             }
       
   976 
       
   977             out.println("   <Directory Id=\"APPLICATIONFOLDER\" Name=\""
       
   978                     + installDirs[installDirs.length - 1] + "\">");
       
   979 
       
   980             // dynamic part
       
   981             id = 0;
       
   982             compId = 0; // reset counters
       
   983             walkFileTree(params, WIN_APP_IMAGE.fetchFrom(params), out, "    ");
       
   984 
       
   985             // closing
       
   986             for (int i = 0; i < installDirs.length; i++)  {
       
   987                 out.println("   </Directory>");
       
   988             }
       
   989             out.println("  </Directory>");
       
   990 
       
   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
   964             out.println(
  1028             out.println(
   965                     "  <Directory Name=\"AppData\" Id=\"LocalAppDataFolder\">");
  1029                     "    <ComponentRef Id=\"CleanupMainApplicationFolder\" />");
   966         }
  1030             out.println(" </Feature>");
   967 
  1031             out.println("</Include>");
   968         // We should get valid folder or subfolders
  1032 
   969         String installDir = WINDOWS_INSTALL_DIR.fetchFrom(params);
  1033         }
   970         String [] installDirs = installDir.split(Pattern.quote("\\"));
       
   971         for (int i = 0; i < (installDirs.length - 1); i++)  {
       
   972             out.println("   <Directory Id=\"SUBDIR" + i + "\" Name=\""
       
   973                 + installDirs[i] + "\">");
       
   974         }
       
   975 
       
   976         out.println("   <Directory Id=\"APPLICATIONFOLDER\" Name=\""
       
   977                 + installDirs[installDirs.length - 1] + "\">");
       
   978 
       
   979         // dynamic part
       
   980         id = 0;
       
   981         compId = 0; // reset counters
       
   982         walkFileTree(params, WIN_APP_IMAGE.fetchFrom(params), out, "    ");
       
   983 
       
   984         // closing
       
   985         for (int i = 0; i < installDirs.length; i++)  {
       
   986             out.println("   </Directory>");
       
   987         }
       
   988         out.println("  </Directory>");
       
   989 
       
   990         // for shortcuts
       
   991         if (SHORTCUT_HINT.fetchFrom(params)) {
       
   992             out.println("  <Directory Id=\"DesktopFolder\" />");
       
   993         }
       
   994         if (MENU_HINT.fetchFrom(params)) {
       
   995             out.println("  <Directory Id=\"ProgramMenuFolder\">");
       
   996             out.println("    <Directory Id=\"ProgramMenuDir\" Name=\""
       
   997                     + MENU_GROUP.fetchFrom(params) + "\">");
       
   998             out.println("      <Component Id=\"comp" + (compId++) + "\""
       
   999                     + " Guid=\"" + UUID.randomUUID().toString() + "\""
       
  1000                     + " Win64=\"yes\""
       
  1001                     + ">");
       
  1002             out.println("        <RemoveFolder Id=\"ProgramMenuDir\" "
       
  1003                     + "On=\"uninstall\" />");
       
  1004             // This has to be under HKCU to make WiX happy.
       
  1005             // There are numberous discussions on this amoung WiX users
       
  1006             // (if user A installs and user B uninstalls key is left behind)
       
  1007             // there are suggested workarounds but none of them are appealing.
       
  1008             // Leave it for now
       
  1009             out.println(
       
  1010                     "         <RegistryValue Root=\"HKCU\" Key=\"Software\\"
       
  1011                     + VENDOR.fetchFrom(params) + "\\"
       
  1012                     + APP_NAME.fetchFrom(params)
       
  1013                     + "\" Type=\"string\" Value=\"\" />");
       
  1014             out.println("      </Component>");
       
  1015             out.println("    </Directory>");
       
  1016             out.println(" </Directory>");
       
  1017         }
       
  1018 
       
  1019         out.println(" </Directory>");
       
  1020 
       
  1021         out.println(" <Feature Id=\"DefaultFeature\" "
       
  1022                 + "Title=\"Main Feature\" Level=\"1\">");
       
  1023         for (int j = 0; j < compId; j++) {
       
  1024             out.println("    <ComponentRef Id=\"comp" + j + "\" />");
       
  1025         }
       
  1026         // component is defined in the template.wsx
       
  1027         out.println("    <ComponentRef Id=\"CleanupMainApplicationFolder\" />");
       
  1028         out.println(" </Feature>");
       
  1029         out.println("</Include>");
       
  1030 
       
  1031         out.close();
       
  1032         return true;
  1034         return true;
  1033     }
  1035     }
  1034 
  1036 
  1035     private File getConfig_ProjectFile(Map<String, ? super Object> params) {
  1037     private File getConfig_ProjectFile(Map<String, ? super Object> params) {
  1036         return new File(CONFIG_ROOT.fetchFrom(params),
  1038         return new File(CONFIG_ROOT.fetchFrom(params),