<!-- This file is based on cargo-wix -->

<!--
	Copyright (C) 2017 Christopher R. Field.

	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-->

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui">

	<Package Name="fend" UpgradeCode="2E3C8164-E07C-4B26-82B2-C5613FE8AD8F" Manufacturer="printfn"
		Language="1033" Codepage="0" Version="$(var.Version)" InstallerVersion="450">
		<SummaryInformation Keywords="Installer"
			Description="Arbitrary-precision unit-aware calculator" Manufacturer="printfn" />

		<!--
			Same-version upgrades need to be allowed, otherwise fend will get installed multiple
				times when installing MSIs with identical version numbers, such as different CI builds.
			See https://wixtoolset.org/docs/schema/wxs/majorupgrade/ for more info.
		-->
		<MajorUpgrade Schedule="afterInstallInitialize" AllowSameVersionUpgrades="yes"
			DowngradeErrorMessage="A newer version of [ProductName] is already installed. Setup will now exit." />

		<Property Id="APPLICATIONFOLDER" Secure="yes">
			<RegistrySearch Id="FindInstallLocation" Root="HKCU" Key="Software\fend"
				Name="InstallationPath" Type="raw" />
		</Property>

		<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" DiskPrompt="CD-ROM #1" />
		<Property Id="DiskPrompt" Value="fend Installation" />


		<Feature Id="Binaries" Title="Application" Description="Installs fend." Level="1"
			ConfigurableDirectory="APPLICATIONFOLDER" AllowAdvertise="no" Display="expand"
			AllowAbsent="no">

			<ComponentRef Id="License" />
			<ComponentRef Id="binary0" />
			<ComponentRef Id="ApplicationShortcut" />

			<Feature Id="Environment" Title="PATH Environment Variable"
				Description="Add the install location of the [ProductName] executable to the PATH system environment variable. This allows the [ProductName] executable to be called from any location."
				Level="1">
				<ComponentRef Id="Path" />
			</Feature>


			<Feature Id="DesktopShortcut" Title="Add a Desktop shortcut"
				Description="Creates a shortcut on your desktop for easier access." Level="1">
				<ComponentRef Id="ApplicationShortcutDesktop" />
			</Feature>
		</Feature>

		<SetProperty Id="ARPINSTALLLOCATION" Value="[APPLICATIONFOLDER]" After="CostFinalize" />

		<Icon Id="ProductICO" SourceFile="$(var.IconPath)" />
		<Property Id="ARPPRODUCTICON" Value="ProductICO" />

		<Property Id="ARPHELPLINK" Value="https://github.com/printfn/fend" />

		<Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Launch fend" />

		<UI>
			<ui:WixUI Id="WixUI_FeatureTree" />
			<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="CustomizeDlg"
				Order="99" />
			<Publish Dialog="CustomizeDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg"
				Order="99" />
			<Publish Dialog="ExitDialog" Control="Finish" Event="DoAction" Value="LaunchApplication"
				Condition="WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed" />
		</UI>

		<Property Id="WixShellExecTarget" Value="[#fend.exe]" />
		<CustomAction Id="LaunchApplication" DllEntry="WixShellExec" Impersonate="yes"
			BinaryRef="Wix4UtilCA_X86" />

		<StandardDirectory Id="ProgramMenuFolder">
			<!-- Create shortcut to start fend from the taskbar -->
			<Directory Id="ApplicationProgramsFolder" Name="fend">
				<Component Id="ApplicationShortcut" Guid="{15F35903-1FBC-47C0-852D-BFC51D428385}">
					<Shortcut Id="ApplicationStartMenuShortcut" Name="fend"
						Description="Arbitrary-precision unit-aware calculator" Target="[!fend.exe]"
						WorkingDirectory="APPLICATIONFOLDER" />
					<RemoveFolder Id="CleanUpShortCut" Directory="ApplicationProgramsFolder"
						On="uninstall" />
					<RegistryValue Root="HKCU" Key="Software\fend" Name="installed" Type="integer"
						Value="1" KeyPath="yes" />
					<!-- make upgrading easier by remembering where it was installed -->
					<RegistryValue Root="HKCU" Key="Software\fend" Name="InstallationPath"
						Type="string" Value="[APPLICATIONFOLDER]" />
				</Component>
			</Directory>
		</StandardDirectory>

		<StandardDirectory Id="ProgramFiles6432Folder">
			<Directory Id="APPLICATIONFOLDER" Name="fend">
				<Component Id="License">
					<File Id="LicenseFile" Name="LICENSE.md" DiskId="1"
						Source="$(var.LicenseMdPath)" KeyPath="yes" />
				</Component>
				<Directory Id="Bin" Name="bin">
					<Component Id="Path" Guid="CDEF645B-899B-4FB5-B932-70DDF60C1D24" KeyPath="yes">
						<Environment Id="PATH" Name="PATH" Value="[Bin]" Permanent="no" Part="last"
							Action="set" System="yes" />
					</Component>
					<Component Id="binary0">
						<File Id="fend.exe" Name="fend.exe" DiskId="1" Source="$(var.FendExePath)"
							KeyPath="yes" />
					</Component>
				</Directory>
			</Directory>
		</StandardDirectory>

		<StandardDirectory Id="DesktopFolder">
			<!-- Create shortcut to start fend from the desktop -->
			<Component Id="ApplicationShortcutDesktop" Guid="6EC22391-82AE-4394-BD05-6930293265EA">
				<Shortcut Id="ApplicationDesktopShortcut" Name="fend"
					Description="Arbitrary-precision unit-aware calculator" Target="[!fend.exe]"
					WorkingDirectory="APPLICATIONFOLDER" />
				<RemoveFolder Id="CleanUpDesktopShortcut" On="uninstall" />
				<RegistryValue Root="HKCU" Key="Software\fend" Name="DesktopShortcut" Type="integer"
					Value="1" KeyPath="yes" />
			</Component>
		</StandardDirectory>
	</Package>

</Wix>
