22 #include <QtCore/QFile> 23 #include <QtCore/QDir> 27 #include <QtCore/QRegExp> 43 :
KArchive( filename ), d(new KArPrivate)
60 qint64, mode_t, time_t, time_t, time_t )
71 mode_t, time_t, time_t, time_t )
77 const QString&, mode_t, time_t, time_t, time_t )
86 if (
mode == QIODevice::WriteOnly )
88 if (
mode != QIODevice::ReadOnly &&
mode != QIODevice::ReadWrite )
98 QByteArray magic = dev->read( 7 );
99 if ( magic !=
"!<arch>" ) {
100 kWarning(7042) <<
"Invalid main magic";
104 char *ar_longnames = 0;
105 while (! dev->atEnd()) {
106 QByteArray ar_header;
107 ar_header.resize(61);
109 int date, uid, gid,
mode;
112 dev->seek( dev->pos() + (2 - (dev->pos() % 2)) % 2 );
114 if ( dev->read(ar_header.data(), 60) != 60 ) {
115 kWarning(7042) <<
"Couldn't read header";
116 delete[] ar_longnames;
121 if (!ar_header.endsWith(
"`\n")) {
123 delete[] ar_longnames;
127 name = ar_header.mid( 0, 16 );
128 date = ar_header.mid( 16, 12 ).toInt();
129 uid = ar_header.mid( 28, 6 ).toInt();
130 gid = ar_header.mid( 34, 6 ).toInt();
131 mode = ar_header.mid( 40, 8 ).toInt();
132 size = ar_header.mid( 48, 10 ).toInt();
134 bool skip_entry =
false;
135 if (name.mid(0, 1) ==
"/") {
136 if (name.mid(1, 1) ==
"/") {
137 delete[] ar_longnames;
138 ar_longnames =
new char[size + 1];
139 ar_longnames[size] =
'\0';
140 dev->read(ar_longnames, size);
142 kDebug(7042) <<
"Read in longnames entry";
143 }
else if (name.mid(1, 1) ==
" ") {
144 kDebug(7042) <<
"Skipped symbol entry";
145 dev->seek( dev->pos() + size );
148 kDebug(7042) <<
"Longfilename #" << name.mid(1, 15).toInt();
149 if (! ar_longnames) {
150 kWarning(7042) <<
"Invalid longfilename reference";
151 delete[] ar_longnames;
154 name = &ar_longnames[name.mid(1, 15).toInt()];
155 name = name.left(name.indexOf(
"/"));
158 if (skip_entry)
continue;
160 name = name.trimmed();
161 name.replace(
'/', QByteArray() );
162 kDebug(7042) <<
"Filename: " << name <<
" Size: " << size;
169 dev->seek( dev->pos() + size );
171 delete[] ar_longnames;
virtual bool closeArchive()
Closes the archive.
virtual bool openArchive(QIODevice::OpenMode mode)
Opens the archive for reading.
virtual void virtual_hook(int id, void *data)
virtual KArchiveDirectory * rootDir()
Retrieves or create the root directory.
KArchive is a base class for reading and writing archives.
QIODevice * device() const
The underlying device.
virtual bool close()
Closes the archive.
A base class for entries in an KArchive.
virtual bool doWriteSymLink(const QString &name, const QString &target, const QString &user, const QString &group, mode_t perm, time_t atime, time_t mtime, time_t ctime)
Writes a symbolic link to the archive.
virtual bool doPrepareWriting(const QString &name, const QString &user, const QString &group, qint64 size, mode_t perm, time_t atime, time_t mtime, time_t ctime)
This virtual method must be implemented by subclasses.
virtual bool doWriteDir(const QString &name, const QString &user, const QString &group, mode_t perm, time_t atime, time_t mtime, time_t ctime)
Write a directory to the archive.
void addEntry(KArchiveEntry *)
KAr(const QString &filename)
Creates an instance that operates on the given filename.
virtual void virtual_hook(int id, void *data)
Represents a file entry in a KArchive.
bool isOpen() const
Checks whether the archive is open.
virtual ~KAr()
If the ar file is still opened, then it will be closed automatically by the destructor.
QIODevice::OpenMode mode() const
Returns the mode in which the archive was opened.
virtual bool doFinishWriting(qint64 size)
Called after writing the data.