<?include "cpack_variables.wxi"?>

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:fw="http://wixtoolset.org/schemas/v4/wxs/firewall">
    <Fragment>
        <Property Id="SYSTEMSETTINGS" Secure="yes" />
        <Property Id="SYSTEMSETTINGS_FOUND" Secure="yes">
            <RegistrySearch Id="SystemSettingsRegistry" Root="HKLM" Key="!(wix.CompanyRootKey)" Name="FirewallRules" Type="raw" />
        </Property>
        <Property Id="SYSTEMSETTINGS_OLD_FOUND" Secure="yes">
            <RegistrySearch Id="SystemSettingsOldRegistry" Root="HKLM" Key="SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules" Name="AusweisApp-Firewall-Rule" Type="raw" />
        </Property>
        <Property Id="SYSTEMSETTINGS_OLD2_FOUND" Secure="yes">
            <RegistrySearch Id="SystemSettingsOld2Registry" Root="HKLM" Key="SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules" Name="AusweisApp2-Firewall-Rule" Type="raw" />
        </Property>
        <SetProperty Before="CostFinalize" Id="SYSTEMSETTINGS" Value="true" Sequence="first" Condition="(NOT SYSTEMSETTINGS) AND (((WIX_UPGRADE_DETECTED OR REINSTALL) AND (SYSTEMSETTINGS_FOUND OR SYSTEMSETTINGS_OLD_FOUND OR SYSTEMSETTINGS_OLD2_FOUND)) OR (NOT (WIX_UPGRADE_DETECTED OR REINSTALL)))" />
        <SetProperty Action="SetSystemSettingsGui1" Before="CostFinalize" Id="SystemSettingsGui" Value="true" Sequence="ui" Condition="SYSTEMSETTINGS = &quot;true&quot;" />
        <SetProperty Action="SetSystemSettingsGui2" Before="CostFinalize" Id="SystemSettingsGui" Value="{}" Sequence="ui" Condition="NOT (SYSTEMSETTINGS = &quot;true&quot;)" />



        <Property Id="DESKTOPSHORTCUT" Secure="yes" />
        <Property Id="DESKTOPSHORTCUT_FOUND" Secure="yes">
            <RegistrySearch Id="DesktopShortcutRegistry" Root="HKLM" Key="!(wix.CompanyRootKey)" Name="SC_Desktop" Type="raw" />
        </Property>
        <Property Id="DESKTOPSHORTCUT_MIGRATION" Secure="yes">
            <RegistrySearch Id="DesktopShortcutRegistryMigration" Root="HKCU" Key="!(wix.CompanyRootKey)" Name="SC_Desktop" Type="raw" />
        </Property>
        <SetProperty Before="CostFinalize" Id="DESKTOPSHORTCUT" Value="true" Sequence="first" Condition="(NOT DESKTOPSHORTCUT) AND (((WIX_UPGRADE_DETECTED OR REINSTALL) AND (DESKTOPSHORTCUT_FOUND OR DESKTOPSHORTCUT_MIGRATION))OR (NOT (WIX_UPGRADE_DETECTED OR REINSTALL)))" />
        <SetProperty Action="SetDesktopShortcutGui1" Before="CostFinalize" Id="DesktopShortcutGui" Value="true" Sequence="ui" Condition="DESKTOPSHORTCUT = &quot;true&quot;" />
        <SetProperty Action="SetDesktopShortcutGui2" Before="CostFinalize" Id="DesktopShortcutGui" Value="{}" Sequence="ui" Condition="NOT (DESKTOPSHORTCUT = &quot;true&quot;)" />



        <Property Id="STARTMENUSHORTCUT" Secure="yes" />
        <Property Id="STARTMENUSHORTCUT_FOUND" Secure="yes">
            <RegistrySearch Id="StartmenueShortcutRegistry" Root="HKLM" Key="!(wix.CompanyRootKey)" Name="SC_Startmenu" Type="raw" />
        </Property>
        <Property Id="STARTMENUSHORTCUT_MIGRATION" Secure="yes">
            <RegistrySearch Id="StartmenueShortcutRegistryMigration" Root="HKCU" Key="!(wix.CompanyRootKey)" Name="SC_Startmenu" Type="raw" />
        </Property>
        <SetProperty Before="CostFinalize" Id="STARTMENUSHORTCUT" Value="true" Sequence="first" Condition="(NOT STARTMENUSHORTCUT) AND (((WIX_UPGRADE_DETECTED OR REINSTALL) AND (STARTMENUSHORTCUT_FOUND OR STARTMENUSHORTCUT_MIGRATION))OR (NOT (WIX_UPGRADE_DETECTED OR REINSTALL)))" />



        <Property Id="LAUNCH" Secure="yes" />
        <SetProperty Action="SetLaunchGui1" Before="CostFinalize" Id="LaunchGui" Value="true" Sequence="ui" Condition="(NOT LAUNCH) OR LAUNCH = &quot;true&quot;" />
        <SetProperty Action="SetLaunchGui2" Before="CostFinalize" Id="LaunchGui" Value="{}" Sequence="ui" Condition="(LAUNCH) AND NOT (LAUNCH = &quot;true&quot;)" />
        <Property Id="WixShellExecTarget" Value="[INSTALL_ROOT][ProductName].exe" />
        <CustomAction Id="LaunchApplication" DllEntry="WixShellExec" Impersonate="yes" BinaryRef="Wix4UtilCA_X86" />
        <InstallExecuteSequence>
            <Custom Action="LaunchApplication" After="InstallFinalize" Condition="LAUNCH = &quot;true&quot;" />
        </InstallExecuteSequence>



        <Feature Id="InstallSettings">
            <ComponentRef Id="WindowsFirewallRule" />
            <ComponentRef Id="DesktopShortcut" />
            <ComponentRef Id="StartmenuShortcut" />
        </Feature>



        <Component Id="WindowsFirewallRule" Guid="{391CF345-5AA2-45CD-D001-C24861C9AB8D}" Directory="TARGETDIR" Condition="SYSTEMSETTINGS = &quot;true&quot;">
            <RegistryKey Root="HKLM" Key="!(wix.CompanyRootKey)">
                <RegistryValue Name="FirewallRules" Type="integer" Value="1" />
            </RegistryKey>

            <!-- Add/remove outgoing data port to/from Windows Firewall -->
            <fw:FirewallException Id="AddOutboundWindowsFirewall"
                                Program="[INSTALL_ROOT][ProductName].exe"
                                Scope="any"
                                Outbound="yes"
                                Name="AusweisApp-Outbound"
                                Description="AusweisApp firewall rule" />

            <!-- Add/remove SaC listening port to/from Windows Firewall -->
            <fw:FirewallException Id="AddListeningPortWindowsFirewallSaC" Program="[INSTALL_ROOT][ProductName].exe" Port="24727" Protocol="udp" Profile="all" Scope="localSubnet" Name="AusweisApp-SaC" Description="Allow inbound udp connections for Smartphone as card reader." />
        </Component>

        <StandardDirectory Id="DesktopFolder">
            <Component Id="DesktopShortcut" Guid="{391CF345-5AA2-45CD-D002-C24861C9AB8D}" Condition="DESKTOPSHORTCUT = &quot;true&quot;">
                <RegistryKey Root="HKLM" Key="!(wix.CompanyRootKey)">
                    <RegistryValue Name="SC_Desktop" Type="integer" Value="1" />
                </RegistryKey>
                <Shortcut Id="DesktopExec" Name="$(var.CPACK_PACKAGE_NAME)" Description="!(loc.ProgramDescription)" Target="[INSTALL_ROOT][ProductName].exe" WorkingDirectory="INSTALL_ROOT" />
            </Component>
        </StandardDirectory>

        <StandardDirectory Id="ProgramMenuFolder">
            <Component Id="StartmenuShortcut" Condition="STARTMENUSHORTCUT = &quot;true&quot;">
                <RegistryKey Root="HKLM" Key="!(wix.CompanyRootKey)">
                    <RegistryValue Name="SC_Startmenu" Type="integer" Value="1" />
                </RegistryKey>
                <Shortcut Id="StartmenuExec" Name="$(var.CPACK_PACKAGE_NAME)" Description="!(loc.ProgramDescription)" Target="[INSTALL_ROOT][ProductName].exe" WorkingDirectory="INSTALL_ROOT" />
            </Component>
        </StandardDirectory>



        <!-- ##################### -->
        <!-- Remember Install Root -->
        <!-- ##################### -->
        <Property Id="WIXUI_INSTALLDIR" Value="INSTALL_ROOT" />
        <Property Id="INSTALLDIR" Secure="yes" />
        <Property Id="INSTALLDIR_REGISTRY" Secure="yes">
            <RegistrySearch Id="InstallRootRegistry" Root="HKLM" Key="!(wix.CompanyRootKey)" Name="lastInstallRoot" Type="raw" />
        </Property>

        <SetProperty Action="SetINSTALL_ROOT_REGISTRY_OVERWRITE" Before="CostFinalize" Id="INSTALL_ROOT" Value="[INSTALLDIR_REGISTRY]" Sequence="first" Condition="INSTALLDIR_REGISTRY" />
        <SetProperty Action="SetINSTALL_ROOT_CMDLINE_OVERWRITE" After="SetINSTALL_ROOT_REGISTRY_OVERWRITE" Id="INSTALL_ROOT" Value="[INSTALLDIR]" Sequence="first" Condition="INSTALLDIR" />

        <Component Id="RememberInstallRoot" Directory="TARGETDIR">
            <RegistryKey Root="HKLM" Key="!(wix.CompanyRootKey)">
                <RegistryValue Name="lastInstallRoot" Type="string" Value="[INSTALL_ROOT]" KeyPath="yes" />
            </RegistryKey>
        </Component>
    </Fragment>
</Wix>
