Fix()
|
Previous Top Next |
:Fix([<lBackup>]) --> nStatus
|
<lBackup>
|
<lBackup> optionally determines if a Backup File should be created when the Zip File is fixed/changed.
|
The default value is .T. (TRUE), meaning that a Backup File is always created, unless <lBackup> is explicitly set to .F. (FALSE).
|
This method returns the updated value of the :Status instance variable, which contains the Zip File Status. Possible values are the following Define Constants from the XbZLib.ch file:
|
|
|
This method fixes all corrupted Central Directory records -- or if no Central Directory records exists, searches for orphaned records (using the :Test() method) and then fixes all found orphaned records.
|
|
Currently, only lost Central Directory records are re-created, based on all found, valid, orphaned Local File Records. Additional fixes might later be added, like fixing incorrect CRC values. The current process will fix most (if not all) errors that are caused by missing Central Directories, though.
|
|
The corrected records are copied to a new Zip File with a random name (based on the original Zip File's Name). After all valid records were copied to the new Zip File, the original Zip File is either deleted or renamed (creating a backup file, by adding the string ".backup.zip" to the original Zip File name), and then the new, corrected, Zip File is renamed to the original Zip File Name and opened instead of the old file, using the same Open Mode as before.
|
|
The process can normally be interrupted by pressing the ESC Key or by creating an xbeP_Close event. Alternatively, if the :CheckEvents Callback is set to a user-defined routine, this behavior can be either modified or disabled. See the :CheckEvents Callback documentation for more details.
|
Open a Zip File named "MyArchive.zip" and Fix (and if necessary first Test) all Entries in the Zip File, but do not create a Backup copy of the original Zip File:
|
|
LOCAL nStatus := XBZ_FILE_OK
|
LOCAL oZip := XbZLibZip():New('MyArchive.zip')
|
if oZip:IsOpen()
|
nStatus := oZip:Fix(.f.)
|
endif
|
oZip:Close()
|