<?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="110"
         Keywords="Installer,OpenAFS,$(var.Manufacturer)"
         Languages="$(var.Languages)"
         Manufacturer="$(var.Manufacturer)"
         Platforms="Intel"
         ShortNames="no"
         SummaryCodepage="1252"
         />
        
        <!-- Launch conditions -->
        <Condition Message="$(loc.StrLaunchCond)">
         <![CDATA[VersionNT >= 500]]>
        </Condition>
        <Condition Message="$(loc.AdminRequired)">Privileged</Condition>
        
        
        <!-- Global Properties -->
        <?include property.wxi?>
        
        <!-- File system and registry settings -->
        <Directory Id="TARGETDIR" Name="SourceDir">
            <?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"/>
	<?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" 
         />
        <CustomAction
         Id="RollbackLoopback"
         BinaryKey="BIN_afsLoopback"
         DllEntry="uninstallLoopbackMSI"
         Execute="deferred" 
         />
	<?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="oncePerProcess" />
		<CustomAction 
		 Id="RemoveNetProvider" 
		 BinaryKey="BIN_afsCustom"
		 DllEntry="UninstallNetProvider"
		 Return="ignore"
		 Execute="oncePerProcess" />
		<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" />

        <!-- Installation Sequences -->
        <AdvertiseExecuteSequence />
        <AdminExecuteSequence />
        <InstallExecuteSequence>
			<RemoveExistingProducts After="InstallValidate">IBMAFS_UPGRADE OR OPENAFS_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="ConfigureClient" After="InstallServices">&amp;feaClient=3</Custom>
			<Custom Action="ConfigureServer" After="ConfigureClient">&amp;feaServer=3</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>
            <ScheduleReboot After="PublishProduct">&amp;feaClient=3 OR &amp;feaServer=3 OR &amp;feaClient=2 OR &amp;feaServer=2</ScheduleReboot>
        </InstallExecuteSequence>

        <!-- Related producs -->
        <!-- MIT's OpenAFS MSI installer -->
        <Upgrade Id="6823EEDD-84FC-4204-ABB3-A80D25779833">
            <UpgradeVersion IgnoreRemoveFailure="no" IncludeMaximum="no" 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>
        
        <!-- 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>
