コード例 #1
0
ファイル: qunzip.cpp プロジェクト: acassis/lintouch
bool QUnZip::getCurrentFile(QIODevice &d) {
    if (!isOpen()) {
        qWarning("QUnZip::locateFile File not open.");
        return false;
    }
    if (!d.isWritable()) {
        qWarning("QUnZip::getCurrentFile File not open for writing.");
        return false;
    }
    if (unzOpenCurrentFile(_d->_unzFile) != UNZ_OK) {
        qWarning("QUnZip::getCurrentFile unzOpenCurrentFile failed.");
        return false;
    }
    char * buf = new char[1024];
    Q_CHECK_PTR(buf);
    int len;
    while ((len = ::unzReadCurrentFile(_d->_unzFile,
                buf, 1024)) > 0) {
        d.writeBlock(buf, len);
    }
    delete []buf;
    ::unzCloseCurrentFile(_d->_unzFile);
    if (d.isBuffered())
        d.flush();
    if (len == 0) {
        return true;
    }
    qWarning("QUnZip::getCurrentFile unzReadCurrentFile failed.");
    return false;
}
コード例 #2
0
ファイル: qunzip.cpp プロジェクト: acassis/lintouch
bool QUnZip::getCurrentFileRaw(QIODevice &d, int &method,
        unsigned long &crc, unsigned long &uncompressed_size) {
    if (!isOpen()) {
        qWarning("QUnZip::getCurrentFileRaw File not open.");
        return false;
    }
    if (!d.isWritable()) {
        qWarning("QUnZip::getCurrentFileRaw File not open for writing.");
        return false;
    }
    if (unzOpenCurrentFile2(_d->_unzFile, &method, NULL, 1) != UNZ_OK) {
        qWarning("QUnZip::getCurrentFileRaw unzOpenCurrentFile2 failed.");
        return false;
    }
    unz_file_info fi;
    if (::unzGetCurrentFileInfo(_d->_unzFile, &fi,
                NULL, 0 , NULL, 0, NULL, 0) != UNZ_OK) {
        qWarning("QUnZip::getCurrentFileRaw unzGetCurrentFileInfo failed.");
        return false;
    }
    crc = fi.crc;
    uncompressed_size = fi.uncompressed_size;

    char * buf = new char[1024];
    Q_CHECK_PTR(buf);
    int len;
    while ((len = ::unzReadCurrentFile(_d->_unzFile,
                buf, 1024)) > 0) {
        d.writeBlock(buf, len);
    }
    delete[] buf;
    ::unzCloseCurrentFile(_d->_unzFile);
    if (d.isBuffered())
        d.flush();
    if (len == 0) {
        return true;
    }
    qWarning("QUnZip::getCurrentFileRaw unzReadCurrentFile failed.");
    return false;
}