简体   繁体   中英

Wix repair installs in default path, not where the app is installed

I have this property:

<Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER"/>

My directories:

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="LocalAppDataFolder">
    <Directory Id="LocalAppDataCompany" Name="Company">
      <Directory Id="INSTALLFOLDER" Name="Product" />
    </Directory>
  </Directory>
</Directory>

And it compiles successfully. When I run the .msi, it installs the files in C:\\Users\\[CurrentUser]\\AppData\\Local\\Company\\Product as expected.

But the problem is:

  1. I run the installer and change the path (let's say in the dialog, i changed the path to Product2
  2. The product is installed in ...\\AppData\\Local\\Company\\Product2 successfully
  3. I run the installer again, and chose repair
  4. Now I have 2 instance of product:

C:\\Users\\[CurrentUser]\\AppData\\Local\\Company\\Product C:\\Users\\[CurrentUser]\\AppData\\Local\\Company\\Product2

How can I fix the repair, to reinstall files (during repair) in the ...\\AppData\\Local\\Company\\Product2 (or wherever the app is installed originally)?

I have tried using registry search (since I am saving the value of INSTALLFOLDER in the registry), but it is not working.

EDIT: Wow I really need to read the complete question before answering. Just noticed you were storing this value in the registry. I'll still leave my answer as is though since it might be useful.


You'll need to implement a remember me pattern so that your install can pickup properties that may have been modified during the initial install. The install dir is probably the most frequently modified property that you should remember. There are a lot of installers that don't do this right and you'll notice if you are upgrading they always default to the default install dir not where you previously installed which can be annoying.

This explains rather well the concept of the "remember me" pattern. You can get away with the simple implementation in the majority of cases.

The gist is that you need to store the value of the altered install dir (generally in the registry) and then try to pick it up every time you run the installer subsequently.

For the INSTALLFOLDER property you'll want to just add two things, a registry search and a registry key.

First we need to add a new component with a registrykey to write the INSTALLFOLDER's value to the registry

<Component Id="InstallFolderRegistry" Directory='INSTALLFOLDER'>
  <RegistryValue Root='HKCU' Key='SOFTWARE\[Manufacturer]\[ProductName]'
                 Name='InstallFolder' Value='[INSTALLFOLDER]'
                 Type='string' KeyPath="yes" />    
</Component>

You can also piggyback this registry value into another component if you wish just remove "KeyPath="yes"".

This will put the value of the INSTALLFOLDER property in the registry during install time.

Now we need to try and read this value if it exists on startup so that during upgrades or during repairs we will get the right location the user chose to install.

<Property Id='INSTALLFOLDER'>
  <RegistrySearch Id='InstallFolderRegSearch' Root='HKCU'
                  Key='SOFTWARE\[Manufacturer]\[ProductName]'
                  Name='InstallFolder' Type='raw' />
</Property>

Now when you repair the installer should find this registry key and then repair the correct directory. Also during upgrades, the install location will be set to the same location as the currently installed product.

To note, if you have a non-static ProductName or Manufacturer you can just put in static text instead of "[Manufacturer]" and "[ProductName]" in the registry path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM