<?xml version='1.0' encoding='utf-8'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>
  <?include productInfo.wxi ?>
  <?include config.wxi ?>

  <Product Name='$(var.ProductName)' Id='*' UpgradeCode='$(var.ProductUpgradeCode)'
    Language='1033' Codepage='1252' Version='$(var.ProductVersion)' Manufacturer='$(var.ProductManufacturer)'>

    <Package Id='*' Keywords='Installer' Description="$(var.ProductName) Setup"
      Comments='$(var.ProductDescription)' Manufacturer='$(var.ProductManufacturer)'
      InstallerVersion='405' Languages='1033' Compressed='yes' SummaryCodepage='1252' InstallScope='perMachine'/>

    <Media Id='1' Cabinet='Cppcheck.cab' EmbedCab='yes' CompressionLevel='high' DiskPrompt='CD-ROM 1' />
    <Property Id='DiskPrompt' Value='Cppcheck installation [1]' />

    <Directory Id='TARGETDIR' Name='SourceDir'>
      <Directory Id='System32' FileSource='SystemFolder' />
      <Directory Id='$(var.PlatformProgramFilesFolder)' Name='PFiles'>
        <Directory Id='INSTALLDIR' Name='$(var.ProductNameShort)'>
          <Component Id='cppcheckcore.dll' Guid='$(var.cppcheckcoreGUID)'>
            <File Id='cppcheckcore.dll' Name='cppcheck-core.dll' DiskId='1' Source='$(var.CliBuildDir)\cppcheck-core.dll' KeyPath='yes' />
          </Component>
          <Component Id='cppcheck.exe' Guid='$(var.cppcheckGUID)'>
            <File Id='cppcheck.exe' Name='cppcheck.exe' DiskId='1' Source='$(var.CliBuildDir)\cppcheck.exe' KeyPath='yes' />
          </Component>
          <Component Id='RegistryEntries' Guid='$(var.registrykeysGUID)'>
            <RegistryKey Root="HKCU" Key="SOFTWARE\$(var.ProductNameShort)" ForceDeleteOnUninstall="yes">
              <RegistryValue Name="InstallationPath" Value="[INSTALLDIR]" Type="string" KeyPath="yes" />
              <RegistryValue Name="Version" Value="$(var.ProductVersion)" Type="string" />
            </RegistryKey>
          </Component>
          <Component Id='GuiExecutable' DiskId='1' Guid='$(var.guiGUID)'>
            <File Id='cppcheckguiexe' Name='cppcheckgui.exe' Source='$(var.GuiBuildDir)\cppcheck-gui.exe' KeyPath='yes'>
              <Shortcut Id='startmenuGui' Directory="ProgramMenuDir" Name='$(var.ProductNameShort)'
                  WorkingDirectory='INSTALLDIR' Icon="cppcheckgui.exe" IconIndex="0" Advertise="yes" />
            </File>
            <File Id='Qt5Coredll' Name='Qt5Core.dll' Source='$(var.QtDllDir)\Qt5Core.dll' />
            <File Id='Qt5Guidll' Name='Qt5Gui.dll' Source='$(var.QtDllDir)\Qt5Gui.dll' />
            <File Id='Qt5Widgetsdll' Name='Qt5Widgets.dll' Source='$(var.QtDllDir)\Qt5Widgets.dll' />
            <File Id='Qt5PrintSupportdll' Name='Qt5PrintSupport.dll' Source='$(var.QtDllDir)\Qt5PrintSupport.dll' />
          </Component>
          <Directory Id='QtPlatformsFolder' Name='platforms'>
            <Component Id='QtPlatforms' DiskId='1' Guid='$(var.qtplatformsGUID)'>
              <File Id='qwindowsdll' Name='qwindows.dll' Source='$(var.QtDllDir)\platforms\qwindows.dll' />
            </Component>
          </Directory>
          <Directory Id='QtStylesFolder' Name='styles'>
            <Component Id='QtStyles' DiskId='1' Guid='$(var.qtstylesGUID)'>
              <File Id='qwindowsvistastyledll' Name='qwindowsvistastyle.dll' Source='$(var.QtDllDir)\styles\qwindowsvistastyle.dll' />
            </Component>
          </Directory>
          <Directory Id='TranslationsFolder' Name='lang'>
            <Component Id='GuiTranslations' Guid='$(var.guiTranslationsGUID)'>
              <File Id='cppcheck_de.qm' Name='cppcheck_de.qm' Source='$(var.TranslationsDir)\cppcheck_de.qm' />
              <File Id='cppcheck_es.qm' Name='cppcheck_es.qm' Source='$(var.TranslationsDir)\cppcheck_es.qm' />
              <File Id='cppcheck_fi.qm' Name='cppcheck_fi.qm' Source='$(var.TranslationsDir)\cppcheck_fi.qm' />
              <File Id='cppcheck_fr.qm' Name='cppcheck_fr.qm' Source='$(var.TranslationsDir)\cppcheck_fr.qm' />
              <File Id='cppcheck_it.qm' Name='cppcheck_it.qm' Source='$(var.TranslationsDir)\cppcheck_it.qm' />
              <File Id='cppcheck_ja.qm' Name='cppcheck_ja.qm' Source='$(var.TranslationsDir)\cppcheck_ja.qm' />
              <File Id='cppcheck_ko.qm' Name='cppcheck_ko.qm' Source='$(var.TranslationsDir)\cppcheck_ko.qm' />
              <File Id='cppcheck_nl.qm' Name='cppcheck_nl.qm' Source='$(var.TranslationsDir)\cppcheck_nl.qm' />
              <File Id='cppcheck_ru.qm' Name='cppcheck_ru.qm' Source='$(var.TranslationsDir)\cppcheck_ru.qm' />
              <File Id='cppcheck_sv.qm' Name='cppcheck_sv.qm' Source='$(var.TranslationsDir)\cppcheck_sv.qm' />
              <File Id='cppcheck_sr.qm' Name='cppcheck_sr.qm' Source='$(var.TranslationsDir)\cppcheck_sr.qm' />
              <File Id='cppcheck_zh_CN.qm' Name='cppcheck_zh_CN.qm' Source='$(var.TranslationsDir)\cppcheck_zh_CN.qm' />
            </Component>
          </Directory>
          <Directory Id='CfgsFolder' Name='cfg'>
            <Component Id='MandatoryCfgs' Guid='$(var.mandatoryCfgsGUID)'>
              <File Id='std.cfg' Name='std.cfg' Source='$(var.CfgsDir)\std.cfg' />
            </Component>
            <Component Id='OptionalCfgs' Guid='$(var.optionalCfgsGUID)'>
              <File Id='avr.cfg' Name='avr.cfg' Source='$(var.CfgsDir)\avr.cfg' />
              <File Id='bsd.cfg' Name='bsd.cfg' Source='$(var.CfgsDir)\bsd.cfg' />
              <File Id='embedded_sql.cfg' Name='embedded_sql.cfg' Source='$(var.CfgsDir)\embedded_sql.cfg' />
              <File Id='gnu.cfg' Name='gnu.cfg' Source='$(var.CfgsDir)\gnu.cfg' />
              <File Id='gtk.cfg' Name='gtk.cfg' Source='$(var.CfgsDir)\gtk.cfg' />
              <File Id='microsoft_sal.cfg' Name='microsoft_sal.cfg' Source='$(var.CfgsDir)\microsoft_sal.cfg' />
              <File Id='motif.cfg' Name='motif.cfg' Source='$(var.CfgsDir)\motif.cfg' />
              <File Id='posix.cfg' Name='posix.cfg' Source='$(var.CfgsDir)\posix.cfg' />
              <File Id='qt.cfg' Name='qt.cfg' Source='$(var.CfgsDir)\qt.cfg' />
              <File Id='sdl.cfg' Name='sdl.cfg' Source='$(var.CfgsDir)\sdl.cfg' />
              <File Id='sfml.cfg' Name='sfml.cfg' Source='$(var.CfgsDir)\sfml.cfg' />
              <File Id='windows.cfg' Name='windows.cfg' Source='$(var.CfgsDir)\windows.cfg' />
              <File Id='wxwidgets.cfg' Name='wxwidgets.cfg' Source='$(var.CfgsDir)\wxwidgets.cfg' />
            </Component>
          </Directory>
          <Directory Id='PtfsFolder' Name='platforms'>
            <Component Id='OptionalPtfs' Guid='$(var.optionalPtfsGUID)'>
              <File Id='avr8.xml' Name='avr8.xml' Source='$(var.PtfsDir)\avr8.xml' />
              <File Id='msp430_eabi_large_datamodel.xml' Name='msp430_eabi_large_datamodel.xml' Source='$(var.PtfsDir)\msp430_eabi_large_datamodel.xml' />
              <File Id='unix32unsigned.xml' Name='unix32-unsigned.xml' Source='$(var.PtfsDir)\unix32-unsigned.xml' />
              <File Id='unix64unsigned.xml' Name='unix64-unsigned.xml' Source='$(var.PtfsDir)\unix64-unsigned.xml' />
            </Component>
          </Directory>
          <Directory Id='AddonsFolder' Name='addons'>
            <Component Id='Addons' Guid='$(var.addonsGUID)'>
              <File Id='cppcheckdata.py' Name='cppcheckdata.py' Source='$(var.AddonsDir)\cppcheckdata.py' />
              <File Id='cert.py' Name='cert.py' Source='$(var.AddonsDir)\cert.py' />
              <File Id='findcasts.py' Name='findcasts.py' Source='$(var.AddonsDir)\findcasts.py' />
              <File Id='misc.py' Name='misc.py' Source='$(var.AddonsDir)\misc.py' />
              <File Id='misra.py' Name='misra.py' Source='$(var.AddonsDir)\misra.py' />
              <File Id='naming.py' Name='naming.py' Source='$(var.AddonsDir)\naming.py' />
              <File Id='threadsafety.py' Name='threadsafety.py' Source='$(var.AddonsDir)\threadsafety.py' />
              <File Id='y2038.py' Name='y2038.py' Source='$(var.AddonsDir)\y2038\y2038.py' />
            </Component>
          </Directory>
          <Component Id='BaseDocs' Guid='$(var.basedocsGUID)'>
            <File Id='authors.txt' Name='authors.txt' DiskId='1' Source='..\authors' />
            <File Id='readme.txt' Name='readme.txt' DiskId='1' Source='..\readme.txt' />
            <File Id='GPLv3.txt' Name='GPLv3.txt' DiskId='1' Source='GPLv3.txt' />
          </Component>
        </Directory>
        <Merge Id="CRT" Language="0" SourceFile="$(var.CrtMergeModule)" DiskId="1" />
      </Directory>

      <Directory Id='ProgramMenuFolder' Name='Programs' >
        <Directory Id='ProgramMenuDir' Name='$(var.ProductName)'>
          <Component Id='ProgramMenuDir' Guid='*'>
            <RemoveFolder Id='ProgramMenuDir' On='uninstall' />
            <RegistryValue Root='HKCU' Key='Software\Cppcheck\$(var.ProductName)' Type='string' Value='' KeyPath='yes' />
          </Component>
        </Directory>
      </Directory>
    </Directory>

    <Property Id="INSTALLLEVEL" Value="1" />
    <Feature Id='Complete' Title='$(var.ProductName)' Description='The complete package.'
      Display='expand' Level='1' AllowAdvertise='no' ConfigurableDirectory='INSTALLDIR' >
      <Feature Id='CppcheckCore' Display='hidden' AllowAdvertise='no' Title='Cppcheck-Core' Description='Cppcheck core components' Level='1'>
        <ComponentRef Id='cppcheckcore.dll' />
        <ComponentRef Id='RegistryEntries' />
        <ComponentRef Id='BaseDocs' />
        <ComponentRef Id='MandatoryCfgs' />
      </Feature>
      <Feature Id='CLI' Title='Command line interface' AllowAdvertise='no' Description='Cppcheck as a command line tool' Level='1'>
        <ComponentRef Id='cppcheck.exe' />
      </Feature>
      <Feature Id='GUI' Title='Graphical interface' AllowAdvertise='no' Description='Cppcheck with a graphical user interface' Level='1'>
        <ComponentRef Id='RegistryEntries' />
        <ComponentRef Id='GuiExecutable' />
        <ComponentRef Id='QtPlatforms' />
        <ComponentRef Id='QtStyles' />
        <Feature Id='Translations' Title='GUI Translations' AllowAdvertise='no' Description='Translations for graphical user interface' Level='1'>
          <ComponentRef Id='GuiTranslations' />
        </Feature>
        <ComponentRef Id='ProgramMenuDir' />
      </Feature>
      <Feature Id='ConfigFiles' Title='Additional configurations' AllowAdvertise='no' Description='Provide additional configuration files, for example for WinAPI, GTK and SDL' Level='1'>
        <ComponentRef Id='OptionalCfgs' />
      </Feature>
      <Feature Id='PlatformFiles' Title='Additional platforms' AllowAdvertise='no' Description='Provide additional platform files, for example unix platforms with unsigned types as default' Level='1'>
        <ComponentRef Id='OptionalPtfs' />
      </Feature>
      <Feature Id='PythonAddons' Title='Python addons' AllowAdvertise='no' Description='Contains several addons requiring python' Level='2'>
        <ComponentRef Id='Addons' />
      </Feature>
      <Feature Id="CRT" AllowAdvertise="no" Display="hidden" Level="1" Title="Microsoft Visual C++ 2015 Runtime Components">
        <MergeRef Id="CRT"/>
      </Feature>
    </Feature>

    <MajorUpgrade DowngradeErrorMessage='Downgrade is not allowed'/>
    <!--Remove some pre 1.57 versions which can't be upgraded with MajorUpgrade-->
    <InstallExecuteSequence>
      <Custom Action='UninstallOld152' After='InstallFinalize'>NOT Installed</Custom>
      <Custom Action='UninstallOld153' After='InstallFinalize'>NOT Installed</Custom>
      <Custom Action='UninstallOld154' After='InstallFinalize'>NOT Installed</Custom>
      <Custom Action='UninstallOld155' After='InstallFinalize'>NOT Installed</Custom>
      <Custom Action='UninstallOld156' After='InstallFinalize'>NOT Installed</Custom>
    </InstallExecuteSequence>
    <CustomAction Id='UninstallOld152' Directory='System32' ExeCommand="msiexec.exe /X {836AF028-6EE2-457C-B242-19D61701BAA3} /qn" Execute="immediate" Return="asyncNoWait"/>
    <CustomAction Id='UninstallOld153' Directory='System32' ExeCommand="msiexec.exe /X {42850B7E-CD5F-449A-B6DA-C423156D2ACF} /qn" Execute="immediate" Return="asyncNoWait"/>
    <CustomAction Id='UninstallOld154' Directory='System32' ExeCommand="msiexec.exe /X {7722557B-4B10-4E8F-918A-78FBAEFB09B1} /qn" Execute="immediate" Return="asyncNoWait"/>
    <CustomAction Id='UninstallOld155' Directory='System32' ExeCommand="msiexec.exe /X {211B2B89-3FE0-4F49-88CC-27E283BEC010} /qn" Execute="immediate" Return="asyncNoWait"/>
    <CustomAction Id='UninstallOld156' Directory='System32' ExeCommand="msiexec.exe /X {1CC8C271-A877-4DF0-B1DE-C1B7D83521BC} /qn" Execute="immediate" Return="asyncNoWait"/>

    <Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" />
    <UI>
      <TextStyle Id="WixUI_Font_Normal" FaceName="Tahoma" Size="8" />
      <TextStyle Id="WixUI_Font_Bigger" FaceName="Tahoma" Size="12" />
      <TextStyle Id="WixUI_Font_Title" FaceName="Tahoma" Size="9" Bold="yes" />

      <Property Id="DefaultUIFont" Value="WixUI_Font_Normal" />
      <Property Id="WixUI_Mode" Value="FeatureTree" />

      <DialogRef Id="ErrorDlg" />
      <DialogRef Id="FatalError" />
      <DialogRef Id="FilesInUse" />
      <DialogRef Id="MsiRMFilesInUse" />
      <DialogRef Id="PrepareDlg" />
      <DialogRef Id="ProgressDlg" />
      <DialogRef Id="ResumeDlg" />
      <DialogRef Id="UserExit" />

      <Publish Dialog="ExitDialog" Control="Finish" Event="EndDialog" Value="Return" Order="999">1</Publish>

      <Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="CustomizeDlg">NOT Installed</Publish>
      <Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg">Installed AND PATCH</Publish>

      <Publish Dialog="CustomizeDlg" Control="Back" Event="NewDialog" Value="MaintenanceTypeDlg" Order="1">Installed</Publish>
      <Publish Dialog="CustomizeDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2">NOT Installed</Publish>
      <Publish Dialog="CustomizeDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>

      <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="CustomizeDlg" Order="1">NOT Installed OR WixUI_InstallMode = "Change"</Publish>
      <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="MaintenanceTypeDlg" Order="2">Installed AND NOT PATCH</Publish>
      <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="3">Installed AND PATCH</Publish>

      <Publish Dialog="MaintenanceWelcomeDlg" Control="Next" Event="NewDialog" Value="MaintenanceTypeDlg">1</Publish>

      <Publish Dialog="MaintenanceTypeDlg" Control="ChangeButton" Event="NewDialog" Value="CustomizeDlg">1</Publish>
      <Publish Dialog="MaintenanceTypeDlg" Control="RepairButton" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
      <Publish Dialog="MaintenanceTypeDlg" Control="RemoveButton" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
      <Publish Dialog="MaintenanceTypeDlg" Control="Back" Event="NewDialog" Value="MaintenanceWelcomeDlg">1</Publish>
    </UI>
    <UIRef Id="WixUI_Common" />

    <Icon Id='cppcheckgui.exe' SourceFile='$(var.GuiBuildDir)\cppcheck-gui.exe' />
    <Property Id="ARPPRODUCTICON" Value="cppcheckgui.exe" />

    <WixVariable Id="WixUIBannerBmp" Value="images\banner.jpg" />
    <WixVariable Id="WixUIDialogBmp" Value="images\dialog.jpg" />
  </Product>
</Wix>
