00001
00002 #include "zipios++/zipios-config.h"
00003
00004 #include <assert.h>
00005
00006 #include "zipios++/meta-iostreams.h"
00007 #include <string>
00008
00009 #include "zipios_common.h"
00010 #include "zipios++/basicentry.h"
00011 #include "zipios++/zipios_defs.h"
00012
00013 #include "outputstringstream.h"
00014
00015 namespace zipios {
00016
00017 using std::ifstream ;
00018 using std::ios ;
00019
00020
00021
00022
00023
00024 BasicEntry::BasicEntry( const string &filename, const string &comment,
00025 const FilePath &basepath )
00026 : _filename ( filename ),
00027 _comment ( comment ),
00028 _basepath ( basepath )
00029 {
00030 string full_path = _basepath + _filename ;
00031 ifstream is( full_path.c_str(), ios::in | ios::binary ) ;
00032 if ( ! is ) {
00033 _valid = false ;
00034 } else {
00035 is.seekg( 0, ios::end ) ;
00036 _size = is.tellg() ;
00037 is.close() ;
00038 _valid = true ;
00039 }
00040 }
00041
00042 string BasicEntry::getComment() const {
00043 return _comment ;
00044 }
00045
00046 uint32 BasicEntry::getCompressedSize() const {
00047 return getSize() ;
00048 }
00049
00050 uint32 BasicEntry::getCrc() const {
00051 return 0 ;
00052 }
00053
00054 vector< unsigned char > BasicEntry::getExtra() const {
00055 return vector< unsigned char > () ;
00056 }
00057
00058 StorageMethod BasicEntry::getMethod() const {
00059 return STORED ;
00060 }
00061
00062 string BasicEntry::getName() const {
00063 return _filename ;
00064 }
00065
00066 string BasicEntry::getFileName() const {
00067 if ( isDirectory() )
00068 return string() ;
00069 string::size_type pos ;
00070 pos = _filename.find_last_of( separator ) ;
00071 if ( pos != string::npos ) {
00072
00073 return _filename.substr(pos + 1) ;
00074 } else {
00075 return _filename ;
00076 }
00077 }
00078
00079 uint32 BasicEntry::getSize() const {
00080 return _size ;
00081 }
00082
00083 int BasicEntry::getTime() const {
00084 return 0 ;
00085 }
00086
00087 bool BasicEntry::isValid() const {
00088 return _valid ;
00089 }
00090
00091
00092 bool BasicEntry::isDirectory() const {
00093 assert( _filename.size() != 0 ) ;
00094 return _filename[ _filename.size() - 1 ] == separator ;
00095 }
00096
00097
00098 void BasicEntry::setComment( const string &comment ) {
00099 _comment = comment ;
00100 }
00101
00102 void BasicEntry::setCompressedSize( uint32 size ) {
00103 }
00104
00105 void BasicEntry::setCrc( uint32 crc ) {
00106 }
00107
00108 void BasicEntry::setExtra( const vector< unsigned char > &extra ) {
00109 }
00110
00111 void BasicEntry::setMethod( StorageMethod method ) {
00112 }
00113
00114 void BasicEntry::setName( const string &name ) {
00115 _filename = name ;
00116 }
00117
00118 void BasicEntry::setSize( uint32 size ) {
00119 _size = size ;
00120 }
00121
00122 void BasicEntry::setTime( int time ) {
00123 }
00124
00125
00126 string BasicEntry::toString() const {
00127 OutputStringStream sout ;
00128 sout << _filename << " (" << _size << " bytes)" ;
00129 return sout.str() ;
00130 }
00131
00132 FileEntry *BasicEntry::clone() const {
00133 return new BasicEntry( *this ) ;
00134 }
00135
00136 BasicEntry::~BasicEntry() {
00137 }
00138
00139
00140 }
00141
00146 00147 00148 00149 00150 00151 00152 00153 00154 00155 00156 00157 00158 00159 00160 00161 00162 00163