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

<!--
    Decal Installer - WiX v4/5 MSI package
    Installs all Decal components to Program Files\Decal\
    Registers COM servers, creates registry entries, and sets up shortcuts.
-->

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
    <Package
        Name="Decal"
        Version="2.9.9.0"
        Manufacturer="Decal Open Source Project"
        UpgradeCode="A1B2C3D4-E5F6-7890-ABCD-EF1234567890"
        Scope="perMachine"
        InstallerVersion="200">

        <MajorUpgrade
            DowngradeErrorMessage="A newer version of Decal is already installed."
            AllowSameVersionUpgrades="yes" />

        <MediaTemplate EmbedCab="yes" />

        <!-- Installation directory structure -->
        <StandardDirectory Id="ProgramFilesFolder">
            <Directory Id="INSTALLFOLDER" Name="Decal" />
        </StandardDirectory>

        <!-- Start Menu -->
        <StandardDirectory Id="ProgramMenuFolder">
            <Directory Id="DecalMenuFolder" Name="Decal" />
        </StandardDirectory>

        <!-- Feature: Core (always installed) -->
        <Feature Id="CoreFeature" Title="Decal Core" Level="1" Absent="disallow">
            <ComponentGroupRef Id="ManagedAssemblies" />
            <ComponentGroupRef Id="COMServers" />
            <ComponentGroupRef Id="NativeDLLs" />
            <ComponentGroupRef Id="Executables" />
            <ComponentGroupRef Id="RegistryEntries" />
            <ComponentGroupRef Id="Shortcuts" />
        </Feature>
    </Package>

    <!-- ================================================================ -->
    <!-- Component Groups                                                  -->
    <!-- ================================================================ -->

    <!-- Managed (.NET) Interop Assemblies -->
    <Fragment>
        <ComponentGroup Id="ManagedAssemblies" Directory="INSTALLFOLDER">
            <!-- Interop assemblies (COM interface definitions) -->
            <Component>
                <File Source="$(var.BuildOutput)\Decal.Interop.Core.dll" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\Decal.Interop.Inject.dll" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\Decal.Interop.Controls.dll" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\Decal.Interop.D3DService.dll" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\Decal.Interop.DHS.dll" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\Decal.Interop.Dat.dll" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\Decal.Interop.Filters.dll" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\Decal.Interop.Input.dll" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\Decal.Interop.Net.dll" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\Decal.Interop.Render.dll" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\Decal.Interop.SpellFilter.dll" />
            </Component>

            <!-- Adapter and FileService -->
            <Component>
                <File Source="$(var.BuildOutput)\Decal.Adapter.dll" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\Decal.FileService.dll" />
            </Component>
        </ComponentGroup>
    </Fragment>

    <!-- COM Server DLLs (C# implementations of native DLLs) -->
    <Fragment>
        <ComponentGroup Id="COMServers" Directory="INSTALLFOLDER">
            <Component>
                <File Source="$(var.BuildOutput)\Decal.Core.dll" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\Decal.DecalDat.dll" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\Decal.DHS.dll" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\Decal.SpellFilter.dll" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\Decal.DecalInput.dll" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\Decal.DecalNet.dll" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\Decal.DecalFilters.dll" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\Decal.DecalControls.dll" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\Decal.DecalRender.dll" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\Decal.D3DService.dll" />
            </Component>
        </ComponentGroup>
    </Fragment>

    <!-- Native C++ DLLs -->
    <Fragment>
        <ComponentGroup Id="NativeDLLs" Directory="INSTALLFOLDER">
            <Component>
                <File Source="$(var.NativeOutput)\Inject.DLL" />
            </Component>
            <Component>
                <File Source="$(var.NativeOutput)\LauncherHook.DLL" />
            </Component>
        </ComponentGroup>
    </Fragment>

    <!-- Executables -->
    <Fragment>
        <ComponentGroup Id="Executables" Directory="INSTALLFOLDER">
            <Component>
                <File Id="DenAgentEXE" Source="$(var.BuildOutput)\Decal.DenAgent.exe" Name="DenAgent.EXE" />
            </Component>
            <Component>
                <File Source="$(var.BuildOutput)\DecalUtil.exe" />
            </Component>
        </ComponentGroup>
    </Fragment>

    <!-- Registry entries -->
    <Fragment>
        <ComponentGroup Id="RegistryEntries" Directory="INSTALLFOLDER">
            <Component Id="DecalRegistryBase">
                <RegistryKey Root="HKLM" Key="SOFTWARE\Decal">
                    <RegistryValue Name="Version" Type="string" Value="2.9.9.0" />
                </RegistryKey>
                <RegistryKey Root="HKLM" Key="SOFTWARE\Decal\Agent">
                    <RegistryValue Name="AgentPath" Type="string" Value="[INSTALLFOLDER]" />
                </RegistryKey>
            </Component>

            <!-- Service registrations -->
            <Component Id="DecalServices">
                <RegistryKey Root="HKLM" Key="SOFTWARE\Decal\Services">
                    <!-- Services are registered by their CLSIDs -->
                </RegistryKey>
            </Component>

            <!-- Plugin registrations -->
            <Component Id="DecalPlugins">
                <RegistryKey Root="HKLM" Key="SOFTWARE\Decal\Plugins">
                    <!-- Plugins register themselves at install time -->
                </RegistryKey>
            </Component>
        </ComponentGroup>
    </Fragment>

    <!-- Shortcuts -->
    <Fragment>
        <ComponentGroup Id="Shortcuts" Directory="DecalMenuFolder">
            <Component Id="DenAgentShortcut">
                <Shortcut Id="DenAgentStartMenu"
                          Name="Decal Agent"
                          Target="[INSTALLFOLDER]DenAgent.EXE"
                          WorkingDirectory="INSTALLFOLDER" />
                <RemoveFolder Id="RemoveDecalMenu" On="uninstall" />
                <RegistryValue Root="HKCU" Key="SOFTWARE\Decal" Name="Installed" Type="integer" Value="1" KeyPath="yes" />
            </Component>
        </ComponentGroup>
    </Fragment>
</Wix>
