• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdeio
 

tdeio/tdeio

  • tdeio
  • tdeio
kar.cpp
1 
2 /* This file is part of the KDE libraries
3  Copyright (C) 2002 Laurence Anderson <l.d.anderson@warwick.ac.uk>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include <tqfile.h>
21 #include <tqdir.h>
22 #include <time.h>
23 #include <kdebug.h>
24 #include <tqptrlist.h>
25 #include <kmimetype.h>
26 #include <tqregexp.h>
27 
28 #include "kfilterdev.h"
29 #include "kar.h"
30 //#include "klimitediodevice.h"
31 
35 
36 class KAr::KArPrivate
37 {
38 public:
39  KArPrivate() {}
40 };
41 
42 KAr::KAr( const TQString& filename )
43  : KArchive( 0L )
44 {
45  //kdDebug(7042) << "KAr(filename) reached." << endl;
46  m_filename = filename;
47  d = new KArPrivate;
48  setDevice( new TQFile( filename ) );
49 }
50 
51 KAr::KAr( TQIODevice * dev )
52  : KArchive( dev )
53 {
54  //kdDebug(7042) << "KAr::KAr( TQIODevice * dev) reached." << endl;
55  d = new KArPrivate;
56 }
57 
58 KAr::~KAr()
59 {
60  // mjarrett: Closes to prevent ~KArchive from aborting w/o device
61  //kdDebug(7042) << "~KAr reached." << endl;
62  if( isOpened() )
63  close();
64  if ( !m_filename.isEmpty() )
65  delete device(); // we created it ourselves
66  delete d;
67 }
68 
69 bool KAr::openArchive( int mode )
70 {
71  // Open archive
72 
73  //kdDebug(7042) << "openarchive reached." << endl;
74 
75  if ( mode == IO_WriteOnly )
76  return true;
77  if ( mode != IO_ReadOnly && mode != IO_ReadWrite )
78  {
79  kdWarning(7042) << "Unsupported mode " << mode << endl;
80  return false;
81  }
82 
83  TQIODevice* dev = device();
84  if ( !dev )
85  return false;
86 
87  char magic[8];
88  dev->readBlock (magic, 8);
89  if (tqstrncmp(magic, "!<arch>", 7) != 0) {
90  kdWarning(7042) << "Invalid main magic" << endl;
91  return false;
92  }
93 
94  char *ar_longnames = 0;
95  while (! dev->atEnd()) {
96  TQCString ar_header;
97  ar_header.resize(61);
98  TQCString name;
99  int date, uid, gid, mode, size;
100 
101  dev->at( dev->at() + (2 - (dev->at() % 2)) % 2 ); // Ar headers are padded to byte boundary
102 
103  if ( dev->readBlock (ar_header.data(), 60) != 60 ) { // Read ar header
104  kdWarning(7042) << "Couldn't read header" << endl;
105  delete[] ar_longnames;
106  //return false;
107  return true; // Probably EOF / trailing junk
108  }
109 
110  if (ar_header.right(2) != "`\n") { // Check header magic
111  kdWarning(7042) << "Invalid magic" << endl;
112  delete[] ar_longnames;
113  return false;
114  }
115 
116  name = ar_header.mid( 0, 16 ); // Process header
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();
122 
123  bool skip_entry = false; // Deal with special entries
124  if (name.mid(0, 1) == "/") {
125  if (name.mid(1, 1) == "/") { // Longfilename table entry
126  delete[] ar_longnames;
127  ar_longnames = new char[size + 1];
128  ar_longnames[size] = '\0';
129  dev->readBlock (ar_longnames, size);
130  skip_entry = true;
131  kdDebug(7042) << "Read in longnames entry" << endl;
132  } else if (name.mid(1, 1) == " ") { // Symbol table entry
133  kdDebug(7042) << "Skipped symbol entry" << endl;
134  dev->at( dev->at() + size );
135  skip_entry = true;
136  } else { // Longfilename
137  kdDebug(7042) << "Longfilename #" << name.mid(1, 15).toInt() << endl;
138  if (! ar_longnames) {
139  kdWarning(7042) << "Invalid longfilename reference" << endl;
140  return false;
141  }
142  name = &ar_longnames[name.mid(1, 15).toInt()];
143  name = name.left(name.find("/"));
144  }
145  }
146  if (skip_entry) continue;
147 
148  name = name.stripWhiteSpace(); // Process filename
149  name.replace( "/", "" );
150  kdDebug(7042) << "Filename: " << name << " Size: " << size << endl;
151 
152  KArchiveEntry* entry;
153  entry = new KArchiveFile(this, name, mode, date, /*uid*/ 0, /*gid*/ 0, 0, dev->at(), size);
154  rootDir()->addEntry(entry); // Ar files don't support directorys, so everything in root
155 
156  dev->at( dev->at() + size ); // Skip contents
157  }
158  delete[] ar_longnames;
159 
160  return true;
161 }
162 
163 bool KAr::closeArchive()
164 {
165  // Close the archive
166  return true;
167 }
168 
169 void KAr::virtual_hook( int id, void* data )
170 { KArchive::virtual_hook( id, data ); }
KAr::closeArchive
virtual bool closeArchive()
Closes the archive.
Definition: kar.cpp:163
KAr::KAr
KAr(const TQString &filename)
Creates an instance that operates on the given filename.
Definition: kar.cpp:42
KAr::openArchive
virtual bool openArchive(int mode)
Opens the archive for reading.
Definition: kar.cpp:69
KAr::~KAr
virtual ~KAr()
If the ar file is still opened, then it will be closed automatically by the destructor.
Definition: kar.cpp:58
KArchiveEntry
A base class for entries in an KArchive.
Definition: karchive.h:396
KArchiveFile
Represents a file entry in a KArchive.
Definition: karchive.h:491
KArchive
KArchive is a base class for reading and writing archives.
Definition: karchive.h:43
KArchive::rootDir
virtual KArchiveDirectory * rootDir()
Retrieves or create the root directory.
Definition: karchive.cpp:368
KArchive::close
virtual void close()
Closes the archive.
Definition: karchive.cpp:108
KArchive::mode
int mode() const
Returns the mode in which the archive was opened.
Definition: karchive.h:90
KArchive::isOpened
bool isOpened() const
Checks whether the archive is open.
Definition: karchive.h:83
KArchive::device
TQIODevice * device() const
The underlying device.
Definition: karchive.h:96

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.9.1
This website is maintained by Timothy Pearson.