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

<!-- *****************************************************************************************
 Modifications Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 
 Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License, version 2.0, as
 published by the Free Software Foundation.

 This program is also distributed with certain software (including
 but not limited to OpenSSL) that is licensed under separate terms,
 as designated in a particular file or component or in included license
 documentation. The authors of MySQL hereby grant you an
 additional permission to link the program and your derivative works
 with the separately licensed software that they have included with
 MySQL.

 Without limiting anything contained in the foregoing, this file,
 which is part of MySQL Connector/ODBC, is also subject to the
 Universal FOSS Exception, version 1.0, a copy of which can be found at
 http://oss.oracle.com/licenses/universal-foss-exception.

 This program is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 See the GNU General Public License, version 2.0, for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-->

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

  <?include myodbc_version.xml ?>
  <!-- *****************************************************************************************
    Product MySQL Server
  -->
  <!--
    SetVersion updates: Name, Id, Version. Do not change them manually.
  -->

  <?if $(var.odbc_64bit) = 1 ?>
    <?define odbc_platform="x64" ?>
    <?define odbc_arch="64-bit" ?>
    <?define upgrade_code="5c230eb8-12f8-47bf-be2f-cd043ea2acb4" ?>
  <?else ?>
    <?define odbc_platform="x86" ?>
    <?define odbc_arch="32-bit" ?>
    <?define upgrade_code="43a4dc40-e864-11ed-a05b-0242ac120003" ?>
  <?endif ?>

  <Product Id="@CONNECTOR_PKG_ID1@" UpgradeCode="$(var.upgrade_code)" Codepage="utf-8"
    Name="AWS ODBC Driver for MySQL" Version="$(var.odbc_ver_long)" Language="1033" Manufacturer="Amazon.com Inc. or affiliates">

  <!-- *****************************************************************************************
    Package
  -->
  <!--
    SetVersion updates: Id. Do not change it manually.
  -->

    <Package Keywords="Installer,MSI,Database"
      Description="AWS ODBC Driver for MySQL" Manufacturer="Amazon.com Inc. or affiliates"
      InstallerVersion="200" Platform="$(var.odbc_platform)"
      Languages="1033" SummaryCodepage="1252" Compressed='yes' />
    <?include mysql-connector-odbc-msi-arpprops.xml ?>

    <!-- *****************************************************************************************
      Custom Actions
    -->

    <CustomAction Id="NewerVersionInstalled" Error="A newer version of this product is already installed." />

    <!-- *****************************************************************************************
      Upgrade Information
    -->

    <MajorUpgrade Schedule="afterInstallInitialize" DowngradeErrorMessage="A newer version of this product is already installed. Setup will now exit." />

    <Upgrade Id="$(var.upgrade_code)">
      <!-- !!!SetVersion updates: Minimum, Maximum -->
      <UpgradeVersion Property="PREVIOUSVERSIONINSTALLED" Minimum="0.0.0" Maximum="$(var.odbc_ver_prev)" IncludeMaximum="yes"
        IncludeMinimum="yes"  />
      <!-- !!!SetVersion updates: Minimum, Maximum -->
      <UpgradeVersion Property="NEWERPRODUCTFOUND" Minimum="$(var.odbc_ver_long)" Maximum="$(var.odbc_ver_short).999" OnlyDetect="yes"
        IncludeMinimum="no" />
    </Upgrade>

    <!-- Visual Studio Redistributable Check -->
    <?if $(var.odbc_64bit) = 1 ?>
      <Property Id="VS14REDISTX64_64_MAJOR">
        <RegistrySearch Id="FindRedistVS14_64_MAJOR"
            Root="HKLM"
            Key="SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64"
            Name="Major"
            Win64="yes"
            Type="raw" />
      </Property>
      <Property Id="VS14REDISTX64_64_MINOR">
        <RegistrySearch Id="FindRedistVS14_64_MINOR"
            Root="HKLM"
            Key="SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64"
            Name="Minor"
            Win64="yes"
            Type="raw" />
      </Property>
      <!-- Through testing we did discover that depending on version of Windows
        VS redist registry keys are available either under 64, or both 32 and 64 bit keys
        (in most cases under both). Just to be safe we decided to always check under both. -->
      <Property Id="VS14REDISTX64_32_MAJOR">
        <RegistrySearch Id="FindRedistVS14_32_MAJOR"
            Root="HKLM"
            Key="SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64"
            Name="Major"
            Win64="no"
            Type="raw" />
      </Property>
      <Property Id="VS14REDISTX64_32_MINOR">
        <RegistrySearch Id="FindRedistVS14_32_MINOR"
            Root="HKLM"
            Key="SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64"
            Name="Minor"
            Win64="no"
            Type="raw" />
      </Property>
      <!-- For numbers (DWORD type in Windows Registry) WiX RegistrySearch uses a special prefix: '#'.
        We have to get rid of it before using properties in the condition check,
        We want to compare numbers, rather than strings. -->
      <CustomAction Id="DwordToNumber" Script="vbscript">
        <![CDATA[
          Session.Property("VS14REDISTX64_64_MAJOR") = Replace(Session.Property("VS14REDISTX64_64_MAJOR"),"#","")
          Session.Property("VS14REDISTX64_64_MINOR") = Replace(Session.Property("VS14REDISTX64_64_MINOR"),"#","")
          Session.Property("VS14REDISTX64_32_MAJOR") = Replace(Session.Property("VS14REDISTX64_32_MAJOR"),"#","")
          Session.Property("VS14REDISTX64_32_MINOR") = Replace(Session.Property("VS14REDISTX64_32_MINOR"),"#","")
        ]]>
      </CustomAction>
      <Condition Message="This application requires Visual Studio 2019 x64 Redistributable. Please install the Redistributable then run this installer again.">
        Installed OR (VS14REDISTX64_64_MAJOR = 14 AND VS14REDISTX64_64_MINOR >= 20) OR (VS14REDISTX64_32_MAJOR = 14 AND VS14REDISTX64_32_MINOR >= 20)
      </Condition>
    <?else?>
      <Property Id="VS14REDISTX86_64_MAJOR">
        <RegistrySearch Id="FindRedistVS14_64_MAJOR"
            Root="HKLM"
            Key="SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86"
            Name="Major"
            Win64="yes"
            Type="raw" />
      </Property>
      <Property Id="VS14REDISTX86_64_MINOR">
        <RegistrySearch Id="FindRedistVS14_64_MINOR"
            Root="HKLM"
            Key="SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86"
            Name="Minor"
            Win64="yes"
            Type="raw" />
      </Property>
      <Property Id="VS14REDISTX86_32_MAJOR">
        <RegistrySearch Id="FindRedistVS14_32_MAJOR"
            Root="HKLM"
            Key="SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86"
            Name="Major"
            Win64="no"
            Type="raw" />
      </Property>
      <Property Id="VS14REDISTX86_32_MINOR">
        <RegistrySearch Id="FindRedistVS14_32_MINOR"
            Root="HKLM"
            Key="SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86"
            Name="Minor"
            Win64="no"
            Type="raw" />
      </Property>
      <!-- For numbers (DWORD type in Windows Registry) WiX RegistrySearch uses a special prefix: '#'.
        We have to get rid of it before using properties in the condition check,
        We want to compare numbers, rather than strings. -->
      <CustomAction Id="DwordToNumber" Script="vbscript">
        <![CDATA[
          Session.Property("VS14REDISTX86_64_MAJOR") = Replace(Session.Property("VS14REDISTX86_64_MAJOR"),"#","")
          Session.Property("VS14REDISTX86_64_MINOR") = Replace(Session.Property("VS14REDISTX86_64_MINOR"),"#","")
          Session.Property("VS14REDISTX86_32_MAJOR") = Replace(Session.Property("VS14REDISTX86_32_MAJOR"),"#","")
          Session.Property("VS14REDISTX86_32_MINOR") = Replace(Session.Property("VS14REDISTX86_32_MINOR"),"#","")
        ]]>
      </CustomAction>
      <Condition Message="This application requires Visual Studio 2019 x86 Redistributable. Please install the Redistributable then run this installer again.">
        Installed OR (VS14REDISTX86_64_MAJOR = 14 AND VS14REDISTX86_64_MINOR >= 20) OR (VS14REDISTX86_32_MAJOR = 14 AND VS14REDISTX86_32_MINOR >= 20)
      </Condition>
    <?endif?>
    <InstallExecuteSequence>
      <Custom Action="DwordToNumber" Before="LaunchConditions"/>
    </InstallExecuteSequence>
    <InstallUISequence>
      <Custom Action="DwordToNumber" Before="LaunchConditions"/>
    </InstallUISequence>

    <!-- *****************************************************************************************
      CAB file
    -->

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

    <!-- *****************************************************************************************
      Registry entries
    -->

    <?if $(var.odbc_64bit) = 1 ?>
      <DirectoryRef Id="ProgramFiles64Folder">
      <Component Id="RegKeys" Guid="33a46aaf-5684-431d-824f-cee1f606985e" DiskId="1" Win64="yes">
    <?else ?>
      <DirectoryRef Id="ProgramFilesFolder">
      <Component Id="RegKeys" Guid="0d96eb9d-5d18-4b55-ba42-f89c929f61cd" DiskId="1">
    <?endif ?>
        <RegistryKey Id="AwsMysqlKey" Root="HKLM" Key="SOFTWARE\Amazon\[ProductName]"
                  ForceDeleteOnUninstall="yes"/>
        <RegistryValue Id="Version" Root="HKLM" Key="SOFTWARE\Amazon\[ProductName]"
                  Name="Version" Type="string" Value="[ProductVersion]"/>
        <RegistryKey Root="HKLM" Key="SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers">
          <RegistryValue Type="string" Name="AWS ODBC ANSI Driver for MySQL" Value="Installed" />
          <RegistryValue Type="string" Name="AWS ODBC Unicode Driver for MySQL" Value="Installed" />
        </RegistryKey>
        <RegistryKey Root="HKLM" Key="SOFTWARE\ODBC\ODBCINST.INI\AWS ODBC ANSI Driver for MySQL">
          <RegistryValue Type="string" Name="Driver" Value="[INSTALLDIR]awsmysqlodbca.dll" />
          <RegistryValue Type="string" Name="Setup" Value="[INSTALLDIR]awsmysqlodbcS.dll" />
        </RegistryKey>
        <RegistryKey Root="HKLM" Key="SOFTWARE\ODBC\ODBCINST.INI\AWS ODBC Unicode Driver for MySQL">
          <RegistryValue Type="string" Name="Driver" Value="[INSTALLDIR]awsmysqlodbcw.dll" />
          <RegistryValue Type="string" Name="Setup" Value="[INSTALLDIR]awsmysqlodbcS.dll" />
        </RegistryKey>
    <!--Need these to make candle happy -->
    <?if $(var.odbc_64bit) = 1 ?>
      </Component>
      </DirectoryRef>
    <?else ?>
      </Component>
      </DirectoryRef>
    <?endif ?>

    <!-- *****************************************************************************************
      Installation Features
    -->

    <!-- *****************************************************************************************
      Product Feature
    -->

    <?if $(var.odbc_64bit) = 1 ?>
    <Feature Id="ODBC" Title="AWS ODBC Driver for MySQL $(var.odbc_ver_long) 64-bit" Level="1" Description="Installs the AWS ODBC Driver for MySQL $(var.odbc_ver_long) 64-bit Unicode and ANSI drivers."  ConfigurableDirectory="INSTALLDIR">
    <?else ?>
    <Feature Id="ODBC" Title="AWS ODBC Driver for MySQL $(var.odbc_ver_long) 32-bit" Level="1" Description="Installs the AWS ODBC Driver for MySQL $(var.odbc_ver_long) 32-bit Unicode and ANSI drivers."  ConfigurableDirectory="INSTALLDIR">
    <?endif ?>
      <ComponentRef Id="RegKeys" />
      <ComponentRef Id="driver" />
      <ComponentRef Id="setup" />
      <ComponentRef Id="installer" />
      <ComponentRef Id="ssl" />
      <ComponentRef Id="dependencies" />
      <ComponentRef Id="plugins" />
    <?if $(var.odbc_64bit) = 1 ?>
    </Feature>
    <?else ?>
    </Feature>
    <?endif ?>

    <!--Feature Id="Help" Title="AWS ODBC Driver for MySQL $(var.odbc_ver_long) Documentation" Level="1" Description="Installs the MySQL ODBC driver help.">
        <ComponentRef Id="help" />
    </Feature-->

    <!-- *****************************************************************************************
      End of Feature
    -->

    <!-- *****************************************************************************************
      Include UI
    -->

    <?include mysql_common_ui.xml ?>

    <!-- *****************************************************************************************
      Properties
    -->

    <Property Id="_IsMaintenance">Change</Property>

    <Property Id="AgreeToLicense">No</Property>
    <Property Id="ApplicationUsers">AllUsers</Property>
    <Property Id="ALLUSERS">1</Property> <!--per-machine installation -->

    <Property Id="INSTALLLEVEL">1</Property>

    <Property Id="ProgressType3">installs</Property>
    <Property Id="ProgressType2">installed</Property>
    <Property Id="ProgressType1">Installing</Property>
    <Property Id="ProgressType0">install</Property>

    <Property Id="QualifiedProductName">AWS ODBC Driver for MySQL $(var.odbc_ver_long)($(var.odbc_driver_type_suffix))</Property>
    <Property Id="InstallationDirectory">AWS ODBC Driver for MySQL</Property>

    <Property Id="ReinstallFileVersion">o</Property>
    <Property Id="RebootYesNo">Yes</Property>
    <Property Id="ReinstallModeText">omus</Property>
    <Property Id="ReinstallRepair">r</Property>

    <Property Id="SetupType">Complete</Property>
    <Property Id="ConfigureServer">1</Property>

    <!-- The Guid has to be the same as in the mysql_odbc_fragment.xml -->
    <Property Id="SVRCNFWIZINSTALLED"><ComponentSearch Id="SvrCnfWizCompSearch"
      Guid="57792803-fbd7-433c-b6b5-60fddf34e0ce" /></Property>

    <!-- *****************************************************************************************
      Admin UI Sequence
    -->

    <AdminUISequence>
      <Show Dialog="SetupCompleteErrorDialog" OnExit="error" />
      <Show Dialog="SetupInterruptedDialog" OnExit="cancel" />
      <Show Dialog="SetupCompleteSuccessDialog" OnExit="success" />

      <Show Dialog="SetupInitializationDialog" Before="CostInitialize" />
      <Show Dialog="AdminWelcomeDialog" After="CostFinalize" />
      <Show Dialog="SetupProgressDialog" After="AdminWelcomeDialog" />
    </AdminUISequence>

    <!-- *****************************************************************************************
      Install Execute Sequence
    -->

    <InstallExecuteSequence>
      <Custom Action="NewerVersionInstalled" After="FindRelatedProducts">NEWERPRODUCTFOUND</Custom>
      <SetODBCFolders Suppress="yes" />
    </InstallExecuteSequence>

    <!-- *****************************************************************************************
      Install UI Sequence
    -->

    <InstallUISequence>
      <Show Dialog="SetupCompleteErrorDialog" OnExit="error" />
      <Show Dialog="SetupInterruptedDialog" OnExit="cancel" />
      <Show Dialog="SetupCompleteSuccessDialog" OnExit="success" />

      <Custom Action="NewerVersionInstalled" After="FindRelatedProducts">NEWERPRODUCTFOUND</Custom>
      <Show Dialog="InstallWelcomeDialog" After="MigrateFeatureStates">Not Installed And (Not PATCH Or IS_MAJOR_UPGRADE)</Show>
      <Show Dialog="SetupResumeDialog" After="InstallWelcomeDialog">Installed And (RESUME Or Preselected) And Not PATCH</Show>
      <Show Dialog="MaintenanceWelcomeDialog" After="SetupResumeDialog">Installed And Not RESUME And Not Preselected And Not PATCH</Show>
      <Show Dialog="SetupProgressDialog" After="MaintenanceWelcomeDialog" />
    </InstallUISequence>

    <!-- *****************************************************************************************
      Binary files
    -->

    <Binary Id="AdminBackground" SourceFile="$(var.odbc_resource)/ConnBackground.jpg" />
    <Binary Id="AdminHeader" SourceFile="$(var.odbc_resource)/ConnHeader.jpg" />
    <Binary Id="SetupTypeComp" SourceFile="$(var.odbc_resource)/setup_type_complete.ico" />
    <Binary Id="SetupTypeCust" SourceFile="$(var.odbc_resource)/setup_type_custom.ico" />
    <Binary Id="SetupTypeTyp" SourceFile="$(var.odbc_resource)/setup_type_typical.ico" />
    <Binary Id="DestDirFolder" SourceFile="$(var.odbc_resource)/dest_dir_folder.ico" />

    <Binary Id="NewBinary2" SourceFile="$(var.odbc_resource)/binary/binary2" />
    <Binary Id="NewBinary3" SourceFile="$(var.odbc_resource)/binary/binary3" />
    <Binary Id="NewBinary4" SourceFile="$(var.odbc_resource)/binary/binary4" />
    <Binary Id="NewBinary6" SourceFile="$(var.odbc_resource)/binary/binary6" />
    <Binary Id="NewBinary7" SourceFile="$(var.odbc_resource)/binary/binary7" />
    <Binary Id="NewBinary8" SourceFile="$(var.odbc_resource)/binary/binary8" />
    <Binary Id="NewBinary9" SourceFile="$(var.odbc_resource)/binary/binary9" />
    <Binary Id="NewBinary13" SourceFile="$(var.odbc_resource)/binary/binary13" />
    <Binary Id="NewBinary14" SourceFile="$(var.odbc_resource)/binary/binary14" />
    <Binary Id="NewBinary16" SourceFile="$(var.odbc_resource)/binary/binary16" />
    <Binary Id="NewBinary17" SourceFile="$(var.odbc_resource)/binary/binary17" />
    <Binary Id="NewBinary18" SourceFile="$(var.odbc_resource)/binary/binary18" />
  </Product>
</Wix>
