<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" UpgradeCode="*"
    Version="$(var.ProductVersion)" Language="1033" Name="Tachidesk Server" Manufacturer="Suwayomi">
    <Package InstallerVersion="300" Compressed="yes" />
    <Media Id="1" Cabinet="Tachidesk_Server.cab" EmbedCab="yes" />

    <!-- Directory -->
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLDIR" Name="Tachidesk-Server" >
          <Directory Id="jre"/>
          <Directory Id="electron"/>
        </Directory>
      </Directory>
      <Directory Id="ProgramMenuFolder">
        <Directory Id="ProgramMenuDir" Name="Tachidesk-Server">
          <Component Id="ProgramMenuDir" Guid="*">
            <RemoveFolder Id="ProgramMenuDir" On="uninstall"/>
            <RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value="" KeyPath="yes"/>
          </Component>
        </Directory>
      </Directory>
      <Directory Id="DesktopFolder" />
    </Directory>

    <!-- Component -->
    <DirectoryRef Id="INSTALLDIR">
      <Component Id="TachideskJAR" Guid="*">
          <File Id="Tachidesk-Server.jar" Source="$(var.SourceDir)/Tachidesk-Server.jar" KeyPath="yes" />
      </Component>

      <Component Id="TachideskBrowserBAT" Guid="*">
        <File Id="TachideskBrowser.bat" Source="$(var.SourceDir)/Tachidesk Browser Launcher.bat" KeyPath="yes" >
          <Shortcut Id="TachideskBrowser.lnk" Name="Tachidesk Browser" Directory="INSTALLDIR"
            WorkingDirectory="INSTALLDIR" Icon="Tachidesk.ico" IconIndex="0" Advertise="yes" />
          <Shortcut Id="DesktopTachideskBrowser.lnk" Name="Tachidesk Browser" Directory="DesktopFolder"
            WorkingDirectory="INSTALLDIR" Icon="Tachidesk.ico" IconIndex="0" Advertise="yes" />
          <Shortcut Id="ProgramMenuTachideskBrowser.lnk" Name="Tachidesk Browser" Directory="ProgramMenuDir"
            WorkingDirectory="INSTALLDIR" Icon="Tachidesk.ico" IconIndex="0" Advertise="yes"
            Description="A free and open source manga reader that runs extensions built for Tachiyomi." />
        </File>
      </Component>

      <Component Id="TachideskDebugBAT" Guid="*">
        <File Id="TachideskDebug.bat" Source="$(var.SourceDir)/Tachidesk Debug Launcher.bat" KeyPath="yes">
          <Shortcut Id="TachideskDebug.lnk" Name="Tachidesk Debug" Directory="INSTALLDIR"
            WorkingDirectory="INSTALLDIR" Icon="Tachidesk.ico" IconIndex="0" Advertise="yes" />
          <Shortcut Id="ProgramMenuTachideskDebug.lnk" Name="Tachidesk Debug" Directory="ProgramMenuDir"
            WorkingDirectory="INSTALLDIR" Icon="Tachidesk.ico" IconIndex="0" Advertise="yes"
            Description="Launches Tachidesk with debug logs attached. If Tachidesk doesn't work for you, running this can give you insight into why." />
        </File>
      </Component>

      <Component Id="TachideskElectronBAT" Guid="*">
        <File Id="TachideskElectron.bat" Source="$(var.SourceDir)/Tachidesk Electron Launcher.bat" KeyPath="yes">
          <Shortcut Id="TachideskElectron.lnk" Name="Tachidesk Electron" Directory="INSTALLDIR"
            WorkingDirectory="INSTALLDIR" Icon="Tachidesk.ico" IconIndex="0" Advertise="yes" />
          <Shortcut Id="DesktopTachideskElectron.lnk" Name="Tachidesk Electron" Directory="DesktopFolder"
            WorkingDirectory="INSTALLDIR" Icon="Tachidesk.ico" IconIndex="0" Advertise="yes" />
          <Shortcut Id="ProgramMenuTachideskElectron.lnk" Name="Tachidesk Electron" Directory="ProgramMenuDir"
            WorkingDirectory="INSTALLDIR" Icon="Tachidesk.ico" IconIndex="0" Advertise="yes"
            Description="Launches Tachidesk inside Electron as a desktop applicaton." />
        </File>
      </Component>
    </DirectoryRef>

    <!-- Feature -->
    <Feature Id="Tachidesk_Server" Title="Tachidesk-Server" Level="1">
      <ComponentGroupRef Id="jre" />
      <ComponentRef Id="TachideskJAR" />
      <ComponentRef Id="TachideskBrowserBAT" />
      <ComponentRef Id="TachideskDebugBAT" />
      <ComponentRef Id="ProgramMenuDir" />
      <ComponentGroupRef Id="electron" />
      <ComponentRef Id="TachideskElectronBAT" />
    </Feature>

    <Icon Id="Tachidesk.ico" SourceFile="$(var.Icon)" />
    <Property Id="ARPPRODUCTICON" Value="Tachidesk.ico" /> <!-- Icon in Add/Remove Programs -->
  </Product>
</Wix>
