<?xml version="1.0" encoding="UTF-8"?>
<!--
    Dragon-ISO — MSI installer (WiX v5)

    Produces: Dragon-ISO-Setup-<Version>.msi (per-machine install).

    Build:
        dotnet publish src/Dragon-ISO.App/Dragon-ISO.App.csproj -c Release -r win-x64 -p:SelfContained=false -o publish/Dragon-ISO
        dotnet build installer/Dragon-ISO.Installer.wixproj -c Release

    Runtime expectations:
        - .NET 8 Desktop runtime present on target (framework-dependent build)
        - NDI 6 Runtime present — checked in NdiRuntimeDirV6Search; absence WARNS
          but does not block install (operators can install NDI after the app)

    Exe filename note:
        Dragon-ISO.App.csproj sets AssemblyName=DragonISO (no hyphen — CLR
        assembly names cannot contain hyphens). The published executable is
        therefore DragonISO.exe. Shortcut targets reference DragonISO.exe.
-->
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
     xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui">

  <Package Name="Dragon-ISO"
           Manufacturer="Wild Dragon LLC"
           Version="$(var.ProductVersion)"
           UpgradeCode="9F4A8B2C-1D3E-4A5B-9C6D-8E7F0A1B2C3D"
           Scope="perMachine"
           Compressed="yes"
           InstallerVersion="500">

    <!--
        SummaryInformation fields surface in File Explorer's "Details" tab and
        in the Windows Installer "About" dialog. Description and Keywords are
        what users see if they right-click the MSI before installing; Comments
        is the longer copy that appears alongside the version in some
        installer dialogs.
    -->
    <SummaryInformation
        Description="Dragon-ISO — per-participant NDI ISO controller for Microsoft Teams. Splits each Teams participant into a normalized NDI source for vMix / OBS / Ross / hardware switchers."
        Manufacturer="Wild Dragon LLC"
        Keywords="Dragon-ISO, NDI, Microsoft Teams, ISO recording, broadcast, live production, vMix, OBS, switcher, Wild Dragon" />

    <!--
        MajorUpgrade: a newer install replaces an older one in-place. We
        disallow downgrades because the engine config schema only carries a
        forward-migration path; downgrading would leave operators with a
        config the older binary doesn't understand.
    -->
    <!--
        Embed cab1.cab directly in the MSI so the installer is a single
        self-contained file. Without this, WiX produces an external cab1.cab
        alongside the MSI; distributing only the MSI breaks installation
        (Windows Installer error 1302 — disk not found).
    -->
    <MediaTemplate EmbedCab="yes" />

    <MajorUpgrade DowngradeErrorMessage="A newer version of Dragon-ISO is already installed. Uninstall it before installing this older version."
                  Schedule="afterInstallInitialize" />

    <!--
        Single MSI feature; users see only the install/uninstall screens.
    -->
    <Feature Id="Main" Title="Dragon-ISO" Level="1">
      <ComponentGroupRef Id="ApplicationFiles" />
      <ComponentGroupRef Id="Shortcuts" />
      <ComponentGroupRef Id="DesktopShortcut" />
      <ComponentGroupRef Id="ArpEntry" />
    </Feature>

    <!--
        Minimal install UI: Welcome/License -> Progress -> Finish.
        No directory picker; installs to Program Files\Wild Dragon\Dragon-ISO.
    -->
    <ui:WixUI Id="WixUI_Minimal" />

    <!--
        Add/Remove Programs metadata. ARPHELPLINK is the "Help" link; ARPURLINFOABOUT
        is the manufacturer/about link; ARPCONTACT is the support contact shown
        when the user clicks "Support information" from the ARP entry. ARPCOMMENTS
        is the long description displayed in some Settings -> Apps surfaces.
    -->
    <Property Id="ARPHELPLINK" Value="https://forge.wilddragon.net/WildDragonLLC/dragon-iso" />
    <Property Id="ARPURLINFOABOUT" Value="https://wilddragon.net" />
    <Property Id="ARPCONTACT" Value="Wild Dragon LLC — support@wilddragon.net" />
    <Property Id="ARPCOMMENTS" Value="Dragon-ISO turns Microsoft Teams' raw NDI broadcast into clean, normalized, per-participant NDI sources for ingestion by a live-production switcher (vMix, OBS, Ross, hardware capture). Each participant gets an individually-addressable source with configurable framerate, resolution, aspect mode, and audio routing." />
    <!-- ARPNOMODIFY is set by WixUI_Minimal. Do not redeclare. -->
    <Property Id="ARPNOREPAIR" Value="1" />

    <!--
        ARP icon: references the same .ico the WPF host uses. WiX requires the
        icon resource to live next to the wxs OR be reachable at build time;
        we point at the source copy under src/Dragon-ISO.App/Assets so the icon
        embedded in the MSI matches the icon in the running exe.
    -->
    <Icon Id="DragonISOIcon" SourceFile="$(var.AssetsDir)Dragon-ISO.ico" />
    <Property Id="ARPPRODUCTICON" Value="DragonISOIcon" />

    <!--
        .NET 8 Desktop Runtime detection. The .NET apphost will surface a
        "framework not found" dialog naturally if the runtime is absent;
        this property is available for future conditional logic.
        VBScript-based install-time dialogs are deprecated in WiX v5 / Windows;
        rewriting in C++ is overkill for a soft warning on a soft dependency.
    -->
    <Property Id="DOTNET8DESKTOPRUNTIME" Value="0">
      <RegistrySearch Id="DotNet8DesktopRuntimeSearch"
                      Root="HKLM"
                      Key="SOFTWARE\dotnet\Setup\InstalledVersions\x64\sharedfx\Microsoft.WindowsDesktop.App\8.0.0"
                      Name="Version"
                      Type="raw" />
    </Property>

    <!--
        NDI Runtime detection. We check for NDI_RUNTIME_DIR_V6 in the system
        environment block. Missing -> warn during install, don't block. The
        engine surfaces a clear MessageBox with an install-NDI link at first
        launch if the runtime really isn't there.
    -->
    <Property Id="NDIRUNTIMEDIR" Value="0">
      <RegistrySearch Id="NdiRuntimeDirV6Search"
                      Root="HKLM"
                      Key="SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
                      Name="NDI_RUNTIME_DIR_V6"
                      Type="raw" />
    </Property>

    <!--
        NDI runtime detection is surfaced at first app launch (App.xaml.cs pops a
        MessageBox with an install link). We deliberately don't block install on
        a missing runtime so admins can stage the app before NDI is rolled out.
        VBScript-based install-time prompts are deprecated in WiX v5 / Windows
        and rewriting in C++ is overkill for a soft warning.
    -->

    <!--
        Install layout under Program Files\Wild Dragon\Dragon-ISO.
    -->
    <StandardDirectory Id="ProgramFiles64Folder">
      <Directory Id="ManufacturerFolder" Name="Wild Dragon">
        <Directory Id="INSTALLFOLDER" Name="Dragon-ISO" />
      </Directory>
    </StandardDirectory>

    <StandardDirectory Id="ProgramMenuFolder">
      <Directory Id="WildDragonStartMenuFolder" Name="Wild Dragon" />
    </StandardDirectory>

    <!--
        Files: harvested from the publish output dir at build time.
        WiX v5 understands <Files Include="..."> with glob patterns and
        synthesizes one Component per file with stable GUIDs.
    -->
    <ComponentGroup Id="ApplicationFiles" Directory="INSTALLFOLDER">
      <Files Include="$(var.PublishDir)**" />
    </ComponentGroup>

    <!--
        Start Menu and Desktop shortcuts: direct .exe targets.

        Don't wrap the Target in runas.exe /trustlevel:0x20000 (or anything
        else that demotes the spawned process). The SAFER-restricted token
        breaks .NET 8 WPF apphost startup: the process appears alive with
        a window, but no managed code past BAML parse executes. Verified
        empirically 2026-05-16; letting Dragon-ISO inherit the launching
        token (medium or high integrity, doesn't matter) is the correct
        behavior. NDI discovery works fine at either integrity level.

        Exe filename: AssemblyName=DragonISO (no hyphen), so target is
        DragonISO.exe not Dragon-ISO.exe.
    -->
    <ComponentGroup Id="Shortcuts" Directory="WildDragonStartMenuFolder">
      <Component Id="StartMenuShortcut" Guid="*">
        <Shortcut Id="StartMenuDragonISO"
                  Name="Dragon-ISO"
                  Description="Per-Participant NDI ISO Controller for Microsoft Teams"
                  Target="[INSTALLFOLDER]DragonISO.exe"
                  WorkingDirectory="INSTALLFOLDER"
                  Icon="DragonISOIcon" />
        <!-- Required by ICE64: Start Menu folder must be cleaned on uninstall. -->
        <RemoveFolder Id="RemoveWildDragonStartMenuFolder"
                      Directory="WildDragonStartMenuFolder"
                      On="uninstall" />
        <RegistryValue Root="HKCU"
                       Key="Software\Wild Dragon\Dragon-ISO"
                       Name="StartMenuShortcut"
                       Type="integer"
                       Value="1"
                       KeyPath="yes" />
      </Component>
    </ComponentGroup>

    <StandardDirectory Id="DesktopFolder" />
    <ComponentGroup Id="DesktopShortcut" Directory="DesktopFolder">
      <Component Id="DesktopShortcutComponent" Guid="*">
        <Shortcut Id="DesktopDragonISO"
                  Name="Dragon-ISO"
                  Description="Per-Participant NDI ISO Controller for Microsoft Teams"
                  Target="[INSTALLFOLDER]DragonISO.exe"
                  WorkingDirectory="INSTALLFOLDER"
                  Icon="DragonISOIcon" />
        <RegistryValue Root="HKCU"
                       Key="Software\Wild Dragon\Dragon-ISO"
                       Name="DesktopShortcut"
                       Type="integer"
                       Value="1"
                       KeyPath="yes" />
      </Component>
    </ComponentGroup>

    <!--
        ARP icon registry entry. Optional: the MSI auto-fills most ARP
        fields from the Package element. We only need to store the install
        path for diagnostic / uninstall tooling.
    -->
    <ComponentGroup Id="ArpEntry" Directory="INSTALLFOLDER">
      <Component Id="ArpIconRegistry" Guid="*">
        <RegistryValue Root="HKLM"
                       Key="Software\Wild Dragon\Dragon-ISO"
                       Name="InstallPath"
                       Type="string"
                       Value="[INSTALLFOLDER]"
                       KeyPath="yes" />
      </Component>
    </ComponentGroup>

  </Package>
</Wix>