<Wix
	xmlns="http://wixtoolset.org/schemas/v4/wxs">
	<Package Name="NetBird" Version="$(env.NETBIRD_VERSION)" Manufacturer="Wiretrustee UG (haftungsbeschreankt)" Language="1033" UpgradeCode="6456ec4e-3ad6-4b9b-a2be-98e81cb21ccf"
        InstallerVersion="500" Compressed="yes"  Codepage="utf-8" >

		<MediaTemplate EmbedCab="yes" />

		<Feature Id="NetbirdFeature" Title="Netbird" Level="1">
			<ComponentGroupRef Id="NetbirdFilesComponent" />
		</Feature>

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

		<StandardDirectory Id="ProgramFiles64Folder">
			<Directory Id="NetbirdInstallDir" Name="Netbird">
				<Component Id="NetbirdFiles" Guid="db3165de-cc6e-4922-8396-9d892950e23e" Bitness="always64">
					<File ProcessorArchitecture="x64" Source=".\dist\netbird_windows_amd64\netbird.exe" KeyPath="yes" />
					<File ProcessorArchitecture="x64" Source=".\dist\netbird_windows_amd64\netbird-ui.exe">
						<Shortcut Id="NetbirdDesktopShortcut" Directory="DesktopFolder" Name="NetBird" WorkingDirectory="NetbirdInstallDir" Icon="NetbirdIcon" />
						<Shortcut Id="NetbirdStartMenuShortcut" Directory="StartMenuFolder" Name="NetBird" WorkingDirectory="NetbirdInstallDir" Icon="NetbirdIcon" />
					</File>
					<File ProcessorArchitecture="x64" Source=".\dist\netbird_windows_amd64\wintun.dll" />

					<ServiceInstall
                                     Id="NetBirdService"
                                     Name="NetBird"
                                     DisplayName="NetBird"
                                     Description="A WireGuard-based mesh network that connects your devices into a single private network."
                                     Start="auto" Type="ownProcess"
                                     ErrorControl="normal"
                                     Account="LocalSystem"
                                     Vital="yes"
                                     Interactive="no"
                                     Arguments='service run config [CommonAppDataFolder]Netbird\config.json log-level info'
                        />
					<ServiceControl Id="NetBirdService" Name="NetBird" Start="install" Stop="both" Remove="uninstall" Wait="yes" />

					<Environment Id="UpdatePath" Name="PATH" Value="[NetbirdInstallDir]" Part="last" Action="set" System="yes" />

				</Component>
			</Directory>
		</StandardDirectory>

		<ComponentGroup Id="NetbirdFilesComponent">
			<ComponentRef Id="NetbirdFiles" />
		</ComponentGroup>

		<Property Id="cmd" Value="cmd.exe"/>

		<CustomAction Id="KillDaemon"
                      ExeCommand='/c "taskkill /im netbird.exe"'
                      Execute="deferred"
                      Property="cmd"
                      Impersonate="no"
                      Return="ignore"
            />

		<CustomAction Id="KillUI"
                      ExeCommand='/c "taskkill /im netbird-ui.exe"'
                      Execute="deferred"
                      Property="cmd"
                      Impersonate="no"
                      Return="ignore"
            />

		<InstallExecuteSequence>
			<!-- For Uninstallation -->
			<Custom Action="KillDaemon" Before="RemoveFiles" Condition="Installed"/>
			<Custom Action="KillUI" After="KillDaemon" Condition="Installed"/>
		</InstallExecuteSequence>

		<!-- Icons -->
		<Icon Id="NetbirdIcon" SourceFile=".\client\ui\netbird.ico" />
		<Property Id="ARPPRODUCTICON" Value="NetbirdIcon" />

	</Package>
</Wix>