#include "zip.h"
#include "unzip.h"
#include <QFile>
#include <QFileInfo>
#include <QString>
#include <QStringList>
#include <QList>
#include <iostream>
#include <iomanip>
Go to the source code of this file.
|
void | invalidCMD () |
|
bool | decompress (const QString &file, const QString &out, const QString &pwd) |
|
bool | compress (const QString &zip, const QString &dir, const QString &pwd) |
|
bool | listFiles (const QString &file, const QString &pwd) |
|
int | main (int argc, char **argv) |
|
bool compress |
( |
const QString & |
zip, |
|
|
const QString & |
dir, |
|
|
const QString & |
pwd |
|
) |
| |
Definition at line 182 of file zipExampleUsage.cpp.
Referenced by main().
187 cout <<
"Directory does not exist." << endl << endl;
197 cout <<
"Unable to create archive: " << uz.
formatError(ec).toAscii().data() << endl << endl;
205 cout <<
"Unable to add directory: " << uz.
formatError(ec).toAscii().data() << endl << endl;
208 uz.
setArchiveComment(
"This archive has been created using OSDaB Zip (http://osdab.sourceforge.net/).");
212 cout <<
"Unable to close the archive: " << uz.
formatError(ec).toAscii().data() << endl << endl;
ErrorCode createArchive(const QString &file, bool overwrite=true)
void setPassword(const QString &pwd)
void setArchiveComment(const QString &comment)
ErrorCode addDirectory(const QString &path, CompressionOptions options=RelativePaths, CompressionLevel level=AutoFull)
QString formatError(ErrorCode c) const
bool decompress |
( |
const QString & |
file, |
|
|
const QString & |
out, |
|
|
const QString & |
pwd |
|
) |
| |
Definition at line 149 of file zipExampleUsage.cpp.
Referenced by main().
152 if (!QFile::exists(file))
154 cout <<
"File does not exist." << endl << endl;
167 cout <<
"Failed to open archive: " << uz.
formatError(ec).toAscii().data() << endl << endl;
174 cout <<
"Extraction failed: " << uz.
formatError(ec).toAscii().data() << endl << endl;
ErrorCode extractAll(const QString &dirname, ExtractionOptions options=ExtractPaths)
PKZip 2.0 file decompression. Compatibility with later versions is not ensured as they may use unsupp...
QString formatError(UnZip::ErrorCode c) const
ErrorCode openArchive(const QString &filename)
void setPassword(const QString &pwd)
Definition at line 140 of file zipExampleUsage.cpp.
Referenced by main().
142 cout <<
"Invalid command line. Usage:" << endl;
143 cout <<
"Compression: zip [-p PWD] DIRECTORY" << endl;
144 cout <<
"List files: zip -l [-p PWD] ZIPFILE" << endl;
145 cout <<
"Decompression: zip -d [-p PWD] ZIPFILE OUTPUT_DIR" << endl << endl;
bool listFiles |
( |
const QString & |
file, |
|
|
const QString & |
pwd |
|
) |
| |
Definition at line 218 of file zipExampleUsage.cpp.
Referenced by main().
220 if (!QFile::exists(file))
222 cout <<
"File does not exist." << endl << endl;
235 cout <<
"Unable to open archive: " << uz.
formatError(ec).toAscii().data() << endl << endl;
240 if (!comment.isEmpty())
241 cout <<
"Archive comment: " << comment.toAscii().data() << endl << endl;
243 QList<UnZip::ZipEntry> list = uz.
entryList();
246 cout <<
"Empty archive.";
250 cout.setf(ios::left);
251 cout << setw(40) <<
"Filename";
252 cout.unsetf(ios::left);
253 cout << setw(10) <<
"Size" << setw(10) <<
"Ratio" << setw(10) <<
"CRC32" << endl;
254 cout.setf(ios::left);
255 cout << setw(40) <<
"--------";
256 cout.unsetf(ios::left);
257 cout << setw(10) <<
"----" << setw(10) <<
"-----" << setw(10) <<
"-----" << endl;
259 for (
int i = 0; i < list.size(); ++i)
265 QString ratioS = QString::number(ratio,
'f', 2).append(
"%");
267 crc = crc.sprintf(
"%X", entry.
crc32).rightJustified(8,
'0');
269 int idx = file.lastIndexOf(
"/");
270 if (idx >= 0 && idx != file.length()-1)
271 file = file.right(file.length() - idx - 1);
272 file = file.leftJustified(40,
' ',
true);
277 cout << setw(40) << file.toAscii().data() << setw(10) << entry.
uncompressedSize << setw(10) << ratioS.toAscii().data() << setw(10) << crc.toAscii().data() << endl;
QList< ZipEntry > entryList() const
PKZip 2.0 file decompression. Compatibility with later versions is not ensured as they may use unsupp...
QString archiveComment() const
QString formatError(UnZip::ErrorCode c) const
ErrorCode openArchive(const QString &filename)
void setPassword(const QString &pwd)
int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Definition at line 44 of file zipExampleUsage.cpp.
48 cout <<
"Test routine for the OSDaB Project Zip/UnZip classes" << endl << endl;
49 cout <<
"Compression: zip [-p PWD] ZIPFILE DIRECTORY" << endl;
50 cout <<
"List files: zip -l [-p PWD] ZIPFILE" << endl;
51 cout <<
"Decompression: zip -d [-p PWD] ZIPFILE OUTPUT_DIR" << endl << endl;
52 cout <<
"(C) 2007 Angius Fabrizio\nLicensed under the terms of the GNU GPL Version 2 or later" << endl;
62 if (strlen(argv[1]) == 2 && argv[1][0] ==
'-')
70 if (strcmp(argv[2],
"-p") == 0)
72 pwd = QString(argv[3]);
73 fname = QString(argv[4]);
74 dname = QString(argv[5]);
80 fname = QString(argv[2]);
81 dname = QString(argv[3]);
92 if (strcmp(argv[2],
"-p") == 0)
94 pwd = QString(argv[3]);
95 fname = QString(argv[4]);
101 fname = QString(argv[2]);
112 pwd = QString(argv[2]);
113 fname = QString(argv[3]);
114 dname = QString(argv[4]);
118 resOK =
compress(fname, dname, pwd);
127 resOK =
compress(QString(argv[1]), QString(argv[2]), 0);
133 cout <<
"Sorry, some error occurred!" << endl;
bool compress(const QString &zip, const QString &dir, const QString &pwd)
bool decompress(const QString &file, const QString &out, const QString &pwd)
bool listFiles(const QString &file, const QString &pwd)