File indexing completed on 2025-01-26 04:14:57

0001 /*
0002  * Copyright (C) 2015 Dan Leinir Turthra Jensen <admin@leinir.dk>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Lesser General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2.1 of the License, or (at your option) version 3, or any
0008  * later version accepted by the membership of KDE e.V. (or its
0009  * successor approved by the membership of KDE e.V.), which shall
0010  * act as a proxy defined in Section 6 of version 3 of the license.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Lesser General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Lesser General Public
0018  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0019  *
0020  */
0021 
0022 #include "KRarFileEntry.h"
0023 
0024 #include <QDebug>
0025 
0026 extern "C"
0027 {
0028     #include <unarr.h>
0029 }
0030 
0031 class KRarFileEntry::Private {
0032 public:
0033     Private()
0034         : crc(0)
0035         , headerStart(0)
0036         , archive(nullptr)
0037         , rar(nullptr)
0038     {
0039     }
0040     unsigned long crc;
0041     qint64        headerStart;
0042     QString       path;
0043     ar_archive* archive;
0044     KRar* rar;
0045 };
0046 
0047 KRarFileEntry::KRarFileEntry(KRar* rar, const QString& name, int access, const QDateTime& date, const QString& user, const QString& group, const QString& symlink, const QString& path, qint64 start, qint64 uncompressedSize, struct ar_archive_s* archive)
0048     : KArchiveFile(rar, name, access, date, user, group, symlink, start, uncompressedSize)
0049     , d(new Private)
0050 {
0051     d->headerStart = start;
0052     d->path = path;
0053     d->rar = rar;
0054     d->archive = archive;
0055 //     qDebug() << "New entry for file" << name << "in path" << path;
0056 }
0057 
0058 KRarFileEntry::~KRarFileEntry()
0059 {
0060     delete d;
0061 }
0062 
0063 void KRarFileEntry::setHeaderStart(qint64 headerstart)
0064 {
0065     d->headerStart = headerstart;
0066 }
0067 qint64 KRarFileEntry::headerStart() const
0068 {
0069     return d->headerStart;
0070 }
0071 
0072 unsigned long KRarFileEntry::crc32() const
0073 {
0074     return d->crc;
0075 }
0076 
0077 void KRarFileEntry::setCRC32(unsigned long crc32)
0078 {
0079     d->crc = crc32;
0080 }
0081 
0082 const QString & KRarFileEntry::path() const
0083 {
0084     return d->path;
0085 }
0086 
0087 QByteArray KRarFileEntry::data() const
0088 {
0089 //     qDebug() << "Attempting to grab data from" << name() << "in" << path();
0090     QByteArray data;
0091 
0092     ar_archive* archive = d->archive;
0093     QString pathname = QString("%1/%2").arg(path()).arg(name());
0094     if(ar_parse_entry_at(archive, d->headerStart))
0095     {
0096         data.resize(size());
0097         if(!ar_entry_uncompress(archive, data.data(), size()))
0098         {
0099             qDebug() << "We got an error reading the data attempting to read" << pathname << " - error will be reported by unarr, see above";// << r << archive_error_string(archive);
0100         }
0101     }
0102     return data;
0103 }
0104 
0105 QIODevice * KRarFileEntry::createDevice() const
0106 {
0107     return nullptr;
0108 }