kzip.h
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2002 Holger Schroeder <holger-kde@holgis.net> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License version 2 as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 00017 */ 00018 #ifndef __kzip_h 00019 #define __kzip_h 00020 00021 #include <sys/stat.h> 00022 #include <sys/types.h> 00023 00024 #include <tqdatetime.h> 00025 #include <tqstring.h> 00026 #include <tqstringlist.h> 00027 #include <tqdict.h> 00028 #include <tqvaluelist.h> 00029 #include <karchive.h> 00030 00031 class KZipFileEntry; 00053 class TDEIO_EXPORT KZip : public KArchive 00054 { 00055 public: 00062 KZip( const TQString& filename ); 00063 00071 KZip( TQIODevice * dev ); 00072 00077 virtual ~KZip(); 00078 00084 TQString fileName() { return m_filename; } 00085 00089 enum ExtraField { NoExtraField = 0, 00090 ModificationTime = 1, 00091 DefaultExtraField = 1 00092 }; 00093 00100 void setExtraField( ExtraField ef ); 00101 00107 ExtraField extraField() const; 00108 00112 enum Compression { NoCompression = 0, 00113 DeflateCompression = 1 00114 }; 00115 00116 00123 void setCompression( Compression c ); 00124 00130 Compression compression() const; 00131 00143 virtual bool writeFile( const TQString& name, const TQString& user, const TQString& group, uint size, const char* data ); // BC: remove reimplementation for KDE-4.0 00144 00154 virtual bool prepareWriting( const TQString& name, const TQString& user, const TQString& group, uint size ); 00155 00156 // TODO(BIC) make virtual. For now it must be implemented by virtual_hook. 00157 bool writeSymLink(const TQString &name, const TQString &target, 00158 const TQString &user, const TQString &group, 00159 mode_t perm, time_t atime, time_t mtime, time_t ctime); 00160 // TODO(BIC) make virtual. For now it must be implemented by virtual_hook. 00161 bool prepareWriting( const TQString& name, const TQString& user, 00162 const TQString& group, uint size, mode_t perm, 00163 time_t atime, time_t mtime, time_t ctime ); 00164 // TODO(BIC) make virtual. For now it must be implemented by virtual_hook. 00165 bool writeFile( const TQString& name, const TQString& user, const TQString& group, 00166 uint size, mode_t perm, time_t atime, time_t mtime, 00167 time_t ctime, const char* data ); 00174 bool writeData( const char* data, uint size ); // TODO make virtual 00175 00181 virtual bool doneWriting( uint size ); 00182 00183 protected: 00190 virtual bool openArchive( int mode ); 00192 virtual bool closeArchive(); 00193 00197 virtual bool writeDir( const TQString& name, const TQString& user, const TQString& group); 00198 // TODO(BIC) uncomment and make virtual for KDE 4. 00199 // bool writeDir( const TQString& name, const TQString& user, const TQString& group, 00200 // mode_t perm, time_t atime, time_t mtime, time_t ctime ); 00201 00202 protected: 00203 virtual void virtual_hook( int id, void* data ); 00205 // from KArchive 00206 bool writeData_impl( const char* data, uint size ); 00207 bool prepareWriting_impl(const TQString& name, const TQString& user, 00208 const TQString& group, uint size, mode_t perm, 00209 time_t atime, time_t mtime, time_t ctime); 00210 bool writeSymLink_impl(const TQString &name, const TQString &target, 00211 const TQString &user, const TQString &group, 00212 mode_t perm, time_t atime, time_t mtime, time_t ctime); 00213 private: 00214 void abort(); 00215 00216 private: 00217 TQString m_filename; 00218 class KZipPrivate; 00219 KZipPrivate * d; 00220 }; 00221 00222 00226 class TDEIO_EXPORT KZipFileEntry : public KArchiveFile 00227 { 00228 public: 00229 /*KZipFileEntry() : st(-1) 00230 {}*/ 00231 KZipFileEntry( KZip* zip, const TQString& name, int access, int date, 00232 const TQString& user, const TQString& group, const TQString& symlink, 00233 const TQString& path, TQ_LONG start, TQ_LONG uncompressedSize, 00234 int encoding, TQ_LONG compressedSize) : 00235 KArchiveFile( zip, name, access, date, user, group, symlink, 00236 start, uncompressedSize ), 00237 m_crc(0), 00238 m_compressedSize(compressedSize), 00239 m_headerStart(0), 00240 m_encoding(encoding), 00241 m_path( path ) 00242 {} 00243 int encoding() const { return m_encoding; } 00244 TQ_LONG compressedSize() const { return m_compressedSize; } 00245 00247 void setCompressedSize(TQ_LONG compressedSize) { m_compressedSize = compressedSize; } 00248 00250 void setHeaderStart(TQ_LONG headerstart) { m_headerStart = headerstart; } 00251 TQ_LONG headerStart() const {return m_headerStart; } 00252 00254 unsigned long crc32() const { return m_crc; } 00255 void setCRC32(unsigned long crc32) { m_crc=crc32; } 00256 00258 TQString path() const { return m_path; } 00259 00264 virtual TQByteArray data() const; 00265 00273 TQIODevice* device() const; // WARNING, not virtual! 00274 00275 private: 00276 unsigned long m_crc; 00277 TQ_LONG m_compressedSize; 00278 TQ_LONG m_headerStart; 00279 int m_encoding; 00280 TQString m_path; 00281 // KDE4: d pointer or at least some int for future extensions 00282 }; 00283 00284 #endif