24 #include <tqptrlist.h>
25 #include <kmimetype.h>
28 #include "kfilterdev.h"
46 m_filename = filename;
48 setDevice(
new TQFile( filename ) );
64 if ( !m_filename.isEmpty() )
75 if (
mode == IO_WriteOnly )
77 if (
mode != IO_ReadOnly &&
mode != IO_ReadWrite )
79 kdWarning(7042) <<
"Unsupported mode " <<
mode << endl;
83 TQIODevice* dev =
device();
88 dev->readBlock (magic, 8);
89 if (tqstrncmp(magic,
"!<arch>", 7) != 0) {
90 kdWarning(7042) <<
"Invalid main magic" << endl;
94 char *ar_longnames = 0;
95 while (! dev->atEnd()) {
99 int date, uid, gid,
mode, size;
101 dev->at( dev->at() + (2 - (dev->at() % 2)) % 2 );
103 if ( dev->readBlock (ar_header.data(), 60) != 60 ) {
104 kdWarning(7042) <<
"Couldn't read header" << endl;
105 delete[] ar_longnames;
110 if (ar_header.right(2) !=
"`\n") {
111 kdWarning(7042) <<
"Invalid magic" << endl;
112 delete[] ar_longnames;
116 name = ar_header.mid( 0, 16 );
117 date = ar_header.mid( 16, 12 ).toInt();
118 uid = ar_header.mid( 28, 6 ).toInt();
119 gid = ar_header.mid( 34, 6 ).toInt();
120 mode = ar_header.mid( 40, 8 ).toInt();
121 size = ar_header.mid( 48, 10 ).toInt();
123 bool skip_entry =
false;
124 if (name.mid(0, 1) ==
"/") {
125 if (name.mid(1, 1) ==
"/") {
126 delete[] ar_longnames;
127 ar_longnames =
new char[size + 1];
128 ar_longnames[size] =
'\0';
129 dev->readBlock (ar_longnames, size);
131 kdDebug(7042) <<
"Read in longnames entry" << endl;
132 }
else if (name.mid(1, 1) ==
" ") {
133 kdDebug(7042) <<
"Skipped symbol entry" << endl;
134 dev->at( dev->at() + size );
137 kdDebug(7042) <<
"Longfilename #" << name.mid(1, 15).toInt() << endl;
138 if (! ar_longnames) {
139 kdWarning(7042) <<
"Invalid longfilename reference" << endl;
142 name = &ar_longnames[name.mid(1, 15).toInt()];
143 name = name.left(name.find(
"/"));
146 if (skip_entry)
continue;
148 name = name.stripWhiteSpace();
149 name.replace(
"/",
"" );
150 kdDebug(7042) <<
"Filename: " << name <<
" Size: " << size << endl;
156 dev->at( dev->at() + size );
158 delete[] ar_longnames;
169 void KAr::virtual_hook(
int id,
void* data )
170 { KArchive::virtual_hook(
id, data ); }
virtual bool closeArchive()
Closes the archive.
KAr(const TQString &filename)
Creates an instance that operates on the given filename.
virtual bool openArchive(int mode)
Opens the archive for reading.
virtual ~KAr()
If the ar file is still opened, then it will be closed automatically by the destructor.
A base class for entries in an KArchive.
Represents a file entry in a KArchive.
KArchive is a base class for reading and writing archives.
virtual KArchiveDirectory * rootDir()
Retrieves or create the root directory.
virtual void close()
Closes the archive.
int mode() const
Returns the mode in which the archive was opened.
bool isOpened() const
Checks whether the archive is open.
TQIODevice * device() const
The underlying device.