8226534: combination of windows options cause exception in MsiBundler JDK-8200758-branch
authorherrick
Wed, 14 Aug 2019 08:08:39 -0400
branchJDK-8200758-branch
changeset 57743 8d6f0aff03fc
parent 57742 e3d4b9bc5093
child 57744 d462d0422e1d
8226534: combination of windows options cause exception in MsiBundler Submitted-by: almatvee Reviewed-by: herrick, asemenyuk
src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java
--- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java	Wed Aug 14 07:50:54 2019 -0400
+++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java	Wed Aug 14 08:08:39 2019 -0400
@@ -188,7 +188,7 @@
         }
         return null;
     }
-        
+
 
     public static final StandardBundlerParam<Boolean> MENU_HINT =
         new WindowsBundlerParam<>(
@@ -918,20 +918,44 @@
                     "  <Directory Name=\"AppData\" Id=\"LocalAppDataFolder\">");
             }
 
+            // reset counters
+            compId = 0;
+            id = 0;
+
             // We should get valid folder or subfolders
             String installDir = WINDOWS_INSTALL_DIR.fetchFrom(params);
             String [] installDirs = installDir.split(Pattern.quote("\\"));
             for (int i = 0; i < (installDirs.length - 1); i++)  {
                 out.println("   <Directory Id=\"SUBDIR" + i + "\" Name=\""
                     + installDirs[i] + "\">");
+                if (!MSI_SYSTEM_WIDE.fetchFrom(params)) {
+                    out.println("   <Component Id=\"comp" + (compId++)
+                        + "\" DiskId=\"1\""
+                        + " Guid=\"" + UUID.randomUUID().toString() + "\""
+                        + " Win64=\"yes\""
+                        + ">");
+                    out.println("<CreateFolder/>");
+                    // has to be under HKCU to make WiX happy
+                    out.println("    <RegistryKey Root=\"HKCU\" "
+                        + " Key=\"Software\\" + VENDOR.fetchFrom(params) + "\\"
+                        + APP_NAME.fetchFrom(params) + "\""
+                        + (CAN_USE_WIX36.fetchFrom(params) ?
+                        ">" : " Action=\"createAndRemoveOnUninstall\">"));
+                    out.println("     <RegistryValue Name=\"Version\" Value=\""
+                        + VERSION.fetchFrom(params)
+                        + "\" Type=\"string\" KeyPath=\"yes\"/>");
+                    out.println("   </RegistryKey>");
+                    out.println("   <RemoveFolder Id=\"RemoveDir"
+                        + (id++) + "\" Directory=\"SUBDIR" + i
+                        + "\" On=\"uninstall\" />");
+                    out.println("</Component>");
+                }
             }
 
             out.println("   <Directory Id=\"APPLICATIONFOLDER\" Name=\""
                     + installDirs[installDirs.length - 1] + "\">");
 
             // dynamic part
-            id = 0;
-            compId = 0; // reset counters
             walkFileTree(params, WIN_APP_IMAGE.fetchFrom(params), out, "    ");
 
             // closing