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
26 package jdk.jpackage.internal;
27
28 import java.io.*;
29 import java.nio.charset.Charset;
30 import java.nio.file.Files;
31 import java.text.MessageFormat;
32 import java.util.*;
33 import java.util.regex.Matcher;
34 import java.util.regex.Pattern;
35
36 import static jdk.jpackage.internal.WindowsBundlerParam.*;
37
38 public class WinMsiBundler extends AbstractBundler {
39
40 private static final ResourceBundle I18N = ResourceBundle.getBundle(
41 "jdk.jpackage.internal.resources.WinResources");
42
43 public static final BundlerParamInfo<WinAppBundler> APP_BUNDLER =
44 new WindowsBundlerParam<>(
45 "win.app.bundler",
46 WinAppBundler.class,
47 params -> new WinAppBundler(),
48 null);
49
50 public static final BundlerParamInfo<Boolean> CAN_USE_WIX36 =
51 new WindowsBundlerParam<>(
52 "win.msi.canUseWix36",
53 Boolean.class,
948 boolean prepareContentList(Map<String, ? super Object> params)
949 throws FileNotFoundException {
950 File f = new File(
951 CONFIG_ROOT.fetchFrom(params), MSI_PROJECT_CONTENT_FILE);
952 PrintStream out = new PrintStream(f);
953
954 // opening
955 out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
956 out.println("<Include>");
957
958 out.println(" <Directory Id=\"TARGETDIR\" Name=\"SourceDir\">");
959 if (MSI_SYSTEM_WIDE.fetchFrom(params)) {
960 // install to programfiles
961 out.println(" <Directory Id=\"ProgramFiles64Folder\" "
962 + "Name=\"PFiles\">");
963 } else {
964 // install to user folder
965 out.println(
966 " <Directory Name=\"AppData\" Id=\"LocalAppDataFolder\">");
967 }
968 out.println(" <Directory Id=\"APPLICATIONFOLDER\" Name=\""
969 + APP_NAME.fetchFrom(params) + "\">");
970
971 // dynamic part
972 id = 0;
973 compId = 0; // reset counters
974 walkFileTree(params, WIN_APP_IMAGE.fetchFrom(params), out, " ");
975
976 // closing
977 out.println(" </Directory>");
978 out.println(" </Directory>");
979
980 // for shortcuts
981 if (SHORTCUT_HINT.fetchFrom(params)) {
982 out.println(" <Directory Id=\"DesktopFolder\" />");
983 }
984 if (MENU_HINT.fetchFrom(params)) {
985 out.println(" <Directory Id=\"ProgramMenuFolder\">");
986 out.println(" <Directory Id=\"ProgramMenuDir\" Name=\""
987 + MENU_GROUP.fetchFrom(params) + "\">");
988 out.println(" <Component Id=\"comp" + (compId++) + "\""
989 + " Guid=\"" + UUID.randomUUID().toString() + "\""
990 + " Win64=\"yes\""
991 + ">");
992 out.println(" <RemoveFolder Id=\"ProgramMenuDir\" "
993 + "On=\"uninstall\" />");
994 // This has to be under HKCU to make WiX happy.
995 // There are numberous discussions on this amoung WiX users
996 // (if user A installs and user B uninstalls key is left behind)
997 // there are suggested workarounds but none of them are appealing.
|
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
26 package jdk.jpackage.internal;
27
28 import java.io.*;
29 import java.nio.charset.Charset;
30 import java.nio.file.Files;
31 import java.text.MessageFormat;
32 import java.util.*;
33 import java.util.regex.Pattern;
34
35 import static jdk.jpackage.internal.WindowsBundlerParam.*;
36
37 public class WinMsiBundler extends AbstractBundler {
38
39 private static final ResourceBundle I18N = ResourceBundle.getBundle(
40 "jdk.jpackage.internal.resources.WinResources");
41
42 public static final BundlerParamInfo<WinAppBundler> APP_BUNDLER =
43 new WindowsBundlerParam<>(
44 "win.app.bundler",
45 WinAppBundler.class,
46 params -> new WinAppBundler(),
47 null);
48
49 public static final BundlerParamInfo<Boolean> CAN_USE_WIX36 =
50 new WindowsBundlerParam<>(
51 "win.msi.canUseWix36",
52 Boolean.class,
947 boolean prepareContentList(Map<String, ? super Object> params)
948 throws FileNotFoundException {
949 File f = new File(
950 CONFIG_ROOT.fetchFrom(params), MSI_PROJECT_CONTENT_FILE);
951 PrintStream out = new PrintStream(f);
952
953 // opening
954 out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
955 out.println("<Include>");
956
957 out.println(" <Directory Id=\"TARGETDIR\" Name=\"SourceDir\">");
958 if (MSI_SYSTEM_WIDE.fetchFrom(params)) {
959 // install to programfiles
960 out.println(" <Directory Id=\"ProgramFiles64Folder\" "
961 + "Name=\"PFiles\">");
962 } else {
963 // install to user folder
964 out.println(
965 " <Directory Name=\"AppData\" Id=\"LocalAppDataFolder\">");
966 }
967
968 // We should get valid folder or subfolders
969 String installDir = WINDOWS_INSTALL_DIR.fetchFrom(params);
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.
|