From 146c7a78e551af2f59c95215833f39be5b6c8a67 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Sat, 4 Jun 2016 11:34:41 -0700
Subject: [PATCH] Improved Windows installer (nkalvi, #2708, #2389).

* Scope selection in the first screen. Since I couldn't detect if the
  user is 'real' admin user, default is still per user.
* Scope is limited to per machine on servers. Though not perfect
  (couldn't detect `DisableMSI` policy), it should handle #2389 better.
* For per machine, location can be changed by selecting Advanced.
  Localization: modified templates from WiX toolkit support localization
  very well. A short sample localization file for en-us is used.
* Dialog elements are moved to their own files.
---
 windows/AdvancedWelcomeEulaDlg_Custom.wxs |  90 ++++++++++++++
 windows/Pandoc-en-us.wxl                  |  14 +++
 windows/WixUI_Advanced_Custom.wxs         | 142 ++++++++++++++++++++++
 windows/make-windows-installer.bat        |   4 +-
 windows/pandoc.wxs                        | 132 ++++++++------------
 5 files changed, 298 insertions(+), 84 deletions(-)
 create mode 100644 windows/AdvancedWelcomeEulaDlg_Custom.wxs
 create mode 100644 windows/Pandoc-en-us.wxl
 create mode 100644 windows/WixUI_Advanced_Custom.wxs

diff --git a/windows/AdvancedWelcomeEulaDlg_Custom.wxs b/windows/AdvancedWelcomeEulaDlg_Custom.wxs
new file mode 100644
index 000000000..61e6d8e00
--- /dev/null
+++ b/windows/AdvancedWelcomeEulaDlg_Custom.wxs
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  <copyright file="AdvancedWelcomeEulaDlg.wxs" company="Outercurve Foundation">
+    Copyright (c) 2004, Outercurve Foundation.
+    This software is released under Microsoft Reciprocal License (MS-RL).
+    The license and further copyright text can be found in the file
+    LICENSE.TXT at the root directory of the distribution.
+  </copyright>
+-->
+<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
+    <Fragment>
+        <UI>
+            <Dialog Id="AdvancedWelcomeEulaDlg_Custom" Width="370" Height="270" Title="!(loc.AdvancedWelcomeEulaDlg_Title)">
+              
+                <Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="!(loc.AdvancedWelcomeEulaDlgBannerBitmap)" />
+                <Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />
+                <Control Id="Title" Type="Text" X="20" Y="10" Width="300" Height="24" Transparent="yes" NoPrefix="yes" Text="!(loc.AdvancedWelcomeEulaDlgTitle)" />
+              
+                <Control Id="LicenseAcceptedCheckBox" Type="CheckBox" X="20" Y="140" Width="226" Height="19" CheckBoxValue="1" Property="LicenseAccepted" Text="!(loc.WelcomeEulaDlgLicenseAcceptedCheckBox)" />
+
+                <Control Id="ScopeGroupBox" Type="GroupBox" X="20" Y="155" Height="70" Width="330" />
+              
+                <Control Id="AllUsersCheckBox" Type="CheckBox" X="88" Y="200" Width="226" Height="18" CheckBoxValue="1" Property="ALLUSERS" Text="!(loc.InstallScopeDlgPerMachine)">
+                  <Condition Action="enable">LicenseAccepted AND (WixUISupportPerUser = 1)</Condition>
+                  <Condition Action="disable">(NOT LicenseAccepted) OR (WixUISupportPerUser = 0)</Condition>                
+                </Control>
+                           
+                <Control Id="PerUserDescription" Type="Text" X="30" Y="167" Width="300" Height="36" NoPrefix="yes" Text="!(loc.InstallScopeDlgPerUserDescription)">
+                  <Condition Action="hide">ALLUSERS</Condition>
+                  <Condition Action="show">NOT (ALLUSERS = 1)</Condition>
+                  <Condition Action="disable">NOT LicenseAccepted</Condition>
+                  <Condition Action="enable">LicenseAccepted</Condition>
+                </Control>
+
+                <Control Id="PerMachineDescription" Type="Text" X="30" Y="167" Width="300" Height="36" Hidden="yes" NoPrefix="yes" Text="!(loc.InstallScopeDlgPerMachineDescription)">
+                  <Condition Action="hide">NOT (ALLUSERS = 1)</Condition>
+                  <Condition Action="show">ALLUSERS = 1</Condition>
+                  <Condition Action="disable">NOT LicenseAccepted</Condition>
+                  <Condition Action="enable">LicenseAccepted</Condition>
+                </Control>
+              
+                <Control Id="Print" Type="PushButton" X="88" Y="243" Width="56" Height="17" Text="!(loc.WixUIPrint)">
+                    <Publish Event="DoAction" Value="WixUIPrintEula">1</Publish>
+                </Control>
+              
+                <Control Id="Advanced" Type="PushButton" X="156" Y="243" Width="56" Height="17" Text="!(loc.AdvancedWelcomeEulaDlgAdvanced)">
+                    <Condition Action="disable">NOT LicenseAccepted OR NOT (ALLUSERS = 1)</Condition>
+                    <Condition Action="enable">(LicenseAccepted = "1") AND (ALLUSERS = 1)</Condition>
+                </Control>
+              
+                <Control Id="Install" Type="PushButton" ElevationShield="yes" X="212" Y="243" Width="80" Height="17" Default="yes" Text="!(loc.AdvancedWelcomeEulaDlgInstall)" Hidden="yes">
+                    <Publish Event="SpawnWaitDialog" Value="WaitForCostingDlg">!(wix.WixUICostingPopupOptOut) OR CostingComplete = 1</Publish>
+                    <Publish Event="EndDialog" Value="Return"><![CDATA[OutOfDiskSpace <> 1]]></Publish>
+                    <Publish Event="SpawnDialog" Value="OutOfRbDiskDlg">OutOfDiskSpace = 1 AND OutOfNoRbDiskSpace = 0 AND (PROMPTROLLBACKCOST="P" OR NOT PROMPTROLLBACKCOST)</Publish>
+                    <Publish Event="EndDialog" Value="Return">OutOfDiskSpace = 1 AND OutOfNoRbDiskSpace = 0 AND PROMPTROLLBACKCOST="D"</Publish>
+                    <Publish Event="EnableRollback" Value="False">OutOfDiskSpace = 1 AND OutOfNoRbDiskSpace = 0 AND PROMPTROLLBACKCOST="D"</Publish>
+                    <Publish Event="SpawnDialog" Value="OutOfDiskDlg">(OutOfDiskSpace = 1 AND OutOfNoRbDiskSpace = 1) OR (OutOfDiskSpace = 1 AND PROMPTROLLBACKCOST="F")</Publish>
+                    <Condition Action="disable">NOT LicenseAccepted</Condition>
+                    <Condition Action="enable">LicenseAccepted = "1"</Condition>
+                    <Condition Action="show">ALLUSERS = 1</Condition>
+                    <Condition Action="hide">NOT (ALLUSERS = 1)</Condition>
+                </Control>
+                <Control Id="InstallNoShield" Type="PushButton" ElevationShield="no" X="212" Y="243" Width="80" Height="17" Default="yes" Text="!(loc.AdvancedWelcomeEulaDlgInstall)" Hidden="yes">
+                    <Publish Event="SpawnWaitDialog" Value="WaitForCostingDlg">!(wix.WixUICostingPopupOptOut) OR CostingComplete = 1</Publish>
+                    <Publish Event="EndDialog" Value="Return"><![CDATA[OutOfDiskSpace <> 1]]></Publish>
+                    <Publish Event="SpawnDialog" Value="OutOfRbDiskDlg">OutOfDiskSpace = 1 AND OutOfNoRbDiskSpace = 0 AND (PROMPTROLLBACKCOST="P" OR NOT PROMPTROLLBACKCOST)</Publish>
+                    <Publish Event="EndDialog" Value="Return">OutOfDiskSpace = 1 AND OutOfNoRbDiskSpace = 0 AND PROMPTROLLBACKCOST="D"</Publish>
+                    <Publish Event="EnableRollback" Value="False">OutOfDiskSpace = 1 AND OutOfNoRbDiskSpace = 0 AND PROMPTROLLBACKCOST="D"</Publish>
+                    <Publish Event="SpawnDialog" Value="OutOfDiskDlg">(OutOfDiskSpace = 1 AND OutOfNoRbDiskSpace = 1) OR (OutOfDiskSpace = 1 AND PROMPTROLLBACKCOST="F")</Publish>
+                    <Condition Action="disable">NOT LicenseAccepted</Condition>
+                    <Condition Action="enable">LicenseAccepted = "1"</Condition>
+                    <Condition Action="show">NOT (ALLUSERS = 1)</Condition>
+                    <Condition Action="hide">ALLUSERS = 1</Condition>
+                </Control>
+              
+                <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="!(loc.WixUICancel)">
+                    <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
+                </Control>
+                <Control Id="LicenseText" Type="ScrollableText" X="20" Y="55" Width="330" Height="80" Sunken="yes" TabSkip="no">
+                  <!--<Text SourceFile="!(wix.WixUILicenseRtf=$(var.licenseRtf))" />-->
+                  <Text SourceFile="!(loc.LicenseRtf)" />
+                </Control>
+            </Dialog>
+        </UI>
+
+        <InstallUISequence>
+            <Show Dialog="AdvancedWelcomeEulaDlg_Custom" Before="ProgressDlg">NOT Installed</Show>
+        </InstallUISequence>
+    </Fragment>
+</Wix>
\ No newline at end of file
diff --git a/windows/Pandoc-en-us.wxl b/windows/Pandoc-en-us.wxl
new file mode 100644
index 000000000..1981f24e8
--- /dev/null
+++ b/windows/Pandoc-en-us.wxl
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<WixLocalization Culture="en-us" Codepage="1252" xmlns="http://schemas.microsoft.com/wix/2006/localization">
+  <String Id="Language">1033</String>
+  <!-- Supported language and codepage codes can be found here: http://www.tramontana.co.hu/wix/lesson2.php#2.4 -->
+  
+  <String Id="LicenseRtf" Overridable="yes">COPYING.rtf</String>
+  
+    <String Id="ExitDialogText">[ProductName] was installed in 
+
+[APPLICATIONFOLDER]. 
+    
+You may need to restart Cmd/Powershell windows before using it.</String>
+
+</WixLocalization>
\ No newline at end of file
diff --git a/windows/WixUI_Advanced_Custom.wxs b/windows/WixUI_Advanced_Custom.wxs
new file mode 100644
index 000000000..6f85d9961
--- /dev/null
+++ b/windows/WixUI_Advanced_Custom.wxs
@@ -0,0 +1,142 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?if $(sys.BUILDARCH)=x64?>
+<?define ProgFilesFolder="ProgramFiles64Folder"?>
+<?else?>
+<?define ProgFilesFolder="ProgramFilesFolder"?>
+<?endif?>
+<!--
+  <copyright file="WixUI_Advanced_Custom.wxs" company="Outercurve Foundation">
+    Copyright (c) 2004, Outercurve Foundation.
+    This software is released under Microsoft Reciprocal License (MS-RL).
+    The license and further copyright text can be found in the file
+    LICENSE.TXT at the root directory of the distribution.
+  </copyright>
+-->
+
+<!--
+WixUI_Advanced_Custom offers a two-click install (EULA checkbox and Install button)
+and offers an Advanced button that lets users choose per-machine or per-user
+installs, install path, and features.
+
+WiX variables used:
+ - WixUISupportPerMachine
+ - WixUISupportPerUser
+ 
+Todo:
+ - Clicking Install doesn't work! - APPLICATIONFOLDER isn't set; need to accept another "incoming" property.
+ - Replace this dialog set UI fragment with the UI extension.
+ = This set is still in active development.
+ = Future releases are likely to be incompatible.
+ = Future releases are likely to be much easier to use.
+ = Use at your own risk.
+
+-->
+
+<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
+    <Fragment>
+        <WixVariable Id="WixUISupportPerUser" Value="1" Overridable="yes" />
+        <WixVariable Id="WixUISupportPerMachine" Value="1" Overridable="yes" />
+
+        <PropertyRef Id="ApplicationFolderName" />
+
+        <CustomAction Id="WixSetDefaultPerUserFolder2" Property="WixPerUserFolder" Value="[LocalAppDataFolder][ApplicationFolderName]" Execute="immediate" />
+        <CustomAction Id="WixSetDefaultPerMachineFolder2" Property="WixPerMachineFolder" Value="[$(var.ProgFilesFolder)][ApplicationFolderName]" Execute="immediate" />
+        <CustomAction Id="WixSetPerUserFolder2" Property="APPLICATIONFOLDER" Value="[WixPerUserFolder]" Execute="immediate" />
+        <CustomAction Id="WixSetPerMachineFolder2" Property="APPLICATIONFOLDER" Value="[WixPerMachineFolder]" Execute="immediate" />
+
+        <InstallExecuteSequence>
+            <Custom Action="WixSetDefaultPerUserFolder2" Before="CostFinalize" />
+            <Custom Action="WixSetDefaultPerMachineFolder2" After="WixSetDefaultPerUserFolder2" />
+            <Custom Action="WixSetPerUserFolder2" After="WixSetDefaultPerMachineFolder2">ACTION="INSTALL" AND APPLICATIONFOLDER="" AND (ALLUSERS="" OR (ALLUSERS=2 AND (NOT Privileged)))</Custom>
+            <Custom Action="WixSetPerMachineFolder2" After="WixSetPerUserFolder2">ACTION="INSTALL" AND APPLICATIONFOLDER="" AND (ALLUSERS=1 OR (ALLUSERS=2 AND Privileged))</Custom>
+        </InstallExecuteSequence>
+        <InstallUISequence>
+            <Custom Action="WixSetDefaultPerUserFolder2" Before="CostFinalize" />
+            <Custom Action="WixSetDefaultPerMachineFolder2" After="WixSetDefaultPerUserFolder2" />
+            <Custom Action="WixSetPerUserFolder2" After="WixSetDefaultPerMachineFolder2">ACTION="INSTALL" AND APPLICATIONFOLDER="" AND (ALLUSERS="" OR (ALLUSERS=2 AND (NOT Privileged)))</Custom>
+            <Custom Action="WixSetPerMachineFolder2" After="WixSetPerUserFolder2">ACTION="INSTALL" AND APPLICATIONFOLDER="" AND (ALLUSERS=1 OR (ALLUSERS=2 AND Privileged))</Custom>
+        </InstallUISequence>
+
+        <UI Id="WixUI_Advanced_Custom">
+            <TextStyle Id="WixUI_Font_Normal" FaceName="!(loc.Advanced_Font_FaceName)" Size="!(loc.Advanced_Font_Normal_Size)" />
+            <TextStyle Id="WixUI_Font_Bigger" FaceName="!(loc.Advanced_Font_FaceName)" Size="!(loc.Advanced_Font_Bigger_Size)" />
+            <TextStyle Id="WixUI_Font_Title" FaceName="!(loc.Advanced_Font_FaceName)" Size="!(loc.Advanced_Font_Title_Size)" Bold="yes" />
+            <TextStyle Id="WixUI_Font_Emphasized" FaceName="!(loc.Advanced_Font_FaceName)" Size="!(loc.Advanced_Font_Emphasized_Size)" Bold="yes" />
+
+            <Property Id="DefaultUIFont" Value="WixUI_Font_Normal" />
+            <Property Id="WixUI_Mode" Value="Advanced" />
+
+            <DialogRef Id="BrowseDlg" />
+            <DialogRef Id="DiskCostDlg" />
+            <DialogRef Id="ErrorDlg" />
+            <DialogRef Id="FatalError" />
+            <DialogRef Id="FilesInUse" />
+            <DialogRef Id="MsiRMFilesInUse" />
+            <DialogRef Id="PrepareDlg" />
+            <DialogRef Id="ProgressDlg" />
+            <DialogRef Id="ResumeDlg" />
+            <DialogRef Id="UserExit" />
+            <DialogRef Id="WelcomeDlg"/>
+
+            <Publish Dialog="ExitDialog" Control="Finish" Event="EndDialog" Value="Return" Order="999">1</Publish>
+            
+            <Publish Dialog="BrowseDlg" Control="OK" Event="DoAction" Value="WixUIValidatePath" Order="1">1</Publish>
+            <Publish Dialog="BrowseDlg" Control="OK" Event="SpawnDialog" Value="InvalidDirDlg" Order="2"><![CDATA[WIXUI_INSTALLDIR_VALID<>"1"]]></Publish>
+
+            <!--<Publish Dialog="AdvancedWelcomeEulaDlg_Custom" Control="Advanced" Event="NewDialog" Value="InstallScopeDlg" Order="1">!(wix.WixUISupportPerMachine) AND !(wix.WixUISupportPerUser)</Publish>-->
+            <!--<Publish Dialog="AdvancedWelcomeEulaDlg_Custom" Control="Advanced" Event="NewDialog" Value="FeaturesDlg" Order="2">NOT !(wix.WixUISupportPerMachine)</Publish>-->
+            <!--<Publish Dialog="AdvancedWelcomeEulaDlg_Custom" Control="Advanced" Event="NewDialog" Value="InstallDirDlg" Order="3">!(wix.WixUISupportPerMachine) AND NOT !(wix.WixUISupportPerUser)</Publish>-->
+
+            <Publish Dialog="AdvancedWelcomeEulaDlg_Custom" Control="Advanced" Property="WixAppFolder" Value="WixPerMachineFolder" Order="1">ALLUSERS = 1</Publish>
+            <Publish Dialog="AdvancedWelcomeEulaDlg_Custom" Control="Advanced" Property="APPLICATIONFOLDER" Value="[$(var.ProgFilesFolder)][ApplicationFolderName]" Order="2">ALLUSERS = 1</Publish>
+            <Publish Dialog="AdvancedWelcomeEulaDlg_Custom" Control="Advanced" Event="NewDialog" Value="InstallDirDlg" Order="3">!(wix.WixUISupportPerMachine) AND  !(wix.WixUISupportPerUser)</Publish>
+
+            <Publish Dialog="AdvancedWelcomeEulaDlg_Custom" Control="AllUsersCheckBox" Property="WixAppFolder" Value="WixPerMachineFolder" Order="1">ALLUSERS = 1</Publish>
+            <Publish Dialog="AdvancedWelcomeEulaDlg_Custom" Control="AllUsersCheckBox" Property="APPLICATIONFOLDER" Value="[$(var.ProgFilesFolder)][ApplicationFolderName]" Order="2">ALLUSERS = 1</Publish>
+
+            <Publish Dialog="AdvancedWelcomeEulaDlg_Custom" Control="AllUsersCheckBox" Property="WixAppFolder" Value="WixPerUserFolder" Order="1">NOT (ALLUSERS = 1)</Publish>
+            <Publish Dialog="AdvancedWelcomeEulaDlg_Custom" Control="AllUsersCheckBox" Property="APPLICATIONFOLDER" Value="[LocalAppDataFolder][ApplicationFolderName]" Order="2">NOT (ALLUSERS = 1)</Publish>
+
+          <!--<Publish Dialog="InstallScopeDlg" Control="Back" Event="NewDialog" Value="AdvancedWelcomeEulaDlg_Custom">1</Publish>-->
+          <!-- override default WixAppFolder of WixPerMachineFolder as standard user won't be shown the radio group to set WixAppFolder -->
+          
+            <!--<Publish Dialog="InstallScopeDlg" Control="Next" Property="WixAppFolder" Value="WixPerUserFolder" Order="1">!(wix.WixUISupportPerUser) AND NOT Privileged</Publish>-->
+
+            
+
+            <!--<Publish Dialog="InstallScopeDlg" Control="Next" Event="NewDialog" Value="FeaturesDlg" Order="6">WixAppFolder = "WixPerUserFolder"</Publish>
+            <Publish Dialog="InstallScopeDlg" Control="Next" Event="NewDialog" Value="InstallDirDlg" Order="7">WixAppFolder = "WixPerMachineFolder"</Publish>-->
+
+            <!--<Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="InstallScopeDlg">!(wix.WixUISupportPerUser)</Publish>-->
+            <Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="AdvancedWelcomeEulaDlg_Custom">1</Publish>
+            <Publish Dialog="InstallDirDlg" Control="Next" Event="SetTargetPath" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
+            <Publish Dialog="InstallDirDlg" Control="Next" Event="DoAction" Value="WixUIValidatePath" Order="2">NOT WIXUI_DONTVALIDATEPATH</Publish>
+            <Publish Dialog="InstallDirDlg" Control="Next" Event="SpawnDialog" Value="InvalidDirDlg" Order="3"><![CDATA[NOT WIXUI_DONTVALIDATEPATH AND WIXUI_INSTALLDIR_VALID<>"1"]]></Publish>
+            <Publish Dialog="InstallDirDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="4">WIXUI_DONTVALIDATEPATH OR WIXUI_INSTALLDIR_VALID="1"</Publish>
+            <Publish Dialog="InstallDirDlg" Control="ChangeFolder" Property="_BrowseProperty" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
+            <Publish Dialog="InstallDirDlg" Control="ChangeFolder" Event="SpawnDialog" Value="BrowseDlg" Order="2">1</Publish>
+
+            <!--<Publish Dialog="FeaturesDlg" Control="Back" Event="NewDialog" Value="InstallScopeDlg">NOT Installed AND WixAppFolder = "WixPerUserFolder"</Publish>-->
+            <Publish Dialog="FeaturesDlg" Control="Back" Event="NewDialog" Value="InstallDirDlg">NOT Installed AND WixAppFolder = "WixPerMachineFolder"</Publish>
+            <Publish Dialog="FeaturesDlg" Control="Back" Event="NewDialog" Value="MaintenanceTypeDlg">Installed</Publish>
+
+            <Publish Dialog="MaintenanceWelcomeDlg" Control="Next" Event="NewDialog" Value="MaintenanceTypeDlg">1</Publish>
+
+            <Publish Dialog="MaintenanceTypeDlg" Control="RepairButton" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
+            <Publish Dialog="MaintenanceTypeDlg" Control="RemoveButton" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
+            <Publish Dialog="MaintenanceTypeDlg" Control="Back" Event="NewDialog" Value="MaintenanceWelcomeDlg">1</Publish>
+
+            <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="MaintenanceTypeDlg" Order="2">Installed AND NOT PATCH</Publish>
+            <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="3">Installed AND PATCH</Publish>
+
+            <Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg">Installed AND PATCH</Publish>
+        </UI>
+
+        <InstallUISequence>
+            <Show Dialog="WelcomeDlg" Before="AdvancedWelcomeEulaDlg_Custom" >Installed AND PATCH</Show>
+        </InstallUISequence>
+
+        <Property Id="WIXUI_INSTALLDIR" Value="APPLICATIONFOLDER" />
+        <UIRef Id="WixUI_Common" />
+    </Fragment>
+</Wix>
\ No newline at end of file
diff --git a/windows/make-windows-installer.bat b/windows/make-windows-installer.bat
index d3d9bb71c..2f0bf4b88 100644
--- a/windows/make-windows-installer.bat
+++ b/windows/make-windows-installer.bat
@@ -18,9 +18,9 @@ if "%VERSION%" == "" (
 )
 echo Detected version %VERSION%
 echo Creating msi...
-candle -dVERSION=%VERSION% -dBINPATH=%BINPATH% pandoc.wxs
+candle -dVERSION=%VERSION% -dBINPATH=%BINPATH% *.wxs -out wixobj\
 if %errorlevel% neq 0 exit /b %errorlevel%
-light  -sw1076 -ext WixUIExtension -ext WixUtilExtension -out pandoc-%VERSION%-windows.msi pandoc.wixobj
+light  -sw1076 -ext WixUIExtension -ext WixUtilExtension -cultures:en-us -loc Pandoc-en-us.wxl -out pandoc-%VERSION%-windows.msi wixobj\*.wixobj
 if %errorlevel% neq 0 exit /b %errorlevel%
 echo Starting kSign: sign, then quit kSign to complete the build...
 kSign
diff --git a/windows/pandoc.wxs b/windows/pandoc.wxs
index d19ed81e1..878800149 100644
--- a/windows/pandoc.wxs
+++ b/windows/pandoc.wxs
@@ -1,18 +1,16 @@
-<?xml version="1.0"?>
 <?define UpgradeCode = "A68E8EF6-ABB1-4F22-A3C5-68DFDF0AB562" ?>
 <?if $(sys.BUILDARCH)=x64?>
-  <?define ProgFilesFolder="ProgramFiles64Folder"?>
+<?define ProgFilesFolder="ProgramFiles64Folder"?>
 <?else?>
-  <?define ProgFilesFolder="ProgramFilesFolder"?>
+<?define ProgFilesFolder="ProgramFilesFolder"?>
 <?endif?>
-
 <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
   <Product Id="*"
   UpgradeCode="$(var.UpgradeCode)" Name="Pandoc $(var.VERSION)"
   Version="$(var.VERSION)" Manufacturer="John MacFarlane"
   Language="1033">
 
-    <Package InstallerVersion="200" Compressed="yes"
+    <Package InstallerVersion="301" Compressed="yes"
     Comments="Windows Installer Package" />
     <Media Id="1" Cabinet="product.cab" EmbedCab="yes" />
     <Property Id="PREVIOUSVERSIONSINSTALLED" Secure="yes" />
@@ -21,7 +19,6 @@
         Minimum='0.0.0.0'  IncludeMinimum='yes'
         Maximum="99.0.0.0" IncludeMaximum="no" />
     </Upgrade>
-    <Property Id="ARPURLINFOABOUT" Value="http://pandoc.org" />
 
     <InstallExecuteSequence>
       <RemoveExistingProducts After="InstallFinalize"/>
@@ -126,92 +123,63 @@
       </Feature>
     </Feature>
 
+    
+    <!-- Set properties for add/remove programs -->
+    <Property Id="ARPURLINFOABOUT" Value="http://pandoc.org" />
+    <Property Id="ARPHELPLINK" Value="http://pandoc.org" />
+    <Property Id="ARPNOREPAIR" Value="yes" Secure="yes" />    <!-- Remove repair -->
+    <Property Id="ARPNOMODIFY" Value="yes" Secure="yes" />    <!-- Remove modify -->
 
+      
+    <!--Needed for WixUI_Advanced-->
+    <Property Id="ApplicationFolderName" Value="Pandoc" />
+    <Property Id="WixAppFolder" Value="WixPerUserFolder" />
+    
+    <!--For Single Package for dual purpose i.e. per User/Machine-->
+    <!--<Property Id="ALLUSERS" Value="2" Secure="yes" />-->
+    <Property Id="MSIINSTALLPERUSER" Value="1" />
+
+    <!--Inform about installed location-->
     <SetProperty Id="ARPINSTALLLOCATION" Value="[APPLICATIONFOLDER]"
                  After="CostFinalize" />
-
     <CustomAction Id="SetExitDialogOptText"
-                  Property="WIXUI_EXITDIALOGOPTIONALTEXT"
-                  Value="[ProductName] was installed in [APPLICATIONFOLDER]. You may need to restart Cmd/Powershell windows before using it." />
+                      Property="WIXUI_EXITDIALOGOPTIONALTEXT"
+                      Value="!(loc.ExitDialogText)" />
+    
+    <!--Offer Per User installs only on workstations (block on servers)-->
+    <SetProperty Id="WixUISupportPerUser" Value="0" Before="FindRelatedProducts">
+      <!--https://msdn.microsoft.com/en-us/library/windows/desktop/aa370329(v=vs.85).aspx-->
+      MsiNTProductType > 1
+    </SetProperty>
+    <SetProperty Id="WixUISupportPerUser" Value="1" Before="FindRelatedProducts" Action="CASupportPerUser">
+      MsiNTProductType = 1
+    </SetProperty>
+    <SetProperty Id="ALLUSERS" Value="1" Before="FindRelatedProducts">
+      MsiNTProductType > 1
+    </SetProperty>
+    <SetProperty Id="ALLUSERS" Value="{}" Before="FindRelatedProducts" Action="CASetPuaPackage">
+      MsiNTProductType = 1
+    </SetProperty>
+    <SetProperty Id="MSIINSTALLPERUSER" Value="1" Before="FindRelatedProducts">
+      MsiNTProductType = 1
+    </SetProperty>
+    <SetProperty Id="WixAppFolder" Value="WixPerMachineFolder" Before="FindRelatedProducts">
+      MsiNTProductType > 1
+    </SetProperty>
 
-    <CustomAction Id="CustomWixSetPerUserFolder"
-                  Property="WixPerUserFolder"
-                  Value="[LocalAppDataFolder][ApplicationFolderName]"
-                  Execute="immediate" />
-
-
-    <InstallExecuteSequence>
-      <Custom Action="CustomWixSetPerUserFolder" After="WixSetDefaultPerUserFolder">
-        ACTION="INSTALL" AND (ALLUSERS="" OR (ALLUSERS=2 AND (NOT Privileged)))
-      </Custom>
-    </InstallExecuteSequence>
+    <!--Make changes to PATH visible immeidiately-->
+    <CustomActionRef Id="WixBroadcastSettingChange" />
+    <CustomActionRef Id="WixBroadcastEnvironmentChange" />
 
     <InstallUISequence>
       <Custom Action="SetExitDialogOptText" Before="ExecuteAction">
         NOT Installed
       </Custom>
-      <Custom Action="CustomWixSetPerUserFolder" After="WixSetDefaultPerUserFolder">
-        ACTION="INSTALL" AND (ALLUSERS="" OR (ALLUSERS=2 AND (NOT Privileged)))
-      </Custom>
     </InstallUISequence>
-
-    <CustomActionRef Id="WixBroadcastSettingChange" />
-    <CustomActionRef Id="WixBroadcastEnvironmentChange" />
-
-    <Property Id="ApplicationFolderName" Value="Pandoc" />
-    <Property Id="WixAppFolder" Value="WixPerUserFolder" />
-    <Property Id="ALLUSERS" Value="2" Secure="yes" />
-    <Property Id="MSIINSTALLPERUSER" Value="1" />
-
-    <WixVariable Id="WixUILicenseRtf" Value="COPYING.rtf" />
-
-    <UI Id="MyWixUI_Advanced">
-      <UIRef Id="WixUI_Advanced" />
-      <UIRef Id="WixUI_ErrorProgressText" />
-
-      <Publish Dialog="InstallScopeDlg" Control="Next"
-               Event="NewDialog" Value="VerifyReadyDlg"
-               Order="6">WixAppFolder = "WixPerUserFolder"</Publish>
-
-      <Publish Dialog="InstallScopeDlg" Control="Next"
-               Property="APPLICATIONFOLDER"
-               Value="[$(var.ProgFilesFolder)][ApplicationFolderName]"
-               Order="7">WixAppFolder = "WixPerMachineFolder"</Publish>
-
-      <Publish Dialog="InstallScopeDlg" Control="Next"
-               Property="APPLICATIONFOLDER" Value="[LocalAppDataFolder][ApplicationFolderName]"
-               Order="8">WixAppFolder = "WixPerUserFolder"</Publish>
-
-      <Publish Dialog="InstallScopeDlg" Control="Next"
-               Property="MSIINSTALLPERUSER" Value="{}"
-               Order="18">WixAppFolder = "WixPerMachineFolder" AND ALLUSERS = 1</Publish>
-      <Publish Dialog="InstallScopeDlg" Control="Next"
-               Property="MSIINSTALLPERUSER" Value="1"
-               Order="19">WixAppFolder = "WixPerUserFolder" AND ALLUSERS = 2</Publish>
-      <Publish Dialog="InstallScopeDlg" Control="Next"
-               Property="ALLUSERS" Value="2"
-               Order="20">WixAppFolder = "WixPerUserFolder"</Publish>
-
-
-      <Publish Dialog="InstallDirDlg" Control="Next"
-               Event="NewDialog" Value="VerifyReadyDlg"
-               Order="4">
-        WIXUI_DONTVALIDATEPATH OR
-        WIXUI_INSTALLDIR_VALID="1"
-      </Publish>
-
-      <Publish Dialog="VerifyReadyDlg" Control="Back"
-               Event="NewDialog" Value="InstallScopeDlg"
-               Order="11">
-        WixAppFolder = "WixPerUserFolder"
-      </Publish>
-      <Publish Dialog="VerifyReadyDlg" Control="Back"
-               Event="NewDialog" Value="InstallDirDlg"
-               Order="12">
-        WixAppFolder = "WixPerMachineFolder"
-      </Publish>
-    </UI>
-
+    
+    <UIRef Id="WixUI_Advanced_Custom"/>
+    
   </Product>
-
+  
+  
 </Wix>