|
A WinDev project using the 7-zip Command Line Interface (CLI) Overview: In one of our projects, the built-in ZIP-functions of WinDev simply do not offer the compression ratio required for the number + size of backups. I chose to use 7-zip. 7-zip can be found at http://www.7-zip.org/ and can be used under LGPL license (GNU Library or Lesser General Public License (LGPL)). 7-zip is developed by Igor Pavlov and offers with its .7z / LZMA2 algorithm one of the best compression ratios you can get. So, it’s free, freely distributable and it’s excellent - that should be enough? No, 7-zip offers an SDK, a command-line version and the .dll for using the LZMA2 algorithm anywhere. This project uses 7zG.exe from a WinDev project. 7zG.exe displays a graphical info of the backup process but obeys the commands of the command-line-interface of 7-zip. We use version 9.20 of 7-zip here. 7-zip comes with 7-zip.chm a Help file which details the possible CLI-commands, switches and parameters. A more elaborate description of the CLI is available at http://www.dotnetperls.com/7-zip-examples but deals with an older version of 7-zip and it’s console executable named 7za.exe. Download / install 7-zip from its creator’s site and put the file 7zG.exe into the \exe directory of your project. A sample command line to backup all files in a certain directory to a 7-zip- archive sitting in a different directory looks like this:7zG a -t7z d:\..path1..\myarchive.7z d:\..path2..\* -mx5 Note 1: with 7-zip, do not mix up common DOS-parsing like *.* with * - ‘all files’ is a single star!Note 2: the destination directory comes first and after that comes the source directory.Note 3: there must be a path to 7zG.exe ...Note 4: Add a quote (Charact(34)) before and after the path - if the path could contain a space! The project is a first version and serves as a demonstration of capabilities only.- no validity check on archive-extensions- tested with .7z only Download the project: WD15_7ZIPCLI.exe (self-extracting exe) Notes for WinDev-programs with a HyperFile Classic analysis: - Backup. Neither a closing of the HyperFiles (HClose(“*”)) nor closing the connection (HCloseConnection(..)) will release the datafiles from status ‘locked’! The 7-zip switch -ssw comes for rescue! A sample backup command line would look like that: 7zG a -t7z d:\directory1\MyArchive.7z d:\directory2\* -mx1 -ssw
Warning: there’s something wrong with 7-zip command line parsing if there sits ANY archive in directory2 ! It will not create the archive in directory1 but update the archive in directory2 instead! Bottom line: Please, delete / remove all archives from the source-directory!!
- Restore: In order to restore HyperFile Classic files you have to close the program before restoring the datafiles! Switch -ssw will not work here! So, the symbolic program lines woul look like MyString = ArchiveName MyString2 = "7zG e "+Charact(34)+MyString+Charact(34)+" -o"+Charact(34) ...+UncompleteDir(MyPathToHFClassic)+Charact(34)+" * -aoa" + CR ...+ "MyProgram.exe" + CR + "EXIT" + CR fSaveText(CompleteDir(fExeDir())+"mybackup.bat",MyString2) ExeRun("mybackup.bat",exeIconize,exeDontWait) EndProgram() Explanation: A batch-file containing the 7-zip command line + a command to restart the program + an EXIT command which works as a close command to the CMD-window. The batch-file mybackup.bat is started and the program itself is terminated. This frees the data files from access by the analysis and allows an orderly restore of the files within the archive. |