<?xml version="1.0"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">

  <?define ProductName="Double Commander" ?>
  <?define UpgradeCode="D220A081-E26D-4ECD-B399-EFEB4D6678EA" ?>

   <Product
     Id="*"
     UpgradeCode="$(var.UpgradeCode)"
     Name="$(var.ProductName)"
     Version="$(var.ProductVersion)"
     Manufacturer="Alexander Koblov"
     Language="1033">

      <Package InstallerVersion="200" Compressed="yes" />

      <Media Id="1" Cabinet="product.cab" EmbedCab="yes"/>
      <Icon Id="ProductIcon" SourceFile="doublecmd.ico"/>
      <Property Id="ARPPRODUCTICON" Value="ProductIcon"/>
      <Property Id="ARPURLINFOABOUT" Value="https://doublecmd.sourceforge.io"/>
      <Property Id="ARPNOREPAIR" Value="1"/>

      <Upgrade Id="$(var.UpgradeCode)">
         <UpgradeVersion Minimum="$(var.ProductVersion)" OnlyDetect="yes" Property="NEWERVERSIONDETECTED"/>
         <UpgradeVersion Minimum="0.0.0" Maximum="$(var.ProductVersion)" IncludeMinimum="yes" IncludeMaximum="no"
                         Property="OLDERVERSIONBEINGUPGRADED"/>
      </Upgrade>
      <Condition Message="A newer version of this software is already installed.">NOT NEWERVERSIONDETECTED</Condition>

      <Directory Id="TARGETDIR" Name="SourceDir">
         <Directory Id="$(var.ProgramFiles)">
            <Directory Id="APPLICATIONFOLDER" Name="$(var.ProductName)">
            </Directory>
         </Directory>
         <Directory Id="ProgramMenuFolder">
            <Directory Id="ApplicationProgramsFolder" Name="$(var.ProductName)">
               <Component Id="ApplicationShortcut" Guid="BA37DDBD-5F67-4BA5-B5B8-01B3998E5BDE">
                  <Shortcut
                    Id="Shortcut"
                    Name="$(var.ProductName)"
                    Description="$(var.ProductName)"
                    Target="[APPLICATIONFOLDER]doublecmd.exe"
                    WorkingDirectory="APPLICATIONFOLDER"/>
                  <RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
                  <RegistryValue Root="HKCU" Key="Software\$(var.ProductName)" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
               </Component>
            </Directory>
         </Directory>
         <Directory Id="DesktopFolder" Name="Desktop">
             <Component Id="ApplicationShortcutDesktop" Guid="*">
                  <Shortcut
                    Id="ApplicationDesktopShortcut"
                    Name="$(var.ProductName)"
                    Description="$(var.ProductName)"
                    Target="[APPLICATIONFOLDER]doublecmd.exe"
                    WorkingDirectory="APPLICATIONFOLDER"/>
                  <RemoveFolder Id="DesktopFolder" On="uninstall"/>
                  <RegistryValue Root="HKCU" Key="Software\$(var.ProductName)" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
             </Component>
         </Directory>
      </Directory>

      <CustomAction
        Id="Overwrite_WixSetDefaultPerMachineFolder"
        Property="WixPerMachineFolder"
        Value="[$(var.ProgramFiles)][ApplicationFolderName]"
        Execute="immediate" />

      <InstallUISequence>
        <Custom Action="Overwrite_WixSetDefaultPerMachineFolder" After="WixSetDefaultPerMachineFolder" />
      </InstallUISequence>

      <InstallExecuteSequence>
         <RemoveExistingProducts After="InstallValidate"/>
         <Custom Action="Overwrite_WixSetDefaultPerMachineFolder" After="WixSetDefaultPerMachineFolder" />
      </InstallExecuteSequence>

      <Feature Id="DefaultFeature" Level="1" Display="hidden">
         <ComponentGroupRef Id="HeatGroup"/>
      </Feature>

      <Feature Id="ApplicationShortcut" Level="1" Title="Start Menu shortcut">
         <ComponentRef Id="ApplicationShortcut" />
      </Feature>

      <Feature Id="ApplicationShortcutDesktop" Level="1" Title="Desktop shortcut" TypicalDefault="advertise">
         <ComponentRef Id="ApplicationShortcutDesktop" />
      </Feature>

      <WixVariable Id="WixUILicenseRtf" Value="license.rtf" />

      <Property Id="ApplicationFolderName" Value="$(var.ProductName)" />
      <Property Id="WixAppFolder" Value="WixPerMachineFolder" />

      <Property Id="ALLUSERS" Secure="yes" Value="2" />
      <Property Id="MSIINSTALLPERUSER" Secure="yes" Value="{}" />
      <UI>
         <UIRef Id="WixUI_Advanced" />
         <Publish Dialog="InstallScopeDlg" Control="Next" Property="MSIINSTALLPERUSER" Value="1" Order="3">WixAppFolder = "WixPerUserFolder"</Publish>
         <Publish Dialog="InstallScopeDlg" Control="Next" Property="MSIINSTALLPERUSER" Value="{}" Order="2">WixAppFolder = "WixPerMachineFolder"</Publish>
      </UI>
   </Product>
</Wix>