<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
  <Package
    Name="GWT"
    Language="1033"
    Version="$(Version)"
    Manufacturer="GWT Contributors"
    UpgradeCode="55555555-5555-5555-5555-555555555555"
    InstallerVersion="500"
    Scope="perUser">
    <SummaryInformation Description="Canvas-based floating terminal GUI for Git Worktree Manager" />
    <Property Id="ARPPRODUCTICON" Value="GwtIcon.exe" />
    <Property Id="GWT_ALLOW_LEGACY_MIGRATION" Secure="yes" />
    <Property Id="GWT_LEGACY_PER_MACHINE_EXE">
      <DirectorySearch Id="GwtLegacyProgramFilesSearch" Path="[ProgramFiles6432Folder]GWT" Depth="0">
        <FileSearch Id="GwtLegacyProgramFilesExeSearch" Name="gwt.exe" />
      </DirectorySearch>
    </Property>
    <Launch
      Condition="NOT GWT_LEGACY_PER_MACHINE_EXE OR GWT_ALLOW_LEGACY_MIGRATION = &quot;1&quot;"
      Message="A per-machine GWT installation was found in Program Files. Uninstall the existing GWT from Windows Settings, then run this installer again." />
    <MajorUpgrade DowngradeErrorMessage="A newer version of GWT is already installed." />
    <MediaTemplate EmbedCab="yes" />

    <StandardDirectory Id="LocalAppDataFolder">
      <Directory Id="GwtProgramsFolder" Name="Programs">
        <Directory Id="INSTALLFOLDER" Name="GWT" />
      </Directory>
    </StandardDirectory>

    <StandardDirectory Id="ProgramMenuFolder">
      <Directory Id="ApplicationProgramsFolder" Name="GWT" />
    </StandardDirectory>

    <Feature Id="MainFeature" Title="GWT" Level="1">
      <ComponentGroupRef Id="ProductComponents" />
      <ComponentGroupRef Id="ShortcutComponents" />
    </Feature>

    <Icon Id="GwtIcon.exe" SourceFile="assets/icons/icon.ico" />
  </Package>

  <Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
      <Component Id="GwtExecutableComponent">
        <!--
          SPEC-1942 2026-05-20 Amendment Bug B: WiX v4 defaults the installed
          File Name to the literal Source string when Name is omitted, so the
          bindpath binder variable leaks into the on-disk file name (observed
          in v9.37.0 as `!(bindpath.gwt)gwt.exe`). Pin the Name explicitly so
          the installed file is always `gwt.exe` regardless of how bindpath
          resolves at build time.
        -->
        <File Id="GwtExecutable" Source="!(bindpath.gwt)gwt.exe" Name="gwt.exe" KeyPath="yes" />
        <Environment Id="GwtUserPath" Name="PATH" Value="[INSTALLFOLDER]" Action="set" Part="last" />
      </Component>
      <Component Id="GwtdExecutableComponent">
        <File Id="GwtdExecutable" Source="!(bindpath.gwt)gwtd.exe" Name="gwtd.exe" KeyPath="yes" />
      </Component>
    </ComponentGroup>

    <ComponentGroup Id="ShortcutComponents" Directory="ApplicationProgramsFolder">
      <Component Id="GwtStartMenuShortcutComponent">
        <Shortcut
          Id="GwtStartMenuShortcut"
          Name="GWT"
          Description="Open GWT"
          Target="[#GwtExecutable]"
          WorkingDirectory="INSTALLFOLDER"
          Icon="GwtIcon.exe"
          IconIndex="0" />
        <RemoveFolder Id="RemoveApplicationProgramsFolder" Directory="ApplicationProgramsFolder" On="uninstall" />
        <RegistryValue Root="HKCU" Key="Software\GWT" Name="StartMenuShortcut" Type="integer" Value="1" KeyPath="yes" />
      </Component>
    </ComponentGroup>
  </Fragment>
</Wix>
