예제 #1
0
파일: main.c 프로젝트: OpenCPN/OpenCPN
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;
}
예제 #2
0
ArchFile::ArchFile(ar_stream *data, ar_archive *(* openFormat)(ar_stream *)) : data(data), ar(nullptr)
{
    if (data && openFormat)
        ar = openFormat(data);
    if (!ar)
        return;
    while (ar_parse_entry(ar)) {
        const char *name = ar_entry_get_name(ar);
        if (name)
            filenames.Append(str::conv::FromUtf8(name));
        else
            filenames.Append(nullptr);
        filepos.Append(ar_entry_get_offset(ar));
    }
    // extract (further) filenames with fallback in derived class constructor
    // once GetFileFromFallback has been correctly set in the vtable
}
예제 #3
0
const char * getName(ARCHIVE * archive)
{
	return ar_entry_get_name(archive->archive);
}