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

  <!-- Mumble Version Specific -->
  <Fragment>
      <?ifdef VersionSubDir ?>
        <DirectoryRef Id="VersionFolder">
      <?else ?>
        <DirectoryRef Id="INSTALLDIR">
      <?endif ?>

      <Component Id="mumble_app.dll">
        <File Source="$(var.SourceDir)\release\mumble_app.dll" KeyPath="yes" />
      </Component>
      <Component Id="mumble_ol.dll">
        <File Source="$(var.SourceDir)\release\mumble_ol.dll" KeyPath="yes" />
      </Component>
      <Component Id="mumble_ol_helper.exe">
         <File Source="$(var.SourceDir)\release\mumble_ol_helper.exe" KeyPath="yes" />
      </Component>
      <Component Id="mumble_ol_x64.dll">
        <File Source="$(var.SourceDir)\release\mumble_ol_x64.dll" KeyPath="yes" />
      </Component>
      <Component Id="mumble_ol_helper_x64.exe">
         <File Source="$(var.SourceDir)\release\mumble_ol_helper_x64.exe" KeyPath="yes" />
      </Component>

      <Component Id="celt0.0.7.0.dll">
        <File Source="$(var.SourceDir)\release\celt0.0.7.0.dll" KeyPath="yes" />
      </Component>
      <Component Id="celt0.0.11.0.dll">
        <File Source="$(var.SourceDir)\release\celt0.0.11.0.dll" KeyPath="yes" />
      </Component>
      <Component Id="speex.dll">
        <File Source="$(var.SourceDir)\release\speex.dll" KeyPath="yes" />
      </Component>
      <Component Id="opus.dll">
        <File Source="$(var.SourceDir)\release\opus.dll" KeyPath="yes" />
      </Component>

      <?ifdef SSE ?>
        <Component Id="celt0.0.7.0.sse.dll">
          <File Source="$(var.SourceDir)\release\celt0.0.7.0.sse.dll" KeyPath="yes" />
        </Component>
        <Component Id="celt0.0.11.0.sse.dll">
          <File Source="$(var.SourceDir)\release\celt0.0.11.0.sse.dll" KeyPath="yes" />
        </Component>
      <?endif ?>

      <?ifdef SSE2 ?>
        <Component Id="celt0.0.7.0.sse2.dll">
          <File Source="$(var.SourceDir)\release\celt0.0.7.0.sse2.dll" KeyPath="yes" />
        </Component>
        <Component Id="celt0.0.11.0.sse2.dll">
          <File Source="$(var.SourceDir)\release\celt0.0.11.0.sse2.dll" KeyPath="yes" />
        </Component>
        <Component Id="opus.sse2.dll">
          <File Source="$(var.SourceDir)\release\opus.sse2.dll" KeyPath="yes" />
        </Component>
      <?endif ?>

      <?ifdef G15 ?>
        <Component Id="mumble_g15_helper.exe">
          <File Source="$(var.SourceDir)\release\mumble-g15-helper.exe" KeyPath="yes" />
        </Component>
      <?endif ?>

      <?ifdef RNN ?>
        <Component Id="rnnoise.dll">
          <File Source="$(var.SourceDir)\release\rnnoise.dll" KeyPath="yes" />
        </Component>
      <?endif ?>    
          
      <?ifdef RedistDirVC14 ?>
      <Component Id="msvcp140.dll">
        <File Source="$(var.RedistDirVC14)\msvcp140.dll" KeyPath="yes" />
      </Component>
      <Component Id="vcruntime140.dll">
        <File Source="$(var.RedistDirVC14)\vcruntime140.dll" KeyPath="yes" />
      </Component>
      <?endif ?>

      <?ifdef RedistDirUCRT ?>
       <?include "MumbleUCRTComponents.wxi" ?>
      <?endif ?>

    <?ifdef VersionSubDir ?>
      </DirectoryRef>
    <?else ?>
      </DirectoryRef>
    <?endif ?>
  </Fragment>

  <!-- Mumble -->
  <Fragment>
    <DirectoryRef Id="INSTALLDIR">
      <Component Id="MumbleDesktopShortcutComponent" Guid="$(var.MumbleDesktopShortcutGuid)" KeyPath="yes">
        <Shortcut Id="MumbleDesktopShortcut"
                  Directory="DesktopFolder"
                  Name="Mumble"
                  WorkingDirectory="INSTALLDIR"
                  Target="[INSTALLDIR]mumble.exe">
          <ShortcutProperty Key="System.AppUserModel.ID" Value="net.sourceforge.mumble.Mumble" />
        </Shortcut>
      </Component>
      
      <Component Id="mumble.exe" Guid="$(var.MumbleExeGuid)">
        <File Id="mumble.exe" Source="$(var.SourceDir)\release\mumble.exe" KeyPath="yes">
          <Shortcut Id="MumbleShortcut" Directory="ApplicationProgramsFolder" Name="Mumble" WorkingDirectory="INSTALLDIR">
            <ShortcutProperty Key="System.AppUserModel.ID" Value="net.sourceforge.mumble.Mumble" />
          </Shortcut>
        </File>

        <RegistryValue Root="HKCR" Key="mumble" Value="URL:Mumble" Type="string" />
        <RegistryValue Root="HKCR" Key="mumble" Name="URL Protocol" Value="" Type="string" />
        <RegistryValue Root="HKCR" Key="mumble\DefaultIcon" Value="[#mumble.exe]" Type="string" />
        <RegistryValue Root="HKCR" Key="mumble\shell\open\command" Value="[#mumble.exe] &quot;%1&quot;" Type="string" />
      </Component>

      <Component Id="MurmurDesktopShortcutComponent" Guid="$(var.MurmurDesktopShortcutGuid)" KeyPath="yes">
        <Shortcut Id="MurmurDesktopShortcut"
                  Directory="DesktopFolder"
                  Name="Murmur"
                  WorkingDirectory="INSTALLDIR"
                  Target="[INSTALLDIR]murmur.exe"
                  Icon="murmur.ico"
                  IconIndex="0" />
      </Component>
        
      <Component Id="murmur.exe">
        <File Id="murmur.exe" Source="$(var.SourceDir)\release\murmur.exe" KeyPath="yes">
          <Shortcut Id="MurmurShortcut" Directory="ApplicationProgramsFolder" Name="Murmur" WorkingDirectory="INSTALLDIR" Icon="murmur.ico" IconIndex="0" />
        </File>
      </Component>
      <Component Id="murmur.ini" NeverOverwrite="yes">
        <File Source="$(var.SourceDir)\scripts\murmur.ini.win32" Name="murmur.ini" KeyPath="yes" />
      </Component>
      <Component Id="Murmur.ice">
        <File Source="$(var.SourceDir)\src\murmur\Murmur.ice" KeyPath="yes" />
      </Component>

      <?ifdef VersionSubDir ?>
        <?ifdef RedistDirVC14 ?>
        <Component Id="Murmur_msvcp140.dll">
          <File Id="Murmur_msvcp120.dll" Source="$(var.RedistDirVC14)\msvcp140.dll" KeyPath="yes" />
        </Component>
        <Component Id="Murmur_vcruntime140.dll">
          <File Id="Murmur_vcruntime140.dll" Source="$(var.RedistDirVC14)\vcruntime140.dll" KeyPath="yes" />
        </Component>
        <?endif ?>
        <?ifdef RedistDirUCRT ?>
          <?include "MurmurUCRTComponents.wxi" ?>
        <?endif ?>
      <?endif ?>

      <Component Id="licence.txt" Guid="$(var.LicenseTextGuid)">
        <File Source="$(var.SourceDir)\installer\gpl.txt" Name="licence.txt" KeyPath="yes" />
      </Component>
      <Component Id="Readme.txt" Guid="$(var.ReadMeTextGuid)">
        <File Source="$(var.SourceDir)\README" Name="Readme.txt" KeyPath="yes" />
      </Component>
      <Component Id="Changes.txt">
        <File Source="$(var.SourceDir)\CHANGES" Name="Changes.txt" KeyPath="yes" />
      </Component>
      <Component Id="speex.txt">
        <File Source="$(var.SourceDir)\installer\speex.txt" KeyPath="yes" />
      </Component>
      <Component Id="qt.txt">
        <File Source="$(var.SourceDir)\installer\qt.txt" KeyPath="yes" />
      </Component>

    </DirectoryRef>
  </Fragment>

  <!-- Directory tree -->
    <Fragment>
      <DirectoryRef Id="INSTALLDIR">
        <?ifdef VersionSubDir ?>
          <Directory Id="VersionContainerFolder" Name="Versions">
            <Directory Id="VersionFolder" Name="$(var.VersionSubDir)">
              <Directory Id="PluginFolder" Name="plugins" />
            </Directory>
          </Directory>
        <?else ?>
          <Directory Id="PluginFolder" Name="plugins" />
        <?endif ?>
      </DirectoryRef>
    </Fragment>
</Wix>
