ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JlCompress Class Reference

Utility class for typical operations. More...

#include <src/ckb/quazip/JlCompress.h>

+ Collaboration diagram for JlCompress:

Static Public Member Functions

static bool compressFile (QString fileCompressed, QString file)
 Compress a single file. More...
 
static bool compressFiles (QString fileCompressed, QStringList files)
 Compress a list of files. More...
 
static bool compressDir (QString fileCompressed, QString dir=QString(), bool recursive=true)
 Compress a whole directory. More...
 
static QString extractFile (QString fileCompressed, QString fileName, QString fileDest=QString())
 Extract a single file. More...
 
static QStringList extractFiles (QString fileCompressed, QStringList files, QString dir=QString())
 Extract a list of files. More...
 
static QStringList extractDir (QString fileCompressed, QString dir=QString())
 Extract a whole archive. More...
 
static QStringList getFileList (QString fileCompressed)
 Get the file list. More...
 

Static Private Member Functions

static bool compressFile (QuaZip *zip, QString fileName, QString fileDest)
 Compress a single file. More...
 
static bool compressSubDir (QuaZip *parentZip, QString dir, QString parentDir, bool recursive=true)
 Compress a subdirectory. More...
 
static bool extractFile (QuaZip *zip, QString fileName, QString fileDest)
 Extract a single file. More...
 
static bool removeFile (QStringList listFile)
 Remove some files. More...
 

Detailed Description

This class contains a number of useful static functions to perform simple operations, such as mass ZIP packing or extraction.

Definition at line 42 of file JlCompress.h.

Member Function Documentation

bool JlCompress::compressDir ( QString  fileCompressed,
QString  dir = QString(),
bool  recursive = true 
)
static

OK Comprime la cartella dir nel file fileCompressed, se recursive e true allora comprime anche le sotto cartelle.

Parameters
fileCompressedThe name of the archive.
dirThe directory to compress.
recursiveWhether to pack the subdirectories as well, or just regular files.
Returns
true if success, false otherwise.

Se la funzione fallisce restituisce false e cancella il file che si e tentato di creare.

La funzione fallisce se:

  • non si riesce ad aprire l'oggetto zip;
  • la compressione di un file fallisce;
  • non si riesce a chiudere l'oggetto zip;

Definition at line 338 of file JlCompress.cpp.

References QuaZip::close(), compressSubDir(), QuaZip::getZipError(), QuaZip::mdCreate, and QuaZip::open().

338  {
339  // Creo lo zip
340  QuaZip zip(fileCompressed);
341  QDir().mkpath(QFileInfo(fileCompressed).absolutePath());
342  if(!zip.open(QuaZip::mdCreate)) {
343  QFile::remove(fileCompressed);
344  return false;
345  }
346 
347  // Aggiungo i file e le sotto cartelle
348  if (!compressSubDir(&zip,dir,dir,recursive)) {
349  QFile::remove(fileCompressed);
350  return false;
351  }
352 
353  // Chiudo il file zip
354  zip.close();
355  if(zip.getZipError()!=0) {
356  QFile::remove(fileCompressed);
357  return false;
358  }
359 
360  return true;
361 }
static bool compressSubDir(QuaZip *parentZip, QString dir, QString parentDir, bool recursive=true)
Compress a subdirectory.
Definition: JlCompress.cpp:103
ZIP file was created with open() call.
Definition: quazip.h:97
ZIP archive.
Definition: quazip.h:84

+ Here is the call graph for this function:

bool JlCompress::compressFile ( QuaZip zip,
QString  fileName,
QString  fileDest 
)
staticprivate

OK Comprime il file fileName, nell'oggetto zip, con il nome fileDest.

Parameters
zipOpened zip to compress the file to.
fileNameThe full path to the source file.
fileDestThe full name of the file inside the archive.
Returns
true if success, false otherwise.

La funzione fallisce se:

  • zip==NULL;
  • l'oggetto zip e stato aperto in una modalita non compatibile con l'aggiunta di file;
  • non e possibile aprire il file d'origine;
  • non e possibile creare il file all'interno dell'oggetto zip;
  • si e rilevato un errore nella copia dei dati;
  • non e stato possibile chiudere il file all'interno dell'oggetto zip;

Definition at line 53 of file JlCompress.cpp.

References QuaZipFile::close(), copyData(), QuaZip::getMode(), QuaZipFile::getZipError(), QuaZip::mdAdd, QuaZip::mdAppend, QuaZip::mdCreate, QuaZipFile::open(), and UNZ_OK.

Referenced by compressFile(), compressFiles(), and compressSubDir().

53  {
54  // zip: oggetto dove aggiungere il file
55  // fileName: nome del file reale
56  // fileDest: nome del file all'interno del file compresso
57 
58  // Controllo l'apertura dello zip
59  if (!zip) return false;
60  if (zip->getMode()!=QuaZip::mdCreate &&
61  zip->getMode()!=QuaZip::mdAppend &&
62  zip->getMode()!=QuaZip::mdAdd) return false;
63 
64  // Apro il file originale
65  QFile inFile;
66  inFile.setFileName(fileName);
67  if(!inFile.open(QIODevice::ReadOnly)) return false;
68 
69  // Apro il file risulato
70  QuaZipFile outFile(zip);
71  if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(fileDest, inFile.fileName()))) return false;
72 
73  // Copio i dati
74  if (!copyData(inFile, outFile) || outFile.getZipError()!=UNZ_OK) {
75  return false;
76  }
77 
78  // Chiudo i file
79  outFile.close();
80  if (outFile.getZipError()!=UNZ_OK) return false;
81  inFile.close();
82 
83  return true;
84 }
#define UNZ_OK
Definition: unzip.h:79
Information about a file to be created.
Definition: quazipnewinfo.h:50
ZIP file was opened for adding files in the archive.
Definition: quazip.h:106
Mode getMode() const
Returns the mode in which ZIP file was opened.
Definition: quazip.cpp:614
ZIP file was created with open() call.
Definition: quazip.h:97
A file inside ZIP archive.
Definition: quazipfile.h:74
static bool copyData(QIODevice &inFile, QIODevice &outFile)
Definition: JlCompress.cpp:29
ZIP file was opened in append mode.
Definition: quazip.h:98

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool JlCompress::compressFile ( QString  fileCompressed,
QString  file 
)
static

OK Comprime il file fileName nel file fileCompressed.

Parameters
fileCompressedThe name of the archive.
fileThe file to compress.
Returns
true if success, false otherwise.

Se la funzione fallisce restituisce false e cancella il file che si e tentato di creare.

La funzione fallisce se:

  • non si riesce ad aprire l'oggetto zip;
  • la compressione del file fallisce;
  • non si riesce a chiudere l'oggetto zip;

Definition at line 263 of file JlCompress.cpp.

References QuaZip::close(), compressFile(), QuaZip::getZipError(), QuaZip::mdCreate, and QuaZip::open().

263  {
264  // Creo lo zip
265  QuaZip zip(fileCompressed);
266  QDir().mkpath(QFileInfo(fileCompressed).absolutePath());
267  if(!zip.open(QuaZip::mdCreate)) {
268  QFile::remove(fileCompressed);
269  return false;
270  }
271 
272  // Aggiungo il file
273  if (!compressFile(&zip,file,QFileInfo(file).fileName())) {
274  QFile::remove(fileCompressed);
275  return false;
276  }
277 
278  // Chiudo il file zip
279  zip.close();
280  if(zip.getZipError()!=0) {
281  QFile::remove(fileCompressed);
282  return false;
283  }
284 
285  return true;
286 }
static bool compressFile(QuaZip *zip, QString fileName, QString fileDest)
Compress a single file.
Definition: JlCompress.cpp:53
ZIP file was created with open() call.
Definition: quazip.h:97
ZIP archive.
Definition: quazip.h:84

+ Here is the call graph for this function:

bool JlCompress::compressFiles ( QString  fileCompressed,
QStringList  files 
)
static

OK Comprime i file specificati in files nel file fileCompressed.

Parameters
fileCompressedThe name of the archive.
filesThe file list to compress.
Returns
true if success, false otherwise.

Se la funzione fallisce restituisce false e cancella il file che si e tentato di creare.

La funzione fallisce se:

  • non si riesce ad aprire l'oggetto zip;
  • la compressione di un file fallisce;
  • non si riesce a chiudere l'oggetto zip;

Definition at line 298 of file JlCompress.cpp.

References QuaZip::close(), compressFile(), QuaZip::getZipError(), QuaZip::mdCreate, and QuaZip::open().

298  {
299  // Creo lo zip
300  QuaZip zip(fileCompressed);
301  QDir().mkpath(QFileInfo(fileCompressed).absolutePath());
302  if(!zip.open(QuaZip::mdCreate)) {
303  QFile::remove(fileCompressed);
304  return false;
305  }
306 
307  // Comprimo i file
308  QFileInfo info;
309  Q_FOREACH (QString file, files) {
310  info.setFile(file);
311  if (!info.exists() || !compressFile(&zip,file,info.fileName())) {
312  QFile::remove(fileCompressed);
313  return false;
314  }
315  }
316 
317  // Chiudo il file zip
318  zip.close();
319  if(zip.getZipError()!=0) {
320  QFile::remove(fileCompressed);
321  return false;
322  }
323 
324  return true;
325 }
static bool compressFile(QuaZip *zip, QString fileName, QString fileDest)
Compress a single file.
Definition: JlCompress.cpp:53
ZIP file was created with open() call.
Definition: quazip.h:97
ZIP archive.
Definition: quazip.h:84

+ Here is the call graph for this function:

bool JlCompress::compressSubDir ( QuaZip zip,
QString  dir,
QString  origDir,
bool  recursive = true 
)
staticprivate

OK Comprime la cartella dir nel file fileCompressed, se recursive e true allora comprime anche le sotto cartelle.

Parameters
parentZipOpened zip containing the parent directory.
dirThe full path to the directory to pack.
parentDirThe full path to the directory corresponding to the root of the ZIP.
recursiveWhether to pack sub-directories as well or only files.
Returns
true if success, false otherwise.

I nomi dei file preceduti dal path creato togliendo il pat della cartella origDir al path della cartella dir. Se la funzione fallisce restituisce false e cancella il file che si e tentato di creare.

La funzione fallisce se:

  • zip==NULL;
  • l'oggetto zip e stato aperto in una modalita non compatibile con l'aggiunta di file;
  • la cartella dir non esiste;
  • la compressione di una sotto cartella fallisce (1);
  • la compressione di un file fallisce; (1) La funzione si richiama in maniera ricorsiva per comprimere le sotto cartelle dunque gli errori di compressione di una sotto cartella sono gli stessi di questa funzione.

Definition at line 103 of file JlCompress.cpp.

References QuaZipFile::close(), compressFile(), QuaZip::getMode(), QuaZip::getZipName(), QuaZip::mdAdd, QuaZip::mdAppend, QuaZip::mdCreate, and QuaZipFile::open().

Referenced by compressDir().

103  {
104  // zip: oggetto dove aggiungere il file
105  // dir: cartella reale corrente
106  // origDir: cartella reale originale
107  // (path(dir)-path(origDir)) = path interno all'oggetto zip
108 
109  // Controllo l'apertura dello zip
110  if (!zip) return false;
111  if (zip->getMode()!=QuaZip::mdCreate &&
112  zip->getMode()!=QuaZip::mdAppend &&
113  zip->getMode()!=QuaZip::mdAdd) return false;
114 
115  // Controllo la cartella
116  QDir directory(dir);
117  if (!directory.exists()) return false;
118 
119  QDir origDirectory(origDir);
120  if (dir != origDir) {
121  QuaZipFile dirZipFile(zip);
122  if (!dirZipFile.open(QIODevice::WriteOnly,
123  QuaZipNewInfo(origDirectory.relativeFilePath(dir) + "/", dir), 0, 0, 0)) {
124  return false;
125  }
126  dirZipFile.close();
127  }
128 
129 
130  // Se comprimo anche le sotto cartelle
131  if (recursive) {
132  // Per ogni sotto cartella
133  QFileInfoList files = directory.entryInfoList(QDir::AllDirs|QDir::NoDotAndDotDot);
134  Q_FOREACH (QFileInfo file, files) {
135  // Comprimo la sotto cartella
136  if(!compressSubDir(zip,file.absoluteFilePath(),origDir,recursive)) return false;
137  }
138  }
139 
140  // Per ogni file nella cartella
141  QFileInfoList files = directory.entryInfoList(QDir::Files);
142  Q_FOREACH (QFileInfo file, files) {
143  // Se non e un file o e il file compresso che sto creando
144  if(!file.isFile()||file.absoluteFilePath()==zip->getZipName()) continue;
145 
146  // Creo il nome relativo da usare all'interno del file compresso
147  QString filename = origDirectory.relativeFilePath(file.absoluteFilePath());
148 
149  // Comprimo il file
150  if (!compressFile(zip,file.absoluteFilePath(),filename)) return false;
151  }
152 
153  return true;
154 }
static bool compressFile(QuaZip *zip, QString fileName, QString fileDest)
Compress a single file.
Definition: JlCompress.cpp:53
Information about a file to be created.
Definition: quazipnewinfo.h:50
static bool compressSubDir(QuaZip *parentZip, QString dir, QString parentDir, bool recursive=true)
Compress a subdirectory.
Definition: JlCompress.cpp:103
ZIP file was opened for adding files in the archive.
Definition: quazip.h:106
Mode getMode() const
Returns the mode in which ZIP file was opened.
Definition: quazip.cpp:614
ZIP file was created with open() call.
Definition: quazip.h:97
QString getZipName() const
Returns the name of the ZIP file.
Definition: quazip.cpp:602
A file inside ZIP archive.
Definition: quazipfile.h:74
ZIP file was opened in append mode.
Definition: quazip.h:98

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QStringList JlCompress::extractDir ( QString  fileCompressed,
QString  dir = QString() 
)
static

OK Estrae il file fileCompressed nella cartella dir.

Parameters
fileCompressedThe name of the archive.
dirThe directory to extract to, the current directory if left empty.
Returns
The list of the full paths of the files extracted, empty on failure.

Se dir = "" allora il file viene estratto nella cartella corrente. Se la funzione fallisce cancella i file che si e tentato di estrarre. Restituisce i nomi assoluti dei file estratti.

La funzione fallisce se:

  • non si riesce ad aprire l'oggetto zip;
  • la compressione di un file fallisce;
  • non si riesce a chiudere l'oggetto zip;

Definition at line 451 of file JlCompress.cpp.

References QuaZip::close(), extractFile(), QuaZip::getCurrentFileName(), QuaZip::getZipError(), QuaZip::goToFirstFile(), QuaZip::goToNextFile(), QuaZip::mdUnzip, QuaZip::open(), and removeFile().

451  {
452  // Apro lo zip
453  QuaZip zip(fileCompressed);
454  if(!zip.open(QuaZip::mdUnzip)) {
455  return QStringList();
456  }
457 
458  QDir directory(dir);
459  QStringList extracted;
460  if (!zip.goToFirstFile()) {
461  return QStringList();
462  }
463  do {
464  QString name = zip.getCurrentFileName();
465  QString absFilePath = directory.absoluteFilePath(name);
466  if (!extractFile(&zip, "", absFilePath)) {
467  removeFile(extracted);
468  return QStringList();
469  }
470  extracted.append(absFilePath);
471  } while (zip.goToNextFile());
472 
473  // Chiudo il file zip
474  zip.close();
475  if(zip.getZipError()!=0) {
476  removeFile(extracted);
477  return QStringList();
478  }
479 
480  return extracted;
481 }
static bool removeFile(QStringList listFile)
Remove some files.
Definition: JlCompress.cpp:241
static bool extractFile(QuaZip *zip, QString fileName, QString fileDest)
Extract a single file.
Definition: JlCompress.cpp:170
ZIP file is open for reading files inside it.
Definition: quazip.h:96
ZIP archive.
Definition: quazip.h:84

+ Here is the call graph for this function:

bool JlCompress::extractFile ( QuaZip zip,
QString  fileName,
QString  fileDest 
)
staticprivate

OK Estrae il file fileName, contenuto nell'oggetto zip, con il nome fileDest.

Parameters
zipThe opened zip archive to extract from.
fileNameThe full name of the file to extract.
fileDestThe full path to the destination file.
Returns
true if success, false otherwise.

Se la funzione fallisce restituisce false e cancella il file che si e tentato di estrarre.

La funzione fallisce se:

  • zip==NULL;
  • l'oggetto zip e stato aperto in una modalita non compatibile con l'estrazione di file;
  • non e possibile aprire il file all'interno dell'oggetto zip;
  • non e possibile creare il file estratto;
  • si e rilevato un errore nella copia dei dati (1);
  • non e stato possibile chiudere il file all'interno dell'oggetto zip (1);

(1): prima di uscire dalla funzione cancella il file estratto.

Definition at line 170 of file JlCompress.cpp.

References QuaZipFile::close(), copyData(), QuaZip::getCurrentFileInfo(), QuaZip::getMode(), QuaZipFileInfo64::getPermissions(), QuaZipFile::getZipError(), QuaZip::mdUnzip, QuaZipFile::open(), removeFile(), QuaZip::setCurrentFile(), and UNZ_OK.

Referenced by extractDir(), extractFile(), and extractFiles().

170  {
171  // zip: oggetto dove aggiungere il file
172  // filename: nome del file reale
173  // fileincompress: nome del file all'interno del file compresso
174 
175  // Controllo l'apertura dello zip
176  if (!zip) return false;
177  if (zip->getMode()!=QuaZip::mdUnzip) return false;
178 
179  // Apro il file compresso
180  if (!fileName.isEmpty())
181  zip->setCurrentFile(fileName);
182  QuaZipFile inFile(zip);
183  if(!inFile.open(QIODevice::ReadOnly) || inFile.getZipError()!=UNZ_OK) return false;
184 
185  // Controllo esistenza cartella file risultato
186  QDir curDir;
187  if (fileDest.endsWith('/')) {
188  if (!curDir.mkpath(fileDest)) {
189  return false;
190  }
191  } else {
192  if (!curDir.mkpath(QFileInfo(fileDest).absolutePath())) {
193  return false;
194  }
195  }
196 
197  QuaZipFileInfo64 info;
198  if (!zip->getCurrentFileInfo(&info))
199  return false;
200 
201  QFile::Permissions srcPerm = info.getPermissions();
202  if (fileDest.endsWith('/') && QFileInfo(fileDest).isDir()) {
203  if (srcPerm != 0) {
204  QFile(fileDest).setPermissions(srcPerm);
205  }
206  return true;
207  }
208 
209  // Apro il file risultato
210  QFile outFile;
211  outFile.setFileName(fileDest);
212  if(!outFile.open(QIODevice::WriteOnly)) return false;
213 
214  // Copio i dati
215  if (!copyData(inFile, outFile) || inFile.getZipError()!=UNZ_OK) {
216  outFile.close();
217  removeFile(QStringList(fileDest));
218  return false;
219  }
220  outFile.close();
221 
222  // Chiudo i file
223  inFile.close();
224  if (inFile.getZipError()!=UNZ_OK) {
225  removeFile(QStringList(fileDest));
226  return false;
227  }
228 
229  if (srcPerm != 0) {
230  outFile.setPermissions(srcPerm);
231  }
232  return true;
233 }
#define UNZ_OK
Definition: unzip.h:79
Mode getMode() const
Returns the mode in which ZIP file was opened.
Definition: quazip.cpp:614
static bool removeFile(QStringList listFile)
Remove some files.
Definition: JlCompress.cpp:241
QFile::Permissions getPermissions() const
Get the file permissions.
Information about a file inside archive (with zip64 support).
bool setCurrentFile(const QString &fileName, CaseSensitivity cs=csDefault)
Sets current file by its name.
Definition: quazip.cpp:408
ZIP file is open for reading files inside it.
Definition: quazip.h:96
A file inside ZIP archive.
Definition: quazipfile.h:74
static bool copyData(QIODevice &inFile, QIODevice &outFile)
Definition: JlCompress.cpp:29
bool getCurrentFileInfo(QuaZipFileInfo *info) const
Retrieves information about the current file.
Definition: quazip.cpp:492

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QString JlCompress::extractFile ( QString  fileCompressed,
QString  fileName,
QString  fileDest = QString() 
)
static

OK Estrae il file fileName, contenuto nel file fileCompressed, con il nome fileDest.

Parameters
fileCompressedThe name of the archive.
fileNameThe file to extract.
fileDestThe destination file, assumed to be identical to file if left empty.
Returns
The list of the full paths of the files extracted, empty on failure.

Se fileDest = "" allora il file viene estratto con lo stesso nome con cui e stato compresso. Se la funzione fallisce cancella il file che si e tentato di estrarre. Restituisce il nome assoluto del file estratto.

La funzione fallisce se:

  • non si riesce ad aprire l'oggetto zip;
  • l'estrazione del file fallisce;
  • non si riesce a chiudere l'oggetto zip;

Definition at line 377 of file JlCompress.cpp.

References QuaZip::close(), extractFile(), QuaZip::getZipError(), QuaZip::mdUnzip, QuaZip::open(), and removeFile().

377  {
378  // Apro lo zip
379  QuaZip zip(fileCompressed);
380  if(!zip.open(QuaZip::mdUnzip)) {
381  return QString();
382  }
383 
384  // Estraggo il file
385  if (fileDest.isEmpty())
386  fileDest = fileName;
387  if (!extractFile(&zip,fileName,fileDest)) {
388  return QString();
389  }
390 
391  // Chiudo il file zip
392  zip.close();
393  if(zip.getZipError()!=0) {
394  removeFile(QStringList(fileDest));
395  return QString();
396  }
397  return QFileInfo(fileDest).absoluteFilePath();
398 }
static bool removeFile(QStringList listFile)
Remove some files.
Definition: JlCompress.cpp:241
static bool extractFile(QuaZip *zip, QString fileName, QString fileDest)
Extract a single file.
Definition: JlCompress.cpp:170
ZIP file is open for reading files inside it.
Definition: quazip.h:96
ZIP archive.
Definition: quazip.h:84

+ Here is the call graph for this function:

QStringList JlCompress::extractFiles ( QString  fileCompressed,
QStringList  files,
QString  dir = QString() 
)
static

OK Estrae i file specificati in files, contenuti nel file fileCompressed, nella cartella dir.

Parameters
fileCompressedThe name of the archive.
filesThe file list to extract.
dirThe directory to put the files to, the current directory if left empty.
Returns
The list of the full paths of the files extracted, empty on failure.

La struttura a cartelle del file compresso viene rispettata. Se dir = "" allora il file viene estratto nella cartella corrente. Se la funzione fallisce cancella i file che si e tentato di estrarre. Restituisce i nomi assoluti dei file estratti.

La funzione fallisce se:

  • non si riesce ad aprire l'oggetto zip;
  • l'estrazione di un file fallisce;
  • non si riesce a chiudere l'oggetto zip;

Definition at line 412 of file JlCompress.cpp.

References QuaZip::close(), extractFile(), QuaZip::getZipError(), QuaZip::mdUnzip, QuaZip::open(), and removeFile().

412  {
413  // Creo lo zip
414  QuaZip zip(fileCompressed);
415  if(!zip.open(QuaZip::mdUnzip)) {
416  return QStringList();
417  }
418 
419  // Estraggo i file
420  QStringList extracted;
421  for (int i=0; i<files.count(); i++) {
422  QString absPath = QDir(dir).absoluteFilePath(files.at(i));
423  if (!extractFile(&zip, files.at(i), absPath)) {
424  removeFile(extracted);
425  return QStringList();
426  }
427  extracted.append(absPath);
428  }
429 
430  // Chiudo il file zip
431  zip.close();
432  if(zip.getZipError()!=0) {
433  removeFile(extracted);
434  return QStringList();
435  }
436 
437  return extracted;
438 }
static bool removeFile(QStringList listFile)
Remove some files.
Definition: JlCompress.cpp:241
static bool extractFile(QuaZip *zip, QString fileName, QString fileDest)
Extract a single file.
Definition: JlCompress.cpp:170
ZIP file is open for reading files inside it.
Definition: quazip.h:96
ZIP archive.
Definition: quazip.h:84

+ Here is the call graph for this function:

QStringList JlCompress::getFileList ( QString  fileCompressed)
static

OK Restituisce la lista dei file resenti nel file compresso fileCompressed.

Returns
The list of the files in the archive, or, more precisely, the list of the entries, including both files and directories if they are present separately.

Se la funzione fallisce, restituisce un elenco vuoto.

La funzione fallisce se:

  • non si riesce ad aprire l'oggetto zip;
  • la richiesta di informazioni di un file fallisce;
  • non si riesce a chiudere l'oggetto zip;

Definition at line 492 of file JlCompress.cpp.

References QuaZip::close(), QuaZip::getCurrentFileInfo(), QuaZip::getZipError(), QuaZip::goToFirstFile(), QuaZip::goToNextFile(), QuaZip::mdUnzip, QuaZipFileInfo64::name, and QuaZip::open().

492  {
493  // Apro lo zip
494  QuaZip* zip = new QuaZip(QFileInfo(fileCompressed).absoluteFilePath());
495  if(!zip->open(QuaZip::mdUnzip)) {
496  delete zip;
497  return QStringList();
498  }
499 
500  // Estraggo i nomi dei file
501  QStringList lst;
502  QuaZipFileInfo64 info;
503  for(bool more=zip->goToFirstFile(); more; more=zip->goToNextFile()) {
504  if(!zip->getCurrentFileInfo(&info)) {
505  delete zip;
506  return QStringList();
507  }
508  lst << info.name;
509  //info.name.toLocal8Bit().constData()
510  }
511 
512  // Chiudo il file zip
513  zip->close();
514  if(zip->getZipError()!=0) {
515  delete zip;
516  return QStringList();
517  }
518  delete zip;
519 
520  return lst;
521 }
bool goToFirstFile()
Sets the current file to the first file in the archive.
Definition: quazip.cpp:466
int getZipError() const
Returns the error code of the last operation.
Definition: quazip.cpp:624
bool goToNextFile()
Sets the current file to the next file in the archive.
Definition: quazip.cpp:478
Information about a file inside archive (with zip64 support).
ZIP file is open for reading files inside it.
Definition: quazip.h:96
void close()
Closes ZIP file.
Definition: quazip.cpp:324
ZIP archive.
Definition: quazip.h:84
bool open(Mode mode, zlib_filefunc_def *ioApi=NULL)
Opens ZIP file.
Definition: quazip.cpp:215
QString name
File name.
bool getCurrentFileInfo(QuaZipFileInfo *info) const
Retrieves information about the current file.
Definition: quazip.cpp:492

+ Here is the call graph for this function:

bool JlCompress::removeFile ( QStringList  listFile)
staticprivate

Rimuove i file il cui nome e specificato all'interno di listFile.

Parameters
listFileThe list of files to remove.
Returns
true if success, false otherwise.

Restituisce true se tutti i file sono stati cancellati correttamente, attenzione perche puo restituire false anche se alcuni file non esistevano e si e tentato di cancellarli.

Definition at line 241 of file JlCompress.cpp.

Referenced by extractDir(), extractFile(), and extractFiles().

241  {
242  bool ret = true;
243  // Per ogni file
244  for (int i=0; i<listFile.count(); i++) {
245  // Lo elimino
246  ret = ret && QFile::remove(listFile.at(i));
247  }
248  return ret;
249 }

+ Here is the caller graph for this function:


The documentation for this class was generated from the following files: