Reputation: 674
I would like to give the user the option to delete the configuration data stored in the APPDATA folder on uninstall. I have found this answer but it's quite old. There is another answer in this mailing list but it's even older.
Is there a new way of doing this?
Upvotes: 1
Views: 313
Reputation: 29
Thank you 'jav'. For me, I found it somewhat difficult to understand, so I'd like to provide some additional explanation regarding 'jav's' solution.
I'll explain the essential elements based on Wix 5.0.
After adding the Wix 5.0 project, a wixproj file will be created. It starts with:
<Project Sdk="WixToolset.Sdk/5.0.1">
and contains MSBuild code.
To use the util:RemoveFolderEx attribute in the next step, it's essential to include the following property in the test.wixproj file:
<ItemGroup>
<PackageReference Include="WixToolset.Util.wixext" Version="5.0.1" />
</ItemGroup>
This step involves creating a Fragment element to contain folder information in a .wxs file. This file will create information for the Component Ref of the Feature property within the Package element in the next step.
The top of the file should look like this:
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
There only one element. The element will contain and the content you, 'jav', wrote earlier. Regarding the "remembered" content, it can be simplified as follows:
<Fragment>
<StandardDirectory Id="LocalAppDataFolder"> <!-- This is a fixed option value -->
<Directory Id="CacheDir" Name="MyAppCache"> <!-- This means %user%\AppData\Local\MyAppCache -->
<Component Id="DeleteCacheDir">
<RegistryValue Root="HKCU" Key="MyRegistriKeyName" Name="cacheValue" Type="string" Value="[CacheDir]" KeyPath="yes"/>
<util:RemoveFolderEx On="uninstall" Property="MUSTUPPERCASEREMOVEID"/> <!-- Here, you insert the registry search ID value implemented below. The reason is explained in https://wixtoolset.org/docs/v3/xsd/util/removefolderex -->
<RemoveFolder Id="RemoveCacheFolder" On="uninstall"/> <!-- This part means specifying a dummy table -->
</Component>
</Directory>
<!-- If you use it like this, Directory will be automatically inserted within the <Directory> property -->
</StandardDirectory>
<Property Id="MUSTUPPERCASEREMOVEID"> <!-- An error will be returned if the ID is not in uppercase -->
<RegistrySearch Id="RemoveCacheDirSearch" Root="HKCU" Key="MyRegistriKeyName" Name="cacheValue" Type="raw"/>
</Property>
</Fragment>
This completes the second step.
This involves the .wxs file containing the Package element. Skipping the options for the Package element, let's focus on the essential Feature property within it. You need to add the Id value of the Component from the second step, like this:
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="....." .....>
<Feature Id="Main">
<ComponentRef Id="DeleteCacheDir" />
.... install directories components
</Feature>
</Package>
</Wix>
I hope this helps you succeed.
Upvotes: 1
Reputation: 674
We can delete folder recursively with RemoveFolderEx
. For this we need to add following to our Wix root element:
xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util"
Borrowed from here
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
<Fragment>
<!-- Retrieve the CONFIGFOLDER "remembered" on installation -->
<Property Id="CONFIGFOLDER_PROP" Secure="yes">
<RegistrySearch Id="APPLICATIONFOLDER_REGSEARCH"
Root="HKCU"
Key="SOFTWARE\$(var.Manufacturer)\$(var.ProductName)"
Type="raw"
Name="Path" />
</Property>
<Component Id="CleanupConfigurationFolder" Directory="CONFIGFOLDER">
<!--
RemoveFolderEx requires that we "remember" the path for uninstall.
Read the path value and set the CONFIGFOLDER property with the value.
-->
<RegistryValue Root="HKCU"
Key="SOFTWARE\$(var.Manufacturer)\$(var.ProductName)"
Name="Path"
Type="string"
Value="[CONFIGFOLDER]"
KeyPath="yes" />
<!-- We need to use CONFIGFOLDER variable here or RemoveFolderEx
will not remove on "uninstall". -->
<util:RemoveFolderEx On="uninstall" Property="INSTALLFOLDER_PROP" />
<!-- Here <RemoveFolder/> if needed -->
</Component>
</Fragment>
</Wix>
And the folder definition:
<!-- Appdata (User data) -->
<StandardDirectory Id="AppDataFolder">
<Directory Id="CONFIGFOLDER" Name="!(loc.Company)"/>
</StandardDirectory>
Unfortunately RemoveFolderEx
does not add the folder to the RemoveFile table, we might get this error:
The directory CONFIGFOLDER is in the user profile but is not listed in the RemoveFile table.
So, as workaround I added following dummy line after it (RemoveFolderEx
)
<!-- Dummy action to track the CONFIGFOLDER in the RemoveFile table -->
<RemoveFolder Id='RemoveConfigurationFolder' Directory='CONFIGFOLDER' On='uninstall' />
Upvotes: 1