Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

filesystemzip.h

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002 
00003 this file is part of rcssserver3D
00004 Fri May 9 2003
00005 Copyright (C) 2002,2003 Koblenz University
00006 Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group
00007 $Id: filesystemzip.h,v 1.5 2004/04/18 16:21:56 rollmark Exp $
00008 
00009 This program is free software; you can redistribute it and/or modify
00010 it under the terms of the GNU General Public License as published by
00011 the Free Software Foundation; version 2 of the License.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with this program; if not, write to the Free Software
00020 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021 */
00022 #ifndef FILESYSTEMZIP_H__
00023 #define FILESYSTEMZIP_H__
00024 
00025 /*      \class FileSystemZIP
00026         $Id: filesystemzip.h,v 1.5 2004/04/18 16:21:56 rollmark Exp $
00027 
00028         FileSystemZIP - The ZIP File System
00029 
00030         This is a bit more tricky than the STD file system, since it uses a ZIP
00031         file as a virtual file system. Decompression is handled with ZLIB whereas
00032         the file format was decoded using custom ZIP-file reading routines ...
00033         handwritten.
00034 
00035         NOTE:
00036 
00037         HISTORY:
00038         30.08.01 - MK
00039         - Initial version
00040         26.01.02 - MR
00041         - added ForEachFile
00042         25.02.02 - MR
00043         - now using a hash map to search for contained files
00044         28.06.02 - MK
00045         - moved to Zeitgeist
00046 
00047         TODO:
00048 
00049         TOFIX:
00050 */
00051 #ifdef HAVE_CONFIG_H
00052 #include <config.h>
00053 #endif
00054 
00055 #ifdef HAVE_HASH_MAP
00056 #include <hash_map>
00057 #else
00058 #include <map>
00059 #endif
00060 
00061 #include <string>
00062 #include <zeitgeist/fileserver/filesystem.h>
00063 
00064 //Forward declarations needed
00065 namespace salt
00066 {
00067   class StdFile;
00068   class RFile;
00069 }
00070 
00071 class FileSystemZIP : public zeitgeist::FileSystem
00072 {
00073     // types
00074 protected:
00075     struct TLocalHeader
00076     {
00077         long    signature;
00078         short   version_needed;
00079         short   general_purpose;
00080         short   compression_method;
00081         short   last_mod_time;
00082         short   last_mod_date;
00083         long    crc32;
00084         unsigned long compressed_size;
00085         unsigned long uncompressed_size;
00086         short   filename_length;
00087         short   extra_field_length;
00088         char    *filename;
00089         char    *extra_field;
00090     };
00091 
00092     struct TFileHeader
00093     {
00094         long    signature;
00095         short   version_made;
00096         short   version_needed;
00097         short   general_purpose;
00098         short   compression_method;
00099         short   last_mod_time;
00100         short   last_mod_date;
00101         long    crc32;
00102         long    compressed_size;
00103         long    uncompressed_size;
00104         short   filename_length;
00105         short   extra_field_length;
00106         short   file_comment_length;
00107         short   disk_number_start;
00108         short   internal_file_attributes;
00109         long    external_file_attributes;
00110         long    relative_offset;
00111         char    *filename;
00112         char    *extra_field;
00113         char    *file_comment;
00114     };
00115 
00116     struct TCentralDirectoryEnd
00117     {
00118         long    signature;
00119         short   this_disk_no;
00120         short   cds_disk_no;
00121         short   num_entries_this_disk;
00122         short   num_entries_total;
00123         long    cd_size;
00124         long    offset_start_cd;
00125         short   zipfile_comment_length;
00126         char    *zipfile_comment;
00127     };
00128 
00129     struct TArchiveEntry
00130     {
00131         char                    *filename;
00132         long                    attr;
00133         long                    data;
00134     };
00135 
00136 #ifdef HAVE_HASH_MAP
00137     typedef std::hash_map<std::string, TArchiveEntry*> TEntryMap;
00138 #else
00139     typedef std::map<std::string, TArchiveEntry*> TEntryMap;
00140 #endif
00141 
00142     // functions
00143 public:
00144     FileSystemZIP();
00145     virtual ~FileSystemZIP();
00146 
00147     virtual void Clear();
00148     virtual boost::shared_ptr<salt::RFile>  Open(const std::string& inName);
00149     virtual bool SetPath(const std::string& inPath);
00150     virtual int ForEachFile(const std::string& expression, TCallback callback, void* param);
00151 
00152 protected:
00153     void AddArchiveEntry(TArchiveEntry *ae);
00154     void ZIPGetLocalHeader(TLocalHeader *lh);
00155     void ZIPGetFileHeader(TFileHeader *fh);
00156     void ZIPGetCentralDirectoryEnd(TCentralDirectoryEnd *cde);
00157     void ZIPGetCentralDirectoryEndFirst(TCentralDirectoryEnd *cde);
00158     void ZIPSkipData(TLocalHeader *lh);
00159 
00160     // members
00161 protected:
00162     boost::shared_ptr<salt::StdFile> mHandle;
00163     std::string mArchiveName;
00164     TEntryMap  mEntryMap;
00165 };
00166 
00167 DECLARE_CLASS(FileSystemZIP);
00168 
00169 #endif // FILESYSTEMZIP_H__

Generated on Thu Apr 6 15:25:37 2006 for rcssserver3d by  doxygen 1.4.4