<?define UpgradeCode = "A68E8EF6-ABB1-4F22-A3C5-68DFDF0AB562" ?>
<?if $(sys.BUILDARCH)=x64?>
<?define ProgFilesFolder="ProgramFiles64Folder"?>
<?else?>
<?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="301" Compressed="yes"
    Comments="Windows Installer Package" />
    <Media Id="1" Cabinet="product.cab" EmbedCab="yes" />
    <Property Id="PREVIOUSVERSIONSINSTALLED" Secure="yes" />
    <Upgrade Id="$(var.UpgradeCode)">
      <UpgradeVersion Property='PREVIOUSVERSIONSINSTALLED'
        Minimum='0.0.0.0'  IncludeMinimum='yes'
        Maximum="99.0.0.0" IncludeMaximum="no" />
    </Upgrade>

    <InstallExecuteSequence>
      <RemoveExistingProducts After="InstallFinalize"/>
    </InstallExecuteSequence>

    <Property Id="DISABLEADVTSHORTCUTS" Value="1" />

    <Directory Id="TARGETDIR" Name="SourceDir">

      <Directory Id="$(var.ProgFilesFolder)">
        <Directory Id="APPLICATIONFOLDER" Name="Pandoc">
          <Component Id="MainExecutable"
                     Guid="ECD35082-4C28-49E1-977E-B90FC7C400C7">
            <RegistryValue Root="HKMU"
                           Key="Software\John MacFarlane\Pandoc"
                           Name="Version" Type="string" Value="[ProductVersion]"
                           KeyPath="yes"/>
            <RemoveFolder Id="APPLICATIONFOLDER" On="uninstall"/>
            <File Id="pandocEXE" Name="pandoc.exe"
                  Source="$(var.BINPATH)\pandoc.exe" />
            <File Id="pandocCOPYRIGHT" Name="COPYRIGHT.txt"
                  Source="$(var.BINPATH)\COPYRIGHT.txt" />
            <File Id="pandocCOPYING" Name="COPYING.rtf"
                  Source="$(var.BINPATH)\COPYING.rtf" />
          </Component>

          <Component Id="CitationSupport"
                     Guid="0A214839-2E69-4026-8DBB-0F0A9DB75C12">
            <RegistryValue Root="HKMU"
                           Key="Software\John MacFarlane\Pandoc"
                           Name="Version" Type="string" Value="[ProductVersion]"
                           KeyPath="yes"/>
          </Component>

          <Component Id="Documentation"
                     Guid="A8D54A76-1A3D-4647-8327-81B69D39D8A3">
            <File Id="pandocMANUAL" Name="Pandoc User's Guide.html"
                  Source="$(var.BINPATH)\MANUAL.html" KeyPath="yes">
              <Shortcut Id="ApplicationStartMenuShortcut"
                        Directory="ApplicationProgramsFolder"
                        Name="Pandoc User’s Guide" Advertise="yes" />
            </File>
          </Component>


          <Component Id="UpdateUserPath"
                     Guid="7ECEAD05-CA5C-4147-82CB-F7CADABAC7F3"
                     KeyPath="yes">
            <Condition>ALLUSERS = "" OR ALLUSERS = 2</Condition>
            <Environment Id='SetUserPath' Name='PATH' Action='set'
                       Permanent='no' System='no' Part='last'
                       Value='[APPLICATIONFOLDER]' />
          </Component>

          <Component Id="UpdateSystemPath"
                     Guid="F8AC4135-C0AE-48C7-BAC5-311DAC97CFD8"
                     KeyPath="yes">
            <Condition>ALLUSERS = 1</Condition>
            <Environment Id='SetSystemPath' Name='PATH' Action='set'
                       Permanent='no' System='yes' Part='last'
                       Value='[APPLICATIONFOLDER]' />
          </Component>

        </Directory>
      </Directory>

      <Directory Id="ProgramMenuFolder">
        <Directory Id="ApplicationProgramsFolder" Name="Pandoc">
          <Component Id="ApplicationShortcut"
                     Guid="7F807DD5-CC54-474A-B571-89630893F563">
            <RemoveFolder Id="ApplicationProgramsFolder"
                          On="uninstall"/>
            <RegistryValue Root="HKMU" Key="Software\John MacFarlane\Pandoc"
                           Name="ShortcutInstalled" Type="integer" Value="1"
                           KeyPath="yes"/>
          </Component>
        </Directory>
      </Directory>

    </Directory>

    <Feature Id="Complete" Level="1" Title="Pandoc $(var.VERSION)"
             Description="Complete package"  Display="expand"
             ConfigurableDirectory="APPLICATIONFOLDER">
      <Feature Id="MainProgram"
               Title="Program"
               Description="The main executable."
               Level="1">
        <ComponentRef Id="MainExecutable" />
        <ComponentRef Id="UpdateUserPath" />
        <ComponentRef Id="UpdateSystemPath" />
      </Feature>
      <Feature Id="Manual" Title="Manual">
        <ComponentRef Id="Documentation" />
        <ComponentRef Id="ApplicationShortcut" />
      </Feature>
      <Feature Id="Citation" Title="Citation Support"
               Description="Citation support.">
        <ComponentRef Id="CitationSupport" />
      </Feature>
    </Feature>


    <!-- Set properties for add/remove programs -->
    <Property Id="ARPURLINFOABOUT" Value="https://pandoc.org" />
    <Property Id="ARPHELPLINK" Value="https://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="!(loc.ExitDialogText)" />

    <!--Offer Per User installs only on workstations (block on servers)-->
    <!--Unless ALLUSERS=1 is specified on command line-->
    <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">
      (NOT ALLUSERS = 1) AND MsiNTProductType = 1
    </SetProperty>
    <SetProperty Id="MSIINSTALLPERUSER" Value="1" Before="FindRelatedProducts">
      (NOT ALLUSERS = 1) AND MsiNTProductType = 1
    </SetProperty>
    <SetProperty Id="WixAppFolder" Value="WixPerMachineFolder" Before="FindRelatedProducts">
      MsiNTProductType > 1
    </SetProperty>

    <!--Make changes to PATH visible immeidiately-->
    <CustomActionRef Id="WixBroadcastSettingChange" />
    <CustomActionRef Id="WixBroadcastEnvironmentChange" />

    <InstallUISequence>
      <Custom Action="SetExitDialogOptText" Before="ExecuteAction">
        NOT Installed
      </Custom>
    </InstallUISequence>

    <UIRef Id="WixUI_Advanced_Custom"/>
    <!--Enable better description when debug logging-->
    <UIRef Id="WixUI_ErrorProgressText" />

  </Product>


</Wix>