Tutorials to .com

Tutorials to .com » Software » Vfp » Visual FoxPro Application for increase in file compression

Visual FoxPro Application for increase in file compression

Print View , by: iSee ,Total views: 39 ,Word Count: 3834 ,Date: Sat, 18 Apr 2009 Time: 9:38 PM


Compressed file can be viewed as a document of the container packaging. File compression, a large number of documents and can be packaged together as a document to view. In addition, the compressed file in the size generally smaller than the original document, such as a text file in the average size after compression is 40% of the original. Therefore, the file compression can save significant storage space and network transmission time, thus making the carrying and transmission of documents faster and more convenient.
In the DOS environment, the frequent use of the compression process is ARJ, RAR and PKZIP / PKUNZIP. In the Windows environment, the frequent use of the WinZip compression software and CleverZip. Basically, the software is sharing software, you can access from the network for free.
Applications in the database, you often need to compress the backup data files or recover from a compressed file. To Visual foxpro as an example, the normal practice is to call through the FoxPro language compression software, and then the operation of the compression software to interface to restore files or documents. This practice not only in the user interface very unfriendly, but also greatly weakens the integrity of the application. FoxPro procedures described in the following two to share the use of dynamic-link library AZIP.DLL and Visual FoxPro in AUNZIP.DLL achieved internal file compression and decompression functions, and thus better solve the problem.

File compression program
* Name: AZIP.PRG
* A description of the procedures: In Visual FoxPro file compression to achieve
* Procedural requirements: AZIP32.DLL placed in the Windows directory or the system under the current directory
* Use: USAGE: AZIP (lInitialize, sArchive, sInclFiles [, ZipParams])
* Parameter Description:
- lInitialize:. T. - first use of this procedure,. F. - the first time using this procedure
- sArchive: with the compressed file name extension, such as "C: \ THISFILE.ZIP"
- sInclFiles: the need to compress the file name, different file names have a space between the cases of 1: "D: \ CUSTDATA.DBF"
Case 2: "C: \ CUSTOMER.DBF D: \ *. TXT D: \ databases \ *.*"
- ZIPparams: file compression parameters [optional]
e (x) x = 'X' the greatest degree of compression
x ='0 'No compression
x = 'S' the smallest degree of compression
x = 'N' ordinary compression (default)
P, including directory information
S the use of your password (must be the last part)
* Model statement: AZIP (. T., "ZIPFILE", "*. DBF *. TXT Customer.doc")
* Return parameters: number of documents have been compressed, If you do not specify the file name is returned -1
* Accept the parameters
PARAMETERS lInitialize, sArchive, sInclFiles, ZIPparams
PRIVATE Params, sTemp
Params = PARAMETERS ()
* Statement of the need to call the DLL function and was the focus of the current window
IF Params = 0 OR lInitialize
PRIVATE HWND
DECLARE INTEGER GetActiveWindow IN win32api
HWND = GetActiveWindow ()
DECLARE addZIP_Initialise IN AZIP32
DECLARE SHORT addZIP_SetParentWindowHandle IN AZIP32 SHORT @ HWindow
DECLARE SHORT addZIP_ArchiveName IN AZIP32 STRING @ sArchName
DECLARE SHORT addZIP_Include IN AZIP32 STRING @ sFileName
DECLARE SHORT addZIP_Recurse IN AZIP32 SHORT @ nRecurse
DECLARE SHORT addZIP_SetCompressionLevel IN AZIP32 SHORT @ nComprLvl
DECLARE SHORT addZIP_IncludeDirectoryEntries IN AZIP32 SHORT @ nInclDir
DECLARE SHORT addZIP_IncludeEmptyDirectoryEntries IN AZIP32 SHORT @ nInclEDir
DECLARE SHORT addZIP_Update IN AZIP32 SHORT @ nUpdate
DECLARE SHORT addZIP_Update IN AZIP32 SHORT @ nUpdate
DECLARE SHORT addZIP IN AZIP32
DECLARE SHORT addZIP_Register IN AZIP32 String @ RegName, Integer @ RegNum
DECLARE SHORT addZIP_Encrypt IN AZIP32 STRING @ sPassw
addZIP_Initialise ()
addZIP_SetParentWindowHandle (HWND)
* If you are using the dynamic-link library version of the register, you can add the following line
addZIP_Register ( "RegistrationName", RegistrationNumber)
* Its role is to use compressed files in a password-protected
* If you do not specify compressed file name, then returned to 0 (no files are compressed)
IF Params <2
RETURN 0
ENDIF
ENDIF
* If you do not specify compressed file name, then rings and return 0 (no files are compressed)
IF Params <3
?? CHR (7)
MESSAGEBOX ( 'lack of operating parameters!', 0, 'AZip Warning!')
RETURN 0
ENDIF
* If you specify a file compression parameters, compression parameters to choose in accordance with
IF Params> 3
ZIPparams = ALLT (ZIPparams)
PRIVATE LastPos, PASSWORD, nCurPos
LastPos = LEN (ZIPparams) + 1
* Password checks for the presence of compression
nCurPos = ATC ( 'S', ZIPparams)
IF nCurPos> 0
cPassWord = SUBSTR (ZIPparams, nCurPos +1)
addZIP_Encrypt (cPassWord)
ZIPparams = LEFT (ZIPparams, nCurPos -1)
ENDIF
* Check whether the save directory information
nCurPos = ATC ( 'P', ZIPparams)
IF nCurPos> 0
addZIP_Recurse (1)
addZIP_IncludeDirectoryEntries (1)
ENDIF
* Check the level of file compression
nCurPos = ATC ( 'E', ZIPparams)
IF nCurPos> 0
PRIVATE cCompLevel, nCompLevel
cCompLevel = SUBSTR (ZIPparams, nCurPos + 1, 1)
DO CASE
* To maximize the compression
CASE cCompLevel = 'X'
nCompLevel = 3
* A minimum degree of compression
CASE cCompLevel = 'S' & & min compression
nCompLevel = 1
* No compression
CASE cCompLevel ='0 '& & no compression
nCompLevel = 0
* Normal compression
OTHERWISE & & normal / default compression
nCompLevel = 2
ENDCASE
addZIP_SetCompressionLevel (nCompLevel)
ENDIF
ELSE
addZIP_SetCompressionLevel (2)
ENDIF
* Specify the path to the file compression
addZIP_ArchiveName (sArchive)
* Check the need for compressed file
sInclFiles = ALLT (STRTRAN (sInclFiles, '','|'))
* The establishment of compressed file information
addZIP_Include (sInclFiles) & & (sInclFiles)
* Compressed file and return to being the number of compressed file
Return addZIP ()

Program files
* Name: AUNZIP.PRG
* A description of the procedures: In Visual FoxPro files to achieve
* Procedural requirements: AUNZIP32.DLL placed in the Windows directory or the System under the current directory
* Use: AUNZIP (lInitialize, sArchive sDir [, sExtractFiles [, UnZIPparams]])
* Parameter Description:
* LInitialize:. T. - first use of this procedure,. F. - the first time using this procedure
* SArchive: with the compressed file name extension, such as "C: \ THISFILE.ZIP"
* SDir: target directory, such as "D: \ TEMP"
* SExtractFiles: need to decompress the file name [optional], a different file name has a space between
* Default :"*.*"
* Case 1: "C: \ CUSTOMER.DBF"
* Case 2: "C: \ CUSTOMER.DBF D: \ *. TXT D: \ DATABASES \ *.*"
* UnZIPparams: compression parameters [optional]
* F file update
* D, including directory information
All coverage * OA (Default)
Does not cover * O0
* OU question whether the coverage
* S use a password (must be the last part)
* Model statement: AUNZIP (. T., "ZIPFILE", "*. DBF *. TXT Customer.doc")
* Return parameters: the number of documents extracted, if the compressed file name is not specified then return -1


* Accept the parameters
PARAMETERS Initialize, sArchive, sDir, sExtractFiles, UnZIPparams
PRIVATE Params, sTemp
Params = PARAMETERS ()
* Statement of the needs of a dynamic link library and was the focus of the current window
IF Params = 0 OR Initialize
PRIVATE HWND
DECLARE INTEGER GetActiveWindow IN win32api
HWND = GetActiveWindow ()
DECLARE addUNZIP_Initialise IN AUNZIP32
DECLARE SHORT addUNZIP_SetParentWindowHandle IN AUNZIP32 SHORT @ HWindow
DECLARE SHORT addUNZIP_ArchiveName IN AUNZIP32 STRING @ sArchName
DECLARE SHORT addUNZIP_RestoreStructure IN AUNZIP32 SHORT @ nResStr
DECLARE SHORT addUNZIP_Freshen IN AUNZIP32 SHORT @ nFreshn
DECLARE SHORT addUNZIP_Include IN AUNZIP32 STRING @ sFileName
DECLARE SHORT addUNZIP_ExtractTo IN AUNZIP32 STRING @ sExtrTo
DECLARE SHORT addUNZIP_Register IN AUNZIP32 STRING @ RegName, INTEGER @ RegNum
DECLARE SHORT addUNZIP_Decrypt IN AUNZIP32 STRING @ sPassw
DECLARE SHORT addUNZIP_Overwrite IN AUNZIP32 SHORT @ nOvLevel
DECLARE SHORT addUNZIP IN AUNZIP32
addUNZIP_Initialise ()
addUNZIP_SetParentWindowHandle (HWND)
* AddUNZIP_Register ( "RegistrationName", RegistrationNumber)
* If you are using the dynamic-link library version of the register, you can add the above line
* Its role is to use compressed files in a password-protected


* If you do not specify compressed file name, then returned to 0 (no files are extracted)
IF Params <2
RETURN 0
ENDIF
ENDIF
* If you do not specify the target extract directory, and return the bell to ring 0 (no files are extracted)
IF Params <3
?? CHR (7)
MESSAGEBOX ( 'lack of decompression parameters!', 0, 'AUNZip Warning!')
RETURN 0
ENDIF
* If there are parameters extracted, then extract the parameters of access
IF Params> 3
UnZIPparams = ALLT (UnZIPparams)
PRIVATE LastPos, PASSWORD, nCurPos
LastPos = LEN (UnZIPparams) + 1
* Check whether or not to use passwords
nCurPos = ATC ( 'S', UnZIPparams)
IF nCurPos> 0
cPassWord = SUBSTR (UnZIPparams, nCurPos +1)
addUNZIP_Decrypt (cPassWord)
UnZIPparams = LEFT (UnZIPparams, nCurPos -1)
ENDIF
* Check whether the restoration of directory information
nCurPos = ATC ( 'D', UnZIPparams)
IF nCurPos> 0
addUNZIP_RestoreStructure (1)
ENDIF
* Check if file updating
nCurPos = ATC ( 'F', UnZIPparams)
IF nCurPos> 0
addUNZIP_RestoreStructure (1)
ENDIF
* Check whether the document cover
DO CASE
* All coverage
CASE 'OA' $ UnZIPparams
addUNZIP_Overwrite (0x0b)
* Non-coverage
CASE 'O0' $ UnZIPparams
addUNZIP_Overwrite (0x0c)
* Question whether the coverage
CASE 'OU' $ UnZIPparams
addUNZIP_Overwrite (0x0a)
ENDCASE
IF nCurPos> 0
addUNZIP_RestoreStructure (1)
ENDIF
ELSE
addUNZIP_Overwrite (0x000a)
ENDIF
* Recognizing the need to extract the compressed file name
addUNZIP_ArchiveName (sArchive)
* Confirm the path to extract the target
addUNZIP_ExtractTo (ALLT (sDir))
* Recognizing the need to decompress the file
sExtractFiles = IIF (Params <4, "*.*", ALLT (STRTRAN (sExtractFiles, '','|')))
* Extract structural information
addUNZIP_Include (sExtractFiles)
* Extract the file and return to being the number of extracted files
RETURN addUNZIP ()

[Supplementary explanation]
Dynamic Link Library is AZIP.DLL and AUNZIP.DLL company NetCom UK Stephen Darlington engineers prepared to share part of the software AddZip.

Authors: UenoAddress: Tsinghua University, 23 # 421 (100084)
E-mail: qyjohn@letterbox.com


Visual FoxPro Tutorial Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.