<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">

  <!-- This is how we include wxi files -->
  <?include "parameters.wxi" ?>

  <!--
    Id="*" is to enable upgrading. * means that the product ID will be autogenerated on each build.
    Name is made of localized product name and version number.
  -->
  <Product Id="*" Name="!(loc.ProductName) v$(var.DisplayVersionNumber)" Language="!(loc.LANG)"
          Version="$(var.VersionNumber)" Manufacturer="!(loc.ManufacturerName)" UpgradeCode="$(var.UpgradeCode)">

    <!--
      Minimum installer version (2.0) - Window XP and above.
      The install scope is per machine, not the current user
    -->
    <Package InstallerVersion="200" InstallPrivileges="elevated"
             Compressed="yes" InstallScope="perMachine" />

    <Media Id="1" Cabinet="Inspec.cab" EmbedCab="yes" CompressionLevel="high" />

    <!--
      Uncomment launch condition below to check for minimum OS
      601 = Windows 7/Server 2008R2.
    -->
    <!-- Condition Message="!(loc.MinimumOSVersionMessage)">
      <![CDATA[Installed OR VersionNT >= 601]]>
    </Condition -->

    <!-- We always do Major upgrades -->
    <MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeErrorMessage)" />

    <!--
      If fastmsi is set, custom actions will be invoked during install to unzip
      project files, and during uninstall to remove the project folder
    -->
    <% if fastmsi %>
    <SetProperty Id="FastUnzip"
                 Value="FASTZIPDIR=[INSTALLLOCATION];FASTZIPAPPNAME=cinc-auditor"
                 Sequence="execute"
                 Before="FastUnzip" />

    <CustomAction Id="FastUnzip"
                  BinaryKey="CustomActionFastMsiDLL"
                  DllEntry="FastUnzip"
                  Execute="deferred"
                  Impersonate="no"
                  Return="check" />

    <Binary Id="CustomActionFastMsiDLL"
            SourceFile="CustomActionFastMsi.CA.dll" />

    <CustomAction Id="Cleanup"
                  Directory="INSTALLLOCATION"
                  ExeCommand="cmd /C &quot;rd /S /Q cinc-auditor&quot;"
                  Execute="deferred"
                  Impersonate="no"
                  Return="ignore" />

    <InstallExecuteSequence>
      <Custom Action="FastUnzip" After="InstallFiles">NOT Installed</Custom>
      <Custom Action="Cleanup" After="RemoveFiles">REMOVE~="ALL"</Custom>
    </InstallExecuteSequence>

    <UI>
      <ProgressText Action="FastUnzip">!(loc.FileExtractionProgress)</ProgressText>
    </UI>
    <% end %>

    <CustomActionRef Id="WixBroadcastSettingChange" />
    <CustomActionRef Id="WixBroadcastEnvironmentChange" />

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="WindowsVolume">
        <Directory Id="INSTALLLOCATION" Name="cinc-project">
          <Directory Id="PROJECTLOCATION" Name="cinc-auditor">
            <Directory Id="PROJECTLOCATIONBIN" Name="bin">
              <Component Id="InspecPath" Guid="{6169A1CB-D9E8-4C7b-ABB8-B6303A9A319A}" >
                <Environment Id="Environment"
                             Name="PATH" Action="set" Part="last" System="yes" Value="[PROJECTLOCATIONBIN]" />
              </Component>
            </Directory>
          </Directory>
        </Directory>
      </Directory>
    </Directory>

    <!-- Set the components defined in our fragment files that will be used for our feature  -->
    <Feature Id="InspecFeature" Title="!(loc.FeatureMainName)" Absent="disallow" AllowAdvertise="no" Level="1" ConfigurableDirectory="INSTALLLOCATION">
      <ComponentGroupRef Id="ProjectDir" />
      <ComponentRef Id="InspecPath" />
    </Feature>

    <!--
      UI Stuff
    -->
    <Icon Id="inspec16.ico" SourceFile="Resources\assets\inspec_16x16.ico"/>
    <Icon Id="inspec32.ico" SourceFile="Resources\assets\inspec_32x32.ico"/>
    <Icon Id="inspec.ico" SourceFile="Resources\assets\inspec.ico"/>
    <Property Id="ARPPRODUCTICON" Value="inspec16.ico" />
    <Property Id="ARPHELPLINK" Value="https://www.cinc.sh/" />
    <Property Id="WIXUI_INSTALLDIR" Value="INSTALLLOCATION" />

    <UIRef Id="InspecUI_InstallDir"/>
    <UI Id="InspecUI_InstallDir">
      <UIRef Id="WixUI_FeatureTree"/>
      <TextStyle Id="WixUI_Font_Normal_White" FaceName="Tahoma" Size="8" Red="255" Green="255" Blue="255" />
      <TextStyle Id="WixUI_Font_Bigger_White" FaceName="Tahoma" Size="12" Red="255" Green="255" Blue="255" />
      <TextStyle Id="WixUI_Font_Title_White" FaceName="Tahoma" Size="9" Bold="yes" Red="255" Green="255" Blue="255" />
    </UI>

    <WixVariable Id="WixUILicenseRtf" Value="Resources\assets\LICENSE.rtf" />
    <WixVariable Id="WixUIDialogBmp" Value="Resources\assets\dialog_background.bmp" />
    <WixVariable Id="WixUIBannerBmp" Value="Resources\assets\banner_background.bmp" />

    <WixVariable Id="WixUIExclamationIco" Value="Resources\assets\inspec_32x32.ico" />
    <WixVariable Id="WixUIInfoIco" Value="Resources\assets\inspec_32x32.ico" />
    <WixVariable Id="WixUINewIco" Value="Resources\assets\inspec_16x16.ico" />
    <WixVariable Id="WixUIUpIco" Value="Resources\assets\inspec_16x16.ico" />

  </Product>
</Wix>
