Example #1
0
int main(int argc, char *argv[])
{
    ar_stream *stream = NULL;
    ar_archive *ar = NULL;
    int entry_count = 1;
    int entry_skips = 0;
    int error_step = 1;

#if !defined(NDEBUG) && defined(_MSC_VER)
    if (!IsDebuggerPresent()) {
        _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
        _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
    }
    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif

    FailIf(argc != 2, "Syntax: %s <filename.ext>", argv[0]);

    stream = ar_open_file(argv[1]);
    FailIf(!stream, "Error: File \"%s\" not found!", argv[1]);

    printf("Parsing \"%s\":\n", argv[1]);
    ar = ar_open_any_archive(stream, strrchr(argv[1], '.'));
    FailIf(!ar, "Error: No valid %s archive!", "RAR, ZIP, 7Z or TAR");

    while (ar_parse_entry(ar)) {
        size_t size = ar_entry_get_size(ar);
        printf("%02d. %s (@%" PRIi64 ")\n", entry_count++, ar_entry_get_name(ar), ar_entry_get_offset(ar));
        while (size > 0) {
            unsigned char buffer[1024];
            size_t count = size < sizeof(buffer) ? size : sizeof(buffer);
            if (!ar_entry_uncompress(ar, buffer, count))
                break;
            size -= count;
        }
        if (size > 0) {
            fprintf(stderr, "Warning: Failed to uncompress... skipping\n");
            entry_skips++;
        }
    }
    FailIf(!ar_at_eof(ar), "Error: Failed to parse entry %d!", entry_count);
    error_step = entry_skips > 0 ? 1000 + entry_skips : 0;

CleanUp:
    ar_close_archive(ar);
    ar_close(stream);
    return error_step;
}
Example #2
0
bool isEOF(ARCHIVE * archive)
{
	return ar_at_eof(archive->archive);
}
Example #3
0
void RarFile::ExtractFilenamesWithFallback()
{
    if (!ar || !ar_at_eof(ar))
        (void)GetFileFromFallback((size_t)-1);
}