File: k7ziptest.cpp

package info (click to toggle)
karchive 5.116.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,436 kB
  • sloc: cpp: 10,083; python: 37; sh: 14; makefile: 5
file content (76 lines) | stat: -rw-r--r-- 2,273 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 *  SPDX-FileCopyrightText: 2011 Mario Bensi <mbensi@ipsquad.net>
 *
 *  SPDX-License-Identifier: LGPL-2.0-or-later
 */

#include "k7zip.h"

#include <QDebug>

#include <stdio.h>

void recursive_print(const KArchiveDirectory *dir, const QString &path)
{
    QStringList l = dir->entries();
    l.sort();
    QStringList::ConstIterator it = l.constBegin();
    for (; it != l.constEnd(); ++it) {
        const KArchiveEntry *entry = dir->entry((*it));
        printf("mode=%07o %s %s %s %s%s %lld isdir=%d\n",
               entry->permissions(),
               entry->date().toString(QStringLiteral("yyyy-MM-dd hh:mm:ss")).toLatin1().constData(),
               entry->user().toLatin1().constData(),
               entry->group().toLatin1().constData(),
               path.toLatin1().constData(),
               (*it).toLatin1().constData(),
               entry->isFile() ? static_cast<const KArchiveFile *>(entry)->size() : 0,
               entry->isDirectory());
        if (!entry->symLinkTarget().isEmpty()) {
            printf("  (symlink to %s)\n", qPrintable(entry->symLinkTarget()));
        }
        if (entry->isDirectory()) {
            recursive_print((KArchiveDirectory *)entry, path + (*it) + '/');
        }
        if (entry->isFile()) {
            const KArchiveFile *f = static_cast<const KArchiveFile *>(entry);
            QByteArray arr(f->data());
            qDebug() << "data" << arr;

            QIODevice *dev = f->createDevice();
            QByteArray contents = dev->readAll();
            qDebug() << "contents" << contents;
            delete dev;
        }
    }
}

// See karchivetest.cpp for the unittest that covers K7Zip.

int main(int argc, char **argv)
{
    if (argc != 2) {
        printf(
            "\n"
            " Usage :\n"
            " ./k7ziptest /path/to/existing_file.7z       tests listing an existing .7z\n");
        return 1;
    }

    K7Zip k7z(argv[1]);

    if (!k7z.open(QIODevice::ReadOnly)) {
        printf("Could not open %s for reading\n", argv[1]);
        return 1;
    }

    const KArchiveDirectory *dir = k7z.directory();

    // printf("calling recursive_print\n");
    recursive_print(dir, QLatin1String(""));
    // printf("recursive_print called\n");

    k7z.close();

    return 0;
}