Ejemplo n.º 1
0
PatcherError FileUtils::mzArchiveStats(const std::string &path,
                                       FileUtils::ArchiveStats *stats,
                                       std::vector<std::string> ignore)
{
    assert(stats != nullptr);

    unzFile uf = mzOpenInputFile(path);

    if (!uf) {
        FLOGE("minizip: Failed to open for reading: {}", path);
        return PatcherError::createArchiveError(
                ErrorCode::ArchiveReadOpenError, path);
    }

    uint64_t count = 0;
    uint64_t totalSize = 0;
    std::string name;
    unz_file_info64 fi;
    memset(&fi, 0, sizeof(fi));

    int ret = unzGoToFirstFile(uf);
    if (ret != UNZ_OK) {
        mzCloseInputFile(uf);
        return PatcherError::createArchiveError(
                ErrorCode::ArchiveReadHeaderError, std::string());
    }

    do {
        if (!mzGetInfo(uf, &fi, &name)) {
            mzCloseInputFile(uf);
            return PatcherError::createArchiveError(
                    ErrorCode::ArchiveReadHeaderError, std::string());
        }

        if (std::find(ignore.begin(), ignore.end(), name) == ignore.end()) {
            ++count;
            totalSize += fi.uncompressed_size;
        }
    } while ((ret = unzGoToNextFile(uf)) == UNZ_OK);

    if (ret != UNZ_END_OF_LIST_OF_FILE) {
        mzCloseInputFile(uf);
        return PatcherError::createArchiveError(
                ErrorCode::ArchiveReadHeaderError, std::string());
    }

    mzCloseInputFile(uf);

    stats->files = count;
    stats->totalSize = totalSize;

    return PatcherError();
}
Ejemplo n.º 2
0
ErrorCode FileUtils::mzArchiveStats(const std::string &path,
                                    FileUtils::ArchiveStats *stats,
                                    std::vector<std::string> ignore)
{
    assert(stats != nullptr);

    MzUnzCtx *ctx = mzOpenInputFile(path);

    if (!ctx) {
        FLOGE("miniunz: Failed to open for reading: %s", path.c_str());
        return ErrorCode::ArchiveReadOpenError;
    }

    uint64_t count = 0;
    uint64_t totalSize = 0;
    std::string name;
    unz_file_info64 fi;
    memset(&fi, 0, sizeof(fi));

    int ret = unzGoToFirstFile(ctx->uf);
    if (ret != UNZ_OK) {
        FLOGE("miniunz: Failed to move to first file: %s",
              mzUnzErrorString(ret).c_str());
        mzCloseInputFile(ctx);
        return ErrorCode::ArchiveReadHeaderError;
    }

    do {
        if (!mzGetInfo(ctx->uf, &fi, &name)) {
            mzCloseInputFile(ctx);
            return ErrorCode::ArchiveReadHeaderError;
        }

        if (std::find(ignore.begin(), ignore.end(), name) == ignore.end()) {
            ++count;
            totalSize += fi.uncompressed_size;
        }
    } while ((ret = unzGoToNextFile(ctx->uf)) == UNZ_OK);

    if (ret != UNZ_END_OF_LIST_OF_FILE) {
        FLOGE("miniunz: Finished before EOF: %s",
              mzUnzErrorString(ret).c_str());
        mzCloseInputFile(ctx);
        return ErrorCode::ArchiveReadHeaderError;
    }

    mzCloseInputFile(ctx);

    stats->files = count;
    stats->totalSize = totalSize;

    return ErrorCode::NoError;
}