<?xml version='1.0' encoding='windows-1252'?>

<?if $(sys.BUILDARCH) = x64 or $(sys.BUILDARCH) = intel64 ?>
    <?define PlatformProgramFilesFolder = "ProgramFiles64Folder" ?>
<?else ?>
    <?define PlatformProgramFilesFolder = "ProgramFilesFolder" ?>
<?endif ?>

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

    <Product
        Id='*'
        Name='Cagire'
        UpgradeCode='F2A3D4E5-6B7C-8D9E-0F1A-2B3C4D5E6F7A'
        Manufacturer='Raphael Forment'
        Language='1033'
        Codepage='1252'
        Version='$(var.Version)'>

        <Package Id='*'
            Keywords='Installer'
            Description='Cagire - Forth-based music sequencer'
            Manufacturer='Raphael Forment'
            InstallerVersion='450'
            Languages='1033'
            Compressed='yes'
            InstallScope='perMachine'
            SummaryCodepage='1252'
            />

        <MajorUpgrade
            Schedule='afterInstallInitialize'
            DowngradeErrorMessage='A newer version of [ProductName] is already installed. Setup will now exit.'/>

        <Media Id='1' Cabinet='media1.cab' EmbedCab='yes' DiskPrompt='CD-ROM #1'/>
        <Property Id='DiskPrompt' Value='Cagire Installation'/>

        <Directory Id='TARGETDIR' Name='SourceDir'>
            <Directory Id='$(var.PlatformProgramFilesFolder)' Name='PFiles'>
                <Directory Id='APPLICATIONFOLDER' Name='Cagire'>

                    <Component Id='CagireCLI' Guid='A1B2C3D4-E5F6-7890-ABCD-EF1234567890' Win64='yes'>
                        <File
                            Id='CagireEXE'
                            Name='cagire.exe'
                            DiskId='1'
                            Source='$(var.CargoTargetBinDir)\cagire.exe'
                            KeyPath='yes'/>
                    </Component>

                    <Component Id='CagireDesktop' Guid='B2C3D4E5-F6A7-8901-BCDE-F12345678901' Win64='yes'>
                        <File
                            Id='CagireDesktopEXE'
                            Name='cagire-desktop.exe'
                            DiskId='1'
                            Source='$(var.CargoTargetBinDir)\cagire-desktop.exe'
                            KeyPath='yes'/>
                    </Component>

                    <Component Id='PathEntry' Guid='C3D4E5F6-A7B8-9012-CDEF-123456789012' Win64='yes' KeyPath='yes'>
                        <Environment
                            Id='PATH'
                            Name='PATH'
                            Value='[APPLICATIONFOLDER]'
                            Permanent='no'
                            Part='last'
                            Action='set'
                            System='yes'/>
                    </Component>

                </Directory>
            </Directory>

            <Directory Id='ProgramMenuFolder'>
                <Directory Id='ApplicationProgramsFolder' Name='Cagire'>
                    <Component Id='StartMenuShortcut' Guid='D4E5F6A7-B8C9-0123-DEFA-234567890123' Win64='yes'>
                        <Shortcut
                            Id='CagireDesktopShortcut'
                            Name='Cagire'
                            Description='Forth-based music sequencer'
                            Target='[APPLICATIONFOLDER]cagire-desktop.exe'
                            WorkingDirectory='APPLICATIONFOLDER'
                            Icon='CagireIcon.exe'/>
                        <RemoveFolder Id='CleanUpShortcutFolder' On='uninstall'/>
                        <RegistryValue
                            Root='HKCU'
                            Key='Software\Cagire'
                            Name='installed'
                            Type='integer'
                            Value='1'
                            KeyPath='yes'/>
                    </Component>
                </Directory>
            </Directory>
        </Directory>

        <Feature
            Id='Binaries'
            Title='Application'
            Description='Installs Cagire CLI and Desktop binaries.'
            Level='1'
            ConfigurableDirectory='APPLICATIONFOLDER'
            AllowAdvertise='no'
            Display='expand'
            Absent='disallow'>

            <ComponentRef Id='CagireCLI'/>
            <ComponentRef Id='CagireDesktop'/>

            <Feature
                Id='Environment'
                Title='PATH Environment Variable'
                Description='Add the install location to the PATH system environment variable. This allows the cagire CLI to be called from any location.'
                Level='1'
                Absent='allow'>
                <ComponentRef Id='PathEntry'/>
            </Feature>
        </Feature>

        <Feature
            Id='StartMenu'
            Title='Start Menu Shortcut'
            Description='Add a Cagire shortcut to the Start Menu.'
            Level='1'
            Absent='allow'>
            <ComponentRef Id='StartMenuShortcut'/>
        </Feature>

        <SetProperty Id='ARPINSTALLLOCATION' Value='[APPLICATIONFOLDER]' After='CostFinalize'/>

        <Icon Id='CagireIcon.exe' SourceFile='assets\Cagire.ico'/>
        <Property Id='ARPPRODUCTICON' Value='CagireIcon.exe'/>
        <Property Id='ARPHELPLINK' Value='https://cagire.raphaelforment.fr'/>
        <Property Id='ARPURLINFOABOUT' Value='https://github.com/Bubobubobubobubo/cagire'/>

        <UI>
            <UIRef Id='WixUI_FeatureTree'/>
            <Publish Dialog='WelcomeDlg' Control='Next' Event='NewDialog' Value='CustomizeDlg' Order='99'>1</Publish>
            <Publish Dialog='CustomizeDlg' Control='Back' Event='NewDialog' Value='WelcomeDlg' Order='99'>1</Publish>
        </UI>

        <WixVariable Id='WixUILicenseRtf' Value='wix\License.rtf'/>

    </Product>

</Wix>
