0

I have adapted a program to stop needing administrator rights or writing data files into its installation programfiles directory. These files are not created by the program but modified: they exist in a fresh installation, even if they were empty (not really the case anyway).

Now I need to adapt the installer, for the additional requirement that, if there are files from a previous version, I must preserve them somehow, so the program uses them instead of the default ones. The previous MSI (not made with WiX) leaves these files behind after un-installation.

My solution for the program itself has been to install the default data files directly into INSTALLFOLDER/programfiles as before, but check within the program at every run if the files exist in appdata, otherwise copy the fresh ones from programfiles, then start using the new path. I do this because I still want this to be per-user data, but I can't rely on an installation to store files in every current and future user profile; and I think that would not be something an MSI should do. (BTW am I wrong here?)

Now for installation the effect I thought would be best is to keep installing the fresh data files into programfiles, but have the MSI move existing files, if any (if there are no data files in programfiles installation should just go on), into appdata (so they will be found and used by the program, for the user who installed). The icing on the cake would be resolving the conflict in case files are found both in programfiles and appdata (I should assume the latter would be more recent).

This is my first try:

<Directory Id="AppDataFolder">
            <Directory Id="appdataDirAuthor" Name="authorName">
                <Directory Id="appdataDir" Name="productName">
                    <Component Id="dbPreserve" Permanent="yes" Guid="XXXXXX">
                        <CopyFile Id="dbPreserveFoo" Delete="yes" DestinationDirectory="appdataDir" SourceDirectory="dbDir" SourceName="Foo*.*" />
                    </Component>
                </Directory>
            </Directory>
        </Directory>

Of course I get errors that I must use a registry KeyPath, and that I'm missing RemoveFile. But what I want is a one-time copy, and I don't need or want the OS to track it, because I'm just mimicking how files would be left over in appdata by the software itself, that un-installation would not touch.

Perhaps this is better suited for an ad hoc script outside the MSI run via a custom action?

  • what is the best way to accomplish this file copying (via MSI standard actions or not)?
  • Is this copying the best or least bad way to accomplish my original goal?

Many thanks in advance.

J.P.
  • 350
  • 2
  • 11

1 Answers1

0

Well after reading the authoritative answers to this other question, I am reaffirmed that this kind of thing is not appropriate to be done by the installer.

Just for info this is the Windows batch script I'll use instead (before InstallFiles):

@echo off

if exist "%APPDATA%\authorName\prodName\Foo.bar" exit /b 0

set dirOrig=0
if exist "%ProgramFiles(x86)%\prodNameOld\DATABASE\Foo.bar" set dirOrig=%ProgramFiles(x86)%\prodNameOld\DATABASE
if exist "%ProgramFiles(x86)%\prodName\DATABASE\Foo.bar"    set dirOrig=%ProgramFiles(x86)%\prodName\DATABASE
if "%dirOrig%"=="0" exit /b 0

xcopy "%dirOrig%\Foo.bar" "%APPDATA%\authorName\prodName\" /y 
xcopy "%dirOrig%\etc.*"   "%APPDATA%\authorName\prodName\" /y
del /f/q "%dirOrig%\*.*"
exit /b 0
Community
  • 1
  • 1
J.P.
  • 350
  • 2
  • 11