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

<?include "cpack_variables.wxi"?>

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
    RequiredVersion="3.6.3303.0">

    <Product Id="$(var.CPACK_WIX_PRODUCT_GUID)"
        Name="$(var.CPACK_PACKAGE_NAME)"
        Language="1033"
        Version="$(var.CPACK_PACKAGE_VERSION)"
        Manufacturer="$(var.CPACK_PACKAGE_VENDOR)"
        UpgradeCode="$(var.CPACK_WIX_UPGRADE_GUID)">

        <Package InstallerVersion="301" Compressed="yes"/>

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

        <MajorUpgrade
            Schedule="afterInstallInitialize"
            AllowSameVersionUpgrades="yes"
            DowngradeErrorMessage="A later version of [ProductName] is already installed. Setup will now exit."/>

        <WixVariable Id="WixUILicenseRtf" Value="$(var.CPACK_WIX_LICENSE_RTF)"/>
        <Property Id="WIXUI_INSTALLDIR" Value="INSTALL_ROOT"/>

        <?ifdef CPACK_WIX_PRODUCT_ICON?>
        <Property Id="ARPPRODUCTICON">ProductIcon.ico</Property>
        <Icon Id="ProductIcon.ico" SourceFile="$(var.CPACK_WIX_PRODUCT_ICON)"/>
        <?endif?>

        <?ifdef CPACK_WIX_UI_BANNER?>
        <WixVariable Id="WixUIBannerBmp" Value="$(var.CPACK_WIX_UI_BANNER)"/>
        <?endif?>

        <?ifdef CPACK_WIX_UI_DIALOG?>
        <WixVariable Id="WixUIDialogBmp" Value="$(var.CPACK_WIX_UI_DIALOG)"/>
        <?endif?>
        
        
       <DirectoryRef Id="TARGETDIR">
            <Directory Id="ProgramMenuFolder">
                <Directory Id="ApplicationProgramsFolder" Name="IRCAD"/>
            </Directory>
        </DirectoryRef>
        
        <DirectoryRef Id="ApplicationProgramsFolder">
            <Component Id="ApplicationShortcut" Guid="$(var.CPACK_WIX_PRODUCT_GUID)">
                <Shortcut
                    Id="$(var.CPACK_PACKAGE_NAME)"
                    Name="$(var.CPACK_PACKAGE_NAME)"
                    Icon='ProductIcon.ico'
                    IconIndex="0"
                    Target="[INSTALL_ROOT]@LAUNCHER_PATH@"
                    Arguments=".\@PROFILE_PATH@" 
                    WorkingDirectory="INSTALL_ROOT"
                />
                <Shortcut
                    Id="UninstallProduct"
                    Name="Uninstall $(var.CPACK_PACKAGE_NAME)"
                    Target="[System64Folder]msiexec.exe"
                    Arguments="/x [ProductCode]"
                    Description="Uninstalls $(var.CPACK_PACKAGE_NAME)"
                    />
            
            
                <RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
                <RegistryValue Root="HKCU" Key="Software\IRCAD\$(var.CPACK_PACKAGE_NAME)" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
            </Component>
        </DirectoryRef>

        <Feature Id="MainApplication" Title="Main Application" Level="1">
            <ComponentRef Id="ApplicationShortcut" />   
        </Feature>

        <FeatureRef Id="ProductFeature"/>

        <UIRef Id="WixUI_InstallDir" />
    </Product>
</Wix>
