<?xml version="1.0" encoding="UTF-8"?>
<!-- Platform specific variables -->
<?if $(var.Platform) = x64 ?>
  <?define Win64 = "yes" ?>
  <?if $(var.Configuration) = Debug ?>
	<?define ProductName_Configuration = ", Debug" ?>
  <?else ?>
	<?define ProductName_Configuration = "" ?>
  <?endif ?>
  <?define ProductName = "FreeSWITCH (64 bit$(var.ProductName_Configuration))" ?>
  <?define PlatformProgramFilesFolder = "ProgramFiles64Folder" ?>
<?else ?>
  <?define Win64 = "no" ?>
  <?if $(var.Configuration) = Debug ?>
	<?define ProductName_Configuration = " (Debug)" ?>
  <?else ?>
	<?define ProductName_Configuration = "" ?>
  <?endif ?>
  <?define ProductName = "FreeSWITCH$(var.ProductName_Configuration)" ?>
  <?define PlatformProgramFilesFolder = "ProgramFilesFolder" ?>
<?endif ?>

<?if $(var.Configuration) = Debug ?>
  <?define CRT_Configuration = "Debug" ?>
<?else ?>
  <?define CRT_Configuration = "" ?>
<?endif ?>

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
	<Product Id="b004a325-1272-47e5-a415-a74e9fc99865" Name="$(var.ProductName)" Language="1033" Version="$(var.ProductVersion)" Manufacturer="FreeSWITCH" UpgradeCode="3af7020b-1348-45e8-a0cf-80909d4eb421">
		<Package InstallerVersion="405" Compressed="yes" />
		<WixVariable Id="WixUILicenseRtf" Value="..\..\docs\COPYING.rtf" />

		<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />

		<CustomAction Id='CheckForUCRT' Error="Installation failed because the Universal C Runtime is not installed. Please run Windows Update and install all required Windows updates. You can download the UCRT separately from here: https://support.microsoft.com/en-us/kb/2999226" />

		<Property Id="UCRTINSTALLED" Secure="yes">
		  <DirectorySearch Id="searchSystem2" Path="[SystemFolder]" Depth="0">
			<FileSearch Id="UCRT_FileSearch"
					Name="ucrtbase.dll"
					MinVersion="6.2.10585.0"/>
		  </DirectorySearch>
		</Property>

		<Binary Id="CustomActionDownloadOpenH264" SourceFile="CustomActions\Setup.CA.DownloadOpenH264\bin\Setup.CA.DownloadOpenH264.CA.dll" />
		<CustomAction Id="SetForCustomActionDownloadOpenH264" Return="check" Property="CustomActionDownloadOpenH264" Value="location=[INSTALLLOCATION]"/>
		<CustomAction Id="CustomActionDownloadOpenH264" BinaryKey="CustomActionDownloadOpenH264" DllEntry="DownloadOpenH264" Execute="deferred" Impersonate="no" Return="check" HideTarget="yes"/>

		<CustomAction Id="SetForCustomActionRemoveOpenH264Binary" Return="check" Property="CustomActionRemoveOpenH264Binary" Value="location=[INSTALLLOCATION]"/>
		<CustomAction Id="CustomActionRemoveOpenH264Binary" BinaryKey="CustomActionDownloadOpenH264" DllEntry="RemoveOpenH264Binary" Execute="deferred" Impersonate="no" Return="check" HideTarget="yes"/>

		<UI>
		  <ProgressText Action="CustomActionDownloadOpenH264">Downloading OpenH264 Video Codec provided by Cisco Systems, Inc.</ProgressText>
		</UI>

		<InstallExecuteSequence>
		  <Custom Action='CheckForUCRT' Before='LaunchConditions'>
			<![CDATA[Not REMOVE="ALL" AND UCRTINSTALLED = ""]]>
		  </Custom>
		  <Custom Action="SetForCustomActionDownloadOpenH264" Before="CustomActionDownloadOpenH264" />
		  <Custom Action="CustomActionDownloadOpenH264" Before="InstallFinalize"> <![CDATA[&DownloadOpenH264TaskFeature=3]]> AND ((NOT (REMOVE="ALL")) OR (REINSTALL="ALL"))
		  </Custom>

		  <Custom Action="SetForCustomActionRemoveOpenH264Binary" Before="CustomActionRemoveOpenH264Binary" />
		  <Custom Action="CustomActionRemoveOpenH264Binary" After="InstallInitialize"> (<![CDATA[&DownloadOpenH264TaskFeature=2]]> AND (Installed OR MaintenanceMode="Modify")) OR ((NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL"))
		  </Custom>

		</InstallExecuteSequence>

		<Directory Id="TARGETDIR" Name="SourceDir">
			<Directory Id="$(var.PlatformProgramFilesFolder)">
				<Directory Id="INSTALLLOCATION" Name="FreeSWITCH">
					<Component Id="openh264licence" Guid="CF3DBA7A-5DDB-45DC-823B-54C52D4A6188">
						<File Id="openh264licence" KeyPath="yes" Source="..\..\docs\OPENH264_BINARY_LICENSE.txt" />
					</Component>
					 <Directory Id="MODLOCATION" Name="mod">
					 </Directory>
					 <Directory Id="CONFLOCATION" Name="conf">
					 </Directory>
					 <Directory Id="SOUNDLOCATION" Name="sounds">
					 </Directory>
					<!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
					<!-- <Component Id="ProductComponent" Guid="6f1498a7-d029-430b-b9d9-fe12e17bdbab"> -->
						<!-- TODO: Insert files, registry keys, and other resources here. -->
					<!-- </Component> -->
					<?if $(var.Platform) != x64 ?>
						<Merge Id="CrtFiles_x86"
						SourceFile="$(var.MergeModules)\Microsoft_VC$(var.VCVer)_$(var.CRT_Configuration)CRT_x86.msm"
						DiskId="1"
						Language="1033"/>
					<?endif ?>
					<?if $(var.Platform) = x64 ?>
						<Merge Id="CrtFiles_x64"
						SourceFile="$(var.MergeModules)\Microsoft_VC$(var.VCVer)_$(var.CRT_Configuration)CRT_x64.msm"
						DiskId="1"
						Language="1033"/>
					<?endif ?>
				</Directory>
			</Directory>
			<Directory Id="ProgramMenuFolder">
				<Directory Id="ApplicationProgramsFolder" Name="FreeSWITCH"/>
			</Directory>
		</Directory>

		<DirectoryRef Id="ApplicationProgramsFolder">
			<Component Id="ApplicationShortcut" Guid="B554D1D1-C8C6-4d46-A3E7-4BA836EF929B">
				<Shortcut Id="ApplicationStartMenuShortcut"
							 Name="FreeSWITCH"
							 Description="FreeSWITCH Telephony SoftSwitch"
							 Target="[INSTALLLOCATION]FreeSwitchConsole.exe"
							 WorkingDirectory="INSTALLLOCATION"/>
				<RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
				<RegistryValue Root="HKCU" Key="Software\FreeSWITCH\FreeSWITCH" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
			</Component>
			<Component Id="FSCliShortcut" Guid="D209546C-C728-4d8f-BDB2-29AED8824282">
				<Shortcut Id="FSCliStartMenuShortcut"
							 Name="FS_Cli"
							 Description="FreeSWITCH Command Line Interface"
							 Target="[INSTALLLOCATION]fs_cli.exe"
							 WorkingDirectory="INSTALLLOCATION"/>
				<RegistryValue Root="HKCU" Key="Software\FreeSWITCH\FS_CLI" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
			</Component>
		</DirectoryRef>	
		<Feature Id="ProductFeature" Title="FreeSWITCH Core" Level="1"
				Description = "FreeSWITCH core library, all available modules and their dependencies."
		>
			<!-- TODO: Remove the comments around this ComponentRef element and the Component above in order to add resources to this installer. -->
			<!-- <ComponentRef Id="ProductComponent" /> -->
			<!-- The following Ref pulls in FreeSWITCHconsole.wxs items -->
			<ComponentRef Id="cmpBEF12B96A80D45AC32F3B692E94A57C9"/>
      <!-- This following Ref Pulls in fs_cli.exe-->
      <ComponentRef Id="cmp5A06A4A7E1884331BC6C949456B5F293"/>
      <!-- Note: The following ComponentGroupRef is required to pull in generated authoring from project references. -->
			<ComponentGroupRef Id="FreeSWITCHBaseFiles" />
			<ComponentGroupRef Id="FreeSWITCHhtdocsFiles" />
			<ComponentGroupRef Id="FreeSWITCHimagesFiles" />
			<ComponentGroupRef Id="FreeSWITCHfontsFiles" />
			<ComponentGroupRef Id="FreeSWITCHgrammarFiles" />
			<?if $(var.Platform) != x64 ?>
			  <MergeRef Id="CrtFiles_x86"/>
			<?endif ?>
			<?if $(var.Platform) = x64 ?>
			  <MergeRef Id="CrtFiles_x64"/>
			<?endif ?>
		</Feature>
		<Feature Id="DownloadOpenH264TaskFeature" Title="Download OpenH264 Binary" Level="1" Absent="allow"
				Description="OpenH264 Video Codec provided by Cisco Systems, Inc. (This is required for mod_av, but you can always disable that module later and not download OpenH264 codec now)"
		>
			<ComponentRef Id="openh264licence" />
		</Feature>
		<Feature Id="ProductFeatureFreeSWITCH" Title="FreeSWITCH" Level="1"
				Description = "FreeSWITCH Console Application Shortcut"
		>
			<ComponentRef Id="ApplicationShortcut" />
		</Feature>
		<Feature Id="ProductFeatureFSCli" Title="FreeSWITCH Command Line Interface" Level="1"
				Description = "FreeSWITCH CLI Application Shortcut"
		>
			<ComponentRef Id="FSCliShortcut" />
		</Feature>
		<Feature Id="ProductFeatureConf" Title="FreeSWITCH Configuration Sample" Level="1"
				Description = "Vanilla is the 'Default configuration' for FreeSWITCH, *NOT* designed for a production environment without some important modifications!"
		>
			<ComponentGroupRef Id="FreeSWITCHConfFiles" />
		</Feature>
		<Feature Id="ProductFeatureSounds" Title="FreeSWITCH Sounds 8Khz" Level="1"
				Description = "We provide 8Khz sounds with the installer. Follow our Confluence to get 16, 32, 48Khz sounds."
		>
			<ComponentGroupRef Id="FreeSWITCHSoundFiles8" />
		</Feature>
    <UIRef Id="WixUI_Mondo" />
  </Product>
</Wix>