#include "zipios++/fcollexceptions.h"
#include "zipios++/fileentry.h"
namespace zipios {
using std::vector;
/** \anchor fcoll_anchor
FileCollection is an abstract baseclass that represents a
collection of files. The specializations of FileCollection
represents different origins of file collections, such as
directories, simple filename lists and compressed archives. */
class FileCollection {
public:
/** FileCollection constructor. */
explicit FileCollection()
: _filename( "-" ),
_entries ( 0 ),
_valid ( false ) {}
/** Copy constructor. */
inline FileCollection( const FileCollection &src ) ;
/** Copy assignment operator. */
inline const FileCollection &operator= ( const FileCollection &src ) ;
/** Closes the FileCollection. */
virtual void close() = 0 ;
/** \anchor fcoll_entries_anchor
Returns a vector of const pointers to the entries in the
FileCollection.
@return a ConstEntries
containing the entries of the FileCollection.
@throw InvalidStateException Thrown if the collection is invalid. */
virtual ConstEntries entries() const ;
enum MatchPath { IGNORE, MATCH } ;
/** \anchor fcoll_getentry_anchor
Returns a ConstEntryPointer to a FileEntry object for the entry
with the specified name. To ignore the path part of the filename in search of a
match, specify FileCollection::IGNORE as the second argument.
@param name A string containing the name of the entry to get.
@param matchpath Speficy MATCH, if the path should match as well,
specify IGNORE, if the path should be ignored.
@return A ConstEntryPointer to the found entry. The returned pointer
equals zero if no entry is found.
@throw InvalidStateException Thrown if the collection is invalid. */
virtual ConstEntryPointer getEntry( const string &name,
MatchPath matchpath = MATCH ) const ;
/** \anchor fcoll_getinputstream
Returns a pointer to an opened istream for the specified
FileEntry. It is the callers responsibility to delete the stream
when he is done with it. Returns 0, if there is no such
FileEntry in the FileCollection.
@param entry A ConstEntryPointer to the FileEntry to get an istream to.
@return an open istream for the specified entry. The istream is allocated on
heap and it is the users responsibility to delete it when he is done with it.
@throw InvalidStateException Thrown if the collection is invalid. */
virtual istream *getInputStream( const ConstEntryPointer &entry ) = 0 ;
/** Returns a pointer to an opened istream for the specified
entry name. It is the callers responsibility to delete the stream
when he is done with it. Returns 0, if there is no entry with the specified
name in the FileCollection.
@param matchpath Speficy MATCH, if the path should match as well,
specify IGNORE, if the path should be ignored.
@return an open istream for the specified entry. The istream is allocated on
heap and it is the users responsibility to delete it when he is done with it.
@throw InvalidStateException Thrown if the collection is invalid. */
virtual istream *getInputStream( const string &entry_name,
MatchPath matchpath = MATCH ) = 0 ;
/** Returns the name of the FileCollection.
@return the name of the FileCollection.
@throw InvalidStateException Thrown if the collection is invalid. */
virtual string getName() const ;
/** Returns the number of entries in the FileCollection.
@return the number of entries in the FileCollection.
@throw InvalidStateException Thrown if the collection is invalid. */
virtual int size() const ;
/** The member function returns true if the collection is valid.
@return true if the collection is valid.
*/
bool isValid() const { return _valid ; }
/** Create a heap allocated clone of the object this method is called for. The
caller is responsible for deallocating the clone when he is done with it.
@return A heap allocated copy of the object this method is called for.
*/
virtual FileCollection *clone() const = 0 ;
/** FileCollection destructor. */
virtual ~FileCollection () ;
protected:
string _filename ;
Entries _entries ;
bool _valid ;
};
//
// Inline methods
//
FileCollection::FileCollection( const FileCollection &src )
: _filename( src._filename ),
_valid ( src._valid )
{
_entries.reserve( src._entries.size() ) ;
Entries::const_iterator it ;
for ( it = src._entries.begin() ; it != src._entries.end() ; ++it )
_entries.push_back( (*it)->clone() ) ;
}
const FileCollection &FileCollection::operator= ( const FileCollection &src ) {
if ( this != &src ) {
_filename = src._filename ;
_valid = src._valid ;
_entries.clear() ;
_entries.reserve( src._entries.size() ) ;
Entries::const_iterator it ;
for ( it = src._entries.begin() ; it != src._entries.end() ; ++it )
_entries.push_back( (*it)->clone() ) ;
}
return *this ;
}
inline ostream & operator<< (ostream &os, const FileCollection& collection) {
os << "collection '" << collection.getName() << "' {" ;
ConstEntries entries = collection.entries();
ConstEntries::const_iterator it;
bool isFirst=true;
for (it=entries.begin(); it != entries.end(); ++it) {
if(! isFirst)
os << ", ";
isFirst = false;
os << (*it)->getName();
}
os << "}";
return os;
}
} // namespace
#endif
/**
\mainpage Zipios++
\image html zipios++.jpg
\image latex zipios++.eps width=10cm
\section intro Introduction
Zipios++ is a java.util.zip-like C++ library for reading and
writing Zip files. Access to individual entries is provided through
standard C++ iostreams. A simple read-only virtual file system that
mounts regular directories and zip files is also provided.
The source code is released under the GNU Lesser General Public
License.
\section status Status
Spanned archives are not supported, and support is not planned.
The library has been tested and appears to be working with
- FreeBSD stable and current / gcc 2.95.3
- Red Hat Linux release 7.0 / gcc 2.96
- Red Hat Linux release 6.2 (Zoot) / egcs-2.91.66
- Linux Mandrake release 7.0 (Air) / gcc 2.95.2
- SGI IRIX64 6.5 / gcc 2.95.2
- SGI IRIX64 6.5 / MIPSpro Compilers: Version 7.30
If you are aware of any other platforms that Zipios++ works on,
please let me know (thomass@deltadata.dk).
\section documentation Documentation
This web page is the front page to the library documentation which
is generated from the source files using Doxygen. Use
the links at the top of the page to browse the API
documentation. The documentation is also available in
a printer-friendly format [pdf].
\subsection zipfiles Zip file access
The two most important classes are \ref zipfile_anchor "ZipFile" and
\ref ZipInputStream_anchor "ZipInputStream". ZipInputStream is an istream
for reading zipfiles. It can be instantiated directly, without the
use of ZipFile. \ref ZipInputStream_getnextentry_anchor
"ZipInputStream::getNextEntry()" positions the new ZipInputStream at the
first entry. The following entry can be accessed by calling
\ref ZipInputStream_getnextentry_anchor "ZipInputStream::getNextEntry()"
again.
ZipFile scans the central directory of a zipfile and provides an
interface to access that directory. The user may search for entries
with a particular filename using \ref fcoll_getentry_anchor "ZipFile::getEntry()",
or simply get the complete list of entries
with \ref fcoll_entries_anchor "ZipFile::entries()". To get an
istream (ZipInputStream) to a particular entry simply use
\ref fcoll_getinputstream "ZipFile::getInputStream()".
\ref example_zip_anchor "example_zip.cpp" demonstrates the central
elements of Zipios++.
A Zip file appended to another file, e.g. a binary program, with the program
\ref appendzip_anchor "appendzip", can be read with
\ref zipfile_openembeddedzipfile "ZipFile::openEmbeddedZipFile()".
\subsection filecollections FileCollections
A ZipFile is actually just a special kind of
\ref fcoll_anchor "FileCollection" that
obtains its entries from a .zip Zip archive. Zipios++ also implements
a \ref dircol_anchor "DirectoryCollection" that obtains its entries
from a specified directory, and a \ref collcoll_anchor "CollectionCollection"
that obtains its entries from
other collections. Using a single CollectionCollection any number of
other FileCollections can be placed under its control and accessed
through the same single interface that is used to access a ZipFile or
a DirectoryCollection. A singleton (a unique global instance)
CollectionCollection can be obtained through
\ref collcoll_inst_anchor "CollectionCollection::inst()" ;
To save typing CollectionCollection has been typedef'ed to CColl. In
the initialization part of an application FileCollections can be
created, and placed under CColll::inst()'s control using
\ref collcoll_addcoll_anchor "CColl::inst().addCollection()"
and later an istream can be obtained using
\ref fcoll_getinputstream "CColl::inst().getInputStream()".
\section download Download
Go to Zipios++ project page on SourceForge for tar balls and ChangeLog.
http://sourceforge.net/project/?group_id=5418
\section links Links
zlib.
The compression library that Zipios++ uses to perform the actual
decompression.
Java 2 Platform, Standard Edition, v 1.3 API Specification
. Zipios++ is heavily inspired by the java.util.zip package.
PKWARE zip format
. A description of the zip file format.
\section bugs Bugs
Submit bug reports and patches to thomass@deltadata.dk
\htmlonly
Project hosted by
Logo created with
\endhtmlonly */
/** \file
Header file that defines FileCollection.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/zipios++/gzipoutputstreambuf.h 0000644 0001750 0001750 00000004072 12104305064 022061 0 ustar don don #ifndef GZIPOUTPUTSTREAMBUF_H
#define GZIPOUTPUTSTREAMBUF_H
#include "zipios++/zipios-config.h"
#include
#include
#include "zipios++/deflateoutputstreambuf.h"
namespace zipios {
/** GZIPOutputStreambuf is a zip output streambuf filter. */
class GZIPOutputStreambuf : public DeflateOutputStreambuf {
public:
/** GZIPOutputStreambuf constructor. A newly constructed GZIPOutputStreambuf
is ready to accept data.
@param outbuf the streambuf to use for output.
@param del_outbuf if true is specified outbuf will be deleted, when
the GZIPOutputStreambuf is destructed. */
explicit GZIPOutputStreambuf( streambuf *outbuf, bool del_outbuf = false ) ;
void setFilename( const string &filename );
void setComment( const string &comment );
/** Calls finish. */
void close() ;
/** Finishes the compression. */
void finish() ;
/** Destructor. */
virtual ~GZIPOutputStreambuf() ;
protected:
virtual int overflow( int c = EOF ) ;
virtual int sync() ;
private:
void writeHeader();
void writeTrailer();
void writeInt(uint32 i);
std::string _filename;
std::string _comment;
bool _open ;
};
} // namespace
#endif
/** \file
Header file that defines ZipOutputStreambuf.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/ 0000755 0001750 0001750 00000000000 12104305064 014666 5 ustar don don flightcrew-0.7.2/src/zipios/src/filterinputstreambuf.cpp 0000644 0001750 0001750 00000002430 12104305064 021647 0 ustar don don
#include "zipios++/zipios-config.h"
#include "zipios++/filterinputstreambuf.h"
namespace zipios {
FilterInputStreambuf::FilterInputStreambuf( streambuf *inbuf, bool del_inbuf )
: _inbuf( inbuf),
_del_inbuf( del_inbuf )
{
if ( _inbuf == NULL ) {
// throw an exception
}
}
FilterInputStreambuf::~FilterInputStreambuf() {
if ( _del_inbuf )
delete _inbuf ;
}
} // namespace
/** \file
Implementation of FilterInputStreambuf.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/zipextraction.cpp 0000644 0001750 0001750 00000004555 12104305064 020306 0 ustar don don /************************************************************************
**
** Copyright (C) 2010 Strahinja Markovic
**
** This file is part of FlightCrew.
**
** FlightCrew is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published
** by the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** FlightCrew is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with FlightCrew. If not, see .
**
*************************************************************************/
#include "zipios++/zipios-config.h"
#include "zipios++/meta-iostreams.h"
#include
#include
#include
#include "zipios++/zipfile.h"
#include "zipios++/zipinputstream.h"
#include "zipios++/zipextraction.h"
#include "zipios++/fcollexceptions.h"
namespace zipios
{
void WriteEntryToFile( const std::istream &stream, const fs::path &filepath )
{
fs::ofstream ofs( filepath, ios::out | ios::binary );
ofs << stream.rdbuf();
ofs.close();
}
void CreateFilepath( const fs::path &filepath )
{
if ( filepath.empty() )
throw IOException();
if ( !fs::exists( filepath.parent_path() ) )
fs::create_directories( filepath.parent_path() );
if ( fs::is_regular_file( filepath ) )
fs::ofstream( filepath );
else if ( fs::is_directory( filepath ) )
fs::create_directory( filepath );
}
void ExtractZipToFolder( const fs::path &path_to_zip, const fs::path &path_to_folder )
{
ZipFile zip( path_to_zip );
ConstEntries entries = zip.entries();
for ( ConstEntries::iterator it = entries.begin(); it != entries.end(); ++it )
{
boost::scoped_ptr< std::istream > stream( zip.getInputStream( *it ) );
fs::path new_file_path = path_to_folder / (*it)->getName();
CreateFilepath( new_file_path );
WriteEntryToFile( *stream, new_file_path );
}
}
} // namespace zipios
flightcrew-0.7.2/src/zipios/src/dircoll.cpp 0000644 0001750 0001750 00000011001 12104305064 017013 0 ustar don don
#include "zipios++/zipios-config.h"
#include "zipios++/meta-iostreams.h"
#include
#include
#include "zipios++/dircoll.h"
#include "../FlightCrew/Misc/BoostFilesystemUse.h"
namespace zipios {
using std::cerr ;
using std::endl ;
using std::vector ;
using std::ifstream ;
DirectoryCollection::DirectoryCollection( const string &path, bool recursive,
bool load_now )
: _entries_loaded( false ),
_recursive ( recursive ),
_filepath ( path )
{
_filename = _filepath ;
_valid = _filepath.isDirectory() ;
if( _valid && load_now )
loadEntries() ;
}
void DirectoryCollection::close() {
_valid = false ;
}
ConstEntries DirectoryCollection::entries() const {
if ( ! _valid )
throw InvalidStateException( "Attempt to use an invalid DirectoryCollection" ) ;
loadEntries() ;
return FileCollection::entries() ;
}
ConstEntryPointer
DirectoryCollection::getEntry( const string &name,
MatchPath matchpath ) const {
if ( ! _valid )
throw InvalidStateException( "Attempt to use an invalid DirectoryCollection" ) ;
if ( matchpath != MATCH || _entries_loaded ) {
loadEntries() ;
return FileCollection::getEntry( name, matchpath ) ;
} else {
// avoid loading entries if possible.
ConstEntryPointer ent ( new DirEntry( name, "", _filepath ) ) ;
if ( ent->isValid() )
return ent ;
else
return 0 ;
}
}
istream *DirectoryCollection::getInputStream( const ConstEntryPointer &entry ) {
if ( ! _valid )
throw InvalidStateException( "Attempt to use an invalid DirectoryCollection" ) ;
return getInputStream( entry->getName() ) ;
}
istream *DirectoryCollection::getInputStream( const string &entry_name,
MatchPath matchpath ) {
if ( ! _valid )
throw InvalidStateException( "Attempt to use an invalid DirectoryCollection" ) ;
if ( matchpath != MATCH || _entries_loaded ) {
loadEntries() ;
ConstEntryPointer ent = getEntry( entry_name, matchpath ) ;
if ( ent == 0 )
return 0 ;
else {
string real_path( _filepath + entry_name ) ;
return new ifstream( real_path.c_str(), ios::in | ios::binary ) ;
}
} else {
// avoid loading entries if possible.
string real_path( _filepath + entry_name ) ;
ifstream *ifs = new ifstream( real_path.c_str(), ios::in | ios::binary ) ;
if( ! *ifs ) {
delete ifs ;
return 0 ;
} else
return ifs ;
}
}
int DirectoryCollection::size() const {
if ( ! _valid )
throw InvalidStateException( "Attempt to use an invalid DirectoryCollection" ) ;
loadEntries() ;
return (int) _entries.size() ;
}
FileCollection *DirectoryCollection::clone() const {
return new DirectoryCollection( *this ) ;
}
DirectoryCollection::~DirectoryCollection() {}
void DirectoryCollection::loadEntries() const {
if( _entries_loaded )
return ;
const_cast< DirectoryCollection * >( this )->load( _recursive ) ;
_entries_loaded = true ;
}
void DirectoryCollection::load( bool recursive, const FilePath &subdir ) {
using namespace boost::filesystem ;
BasicEntry *ent ;
for ( fs::directory_iterator it( (_filepath + subdir).asString() ) ; it != fs::directory_iterator() ; ++it ) {
if ( *it == "." || *it == ".." || *it == "..." )
continue ;
if ( fs::is_directory( it->path() ) && recursive ) {
load( recursive, subdir + it->path().filename().string() ) ;
} else {
_entries.push_back( ent = new BasicEntry( subdir + it->path().filename().string(), "", _filepath ) ) ;
ent->setSize( (zipios::uint32) fs::file_size( it->path() ) ) ;
}
}
}
} // namespace
/** \file
Implementation of DirectoryCollection.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/gzipoutputstream.cpp 0000644 0001750 0001750 00000003657 12104305064 021053 0 ustar don don
#include "zipios++/zipios-config.h"
#include "zipios++/meta-iostreams.h"
#include "zipios++/gzipoutputstreambuf.h"
#include "zipios++/gzipoutputstream.h"
using std::ostream;
namespace zipios {
GZIPOutputStream::GZIPOutputStream( std::ostream &os )
: ostream( 0 ),
ofs( 0 )
{
ozf = new GZIPOutputStreambuf( os.rdbuf() ) ;
init( ozf ) ;
}
GZIPOutputStream::GZIPOutputStream( const std::string &filename )
: ostream( 0 ),
ofs( 0 )
{
ofs = new std::ofstream( filename.c_str(), std::ios::out | std::ios::binary ) ;
ozf = new GZIPOutputStreambuf( ofs->rdbuf() ) ;
init( ozf ) ;
}
void GZIPOutputStream::setFilename( const string &filename ) {
ozf->setFilename(filename);
}
void GZIPOutputStream::setComment( const string &comment ) {
ozf->setComment(comment);
}
void GZIPOutputStream::close() {
ozf->close() ;
if ( ofs )
ofs->close() ;
}
void GZIPOutputStream::finish() {
ozf->finish() ;
}
GZIPOutputStream::~GZIPOutputStream() {
// It's ok to call delete with a Null pointer.
delete ozf ;
delete ofs ;
}
} // namespace
/** \file
Implementation of GZIPOutputStream.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/fcollexceptions.cpp 0000644 0001750 0001750 00000006322 12104305064 020576 0 ustar don don
#include "zipios++/zipios-config.h"
#include "zipios++/meta-iostreams.h"
#include "zipios++/fcollexceptions.h"
namespace zipios {
using std::cerr ;
using std::endl ;
IOException::IOException() throw ()
: _what( "I/O exception" ) {}
IOException::IOException( const string &msg ) throw ()
: _what( msg ) {}
IOException::IOException( const IOException &src ) throw ()
: std::exception(), _what( src._what ) {}
IOException &IOException::operator= ( const IOException &src ) throw () {
_what = src._what ;
return *this ;
}
const char *IOException::what() const throw () {
return _what.c_str() ;
}
IOException::~IOException() throw () {}
FCollException::FCollException() throw ()
: _what( "FileCollection exception" ) {}
FCollException::FCollException( const string &msg ) throw ()
: _what( msg ) {}
FCollException::FCollException( const FCollException &src ) throw ()
: std::exception(),_what( src._what ) {}
FCollException &FCollException::operator= ( const FCollException &src ) throw () {
_what = src._what ;
return *this ;
}
const char *FCollException::what() const throw () {
return _what.c_str() ;
}
FCollException::~FCollException() throw () {}
InvalidStateException::InvalidStateException() throw ()
: _what( "InvalidState exception" ) {}
InvalidStateException::InvalidStateException( const string &msg ) throw ()
: _what( msg ) {}
InvalidStateException::
InvalidStateException( const InvalidStateException &src ) throw ()
: std::exception(), _what( src._what ) {}
InvalidStateException &InvalidStateException::
operator= ( const InvalidStateException &src ) throw () {
_what = src._what ;
return *this ;
}
const char *InvalidStateException::what() const throw () {
return _what.c_str() ;
}
InvalidStateException::~InvalidStateException() throw () {}
Exception::Exception() throw ()
: _what( "Exception" ) {}
Exception::Exception( const string &msg ) throw ()
: _what( msg ) {}
Exception::
Exception( const Exception &src ) throw ()
: std::exception(),_what( src._what ) {}
Exception &Exception::
operator= ( const Exception &src ) throw () {
_what = src._what ;
return *this ;
}
const char *Exception::what() const throw () {
return _what.c_str() ;
}
Exception::~Exception() throw () {}
} // namespace
/** \file
Implementation of a number of Exceptions used by FileCollection and its
subclasses.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/zipoutputstreambuf.cpp 0000644 0001750 0001750 00000011700 12104305064 021365 0 ustar don don
#include
#include "zipios++/zipios-config.h"
#include
#include "zipios++/meta-iostreams.h"
#include
#include "zipios++/zipoutputstreambuf.h"
namespace zipios {
using std::ios ;
using std::cerr ;
using std::endl ;
//using std::min ;
ZipOutputStreambuf::ZipOutputStreambuf( streambuf *outbuf, bool del_outbuf )
: DeflateOutputStreambuf( outbuf, false, del_outbuf ),
_open_entry( false ),
_open ( true ),
_method ( DEFLATED ),
_level ( 6 )
{
}
void ZipOutputStreambuf::closeEntry() {
if ( ! _open_entry )
return ;
closeStream() ;
updateEntryHeaderInfo() ;
setEntryClosedState( ) ;
}
void ZipOutputStreambuf::close() {
finish() ;
}
void ZipOutputStreambuf::finish() {
if( ! _open )
return ;
closeEntry() ;
ostream os( _outbuf ) ;
writeCentralDirectory( _entries, EndOfCentralDirectory( _zip_comment), os ) ;
_open = false ;
}
ZipOutputStreambuf::~ZipOutputStreambuf() {
finish() ;
}
void ZipOutputStreambuf::putNextEntry( const ZipCDirEntry &entry ) {
if ( _open_entry )
closeEntry() ;
if ( ! init( _level ) )
cerr << "ZipOutputStreambuf::putNextEntry(): init() failed!\n" ;
_entries.push_back( entry ) ;
ZipCDirEntry &ent = _entries.back() ;
ostream os( _outbuf ) ;
// Update entry header info
ent.setLocalHeaderOffset( static_cast< uint32 >( os.tellp() ) ) ;
ent.setMethod( _method ) ;
os << static_cast< ZipLocalEntry >( ent ) ;
_open_entry = true ;
}
void ZipOutputStreambuf::setComment( const string &comment ) {
_zip_comment = comment ;
}
void ZipOutputStreambuf::setLevel( int level ) {
_level = level ;
}
void ZipOutputStreambuf::setMethod( StorageMethod method ) {
_method = method ;
if( method == STORED )
setLevel( NO_COMPRESSION ) ;
else if ( method == DEFLATED ) {
if( _level == NO_COMPRESSION )
setLevel( DEFAULT_COMPRESSION ) ;
} else
throw FCollException( "Specified compression method not supported" ) ;
}
//
// Protected and private methods
//
int ZipOutputStreambuf::overflow( int c ) {
return DeflateOutputStreambuf::overflow( c ) ;
// // FIXME: implement
// cout << "ZipOutputStreambuf::overflow() not implemented yet!\n" ;
// return EOF ;
}
int ZipOutputStreambuf::sync() {
return DeflateOutputStreambuf::sync() ;
// // FIXME: implement
// cout << "ZipOutputStreambuf::sync() not implemented yet!\n" ;
// return EOF ;
}
void ZipOutputStreambuf::setEntryClosedState() {
_open_entry = false ;
// FIXME: update put pointers to trigger overflow on write. overflow
// should then return EOF while _open_entry is false.
}
void ZipOutputStreambuf::updateEntryHeaderInfo() {
if ( ! _open_entry )
return ;
ostream os( _outbuf ) ;
int curr_pos = static_cast< int >( os.tellp() ) ;
// update fields in _entries.back()
ZipCDirEntry &entry = _entries.back() ;
entry.setSize( getCount() ) ;
entry.setCrc( getCrc32() ) ;
entry.setCompressedSize( curr_pos - entry.getLocalHeaderOffset()
- entry.getLocalHeaderSize() ) ;
// Mark Donszelmann: added current date and time
time_t ltime;
time( <ime );
struct tm *now;
now = localtime( <ime );
int dosTime = (now->tm_year - 80) << 25 | (now->tm_mon + 1) << 21 | now->tm_mday << 16 |
now->tm_hour << 11 | now->tm_min << 5 | now->tm_sec >> 1;
entry.setTime(dosTime);
// write ZipLocalEntry header to header position
os.seekp( entry.getLocalHeaderOffset() ) ;
os << static_cast< ZipLocalEntry >( entry ) ;
os.seekp( curr_pos ) ;
}
void ZipOutputStreambuf::writeCentralDirectory( const vector< ZipCDirEntry > &entries,
EndOfCentralDirectory eocd,
ostream &os ) {
int cdir_start = static_cast< int >( os.tellp() ) ;
std::vector< ZipCDirEntry >::const_iterator it ;
int cdir_size = 0 ;
for ( it = entries.begin() ; it != entries.end() ; ++it ) {
os << *it ;
cdir_size += it->getCDirHeaderSize() ;
}
eocd.setOffset( cdir_start ) ;
eocd.setCDirSize( cdir_size ) ;
eocd.setTotalCount( static_cast< uint16 >( entries.size() ) ) ;
os << eocd ;
}
} // namespace
/** \file
Implementation of ZipOutputStreambuf.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/fcoll.cpp 0000644 0001750 0001750 00000005260 12104305064 016474 0 ustar don don
#include "zipios++/zipios-config.h"
#include
#include
#include
#include "zipios++/fcoll.h"
namespace zipios {
using std::find_if ;
// FIXME: make InvalidStateException message customized for
// subclasses. maybe make an InvalidStateException factory ;-)
ConstEntries FileCollection::entries() const {
if ( ! _valid )
throw InvalidStateException( "Attempt to get entries from an invalid FileCollection" ) ;
// The constructor below is not in all vector impl. (not those
// without member templates)
// ConstEntries ( _entries.begin(), _entries.end() ) ;
// Instead of using that we copy the vector manually
ConstEntries cep_vec ;
cep_vec.reserve( _entries.size() ) ;
Entries::const_iterator cit ;
for ( cit = _entries.begin() ; cit != _entries.end() ; ++cit )
cep_vec.push_back( *cit ) ;
return cep_vec ;
}
ConstEntryPointer FileCollection::getEntry( const string &name,
MatchPath matchpath ) const {
if ( ! _valid )
throw InvalidStateException( "Attempt to get an entry from an invalid FileCollection" ) ;
Entries::const_iterator iter ;
if ( matchpath == MATCH )
iter = find_if( _entries.begin(), _entries.end(), FileEntry::MatchName( name ) ) ;
else
iter = find_if( _entries.begin(), _entries.end(), FileEntry::MatchFileName( name ) ) ;
if ( iter == _entries.end() )
return 0 ;
else
return *iter ;
}
string FileCollection::getName() const {
if ( ! _valid )
throw InvalidStateException( "Attempt to get the name of an invalid FileCollection" ) ;
return _filename ;
}
int FileCollection::size() const {
if ( ! _valid )
throw InvalidStateException( "Attempt to get size of an invalid FileCollection" ) ;
return static_cast< int >( _entries.size() ) ;
}
FileCollection::~FileCollection() {
}
} // namespace
/** \file
Implementation of FileCollection.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/filepath.cpp 0000644 0001750 0001750 00000004052 12104305064 017167 0 ustar don don
#include "zipios++/zipios-config.h"
#include
#include
#include
#include
#include "zipios++/filepath.h"
namespace zipios {
using namespace std ;
const char FilePath::_separator = '/' ;
FilePath::FilePath( const string &path, bool check_exists )
: _checked( false ),
_path( path ) {
pruneTrailingSeparator() ;
if ( check_exists )
exists() ;
}
void FilePath::check() const {
_checked = true ;
_exists = false ;
_is_reg = false ;
_is_dir = false ;
_is_char = false ;
_is_block = false ;
_is_socket = false ;
_is_fifo = false ;
struct stat buf ;
if ( stat( _path.c_str(), &buf ) != -1 ) {
_exists = true ;
#if defined(BOOST_WINNT)
_is_reg = _S_IFREG & buf.st_mode ;
_is_dir = _S_IFDIR & buf.st_mode ;
_is_char = _S_IFCHR & buf.st_mode ;
#else
_is_reg = S_ISREG ( buf.st_mode ) ;
_is_dir = S_ISDIR ( buf.st_mode ) ;
_is_char = S_ISCHR ( buf.st_mode ) ;
_is_block = S_ISBLK ( buf.st_mode ) ;
_is_socket = S_ISSOCK( buf.st_mode ) ;
_is_fifo = S_ISFIFO( buf.st_mode ) ;
#endif
}
}
} // namespace
/** \file
Implementation of FilePath.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/gzipoutputstreambuf.cpp 0000644 0001750 0001750 00000006246 12104305064 021545 0 ustar don don
#include
#include "zipios++/zipios-config.h"
#include
#include "zipios++/meta-iostreams.h"
#include
#include "zipios++/gzipoutputstreambuf.h"
namespace zipios {
using std::ios ;
using std::cerr ;
using std::endl ;
GZIPOutputStreambuf::GZIPOutputStreambuf( streambuf *outbuf, bool del_outbuf )
: DeflateOutputStreambuf( outbuf, true, del_outbuf ),
_open ( false )
{
}
void GZIPOutputStreambuf::setFilename( const string &filename ) {
_filename = filename ;
}
void GZIPOutputStreambuf::setComment( const string &comment ) {
_comment = comment ;
}
void GZIPOutputStreambuf::close() {
finish() ;
}
void GZIPOutputStreambuf::finish() {
if( ! _open )
return ;
closeStream();
writeTrailer();
_open = false ;
}
GZIPOutputStreambuf::~GZIPOutputStreambuf() {
finish() ;
}
int GZIPOutputStreambuf::overflow( int c ) {
if (!_open) {
writeHeader();
_open = true;
}
return DeflateOutputStreambuf::overflow( c ) ;
}
int GZIPOutputStreambuf::sync() {
return DeflateOutputStreambuf::sync() ;
}
void GZIPOutputStreambuf::writeHeader() {
unsigned char flg = 0x00;
flg |= (_filename == "") ? 0x00 : 0x08;
flg |= (_comment == "") ? 0x00 : 0x10;
ostream os( _outbuf ) ;
os << (unsigned char)0x1f; // Magic #
os << (unsigned char)0x8b; // Magic #
os << (unsigned char)0x08; // Deflater.DEFLATED
os << flg; // FLG
os << (unsigned char)0x00; // MTIME
os << (unsigned char)0x00; // MTIME
os << (unsigned char)0x00; // MTIME
os << (unsigned char)0x00; // MTIME
os << (unsigned char)0x00; // XFLG
os << (unsigned char)0x00; // OS
if (_filename != "") {
os << _filename.c_str();// Filename
os << (unsigned char)0x00;
}
if (_comment != "") {
os << _comment.c_str(); // Comment
os << (unsigned char)0x00;
}
}
void GZIPOutputStreambuf::writeTrailer() {
writeInt(getCrc32());
writeInt(getCount());
}
void GZIPOutputStreambuf::writeInt(uint32 i) {
ostream os( _outbuf ) ;
os << (unsigned char)( i & 0xFF);
os << (unsigned char)((i >> 8) & 0xFF);
os << (unsigned char)((i >> 16) & 0xFF);
os << (unsigned char)((i >> 24) & 0xFF);
}
} // namespace
/** \file
Implementation of GZIPOutputStreambuf.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/filteroutputstreambuf.cpp 0000644 0001750 0001750 00000002447 12104305064 022060 0 ustar don don
#include "zipios++/zipios-config.h"
#include "zipios++/filteroutputstreambuf.h"
namespace zipios {
FilterOutputStreambuf::FilterOutputStreambuf( streambuf *outbuf, bool del_outbuf )
: _outbuf( outbuf),
_del_outbuf( del_outbuf )
{
if ( _outbuf == NULL ) {
// throw an exception
}
}
FilterOutputStreambuf::~FilterOutputStreambuf() {
if ( _del_outbuf )
delete _outbuf ;
}
} // namespace
/** \file
Implementation of FilterOutputStreambuf.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/fileentry.cpp 0000644 0001750 0001750 00000002212 12104305064 017370 0 ustar don don
#include "zipios++/zipios-config.h"
#include "zipios++/meta-iostreams.h"
#include
#include "zipios++/fileentry.h"
namespace zipios {
ostream &operator<< ( ostream &os, const FileEntry &entry ) {
os << entry.toString() ;
return os ;
}
} // namespace
/** \file
Implementation of FileEntry.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/outputstringstream.h 0000644 0001750 0001750 00000004153 12104305064 021045 0 ustar don don #ifndef OUTPUTSTRINGSTREAM_H
#define OUTPUTSTRINGSTREAM_H
#include "zipios++/zipios-config.h"
#include "zipios++/meta-iostreams.h"
#include
namespace zipios {
#if defined (HAVE_STD_IOSTREAM) && defined (USE_STD_IOSTREAM)
typedef std::ostringstream OutputStringStream ;
#else
/** OutputStringStream is typedefed to ostringstream if sstream is
part of the standard library (unless Zipios++ has been explicitly
configured not to use it). If sstream is not present
OutputStringStream is a subclass of ostrstream from
strstream.h. In this case OutputStringStream specializes the str()
method, such that the caller does not have to concern himself with
null-terminating the string and unfreezing the ostrstream. */
class OutputStringStream : public ostrstream {
public:
/** Specialization of ostrstream::str() that takes care of
null-terminating the string and unfreezing the ostrstream. */
inline string str() {
*this << ends ; // null terminate ostrstream
string o_str( ostrstream::str() ) ;
freeze( 0 ) ;
return o_str ;
}
private:
// To avoid invoking such a member function in the base
// class if there is one!
string str() const ;
};
#endif
} // namespace
#endif
/** \file
Header file that defines OutputStringStream.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/zipios_common.h 0000644 0001750 0001750 00000002646 12104305064 017734 0 ustar don don #ifndef ZIPIOS_COMMON_H
#define ZIPIOS_COMMON_H
#include "zipios++/zipios-config.h"
#include
namespace zipios {
using std::vector;
static const char separator = '/' ;
template< class Type >
void operator += ( vector< Type > &v1, const vector< Type > &v2 ) {
typename std::vector::const_iterator cit ;
for ( cit = v2.begin() ; cit != v2.end() ; ++cit )
v1.push_back( *cit ) ;
}
template< class T >
inline const T& min( const T& a, const T& b ) {
return b < a ? b : a ;
}
} // namespace
#endif
/** \file
Header file containing miscellaneous small functions.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/zipinputstreambuf.cpp 0000644 0001750 0001750 00000007764 12104305064 021203 0 ustar don don
#include "zipios++/zipios-config.h"
#include
#include "zipios++/meta-iostreams.h"
#include
#include "zipios++/zipinputstreambuf.h"
#include "zipios_common.h"
namespace zipios {
using std::ios ;
using std::cerr ;
using std::endl ;
ZipInputStreambuf::ZipInputStreambuf( streambuf *inbuf, int s_pos, bool del_inbuf )
: InflateInputStreambuf( inbuf, s_pos, del_inbuf ),
_open_entry( false )
{}
void ZipInputStreambuf::closeEntry() {
if ( ! _open_entry )
return ;
// check if we're positioned correctly, otherwise position us correctly
int position = static_cast< int >( _inbuf->pubseekoff(0, ios::cur,
ios::in) );
if ( position != _data_start + static_cast< int >( _curr_entry.getCompressedSize() ) )
_inbuf->pubseekoff(_data_start + _curr_entry.getCompressedSize(),
ios::beg, ios::in) ;
}
void ZipInputStreambuf::close() {
}
ConstEntryPointer ZipInputStreambuf::getNextEntry() {
if ( _open_entry )
closeEntry() ;
// read the zip local header
istream is( _inbuf ) ; // istream does not destroy the streambuf.
is.exceptions( ios::eofbit | ios::failbit | ios::badbit );
try {
is >> _curr_entry ;
if ( _curr_entry.isValid() ) {
_data_start = static_cast< int >( _inbuf->pubseekoff(0, ios::cur, ios::in) );
if ( _curr_entry.getMethod() == DEFLATED ) {
_open_entry = true ;
reset() ; // reset inflatestream data structures
// cerr << "deflated" << endl ;
} else if ( _curr_entry.getMethod() == STORED ) {
_open_entry = true ;
_remain = _curr_entry.getSize() ;
// Force underflow on first read:
setg( &( _outvec[ 0 ] ),
&( _outvec[ 0 ] ) + _outvecsize,
&( _outvec[ 0 ] ) + _outvecsize );
// cerr << "stored" << endl ;
} else {
_open_entry = false ; // Unsupported compression format.
throw FCollException( "Unsupported compression format" ) ;
}
}
} catch (...) {
_open_entry = false ;
}
if ( _curr_entry.isValid() && _curr_entry.trailingDataDescriptor() )
throw FCollException( "Trailing data descriptor in zip file not supported" ) ;
return new ZipLocalEntry( _curr_entry ) ;
}
ZipInputStreambuf::~ZipInputStreambuf() {
}
int ZipInputStreambuf::underflow() {
if ( ! _open_entry )
return EOF ; // traits_type::eof()
if ( _curr_entry.getMethod() == DEFLATED )
return InflateInputStreambuf::underflow() ;
// Ok, we're are stored, so we handle it ourselves.
int num_b = min( _remain, _outvecsize ) ;
int g = static_cast< int >( _inbuf->sgetn( &(_outvec[ 0 ] ) , num_b ) ) ;
setg( &( _outvec[ 0 ] ),
&( _outvec[ 0 ] ),
&( _outvec[ 0 ] ) + g ) ;
_remain -= g ;
if ( g > 0 )
return static_cast< unsigned char >( *gptr() ) ;
else
return EOF ; // traits_type::eof()
}
// FIXME: We need to check somew
//
// // gp_bitfield bit 3 is one, if the length of the zip entry
// // is stored in a trailer.
// if ( is->good && ( _curr_entry.gp_bitfield & 4 ) != 1 )
// return true ;
// else {
// is->clear() ;
// return false ;
// }
} // namespace
/** \file
Implementation of ZipInputStreambuf.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/basicentry.cpp 0000644 0001750 0001750 00000006734 12104305064 017547 0 ustar don don
#include "zipios++/zipios-config.h"
#include
#include "zipios++/meta-iostreams.h"
#include
#include "zipios_common.h"
#include "zipios++/basicentry.h"
#include "zipios++/zipios_defs.h"
#include "outputstringstream.h"
namespace zipios {
using std::ifstream ;
using std::ios ;
//
// Public definitions
//
BasicEntry::BasicEntry( const string &filename, const string &comment,
const FilePath &basepath )
: _filename ( filename ),
_comment ( comment ),
_basepath ( basepath )
{
string full_path = _basepath + _filename ;
ifstream is( full_path.c_str(), ios::in | ios::binary ) ;
if ( ! is ) {
_valid = false ;
} else {
is.seekg( 0, ios::end ) ;
_size = static_cast< int >( is.tellg() ) ;
is.close() ;
_valid = true ;
}
}
string BasicEntry::getComment() const {
return _comment ;
}
uint32 BasicEntry::getCompressedSize() const {
return getSize() ;
}
uint32 BasicEntry::getCrc() const {
return 0 ;
}
vector< unsigned char > BasicEntry::getExtra() const {
return vector< unsigned char > () ;
}
StorageMethod BasicEntry::getMethod() const {
return STORED ;
}
string BasicEntry::getName() const {
return _filename ;
}
string BasicEntry::getFileName() const {
if ( isDirectory() )
return string() ;
string::size_type pos ;
pos = _filename.find_last_of( separator ) ;
if ( pos != string::npos ) { // separator found!
// isDirectory() check means pos should not be last, so pos+1 is ok
return _filename.substr(pos + 1) ;
} else {
return _filename ;
}
}
uint32 BasicEntry::getSize() const {
return _size ;
}
int BasicEntry::getTime() const {
return 0 ; // FIXME later
}
bool BasicEntry::isValid() const {
return _valid ;
}
// virtual int hashCode() const {}
bool BasicEntry::isDirectory() const {
assert( _filename.size() != 0 ) ;
return _filename[ _filename.size() - 1 ] == separator ;
}
void BasicEntry::setComment( const string &comment ) {
_comment = comment ;
}
void BasicEntry::setCompressedSize( uint32 ) {
}
void BasicEntry::setCrc( uint32 ) {
}
void BasicEntry::setExtra( const vector< unsigned char > & ) {
}
void BasicEntry::setMethod( StorageMethod ) {
}
void BasicEntry::setName( const string &name ) {
_filename = name ;
}
void BasicEntry::setSize( uint32 size ) {
_size = size ;
}
void BasicEntry::setTime( int ) {
}
string BasicEntry::toString() const {
OutputStringStream sout ;
sout << _filename << " (" << _size << " bytes)" ;
return sout.str() ;
}
FileEntry *BasicEntry::clone() const {
return new BasicEntry( *this ) ;
}
BasicEntry::~BasicEntry() {
}
} // namespace
/** \file
Implementation of BasicEntry.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/zipfile.cpp 0000644 0001750 0001750 00000013603 12104305064 017037 0 ustar don don
#include "zipios++/zipios-config.h"
#include "zipios++/meta-iostreams.h"
#include "zipios++/fcoll.h"
#include "zipios++/zipfile.h"
#include "zipios++/zipinputstream.h"
#include "zipios++/zipios_defs.h"
#include "backbuffer.h"
#include "../../FlightCrew/Misc/BoostFilesystemUse.h"
namespace zipios {
//
// Public
//
ZipFile ZipFile::openEmbeddedZipFile( const string &name ) {
// open zipfile, read 4 last bytes close file
// create ZipFile object.
ifstream ifs( name.c_str(), ios::in | ios::binary ) ;
ifs.seekg( -4, ios::end ) ;
uint32 start_offset = readUint32( ifs ) ;
ifs.close() ;
return ZipFile( name, start_offset, 4 ) ;
}
ZipFile::ZipFile( const string &name , int s_off, int e_off
/* , ios::open_mode mode */ )
: _vs( s_off, e_off ) {
_filename = name ;
ifstream _zipfile( name.c_str(), ios::in | ios::binary ) ;
init( _zipfile ) ;
}
ZipFile::ZipFile( const fs::path &name , int s_off, int e_off
/* , ios::open_mode mode */ )
: _vs( s_off, e_off ) {
_filename = name.string();
fs::ifstream _zipfile( name, ios::in | ios::binary ) ;
init( _zipfile ) ;
}
FileCollection *ZipFile::clone() const {
return new ZipFile( *this ) ;
}
ZipFile::~ZipFile() {
close() ;
}
void ZipFile::close() {
_valid = false ;
}
istream *ZipFile::getInputStream( const ConstEntryPointer &entry ) {
if ( ! _valid )
throw InvalidStateException( "Attempt to use an invalid FileCollection" ) ;
return getInputStream( entry->getName() ) ;
}
istream *ZipFile::getInputStream( const string &entry_name,
MatchPath matchpath ) {
if ( ! _valid )
throw InvalidStateException( "Attempt to use an invalid ZipFile" ) ;
ConstEntryPointer ent = getEntry( entry_name, matchpath ) ;
if ( ent == 0 )
return 0 ;
else {
ZipInputStream *zis( new ZipInputStream( _filename,
static_cast< const ZipCDirEntry * >( ent.get() )->
getLocalHeaderOffset() + _vs.startOffset() ) ) ;
zis->getNextEntry();
return zis;
}
}
//
// Private
//
bool ZipFile::init( istream &_zipfile ) {
// Check stream error state
if ( ! _zipfile ) {
setError ( "Error reading from file" ) ;
return false ;
}
_valid = readCentralDirectory( _zipfile ) ;
return _valid ;
}
bool ZipFile::readCentralDirectory ( istream &_zipfile ) {
// Find and read eocd.
if ( ! readEndOfCentralDirectory( _zipfile ) )
throw FCollException( "Unable to find zip structure: End-of-central-directory" ) ;
// Position read pointer to start of first entry in central dir.
_vs.vseekg( _zipfile, _eocd.offset(), ios::beg ) ;
int entry_num = 0 ;
// Giving the default argument in the next line to keep Visual C++ quiet
_entries.resize ( _eocd.totalCount(), 0 ) ;
while ( ( entry_num < _eocd.totalCount() ) ) {
ZipCDirEntry *ent = new ZipCDirEntry ;
_entries[ entry_num ] = ent ;
_zipfile >> *ent ;
if ( ! _zipfile ) {
if ( _zipfile.bad() )
throw IOException( "Error reading zip file while reading zip file central directory" ) ;
else if ( _zipfile.fail() )
throw FCollException( "Zip file consistency problem. Failure while reading zip file central directory" ) ;
else if ( _zipfile.eof() )
throw IOException( "Premature end of file while reading zip file central directory" ) ;
}
++entry_num ;
}
// Consistency check. eocd should start here
int pos = _vs.vtellg( _zipfile ) ;
_vs.vseekg( _zipfile, 0, ios::end ) ;
int remaining = static_cast< int >( _vs.vtellg( _zipfile ) ) - pos ;
if ( remaining != _eocd.eocdOffSetFromEnd() )
throw FCollException( "Zip file consistency problem. Zip file data fields are inconsistent with zip file layout" ) ;
// Consistency check 2, are local headers consistent with
// cd headers
if ( ! confirmLocalHeaders( _zipfile ) )
throw FCollException( "Zip file consistency problem. Zip file data fields are inconsistent with zip file layout" ) ;
return true ;
}
bool ZipFile::readEndOfCentralDirectory ( istream &_zipfile ) {
BackBuffer bb( _zipfile, _vs ) ;
int read_p = -1 ;
bool found = false ;
while ( ! found ) {
if ( read_p < 0 )
if ( ! bb.readChunk ( read_p ) ) {
found = false ;
break ;
}
if ( _eocd.read( bb, read_p ) ) {
found = true ;
break ;
}
--read_p ;
}
return found ;
}
bool ZipFile::confirmLocalHeaders( istream &_zipfile ) {
Entries::const_iterator it ;
ZipCDirEntry *ent ;
int inconsistencies = 0 ;
ZipLocalEntry zlh ;
for ( it = _entries.begin() ; it != _entries.end() ; it++ ) {
ent = static_cast< ZipCDirEntry * >( (*it).get() ) ;
_vs.vseekg( _zipfile, ent->getLocalHeaderOffset(), ios::beg ) ;
_zipfile >> zlh ;
if ( ! _zipfile || zlh != *ent ) {
inconsistencies++ ;
_zipfile.clear() ;
}
}
return ! inconsistencies ;
}
void ZipFile::setError ( string error_str ) {
_valid = false ;
#ifdef _USE_EXCEPTIONS
throw error_str ; // define exception class instead.
#else
cerr << error_str << endl ; // define operator<< for exception class if such a class replaces string
#endif
}
}
/** \file
The implementation of ZipFile.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/zipoutputstream.cpp 0000644 0001750 0001750 00000004556 12104305064 020703 0 ustar don don
#include "zipios++/zipios-config.h"
#include "zipios++/meta-iostreams.h"
#include "zipios++/zipoutputstreambuf.h"
#include "zipios++/zipoutputstream.h"
using std::ostream;
namespace zipios {
ZipOutputStream::ZipOutputStream( std::ostream &os )
: ostream( 0 ),
// SGIs basic_ifstream calls istream with 0, but calls basic_ios constructor first??
ofs( 0 )
{
ozf = new ZipOutputStreambuf( os.rdbuf() ) ;
init( ozf ) ;
}
ZipOutputStream::ZipOutputStream( const std::string &filename )
: ostream( 0 ),
ofs( 0 )
{
ofs = new std::ofstream( filename.c_str(), std::ios::out | std::ios::binary ) ;
ozf = new ZipOutputStreambuf( ofs->rdbuf() ) ;
this->init( ozf ) ;
}
void ZipOutputStream::closeEntry() {
ozf->closeEntry() ;
}
void ZipOutputStream::close() {
ozf->close() ;
if ( ofs )
ofs->close() ;
}
void ZipOutputStream::finish() {
ozf->finish() ;
}
void ZipOutputStream::putNextEntry( const ZipCDirEntry &entry ) {
ozf->putNextEntry( entry ) ;
}
void ZipOutputStream::putNextEntry(const std::string& entryName) {
putNextEntry( ZipCDirEntry(entryName));
}
void ZipOutputStream::setComment( const std::string &comment ) {
ozf->setComment( comment ) ;
}
void ZipOutputStream::setLevel( int level ) {
ozf->setLevel( level ) ;
}
void ZipOutputStream::setMethod( StorageMethod method ) {
ozf->setMethod( method ) ;
}
ZipOutputStream::~ZipOutputStream() {
// It's ok to call delete with a Null pointer.
delete ozf ;
delete ofs ;
}
} // namespace
/** \file
Implementation of ZipOutputStream.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/zipheadio.cpp 0000644 0001750 0001750 00000014114 12104305064 017347 0 ustar don don
#include "zipios++/zipios-config.h"
#include "zipios++/meta-iostreams.h"
#include
#include
#include "zipios_common.h"
#include "zipios++/zipheadio.h"
#include "outputstringstream.h"
namespace zipios {
std::istream& operator>> ( std::istream &is, ZipLocalEntry &zlh ) {
zlh._valid = false ; // set to true upon successful completion.
if ( ! is )
return is ;
// // Before reading anything we record the position in the stream
// // This is a field in the central directory entry, but not
// // in the local entry. After all, we know where we are, anyway.
// zlh.rel_offset_loc_head = is.tellg() ;
if ( zlh.signature != readUint32( is ) ) {
// put stream in error state and return
is.setstate ( std::ios::failbit ) ;
return is ;
}
zlh.extract_version = readUint16( is ) ;
zlh.gp_bitfield = readUint16( is ) ;
zlh.compress_method = readUint16( is ) ;
zlh.last_mod_ftime = readUint16( is ) ;
zlh.last_mod_fdate = readUint16( is ) ;
zlh.crc_32 = readUint32( is ) ;
zlh.compress_size = readUint32( is ) ;
zlh.uncompress_size = readUint32( is ) ;
zlh.filename_len = readUint16( is ) ;
zlh.extra_field_len = readUint16( is ) ;
// Read filename and extra_field
readByteSeq( is, zlh.filename, zlh.filename_len ) ;
readByteSeq( is, zlh.extra_field, zlh.extra_field_len ) ;
if ( is )
zlh._valid = true ;
return is ;
}
std::istream& operator>> ( std::istream &is, DataDescriptor & ) {
return is ;
}
std::istream& operator>> ( std::istream &is, ZipCDirEntry &zcdh ) {
zcdh._valid = false ; // set to true upon successful completion.
if ( ! is )
return is ;
if ( zcdh.signature != readUint32( is ) ) {
// put stream in error state and return
is.setstate ( std::ios::failbit ) ;
return is ;
}
zcdh.writer_version = readUint16( is ) ;
zcdh.extract_version = readUint16( is ) ;
zcdh.gp_bitfield = readUint16( is ) ;
zcdh.compress_method = readUint16( is ) ;
zcdh.last_mod_ftime = readUint16( is ) ;
zcdh.last_mod_fdate = readUint16( is ) ;
zcdh.crc_32 = readUint32( is ) ;
zcdh.compress_size = readUint32( is ) ;
zcdh.uncompress_size = readUint32( is ) ;
zcdh.filename_len = readUint16( is ) ;
zcdh.extra_field_len = readUint16( is ) ;
zcdh.file_comment_len = readUint16( is ) ;
zcdh.disk_num_start = readUint16( is ) ;
zcdh.intern_file_attr = readUint16( is ) ;
zcdh.extern_file_attr = readUint32( is ) ;
zcdh.rel_offset_loc_head = readUint32( is ) ;
// Read filename and extra_field
readByteSeq( is, zcdh.filename, zcdh.filename_len ) ;
readByteSeq( is, zcdh.extra_field, zcdh.extra_field_len ) ;
readByteSeq( is, zcdh.file_comment, zcdh.file_comment_len ) ;
if ( is )
zcdh._valid = true ;
return is ;
}
std::ostream &operator<< ( std::ostream &os, const ZipLocalEntry &zlh ) {
if ( ! os )
return os ;
writeUint32( zlh.signature , os ) ;
writeUint16( zlh.extract_version, os ) ;
writeUint16( zlh.gp_bitfield , os ) ;
writeUint16( zlh.compress_method, os ) ;
writeUint16( zlh.last_mod_ftime , os ) ;
writeUint16( zlh.last_mod_fdate , os ) ;
writeUint32( zlh.crc_32 , os ) ;
writeUint32( zlh.compress_size , os ) ;
writeUint32( zlh.uncompress_size, os ) ;
writeUint16( zlh.filename_len , os ) ;
writeUint16( zlh.extra_field_len, os ) ;
// Write filename and extra_field
writeByteSeq( os, zlh.filename ) ;
writeByteSeq( os, zlh.extra_field ) ;
return os ;
}
std::ostream &operator<< ( std::ostream &os, const ZipCDirEntry &zcdh ) {
if ( ! os )
return os ;
writeUint32( zcdh.signature , os ) ;
writeUint16( zcdh.writer_version , os ) ;
writeUint16( zcdh.extract_version , os ) ;
writeUint16( zcdh.gp_bitfield , os ) ;
writeUint16( zcdh.compress_method , os ) ;
writeUint16( zcdh.last_mod_ftime , os ) ;
writeUint16( zcdh.last_mod_fdate , os ) ;
writeUint32( zcdh.crc_32 , os ) ;
writeUint32( zcdh.compress_size , os ) ;
writeUint32( zcdh.uncompress_size , os ) ;
writeUint16( zcdh.filename_len , os ) ;
writeUint16( zcdh.extra_field_len , os ) ;
writeUint16( zcdh.file_comment_len , os ) ;
writeUint16( zcdh.disk_num_start , os ) ;
writeUint16( zcdh.intern_file_attr , os ) ;
writeUint32( zcdh.extern_file_attr , os ) ;
writeUint32( zcdh.rel_offset_loc_head, os ) ;
// Write filename and extra_field
writeByteSeq( os, zcdh.filename ) ;
writeByteSeq( os, zcdh.extra_field ) ;
writeByteSeq( os, zcdh.file_comment ) ;
return os ;
}
std::ostream &operator<< ( std::ostream &os, const EndOfCentralDirectory &eocd ) {
if ( ! os )
return os ;
writeUint32( eocd.signature , os ) ;
writeUint16( eocd.disk_num , os ) ;
writeUint16( eocd.cdir_disk_num , os ) ;
writeUint16( eocd.cdir_entries , os ) ;
writeUint16( eocd.cdir_tot_entries, os ) ;
writeUint32( eocd.cdir_size , os ) ;
writeUint32( eocd.cdir_offset , os ) ;
writeUint16( eocd.zip_comment_len , os ) ;
writeByteSeq( os, eocd.zip_comment ) ;
return os ;
}
} // namespace
/** \file
Implementation of I/O functions for the header structures
defined in ziphead.h.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/inflateinputstreambuf.cpp 0000644 0001750 0001750 00000014011 12104305064 022002 0 ustar don don
#include "zipios++/zipios-config.h"
#include "zipios++/meta-iostreams.h"
#include
#include "zipios++/fcollexceptions.h"
#include "zipios++/inflateinputstreambuf.h"
#include "outputstringstream.h"
namespace zipios {
using std::cerr ;
using std::endl ;
InflateInputStreambuf::InflateInputStreambuf( streambuf *inbuf, int s_pos, bool del_inbuf )
: FilterInputStreambuf( inbuf, del_inbuf ),
_zs_initialized ( false ),
_invecsize ( 1000 ),
_invec ( _invecsize ),
_outvecsize ( 1000 ),
_outvec ( _outvecsize )
{
// NOTICE: It is important that this constructor and the methods it
// calls doesn't do anything with the input streambuf _inbuf, other
// than repositioning it to the specified position. The reason is
// that this class can be subclassed, and the subclass should get a
// chance to read from the buffer first)
// zlib init:
_zs.zalloc = Z_NULL ;
_zs.zfree = Z_NULL ;
_zs.opaque = Z_NULL ;
reset( s_pos ) ;
// We're not checking the return value of reset() and throwing
// an exception in case of an error, because we cannot catch the exception
// in the constructors of subclasses with all compilers.
}
InflateInputStreambuf::~InflateInputStreambuf() {
// Dealloc z_stream stuff
int err = inflateEnd( &_zs ) ;
if( err != Z_OK ) {
cerr << "~inflatebuf: inflateEnd failed" ;
#ifdef HAVE_ZERROR
cerr << ": " << zError( err ) ;
#endif
cerr << endl ;
}
}
int InflateInputStreambuf::underflow() {
// If not underflow don't fill buffer
if ( gptr() < egptr() )
return static_cast< unsigned char >( *gptr() ) ;
// Prepare _outvec and get array pointers
_zs.avail_out = _outvecsize ;
_zs.next_out = reinterpret_cast< unsigned char * >( &( _outvec[ 0 ] ) ) ;
// Inflate until _outvec is full
// eof (or I/O prob) on _inbuf will break out of loop too.
int err = Z_OK ;
while ( _zs.avail_out > 0 && err == Z_OK ) {
if ( _zs.avail_in == 0 ) { // fill _invec
int bc = static_cast< int >( _inbuf->sgetn( &(_invec[ 0 ] ) ,
_invecsize ) ) ;
// FIXME: handle i/o problems.
_zs.next_in = reinterpret_cast< unsigned char * >( &( _invec[0] ) ) ;
_zs.avail_in = bc ;
// If we could not read any new data (bc == 0) and inflate isn't
// done it will return Z_BUF_ERROR and thus breaks out of the
// loop. This means we don't have to respond to the situation
// where we can't read more bytes here.
}
err = inflate( &_zs, Z_NO_FLUSH ) ;
}
// Normally the number of inflated bytes will be the
// full length of the output buffer, but if we can't read
// more input from the _inbuf streambuf, we end up with
// less.
int inflated_bytes = _outvecsize - _zs.avail_out ;
setg( &( _outvec[ 0 ] ),
&( _outvec[ 0 ] ),
&( _outvec[ 0 ] ) + inflated_bytes ) ;
// FIXME: look at the error returned from inflate here, if there is
// some way to report it to the InflateInputStreambuf user.
// Until I find out I'll just print a warning to stdout.
if( err != Z_OK && err != Z_STREAM_END ) {
#if defined (HAVE_STD_IOSTREAM) && defined (USE_STD_IOSTREAM)
// Throw an exception to make istream set badbit
OutputStringStream msgs ;
msgs << "InflateInputStreambuf: inflate failed" ;
#ifdef HAVE_ZERROR
msgs << ": " << zError( err ) ;
#endif
throw IOException( msgs.str() ) ;
#endif
// If HAVE_STD_IOSTREAM not defined we just return eof
// if no output is produced, and that happens anyway
}
if (inflated_bytes > 0 )
return static_cast< unsigned char >( *gptr() ) ;
else
return EOF ; // traits_type::eof() ;
}
// This method is called in the constructor, so it must not
// read anything from the input streambuf _inbuf (see notice in constructor)
bool InflateInputStreambuf::reset( int stream_position ) {
if ( stream_position >= 0 ) { // reposition _inbuf
_inbuf->pubseekpos( stream_position ) ;
}
// _zs.next_in and avail_in must be set according to
// zlib.h (inline doc).
_zs.next_in = reinterpret_cast< unsigned char * >( &( _invec[0] ) ) ;
_zs.avail_in = 0 ;
int err ;
if( _zs_initialized ) { // just reset it
err = inflateReset( &_zs ) ;
} else { // init it
err = inflateInit2( &_zs, -MAX_WBITS ) ;
/* windowBits is passed < 0 to tell that there is no zlib header.
Note that in this case inflate *requires* an extra "dummy" byte
after the compressed stream in order to complete decompression
and return Z_STREAM_END. We always have an extra "dummy" byte,
because there is always some trailing data after the compressed
data (either the next entry or the central directory. */
_zs_initialized = true ;
}
// streambuf init:
// The important thing here, is that
// - the pointers are not NULL (which would mean unbuffered)
// - and that gptr() is not less than egptr() (so we trigger underflow
// the first time data is read).
setg( &( _outvec[ 0 ] ),
&( _outvec[ 0 ] ) + _outvecsize,
&( _outvec[ 0 ] ) + _outvecsize ) ;
if ( err == Z_OK )
return true ;
else
return false ;
}
} // namespace
/** \file
Implementation of InflateInputStreambuf.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/deflateoutputstreambuf.cpp 0000644 0001750 0001750 00000013473 12104305064 022200 0 ustar don don
#include "zipios++/zipios-config.h"
#include "zipios++/meta-iostreams.h"
#include
#include "zipios++/fcollexceptions.h"
#include "zipios++/deflateoutputstreambuf.h"
#include "outputstringstream.h"
namespace zipios {
using std::cerr ;
using std::endl ;
DeflateOutputStreambuf::DeflateOutputStreambuf( streambuf *outbuf, bool user_init,
bool del_outbuf )
: FilterOutputStreambuf( outbuf, del_outbuf ),
_zs_initialized ( false ),
_invecsize ( 1000 ),
_invec ( _invecsize ),
_outvecsize ( 1000 ),
_outvec ( _outvecsize )
{
// NOTICE: It is important that this constructor and the methods it
// calls doesn't do anything with the output streambuf _outbuf The
// reason is that this class can be subclassed, and the subclass
// should get a chance to write to the buffer first
// zlib init:
_zs.zalloc = Z_NULL ;
_zs.zfree = Z_NULL ;
_zs.opaque = Z_NULL ;
if ( user_init && ! init() )
cerr << "DeflateOutputStreambuf::reset() failed!\n" ; // FIXME: throw something
}
DeflateOutputStreambuf::~DeflateOutputStreambuf() {
closeStream() ;
}
// This method is called in the constructor, so it must not write
// anything to the output streambuf _outbuf (see notice in
// constructor)
bool DeflateOutputStreambuf::init( int comp_level ) {
static const int default_mem_level = 8 ;
// _zs.next_in and avail_in must be set according to
// zlib.h (inline doc).
_zs.next_in = reinterpret_cast< unsigned char * >( &( _invec[ 0 ] ) ) ;
_zs.avail_in = 0 ;
_zs.next_out = reinterpret_cast< unsigned char * >( &( _outvec[ 0 ] ) ) ;
_zs.avail_out = _outvecsize ;
int err ;
if( _zs_initialized ) { // just reset it
endDeflation() ;
err = deflateReset( &_zs ) ;
// FIXME: bug, for deflateReset we do not update the compression level
} else { // init it
err = deflateInit2( &_zs, comp_level, Z_DEFLATED, -MAX_WBITS,
default_mem_level, Z_DEFAULT_STRATEGY ) ;
/* windowBits is passed < 0 to tell that no zlib header should be
written. */
_zs_initialized = true ;
}
// streambuf init:
setp( &( _invec[ 0 ] ), &( _invec[ 0 ] ) + _invecsize ) ;
_crc32 = crc32( 0, Z_NULL, 0 ) ;
_overflown_bytes = 0 ;
if ( err == Z_OK )
return true ;
else
return false ;
}
bool DeflateOutputStreambuf::closeStream() {
int err = Z_OK ;
if( _zs_initialized ) {
endDeflation() ;
err = deflateEnd( &_zs ) ;
_zs_initialized = false ;
}
if ( err == Z_OK )
return true ;
else {
cerr << "DeflateOutputStreambuf::closeStream(): deflateEnd failed" ;
#ifdef HAVE_ZERROR
cerr << ": " << zError( err ) ;
#endif
cerr << endl ;
return false ;
}
}
int DeflateOutputStreambuf::overflow( int c ) {
_zs.avail_in = static_cast< uInt >( pptr() - pbase() ) ;
_zs.next_in = reinterpret_cast< unsigned char * >( &( _invec[ 0 ] ) ) ;
_crc32 = crc32( _crc32, _zs.next_in, _zs.avail_in ) ; // update crc32
_overflown_bytes += _zs.avail_in ;
_zs.next_out = reinterpret_cast< unsigned char * >( &( _outvec[ 0 ] ) ) ;
_zs.avail_out = _outvecsize ;
// Deflate until _invec is empty.
int err = Z_OK ;
while ( ( _zs.avail_in > 0 || _zs.avail_out == 0 ) && err == Z_OK ) {
if ( _zs.avail_out == 0 )
flushOutvec() ;
err = deflate( &_zs, Z_NO_FLUSH ) ;
}
flushOutvec() ;
// Update 'put' pointers
setp( &( _invec[ 0 ] ), &( _invec[ 0 ] ) + _invecsize ) ;
if( err != Z_OK && err != Z_STREAM_END ) {
#if defined (HAVE_STD_IOSTREAM) && defined (USE_STD_IOSTREAM)
// Throw an exception to make istream set badbit
OutputStringStream msgs ;
msgs << "Deflation failed" ;
#ifdef HAVE_ZERROR
msgs << ": " << zError( err ) ;
#endif
throw IOException( msgs.str() ) ;
#endif
cerr << "Deflation failed\n" ;
return EOF ;
}
if ( c != EOF ) {
*pptr() = c ;
pbump( 1 ) ;
}
return 0 ;
}
int DeflateOutputStreambuf::sync() {
// FIXME: Do something
// return overflow() ;
return 0 ;
}
bool DeflateOutputStreambuf::flushOutvec() {
int deflated_bytes = _outvecsize - _zs.avail_out ;
int bc = static_cast< int >( _outbuf->sputn( &( _outvec[ 0 ] ), deflated_bytes ) ) ;
_zs.next_out = reinterpret_cast< unsigned char * >( &( _outvec[ 0 ] ) ) ;
_zs.avail_out = _outvecsize ;
return deflated_bytes == bc ;
}
void DeflateOutputStreambuf::endDeflation() {
overflow() ;
_zs.next_out = reinterpret_cast< unsigned char * >( &( _outvec[ 0 ] ) ) ;
_zs.avail_out = _outvecsize ;
// Deflate until _invec is empty.
int err = Z_OK ;
while ( err == Z_OK ) {
if ( _zs.avail_out == 0 )
flushOutvec() ;
err = deflate( &_zs, Z_FINISH ) ;
}
flushOutvec() ;
if ( err != Z_STREAM_END ) {
cerr << "DeflateOutputStreambuf::endDeflation(): deflation failed:\n" ;
#ifdef HAVE_ZERROR
cerr << ": " << zError( err ) ;
#endif
cerr << endl ;
}
}
} // namespace
/** \file
Implementation of DeflateOutputStreambuf.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/collcoll.cpp 0000644 0001750 0001750 00000011014 12104305064 017172 0 ustar don don
#include "zipios++/zipios-config.h"
#include "zipios++/meta-iostreams.h"
#include "zipios++/collcoll.h"
#include "zipios_common.h"
namespace zipios {
using std::ifstream ;
CollectionCollection *CollectionCollection::_inst = 0 ;
CollectionCollection::CollectionCollection() {
_valid = true ; // we're valid even though we are empty!
}
bool CollectionCollection::addCollection( const FileCollection &collection ) {
if ( ! _valid )
throw InvalidStateException( "Attempt to add a FileCollection to an invalid CollectionCollection" ) ;
if ( this == &collection || ! collection.isValid() )
return false ;
_collections.push_back( collection.clone() ) ;
return true ;
}
bool CollectionCollection::addCollection( FileCollection *collection ) {
if ( ! _valid )
throw InvalidStateException( "Attempt to add a FileCollection to an invalid CollectionCollection" ) ;
if ( collection == 0 || this == collection || ! collection->isValid() )
return false ;
_collections.push_back( collection ) ;
return true ;
}
void CollectionCollection::close() {
_valid = false ;
}
ConstEntries CollectionCollection::entries() const {
if ( ! _valid )
throw InvalidStateException( "Attempt to get entries from an invalid CollectionCollection" ) ;
ConstEntries all_entries ;
std::vector< FileCollection * >::const_iterator it ;
for ( it = _collections.begin() ; it != _collections.end() ; it++ )
all_entries += (*it)->entries() ;
return all_entries ;
}
ConstEntryPointer CollectionCollection::getEntry( const string &name,
MatchPath matchpath ) const {
if ( ! _valid )
throw InvalidStateException( "Attempt to get an entry from an invalid CollectionCollection" ) ;
// Returns the first matching entry.
std::vector< FileCollection * >::const_iterator it ;
ConstEntryPointer cep ;
getEntry( name, cep, it, matchpath ) ;
return cep ;
}
istream *CollectionCollection::getInputStream( const ConstEntryPointer &entry ) {
if ( ! _valid )
throw InvalidStateException( "Attempt to get an input stream from an invalid CollectionCollection" ) ;
return getInputStream( entry->getName() ) ;
}
istream *CollectionCollection::getInputStream( const string &entry_name,
MatchPath matchpath ) {
if ( ! _valid )
throw InvalidStateException( "Attempt to get an input stream from an invalid CollectionCollection" ) ;
std::vector< FileCollection * >::const_iterator it ;
ConstEntryPointer cep ;
getEntry( entry_name, cep, it, matchpath ) ;
if ( cep == 0 )
return 0 ;
else
return (*it)->getInputStream( entry_name ) ;
}
int CollectionCollection::size() const {
if ( ! _valid )
throw InvalidStateException( "Attempt to get the size of an invalid CollectionCollection" ) ;
int sz = 0 ;
std::vector< FileCollection * >::const_iterator it ;
for ( it = _collections.begin() ; it != _collections.end() ; it++ )
sz += (*it)->size() ;
return sz ;
}
FileCollection *CollectionCollection::clone() const {
return new CollectionCollection( *this ) ;
}
CollectionCollection::~CollectionCollection() {
std::vector< FileCollection * >::iterator it ;
for ( it = _collections.begin() ; it != _collections.end() ; ++it )
delete *it ;
}
//
// Protected member functions
//
void CollectionCollection::getEntry( const string &name,
ConstEntryPointer &cep,
std::vector< FileCollection * >::const_iterator &it,
MatchPath matchpath ) const {
// Returns the first matching entry.
cep = 0 ;
for ( it = _collections.begin() ; it != _collections.end() ; it++ ) {
cep = (*it)->getEntry( name, matchpath ) ;
if ( cep )
break ;
}
}
} // namespace
/** \file
Implementation of CollectionCollection.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/ziphead.cpp 0000644 0001750 0001750 00000020302 12104305064 017013 0 ustar don don
#include "zipios++/zipios-config.h"
#include "zipios++/meta-iostreams.h"
#include
#include
#include
#include "zipios_common.h"
#include "zipios++/ziphead.h"
#include "zipios++/zipheadio.h"
#include "zipios++/zipios_defs.h"
#include "outputstringstream.h"
namespace zipios {
using std::ios ;
bool operator== ( const ZipLocalEntry &zlh, const ZipCDirEntry &ze ) {
// Not all fields need to be identical. Some of the information
// may be put in a data descriptor that trails the compressed
// data, according to the specs (The trailing data descriptor
// can contain crc_32, compress_size and uncompress_size.)
// Experience has shown that extra_field and extra_field_len
// can differ too.
// cerr << "----- BEGIN -----" << endl ;
// cerr << ( zlh.extract_version == ze.extract_version ) << endl ;
// cerr << ( zlh.gp_bitfield == ze.gp_bitfield ) << endl ;
// cerr << ( zlh.compress_method == ze.compress_method ) << endl ;
// cerr << ( zlh.last_mod_ftime == ze.last_mod_ftime ) << endl ;
// cerr << ( zlh.last_mod_fdate == ze.last_mod_fdate ) << endl ;
// cerr << ( zlh.filename_len == ze.filename_len ) << endl ;
// cerr << ( zlh.filename == ze.filename ) << endl ;
// cerr << "----- END -----" << endl ;
return ( zlh.extract_version == ze.extract_version &&
zlh.gp_bitfield == ze.gp_bitfield &&
zlh.compress_method == ze.compress_method &&
zlh.last_mod_ftime == ze.last_mod_ftime &&
zlh.last_mod_fdate == ze.last_mod_fdate &&
zlh.filename_len == ze.filename_len &&
zlh.filename == ze.filename ) ;
}
//
// ZipLocalEntry methods
//
const uint32 ZipLocalEntry::signature = 0x04034b50 ;
void ZipLocalEntry::setDefaultExtract() {
extract_version = 20 ; // version number
}
string ZipLocalEntry::getComment() const {
return "" ; // No comment in a local entry
}
uint32 ZipLocalEntry::getCompressedSize() const {
return compress_size ;
}
uint32 ZipLocalEntry::getCrc() const {
return crc_32 ;
}
vector< unsigned char > ZipLocalEntry::getExtra() const {
return extra_field ;
}
StorageMethod ZipLocalEntry::getMethod() const {
return static_cast< StorageMethod >( compress_method ) ;
}
string ZipLocalEntry::getName() const {
return filename ;
}
string ZipLocalEntry::getFileName() const {
if ( isDirectory() )
return string() ;
string::size_type pos ;
pos = filename.find_last_of( separator ) ;
if ( pos != string::npos ) { // separator found!
// isDirectory() check means pos should not be last, so pos+1 is ok
return filename.substr( pos + 1 ) ;
} else {
return filename ;
}
}
uint32 ZipLocalEntry::getSize() const {
return uncompress_size ;
}
int ZipLocalEntry::getTime() const {
return ( last_mod_fdate << 16 ) + last_mod_ftime ;
// FIXME: what to do with this time date thing? (not only here?)
}
bool ZipLocalEntry::isValid() const {
return _valid ;
}
bool ZipLocalEntry::isDirectory() const {
assert( filename.size() != 0 ) ;
return filename[ filename.size() - 1 ] == separator ;
}
void ZipLocalEntry::setComment( const string & ) {
// A local entry cannot hold a comment
}
void ZipLocalEntry::setCompressedSize( uint32 size ) {
compress_size = size ;
}
void ZipLocalEntry::setCrc( uint32 crc ) {
crc_32 = crc ;
}
void ZipLocalEntry::setExtra( const vector< unsigned char > &extra ) {
extra_field = extra ;
extra_field_len = static_cast< uint16 >( extra_field.size() ) ;
}
void ZipLocalEntry::setMethod( StorageMethod method ) {
compress_method = static_cast< uint16 >( method ) ;
}
void ZipLocalEntry::setName( const string &name ) {
filename = name ;
filename_len = static_cast< uint16 >( filename.size() ) ;
}
void ZipLocalEntry::setSize( uint32 size ) {
uncompress_size = size ;
}
void ZipLocalEntry::setTime( int time ) {
// FIXME: fix time setting here, and ind flist and elsewhere. Define the
// date time semantics before mucking about - how surprising
// Mark Donszelmann: added these lines to make zip work for winzip
last_mod_fdate = (time >> 16) & 0x0000FFFF;
last_mod_ftime = time & 0x0000FFFF;
}
string ZipLocalEntry::toString() const {
OutputStringStream sout ;
sout << filename << " (" << uncompress_size << " bytes, " ;
sout << compress_size << " bytes compressed)" ;
return sout.str() ;
}
int ZipLocalEntry::getLocalHeaderSize() const {
return static_cast< int >( 30 + filename.size() + extra_field.size() ) ;
}
bool ZipLocalEntry::trailingDataDescriptor() const {
// gp_bitfield bit 3 is one, if this entry uses a trailing data
// descriptor to keep size, compressed size and crc-32
// fields.
if ( ( gp_bitfield & 4 ) == 1 )
return true ;
else
return false ;
}
FileEntry *ZipLocalEntry::clone() const {
return new ZipLocalEntry( *this ) ;
}
//
// ZipCDirEntry methods
//
const uint32 ZipCDirEntry::signature = 0x02014b50 ;
void ZipCDirEntry::setDefaultWriter() {
writer_version = 0 ;
#ifdef WIN32
writer_version |= static_cast< uint16 >( 0 ) << 8 ; // Windows, DOS
#else
writer_version |= static_cast< uint16 >( 3 ) << 8 ; // Unix
#endif
writer_version |= 20 ; // version number
}
string ZipCDirEntry::getComment() const {
return file_comment ;
}
uint32 ZipCDirEntry::getLocalHeaderOffset() const {
return rel_offset_loc_head ;
}
void ZipCDirEntry::setLocalHeaderOffset( uint32 offset ) {
rel_offset_loc_head = offset ;
}
void ZipCDirEntry::setComment( const string &comment ) {
file_comment = comment ;
file_comment_len = static_cast< uint16 >( file_comment.size() ) ;
}
string ZipCDirEntry::toString() const {
OutputStringStream sout ;
sout << filename << " (" << uncompress_size << " bytes, " ;
sout << compress_size << " bytes compressed)" ;
return sout.str() ;
}
int ZipCDirEntry::getCDirHeaderSize() const {
return static_cast< int >( 46 + filename.size() + extra_field.size() + file_comment.size() ) ;
}
FileEntry *ZipCDirEntry::clone() const {
return new ZipCDirEntry( *this ) ;
}
//
// EndOfCentralDirectory methods
//
const uint32 EndOfCentralDirectory::signature = 0x06054b50 ;
bool EndOfCentralDirectory::read( vector &buf, int pos ) {
if ( ( buf.size() - pos < sizeof( uint32 ) ) ||
( ! checkSignature( &( buf[ pos ] ) ) ) )
return false ;
eocd_offset_from_end = buf.size() - pos ;
pos += sizeof( uint32 ) ;
disk_num = ztohs( &( buf[ pos ] ) ) ; pos += sizeof( uint16 ) ;
cdir_disk_num = ztohs( &( buf[ pos ] ) ) ; pos += sizeof( uint16 ) ;
cdir_entries = ztohs( &( buf[ pos ] ) ) ; pos += sizeof( uint16 ) ;
cdir_tot_entries = ztohs( &( buf[ pos ] ) ) ; pos += sizeof( uint16 ) ;
cdir_size = ztohl( &( buf[ pos ] ) ) ; pos += sizeof( uint32 ) ;
cdir_offset = ztohl( &( buf[ pos ] ) ) ; pos += sizeof( uint32 ) ;
zip_comment_len = ztohs( &( buf[ pos ] ) ) ; pos += sizeof( uint16 ) ;
// cerr << "Zip comment length = " << zip_comment_len << endl ;
// cerr << "Length of remaining file = " << buf.size() - pos << endl ;
return true ; // Dummy
}
bool EndOfCentralDirectory::checkSignature ( unsigned char *buf ) const {
// cerr << "potential header: " << ztohl( buf ) << endl ;
return checkSignature( ztohl( buf ) ) ;
}
} // namespace
/** \file
Implementation of routines for reading the central directory and
local headers of a zip archive.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/zipinputstream.cpp 0000644 0001750 0001750 00000004400 12104305064 020466 0 ustar don don
#include "zipios++/zipios-config.h"
#include "zipios++/meta-iostreams.h"
#include "zipios++/zipinputstreambuf.h"
#include "zipios++/zipinputstream.h"
using std::istream;
namespace zipios {
ZipInputStream::ZipInputStream( std::istream &is, std::streampos pos )
: istream( 0 ),
// SGIs basic_ifstream calls istream with 0, but calls basic_ios constructor first??
ifs( 0 )
{
izf = new ZipInputStreambuf( is.rdbuf(), static_cast< int >( pos ) ) ;
// this->rdbuf( izf ) ; is replaced by:
this->init( izf ) ;
}
ZipInputStream::ZipInputStream( const std::string &filename, std::streampos pos )
: istream( 0 ),
ifs( 0 )
{
ifs = new std::ifstream( filename.c_str(), std::ios::in |std:: ios::binary ) ;
izf = new ZipInputStreambuf( ifs->rdbuf(), static_cast< int >( pos ) ) ;
// this->rdbuf( izf ) ; is replaced by:
this->init( izf ) ;
}
int ZipInputStream::available() {
return 1 ; // FIXME: Dummy implementation
}
void ZipInputStream::closeEntry() {
izf->closeEntry() ;
}
void ZipInputStream::close() {
izf->close() ;
}
// ZipLocalEntry *ZipInputStream::createZipCDirEntry( const string
// &name ) {}
ConstEntryPointer ZipInputStream::getNextEntry() {
clear() ; // clear eof and other flags.
return izf->getNextEntry() ;
}
ZipInputStream::~ZipInputStream() {
// It's ok to call delete with a Null pointer.
delete izf ;
delete ifs ;
}
} // namespace
/** \file
Implementation of ZipInputStream.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/zipios/src/backbuffer.h 0000644 0001750 0001750 00000010050 12104305064 017125 0 ustar don don #ifndef BACKBUFFER_H
#define BACKBUFFER_H
#include "zipios++/zipios-config.h"
#include
#include "zipios++/meta-iostreams.h"
#include
#include "zipios++/fcollexceptions.h"
#include "zipios++/ziphead.h"
#include "zipios++/zipheadio.h"
#include "zipios++/virtualseeker.h"
#include "zipios_common.h"
namespace zipios {
using std::ios ;
using std::cerr ;
using std::endl ;
/** A BackBuffer instance is useful for reading the last part of a
file in an efficient manner, when it is not known exactly how far
back (towards the front!) to go, to find the start of the desired
data block. BackBuffer is a vector< unsigned char > that fills
itself with data from a file by reading chunks from the end of the
file progressing towards the start. Upon construction the
BackBuffer instance is associated with a file and a chunksize can
be specified. To read a chunk of the file into the BackBuffer call
readChunk(). */
class BackBuffer : public vector< unsigned char > {
public:
/** BackBuffer constructor.
@param is The istream to read the data from. The stream must be seekable,
as BackBuffer will reposition the file position to read chunks from the back
of the file.
@param chunk_size specifies the size of the chunks to read the file into
the BackBuffer in.
@throw FCollException Thrown if the VirtualSeeker vs that has been specified is
invalid for the istream is. */
inline explicit BackBuffer( istream &is, VirtualSeeker vs = VirtualSeeker(),
int chunk_size = 1024 ) ;
/** Reads another chunk and returns the size of the chunk that has
been read. Returns 0 on I/O failure.
@param read_pointer When a new chunk is read in the already
stored bytes change position in the BackBuffer. read_pointer is
assumed by readChunk() to be a pointer into a position in the
BackBuffer, and is updated to point to the same position in the file
as it pointed to before the new chunk was read. */
inline int readChunk( int &read_pointer ) ;
private:
VirtualSeeker _vs ;
int _chunk_size ;
istream &_is ;
streampos _file_pos ;
};
BackBuffer::BackBuffer( istream &is, VirtualSeeker vs, int chunk_size )
: _vs ( vs ),
_chunk_size( chunk_size ),
_is ( is )
{
_vs.vseekg( is, 0, ios::end ) ;
_file_pos = _vs.vtellg( is ) ;
// Only happens if _vs.startOffset() is a position
// in the file that lies after _vs.endOffset(), which
// is clearly not a valid situation.
if ( _file_pos < 0 )
throw FCollException( "Invalid virtual file endings" ) ;
}
int BackBuffer::readChunk( int &read_pointer ) {
// Update chunk_size and file position
_chunk_size = min ( static_cast< int >( _file_pos ), _chunk_size ) ;
_file_pos -= _chunk_size ;
_vs.vseekg( _is, static_cast< int >( _file_pos ), ios::beg ) ;
// Make space for _chunk_size new bytes first in buffer
insert ( begin(), _chunk_size, static_cast< char > ( 0 ) ) ;
// Read in the next _chunk_size of bytes
readByteSeq ( _is, &( (*this)[ 0 ] ), _chunk_size ) ;
read_pointer += _chunk_size ;
if ( _is.good() )
return _chunk_size ;
else
return 0 ;
}
}
#endif
/** \file
The header file for BackBuffer
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
flightcrew-0.7.2/src/FlightCrew-gui/ 0000755 0001750 0001750 00000000000 11621123054 015402 5 ustar don don flightcrew-0.7.2/src/FlightCrew-gui/MainWindow.h 0000644 0001750 0001750 00000007637 11621123054 017644 0 ustar don don /************************************************************************
**
** Copyright (C) 2010 Strahinja Markovic
**
** This file is part of FlightCrew.
**
** FlightCrew is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published
** by the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** FlightCrew is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with FlightCrew. If not, see .
**
*************************************************************************/
#pragma once
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
// We set the MSVC warning level down to 3
// for code that we have no control over
#if defined(_MSC_VER)
# pragma warning( push, 3 )
#endif
#include
#include "ui_Form.h"
// ... and then we reset the warning level
// back to normal (warning level 4)
#if defined(_MSC_VER)
# pragma warning( pop )
#endif
#include
#include
namespace fc = FlightCrew;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
/**
* Constructor.
*
* @param parent The window's parent object.
* @param flags The flags used to modify window behavior.
*/
MainWindow( QWidget *parent = 0, Qt::WFlags flags = 0 );
/**
* Destructor.
*/
~MainWindow();
protected:
/**
* Handles drag events. In our case, this func only
* allows file drags.
* @note Overridden from QMainWindow.
*
* @param event The drag event.
*/
void dragEnterEvent( QDragEnterEvent *event );
/**
* Handles drop events. In our case, file drop events.
* The file is then validated.
* @note Overridden from QMainWindow.
*
* @param event The drop event.
*/
void dropEvent( QDropEvent *event );
private slots:
/**
* Validates the epub file listed in the combo box.
*/
void StartValidation();
/**
* Opens a file browsing dialog so that the user
* can select a file to validate.
*/
void BrowseForEpub();
private:
/**
* Displays the validation results in the table.
*
* @param results The validation results we got from FlightCrew.
*/
void DisplayResults( const std::vector< fc::Result > &results );
/**
* Informs the user that no problems were found.
*/
void DisplayNoProblemsMessage();
/**
* Adds a filename to the combo box and makes in the
* currently selected item.
*
* @param filename The file to add to the combo.
*/
void AddFilenameToComboBox( const QString &filename );
/**
* Reads all the stored application settings like
* window position, geometry etc.
*/
void ReadSettings();
/**
* Writes all the stored application settings like
* window position, geometry etc.
*/
void WriteSettings();
/**
* Confirgures the table for presenting validation results.
*/
void ConfigureTableForResults();
/**
* Connects all the required signals to their slots.
*/
void ConnectSignalsToSlots();
///////////////////////////////
// PRIVATE MEMBER VARIABLES
///////////////////////////////
/**
* The last folder from which the user opened a file.
*/
QString m_LastFolderOpen;
/**
* Holds all the widgets Qt Designer created for us.
*/
Ui::MainWindow ui;
};
#endif // MAINWINDOW_H flightcrew-0.7.2/src/FlightCrew-gui/main.cpp 0000644 0001750 0001750 00000004010 11621123054 017025 0 ustar don don /************************************************************************
**
** Copyright (C) 2010 Strahinja Markovic
**
** This file is part of FlightCrew.
**
** FlightCrew is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published
** by the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** FlightCrew is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with FlightCrew. If not, see .
**
*************************************************************************/
// We set the MSVC warning level down to 3
// for code that we have no control over
#if defined(_MSC_VER)
# pragma warning( push, 3 )
#endif
#include
#include
// Needs to go here because of Qt includes for some reason
#include "MainWindow.h"
#include "UpdateChecker.h"
// ... and then we reset the warning level
// back to normal (warning level 4)
#if defined(_MSC_VER)
# pragma warning( pop )
#endif
// Application entry point
int main( int argc, char *argv[] )
{
QT_REQUIRE_VERSION( argc, argv, "4.6.0" );
QApplication app( argc, argv );
// Set application information for
// easier use of QSettings classes
QCoreApplication::setOrganizationName( "Strahinja Markovic" );
QCoreApplication::setApplicationName( "FlightCrew-gui" );
// Needs to be created on the heap so that
// the reply has time to return.
UpdateChecker *checker = new UpdateChecker( &app );
checker->CheckForUpdate();
MainWindow *widget = new MainWindow();
widget->show();
return app.exec();
}
flightcrew-0.7.2/src/FlightCrew-gui/resources/ 0000755 0001750 0001750 00000000000 11621123054 017414 5 ustar don don flightcrew-0.7.2/src/FlightCrew-gui/resources/mac/ 0000755 0001750 0001750 00000000000 11621123054 020154 5 ustar don don flightcrew-0.7.2/src/FlightCrew-gui/resources/mac/MacOSXBundleInfo.plist 0000644 0001750 0001750 00000002030 11621123054 024264 0 ustar don don 
CFBundleVersion
FCVERSION
NSHumanReadableCopyright
Copyright © Strahinja Markovic 2010, GNU LGPL v3, CC 3.0 BY-SA
CFBundleShortVersionString
FCVERSION
CFBundleGetInfoString
FCVERSION FlightCrew Open Source ePub Validator. See http://code.google.com/p/flightcrew/
CFBundleIdentifier
com.valloric.Sigil.app
CFBundleDevelopmentRegion
English
CFBundleExecutable
FlightCrew-gui
CFBundleInfoDictionaryVersion
6.0
CFBundleName
FlightCrew-gui
CFBundlePackageType
APPL
CFBundleSignature
Fcva
CSResourcesFileMapped
flightcrew-0.7.2/src/FlightCrew-gui/resources/bash/ 0000755 0001750 0001750 00000000000 11621123054 020331 5 ustar don don flightcrew-0.7.2/src/FlightCrew-gui/resources/bash/flightcrew-gui.sh 0000644 0001750 0001750 00000001144 11621123054 023605 0 ustar don don #!/bin/sh
# Entry point for FlightCrew-gui on Unix systems.
# Adds the directory the FlightCrew-gui executable is located
# in to the LD_LIBRARY_PATH so the custom Qt libs
# are recognized and loaded.
appname=`basename $0 | sed s,\.sh$,,`
dirname=`dirname $0`
tmp="${dirname#?}"
if [ "${dirname%$tmp}" != "/" ]; then
dirname=$PWD/$dirname
fi
LD_LIBRARY_PATH=$dirname
export LD_LIBRARY_PATH
#if no agruments are passed then call just FlightCrew-gui program; else pass arguments.
if [$* == ""]
then
$dirname/$appname
else
#argument may not be pass correctly without qoutation marks.
$dirname/$appname "$*"
fi
flightcrew-0.7.2/src/FlightCrew-gui/CMakeLists.txt 0000644 0001750 0001750 00000035274 11621123054 020155 0 ustar don don ########################################################
#
# This is a CMake configuration file.
# To use it you need CMake which can be
# downloaded from here:
# http://www.cmake.org/cmake/resources/software.html
#
#########################################################
cmake_minimum_required( VERSION 2.8 )
# We use the lower case name
# on UNIX systems other than Mac OS X
if ( WIN32 OR APPLE )
project( FlightCrew-gui )
else()
project( flightcrew-gui )
endif()
#############################################################################
find_package( Qt4 4.6.0 COMPONENTS QtCore QtGui QtMain QtNetwork REQUIRED )
include( ${QT_USE_FILE} )
#############################################################################
file( GLOB_RECURSE RAW_SOURCES *.h *.cpp )
set( QOBJECT_HEADERS
MainWindow.h
UpdateChecker.h
)
set( UI_FILES
Form.ui
)
# Runs MOC on specifed files
qt4_wrap_cpp( MOC_FILES_CPP ${QOBJECT_HEADERS} )
# Runs UIC on specified files
qt4_wrap_ui( UI_FILES_H ${UI_FILES} )
set( ALL_SOURCES ${RAW_SOURCES} ${MOC_FILES_CPP} ${UI_FILES_H} )
#############################################################################
# Apple bundle configuration
if( APPLE )
# Copy the PLIST file...
exec_program( "cp ${PROJECT_SOURCE_DIR}/resources/mac/MacOSXBundleInfo.plist ${PROJECT_BINARY_DIR}")
# ...and set the FlightCrew version string
exec_program( "sed -i -e 's/FCVERSION/${FLIGHTCREW_FULL_VERSION}/g' ${PROJECT_BINARY_DIR}/MacOSXBundleInfo.plist")
endif()
#############################################################################
# Creating source groups for VS, Xcode
include( ${CMAKE_SOURCE_DIR}/cmake_extras/FileSystemSourceGroups.cmake )
create_source_groups( RAW_SOURCES )
#############################################################################
# We need to pick up the stdafx.h file
# and the headers for the linked-to libraries
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${BoostParts_SOURCE_DIR}
${FlightCrew_SOURCE_DIR}
${XercesExtensions_SOURCE_DIR}
)
#############################################################################
# We make bundles for Mac OS X
if ( APPLE )
add_executable( ${PROJECT_NAME} MACOSX_BUNDLE ${ALL_SOURCES} )
set_target_properties( ${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${PROJECT_BINARY_DIR}/MacOSXBundleInfo.plist )
# ...and a normal executable for everything else.
else()
add_executable( ${PROJECT_NAME} WIN32 ${ALL_SOURCES} )
endif()
target_link_libraries( ${PROJECT_NAME} FlightCrew ${QT_LIBRARIES} )
#############################################################################
if( BUILD_SHARED_FC )
add_definitions( -DFC_BUILT_AS_DLL )
endif()
#############################################################################
# "Link time code generation" flags for MSVC
# TODO: split into special cmake file
if( MSVC )
# We'd love to use /W4 here, but there's just so much
# noise coming from Qt it's absurd
add_definitions( /DUNICODE /D_UNICODE )
set_source_files_properties( MainWindow.cpp PROPERTIES COMPILE_DEFINITIONS /W4 )
set_source_files_properties( main.cpp PROPERTIES COMPILE_DEFINITIONS /W4 )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:wchar_t-" )
set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oi /GL" )
set( CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG" )
# "Print all warnings" flag for GCC
elseif( CMAKE_COMPILER_IS_GNUCXX )
add_definitions( -Wall )
endif()
set_source_files_properties( MainWindow.cpp PROPERTIES COMPILE_DEFINITIONS FLIGHTCREW_FULL_VERSION="${FLIGHTCREW_FULL_VERSION}" )
set_source_files_properties( UpdateChecker.cpp PROPERTIES COMPILE_DEFINITIONS FLIGHTCREW_FULL_VERSION="${FLIGHTCREW_FULL_VERSION}" )
#############################################################################
# For Mac, add frameworks and make a DMG
if( APPLE )
if(CMAKE_GENERATOR STREQUAL Xcode)
set( WORK_DIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release" )
else()
set( WORK_DIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" )
endif()
add_custom_target( addframeworks ALL
COMMAND ${QT_BINARY_DIR}/macdeployqt FlightCrew-gui.app
WORKING_DIRECTORY ${WORK_DIR}
DEPENDS ${PROJECT_NAME} )
add_custom_target( makedmg
COMMAND ${QT_BINARY_DIR}/macdeployqt FlightCrew-gui.app -dmg -no-plugins
WORKING_DIRECTORY ${WORK_DIR}
DEPENDS addframeworks )
# For Linux and Windows, provide binary installers.
# For this to work on Linux, InstallJammer needs to be installed and on the system path.
# For this to work on Windows, Inno Setup's iscc compiler needs to be installed and on the system path.
else()
set( TEMP_PACKAGE_DIR ${CMAKE_BINARY_DIR}/temp_folder )
set( MAIN_PACKAGE_DIR ${TEMP_PACKAGE_DIR}/FlightCrew )
set( OUTPUT_PACKAGE_DIR ${CMAKE_BINARY_DIR}/installer )
# MPI (InstallJammer) file will need to be copied to this location
set( MPI_LOCATION ${CMAKE_BINARY_DIR}/temp_folder/FlightCrew.mpi )
# ISS conf file for the Inno Setup compiler
# We first create a CMake configured version of the ISS file,
# and then we copy it to the temp folder every time we need to build the installer.
set( ISS_MAIN_LOCATION ${CMAKE_SOURCE_DIR}/installer/FlightCrew.iss )
Set( ISS_OC_LOCATION ${CMAKE_SOURCE_DIR}/OpenCandy/FlightCrewOC.iss )
set( ISS_CONFIGURED_LOCATION ${CMAKE_BINARY_DIR}/FlightCrew_configured.iss )
set( ISS_TEMP_LOCATION ${CMAKE_BINARY_DIR}/temp_folder/FlightCrew_configured.iss )
if ( 64_BIT_PLATFORM )
# Used in the ISS CMake configuration
set( ISS_ARCH "x64" )
set( ISS_SETUP_FILENAME_PLATFORM "-x64" )
endif()
# This is used to build OpenCandy installers. You can't build them
# from the source repo and you shouldn't want to either. By default,
# vanilla installers are built. You want the vanillas.
if ( EXISTS ${ISS_OC_LOCATION} )
set( OC_INSTALLERS TRUE )
endif()
# Creates a copy of the ISS file in ${ISS_CONFIGURED_LOCATION} and then configures it
if ( OC_INSTALLERS )
set( LICENSE_LOCATION ${CMAKE_SOURCE_DIR}/OpenCandy/win_installer_note.txt )
configure_file( ${ISS_OC_LOCATION} ${ISS_CONFIGURED_LOCATION} )
else()
set( LICENSE_LOCATION ${CMAKE_SOURCE_DIR}/installer/win_installer_note.txt )
configure_file( ${ISS_MAIN_LOCATION} ${ISS_CONFIGURED_LOCATION} )
endif()
# Specify platform var for installjammer
if ( WIN32 )
set( PLATFORM "Windows" )
else()
if ( 64_BIT_PLATFORM )
set( PLATFORM "Linux-x86_64" )
else()
set( PLATFORM "Linux-x86" )
endif()
endif()
# We use Inno for the Windows installers and InstallJammer for the Linux ones
if ( WIN32 )
# Run Inno Setup's iscc compiler (*AFTER* all the PRE_BUILD custom commands execute)
add_custom_target( makeinstaller
COMMAND cmake -E echo "For this to work, Inno Setup's iscc compiler needs to be installed and on the system path."
COMMAND iscc ${ISS_TEMP_LOCATION} )
else()
# Run InstallJammer (*AFTER* all the PRE_BUILD custom commands execute)
add_custom_target( makeinstaller
COMMAND cmake -E echo "For this to work, InstallJammer needs to be installed and on the system path."
COMMAND installjammer -DBaseDir ${MAIN_PACKAGE_DIR}
-DFCMajorVersion ${FLIGHTCREW_MAJOR_VERSION}
-DFCMinorVersion ${FLIGHTCREW_MINOR_VERSION}
-DFCRevisionVersion ${FLIGHTCREW_REVISION_VERSION}
--platform ${PLATFORM}
--output-dir ${OUTPUT_PACKAGE_DIR}
--build-for-release
--verbose
--build ${MPI_LOCATION} )
endif()
# We need to copy the files that will be used to make the installer to
# a temporary directory. On the MSVC compiler the PRE_BUILD custom commands
# can be added directly, but on other generators we need an intermediate target
# since the PRE_BUILD condition is not supported. Using the intermediate for
# MSVC makes it unnecessarily recompile that target every time the project is built.
# So we use the direct way on MSVC, and the intemediate way for other generators.
if( MSVC_IDE )
set( TARGET_FOR_COPY makeinstaller )
add_dependencies( makeinstaller ${PROJECT_NAME} )
else()
set( TARGET_FOR_COPY copyfiles )
# The intermediate target for copying
add_custom_target( copyfiles
COMMENT "Copying installer files to temporary location..."
DEPENDS ${PROJECT_NAME} )
add_dependencies( makeinstaller copyfiles )
endif()
if ( WIN32 OR APPLE )
set( FC_CLI_NAME FlightCrew-cli )
else()
set( FC_CLI_NAME flightcrew-cli )
endif()
# We want to include the CLI in the installer, so it has to be built
add_dependencies( makeinstaller ${FC_CLI_NAME} )
# Copy MPI file to temp folder location
add_custom_command( TARGET ${TARGET_FOR_COPY} PRE_BUILD
COMMAND cmake -E copy ${CMAKE_SOURCE_DIR}/installer/FlightCrew.mpi ${MPI_LOCATION} )
# Copy ISS file to temp folder location
add_custom_command( TARGET ${TARGET_FOR_COPY} PRE_BUILD
COMMAND cmake -E copy ${ISS_CONFIGURED_LOCATION} ${ISS_TEMP_LOCATION} )
# Copy Qt runtime libs
set( QT_LIBS QtCore QtGui QtNetwork )
if( UNIX )
# DBus is needed on Linux
list( APPEND QT_LIBS QtDBus )
endif()
add_custom_command( TARGET ${TARGET_FOR_COPY} PRE_BUILD COMMAND cmake -E make_directory ${MAIN_PACKAGE_DIR}/ )
foreach( lib ${QT_LIBS} )
set( location location-NOTFOUND )
find_file( location ${lib} NAMES ${lib}4.dll lib${lib}.so.4 PATHS ${QT_LIBRARY_DIR} )
add_custom_command( TARGET ${TARGET_FOR_COPY} PRE_BUILD COMMAND cmake -E copy ${location} ${MAIN_PACKAGE_DIR}/ )
endforeach( lib )
# Set the path of the application executable
if( MSVC_IDE )
set( EXE_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/${PROJECT_NAME}${CMAKE_EXECUTABLE_SUFFIX} )
set( CLI_EXE_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/${FC_CLI_NAME}${CMAKE_EXECUTABLE_SUFFIX} )
else()
set( EXE_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}${CMAKE_EXECUTABLE_SUFFIX} )
set( CLI_EXE_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${FC_CLI_NAME}${CMAKE_EXECUTABLE_SUFFIX} )
endif()
# Copy the application executable
add_custom_command( TARGET ${TARGET_FOR_COPY} PRE_BUILD
COMMAND cmake -E copy ${EXE_PATH} ${MAIN_PACKAGE_DIR} )
# Copy the CLI application executable
add_custom_command( TARGET ${TARGET_FOR_COPY} PRE_BUILD
COMMAND cmake -E copy ${CLI_EXE_PATH} ${MAIN_PACKAGE_DIR} )
# We need to copy the CRT dlls
if ( WIN32 )
# Add -DWIN_INSTALLER_USE_64BIT_CRT=1 to the cmake call if you want to build
# an installer for the x64 verison of Sigil. This will make sure that the
# correct CRT libs are included in the installer.
if ( WIN_INSTALLER_USE_64BIT_CRT )
message( STATUS "Using the 64 bit CRT in the FlightCrew Windows installer" )
add_custom_command( TARGET ${TARGET_FOR_COPY} PRE_BUILD
COMMAND cmake -E copy ${CMAKE_SOURCE_DIR}/installer/msvc_crt/x64/msvcp100.dll ${MAIN_PACKAGE_DIR} )
add_custom_command( TARGET ${TARGET_FOR_COPY} PRE_BUILD
COMMAND cmake -E copy ${CMAKE_SOURCE_DIR}/installer/msvc_crt/x64/msvcr100.dll ${MAIN_PACKAGE_DIR} )
else()
message( STATUS "Using the 32 bit CRT in the FlightCrew Windows installer" )
add_custom_command( TARGET ${TARGET_FOR_COPY} PRE_BUILD
COMMAND cmake -E copy ${CMAKE_SOURCE_DIR}/installer/msvc_crt/x86/msvcp100.dll ${MAIN_PACKAGE_DIR} )
add_custom_command( TARGET ${TARGET_FOR_COPY} PRE_BUILD
COMMAND cmake -E copy ${CMAKE_SOURCE_DIR}/installer/msvc_crt/x86/msvcr100.dll ${MAIN_PACKAGE_DIR} )
endif()
endif()
if( UNIX )
# Copy the Unix launcher that adds the working directory to the LD_LIBRARY_PATH
add_custom_command( TARGET ${TARGET_FOR_COPY} PRE_BUILD
COMMAND cmake -E copy ${PROJECT_SOURCE_DIR}/resources/bash/flightcrew-gui.sh ${MAIN_PACKAGE_DIR} )
endif()
# Copy the Changelog
add_custom_command( TARGET ${TARGET_FOR_COPY} PRE_BUILD
COMMAND cmake -E copy ${CMAKE_SOURCE_DIR}/ChangeLog.txt ${MAIN_PACKAGE_DIR} )
# Copy the license files
add_custom_command( TARGET ${TARGET_FOR_COPY} PRE_BUILD
COMMAND cmake -E copy ${CMAKE_SOURCE_DIR}/COPYING.txt ${MAIN_PACKAGE_DIR} )
add_custom_command( TARGET ${TARGET_FOR_COPY} PRE_BUILD
COMMAND cmake -E copy ${CMAKE_SOURCE_DIR}/COPYING.LESSER.txt ${MAIN_PACKAGE_DIR} )
# Remove the temp directory used for building the installer
add_custom_command( TARGET makeinstaller POST_BUILD
COMMAND cmake -E remove_directory ${TEMP_PACKAGE_DIR}
COMMENT "Removing temporary directory..." )
endif()
#############################################################################
# You can change the install location by
# running cmake like this:
#
# cmake -DCMAKE_INSTALL_PREFIX=/new/install/prefix
#
# By default, the prefix is "/usr/local"
#
if( UNIX AND NOT APPLE )
install( TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin )
endif()
flightcrew-0.7.2/src/FlightCrew-gui/MainWindow.cpp 0000644 0001750 0001750 00000021467 11621123054 020174 0 ustar don don /************************************************************************
**
** Copyright (C) 2010 Strahinja Markovic
**
** This file is part of FlightCrew.
**
** FlightCrew is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published
** by the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** FlightCrew is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with FlightCrew. If not, see .
**
*************************************************************************/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "MainWindow.h"
#include
namespace fc = FlightCrew;
static const QString SETTINGS_GROUP = "mainwindow";
static const QBrush WARNING_BRUSH = QBrush( QColor( 255, 255, 230 ) );
static const QBrush ERROR_BRUSH = QBrush( QColor( 255, 230, 230 ) );
static const QString FLIGHTCREW_VERSION = QString( FLIGHTCREW_FULL_VERSION );
MainWindow::MainWindow( QWidget*, Qt::WFlags )
{
ui.setupUi( this );
// We want to have the version showing in the window title.
setWindowTitle( "FlightCrew - " + FLIGHTCREW_VERSION );
// Telling Qt to delete this window
// from memory when it is closed
setAttribute( Qt::WA_DeleteOnClose );
setAcceptDrops( true );
// Needs to come before signals connect
// (avoiding side-effects)
ReadSettings();
ConnectSignalsToSlots();
}
MainWindow::~MainWindow()
{
WriteSettings();
}
void MainWindow::dragEnterEvent( QDragEnterEvent *event )
{
if ( event->mimeData()->hasFormat( "text/uri-list" ) )
event->acceptProposedAction();
}
void MainWindow::dropEvent( QDropEvent *event )
{
if ( !event->mimeData()->hasUrls() )
return;
event->acceptProposedAction();
QList< QUrl > urls = event->mimeData()->urls();
if ( urls.empty() )
return;
AddFilenameToComboBox( urls[ 0 ].toLocalFile() );
StartValidation();
}
void MainWindow::StartValidation()
{
QString current_file = ui.FilepathsCombo->currentText();
if ( QFileInfo( current_file ).suffix().toLower() != "epub" )
{
QMessageBox::critical( this,
tr( "FlightCrew-gui" ),
tr( "The specified file does not appear to be an epub." )
);
return;
}
if ( !QFileInfo( current_file ).exists() )
{
QMessageBox::critical( this,
tr( "FlightCrew-gui" ),
tr( "The specified file does not exist." )
);
return;
}
ui.ResultTable->clearContents();
std::vector< fc::Result > results;
QApplication::setOverrideCursor( Qt::WaitCursor );
try
{
results = fc::ValidateEpub( current_file.toUtf8().constData() );
}
catch ( std::exception& exception )
{
// TODO: extract boost exception info
QMessageBox::critical( this,
tr( "FlightCrew-gui" ),
tr( "An exception occurred: %1." )
.arg( QString::fromStdString( exception.what() ) )
);
return;
}
QApplication::restoreOverrideCursor();
DisplayResults( results );
}
void MainWindow::BrowseForEpub()
{
QString filename = QFileDialog::getOpenFileName( this,
tr( "Open File" ),
m_LastFolderOpen,
tr( "Epub files (*.epub)" )
);
if ( !filename.isEmpty() )
{
// Store the folder the user opened from
m_LastFolderOpen = QFileInfo( filename ).absolutePath();
AddFilenameToComboBox( filename );
}
}
void MainWindow::DisplayResults( const std::vector< fc::Result > &results )
{
ui.ResultTable->clear();
if ( results.empty() )
{
DisplayNoProblemsMessage();
return;
}
ConfigureTableForResults();
for ( unsigned int i = 0; i < results.size(); ++i )
{
fc::Result result = results[ i ];
ui.ResultTable->insertRow( ui.ResultTable->rowCount() );
QBrush row_brush = result.GetResultType() == fc::ResultType_WARNING ?
WARNING_BRUSH :
ERROR_BRUSH;
QTableWidgetItem *item = NULL;
item = new QTableWidgetItem( QString::fromUtf8( result.GetFilepath().c_str() ) );
item->setBackground( row_brush );
ui.ResultTable->setItem( i, 0, item );
item = result.GetErrorLine() > 0 ?
new QTableWidgetItem( QString::number( result.GetErrorLine() ) ) :
new QTableWidgetItem( tr( "N/A" ) );
item->setBackground( row_brush );
ui.ResultTable->setItem( i, 1, item );
item = new QTableWidgetItem( QString::fromUtf8( result.GetMessage().c_str() ) );
item->setBackground( row_brush );
ui.ResultTable->setItem( i, 2, item );
}
// We first force the line number column
// to the smallest needed size...
ui.ResultTable->resizeColumnToContents( 0 );
// ... and now the file column can be widened.
ui.ResultTable->resizeColumnToContents( 1 );
}
void MainWindow::DisplayNoProblemsMessage()
{
ui.ResultTable->setRowCount( 1 );
ui.ResultTable->setColumnCount( 1 );
ui.ResultTable->setHorizontalHeaderLabels(
QStringList() << tr( "Message" ) );
QTableWidgetItem *item = new QTableWidgetItem( tr( "No problems found!" ) );
item->setTextAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
QFont font = item->font();
font.setPointSize( 16 );
item->setFont( font );
ui.ResultTable->setItem( 0, 0, item );
ui.ResultTable->resizeRowToContents( 0 );
}
void MainWindow::AddFilenameToComboBox( const QString &filename )
{
int index = ui.FilepathsCombo->findText( filename );
if ( index == -1 )
{
ui.FilepathsCombo->insertItem( 0, filename );
ui.FilepathsCombo->setCurrentIndex( 0 );
}
else
{
ui.FilepathsCombo->setCurrentIndex( index );
}
}
void MainWindow::ReadSettings()
{
QSettings settings;
settings.beginGroup( SETTINGS_GROUP );
// The size of the window and it's full screen status
QByteArray geometry = settings.value( "geometry" ).toByteArray();
if ( !geometry.isNull() )
restoreGeometry( geometry );
ui.FilepathsCombo->addItems( settings.value( "path_strings" ).toStringList() );
m_LastFolderOpen = settings.value( "lastfolderopen" ).toString();
ui.FilepathsCombo->setCurrentIndex( settings.value( "lastusedcomboindex" ).toInt() );
}
void MainWindow::WriteSettings()
{
QSettings settings;
settings.beginGroup( SETTINGS_GROUP );
// The size of the window and it's full screen status
settings.setValue( "geometry", saveGeometry() );
QStringList path_strings;
for ( int i = 0; i < ui.FilepathsCombo->count(); ++i )
{
path_strings.append( ui.FilepathsCombo->itemText( i ) );
}
settings.setValue( "path_strings", path_strings );
settings.setValue( "lastusedcomboindex", ui.FilepathsCombo->currentIndex() );
settings.setValue( "lastfolderopen", m_LastFolderOpen );
}
void MainWindow::ConfigureTableForResults()
{
ui.ResultTable->setRowCount( 0 );
ui.ResultTable->setColumnCount( 3 );
ui.ResultTable->setHorizontalHeaderLabels(
QStringList() << tr( "File" ) << tr( "Line" ) << tr( "Message" ) );
ui.ResultTable->verticalHeader()->setResizeMode( QHeaderView::ResizeToContents );
}
void MainWindow::ConnectSignalsToSlots()
{
connect( ui.actionExit, SIGNAL( triggered() ), qApp, SLOT( closeAllWindows() ) );
connect( ui.GoButton, SIGNAL( clicked() ), this, SLOT( StartValidation() ) );
connect( ui.BrowseButton, SIGNAL( clicked() ), this, SLOT( BrowseForEpub() ) );
}
flightcrew-0.7.2/src/FlightCrew-gui/UpdateChecker.cpp 0000644 0001750 0001750 00000015412 11621123054 020620 0 ustar don don /************************************************************************
**
** Copyright (C) 2010 Strahinja Markovic
**
** This file is part of FlightCrew.
**
** FlightCrew is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published
** by the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** FlightCrew is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with FlightCrew. If not, see .
**
*************************************************************************/
#include
#include
#include
#include
#include
#include
#include
#include
#include