2

I have a .NET 4.0 application that uses Isolated Storage to store user files for my application. This ends up using a folder structure like the following:

%LocalAppData%\IsolatedStorage\af34odgf.fj1\bheukjsx.mvr\Url.vc242bhqlc4nzx5043sp5wof15zyzvq0\AssemFiles.

This is fine, I think. However, since these directories and files are created after my application is installed, Windows Installer will not remove them. There are many references online that indicate that one should use a custom action to remove files and directories that are created after installation. I am stuck on how to actually implement this for IsolatedStorage. Specifically, how do I obtain the path to the Isolated Storage folder of my application from the context of the custom action?

If I execute something like IsolatedStorageFile.GetUserStoreForApplication(); from my custom action, won't "application" refer to my installer rather than my application? If so, that would give me a completely different and new Isolated Storage folder path. Or do I have a misconception about where the custom action DLLs "live"?

I am currently using WiX, but I suspect the answer is likely independent of that.

Stephen Booher
  • 6,322
  • 3
  • 33
  • 49
  • 1
    How about letting your application save the list of paths in the registry or filesystem and read it upon uninstall? – KMoraz Jan 11 '12 at 21:55
  • Typically user data files and configuration should be left on the machine. Among other things, this supports an uninstall and reinstall not deleting their data, and avoids problems associated with attempting to remove files from other users on a multi-user system. – Michael Urman Jan 12 '12 at 12:44
  • @MichaelUrman What if the files may be large? The application in question performs a fair amount of long running network data transfers, and it currently uses Isolated Storage as a long-term cache for these files while the transfers are running. This is so that the application can be terminated at any time, yet still able to resume data transferring upon being reopened. While the application cleans up after itself in normal usage, if someone were to terminate the application, then uninstall the application, several files could be left on the machine which could total a few hundred MB. – Stephen Booher Jan 12 '12 at 14:46
  • Perhaps your use case is atypical, or perhaps it should be storing these temporary files in %TEMP% (people are used to occasionally cleaning up this location). From a disk space usage perspective, however, what's the difference between terminating it followed by never running the application again, and followed by uninstalling the application? We all have to make trade-offs. – Michael Urman Jan 12 '12 at 19:59

3 Answers3

0

I think the best way to address this is to have the application save just the Isolated Storage path in the registry, rather than attempting to maintain a path list of every file that the Isolated Storage code for the application ever creates or deletes.

When uninstalling, this registry entry can be read and used with a WiX utils extension called RemoveFolderEx. This extension differs from RemoveFolder in that RemoveFolderEx will remove a folder and its contents.

Also, see this related question/answer, IsolatedStorage: Delete preferences in uninstaller?, which suggests that one might be able to move the Isolated Storage code into a separate assembly that is shared between the main application and the installer, allowing them to reference the same Isolated Storage stores.

Community
  • 1
  • 1
Stephen Booher
  • 6,322
  • 3
  • 33
  • 49
0
[STAThread]
static void Main()
{
    //uninstall the application logic
    var args = Environment.GetCommandLineArgs();

    if(args.Any(x => string.Equals(x, "uninstall", StringComparison.OrdinalIgnoreCase))
    {
         // Your code to remove isolated storage files
         return;
    }

    // Normal Application Startup flow

}                

This may be unconventional, but in my applications I add code and it works for me...then in Wix add a Quiet Custom Action http://wixtoolset.org/documentation/manual/v3/customactions/qtexec.html with the path to your program and pass the uninstall argument to execute before the files are removed in the normal uninstallation flow

Rudy
  • 217
  • 3
  • 6
0

If you can get your application to store these files and folders in a well-known location then you can set a property with that path and then use it in RemoveFolder tag to remove all the files on uninstall.

<RemoveFolder Id="RemoveFolder" On="uninstall" Property="TEMPLOCATION"/>
sttaq
  • 1,603
  • 2
  • 20
  • 38
  • RemoveFolder will only work on empty folders. If you want to remove an entire folder and its contents, the Windows Installer has to know the path of every file and folder within that folder. (That wasn't really the question I was asking though.) Unfortunately, based on the lack of responses and my own research into the problem, it seems like the answer to this question is that it's not possible to do what I want to do using the Windows Installer. There are a few alternatives, of course, primarily already mentioned by the comments to the question above or by using an alternative installer. – Stephen Booher Mar 30 '12 at 03:30
  • Is this (http://stackoverflow.com/questions/195919/removing-files-when-uninstalling-wix) something similar to your problem? – sttaq Mar 30 '12 at 09:01