<?xml version='1.0' encoding='utf-8'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"
>		

		<Product Name='{app}' Id='*' UpgradeCode='{upgrade_code}'
				Language='1033' Codepage='1252' Version='{version}' Manufacturer='Kovid Goyal'>
				
				<Package Id='*' Keywords='Installer' Description="{app} Installer"
						Comments='{app} is a registered trademark of Kovid Goyal' Manufacturer='Kovid Goyal'
						InstallerVersion='300' Languages='1033' Compressed='yes'
						SummaryCodepage='1252' />

                <Media Id="1" Cabinet="{app}.cab" CompressionLevel="{compression}" EmbedCab="yes" />
                
                <Upgrade Id="{upgrade_code}">
                    <UpgradeVersion Maximum="{version}"
                       IncludeMaximum="yes"
                       OnlyDetect="no"
                       Language="1033"
                       Property="OLDPRODUCTFOUND"/>
                    <UpgradeVersion Minimum="{version}"
                       IncludeMinimum="no"
                       OnlyDetect="yes"
                       Language="1033"
                       Property="NEWPRODUCTFOUND"/>
               </Upgrade>
               <CustomAction Id="PreventDowngrading" Error="Newer version already installed."/>

                <Directory Id='TARGETDIR' Name='SourceDir'>
                        <Merge Id="VCRedist" SourceFile="{crt_msm}" DiskId="1" Language="0"/>
						<Directory Id='ProgramFilesFolder' Name='PFiles'>
								<Directory Id='APPLICATIONFOLDER' Name='{app}' />
						</Directory>
                        <Directory Id="ProgramMenuFolder">
                            <Directory Id="ApplicationProgramsFolder" Name="{app} - E-book Management"/>
                        </Directory>
                        <Directory Id="DesktopFolder" Name="Desktop"/>
				</Directory>

				<DirectoryRef Id="APPLICATIONFOLDER">
						{app_components}
                        <Component Id="AddToPath" Guid="*">
                            <Environment Id='UpdatePath' Name='PATH' Action='set' System='yes' Part='last' Value='[APPLICATIONFOLDER]' />
                            <RegistryValue Root="HKCU" Key="Software\Microsoft\{app}" Name="system_path_updated" Type="integer" Value="1" KeyPath="yes"/>
                        </Component>
                </DirectoryRef>

                <DirectoryRef Id="ApplicationProgramsFolder">
                    <Component Id="StartMenuShortcuts" Guid="*">
                        <Shortcut Id="s1" Name="{app} - E-book management"
                            Description="Manage your e-book collection and download news"
                            Target="[#{exe_map[calibre]}]"
                             WorkingDirectory="APPLICATIONROOTDIRECTORY" />
                        <Shortcut Id="s2" Name="E-book viewer"
                            Description="Viewer for all the major e-book formats"
                            Target="[#{exe_map[ebook-viewer]}]"
                             WorkingDirectory="APPLICATIONROOTDIRECTORY" />
                        <Shortcut Id="s3" Name="LRF viewer"
                            Description="Viewer for LRF format e-books"
                            Target="[#{exe_map[lrfviewer]}]"
                             WorkingDirectory="APPLICATIONROOTDIRECTORY" />
                        <util:InternetShortcut Id="OnlineDocumentationShortcut"
                            Name="User Manual" Type="url"
                               Target="http://calibre-ebook.com/user_manual"/>
                        <util:InternetShortcut Id="GetInvolvedS"
                            Name="Get Involved" Type="url"
                            Target="http://calibre-ebook.com/get-involved"/>

                        <RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
                        <RegistryValue Root="HKCU" Key="Software\Microsoft\{app}" Name="start_menu_shortcuts_installed" Type="integer" Value="1" KeyPath="yes"/>
                    </Component>
                </DirectoryRef>

                <DirectoryRef Id="DesktopFolder">
                    <Component Id="DesktopShortcut" Guid="*">
                        <Shortcut Id="ds1" Name="{app} - E-book management"
                            Description="Manage your e-book collection and download news"
                            Target="[#{exe_map[calibre]}]"
                            WorkingDirectory="APPLICATIONROOTDIRECTORY" />
                        <RegistryValue Root="HKCU" Key="Software\Microsoft\{app}" Name="desktop_shortcut_installed" Type="integer" Value="1" KeyPath="yes"/>
                    </Component> 
                </DirectoryRef>
         


				<Feature Id="Complete" Title="{app}" Display="expand" Level="1"
						ConfigurableDirectory="APPLICATIONFOLDER">

						<Feature Id="MainApplication" Title="Program Files" Level="1"
                            Description="All the files need to run {app}" Absent="disallow">
                        </Feature>

                        <Feature Id="VCRedist" Title="Visual C++ 8.0 Runtime" AllowAdvertise="no" Display="hidden" Level="1">
                            <MergeRef Id="VCRedist"/>
                        </Feature>

                        <Feature Id="FSMS" Title="Start menu shortcuts" Level="1"
                            Description="Program shortcuts installed in the Start Menu">
                            <ComponentRef Id="StartMenuShortcuts"/>
                        </Feature>

                        <Feature Id="DS" Title="Shortcut on desktop" Level="1"
                            Description="Shortcut to {app} on your desktop">
                            <ComponentRef Id="DesktopShortcut"/>
                        </Feature>

                        <Feature Id="FAddToPath" Title="Add install directory to path" Level="1"
                            Description="Add installation directory to PATH. Makes using command line tools easier">
                            <ComponentRef Id="AddToPath"/>
                        </Feature>
				</Feature>

				<!-- Add icon to entry in Add/Remove programs -->
                <Icon Id="main_icon" SourceFile="{main_icon}"/>
				<Property Id="ARPPRODUCTICON" Value="main_icon" />

                <Condition
                    Message="This application is only supported on Windows XP SP2, or higher.">
                    <![CDATA[Installed OR (VersionNT >= 501)]]>
                </Condition>
                <InstallExecuteSequence>
                    <Custom Action="PreventDowngrading" After="FindRelatedProducts">NEWPRODUCTFOUND</Custom>
                    <RemoveExistingProducts After="InstallFinalize" />
                </InstallExecuteSequence>
                <InstallUISequence>
                    <Custom Action="PreventDowngrading" After="FindRelatedProducts">NEWPRODUCTFOUND</Custom>
                </InstallUISequence>

                <UI>
                    <UIRef Id="WixUI_Advanced" />
                    <Publish Dialog="ExitDialog"
                        Control="Finish" 
                        Event="DoAction" 
                        Value="LaunchApplication">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish>

                </UI>

                <!-- 
                Set default folder name and allow only per machine installs.
                For a per-machine installation, the default installation location
                will be [ProgramFilesFolder][ApplicationFolderName] and the user
                will be able to change it in the setup UI. This is because the installer
                has to install the VC90 merge module into the system winsxs folder for python
                to work, so per user installs are impossible anyway.
                -->
                <Property Id="ApplicationFolderName" Value="Calibre2" />
                <Property Id="WixAppFolder" Value="WixPerMachineFolder" />
                <WixVariable Id="WixUISupportPerUser" Value="0" />

                <!-- Add option to launch calibre after install -->
                <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Launch {app}" />
                <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOX" Value="1"/>
                <Property Id="WixShellExecTarget" Value="[#{exe_map[calibre]}]" />
                <CustomAction Id="LaunchApplication" BinaryKey="WixCA"
                    DllEntry="WixShellExec" Impersonate="yes"/>

                <InstallUISequence>
                    <FileCost Suppress="yes" />
                </InstallUISequence>

		</Product>
</Wix>



