The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
<?xml version="1.0" encoding="utf-8"?>

<?include Variables.wxi ?>

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="$(var.ProductGUID)" UpgradeCode="$(var.UpgradeCode)"
           Language='1033'  Codepage="1252"  Manufacturer="$(var.Manufacturer)"
           Name="$(var.ProductName)" Version="$(var.CurrentVersion)">

    <Package Id='*' Description='Perl for Win32 operating systems.'  
             Languages='1033' SummaryCodepage="1252" Platform="$(var.Platform)" Comments="$(var.PkgComments)" 
             InstallerVersion='200' Compressed='yes' InstallPrivileges='elevated' InstallScope="perMachine" />
    
    <Media Id='1' Cabinet='Perl.cab' CompressionLevel='high' EmbedCab='yes' />
    
    <Property Id='INSTALLDIR' Value="$(var.DefaultInstallDir)" />
    <Property Id="ARPCOMMENTS" Value="$(var.ProductName) version [%app_version%]" />
    <Property Id="ARPCONTACT" Value="$(var.Manufacturer)" />
    <Property Id="ARPURLINFOABOUT" Value="$(var.URLAbout)" />
    <Property Id="ARPHELPLINK" Value="$(var.URLHelp)" />
    <Property Id="ARPPRODUCTICON" Value="i_main_ico" />
    <Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" />
    <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOX" Value="1" />
    <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Read README file." />
    <Property Id="WIXUI_EXITDIALOGOPTIONALTEXT" Value="Before you start using $(var.ProductName), read the Release Notes and the README file. These are both available from the start menu under &quot;$(var.ProductName)&quot;." />
    <Property Id="WixShellExecTarget" Value="[#f_readme_txt]" />
    <Property Id="MergeModuleID" Value="$(var.MergeModuleID)" /> <!-- BEWARE: needed for ClearSite/ClearFolders hack (see HelperCA sources) -->

    <Property Id="UPGRADEDIR">
      <RegistrySearch Id="InstallDir" Root="HKLM" Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\[OLDERVERSIONBEINGUPGRADED]" Name="InstallLocation" Type="raw" />
    </Property>

    <Icon Id="i_main_ico" SourceFile="$(var.FileMainIcon)" />
    
    <WixVariable Id="WixUILicenseRtf" Value="$(var.FileLicenseRtf)" />
    <WixVariable Id="WixUIDialogBmp"  Value="$(var.FileDialogBmp)" />
    <WixVariable Id="WixUIBannerBmp"  Value="$(var.FileBannerBmp)" />
    <Binary Id="Bmp_MainBanner"  SourceFile="$(var.FileBannerBmp)" />

    <Upgrade Id="$(var.UpgradeCode)">
      <UpgradeVersion Property="NEWERVERSIONDETECTED"      Minimum="$(var.CurrentVersion)" IncludeMinimum='no' OnlyDetect="yes" />
      <UpgradeVersion Property="OLDERVERSIONBEINGUPGRADED" Minimum="$(var.MinCanUpgradeVer)" IncludeMinimum='yes' Maximum="$(var.CurrentVersion)" IncludeMaximum='no' />
      <UpgradeVersion Property="UPG_NOT_POSSIBLE"     Minimum='0.0.0' IncludeMinimum='yes' Maximum="$(var.MinCanUpgradeVer)" IncludeMaximum='no' OnlyDetect="yes" />
    </Upgrade>
    <!-- http://stackoverflow.com/questions/320921/how-to-add-a-wix-custom-action-that-happens-only-on-uninstall-via-msi -->

    <Binary Id='B_HelperCA' SourceFile="$(var.FileHelperDLL)" />
    <CustomAction Id='PreventDowngrading'  Error='A newer version of $(var.ProductName) is already installed.' />
    <CustomAction Id='UninstallOldVersion' Error='Already installed version of $(var.ProductName) cannot be upgraded; it has to be uninstalled first.' />
    
    <CustomAction Id="CA_GetARPInstallLoc" Property ="INSTALLDIR"         Value="[UPGRADEDIR]"  Execute="immediate"/>
    <CustomAction Id="CA_SetARPInstallLoc" Property ="ARPINSTALLLOCATION" Value="[INSTALLDIR]"  Execute="immediate"/>
    <CustomAction Id="CA_SetFileList"      Property ="CA_Relocate"        Value="MSI;[INSTALLDIR];[#f_perl2_reloc_txt]" Return="check" />
    <CustomAction Id="CA_SetLocation_Perl" Property ="P_Perl_Location" Value="&quot;[#f_perl_bin_perl_exe.$(var.MergeModuleID)]&quot;" Execute="immediate"/>
    <CustomAction Id='CA_ClearSiteFolder'  BinaryKey='B_HelperCA' DllEntry='ClearSiteFolder' />
    <CustomAction Id='CA_ClearFolders'     BinaryKey='B_HelperCA' DllEntry='ClearFoldersFast' />
    <CustomAction Id='CA_CheckForSpaces'   BinaryKey='B_HelperCA' DllEntry='CheckForSpaces' />
    <CustomAction Id="CA_Relocate"         BinaryKey="B_HelperCA" DllEntry="RelocateMSI" Return="check" Execute="deferred" />
    <CustomAction Id="CA_SpecialRefresh"   BinaryKey="B_HelperCA" DllEntry="SpecialRefresh" Execute="deferred" Impersonate="yes" />
    <CustomAction Id="LaunchReadmeFile"    BinaryKey="WixCA"      DllEntry="WixShellExec" Impersonate="yes" />
    
    <InstallExecuteSequence>
      <!-- InstallExecuteSequence is used to define Custom Actions that fire after the UI is finished and the install is starting to execute -->
      <RemoveExistingProducts After='InstallInitialize' /> <!-- Windows Installer sets the UPGRADINGPRODUCTCODE Property when it runs this action -->
      <Custom Action='PreventDowngrading'  After ='FindRelatedProducts'>NEWERVERSIONDETECTED</Custom>
      <Custom Action='UninstallOldVersion' After ='FindRelatedProducts'>UPG_NOT_POSSIBLE</Custom>
      <Custom Action='CA_ClearSiteFolder'  Before='InstallInitialize'>(Installed AND (NOT UPGRADINGPRODUCTCODE)) OR (Installed AND UPGRADINGPRODUCTCODE AND UPG_NOT_POSSIBLE)</Custom> <!-- remove perl/site folder -->
      <Custom Action='CA_ClearFolders'     Before='InstallInitialize'>REMOVE="ALL"</Custom> <!-- remove cpan/cpanplus/ppm folders -->
      <Custom Action="CA_SetARPInstallLoc" Before="RegisterProduct" />
      <Custom Action="CA_SetLocation_Perl" After ="CostFinalize"/>
      <Custom Action="CA_SetFileList"      After ="InstallFiles"/>    
      <Custom Action="CA_Relocate"         After ="CA_SetFileList">NOT Installed</Custom>
      <Custom Action="CA_SpecialRefresh"   After ="PublishProduct" /> <!-- or maybe After="WriteEnvironmentStrings" -->
    </InstallExecuteSequence>
    
    <InstallUISequence>
      <!-- InstallUISequence is used to define a dialog or Custom Action that fires in the UI sequence of events during the install -->
      <Custom Action='PreventDowngrading'  After ='FindRelatedProducts'>NEWERVERSIONDETECTED</Custom>
      <Custom Action='UninstallOldVersion' After ='FindRelatedProducts'>UPG_NOT_POSSIBLE</Custom>
      <Custom Action="CA_GetARPInstallLoc" Before="CostInitialize">OLDERVERSIONBEINGUPGRADED AND UPGRADEDIR</Custom>
    </InstallUISequence>
    
    <UI>
      <ProgressText Action="CA_ClearSiteFolder">Preparing the site folder for cleaning... (please wait a while)</ProgressText>
    </UI>

    <Condition Message="Cannot install on Windows 9x or ME systems.">VersionNT</Condition>
    <Condition Message="Cannot install on Windows NT 4.0 or Windows 2000 systems.">VersionNT &gt; 500</Condition>

    <UIRef Id='WixUI_MyInstallDirDlg' />
    <UIRef Id='WixUI_ErrorProgressText' />
    <UIRef Id='WixUI_Common' />
    
    <UI Id="WixUI_MyInstallDirDlg">
        <TextStyle Id="WixUI_Font_Normal" FaceName="Tahoma" Size="8" />
        <TextStyle Id="WixUI_Font_Bigger" FaceName="Tahoma" Size="12" />
        <TextStyle Id="WixUI_Font_Title"  FaceName="Tahoma" Size="9" Bold="yes" />

        <Property Id="DefaultUIFont" Value="WixUI_Font_Normal" />
        <Property Id="WixUI_Mode"    Value="InstallDir" />
        <Property Id="ARPNOMODIFY"   Value="1" />

        <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="ExitDialog" />

        <Publish Dialog="BrowseDlg"             Control="OK"     Event="DoAction" Value="WixUIValidatePath" Order="3">1</Publish>
        <Publish Dialog="BrowseDlg"             Control="OK"     Event="SpawnDialog" Value="InvalidDirDlg" Order="4"><![CDATA[WIXUI_INSTALLDIR_VALID<>"1"]]></Publish>
        <Publish Dialog="ExitDialog"            Control="Finish" Event="EndDialog" Value="Return" Order="999">1</Publish>
        <Publish Dialog="WelcomeDlg"            Control="Next"   Event="NewDialog" Value="LicenseAgreementDlg">1</Publish>
        <Publish Dialog="LicenseAgreementDlg"   Control="Back"   Event="NewDialog" Value="WelcomeDlg">1</Publish>
        <Publish Dialog="LicenseAgreementDlg"   Control="Next"   Event="NewDialog" Value="D_MyInstallDirDlg">LicenseAccepted = "1"</Publish>
        <Publish Dialog="D_MyInstallDirDlg"     Control="Back"   Event="NewDialog" Value="LicenseAgreementDlg">1</Publish>
        <Publish Dialog="D_MyInstallDirDlg"     Control="Next"   Event="SetTargetPath" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
        <Publish Dialog="D_MyInstallDirDlg"     Control="Next"   Event="DoAction" Value="WixUIValidatePath" Order="2">NOT WIXUI_DONTVALIDATEPATH</Publish>
        <Publish Dialog="D_MyInstallDirDlg"     Control="Next"   Event="SpawnDialog" Value="InvalidDirDlg" Order="3"><![CDATA[NOT WIXUI_DONTVALIDATEPATH AND WIXUI_INSTALLDIR_VALID<>"1"]]></Publish>
        <Publish Dialog="D_MyInstallDirDlg"     Control="Next"   Event="DoAction" Value="CA_CheckForSpaces" Order="4">NOT WIXUI_DONTVALIDATEPATH</Publish>
        <Publish Dialog="D_MyInstallDirDlg"     Control="Next"   Event="SpawnDialog" Value="D_BadLocationDlg" Order="5"><![CDATA[NOT WIXUI_DONTVALIDATEPATH AND WIXUI_INSTALLDIR_VALID<>"1"]]></Publish>
        <Publish Dialog="D_MyInstallDirDlg"     Control="Next"   Event="NewDialog" Value="VerifyReadyDlg" Order="6">WIXUI_DONTVALIDATEPATH OR WIXUI_INSTALLDIR_VALID="1"</Publish>
        <Publish Dialog="D_MyInstallDirDlg"     Control="ChangeFolder" Property="_BrowseProperty" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
        <Publish Dialog="D_MyInstallDirDlg"     Control="ChangeFolder" Event="SpawnDialog" Value="BrowseDlg" Order="2">1</Publish>
        <Publish Dialog="VerifyReadyDlg"        Control="Back"   Event="NewDialog" Value="D_MyInstallDirDlg" Order="1">NOT Installed</Publish>
        <Publish Dialog="VerifyReadyDlg"        Control="Back"   Event="NewDialog" Value="MaintenanceTypeDlg" Order="2">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="ExitDialog"            Control="Finish" Event="DoAction" Value="LaunchReadmeFile">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish>

        <Dialog Id="D_MyInstallDirDlg" Width="370" Height="270" Title="!(loc.InstallDirDlg_Title)">
          <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="!(loc.WixUINext)" />
          <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="!(loc.WixUIBack)" />
          <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="Description" Type="Text" X="25" Y="23" Width="280" Height="15" Transparent="yes" NoPrefix="yes" Text="!(loc.InstallDirDlgDescription)" />
          <Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes" Text="!(loc.InstallDirDlgTitle)" />
          <Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="Bmp_MainBanner" />
          <Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0" />
          <Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />
          <Control Id="FolderLabel" Type="Text" X="20" Y="60" Width="290" Height="30" NoPrefix="yes" Text="!(loc.InstallDirDlgFolderLabel)" />
          <Control Id="Folder" Type="PathEdit" X="20" Y="100" Width="320" Height="18" Property="WIXUI_INSTALLDIR" Indirect="yes" />
          <Control Id="ChangeFolder" Type="PushButton" X="20" Y="120" Width="56" Height="17" Text="!(loc.InstallDirDlgChange)" />
        </Dialog>

        <Dialog Id="D_BadLocationDlg" Width="260" Height="85" Title="!(loc.InstallDirDlg_Title)" NoMinimize="yes">
          <Control Id="Return" Type="PushButton" X="100" Y="57" Width="56" Height="17" Default="yes" Cancel="yes" Text="&amp;Return">
            <Publish Event="EndDialog" Value="Return">1</Publish>
          </Control>
          <Control Id="Text" Type="Text" X="48" Y="15" Width="194" Height="30" TabSkip="no">
            <Text>$(var.ProductName) cannot be installed in a directory with spaces or non-ASCII characters.</Text>
          </Control>
        </Dialog>
    </UI>

<!-- generated start menu icons -->
[%xml_startmenu_icons-%]
<!-- generated start menu icons - END -->
    
    <Directory Id="TARGETDIR" Name="SourceDir">

      <Directory Id='ProgramMenuFolder'>
        <Directory Id='D_App_Menu' Name='$(var.ProductName)'>
<!-- generated start menu folder -->
[%xml_startmenu-%]
<!-- generated start menu folder - END -->
        </Directory>
      </Directory>

      <Directory Id="INSTALLDIR">
        <Merge Id="strawberry_msm" Language="1033" SourceFile="[%msm_filename%]" DiskId="1" />

        <!-- shell associations -->
        <Component Id="C_RegistryEntries" DisableRegistryReflection="yes" Guid="{444423AA-572A-313F-B6CB-BF89C746EBE3}">
          <RegistryKey   Id="RK_sp1010c_executecommand" Action="createAndRemoveOnUninstall" Key="SOFTWARE\Classes\Perl_program_file\shell\Execute Perl Program\command" Root="HKLM" />
          <RegistryKey   Id="RK_sp1010c_execute"        Action="createAndRemoveOnUninstall" Key="SOFTWARE\Classes\Perl_program_file\shell\Execute Perl Program" Root="HKLM" />
          <RegistryKey   Id="RK_sp1010c_shell"          Action="createAndRemoveOnUninstall" Key="SOFTWARE\Classes\Perl_program_file\shell" Root="HKLM" />
          <RegistryKey   Id="RK_sp1010c_root"           Action="createAndRemoveOnUninstall" Key="SOFTWARE\Classes\Perl_program_file" Root="HKLM" />
          <RegistryValue Id="RV_sp1010r_pointer"        Root="HKCR" Key=".pl" Value="Perl_program_file" Type="string" KeyPath="yes" />
          <RegistryValue Id="RV_sp1010c_pointer"        Root="HKLM" Key="SOFTWARE\Classes\Perl_program_file" Value="Perl program file" Type="string" />
          <RegistryValue Id="RV_sp1010c_executecommand" Root="HKLM" Key="SOFTWARE\Classes\Perl_program_file\shell\Execute Perl Program\command" Value="[P_Perl_Location] &quot;%1&quot; %*" Type="string" />
        </Component>

        <!-- xxx the following setion is a HACK -->
        <Component Id="C_Removal" Guid="{444429AA-91B4-3C1E-891C-BAB97EC5FF1C}" KeyPath="yes">
          <RemoveFolder Id="rm1" Directory="d_win32" On="uninstall" />
          <RemoveFile Id="rm2" Directory="d_win32" Name="*" On="uninstall" />
        </Component>

<!-- generated directory tree -->
[%xml_msi_dirtree-%]
<!-- generated directory tree - END -->
      </Directory>
    </Directory>
    
    <Feature Id="feat_MSI"  Title="MSI Files" Level="1" />  <!-- all members are included via Feature attribute -->   
    <Feature Id="feat_StartMenu" Title="Start Menu" Level="1" /> <!-- all members are included via Feature attribute -->
    <Feature Id="F_MainApplication" Title="Main Application" Level="1">
      <ComponentRef Id="C_RegistryEntries" />
      <ComponentRef Id="C_Removal" />
      <MergeRef Id="strawberry_msm" />
    </Feature>
    
  </Product>
</Wix>