2
#include "zipios-config.h"
4
#include "meta-iostreams.h"
10
#include "directory.h"
13
using namespace zipios;
15
DirectoryCollection::DirectoryCollection( const string &path, bool recursive,
17
: _entries_loaded( false ),
18
_recursive ( recursive ),
21
_filename = _filepath ;
22
_valid = _filepath.isDirectory() ;
24
if( _valid && load_now )
28
void DirectoryCollection::close() {
33
ConstEntries DirectoryCollection::entries() const {
35
throw InvalidStateException( "Attempt to use an invalid DirectoryCollection" ) ;
39
return FileCollection::entries() ;
44
DirectoryCollection::getEntry( const string &name,
45
MatchPath matchpath ) const {
47
throw InvalidStateException( "Attempt to use an invalid DirectoryCollection" ) ;
49
if ( matchpath != MATCH || _entries_loaded ) {
51
return FileCollection::getEntry( name, matchpath ) ;
53
// avoid loading entries if possible.
54
ConstEntryPointer ent ( new DirEntry( name, "", _filepath ) ) ;
63
istream *DirectoryCollection::getInputStream( const ConstEntryPointer &entry ) {
65
throw InvalidStateException( "Attempt to use an invalid DirectoryCollection" ) ;
67
return getInputStream( entry->getName() ) ;
71
std::istream *DirectoryCollection::getInputStream( const string &entry_name,
77
throw InvalidStateException( "Attempt to use an invalid DirectoryCollection" ) ;
79
if ( matchpath != MATCH || _entries_loaded ) {
82
ConstEntryPointer ent = getEntry( entry_name, matchpath ) ;
87
string real_path( _filepath + entry_name ) ;
88
return new ifstream( real_path.c_str(), ios::in | ios::binary ) ;
92
// avoid loading entries if possible.
93
string real_path( _filepath + entry_name ) ;
94
ifstream *ifs = new ifstream( real_path.c_str(), ios::in | ios::binary ) ;
104
int DirectoryCollection::size() const {
106
throw InvalidStateException( "Attempt to use an invalid DirectoryCollection" ) ;
109
return _entries.size() ;
112
FileCollection *DirectoryCollection::clone() const {
113
return new DirectoryCollection( *this ) ;
116
DirectoryCollection::~DirectoryCollection() {}
119
void DirectoryCollection::loadEntries() const {
120
if( _entries_loaded )
123
const_cast< DirectoryCollection * >( this )->load( _recursive ) ;
125
_entries_loaded = true ;
129
void DirectoryCollection::load( bool recursive, const FilePath &subdir ) {
130
using namespace boost::filesystem ;
132
for ( dir_it it( _filepath + subdir ) ; it != dir_it() ; ++it ) {
134
if ( *it == "." || *it == ".." || *it == "..." )
137
if ( get< is_directory >( it ) && recursive ) {
138
load( recursive, subdir + *it ) ;
140
_entries.push_back( ent = new BasicEntry( subdir + *it, "", _filepath ) ) ;
141
ent->setSize( get< boost::filesystem::size >( it ) ) ;
150
Implementation of DirectoryCollection.
154
Zipios++ - a small C++ library that provides easy access to .zip files.
155
Copyright (C) 2000 Thomas S�ndergaard
157
This library is free software; you can redistribute it and/or
158
modify it under the terms of the GNU Lesser General Public
159
License as published by the Free Software Foundation; either
160
version 2 of the License, or (at your option) any later version.
162
This library is distributed in the hope that it will be useful,
163
but WITHOUT ANY WARRANTY; without even the implied warranty of
164
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
165
Lesser General Public License for more details.
167
You should have received a copy of the GNU Lesser General Public
168
License along with this library; if not, write to the Free Software
169
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA