<?xml version="1.0" ?>
<Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'>

    <!-- See config.wxi for the symbols that it defines/asserts -->
    <?include config.wxi?>

    <!-- See language_config for localization options. -->
    <?include language_config.wxi?>

    <!--
      We autogenerate a new product code for each build.  According to MSDN we have
      to change the product code whenever we change the name of the MSI file.  Each
      version of OpenAFS has a different MSI name.  Thus, each version needs a
      unique product code.
      -->
    <Product 
        Id="????????-????-????-????-????????????"
        Codepage="$(var.Codepage)"
        Language="$(var.LanguageCode)"
        Manufacturer="$(var.Manufacturer)"
        Name="$(var.ProductName)"
        UpgradeCode="6823EEDD-84FC-4204-ABB3-A80D25779833"
        Version="$(var.NumericVersion)"
        >

		<!--
		Note that we are not specifying an explicit Package Code below.  That way WiX will
		generate a new one for each build.  If an explicit one needs to be specified, use :
		         Id="$(var.PackageCode)"
		-->
        <Package
		 Id="????????-????-????-????-????????????"
         AdminImage="no"
         Comments="$(var.PackageComments)"
         Compressed="yes"
         Description="$(var.ProductName)"
         InstallerVersion="$(var.InstallerVersion)"
         Keywords="Installer,OpenAFS,$(var.Manufacturer)"
         Languages="$(var.Languages)"
         Manufacturer="$(var.Manufacturer)"
         Platforms="$(var.Platform)"
         ShortNames="no"
         SummaryCodepage="1252"
         />
        
        <!-- Launch conditions -->
        <Condition Message="$(loc.StrLaunchCond)">
         <![CDATA[VersionNT >= 500]]>
        </Condition>
        <Condition Message="$(loc.AdminRequired)">Privileged</Condition>
    <?if $(var.Platform) = "x64" ?>
        <Condition Message="$(loc.StrPlatform64)">
         <![CDATA[VersionNT64]]>
        </Condition>
    <?else?>
        <Condition Message="$(loc.StrPlatformNot64)">
         <![CDATA[NOT VersionNT64]]>
        </Condition>
    <?endif?>
        
        <!-- Global Properties -->
        <?include property.wxi?>
        
        <!-- File system and registry settings -->
        <Directory Id="TARGETDIR" Name="SourceDir">
            <?include platform.wxi?>
            <?include registry.wxi?>
            <?include files.wxi?>
        </Directory>
        
        <!-- Features -->
        <?include feature.wxi?>
        
        <!-- User interface -->
        <?include lang\$(var.Language)\ui.wxi?>
        
        <!-- Custom actions -->
    <?ifndef UseDllLoopbackInstaller?>
        <Binary
         Id="BIN_instloop"
         src="$(var.MediaBinDir)instloop.exe"/>
    <?else?>
        <Binary
         Id="BIN_afsLoopback"
         src="$(var.MediaBinDir)afsloopback.dll"/>
    <?endif?>
        <Binary
		 Id="BIN_afsCustom"
		 src="$(var.MediaDllDir)afscustom.dll"/>
    <Binary
       Id="BIN_idndl.exe"
       src="$(var.IDNMRedistDir)\idndl.$(var.Arch).exe" />
    <CustomAction
       Id="InstallIDNMRedistributable"
       BinaryKey="BIN_idndl.exe"
       ExeCommand="/quiet /norestart"
       Execute="deferred"
       Impersonate="no"
       />

	<?ifdef UseDllLoopbackInstaller?>
        <CustomAction
         Id="InstallLoopback"
         BinaryKey="BIN_afsLoopback"
         DllEntry="installLoopbackMSI"
         Execute="deferred" 
         Impersonate="no"
         />
	<?ifdef RemoveLoopback?>
        <CustomAction
         Id="RemoveLoopback"
         BinaryKey="BIN_afsLoopback"
         DllEntry="uninstallLoopbackMSI"
         Execute="deferred" 
         Impersonate="no"
         />
        <CustomAction
         Id="RollbackLoopback"
         BinaryKey="BIN_afsLoopback"
         DllEntry="uninstallLoopbackMSI"
         Execute="deferred" 
         Impersonate="no"
         />
	<?endif?>
	<?else?>
		<CustomAction
		 Id="InstallLoopback"
		 BinaryKey="BIN_instloop"
		 ExeCommand="-i"
		 Impersonate="no"
		 Execute="deferred"
		 />
		<?ifdef RemoveLoopback?>
			<CustomAction
			Id="RollbackLoopback"
			BinaryKey="BIN_instloop"
			ExeCommand="-u"
			Impersonate="no"
			Execute="rollback"
			/>
			<CustomAction
			Id="RemoveLoopback"
			BinaryKey="BIN_instloop"
			ExeCommand="-u"
			Impersonate="no"
			Execute="deferred"
			/>
		<?endif?>
	<?endif?>
        <CustomAction
         Id="InstallNetProvider" 
         BinaryKey="BIN_afsCustom" 
         DllEntry="InstallNetProvider"
         Execute="deferred" 
         Impersonate="no"
        />
		<CustomAction 
		 Id="RemoveNetProvider" 
		 BinaryKey="BIN_afsCustom"
		 DllEntry="UninstallNetProvider"
		 Return="ignore"
		 Execute="deferred" 
                 Impersonate="no"
                />
		<CustomAction 
		 Id="RollbackNetProvider" 
		 BinaryKey="BIN_afsCustom"
		 DllEntry="UninstallNetProvider"
		 Return="ignore"
		 Execute="rollback" />
		<CustomAction
		 Id="ConfigureClient"
		 BinaryKey="BIN_afsCustom"
		 DllEntry="ConfigureClientService"
		 Impersonate="no"
		 Execute="deferred" />
		<CustomAction
		 Id="ConfigureServer"
		 BinaryKey="BIN_afsCustom"
		 DllEntry="ConfigureServerService"
		 Impersonate="no"
		 Execute="deferred" />
		<CustomAction 
		 Id="RemoveNsisInstallation" 
		 BinaryKey="BIN_afsCustom"
		 DllEntry="UninstallNsisInstallation"
		 Execute="immediate" />
		<CustomAction
		 Id="CreateAFSAdminGroup"
		 BinaryKey="BIN_afsCustom"
		 DllEntry="CreateAFSClientAdminGroup"
		 Impersonate="no"
		 Execute="deferred" />
		<CustomAction
		 Id="RemoveAFSAdminGroup"
		 BinaryKey="BIN_afsCustom"
		 DllEntry="RemoveAFSClientAdminGroup"
		 Impersonate="no"
		 Execute="deferred" />
		<CustomAction
		 Id="RollbackAFSAdminGroup"
		 BinaryKey="BIN_afsCustom"
		 DllEntry="RemoveAFSClientAdminGroup"
		 Impersonate="no"
		 Execute="rollback" />
		<CustomAction
		 Id="AbortInstallationA"
		 BinaryKey="BIN_afsCustom"
		 DllEntry="AbortMsiImmediate"
		 Execute="immediate" />
		<CustomAction
		 Id="AbortInstallationB"
		 BinaryKey="BIN_afsCustom"
		 DllEntry="AbortMsiImmediate"
		 Execute="immediate" />
                <CustomAction
                    Id="BackupAFSClientRegistryKeys"
                    BinaryKey="BIN_afsCustom"
                    DllEntry="BackupAFSClientRegistryKeys"
                    Execute="deferred"
                    Impersonate="no" />
                <CustomAction
                    Id="RestoreAFSClientRegistryKeys"
                    BinaryKey="BIN_afsCustom"
                    DllEntry="RestoreAFSClientRegistryKeys"
                    Execute="deferred"
                    Impersonate="no" />
                <CustomAction
                    Id="RollbackRestoreAFSClientRegistryKeys"
                    BinaryKey="BIN_afsCustom"
                    DllEntry="BackupAFSClientRegistryKeys"
                    Execute="rollback"
                    Impersonate="no" />
                <CustomAction
                    Id="DetectSavedConfiguration"
                    BinaryKey="BIN_afsCustom"
                    DllEntry="DetectSavedConfiguration"
                    Execute="firstSequence" />
                <CustomAction
                   Id="SetInstallLocation"
                   Property="ARPINSTALLLOCATION"
                   Value="[AFSDIR]" />

        <!-- Installation Sequences -->
        <AdvertiseExecuteSequence />
        <AdminExecuteSequence />
        <InstallExecuteSequence>
			<RemoveExistingProducts After="InstallValidate">(Not Installed) And (IBMAFS_UPGRADE OR OPENAFS_UPGRADE OR AFSPLUGIN_UPGRADE)</RemoveExistingProducts>
			<Custom Action="RemoveNsisInstallation" Before="AbortInstallationA">NSISUNINSTALL &lt;&gt; "" AND UILevel &gt;= 4</Custom>
			<Custom Action="AbortInstallationA" Before="CostInitialize">NSISUNINSTALL &lt;&gt; "" AND UILevel &lt; 4</Custom>
			<!-- Assert that if the server is going to be installed locally after this session, control center and client are also local -->
			<Custom Action="AbortInstallationB" After="MigrateFeatureStates">
				<![CDATA[((&feaServer=3 OR (!feaServer=3 AND &feaServer<1)) AND (&feaClient=2 OR (&feaClient<>3 AND !feaClient<>3) OR &feaControlCenter=2 OR (&feaControlCenter<>3 AND !feaControlCenter<>3) ))]]>
			</Custom>
		<?ifdef RemoveLoopback?>
			<Custom Action="RemoveLoopback" After="SelfRegModules">&amp;feaLoopback=2 OR &amp;feaLoopback=3</Custom>
            <Custom Action="RollbackLoopback" After="RemoveLoopback">&amp;feaLoopback=3</Custom>
            <Custom Action="InstallLoopback" After="RollbackLoopback">&amp;feaLoopback=3</Custom>
		<?else?>
            <Custom Action="InstallLoopback" After="SelfRegModules">&amp;feaLoopback=3</Custom>
        <?endif?>
            <Custom Action="RollbackNetProvider" After="WriteRegistryValues">&amp;feaClient=3</Custom>
			<Custom Action="InstallNetProvider" After="RollbackNetProvider">&amp;feaClient=3</Custom>
			<Custom Action="RemoveNetProvider" After="InstallNetProvider">&amp;feaClient=2</Custom>
      <Custom Action="InstallIDNMRedistributable" After="WriteRegistryValues">!feaClient=2 And &amp;feaClient=3 And (VersionNT=501 Or VersionNT=502)</Custom>
			<Custom Action="ConfigureClient" After="InstallServices">&amp;feaClient=3</Custom>
			<Custom Action="ConfigureServer" After="ConfigureClient">&amp;feaServer=3</Custom>
                        <Custom Action="RollbackRestoreAFSClientRegistryKeys" After="RemoveNetProvider">!feaClient=2 And &amp;feaClient=3 And RESTORE_CONFIG</Custom>
                        <Custom Action="RestoreAFSClientRegistryKeys" After="RollbackRestoreAFSClientRegistryKeys">!feaClient=2 And &amp;feaClient=3 And RESTORE_CONFIG</Custom>
                        <Custom Action="BackupAFSClientRegistryKeys" Before="DeleteServices">!feaClient=3 And &amp;feaClient=2</Custom>
			<!-- <Custom Action="RemoveAFSAdminGroup" Before="">&amp;feaClient=2</Custom> -->
			<Custom Action="RollbackAFSAdminGroup" Before="CreateAFSAdminGroup">&amp;feaClient=3</Custom>
			<Custom Action="CreateAFSAdminGroup" Before="CreateFolders">&amp;feaClient=3</Custom>
                        <Custom Action="SetInstallLocation" Before="RegisterProduct" />
                        <Custom Action="DetectSavedConfiguration" Before="CostInitialize" />
            <ScheduleReboot After="PublishProduct">&amp;feaClient=3 OR &amp;feaServer=3 OR &amp;feaClient=2 OR &amp;feaServer=2</ScheduleReboot>
        </InstallExecuteSequence>

        <!-- Related producs -->
        <!-- OpenAFS MSI installer -->
        <Upgrade Id="6823EEDD-84FC-4204-ABB3-A80D25779833">
            <UpgradeVersion IgnoreRemoveFailure="no" IncludeMaximum="yes" Maximum="$(var.NumericVersion)" MigrateFeatures="yes" Property="OPENAFS_UPGRADE" />
        </Upgrade>
        
        <!-- MIT's Transarc AFS MSI Installer -->
        <Upgrade Id="5332B94F-DE38-4927-9EAB-51F4A64193A7">
            <UpgradeVersion IgnoreRemoveFailure="no" IncludeMaximum="yes" Maximum="3.6.2" MigrateFeatures="no" Property="IBMAFS_UPGRADE" />
        </Upgrade>
        
  <?if $(env.CPU) = "i386" ?>
        <!-- Secure-Endpoints OpenAFS NetIDMgr plug-in -->
        <Upgrade Id="646D643A-73E3-4C77-AE4A-EDBE313DD45D">
            <UpgradeVersion IgnoreRemoveFailure="no" IncludeMaximum="no" Maximum="$(var.NumericVersion)" MigrateFeatures="no" Property="AFSPLUGIN_UPGRADE" />
        </Upgrade>
  <?endif?>
        
        <!-- openafs.org NSIS installer is detected using other means -->
        <!-- Please let us know if you want other Installers to be detected and upgraded/removed -->

		<!-- Media -->
		<Media Id="1" Cabinet="disk1.cab" CompressionLevel="high" EmbedCab="yes" />
    </Product>
</Wix>
