Wix Bootstrapper - Best way to update/install Visual FoxPro database

206 views Asked by At

As mentioned here wix-bootstrapper-update-ui-xaml-from-customaction I use a Bootstrapper to install two MSI-packages.

During the installation I want to install/update a Visual FoxPro database (consisting of free tables).

At the moment I achieve this by calling a Visual FoxPro-exe during the ApplyComplete-Event of the BootstrapperApplication. To establish a communication between the BootstrapperApplication and the Visual FoxPro-exe I use MSMQ :

private void OnApplyComplete(object sender, ApplyCompleteEventArgs e)
{
    string updateFile = this.installationFolder + "\\updfile.exe";

    if (!MessageQueue.Exists(NAMEDPVDATENBANKNACHRICHTENSCHLANGE))
    {
        this._msmq = MessageQueue.Create(UPDATEMSMQ);
    }
    else
    {
        this._msmq = new MessageQueue(UPDATEMSMQ);
    }

    this._msmq.SetPermissions("Everyone", MessageQueueAccessRights.FullControl);
    this._msmq.Purge();

    if (System.IO.File.Exists(updateFile))
    {
        this._dbUpdate = true;
        ProcessStartInfo updateProcessInfo = new ProcessStartInfo();
        updateProcessInfo.FileName = updateFile;
        updateProcessInfo.Arguments = UPDATEMSMQ;
        updateProcessInfo.UseShellExecute = true;
        updateProcessInfo.WorkingDirectory = this.installationFolder;
        updateProcessInfo.CreateNoWindow = true;


        Process updateProcess = new Process();
        updateProcess.StartInfo = updateProcessInfo;
        updateProcess.EnableRaisingEvents = true;
        updateProcess.Exited += new EventHandler(this.updateFinished);
        updateProcess .Start();

        while (this._dbUpdate)
        {
            Message msg = null;
            try
            {
                nachricht = this._msmq.Receive(new TimeSpan(0, 0, 45));
            }
            catch (MessageQueueException msgEx)
            {
                if (nachrichtAusnahme.MessageQueueErrorCode != MessageQueueErrorCode.IOTimeout)
                {                                
                    this.Engine.Log(LogLevel.Verbose, msgEx);
                }
            }

            if (msg != null)
            {
                msg.Formatter = new ActiveXMessageFormatter();

                this.Engine.Log(LogLevel.Verbose, "VfpUpdate - " + msg.Body.ToString());
            }
        }   
    }
    this._msmq.Close();
    MessageQueue.Delete(UPDATEMSMQ);

}

private void updateFinished(object sender, EventArgs e)
{
    this._dbUpdate = false;
    this.Engine.Log(LogLevel.Verbose, "Update finished");
}

This way it works like a charm unless there are errors during the the update of the Visual FoxPro database. It should be possible to roll-back the changes made during the installation. For me it would be no problem to create a backup of the Visual FoxPro-files and to restore the files if an error occurs. But how should I do this with the files changed by the actual Bootstrapper?

With a CustomAction I can use ActionResult.Failure or ActionResult.Success. But with a CustomAction I face the following issues:

  • no access to Application.Current (for reading values from a customized ResourceDictionary with localized strings that I use within the Bootstrapper)
  • MSMQ-queue is broken (closed?!) after the first message is delivered
  • display the currently performed task in the MainWindow.

Any advice on how to perform the update of the Visual FoxPro database inside a BootstrapperApplication is really welcome.

1

There are 1 answers

0
Cetin Basoz On

I don't know that in the context of an installation bootstrapper. OTOH, either a VFP database and tables or VFP tables (free) are just plain files that are copied/moved from a folder. You don't need to have an exe for that to create them programmatically.

Also having those files as part of the setup might not be a good idea as well. If some files are removed because of version changes then your installer might start to bark about that.

Looking at the bootstrapper code, I have a suspicion that you are creating those free tables in the installation folder or its subfolders which would be a real PITA. Because installation folder is generally under "Program Files (x86)" which is a read only location.

Your bootstrapper code is C#. You might use C# to create those tables as well. One way to do that is to use VFPOLEDB and ExecScript() calls.