<?xml version="1.0" encoding="UTF-8"?>

<?include AerofoilPackageDefs.wxi ?>
<?include AerofoilPackageVersion.wxi ?>
<!--
    You're probably getting a build failure on this line ^^^
    This is because the Aerofoil upgrade code is not included in this project, to prevent collision with Aerofoil's upgrade GUID.
    To fix this, create the AerofoilPackageDefs.wxi file in the ReleasePackageInstaller project dir.  It should look like this:

<?xml version="1.0" encoding="utf-8"?>
<Include>
  <?define AerofoilUpgradeCode="PUT A GUID HERE" ?>
</Include>

    DO NOT USE AEROFOIL'S UPGRADE CODE GUID FOR YOUR OWN PROJECTS, it will cause your project to be considered a version of
    Aerofoil, causing it to either fail to install, or uninstall Aerofoil itself.

    If for some reason you need to do this or insist on doing it anyway, Aerofoil's upgrade code GUID is 2ae0587c-2a5f-4299-b5a8-e6cfed7cd84c
-->

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" Name="Aerofoil" Language="1033" Version="$(var.AerofoilReleaseVersion)" Manufacturer="The Aerofoil Project" UpgradeCode="$(var.AerofoilUpgradeCode)">
    <Package InstallerVersion="301" Compressed="yes" InstallScope="perMachine">
    </Package>

    <Icon Id="icon.ico" SourceFile="$(var.Aerofoil.ProjectDir)\ConvertedResources\Large128.ico" />

    <Property Id="ARPPRODUCTICON" Value="icon.ico" />

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
		<MediaTemplate CompressionLevel="high" EmbedCab="yes" />

    <Directory Id="TARGETDIR" Name="SourceDir">
      <!-- Installation directory -->
      <Directory Id="ProgramFiles64Folder">
        <Directory Id="AEROFOILPRODUCTDIR" Name="Aerofoil">
          <Directory Id="AEROFOILRESOURCESDIR" Name="Resources" />
          <Directory Id="AEROFOILPACKAGEDDIR" Name="Packaged">
            <Directory Id="AEROFOILHOUSESDIR" Name="Houses" />
            <Directory Id="AEROFOILWINCURSORSDIR" Name="WinCursors" />
          </Directory>
          <Directory Id="AEROFOILDOCUMENTATIONDIR" Name="Documentation" />
          <Directory Id="AEROFOILTOOLSDIR" Name="Tools" />
        </Directory>
      </Directory>

      <!-- Start menu -->
      <Directory Id="ProgramMenuFolder">
        <Directory Id="ApplicationProgramsFolder" Name="Aerofoil"/>
      </Directory>


      <!-- Desktop -->
      <Directory Id="DesktopFolder" Name="Desktop" />
    </Directory>

    <DirectoryRef Id="AEROFOILPRODUCTDIR">
      <Component Id="Aerofoil.exe" Guid="*">
        <File Id="Aerofoil.exe" Source="$(var.Aerofoil.TargetPath)" KeyPath="yes" Checksum="yes" />
      </Component>
      <Component Id="FreeType.dll" Guid="*">
        <File Id="FreeType.dll" Source="$(var.FreeType.TargetPath)" KeyPath="yes" Checksum="yes"/>
      </Component>
      <Component Id="GpApp.dll" Guid="*">
        <File Id="GpApp.dll" Source="$(var.GpApp.TargetPath)" KeyPath="yes" Checksum="yes"/>
      </Component>
      <Component Id="GpAudioDriver_XAudio2.dll" Guid="*">
        <File Id="GpAudioDriver_XAudio2.dll" Source="$(var.GpAudioDriver_XAudio2.TargetPath)" KeyPath="yes" Checksum="yes"/>
      </Component>
      <Component Id="xaudio2_9redist.dll" Guid="*">
        <File Id="xaudio2_9redist.dll" Source="$(var.GpAudioDriver_XAudio2.TargetDir)xaudio2_9redist.dll" KeyPath="yes" Checksum="yes"/>
      </Component>
      <Component Id="GpDisplayDriver_D3D11.dll" Guid="*">
        <File Id="GpDisplayDriver_D3D11.dll" Source="$(var.GpDisplayDriver_D3D11.TargetPath)" KeyPath="yes" Checksum="yes"/>
      </Component>
      <Component Id="GpInputDriver_XInput.dll" Guid="*">
        <File Id="GpInputDriver_XInput.dll" Source="$(var.GpInputDriver_XInput.TargetPath)" KeyPath="yes" Checksum="yes"/>
      </Component>
      <Component Id="GpFontHandler_FreeType2.dll" Guid="*">
        <File Id="GpFontHandler_FreeType2.dll" Source="$(var.GpFontHandler_FreeType2.TargetPath)" KeyPath="yes" Checksum="yes"/>
      </Component>
    </DirectoryRef>

    <DirectoryRef Id="AEROFOILPACKAGEDDIR">
      <Component Id="ApplicationResources" Guid="*">
        <File Id="ApplicationResources.gpa" Source="$(var.PackagedDataDir)\ApplicationResources.gpa" KeyPath="yes" Checksum="yes"/>
      </Component>
    </DirectoryRef>

    <DirectoryRef Id="AEROFOILTOOLSDIR">
      <Component Id="bin2gp.exe" Guid="*">
        <File Id="bin2gp.exe" Source="$(var.bin2gp.TargetPath)" KeyPath="yes" Checksum="yes"/>
      </Component>
      <Component Id="flattenmov.exe" Guid="*">
        <File Id="flattenmov.exe" Source="$(var.flattenmov.TargetPath)" KeyPath="yes" Checksum="yes"/>
      </Component>
      <Component Id="FTagData.exe" Guid="*">
        <File Id="FTagData.exe" Source="$(var.FTagData.TargetPath)" KeyPath="yes" Checksum="yes"/>
      </Component>
      <Component Id="gpr2gpa.exe" Guid="*">
        <File Id="gpr2gpa.exe" Source="$(var.gpr2gpa.TargetPath)" KeyPath="yes" Checksum="yes"/>
      </Component>
      <Component Id="hqx2bin.exe" Guid="*">
        <File Id="hqx2bin.exe" Source="$(var.hqx2bin.TargetPath)" KeyPath="yes" Checksum="yes"/>
      </Component>
      <Component Id="hqx2gp.exe" Guid="*">
        <File Id="hqx2gp.exe" Source="$(var.hqx2gp.TargetPath)" KeyPath="yes" Checksum="yes"/>
      </Component>
      <Component Id="MakeTimestamp.exe" Guid="*">
        <File Id="MakeTimestamp.exe" Source="$(var.MakeTimestamp.TargetPath)" KeyPath="yes" Checksum="yes"/>
      </Component>
      <Component Id="unpacktool.exe" Guid="*">
        <File Id="unpacktool.exe" Source="$(var.unpacktool.TargetPath)" KeyPath="yes" Checksum="yes"/>
      </Component>
    </DirectoryRef>

    <DirectoryRef Id="AEROFOILDOCUMENTATIONDIR">
      <Component Id="readme.txt" Guid="*">
        <File Id="readme.txt" Source="$(var.DocumentationDataDir)\readme.txt" KeyPath="yes" Checksum="yes"/>
      </Component>
    </DirectoryRef>

    <DirectoryRef Id="ApplicationProgramsFolder">
      <Component Id="StartMenuShortcuts" Guid="*">
        <Shortcut Id="ApplicationStartMenuShortcut"
                  Name="Aerofoil"
                  Description="Aerofoil"
                  Target="[#Aerofoil.exe]"
                  WorkingDirectory="AEROFOILPRODUCTDIR"/>
        <Shortcut Id="ReadMeStartMenuShortcut"
                  Name="Aerofoil Documentation"
                  Description="Aerofoil Documentation"
                  Target="[#readme.txt]"
                  WorkingDirectory="AEROFOILDOCUMENTATIONDIR"/>
        <RemoveFolder Id="CleanUpShortCutStartMenu" Directory="ApplicationProgramsFolder" On="uninstall"/>
        <RegistryValue Root="HKCU" Key="Software\AerofoilProject\Aerofoil" Name="installed_startmenu" Type="integer" Value="1" KeyPath="yes"/>
      </Component>
    </DirectoryRef>

    <DirectoryRef Id="DesktopFolder">
      <Component Id="DesktopShortcuts" Guid="*">
        <Shortcut Id="ApplicationDesktopShortcut"
          Name="Aerofoil"
          Description="Aerofoil"
          Target="[#Aerofoil.exe]"
          WorkingDirectory="AEROFOILPRODUCTDIR"/>
        <RemoveFolder Id="CleanUpShortCutDesktop" On="uninstall"/>
        <RegistryValue Root="HKCU" Key="Software\AerofoilProject\Aerofoil" Name="installed_desktop" Type="integer" Value="1" KeyPath="yes"/>
      </Component>
    </DirectoryRef>

    <Feature Id="AerofoilApplicationFeature" Title="Glider PRO Game Data" Level="1" Display="expand" ConfigurableDirectory="AEROFOILPRODUCTDIR" Description="!(loc.AerofoilApplicationFeatureDescription)">
      <ComponentRef Id="Aerofoil.exe" />
      <ComponentRef Id="FreeType.dll" />
      <ComponentRef Id="GpApp.dll" />
      <ComponentRef Id="GpAudioDriver_XAudio2.dll" />
      <ComponentRef Id="xaudio2_9redist.dll" />
      <ComponentRef Id="GpDisplayDriver_D3D11.dll" />
      <ComponentRef Id="GpInputDriver_XInput.dll" />
      <ComponentRef Id="GpFontHandler_FreeType2.dll" />
      
      <ComponentRef Id="ApplicationResources" />

      <ComponentRef Id="readme.txt" />

      <ComponentGroupRef Id="WinCursorsComponentGroup"/>
      <ComponentGroupRef Id="DefaultHousesComponentGroup"/>
      
      <ComponentGroupRef Id="ResourcesComponentGroup"/>
      <ComponentGroupRef Id="LooseDocumentationComponentGroup"/>

      <ComponentRef Id="StartMenuShortcuts" />
      <ComponentRef Id="DesktopShortcuts" />

      <Feature Id="HousePack1Feature" Title="Additional Houses" Level="1" Description="!(loc.HousePack1FeatureDescription)">
        <ComponentGroupRef Id="HousePack1ComponentGroup" />
      </Feature>

      <Feature Id="ImportToolsFeature" Title="Data Import Utilities" Level="4" Description="!(loc.ImportToolsFeatureDescription)">
        <ComponentRef Id="bin2gp.exe" />
        <ComponentRef Id="flattenmov.exe" />
        <ComponentRef Id="FTagData.exe" />
        <ComponentRef Id="gpr2gpa.exe" />
        <ComponentRef Id="hqx2bin.exe" />
        <ComponentRef Id="hqx2gp.exe" />
        <ComponentRef Id="MakeTimestamp.exe" />
        <ComponentRef Id="unpacktool.exe" />
      </Feature>
    </Feature>

    <WixVariable Id="WixUILicenseRtf" Value="$(var.ProjectDir)\LICENSE.rtf"/>
    <WixVariable Id="WixUIDialogBmp" Value="$(var.ProjectDir)\DialogBanner.png"/>
    <WixVariable Id="WixUIBannerBmp" Value="$(var.ProjectDir)\TopBanner.bmp"/>

    <DirectoryRef Id="TARGETDIR">
      <Merge Id="VCRedist" SourceFile="C:\Program Files (x86)\Common Files\Merge Modules\Microsoft_VC140_CRT_x64.msm" DiskId="1" Language="0" />
    </DirectoryRef>
    
    <Feature Id="VCRedist" Title="Microsoft Visual C++ 2017 Runtime" AllowAdvertise="no" Display="hidden" Level="1">
      <MergeRef Id="VCRedist" />
    </Feature>

    <UI>
      <UIRef Id="WixUI_Mondo" />
      <Publish Dialog="ExitDialog" Control="Finish" Event="DoAction" Value="LaunchApplication">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish>
    </UI>

    <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Read the Aerofoil documentation" />
    <Property Id="WixShellExecTarget" Value="[#readme.txt]" />
    <CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />
  </Product>
</Wix>
