<?xml version='1.0' encoding='windows-1252'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>

    <!-- Define platform-specific variables based on target architecture -->
    <?if $(sys.BUILDARCH) = x64 or $(sys.BUILDARCH) = arm64 ?>
        <?define Win64 = "yes" ?>
        <?define PlatformProgramFilesFolder = "ProgramFiles64Folder" ?>
    <?else ?>
        <?define Win64 = "no" ?>
        <?define PlatformProgramFilesFolder = "ProgramFilesFolder" ?>
    <?endif ?>

    <Product
        Id='*'
        Name='Rustnet'
        UpgradeCode='455c823b-9665-43e0-baa4-bd0fcb762463'
        Manufacturer='domcyrus'
        Language='1033'
        Codepage='1252'
        Version='$(var.Version)'>

        <Package Id='*'
            Keywords='Installer'
            Description='Rustnet Network Monitor Installer'
            Manufacturer='domcyrus'
            InstallerVersion='500'
            Languages='1033'
            Compressed='yes'
            SummaryCodepage='1252'
            Platform='$(var.Platform)'
            />

        <MajorUpgrade
            DowngradeErrorMessage="A newer version of [ProductName] is already installed."
            Schedule="afterInstallInitialize"
            AllowSameVersionUpgrades="yes" />

        <Media Id='1' Cabinet='rustnet.cab' EmbedCab='yes' DiskPrompt="CD-ROM #1" />
        <Property Id='DiskPrompt' Value="Rustnet Installation [1]" />

        <Directory Id='TARGETDIR' Name='SourceDir'>
            <Directory Id='$(var.PlatformProgramFilesFolder)'>
                <Directory Id='APPLICATIONROOTDIRECTORY' Name='Rustnet'>
                    <Component Id='MainExecutable' Guid='*' Win64='$(var.Win64)'>
                        <File Id='RustnetExe'
                            Name='rustnet.exe'
                            DiskId='1'
                            Source='$(var.CargoTargetBinDir)\rustnet.exe'
                            KeyPath='yes'/>
                        <Environment Id='PATH' Name='PATH' Value='[APPLICATIONROOTDIRECTORY]'
                            Permanent='no' Part='last' Action='set' System='yes' />
                    </Component>
                    <Component Id='AppIcon' Guid='*' Win64='$(var.Win64)'>
                        <File Id='RustnetIco'
                            Name='rustnet.ico'
                            DiskId='1'
                            Source='resources\packaging\windows\graphics\rustnet.ico'/>
                    </Component>
                    <Component Id='AssetsDir' Guid='*' Win64='$(var.Win64)'>
                        <File Id='ServicesFile'
                            Name='services'
                            DiskId='1'
                            Source='assets\services'
                            KeyPath='yes'/>
                    </Component>
                </Directory>
            </Directory>

            <Directory Id="ProgramMenuFolder">
                <Directory Id="ApplicationProgramsFolder" Name="Rustnet">
                    <Component Id="ApplicationShortcut" Guid="*" Win64="$(var.Win64)">
                        <Shortcut Id="ApplicationStartMenuShortcut"
                            Name="Rustnet"
                            Description="Cross-platform network monitoring tool"
                            Target="[APPLICATIONROOTDIRECTORY]rustnet.exe"
                            WorkingDirectory="APPLICATIONROOTDIRECTORY"
                            Icon="rustnet.ico"/>
                        <RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
                        <RegistryValue Root="HKCU" Key="Software\domcyrus\Rustnet" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
                    </Component>
                </Directory>
            </Directory>
        </Directory>

        <Icon Id="rustnet.ico" SourceFile="resources\packaging\windows\graphics\rustnet.ico" />

        <Feature
            Id='Complete'
            Title='Rustnet'
            Description='Complete installation of Rustnet Network Monitor'
            Level='1'
            ConfigurableDirectory='APPLICATIONROOTDIRECTORY'>
            <ComponentRef Id='MainExecutable' />
            <ComponentRef Id='AppIcon' />
            <ComponentRef Id='AssetsDir' />
            <ComponentRef Id='ApplicationShortcut' />
        </Feature>

    </Product>
</Wix>