Anatomy of the Update Utility

When the Update Utility EXE is run, the basic steps taken to update an existing application are:

Backup Files Notification

A message is displayed that notifies the user to perform a backup of the application’s files before applying the update. The ApplicationUpdate class has a property, lBackupMessage, that when set to .F. will prevent this message from being displayed.

Identify Application Directory

The Select Directory dialog is displayed so that the user can identify the “application” or “home” directory of the application to be updated. The “home” directory contains the Application Definition table (SVPMApplicationDefinition.APD) and the update does not proceed until a directory is chosen that contains this table.

Already Updated Notification

A check is made to see if the update has already been applied to the selected application. The update has already been applied if the entry in the Version field in the Application Definition table that is in the update directory is the same as the entry in the Version field in the same table in the application’s “home” directory. If the same, a message is displayed that notifies the user that the application has already been updated. The user is then given the option of continuing with the update or exiting. If the Application Definition table is not included in the update files this notification will not occur.

Set Path

The VFP path is set to that of the application so that all of the application’s files can be found in case they need to be replaced with updated files. The path will include the “home” directory, any subdirectories of the “home” directory, the Data and Reports directories and Path Additions specified on the Directories form as stored in the Application Definition table.

If the application’s “home” directory is on a server with multiple users running the application, the drive letter in the directories stored in the Application Definition table may need to be different for different users. If so, Drive Swapping functionality has been built into the Update Utility to handle this situation. See the LoadDriveSwap method in the ApplicationUpdate class in the SAppUpd class library for an example of how to load an array that will implement the Drive Swapping functionality.

Copy Update Files to Temporary Update Directory

A temporary update directory is created as a subdirectory of the original update directory. Then, all files in the update directory are copied to the temporary update directory except for Foxuser and Update Utility EXE files. This copying is done so that the original update files are not modified in any way which will allow the update to be applied over and over again without the user having to reinstall the update.

Update Tables in Temporary Update Directory

The tables in the temporary update directory are updated as specified on the Data Update Definition form on the Tools/Update Builder menu in VPM. The table SAppUpdT holds the definition of how tables will be updated while SAppUpdF holds the definition of how fields in specific records will be updated. For each table in the temporary update directory, a search is made to find a record in SAppUpdT for that table. If found and the update method is “Maintain” or “Combine”, the table is opened. The table is then performed as follows:

·       Maintain user data: The table is zapped and then all of the records from the user’s version of the table are appended.

·       Combine user data and update data: The records in the user’s version of the table are combined with the records in the update version of the table. If there are records in each of the two tables that have the same PK value, the duplicate record from the user’s version of the table is retained and the record from the update version of the table is deleted. For this method to be used a Primary Key (PK) tag must be specified for the table.

For each record in SAppUpdF, the table to be updated is searched for, first in the temporary update directory and then in the application’s directories included in the VFP path. If found, the table is opened and the record to be updated is found using the PK field values that were entered on the Data Update Definition form. A PK tag must be selected for the table for the record to be found. If there are no PK field values and the table contains only a single record, that record is selected for update. The field update is then performed as follows:

·       Update with value from update table: If the check box in the column with the “T” heading was checked for this field on the Data Update Definition form, the version of the table in the original update directory is opened and the appropriate record is found. The value in the specified field in this record is then placed into the field in the record to be updated.

·       Update with value from Value field: If the Value field was filled-in for this field on the Data Update Definition form, that value is converted to the appropriate type and then placed into the field in the record to be updated.

Copy Files from Temporary Update Directory to Application’s Directories

All files are then copied from the temporary update directory to the application’s directories. For each file in the temporary update directory, an attempt is made to find the file within the application’s path. If found, the file in the application directory is replaced with the version in the temporary update directory. If not found, the application directory to which the file will be copied is determined according to the type of file as follows:

·       Tables, indexes, and databases: If a directory has been specified in the Tables field on the Directories form, the table, index, or database file is copied to that directory. If not, and the SDATADDTV data dictionary table can be found, the file is copied to the directory that contains the SDATADDTV table. Otherwise, the file is copied to the application’s “home” directory.

·       Reports: If a directory has been specified in the Reports field on the Directories form, the report file is copied to that directory. If not, and the Errors report can be found, the file is copied to the directory that contains the Errors report. Otherwise, the file is copied to the application’s “home” directory.

·       Other files: All other files are copied to the “home” directory.

If the above does not result in a new file being copied to the desired directory, code can be added to the CopyToDir method of the ApplicationUpdate class in the SAppUpd2 class library that will return the name of the directory to which the file should be copied. For example:

 

LPARAM stcFile

IF stcFile = “NEWTABLE.DBF”

   RETURN “C:\MYDATA”

ELSE

   RETURN “”

ENDIF

 

More:

Team Development & Source Control