Example #1
0
/**
 * @brief Adds the content of a folder to the archive.
 * @param resourcesFolder Resources' folder.
 * @param folderName Folder to add to the archive.
 * @param archivedFile The archive file opened with QuaZip.
 */
void ExportManager::addToArchive(QDir resourcesFolder, QString folderName, QuaZipFile& archivedFile) {
	QDir folder = resourcesFolder.absolutePath() + QDir::separator() + folderName;
	QDirIterator it(folder.absolutePath());
	while(it.hasNext()) {
		QString filePath = it.next();
		QString filename = filePath;
		filename.remove(0, folder.absolutePath().size()+1);
		if(filename=="." || filename=="..") {
			continue;
		}
		QFile file(filePath);
		if(!file.open(QIODevice::ReadOnly)) {
			throw ExportException("Cannot open file "+filePath+".");
		}

		// Creates the file in the archive:
		QString filePathInArchive = filePath;
		filePathInArchive.remove(0, resourcesFolder.absolutePath().size()+1); // Removes '[..]/Resources/'.
		if(!archivedFile.open(QIODevice::WriteOnly, QuaZipNewInfo(filePathInArchive))) {
			throw ExportException("Cannot create file "+filePathInArchive+" in archive.");
		}

		// Writes the file's content:
		char c;
		while(file.getChar(&c) && archivedFile.putChar(c));
		archivedFile.close();
		file.close();
	}
}
Example #2
0
    foreach(QFileInfo fileInfo, files) {

        if (!fileInfo.isFile()) {
            continue;
        }

        QString fileNameWithRelativePath (fileInfo.filePath().remove(0, dir.absolutePath().length() + 1));

        inFile.setFileName(fileInfo.filePath());
        //KeyProvider kp;
        if (!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(fileNameWithRelativePath, fileInfo.filePath())/*, kp.GetKey().toAscii()*/)) {
          return false;
        }

        if (!inFile.open(QIODevice::ReadOnly)) {
            return false;
        }

        while (inFile.getChar(&c) && outFile.putChar(c));

        if (outFile.getZipError() != UNZ_OK) {
            return false;
        }

        outFile.close();

        if (outFile.getZipError() != UNZ_OK) {
            return false;
        }

        inFile.close();
    }
Example #3
0
void QZip::zipDir(QuaZipFile &outFile,const QString &zipPath,const QString &zipTPath){
    QDir dir(zipPath);
    dir.setCurrent(zipPath);
    QFileInfoList files=dir.entryInfoList();

    QFile inFile;
    char c;
    foreach(QFileInfo file, files) {
        if(file.isDir()){
            if(!file.absoluteFilePath().endsWith(".")){
                QString zipDirecName = zipTPath==""?file.fileName():zipTPath+"\\"+file.fileName();
                zipDir(outFile,file.absoluteFilePath(),zipDirecName);
                dir.setCurrent(zipPath);
            }
            continue;//
        }
        inFile.setFileName(file.fileName());
        if(!inFile.open(QIODevice::ReadOnly)) {
            qWarning("testCreate(): inFile.open(): %s", inFile.errorString().toLocal8Bit().constData());
            return;
        }
        QString zipDirName = zipTPath==""?inFile.fileName():zipTPath+"\\"+inFile.fileName();
        if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(zipDirName, inFile.fileName()))) {
            qWarning("testCreate(): outFile.open(): %d", outFile.getZipError());
            return;
        }
        while(inFile.getChar(&c)&&outFile.putChar(c));
        if(outFile.getZipError()!=UNZ_OK) {
            qWarning("testCreate(): outFile.putChar(): %d", outFile.getZipError());
            return;
        }
        outFile.close();
        if(outFile.getZipError()!=UNZ_OK) {
            qWarning("testCreate(): outFile.close(): %d", outFile.getZipError());
            return;
        }
        inFile.close();
    }
}