Added Enigma game
This commit is contained in:
7
project/jni/application/enigma/lib-src/zipios++/AUTHORS
Normal file
7
project/jni/application/enigma/lib-src/zipios++/AUTHORS
Normal file
@@ -0,0 +1,7 @@
|
||||
Main author: Thomas Sondergaard (thomass@deltadata.dk)
|
||||
Windows support: Kevin Shea (kevin.shea@d-cubed.co.uk)
|
||||
Bug fixes and test suite: Kirk Klobe (kirkk@visi.com)
|
||||
|
||||
The files zipios++/directory.h and zipios++/directory.cpp originate
|
||||
from the dir_it library written by Dietmar Kuehl (it's available for
|
||||
download at http://www.boost.org)
|
||||
515
project/jni/application/enigma/lib-src/zipios++/COPYING
Normal file
515
project/jni/application/enigma/lib-src/zipios++/COPYING
Normal file
@@ -0,0 +1,515 @@
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations
|
||||
below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
^L
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it
|
||||
becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
^L
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control
|
||||
compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
^L
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
^L
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
^L
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
^L
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply, and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License
|
||||
may add an explicit geographical distribution limitation excluding those
|
||||
countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
^L
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
^L
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms
|
||||
of the ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library.
|
||||
It is safest to attach them to the start of each source file to most
|
||||
effectively convey the exclusion of warranty; and each file should
|
||||
have at least the "copyright" line and a pointer to where the full
|
||||
notice is found.
|
||||
|
||||
|
||||
<one line to give the library's name and a brief idea of what it
|
||||
does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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
|
||||
|
||||
Also add information on how to contact you by electronic and paper
|
||||
mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or
|
||||
your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James
|
||||
Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
|
||||
|
||||
1101
project/jni/application/enigma/lib-src/zipios++/ChangeLog
Normal file
1101
project/jni/application/enigma/lib-src/zipios++/ChangeLog
Normal file
File diff suppressed because it is too large
Load Diff
182
project/jni/application/enigma/lib-src/zipios++/INSTALL
Normal file
182
project/jni/application/enigma/lib-src/zipios++/INSTALL
Normal file
@@ -0,0 +1,182 @@
|
||||
Basic Installation
|
||||
==================
|
||||
|
||||
These are generic installation instructions.
|
||||
|
||||
The `configure' shell script attempts to guess correct values for
|
||||
various system-dependent variables used during compilation. It uses
|
||||
those values to create a `Makefile' in each directory of the package.
|
||||
It may also create one or more `.h' files containing system-dependent
|
||||
definitions. Finally, it creates a shell script `config.status' that
|
||||
you can run in the future to recreate the current configuration, a file
|
||||
`config.cache' that saves the results of its tests to speed up
|
||||
reconfiguring, and a file `config.log' containing compiler output
|
||||
(useful mainly for debugging `configure').
|
||||
|
||||
If you need to do unusual things to compile the package, please try
|
||||
to figure out how `configure' could check whether to do them, and mail
|
||||
diffs or instructions to the address given in the `README' so they can
|
||||
be considered for the next release. If at some point `config.cache'
|
||||
contains results you don't want to keep, you may remove or edit it.
|
||||
|
||||
The file `configure.in' is used to create `configure' by a program
|
||||
called `autoconf'. You only need `configure.in' if you want to change
|
||||
it or regenerate `configure' using a newer version of `autoconf'.
|
||||
|
||||
The simplest way to compile this package is:
|
||||
|
||||
1. `cd' to the directory containing the package's source code and type
|
||||
`./configure' to configure the package for your system. If you're
|
||||
using `csh' on an old version of System V, you might need to type
|
||||
`sh ./configure' instead to prevent `csh' from trying to execute
|
||||
`configure' itself.
|
||||
|
||||
Running `configure' takes awhile. While running, it prints some
|
||||
messages telling which features it is checking for.
|
||||
|
||||
2. Type `make' to compile the package.
|
||||
|
||||
3. Optionally, type `make check' to run any self-tests that come with
|
||||
the package.
|
||||
|
||||
4. Type `make install' to install the programs and any data files and
|
||||
documentation.
|
||||
|
||||
5. You can remove the program binaries and object files from the
|
||||
source code directory by typing `make clean'. To also remove the
|
||||
files that `configure' created (so you can compile the package for
|
||||
a different kind of computer), type `make distclean'. There is
|
||||
also a `make maintainer-clean' target, but that is intended mainly
|
||||
for the package's developers. If you use it, you may have to get
|
||||
all sorts of other programs in order to regenerate files that came
|
||||
with the distribution.
|
||||
|
||||
Compilers and Options
|
||||
=====================
|
||||
|
||||
Some systems require unusual options for compilation or linking that
|
||||
the `configure' script does not know about. You can give `configure'
|
||||
initial values for variables by setting them in the environment. Using
|
||||
a Bourne-compatible shell, you can do that on the command line like
|
||||
this:
|
||||
CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
|
||||
|
||||
Or on systems that have the `env' program, you can do it like this:
|
||||
env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
|
||||
|
||||
Compiling For Multiple Architectures
|
||||
====================================
|
||||
|
||||
You can compile the package for more than one kind of computer at the
|
||||
same time, by placing the object files for each architecture in their
|
||||
own directory. To do this, you must use a version of `make' that
|
||||
supports the `VPATH' variable, such as GNU `make'. `cd' to the
|
||||
directory where you want the object files and executables to go and run
|
||||
the `configure' script. `configure' automatically checks for the
|
||||
source code in the directory that `configure' is in and in `..'.
|
||||
|
||||
If you have to use a `make' that does not supports the `VPATH'
|
||||
variable, you have to compile the package for one architecture at a time
|
||||
in the source code directory. After you have installed the package for
|
||||
one architecture, use `make distclean' before reconfiguring for another
|
||||
architecture.
|
||||
|
||||
Installation Names
|
||||
==================
|
||||
|
||||
By default, `make install' will install the package's files in
|
||||
`/usr/local/bin', `/usr/local/man', etc. You can specify an
|
||||
installation prefix other than `/usr/local' by giving `configure' the
|
||||
option `--prefix=PATH'.
|
||||
|
||||
You can specify separate installation prefixes for
|
||||
architecture-specific files and architecture-independent files. If you
|
||||
give `configure' the option `--exec-prefix=PATH', the package will use
|
||||
PATH as the prefix for installing programs and libraries.
|
||||
Documentation and other data files will still use the regular prefix.
|
||||
|
||||
In addition, if you use an unusual directory layout you can give
|
||||
options like `--bindir=PATH' to specify different values for particular
|
||||
kinds of files. Run `configure --help' for a list of the directories
|
||||
you can set and what kinds of files go in them.
|
||||
|
||||
If the package supports it, you can cause programs to be installed
|
||||
with an extra prefix or suffix on their names by giving `configure' the
|
||||
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
|
||||
|
||||
Optional Features
|
||||
=================
|
||||
|
||||
Some packages pay attention to `--enable-FEATURE' options to
|
||||
`configure', where FEATURE indicates an optional part of the package.
|
||||
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
|
||||
is something like `gnu-as' or `x' (for the X Window System). The
|
||||
`README' should mention any `--enable-' and `--with-' options that the
|
||||
package recognizes.
|
||||
|
||||
For packages that use the X Window System, `configure' can usually
|
||||
find the X include and library files automatically, but if it doesn't,
|
||||
you can use the `configure' options `--x-includes=DIR' and
|
||||
`--x-libraries=DIR' to specify their locations.
|
||||
|
||||
Specifying the System Type
|
||||
==========================
|
||||
|
||||
There may be some features `configure' can not figure out
|
||||
automatically, but needs to determine by the type of host the package
|
||||
will run on. Usually `configure' can figure that out, but if it prints
|
||||
a message saying it can not guess the host type, give it the
|
||||
`--host=TYPE' option. TYPE can either be a short name for the system
|
||||
type, such as `sun4', or a canonical name with three fields:
|
||||
CPU-COMPANY-SYSTEM
|
||||
|
||||
See the file `config.sub' for the possible values of each field. If
|
||||
`config.sub' isn't included in this package, then this package doesn't
|
||||
need to know the host type.
|
||||
|
||||
If you are building compiler tools for cross-compiling, you can also
|
||||
use the `--target=TYPE' option to select the type of system they will
|
||||
produce code for and the `--build=TYPE' option to select the type of
|
||||
system on which you are compiling the package.
|
||||
|
||||
Sharing Defaults
|
||||
================
|
||||
|
||||
If you want to set default values for `configure' scripts to share,
|
||||
you can create a site shell script called `config.site' that gives
|
||||
default values for variables like `CC', `cache_file', and `prefix'.
|
||||
`configure' looks for `PREFIX/share/config.site' if it exists, then
|
||||
`PREFIX/etc/config.site' if it exists. Or, you can set the
|
||||
`CONFIG_SITE' environment variable to the location of the site script.
|
||||
A warning: not all `configure' scripts look for a site script.
|
||||
|
||||
Operation Controls
|
||||
==================
|
||||
|
||||
`configure' recognizes the following options to control how it
|
||||
operates.
|
||||
|
||||
`--cache-file=FILE'
|
||||
Use and save the results of the tests in FILE instead of
|
||||
`./config.cache'. Set FILE to `/dev/null' to disable caching, for
|
||||
debugging `configure'.
|
||||
|
||||
`--help'
|
||||
Print a summary of the options to `configure', and exit.
|
||||
|
||||
`--quiet'
|
||||
`--silent'
|
||||
`-q'
|
||||
Do not print messages saying which checks are being made. To
|
||||
suppress all normal output, redirect it to `/dev/null' (any error
|
||||
messages will still be shown).
|
||||
|
||||
`--srcdir=DIR'
|
||||
Look for the package's source code in directory DIR. Usually
|
||||
`configure' can determine that directory automatically.
|
||||
|
||||
`--version'
|
||||
Print the version of Autoconf used to generate the `configure'
|
||||
script, and exit.
|
||||
|
||||
`configure' also accepts some other, not widely useful, options.
|
||||
64
project/jni/application/enigma/lib-src/zipios++/NEWS
Normal file
64
project/jni/application/enigma/lib-src/zipios++/NEWS
Normal file
@@ -0,0 +1,64 @@
|
||||
Release notes for Zipios++ 0.1.5
|
||||
--------------------------------
|
||||
New features:
|
||||
- Support for Visual C++ 6
|
||||
- VFS feature finished
|
||||
- Support for writing zip archives (pre-beta!)
|
||||
|
||||
Bug fixes:
|
||||
- Code reorganized and many minor bug fixes
|
||||
|
||||
Changes:
|
||||
- flex/lex is no longer required
|
||||
|
||||
|
||||
|
||||
Release notes for Zipios++ 0.1.4
|
||||
--------------------------------
|
||||
Bug fixes:
|
||||
- A bug in a code fragment used in all the test programs for copying
|
||||
data from an istream to an ostream has been fixed
|
||||
- A nasty and embarrasing bug in ZipInputStreambuf and
|
||||
InflateInputStreambuf that prevented zip entries containing the character
|
||||
255 from being correctly decompressed has been fixed
|
||||
|
||||
|
||||
|
||||
Release notes for Zipios++ 0.1.3
|
||||
--------------------------------
|
||||
Changes:
|
||||
- Changed the license to GNU Lesser General Public License
|
||||
|
||||
|
||||
|
||||
Release notes for Zipios++ 0.1.2
|
||||
--------------------------------
|
||||
New features:
|
||||
- ZipFile can now be used to read zip files embedded in other files. The
|
||||
static method ZipFile::openEmbeddedZipFile() can be used to open zip
|
||||
files embedded in another file with the binary appendzip, which is
|
||||
also part of the Zipios++ distribution
|
||||
|
||||
|
||||
Bug fixes:
|
||||
Installation:
|
||||
- Header files are now installed (under (usr/include/)zipios++/)
|
||||
- The library libzipios.a is now installed
|
||||
- The test binaries are no longer installed
|
||||
- Renamed config.h to zipios-config.h to avoid file name collisions
|
||||
|
||||
Building:
|
||||
- Added a switch --with-std-compliant-iostream (and --without-...)
|
||||
to the configure script, such that the library can be build against
|
||||
the old iostream.h library, even if a newer std compliant iostream
|
||||
implementation is available in iostream
|
||||
|
||||
Source:
|
||||
- Most functions now throw exceptions (reflected in the documentation)
|
||||
instead of printing error messages to stderr
|
||||
- Fixes to make the library compile and work with gcc 2.95.2
|
||||
|
||||
|
||||
Missing features and known bugs:
|
||||
- DirectoryCollection::entries() end DirectoryCollection::size() are
|
||||
not implemented yet
|
||||
81
project/jni/application/enigma/lib-src/zipios++/README
Normal file
81
project/jni/application/enigma/lib-src/zipios++/README
Normal file
@@ -0,0 +1,81 @@
|
||||
Introduction
|
||||
------------
|
||||
Zipios++ is a small C++ library for reading zip files. The structure
|
||||
and public interface are based (somewhat loosely) on the java.util.zip
|
||||
package. The streams created to access the individual entries in a zip
|
||||
file are based on the standard iostream library.
|
||||
|
||||
Zipios++ also provides a way for an application to support files from
|
||||
multiple sources (e.g. from zip files or from ordinary directories)
|
||||
transparently.
|
||||
|
||||
The source code is released under the GNU Lesser General Public
|
||||
License.
|
||||
|
||||
|
||||
Installation (Unix)
|
||||
-------------------
|
||||
This software package uses autoconf/automake, so the fast installation
|
||||
procedure is
|
||||
|
||||
./configure
|
||||
make
|
||||
make install
|
||||
|
||||
For details about installation of autoconfiscated packages refer to
|
||||
the INSTALL file
|
||||
|
||||
'make install' installs the Zipios++ header files under
|
||||
/usr/include/zipios++/ and the library libzipios.a under
|
||||
/usr/lib/. You can choose another base path than /usr/ by using the
|
||||
--prefix switch with configure. See the INSTALL file for
|
||||
details. Running make also builds a number of test programs that
|
||||
remain in the source directory zipios++/. The built example binaries
|
||||
and the corresponding source code have names that start with test_ and
|
||||
example_. These test programs demonstrate the most important features
|
||||
in Zipios++.
|
||||
|
||||
Installation (Windows)
|
||||
----------------------
|
||||
Currently, makefiles are only provided for Visual C++, along with a
|
||||
Developer Studio project. It is also planned to support Inprise and Gnu
|
||||
compilers in the near future.
|
||||
|
||||
Before building, if zlib is not in a standard compiler path, the location of
|
||||
its headers and .lib file must be defined at the top of win32\Makefile.com
|
||||
|
||||
To install, using the appropriate make program and one of the following
|
||||
makefiles:
|
||||
Makefile.vc5 - Visual C++ 5, 6
|
||||
|
||||
the procedure (for Visual C++) is
|
||||
cd win32
|
||||
nmake -f Makefile.vc5
|
||||
|
||||
To use the Developer Studio project, run configure.bat from win32 before
|
||||
compiling. Again, a non-standard location for zlib must be defined in the
|
||||
project settings before building.
|
||||
|
||||
No install options have been defined yet.
|
||||
|
||||
Status and Documentation
|
||||
-------------
|
||||
Please refer to the online documentation at
|
||||
http://zipios.sourceforge.net. A printable version of the online
|
||||
documentation is also available at the same URL. The documentation can
|
||||
be automatically generated from the source if you have Doxygen
|
||||
installed by running
|
||||
|
||||
./configure
|
||||
make doc
|
||||
|
||||
|
||||
Bugs
|
||||
----
|
||||
Submit bug reports and patches to thomass@deltadata.dk
|
||||
|
||||
Contributing
|
||||
------------
|
||||
If you're interested in helping with Zipios++ then drop me a note at
|
||||
thomass@deltadata.dk.
|
||||
|
||||
117
project/jni/application/enigma/lib-src/zipios++/src/backbuffer.h
Normal file
117
project/jni/application/enigma/lib-src/zipios++/src/backbuffer.h
Normal file
@@ -0,0 +1,117 @@
|
||||
#ifndef BACKBUFFER_H
|
||||
#define BACKBUFFER_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
#include <vector>
|
||||
|
||||
#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<int> ( static_cast< int >( _file_pos ), _chunk_size ) ;
|
||||
_file_pos -= _chunk_size ;
|
||||
_vs.vseekg( _is, _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
|
||||
*/
|
||||
@@ -0,0 +1,163 @@
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
#include <string>
|
||||
|
||||
#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 = 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 size ) {
|
||||
}
|
||||
|
||||
void BasicEntry::setCrc( uint32 crc ) {
|
||||
}
|
||||
|
||||
void BasicEntry::setExtra( const vector< unsigned char > &extra ) {
|
||||
}
|
||||
|
||||
void BasicEntry::setMethod( StorageMethod method ) {
|
||||
}
|
||||
|
||||
void BasicEntry::setName( const string &name ) {
|
||||
_filename = name ;
|
||||
}
|
||||
|
||||
void BasicEntry::setSize( uint32 size ) {
|
||||
_size = size ;
|
||||
}
|
||||
|
||||
void BasicEntry::setTime( int time ) {
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
*/
|
||||
162
project/jni/application/enigma/lib-src/zipios++/src/collcoll.cpp
Normal file
162
project/jni/application/enigma/lib-src/zipios++/src/collcoll.cpp
Normal file
@@ -0,0 +1,162 @@
|
||||
|
||||
#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
|
||||
*/
|
||||
@@ -0,0 +1,224 @@
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#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 = 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 = _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
|
||||
*/
|
||||
170
project/jni/application/enigma/lib-src/zipios++/src/dircoll.cpp
Normal file
170
project/jni/application/enigma/lib-src/zipios++/src/dircoll.cpp
Normal file
@@ -0,0 +1,170 @@
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
#include <vector>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "zipios++/dircoll.h"
|
||||
|
||||
#include "directory.h"
|
||||
|
||||
|
||||
using namespace zipios;
|
||||
|
||||
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() ) ;
|
||||
}
|
||||
|
||||
|
||||
std::istream *DirectoryCollection::getInputStream( const string &entry_name,
|
||||
MatchPath matchpath )
|
||||
{
|
||||
using std::ifstream ;
|
||||
|
||||
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 _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 ( dir_it it( _filepath + subdir ) ; it != dir_it() ; ++it ) {
|
||||
|
||||
if ( *it == "." || *it == ".." || *it == "..." )
|
||||
continue ;
|
||||
|
||||
if ( get< is_directory >( it ) && recursive ) {
|
||||
load( recursive, subdir + *it ) ;
|
||||
} else {
|
||||
_entries.push_back( ent = new BasicEntry( subdir + *it, "", _filepath ) ) ;
|
||||
ent->setSize( get< boost::filesystem::size >( it ) ) ;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
*/
|
||||
@@ -0,0 +1,393 @@
|
||||
/** \file
|
||||
This file and directory.h are borrowed from the dir_it library
|
||||
available at http://www.boost.org. dir_it is a directory iterator.
|
||||
*/
|
||||
|
||||
// -*-C++-*- directory.cc
|
||||
// <!!---------------------------------------------------------------------->
|
||||
// <!! Copyright (C) 1998 Dietmar Kuehl, Claas Solutions GmbH >
|
||||
// <!!>
|
||||
// <!! Permission to use, copy, modify, distribute and sell this >
|
||||
// <!! software for any purpose is hereby granted without fee, provided >
|
||||
// <!! that the above copyright notice appears in all copies and that >
|
||||
// <!! both that copyright notice and this permission notice appear in >
|
||||
// <!! supporting documentation. Dietmar Kuehl and Claas Solutions make no >
|
||||
// <!! representations about the suitability of this software for any >
|
||||
// <!! purpose. It is provided "as is" without express or implied warranty. >
|
||||
// <!!---------------------------------------------------------------------->
|
||||
|
||||
// Author: Dietmar Kuehl dietmar.kuehl@claas-solutions.de
|
||||
// Title: Implementation of the directory iterator
|
||||
// Version: $Name: $ $Id: directory.cpp,v 1.5 2004/05/01 17:33:11 dheck Exp $
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
#include "directory.h"
|
||||
|
||||
# define BOOST_UNIX 1
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// The POSIX version uses the functions opendir(), readdir(), and closdir()
|
||||
// to find directory entries. In addition, stat() is used to find out
|
||||
// about specific file attributes.
|
||||
|
||||
#if 1
|
||||
|
||||
#ifndef __USE_BSD
|
||||
#define __USE_BSD
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
|
||||
struct boost::filesystem::dir_it::representation
|
||||
{
|
||||
representation():
|
||||
m_handle(0),
|
||||
m_refcount(1),
|
||||
m_stat_p(false)
|
||||
{
|
||||
}
|
||||
|
||||
representation(std::string const &dirname):
|
||||
m_handle(opendir(dirname.c_str())),
|
||||
m_refcount(1),
|
||||
m_directory(dirname),
|
||||
m_stat_p(false)
|
||||
{
|
||||
if( m_directory.size() == 0 )
|
||||
m_directory = "./" ;
|
||||
if (m_directory[m_directory.size() - 1] != '/')
|
||||
m_directory += '/';
|
||||
operator++ ();
|
||||
}
|
||||
|
||||
~representation() { if ( m_handle ) closedir(m_handle); }
|
||||
|
||||
representation *reference()
|
||||
{
|
||||
++m_refcount;
|
||||
return this;
|
||||
}
|
||||
representation *release() { return --m_refcount? 0: this; }
|
||||
|
||||
representation &operator++()
|
||||
{
|
||||
if (m_handle)
|
||||
{
|
||||
m_stat_p = false;
|
||||
dirent *rc = readdir(m_handle);
|
||||
if (rc != 0)
|
||||
m_current = rc->d_name;
|
||||
else
|
||||
{
|
||||
m_current = "";
|
||||
closedir(m_handle);
|
||||
m_handle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator== (representation const &rep) const
|
||||
{
|
||||
return (m_handle == 0) == (rep.m_handle == 0);
|
||||
}
|
||||
|
||||
std::string const &operator* () { return m_current; }
|
||||
|
||||
struct stat &get_stat()
|
||||
{
|
||||
if (!m_stat_p)
|
||||
stat( (m_directory + m_current).c_str(), &m_stat);
|
||||
return m_stat;
|
||||
}
|
||||
|
||||
void set_mode(mode_t m, bool nv)
|
||||
{
|
||||
if (((get_stat().st_mode & m) == 0) == nv)
|
||||
chmod((m_directory + m_current).c_str(), get_stat().st_mode ^ m);
|
||||
}
|
||||
void change_owner(uid_t uid) { chown((m_directory + m_current).c_str(), uid, get_stat().st_gid); }
|
||||
void change_group(gid_t gid) { chown((m_directory + m_current).c_str(), get_stat().st_uid, gid); }
|
||||
|
||||
private:
|
||||
DIR *m_handle;
|
||||
int m_refcount;
|
||||
std::string m_directory;
|
||||
std::string m_current;
|
||||
struct stat m_stat;
|
||||
bool m_stat_p;
|
||||
};
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
|
||||
template <> bool get<is_link>(dir_it const &it) { return S_ISLNK(it.rep->get_stat().st_mode); }
|
||||
template <> bool get<is_regular>(dir_it const &it) { return S_ISREG(it.rep->get_stat().st_mode); }
|
||||
template <> bool get<is_directory>(dir_it const &it) { return S_ISDIR(it.rep->get_stat().st_mode); }
|
||||
template <> bool get<is_char_device>(dir_it const &it) { return S_ISCHR(it.rep->get_stat().st_mode); }
|
||||
template <> bool get<is_block_device>(dir_it const &it) { return S_ISBLK(it.rep->get_stat().st_mode); }
|
||||
template <> bool get<is_fifo>(dir_it const &it) { return S_ISFIFO(it.rep->get_stat().st_mode); }
|
||||
template <> bool get<is_socket>(dir_it const &it) { return S_ISSOCK(it.rep->get_stat().st_mode); }
|
||||
|
||||
template <> bool get<user_read>(dir_it const &it) { return it.rep->get_stat().st_mode & S_IRUSR; }
|
||||
template <> void set<user_read>(dir_it const &it, bool nv) { it.rep->set_mode(S_IRUSR, nv); }
|
||||
template <> bool get<user_write>(dir_it const &it) { return it.rep->get_stat().st_mode & S_IWUSR; }
|
||||
template <> void set<user_write>(dir_it const &it, bool nv) { it.rep->set_mode(S_IWUSR, nv); }
|
||||
template <> bool get<user_execute>(dir_it const &it) { return it.rep->get_stat().st_mode & S_IXUSR; }
|
||||
template <> void set<user_execute>(dir_it const &it, bool nv) { it.rep->set_mode(S_IXUSR, nv); }
|
||||
template <> bool get<set_uid>(dir_it const &it) { return it.rep->get_stat().st_mode & S_ISUID; }
|
||||
template <> void set<set_uid>(dir_it const &it, bool nv) { it.rep->set_mode(S_ISUID, nv); }
|
||||
|
||||
template <> bool get<group_read>(dir_it const &it) { return it.rep->get_stat().st_mode & S_IRGRP; }
|
||||
template <> void set<group_read>(dir_it const &it, bool nv) { it.rep->set_mode(S_IRGRP, nv); }
|
||||
template <> bool get<group_write>(dir_it const &it) { return it.rep->get_stat().st_mode & S_IWGRP; }
|
||||
template <> void set<group_write>(dir_it const &it, bool nv) { it.rep->set_mode(S_IWGRP, nv); }
|
||||
template <> bool get<group_execute>(dir_it const &it) { return it.rep->get_stat().st_mode & S_IXGRP; }
|
||||
template <> void set<group_execute>(dir_it const &it, bool nv) { it.rep->set_mode(S_IXGRP, nv); }
|
||||
template <> bool get<set_gid>(dir_it const &it) { return it.rep->get_stat().st_mode & S_ISGID; }
|
||||
template <> void set<set_gid>(dir_it const &it, bool nv) { it.rep->set_mode(S_ISGID, nv); }
|
||||
|
||||
template <> bool get<other_read>(dir_it const &it) { return it.rep->get_stat().st_mode & S_IROTH; }
|
||||
template <> void set<other_read>(dir_it const &it, bool nv) { it.rep->set_mode(S_IROTH, nv); }
|
||||
template <> bool get<other_write>(dir_it const &it) { return it.rep->get_stat().st_mode & S_IWOTH; }
|
||||
template <> void set<other_write>(dir_it const &it, bool nv) { it.rep->set_mode(S_IWOTH, nv); }
|
||||
template <> bool get<other_execute>(dir_it const &it) { return it.rep->get_stat().st_mode & S_IXOTH; }
|
||||
template <> void set<other_execute>(dir_it const &it, bool nv) { it.rep->set_mode(S_IXOTH, nv); }
|
||||
template <> bool get<sticky>(dir_it const &it) { return it.rep->get_stat().st_mode & S_ISVTX; }
|
||||
template <> void set<sticky>(dir_it const &it, bool nv) { it.rep->set_mode(S_ISVTX, nv); }
|
||||
|
||||
template <> nlink_t get<links>(dir_it const &it) { return it.rep->get_stat().st_nlink; }
|
||||
template <> size_t get<size>(dir_it const &it) { return it.rep->get_stat().st_size; }
|
||||
template <> unsigned long get<blocks>(dir_it const &it) { return it.rep->get_stat().st_blocks; }
|
||||
template <> unsigned long get<blksize>(dir_it const &it) { return it.rep->get_stat().st_blksize; }
|
||||
|
||||
template <> mtime::value_type get<mtime>(dir_it const &it) { return (const time_t*)&it.rep->get_stat().st_mtime; }
|
||||
template <> atime::value_type get<atime>(dir_it const &it) { return (time_t*)&it.rep->get_stat().st_atime; }
|
||||
template <> ctime::value_type get<ctime>(dir_it const &it) { return (time_t*)&it.rep->get_stat().st_ctime; }
|
||||
|
||||
template <> uid_t get<uid>(dir_it const &it) { return it.rep->get_stat().st_uid; }
|
||||
template <> void set<uid>(dir_it const &it, uid_t uid) { it.rep->change_owner(uid); }
|
||||
template <> std::string get<uname>(dir_it const &it)
|
||||
{
|
||||
struct passwd *pw = getpwuid(it.rep->get_stat().st_uid);
|
||||
if (pw == 0)
|
||||
throw unknown_uid(it.rep->get_stat().st_uid);
|
||||
return pw->pw_name;
|
||||
}
|
||||
template <> void set<uname>(dir_it const &it, std::string name)
|
||||
{
|
||||
struct passwd *pw = getpwnam(name.c_str());
|
||||
if (pw != 0)
|
||||
it.rep->change_owner(pw->pw_uid);
|
||||
else
|
||||
throw unknown_uname(name);
|
||||
}
|
||||
|
||||
template <> gid_t get<gid>(dir_it const &it) { return it.rep->get_stat().st_gid; }
|
||||
template <> void set<gid>(dir_it const &it, gid_t gid) { it.rep->change_group(gid); }
|
||||
template <> std::string get<gname>(dir_it const &it)
|
||||
{
|
||||
struct group *grp = getgrgid(it.rep->get_stat().st_gid);
|
||||
if (grp == 0)
|
||||
throw unknown_gid(it.rep->get_stat().st_gid);
|
||||
return grp->gr_name;
|
||||
}
|
||||
template <> void set<gname>(dir_it const &it, std::string name)
|
||||
{
|
||||
struct group *grp = getgrnam(name.c_str());
|
||||
if (grp != 0)
|
||||
it.rep->change_group(grp->gr_gid);
|
||||
else
|
||||
throw unknown_gname(name);
|
||||
}
|
||||
|
||||
|
||||
template <> bool get<is_hidden>(dir_it const &it) { return (*it)[0] == '.'; }
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(BOOST_WINNT)
|
||||
|
||||
#include "io.h"
|
||||
#include "direct.h"
|
||||
|
||||
struct boost::filesystem::dir_it::representation
|
||||
{
|
||||
representation():
|
||||
m_handle(-1),
|
||||
m_refcount(1)
|
||||
{
|
||||
}
|
||||
|
||||
representation(std::string const &dirname):
|
||||
m_handle(_findfirst((dirname + "\\*").c_str(), &m_data)),
|
||||
m_refcount(1)
|
||||
{
|
||||
}
|
||||
|
||||
~representation() { if (m_handle != -1) _findclose(m_handle); }
|
||||
|
||||
representation *reference()
|
||||
{
|
||||
++m_refcount;
|
||||
return this;
|
||||
}
|
||||
representation *release() { return --m_refcount? 0: this; }
|
||||
|
||||
representation &operator++()
|
||||
{
|
||||
if (m_handle != -1)
|
||||
{
|
||||
if (_findnext(m_handle, &m_data) == -1)
|
||||
{
|
||||
_findclose(m_handle);
|
||||
m_handle = -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator== (representation const &rep) const
|
||||
{
|
||||
return (m_handle == -1) == (rep.m_handle == -1);
|
||||
}
|
||||
|
||||
std::string operator* () { return m_data.name; }
|
||||
|
||||
|
||||
struct _finddata_t const &get_data() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void set_mode(mode_t m, bool nv)
|
||||
{
|
||||
if (((get_stat().st_mode & m) == 0) == nv)
|
||||
chmod((m_directory + m_current).c_str(), get_stat().st_mode ^ m);
|
||||
}
|
||||
void change_owner(uid_t uid) { chown((m_directory + m_current).c_str(), uid, get_stat().st_gid); }
|
||||
void change_group(gid_t gid) { chown((m_directory + m_current).c_str(), get_stat().st_uid, gid); }
|
||||
#endif
|
||||
|
||||
private:
|
||||
struct _finddata_t m_data;
|
||||
long m_handle;
|
||||
int m_refcount;
|
||||
std::string m_directory;
|
||||
};
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
#if 0
|
||||
template <> size_t get<size> (dir_it const &it) //::operator size::value_type() const
|
||||
{
|
||||
return it.rep->get_data().size;
|
||||
}
|
||||
template <> get<mtime>::operator mtime::value_type() const
|
||||
{
|
||||
return &m_it.rep->get_data().time_write;
|
||||
}
|
||||
template <> get<is_directory>::operator is_directory::value_type() const
|
||||
{
|
||||
return (m_it.rep->get_data().attrib & _A_SUBDIR) != 0;
|
||||
}
|
||||
template <> get<is_regular>::operator is_regular::value_type() const
|
||||
{
|
||||
return (m_it.rep->get_data().attrib & _A_SUBDIR) == 0;
|
||||
}
|
||||
template <> get<is_hidden>::operator is_hidden::value_type() const
|
||||
{
|
||||
return (m_it.rep->get_data().attrib & _A_HIDDEN) != 0;
|
||||
}
|
||||
template <> get<user_read>::operator user_read::value_type() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
template <> get<user_write>::operator user_write::value_type() const
|
||||
{
|
||||
return (m_it.rep->get_data().attrib & _A_RDONLY) == 0;
|
||||
}
|
||||
template <> get<user_execute>::operator user_execute::value_type() const
|
||||
{
|
||||
std::string name(*m_it);
|
||||
std::string ext(name.substr(name.find_last_of('.')));
|
||||
return ext == ".exe" || ext == ".bat";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
boost::filesystem::dir_it::dir_it():
|
||||
rep(new representation())
|
||||
{
|
||||
}
|
||||
|
||||
boost::filesystem::dir_it::dir_it(std::string const &dirname):
|
||||
rep(new representation(dirname))
|
||||
{
|
||||
}
|
||||
|
||||
boost::filesystem::dir_it::dir_it(boost::filesystem::dir_it const &it):
|
||||
rep(it.rep->reference())
|
||||
{
|
||||
}
|
||||
|
||||
boost::filesystem::dir_it::~dir_it()
|
||||
{
|
||||
delete rep->release();
|
||||
}
|
||||
|
||||
boost::filesystem::dir_it &boost::filesystem::dir_it::operator= (boost::filesystem::dir_it const &it)
|
||||
{
|
||||
it.rep->reference();
|
||||
delete rep->release();
|
||||
rep = it.rep;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
std::string boost::filesystem::dir_it::operator* () const
|
||||
{
|
||||
return *(*rep);
|
||||
}
|
||||
|
||||
boost::filesystem::dir_it &boost::filesystem::dir_it::operator++ ()
|
||||
{
|
||||
++(*rep);
|
||||
return *this;
|
||||
}
|
||||
|
||||
boost::filesystem::dir_it::proxy boost::filesystem::dir_it::operator++ (int)
|
||||
{
|
||||
std::string rc(*(*rep));
|
||||
++(*rep);
|
||||
return rc;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
bool boost::filesystem::dir_it::operator== (boost::filesystem::dir_it const &it) const
|
||||
{
|
||||
return *rep == *(it.rep);
|
||||
}
|
||||
|
||||
bool boost::filesystem::dir_it::operator!= (boost::filesystem::dir_it const &it) const
|
||||
{
|
||||
return !(*rep == *(it.rep));
|
||||
}
|
||||
351
project/jni/application/enigma/lib-src/zipios++/src/directory.h
Normal file
351
project/jni/application/enigma/lib-src/zipios++/src/directory.h
Normal file
@@ -0,0 +1,351 @@
|
||||
/** \file
|
||||
This file and directory.cpp are borrowed from the dir_it library
|
||||
available at http://www.boost.org. dir_it is a directory iterator.
|
||||
*/
|
||||
|
||||
// -*-C++-*- directory.h
|
||||
// <!!---------------------------------------------------------------------->
|
||||
// <!! Copyright (C) 1998 Dietmar Kuehl, Claas Solutions GmbH >
|
||||
// <!!>
|
||||
// <!! Permission to use, copy, modify, distribute and sell this >
|
||||
// <!! software for any purpose is hereby granted without fee, provided >
|
||||
// <!! that the above copyright notice appears in all copies and that >
|
||||
// <!! both that copyright notice and this permission notice appear in >
|
||||
// <!! supporting documentation. Dietmar Kuehl and Claas Solutions make no >
|
||||
// <!! representations about the suitability of this software for any >
|
||||
// <!! purpose. It is provided "as is" without express or implied warranty. >
|
||||
// <!!---------------------------------------------------------------------->
|
||||
|
||||
// Author: Dietmar Kuehl dietmar.kuehl@claas-solutions.de
|
||||
// Title: An input iterator used to list the entries in a directory
|
||||
// Version: $Name: $ $Id: directory.h,v 1.6 2004/05/01 17:33:10 dheck Exp $
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
#if !defined(BOOST_DIRECTORY_H)
|
||||
#define BOOST_DIRECTORY_H 1
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include <stdexcept>
|
||||
|
||||
// #include <boost.h> Contents of boost.h
|
||||
|
||||
// Allow control over DLL version being built
|
||||
# define BOOST_DECL
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
class dir_it;
|
||||
|
||||
#if defined(__GNUG__)
|
||||
template <class Property>
|
||||
typename Property::value_type get(dir_it const &);
|
||||
template <class Property>
|
||||
void set(dir_it const &, typename Property::value_type);
|
||||
#else
|
||||
template <class Property> class get;
|
||||
template <class Property> class set;
|
||||
#endif
|
||||
|
||||
class BOOST_DECL dir_it //: public std::iterator<std::input_iterator_tag, std::string>
|
||||
{
|
||||
#if defined(__GNUG__)
|
||||
template <class Property>
|
||||
friend typename Property::value_type get(dir_it const &);
|
||||
template <class Property>
|
||||
friend void set(dir_it const &, typename Property::value_type);
|
||||
#endif
|
||||
|
||||
struct representation;
|
||||
|
||||
public:
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef std::string value_type;
|
||||
typedef std::string *pointer;
|
||||
typedef std::string &reference;
|
||||
|
||||
class proxy
|
||||
{
|
||||
friend class dir_it;
|
||||
proxy(std::string const &ent): entry(ent) {}
|
||||
public:
|
||||
std::string operator*() const { return entry; }
|
||||
private:
|
||||
std::string entry;
|
||||
};
|
||||
|
||||
dir_it();
|
||||
dir_it(std::string const &);
|
||||
dir_it(dir_it const &);
|
||||
~dir_it();
|
||||
dir_it &operator= (dir_it const &);
|
||||
|
||||
std::string operator* () const;
|
||||
dir_it &operator++ ();
|
||||
proxy operator++ (int);
|
||||
|
||||
bool operator== (dir_it const &) const;
|
||||
bool operator!= (dir_it const &) const;
|
||||
|
||||
#if defined(__GNUG__)
|
||||
private:
|
||||
#endif
|
||||
representation *rep;
|
||||
};
|
||||
|
||||
struct size { typedef size_t value_type; };
|
||||
struct mtime { typedef time_t const *value_type; };
|
||||
|
||||
struct is_directory { typedef bool value_type; };
|
||||
struct is_regular { typedef bool value_type; };
|
||||
struct is_hidden { typedef bool value_type; };
|
||||
|
||||
struct user_read { typedef bool value_type; };
|
||||
struct user_write { typedef bool value_type; };
|
||||
struct user_execute { typedef bool value_type; };
|
||||
|
||||
#if defined(__GNUG__)
|
||||
template <> size::value_type get<size>(dir_it const &);
|
||||
template <> mtime::value_type get<mtime>(dir_it const &);
|
||||
template <> bool get<is_directory>(dir_it const &);
|
||||
template <> bool get<is_regular>(dir_it const &);
|
||||
template <> bool get<is_hidden>(dir_it const &);
|
||||
template <> bool get<user_read>(dir_it const &);
|
||||
template <> void set<user_read>(dir_it const &, bool);
|
||||
template <> bool get<user_write>(dir_it const &);
|
||||
template <> void set<user_write>(dir_it const &, bool);
|
||||
template <> bool get<user_execute>(dir_it const &);
|
||||
template <> void set<user_execute>(dir_it const &, bool);
|
||||
#else
|
||||
template <> class BOOST_DECL get<size>
|
||||
{
|
||||
typedef size::value_type value_type;
|
||||
public:
|
||||
get(dir_it const &it): m_it(it) {}
|
||||
operator value_type() const;
|
||||
private:
|
||||
dir_it const &m_it;
|
||||
};
|
||||
|
||||
template <> class BOOST_DECL get<mtime>
|
||||
{
|
||||
typedef mtime::value_type value_type;
|
||||
public:
|
||||
get(dir_it const &it): m_it(it) {}
|
||||
operator value_type() const;
|
||||
private:
|
||||
dir_it const &m_it;
|
||||
};
|
||||
|
||||
template <> class BOOST_DECL get<is_directory>
|
||||
{
|
||||
typedef is_directory::value_type value_type;
|
||||
public:
|
||||
get(dir_it const &it): m_it(it) {}
|
||||
operator value_type() const;
|
||||
private:
|
||||
dir_it const &m_it;
|
||||
};
|
||||
|
||||
template <> class BOOST_DECL get<is_regular>
|
||||
{
|
||||
typedef is_regular::value_type value_type;
|
||||
public:
|
||||
get(dir_it const &it): m_it(it) {}
|
||||
operator value_type() const;
|
||||
private:
|
||||
dir_it const &m_it;
|
||||
};
|
||||
|
||||
template <> class BOOST_DECL get<is_hidden>
|
||||
{
|
||||
typedef is_hidden::value_type value_type;
|
||||
public:
|
||||
get(dir_it const &it): m_it(it) {}
|
||||
operator value_type() const;
|
||||
private:
|
||||
dir_it const &m_it;
|
||||
};
|
||||
template <> class BOOST_DECL set<is_hidden>
|
||||
{
|
||||
public:
|
||||
set(dir_it const &, is_hidden::value_type);
|
||||
};
|
||||
|
||||
template <> class BOOST_DECL get<user_read>
|
||||
{
|
||||
typedef user_read::value_type value_type;
|
||||
public:
|
||||
get(dir_it const &it): m_it(it) {}
|
||||
operator value_type() const;
|
||||
private:
|
||||
dir_it const &m_it;
|
||||
};
|
||||
|
||||
template <> class BOOST_DECL get<user_write>
|
||||
{
|
||||
typedef user_write::value_type value_type;
|
||||
public:
|
||||
get(dir_it const &it): m_it(it) {}
|
||||
operator value_type() const;
|
||||
private:
|
||||
dir_it const &m_it;
|
||||
};
|
||||
template <> class BOOST_DECL set<user_write>
|
||||
{
|
||||
public:
|
||||
set(dir_it const &, user_write::value_type);
|
||||
};
|
||||
|
||||
template <> class BOOST_DECL get<user_execute>
|
||||
{
|
||||
typedef user_execute::value_type value_type;
|
||||
public:
|
||||
get(dir_it const &it): m_it(it) {}
|
||||
operator value_type() const;
|
||||
private:
|
||||
dir_it const &m_it;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
struct is_link { typedef bool value_type; };
|
||||
template <> bool get<is_link>(dir_it const &);
|
||||
|
||||
struct is_char_device { typedef bool value_type; };
|
||||
template <> bool get<is_char_device>(dir_it const &);
|
||||
|
||||
struct is_block_device { typedef bool value_type; };
|
||||
template <> bool get<is_block_device>(dir_it const &);
|
||||
|
||||
struct is_fifo { typedef bool value_type; };
|
||||
template <> bool get<is_fifo>(dir_it const &);
|
||||
|
||||
struct is_socket { typedef bool value_type; };
|
||||
template <> bool get<is_socket>(dir_it const &);
|
||||
|
||||
struct atime { typedef time_t *value_type; };
|
||||
template <> atime::value_type get<atime>(dir_it const &);
|
||||
struct ctime { typedef time_t *value_type; };
|
||||
template <> ctime::value_type get<ctime>(dir_it const &);
|
||||
|
||||
struct group_read { typedef bool value_type; };
|
||||
template <> bool get<group_read>(dir_it const &);
|
||||
template <> void set<group_read>(dir_it const &, bool);
|
||||
struct group_write { typedef bool value_type; };
|
||||
template <> bool get<group_write>(dir_it const &);
|
||||
template <> void set<group_write>(dir_it const &, bool);
|
||||
struct group_execute { typedef bool value_type; };
|
||||
template <> bool get<group_execute>(dir_it const &);
|
||||
template <> void set<group_execute>(dir_it const &, bool);
|
||||
struct other_read { typedef bool value_type; };
|
||||
template <> bool get<other_read>(dir_it const &);
|
||||
template <> void set<other_read>(dir_it const &, bool);
|
||||
struct other_write { typedef bool value_type; };
|
||||
template <> bool get<other_write>(dir_it const &);
|
||||
template <> void set<other_write>(dir_it const &, bool);
|
||||
struct other_execute { typedef bool value_type; };
|
||||
template <> bool get<other_execute>(dir_it const &);
|
||||
template <> void set<other_execute>(dir_it const &, bool);
|
||||
|
||||
struct set_uid { typedef bool value_type; };
|
||||
template <> bool get<set_uid>(dir_it const &);
|
||||
template <> void set<set_uid>(dir_it const &, bool);
|
||||
struct set_gid { typedef bool value_type; };
|
||||
template <> bool get<set_gid>(dir_it const &);
|
||||
template <> void set<set_gid>(dir_it const &, bool);
|
||||
struct sticky { typedef bool value_type; };
|
||||
template <> bool get<sticky>(dir_it const &);
|
||||
template <> void set<sticky>(dir_it const &, bool);
|
||||
|
||||
struct mode { typedef mode_t value_type; };
|
||||
template <> mode_t get<mode>(dir_it const &);
|
||||
template <> void set<mode>(dir_it const &, mode_t);
|
||||
|
||||
struct links { typedef nlink_t value_type; };
|
||||
template<> nlink_t get<links>(dir_it const &);
|
||||
struct blocks { typedef unsigned long value_type; };
|
||||
template<> unsigned long get<blocks>(dir_it const &);
|
||||
struct blksize { typedef unsigned long value_type; };
|
||||
template<> unsigned long get<blksize>(dir_it const &);
|
||||
|
||||
class unknown_uid: public std::invalid_argument
|
||||
{
|
||||
public:
|
||||
unknown_uid(uid_t u): std::invalid_argument("unknown user ID"), m_uid(u) {}
|
||||
uid_t uid() const { return m_uid; }
|
||||
private:
|
||||
uid_t m_uid;
|
||||
};
|
||||
struct uid { typedef uid_t value_type; };
|
||||
template<> uid_t get<uid>(dir_it const &);
|
||||
template<> void set<uid>(dir_it const &, uid_t);
|
||||
class unknown_uname: public std::invalid_argument
|
||||
{
|
||||
public:
|
||||
unknown_uname(std::string u): std::invalid_argument("unknown user name"), m_uname(u) {}
|
||||
// TODO: Why does this destructor have to be redefined so as to avoid the "looser throw specifier" error.
|
||||
~unknown_uname() throw() { }
|
||||
std::string uname() const { return m_uname; }
|
||||
private:
|
||||
std::string m_uname;
|
||||
};
|
||||
struct uname { typedef std::string value_type; };
|
||||
template<> std::string get<uname>(dir_it const &);
|
||||
template<> void set<uname>(dir_it const &, std::string );
|
||||
|
||||
class unknown_gid: public std::invalid_argument
|
||||
{
|
||||
public:
|
||||
unknown_gid(gid_t g): std::invalid_argument("unknown group ID"), m_gid(g) {}
|
||||
gid_t gid() const { return m_gid; }
|
||||
private:
|
||||
gid_t m_gid;
|
||||
};
|
||||
struct gid { typedef gid_t value_type; };
|
||||
template<> gid_t get<gid>(dir_it const &);
|
||||
template<> void set<gid>(dir_it const &, gid_t);
|
||||
class unknown_gname: public std::invalid_argument
|
||||
{
|
||||
public:
|
||||
unknown_gname(std::string g): std::invalid_argument("unknown group name"), m_gname(g) {}
|
||||
// TODO: Why does this destructor have to be redefined so as to avoid the "looser throw specifier" error.
|
||||
~unknown_gname() throw() { }
|
||||
std::string gname() const { return m_gname; }
|
||||
private:
|
||||
std::string m_gname;
|
||||
};
|
||||
struct gname { typedef std::string value_type; };
|
||||
template<> std::string get<gname>(dir_it const &);
|
||||
template<> void set<gname>(dir_it const &, std::string );
|
||||
|
||||
|
||||
} // namespace filesystem
|
||||
} // namespace boost
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <>
|
||||
struct iterator_traits<boost::filesystem::dir_it> {
|
||||
public:
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef std::string value_type;
|
||||
typedef std::string *pointer;
|
||||
typedef std::string &reference;
|
||||
typedef input_iterator_tag iterator_category;
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
#endif /* BOOST_DIRECTORY_H */
|
||||
@@ -0,0 +1,90 @@
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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 _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
|
||||
*/
|
||||
@@ -0,0 +1,144 @@
|
||||
|
||||
#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 ()
|
||||
: _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 ()
|
||||
: _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 ()
|
||||
: _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 ()
|
||||
: _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
|
||||
*/
|
||||
@@ -0,0 +1,39 @@
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
#include <string>
|
||||
|
||||
#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
|
||||
*/
|
||||
@@ -0,0 +1,72 @@
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#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 ;
|
||||
_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 ) ; // doesn't work with mingw32
|
||||
_is_fifo = S_ISFIFO( buf.st_mode ) ;
|
||||
}
|
||||
}
|
||||
|
||||
} // 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
|
||||
*/
|
||||
@@ -0,0 +1,47 @@
|
||||
|
||||
#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
|
||||
*/
|
||||
@@ -0,0 +1,47 @@
|
||||
|
||||
#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
|
||||
*/
|
||||
@@ -0,0 +1,179 @@
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#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 = _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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 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
|
||||
*/
|
||||
@@ -0,0 +1,69 @@
|
||||
#ifndef OUTPUTSTRINGSTREAM_H
|
||||
#define OUTPUTSTRINGSTREAM_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
#include <string>
|
||||
|
||||
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 std::ostrstream {
|
||||
public:
|
||||
|
||||
/** Specialization of ostrstream::str() that takes care of
|
||||
null-terminating the string and unfreezing the ostrstream. */
|
||||
inline std::string str() {
|
||||
*this << std::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!
|
||||
std::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
|
||||
*/
|
||||
208
project/jni/application/enigma/lib-src/zipios++/src/zipfile.cpp
Normal file
208
project/jni/application/enigma/lib-src/zipios++/src/zipfile.cpp
Normal file
@@ -0,0 +1,208 @@
|
||||
|
||||
#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"
|
||||
|
||||
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 ) ;
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
return new ZipInputStream( _filename,
|
||||
static_cast< const ZipCDirEntry * >( ent.get() )->
|
||||
getLocalHeaderOffset() + _vs.startOffset() ) ;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 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
|
||||
*/
|
||||
291
project/jni/application/enigma/lib-src/zipios++/src/ziphead.cpp
Normal file
291
project/jni/application/enigma/lib-src/zipios++/src/ziphead.cpp
Normal file
@@ -0,0 +1,291 @@
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#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 {
|
||||
//std::assert( filename.size() != 0 ) ;
|
||||
return filename[ filename.size() - 1 ] == separator ;
|
||||
}
|
||||
|
||||
|
||||
void ZipLocalEntry::setComment( const string &comment ) {
|
||||
// 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 = extra_field.size() ;
|
||||
}
|
||||
|
||||
void ZipLocalEntry::setMethod( StorageMethod method ) {
|
||||
compress_method = static_cast< uint16 >( method ) ;
|
||||
}
|
||||
|
||||
void ZipLocalEntry::setName( const string &name ) {
|
||||
filename = name ;
|
||||
filename_len = 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
|
||||
}
|
||||
|
||||
string ZipLocalEntry::toString() const {
|
||||
OutputStringStream sout ;
|
||||
sout << filename << " (" << uncompress_size << " bytes, " ;
|
||||
sout << compress_size << " bytes compressed)" ;
|
||||
return sout.str() ;
|
||||
}
|
||||
|
||||
int ZipLocalEntry::getLocalHeaderSize() const {
|
||||
return 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 = 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 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<unsigned char> &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
|
||||
*/
|
||||
@@ -0,0 +1,195 @@
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
|
||||
#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 &dd ) {
|
||||
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
|
||||
*/
|
||||
@@ -0,0 +1,80 @@
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
|
||||
#include "zipios++/zipinputstreambuf.h"
|
||||
#include "zipios++/zipinputstream.h"
|
||||
|
||||
namespace zipios {
|
||||
|
||||
ZipInputStream::ZipInputStream( std::istream &is, std::streampos pos )
|
||||
: std::istream( 0 ),
|
||||
// SGIs basic_ifstream calls istream with 0, but calls basic_ios constructor first??
|
||||
ifs( 0 )
|
||||
{
|
||||
izf = new ZipInputStreambuf( is.rdbuf(), pos ) ;
|
||||
// this->rdbuf( izf ) ; is replaced by:
|
||||
this->init( izf ) ;
|
||||
}
|
||||
|
||||
ZipInputStream::ZipInputStream( const std::string &filename, std::streampos pos )
|
||||
: std::istream( 0 ),
|
||||
ifs( 0 )
|
||||
{
|
||||
ifs = new std::ifstream( filename.c_str(), std::ios::in |std:: ios::binary ) ;
|
||||
izf = new ZipInputStreambuf( ifs->rdbuf(), 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
|
||||
*/
|
||||
@@ -0,0 +1,140 @@
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#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 )
|
||||
{
|
||||
ConstEntryPointer entry = getNextEntry() ;
|
||||
|
||||
if ( ! entry->isValid() ) {
|
||||
; // FIXME: throw something?
|
||||
}
|
||||
}
|
||||
|
||||
void ZipInputStreambuf::closeEntry() {
|
||||
if ( ! _open_entry )
|
||||
return ;
|
||||
|
||||
// check if we're positioned correctly, otherwise position us correctly
|
||||
int position = _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 >> _curr_entry ;
|
||||
if ( _curr_entry.isValid() ) {
|
||||
_data_start = _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" ) ;
|
||||
}
|
||||
} else {
|
||||
_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 = _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
|
||||
*/
|
||||
@@ -0,0 +1,52 @@
|
||||
#ifndef ZIPIOS_COMMON_H
|
||||
#define ZIPIOS_COMMON_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace zipios {
|
||||
|
||||
using std::vector;
|
||||
|
||||
static const char separator = '/' ;
|
||||
|
||||
template< class Type >
|
||||
void operator += ( vector< Type > &v1, const vector< Type > &v2 ) {
|
||||
typename std::vector<Type>::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
|
||||
*/
|
||||
@@ -0,0 +1,101 @@
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
|
||||
#include "zipios++/zipoutputstreambuf.h"
|
||||
#include "zipios++/zipoutputstream.h"
|
||||
|
||||
namespace zipios {
|
||||
|
||||
ZipOutputStream::ZipOutputStream( std::ostream &os )
|
||||
: std::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 )
|
||||
: std::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
|
||||
*/
|
||||
@@ -0,0 +1,193 @@
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#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( 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 = 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() ) ;
|
||||
|
||||
// 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 = 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( 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
|
||||
*/
|
||||
@@ -0,0 +1,87 @@
|
||||
#ifndef BASICENTRY_H
|
||||
#define BASICENTRY_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
#include <string>
|
||||
|
||||
#include "zipios++/fcollexceptions.h"
|
||||
#include "zipios++/fileentry.h"
|
||||
#include "zipios++/filepath.h"
|
||||
#include "zipios++/zipios_defs.h"
|
||||
|
||||
namespace zipios {
|
||||
|
||||
/** BasicEntry is a FileEntry that is suitable as a base class for
|
||||
basic entries, that e.g. do not support any form of compression */
|
||||
class BasicEntry : public FileEntry {
|
||||
public:
|
||||
/** Constructor.
|
||||
@param filename the filename of the entry.
|
||||
@param comment a comment for the entry.
|
||||
*/
|
||||
explicit BasicEntry( const string &filename, const string &comment,
|
||||
const FilePath &basepath = FilePath() ) ;
|
||||
virtual string getComment() const ;
|
||||
virtual uint32 getCompressedSize() const ;
|
||||
virtual uint32 getCrc() const ;
|
||||
virtual vector< unsigned char > getExtra() const ;
|
||||
virtual StorageMethod getMethod() const ;
|
||||
virtual string getName() const ;
|
||||
virtual string getFileName() const ;
|
||||
virtual uint32 getSize() const ;
|
||||
virtual int getTime() const ;
|
||||
virtual bool isValid() const ;
|
||||
|
||||
// virtual int hashCode() const ;
|
||||
virtual bool isDirectory() const ;
|
||||
|
||||
virtual void setComment( const string &comment ) ;
|
||||
virtual void setCompressedSize( uint32 size ) ;
|
||||
virtual void setCrc( uint32 crc ) ;
|
||||
virtual void setExtra( const vector< unsigned char > &extra ) ;
|
||||
virtual void setMethod( StorageMethod method ) ;
|
||||
virtual void setName( const string &name ) ;
|
||||
virtual void setSize( uint32 size ) ;
|
||||
virtual void setTime( int time ) ;
|
||||
|
||||
virtual string toString() const ;
|
||||
|
||||
virtual FileEntry *clone() const ;
|
||||
|
||||
virtual ~BasicEntry() ;
|
||||
protected:
|
||||
string _filename ;
|
||||
string _comment ;
|
||||
int _size ;
|
||||
bool _valid ;
|
||||
FilePath _basepath ;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
/** \file
|
||||
Header file that defines 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
|
||||
*/
|
||||
@@ -0,0 +1,174 @@
|
||||
#ifndef COLLCOLL_H
|
||||
#define COLLCOLL_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "zipios++/fcoll.h"
|
||||
|
||||
namespace zipios {
|
||||
|
||||
using std::string ;
|
||||
|
||||
/** \anchor collcoll_anchor
|
||||
CollectionCollection is a FileCollection that consists of an
|
||||
arbitrary number of FileCollections. With a CollectionCollection
|
||||
the user can use multiple FileCollections transparently, making it
|
||||
easy for a program to keep some of its files in a zip archive and
|
||||
others stored in ordinary files. CollectionCollection can be used
|
||||
to create a simple virtual filesystem, where all collections are
|
||||
mounted in /. If more than one collection contain a file with
|
||||
the same path only the one in the first added collection will
|
||||
be accessible.
|
||||
*/
|
||||
class CollectionCollection : public FileCollection {
|
||||
public:
|
||||
/** \anchor collcoll_inst_anchor
|
||||
This static method provides a singleton instance of a CollectionCollection.
|
||||
The instance is instantiated the first time the method is called.
|
||||
@return A pointer to a singleton CollectionCollection instance.
|
||||
*/
|
||||
static inline CollectionCollection &inst() ;
|
||||
|
||||
/** Constructor.
|
||||
*/
|
||||
explicit CollectionCollection() ;
|
||||
|
||||
/** Copy constructor. */
|
||||
inline CollectionCollection( const CollectionCollection &src ) ;
|
||||
|
||||
/** Copy assignment operator. */
|
||||
inline const CollectionCollection &operator= ( const CollectionCollection &src ) ;
|
||||
|
||||
/** \anchor collcoll_addcoll_anchor
|
||||
Adds a collection.
|
||||
@param collection The collection to add.
|
||||
@return true if the collection was added succesfully and
|
||||
the added collection is valid.
|
||||
*/
|
||||
bool addCollection( const FileCollection &collection ) ;
|
||||
|
||||
/** Adds the collection pointed to by collection. The CollectionCollection
|
||||
will call delete on the pointer when it is destructed, so the caller
|
||||
should make absolutely sure to only pass in a collection created with new
|
||||
and be sure to leave it alone after adding it. If the collection is not
|
||||
added false is returned and the caller remains responsible for the
|
||||
collection pointed to by collection.
|
||||
@param collection A pointer to the collection to add.
|
||||
@return true if the collection was added succesfully and
|
||||
the added collection is valid. */
|
||||
bool addCollection( FileCollection *collection ) ;
|
||||
|
||||
virtual void close() ;
|
||||
|
||||
virtual ConstEntries entries() const ;
|
||||
|
||||
virtual ConstEntryPointer getEntry( const string &name,
|
||||
MatchPath matchpath = MATCH ) const ;
|
||||
|
||||
virtual istream *getInputStream( const ConstEntryPointer &entry ) ;
|
||||
|
||||
virtual istream *getInputStream( const string &entry_name,
|
||||
MatchPath matchpath = MATCH ) ;
|
||||
|
||||
/** Returns the number in entries in all collections kept by
|
||||
the CollectionCollection object */
|
||||
virtual int size() const ;
|
||||
|
||||
virtual FileCollection *clone() const ;
|
||||
|
||||
virtual ~CollectionCollection() ;
|
||||
|
||||
protected:
|
||||
/** A protected getEntry member function, that not only
|
||||
finds an entry that match the name, if such an entry exists
|
||||
in the collection, it also returns, which collection it was found
|
||||
in.
|
||||
*/
|
||||
void getEntry( const string &name,
|
||||
ConstEntryPointer &cep,
|
||||
std::vector< FileCollection * >::const_iterator &it,
|
||||
MatchPath matchpath = MATCH ) const ;
|
||||
|
||||
vector< FileCollection * > _collections ;
|
||||
private:
|
||||
static CollectionCollection *_inst ;
|
||||
};
|
||||
|
||||
|
||||
/** Shortcut name for a CollectionCollection. If the static method
|
||||
inst is used, it is often used a lot, so it's handy with a short name for
|
||||
CollectionCollection */
|
||||
typedef CollectionCollection CColl ;
|
||||
|
||||
|
||||
//
|
||||
// Inline (member) functions
|
||||
//
|
||||
|
||||
CollectionCollection &CollectionCollection::inst() {
|
||||
if( _inst != 0 )
|
||||
return *_inst ;
|
||||
else
|
||||
return *( _inst = new CollectionCollection ) ;
|
||||
}
|
||||
|
||||
CollectionCollection::CollectionCollection( const CollectionCollection &src )
|
||||
: FileCollection( src )
|
||||
{
|
||||
_collections.reserve( src._collections.size() ) ;
|
||||
std::vector< FileCollection * >::const_iterator it ;
|
||||
for ( it = src._collections.begin() ; it != src._collections.end() ; ++it )
|
||||
_collections.push_back( (*it)->clone() ) ;
|
||||
}
|
||||
|
||||
|
||||
const CollectionCollection &
|
||||
CollectionCollection::operator= ( const CollectionCollection &src ) {
|
||||
this->FileCollection::operator=( src ) ;
|
||||
// FileCollection::=( static_cast< FileCollection >( src ) ) ;
|
||||
|
||||
if ( this != &src ) {
|
||||
// Destroy current contents.
|
||||
std::vector< FileCollection * >::const_iterator it ;
|
||||
for ( it = _collections.begin() ; it != _collections.end() ; ++it )
|
||||
delete *it ;
|
||||
// Then copy src's content.
|
||||
_collections.clear() ;
|
||||
_collections.reserve( src._collections.size() ) ;
|
||||
for ( it = src._collections.begin() ; it != src._collections.end() ; ++it )
|
||||
_collections.push_back( (*it)->clone() ) ;
|
||||
}
|
||||
return *this ;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/** \file
|
||||
Header file that defines 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
|
||||
*/
|
||||
@@ -0,0 +1,109 @@
|
||||
#ifndef DEFLATEOUTPUTSTREAMBUF_H
|
||||
#define DEFLATEOUTPUTSTREAMBUF_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
#include <vector>
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#include "zipios++/filteroutputstreambuf.h"
|
||||
#include "zipios++/ziphead.h"
|
||||
#include "zipios++/zipios_defs.h"
|
||||
|
||||
namespace zipios {
|
||||
|
||||
using std::vector ;
|
||||
|
||||
/** DeflateOutputStreambuf is an output stream filter, that deflates
|
||||
the data that is written to it before it passes it on to the
|
||||
output stream it is attached to. Deflation/Inflation is a
|
||||
compression/decompression method used in gzip and zip. The zlib
|
||||
library is used to perform the actual deflation, this class only
|
||||
wraps the functionality in an output stream filter. */
|
||||
class DeflateOutputStreambuf : public FilterOutputStreambuf {
|
||||
public:
|
||||
|
||||
/** DeflateOutputStreambuf constructor.
|
||||
@param outbuf the streambuf to use for output.
|
||||
@param user_init If false user must invoke init() before writing any data.
|
||||
(ZipOutputStreambuf needs to do this)
|
||||
@param del_outbuf if true is specified outbuf will be deleted, when
|
||||
the DeflateOutputStreambuf is destructed. */
|
||||
explicit DeflateOutputStreambuf( streambuf *outbuf, bool user_init = false,
|
||||
bool del_outbuf = false ) ;
|
||||
|
||||
/** Destructor. */
|
||||
virtual ~DeflateOutputStreambuf() ;
|
||||
|
||||
bool init( int comp_level = 6 ) ;
|
||||
bool closeStream() ;
|
||||
|
||||
/** Returns the CRC32 for the current stream. The returned value is
|
||||
the CRC for the data that has been compressed already (due to a
|
||||
call to overflow()). As DeflateOutputStreambuf may buffer an
|
||||
arbitrary amount of bytes until closeStream() has been invoked,
|
||||
the returned value is not very useful before closeStream() has
|
||||
been called. */
|
||||
uint32 getCrc32() const { return _crc32 ; }
|
||||
|
||||
/** Returns the number of bytes written to the streambuf, that has
|
||||
been processed from the input buffer by the compressor. After
|
||||
closeStream() has been called this number is the total number of
|
||||
bytes written to the stream. */
|
||||
uint32 getCount() const { return _overflown_bytes ; }
|
||||
|
||||
protected:
|
||||
virtual int overflow( int c = EOF ) ;
|
||||
virtual int sync() ;
|
||||
|
||||
/** Flushes _outvec and updates _zs.next_out and _zs.avail_out. */
|
||||
bool flushOutvec() ;
|
||||
|
||||
/** Flushes the remaining data in the zlib buffers, after which the
|
||||
only possible operations are deflateEnd() or deflateReset(). */
|
||||
void endDeflation() ;
|
||||
|
||||
private:
|
||||
z_stream _zs ;
|
||||
bool _zs_initialized ;
|
||||
protected: // FIXME: reconsider design?
|
||||
const int _invecsize ;
|
||||
vector< char > _invec ;
|
||||
const int _outvecsize ;
|
||||
vector< char > _outvec ;
|
||||
|
||||
uint32 _crc32 ;
|
||||
uint32 _overflown_bytes ;
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/** \file
|
||||
Header file that defines 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
|
||||
*/
|
||||
@@ -0,0 +1,93 @@
|
||||
#ifndef DIRCOLL_H
|
||||
#define DIRCOLL_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
|
||||
#include "zipios++/fcoll.h"
|
||||
#include "zipios++/basicentry.h"
|
||||
#include "zipios++/filepath.h"
|
||||
|
||||
namespace zipios {
|
||||
|
||||
/** DirEntry is a BasicEntry. */
|
||||
typedef BasicEntry DirEntry ;
|
||||
|
||||
/** \anchor dircol_anchor
|
||||
DirectoryCollection is a FileCollection that obtains its entries
|
||||
from a directory. */
|
||||
class DirectoryCollection : public FileCollection {
|
||||
public:
|
||||
|
||||
/** Default Constructor. */
|
||||
explicit DirectoryCollection()
|
||||
: _entries_loaded( false ), _recursive( true ) {}
|
||||
|
||||
|
||||
/** Constructor.
|
||||
@param path A directory path name. If the name is not a valid
|
||||
directory the created DirectoryCollection will be invalid.
|
||||
@param load_now Load directory into memory now. Otherwise it will
|
||||
be done when it is first needed.
|
||||
*/
|
||||
explicit DirectoryCollection( const string &path,
|
||||
bool recursive = true,
|
||||
bool load_now = false ) ;
|
||||
|
||||
/* Default Copy constructor and copy assignment operator are sufficient. */
|
||||
|
||||
virtual void close() ;
|
||||
|
||||
virtual ConstEntries entries() const ;
|
||||
|
||||
virtual ConstEntryPointer getEntry( const string &name,
|
||||
MatchPath matchpath = MATCH ) const ;
|
||||
|
||||
virtual istream *getInputStream( const ConstEntryPointer &entry ) ;
|
||||
|
||||
virtual istream *getInputStream( const string &entry_name,
|
||||
MatchPath matchpath = MATCH ) ;
|
||||
|
||||
virtual int size() const ;
|
||||
|
||||
virtual FileCollection *clone() const ;
|
||||
|
||||
/** Destructor. */
|
||||
virtual ~DirectoryCollection() ;
|
||||
|
||||
protected:
|
||||
mutable bool _entries_loaded ;
|
||||
bool _recursive ; // recurse into subdirs.
|
||||
FilePath _filepath ;
|
||||
|
||||
void loadEntries() const ;
|
||||
void load( bool recursive, const FilePath &subdir = FilePath() ) ;
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
|
||||
/** \file
|
||||
Header file that defines 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
|
||||
*/
|
||||
307
project/jni/application/enigma/lib-src/zipios++/zipios++/fcoll.h
Normal file
307
project/jni/application/enigma/lib-src/zipios++/zipios++/fcoll.h
Normal file
@@ -0,0 +1,307 @@
|
||||
#ifndef fcoll_H
|
||||
#define fcoll_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#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 <A
|
||||
HREF="http://www.gnu.org/copyleft/lesser.html">GNU Lesser General Public
|
||||
License</A>.
|
||||
|
||||
\section status Status
|
||||
|
||||
Spanned archives are not supported, and support is not planned.
|
||||
|
||||
|
||||
The library has been tested and appears to be working with
|
||||
<UL>
|
||||
<LI><A HREF="http://www.freebsd.org/ports/archivers.html#zipios++-0.1.5">FreeBSD stable and current / gcc 2.95.3</A></LI>
|
||||
<LI>Red Hat Linux release 7.0 / gcc 2.96</LI>
|
||||
<LI>Red Hat Linux release 6.2 (Zoot) / egcs-2.91.66</LI>
|
||||
<LI>Linux Mandrake release 7.0 (Air) / gcc 2.95.2</LI>
|
||||
<LI>SGI IRIX64 6.5 / gcc 2.95.2</LI>
|
||||
<LI>SGI IRIX64 6.5 / MIPSpro Compilers: Version 7.30</LI>
|
||||
</UL>
|
||||
|
||||
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 <A
|
||||
HREF="http://www.stack.nl/~dimitri/doxygen/index.html">Doxygen</A>. Use
|
||||
the links at the top of the page to browse the API
|
||||
documentation. The documentation is also available in
|
||||
a printer-friendly format <A HREF="refman.pdf">[pdf]</A>.
|
||||
|
||||
\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. A new ZipInputStream reads from the first entry, and
|
||||
the user can skip to the next entry by calling
|
||||
\ref ZipInputStream_getnextentry_anchor "ZipInputStream::getNextEntry()".
|
||||
|
||||
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.
|
||||
<A HREF="http://sourceforge.net/project/?group_id=5418" >
|
||||
http://sourceforge.net/project/?group_id=5418</A>
|
||||
|
||||
\section links Links
|
||||
<A HREF="ftp://ftp.freesoftware.com/pub/infozip/zlib/zlib.html">zlib</A>.
|
||||
The compression library that Zipios++ uses to perform the actual
|
||||
decompression.
|
||||
|
||||
<A HREF="http://java.sun.com/products/jdk/1.3/docs/api/index.html">
|
||||
Java 2 Platform, Standard Edition, v 1.3 API Specification
|
||||
</A>. Zipios++ is heavily inspired by the java.util.zip package.
|
||||
|
||||
<A
|
||||
HREF="http://www.geocities.com/SiliconValley/Lakes/2160/fformats/files/zip.txt">
|
||||
PKWARE zip format
|
||||
</A>. A description of the zip file format.
|
||||
|
||||
\section bugs Bugs
|
||||
Submit bug reports and patches to thomass@deltadata.dk
|
||||
|
||||
|
||||
|
||||
\htmlonly
|
||||
Project hosted by <A HREF="http://sourceforge.net">
|
||||
<img src="http://sourceforge.net/sflogo.php?group_id=5418&type=1" >
|
||||
</A><p>
|
||||
Logo created with <A HREF="http://www.webgfx.ch/titlepic.htm">
|
||||
<img src="webgfx.gif" >
|
||||
</A>
|
||||
\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
|
||||
*/
|
||||
@@ -0,0 +1,100 @@
|
||||
#ifndef FCOLLEXCEPTIONS_H
|
||||
#define FCOLLEXCEPTIONS_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
namespace zipios {
|
||||
|
||||
using std::string ;
|
||||
using std::exception ;
|
||||
|
||||
/** An IOException is used to signal an I/O error.
|
||||
*/
|
||||
class IOException : public exception {
|
||||
public:
|
||||
IOException() throw () ;
|
||||
explicit IOException( const string &msg ) throw () ;
|
||||
IOException( const IOException &src ) throw () ;
|
||||
IOException &operator= ( const IOException &src ) throw () ;
|
||||
|
||||
virtual const char *what() const throw () ;
|
||||
virtual ~IOException() throw () ;
|
||||
private:
|
||||
string _what ;
|
||||
};
|
||||
|
||||
/** An FCollException is used to signal a problem with a
|
||||
FileCollection. */
|
||||
class FCollException : public exception {
|
||||
public:
|
||||
FCollException() throw () ;
|
||||
explicit FCollException( const string &msg ) throw () ;
|
||||
FCollException( const FCollException &src ) throw () ;
|
||||
FCollException &operator= ( const FCollException &src ) throw () ;
|
||||
|
||||
virtual const char *what() const throw () ;
|
||||
virtual ~FCollException() throw () ;
|
||||
private:
|
||||
string _what ;
|
||||
};
|
||||
|
||||
/** An object member function may throw this exception, if the
|
||||
operation it normally performs is inappropriate or impossible to
|
||||
perform because of the current state of the object. */
|
||||
class InvalidStateException : public exception {
|
||||
public:
|
||||
InvalidStateException() throw () ;
|
||||
explicit InvalidStateException( const string &msg ) throw () ;
|
||||
InvalidStateException( const InvalidStateException &src ) throw () ;
|
||||
InvalidStateException &operator= ( const InvalidStateException &src ) throw () ;
|
||||
|
||||
virtual const char *what() const throw () ;
|
||||
virtual ~InvalidStateException() throw () ;
|
||||
private:
|
||||
string _what ;
|
||||
};
|
||||
|
||||
/** Basic exception */
|
||||
class Exception : public exception {
|
||||
public:
|
||||
Exception() throw () ;
|
||||
explicit Exception( const string &msg ) throw () ;
|
||||
Exception( const Exception &src ) throw () ;
|
||||
Exception &operator= ( const Exception &src ) throw () ;
|
||||
|
||||
virtual const char *what() const throw () ;
|
||||
virtual ~Exception() throw () ;
|
||||
private:
|
||||
string _what ;
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
/** \file
|
||||
Header file that defines 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
|
||||
*/
|
||||
@@ -0,0 +1,240 @@
|
||||
#ifndef FILEENTRY_H
|
||||
#define FILEENTRY_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
|
||||
#include "zipios++/simplesmartptr.h"
|
||||
#include "zipios++/zipios_defs.h"
|
||||
|
||||
namespace zipios {
|
||||
|
||||
using std::vector ;
|
||||
using std::ostream ;
|
||||
using std::istream ;
|
||||
using std::string ;
|
||||
|
||||
/** The types used with FileEntry::setMethod and
|
||||
FileEntry::getMethod. The current entries are the types supported
|
||||
by the zip format. The numbering also matches the numbering used
|
||||
in the zip file format, ie STORED is indicated by a 0 in the
|
||||
method field in a zip file and so on. */
|
||||
enum StorageMethod { STORED = 0, SHRUNK, REDUCED1, REDUCED2,
|
||||
REDUCED3, REDUCED4, IMPLODED, RESERVED,
|
||||
DEFLATED } ;
|
||||
|
||||
class FileEntry ;
|
||||
|
||||
/** \typedef typedef SimpleSmartPointer< FileEntry > EntryPointer
|
||||
EntryPointer is a SimpleSmartPointer for FileEntry's. */
|
||||
typedef SimpleSmartPointer< FileEntry > EntryPointer ;
|
||||
|
||||
|
||||
/** ConstEntryPointer is a SimpleSmartPointer for const FileEntry's. */
|
||||
typedef SimpleSmartPointer< const FileEntry > ConstEntryPointer ;
|
||||
|
||||
/** Entries is a vector of EntryPointer's */
|
||||
typedef vector< EntryPointer > Entries ;
|
||||
|
||||
/** ConstEntries is a vector of ConstEntryPointer's */
|
||||
typedef vector< EntryPointer > ConstEntries ;
|
||||
|
||||
|
||||
|
||||
/** A FileEntry represents an entry in a FileCollection. The interface
|
||||
is a copy of the ZipEntry interface from the java.util.zip
|
||||
package. The name has been changed to FileEntry, as FileCollection
|
||||
is a more general abstraction, that covers other types of file
|
||||
collections than just zip files. */
|
||||
class FileEntry {
|
||||
public:
|
||||
|
||||
/* Default construcotr, copy constructor and copy assignment
|
||||
operator are sufficient. */
|
||||
|
||||
/** Returns the comment of the entry, if it has one. Otherwise it
|
||||
returns an empty string.
|
||||
@return the comment associated with the entry, if there is one.
|
||||
*/
|
||||
virtual string getComment() const = 0 ;
|
||||
/** Returns the compressed size of the entry. If the entry is not
|
||||
stored in a compressed format, the uncompressed size is
|
||||
returned.
|
||||
@return the compressed size of the entry. If the entry is stored without
|
||||
compression the uncompressed size is returned.
|
||||
*/
|
||||
virtual uint32 getCompressedSize() const = 0 ;
|
||||
/** Returns the Crc for the entry, if it has one. FIXME: what is
|
||||
returned if it doesn't have one?
|
||||
@return the Crc for the entry, if it has one.
|
||||
*/
|
||||
virtual uint32 getCrc() const = 0 ;
|
||||
/** Returns a vector of bytes of extra data that may be stored with
|
||||
the entry.
|
||||
@return A vector< unsigned char > of extra bytes that may potentially
|
||||
be associated with an entry.
|
||||
*/
|
||||
virtual vector< unsigned char > getExtra() const = 0 ;
|
||||
/** Returns the method used to store the entry in the FileCollection.
|
||||
@return the storage method used to store the entry in the collection.
|
||||
@see StorageMethod.
|
||||
*/
|
||||
virtual StorageMethod getMethod() const = 0 ;
|
||||
/** Returns the full filename of the entry, including a path if the
|
||||
entry is stored in a subfolder.
|
||||
@return the filename of the entry, including path if the entry is stored
|
||||
in a sub-folder.
|
||||
*/
|
||||
virtual string getName() const = 0 ;
|
||||
/** Returns the filename of the entry.
|
||||
@return Returns the filename of the entry.
|
||||
*/
|
||||
virtual string getFileName() const = 0 ;
|
||||
/** Returns the (uncompressed) size of the entry data.
|
||||
@return Returns the (uncompressed) size of the entry.
|
||||
*/
|
||||
virtual uint32 getSize() const = 0 ;
|
||||
/** Returns the date and time of FIXME: what?
|
||||
@return the date and time of the entry.
|
||||
*/
|
||||
virtual int getTime() const = 0 ;
|
||||
/** Any method or operator that initializes a FileEntry may set a
|
||||
flag, that specifies whether the read entry is valid or not. If
|
||||
it isn't this method returns false.
|
||||
@return true if the FileEntry has been parsed succesfully.
|
||||
*/
|
||||
virtual bool isValid() const = 0 ;
|
||||
// virtual int hashCode() const = 0 ;
|
||||
/** Returns true if the entry is a directory. A directory entry is
|
||||
an entry which name ends with a separator ('/' for Unix systems,
|
||||
'\' for Windows and DOS systems.
|
||||
@return true if the entry is a directory.
|
||||
*/
|
||||
virtual bool isDirectory() const = 0 ;
|
||||
|
||||
/** Sets the comment field for the FileEntry.
|
||||
@param comment string with the new comment.
|
||||
*/
|
||||
virtual void setComment( const string &comment ) = 0 ;
|
||||
/** Set the compressed size field of the entry.
|
||||
@param size value to set the compressed size field of the entry to.
|
||||
*/
|
||||
virtual void setCompressedSize( uint32 size ) = 0 ;
|
||||
/** Sets the crc field.
|
||||
@param crc value to set the crc field to.
|
||||
*/
|
||||
virtual void setCrc( uint32 crc ) = 0 ;
|
||||
/** Sets the extra field.
|
||||
@param extra the extra field is set to this value.
|
||||
*/
|
||||
virtual void setExtra( const vector< unsigned char > &extra ) = 0 ;
|
||||
/** Sets the storage method field for the entry.
|
||||
@param method the method field is set to the specified value.
|
||||
*/
|
||||
virtual void setMethod( StorageMethod method ) = 0 ;
|
||||
/** Sets the name field for the entry.
|
||||
@param name the name field is set to the specified value.
|
||||
*/
|
||||
virtual void setName( const string &name ) = 0 ;
|
||||
/** Sets the size field for the entry.
|
||||
@param size the size field is set to this value.
|
||||
*/
|
||||
virtual void setSize( uint32 size ) = 0 ;
|
||||
/** Sets the time field for the entry.
|
||||
@param time the time field is set to the specified value.
|
||||
*/
|
||||
virtual void setTime( int time ) = 0 ;
|
||||
|
||||
/** Returns a human-readable string representation of the entry.
|
||||
@return a human-readable string representation of the entry.
|
||||
*/
|
||||
virtual string toString() const = 0 ;
|
||||
|
||||
/** 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 FileEntry *clone() const = 0 ;
|
||||
|
||||
/** FileEntry destructor. */
|
||||
virtual ~FileEntry() {}
|
||||
|
||||
// protected:
|
||||
class MatchName ;
|
||||
class MatchFileName ;
|
||||
protected:
|
||||
friend class SimpleSmartPointer< FileEntry > ;
|
||||
friend class SimpleSmartPointer< const FileEntry > ;
|
||||
void ref() const { _refcount.ref() ; }
|
||||
unsigned int unref() const { return _refcount.unref() ; }
|
||||
|
||||
ReferenceCount< FileEntry > _refcount ;
|
||||
};
|
||||
|
||||
/** Function object to be used with the STL find_if algorithm to
|
||||
find a FileEntry in a container, which name (as obtained with
|
||||
FileEntry::getName()) is identical to the name specified in the
|
||||
MatchName constructor. */
|
||||
class FileEntry::MatchName {
|
||||
public:
|
||||
explicit MatchName( const string &name ) : _name( name ) {}
|
||||
bool operator() ( const ConstEntryPointer &entry ) {
|
||||
return entry->getName() == _name ;
|
||||
}
|
||||
private:
|
||||
string _name ;
|
||||
};
|
||||
|
||||
/** Function object to be used with the STL find_if algorithm to
|
||||
find a FileEntry in a container, which name (as obtained with
|
||||
FileEntry::getFileName()) is identical to the name specified in the
|
||||
MatchName constructor. */
|
||||
class FileEntry::MatchFileName {
|
||||
public:
|
||||
explicit MatchFileName( const string &name ) : _name( name ) {}
|
||||
bool operator() ( const ConstEntryPointer &entry ) {
|
||||
return entry->getFileName() == _name ;
|
||||
}
|
||||
private:
|
||||
string _name ;
|
||||
};
|
||||
|
||||
ostream &operator<< ( ostream &os, const FileEntry &entry ) ;
|
||||
|
||||
inline ostream &operator<< ( ostream &os, const ConstEntryPointer &entry ) {
|
||||
os << *entry ;
|
||||
return os ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/** \file
|
||||
Header file that defines 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
|
||||
*/
|
||||
@@ -0,0 +1,202 @@
|
||||
#ifndef FILEPATH_H
|
||||
#define FILEPATH_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
namespace zipios {
|
||||
|
||||
using namespace std ;
|
||||
|
||||
/** FilePath represents a path to a file or directory name. FilePath has
|
||||
member functions to check if the file path is a valid file system entity,
|
||||
and to check what kind of file system entity it is, e.g. is it a file, a
|
||||
directory, a pipe etc.
|
||||
*/
|
||||
class FilePath {
|
||||
public:
|
||||
/** Constructor.
|
||||
@param path A string representation of the path.
|
||||
@param check_exists If true is specified the constructor will
|
||||
check the existence and type of the path immidiately, instead of
|
||||
deferring that task until it is needed. */
|
||||
FilePath( const string &path = "", bool check_exists = false ) ;
|
||||
|
||||
inline FilePath &operator= ( const string &rhs ) ;
|
||||
|
||||
inline operator string() const ;
|
||||
|
||||
/** Concatenates FilePath objects. A file separator is inserted
|
||||
if appropriate. */
|
||||
inline FilePath operator+ ( const FilePath &name ) const ;
|
||||
|
||||
/** Returns filename of the FilePath object by pruning the path
|
||||
off. */
|
||||
inline FilePath filename() const ;
|
||||
|
||||
|
||||
/** @return true If the path is a valid file system entity. */
|
||||
inline bool exists() const ;
|
||||
|
||||
/** @return true if the path is a regular file. */
|
||||
inline bool isRegular() const ;
|
||||
|
||||
/** @return true if the path is a directory. */
|
||||
inline bool isDirectory() const ;
|
||||
|
||||
/** @return true if the path is character special (a character
|
||||
device file). */
|
||||
inline bool isCharSpecial() const ;
|
||||
|
||||
/** @return true if the path is block special (a block device
|
||||
file). */
|
||||
inline bool isBlockSpecial() const ;
|
||||
|
||||
/** @return true if the path is a socket. */
|
||||
inline bool isSocket() const ;
|
||||
|
||||
/** @return true if the path is a Fifo (a pipe). */
|
||||
inline bool isFifo() const ;
|
||||
|
||||
protected:
|
||||
|
||||
/** Prunes the trailing separator of a specified path. */
|
||||
inline void pruneTrailingSeparator() ;
|
||||
|
||||
/** This function sets _checked to true, stats the path, to see if
|
||||
it exists and to determine what type of file it is. All the query
|
||||
functions check if _checked is true, and if it isn't they call
|
||||
check(). This means stat'ing is deferred until it becomes
|
||||
necessary. */
|
||||
void check() const ;
|
||||
|
||||
static const char _separator;
|
||||
|
||||
// FIXME: Should be bitfield
|
||||
mutable bool _checked ;
|
||||
mutable bool _exists ;
|
||||
mutable bool _is_reg ;
|
||||
mutable bool _is_dir ;
|
||||
mutable bool _is_char ;
|
||||
mutable bool _is_block ;
|
||||
mutable bool _is_socket ;
|
||||
mutable bool _is_fifo ;
|
||||
string _path ;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Inline member functions
|
||||
//
|
||||
|
||||
FilePath &FilePath::operator= ( const string &rhs ) {
|
||||
_path = rhs ;
|
||||
pruneTrailingSeparator() ;
|
||||
return *this ;
|
||||
}
|
||||
|
||||
void FilePath::pruneTrailingSeparator() {
|
||||
if ( _path.size() > 0 )
|
||||
if ( _path[ _path.size() -1 ] == _separator )
|
||||
_path.erase( _path.size() - 1 ) ;
|
||||
}
|
||||
|
||||
FilePath::operator string() const {
|
||||
return _path ;
|
||||
}
|
||||
|
||||
|
||||
FilePath FilePath::operator+ ( const FilePath &name ) const {
|
||||
if ( _path.size() > 0 )
|
||||
return _path + _separator + name._path ;
|
||||
else
|
||||
return name._path ;
|
||||
}
|
||||
|
||||
|
||||
FilePath FilePath::filename() const {
|
||||
string::size_type pos ;
|
||||
pos = _path.find_last_of( _separator ) ;
|
||||
if ( pos != string::npos )
|
||||
return _path.substr( pos + 1);
|
||||
else
|
||||
return _path ;
|
||||
}
|
||||
|
||||
|
||||
bool FilePath::exists() const {
|
||||
if ( ! _checked )
|
||||
check() ;
|
||||
return _exists ;
|
||||
}
|
||||
|
||||
|
||||
bool FilePath::isRegular() const {
|
||||
if ( ! _checked )
|
||||
check() ;
|
||||
return _is_reg ;
|
||||
}
|
||||
|
||||
|
||||
bool FilePath::isDirectory() const {
|
||||
if ( ! _checked )
|
||||
check() ;
|
||||
return _is_dir ;
|
||||
}
|
||||
|
||||
|
||||
bool FilePath::isCharSpecial() const {
|
||||
if ( ! _checked )
|
||||
check() ;
|
||||
return _is_char ;
|
||||
}
|
||||
|
||||
|
||||
bool FilePath::isBlockSpecial() const {
|
||||
if ( ! _checked )
|
||||
check() ;
|
||||
return _is_block ;
|
||||
}
|
||||
|
||||
|
||||
bool FilePath::isSocket() const {
|
||||
if ( ! _checked )
|
||||
check() ;
|
||||
return _is_socket ;
|
||||
}
|
||||
|
||||
|
||||
bool FilePath::isFifo() const {
|
||||
if ( ! _checked )
|
||||
check() ;
|
||||
return _is_fifo ;
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
/** \file
|
||||
Header file that defines 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
|
||||
*/
|
||||
@@ -0,0 +1,66 @@
|
||||
#ifndef FILTERINPUTSTREAMBUF_H
|
||||
#define FILTERINPUTSTREAMBUF_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
|
||||
namespace zipios {
|
||||
|
||||
using std::streambuf ;
|
||||
|
||||
/** An input streambuf filter is a streambuf that filters the input it
|
||||
gets from the streambuf it is attached to. FilterInputStreambuf is a base class to
|
||||
derive input streambuf filters from. */
|
||||
class FilterInputStreambuf : public streambuf {
|
||||
public:
|
||||
/** Constructor.
|
||||
@param inbuf the streambuf to use for input.
|
||||
@param del_inbuf if true is specified inbuf will be deleted, when
|
||||
the FilterInputStreambuf is destructed.
|
||||
*/
|
||||
explicit FilterInputStreambuf( streambuf *inbuf, bool del_inbuf = false ) ;
|
||||
/** Destructor. */
|
||||
virtual ~FilterInputStreambuf() ;
|
||||
|
||||
protected:
|
||||
int _s_pos ; // Position in this streambuf - FIXME: is this used?
|
||||
streambuf *_inbuf ;
|
||||
bool _del_inbuf ;
|
||||
private:
|
||||
|
||||
/** Copy-constructor is private to prevent copying. */
|
||||
FilterInputStreambuf( const FilterInputStreambuf &src ) ;
|
||||
|
||||
/** Copy-assignment operator is private to prevent copying. */
|
||||
const FilterInputStreambuf &operator= ( const FilterInputStreambuf &src ) ;
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/** \file
|
||||
Header file that defines 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
|
||||
*/
|
||||
@@ -0,0 +1,58 @@
|
||||
#ifndef FILTEROUTPUTSTREAMBUF_H
|
||||
#define FILTEROUTPUTSTREAMBUF_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
|
||||
namespace zipios {
|
||||
|
||||
using std::streambuf ;
|
||||
|
||||
/** A FilterOutputStreambuf is a streambuf that filters the data that is written
|
||||
to it before it passes it on to the output streambuf it is connected to. */
|
||||
class FilterOutputStreambuf : public streambuf {
|
||||
public:
|
||||
|
||||
/** Constructor.
|
||||
@param outbuf the streambuf to pass the filtered data on to.
|
||||
@param del_outbuf if true is specified outbuf will be deleted, when
|
||||
the FilterOutputStreambuf is destructed. */
|
||||
explicit FilterOutputStreambuf( streambuf *outbuf, bool del_outbuf = false ) ;
|
||||
|
||||
/** Destructor. */
|
||||
virtual ~FilterOutputStreambuf() ;
|
||||
|
||||
protected:
|
||||
streambuf *_outbuf ;
|
||||
bool _del_outbuf ;
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/** \file
|
||||
Header file that defines 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
|
||||
*/
|
||||
@@ -0,0 +1,89 @@
|
||||
#ifndef INFLATEINPUTSTREAMBUF_H
|
||||
#define INFLATEINPUTSTREAMBUF_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
#include <vector>
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#include "zipios++/filterinputstreambuf.h"
|
||||
|
||||
namespace zipios {
|
||||
|
||||
using std::vector ;
|
||||
|
||||
/** InflateInputStreambuf is an input stream filter, that inflates the input
|
||||
from the attached input stream. Deflation/Inflation is a
|
||||
compression/decompression method used in gzip and zip. The zlib
|
||||
library is used to perform the actual inflation, this class only
|
||||
wraps the functionality in an input stream filter. */
|
||||
class InflateInputStreambuf : public FilterInputStreambuf {
|
||||
public:
|
||||
/** InflateInputStreambuf constructor.
|
||||
@param inbuf the streambuf to use for input.
|
||||
@param s_pos a position to reset the inbuf to before reading. Specify
|
||||
-1 to read from the current position.
|
||||
@param del_inbuf if true is specified inbuf will be deleted, when
|
||||
the InflateInputStreambuf is destructed.
|
||||
*/
|
||||
explicit InflateInputStreambuf( streambuf *inbuf, int s_pos = -1, bool del_inbuf = false ) ;
|
||||
virtual ~InflateInputStreambuf() ;
|
||||
|
||||
/** Resets the zlib stream and purges input and output buffers.
|
||||
repositions the input streambuf at stream_position.
|
||||
@param stream_position a position to reset the inbuf to before reading. Specify
|
||||
-1 to read from the current position.
|
||||
*/
|
||||
bool reset( int stream_position = -1 ) ;
|
||||
protected:
|
||||
virtual int underflow() ;
|
||||
private:
|
||||
z_stream _zs ;
|
||||
bool _zs_initialized ;
|
||||
const int _invecsize ;
|
||||
vector< char > _invec ;
|
||||
protected: // FIXME: reconsider design?
|
||||
const int _outvecsize ;
|
||||
vector< char > _outvec ;
|
||||
|
||||
private:
|
||||
|
||||
/** Copy-constructor is private to prevent copying. */
|
||||
InflateInputStreambuf( const InflateInputStreambuf &src ) ;
|
||||
|
||||
/** Copy-assignment operator is private to prevent copying. */
|
||||
const InflateInputStreambuf &operator= ( const InflateInputStreambuf &src ) ;
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/** \file
|
||||
Header file that defines 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
|
||||
*/
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef META_IOSTREAMS_H
|
||||
#define META_IOSTREAMS_H
|
||||
|
||||
// Includes the different iostream libraries
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#if defined (HAVE_STD_IOSTREAM) && defined (USE_STD_IOSTREAM)
|
||||
#include <sstream>
|
||||
#else
|
||||
#include <strstream>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,173 @@
|
||||
#ifndef SIMPLESMARTPTR_H
|
||||
#define SIMPLESMARTPTR_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
namespace zipios {
|
||||
|
||||
/** SimpleSmartPointer is a simple reference counting smart pointer
|
||||
template. The type pointed to must keep a reference count that is
|
||||
accessible through the two methods void ref() const and unsigned
|
||||
int unref() const. The type must also handle the reference count
|
||||
properly. The easiest way to do that is to use the ReferenceCount
|
||||
template class. */
|
||||
template< class Type >
|
||||
class SimpleSmartPointer {
|
||||
public:
|
||||
Type *operator-> () const { return _p ; }
|
||||
|
||||
Type &operator* () const { return *_p ; }
|
||||
|
||||
SimpleSmartPointer( Type *p = 0 ) : _p( p ) { ref() ; }
|
||||
|
||||
template< class T2 > SimpleSmartPointer( const SimpleSmartPointer< T2 > &src )
|
||||
: _p( src.get() ) { ref() ; }
|
||||
|
||||
SimpleSmartPointer( const SimpleSmartPointer &src ) : _p( src.get() ) {
|
||||
ref() ;
|
||||
}
|
||||
|
||||
~SimpleSmartPointer () { if ( unref() == 0 ) deleteIt() ; }
|
||||
|
||||
template< class T2 >
|
||||
SimpleSmartPointer &operator= ( const SimpleSmartPointer< T2 > &src ) {
|
||||
ref( src.get() ) ;
|
||||
if ( unref() == 0 )
|
||||
deleteIt() ;
|
||||
_p = src.get() ;
|
||||
return *this ;
|
||||
}
|
||||
|
||||
SimpleSmartPointer &operator= ( const SimpleSmartPointer &src ) {
|
||||
ref( src.get() ) ;
|
||||
if ( unref() == 0 )
|
||||
deleteIt() ;
|
||||
_p = src.get() ;
|
||||
return *this ;
|
||||
}
|
||||
|
||||
SimpleSmartPointer &operator=( Type *src ) {
|
||||
_p = src ;
|
||||
ref() ;
|
||||
return *this ;
|
||||
}
|
||||
|
||||
bool operator== ( const Type *p ) const { return _p == p ; }
|
||||
bool operator!= ( const Type *p ) const { return _p != p ; }
|
||||
bool operator== ( const SimpleSmartPointer &sp ) const { return _p == sp.get() ; }
|
||||
bool operator!= ( const SimpleSmartPointer &sp ) const { return _p != sp.get() ; }
|
||||
bool operator! () const { return ! _p ; }
|
||||
// This next method is inspired by iostream, and is for use with
|
||||
// if ( some_smart_pointer ).
|
||||
operator void*() const { return _p ? (void *)(-1) : (void *)(0) ; }
|
||||
|
||||
Type *get() const { return _p ; }
|
||||
|
||||
/** Returns the reference count - For debugging purposes. */
|
||||
unsigned int getReferenceCount() const { return _p->getReferenceCount(); }
|
||||
|
||||
|
||||
private:
|
||||
template< class T2 >
|
||||
void ref( const T2 *ptr ) { if ( ptr ) ptr->ref() ; }
|
||||
|
||||
void ref() const { if ( _p ) _p->ref() ; }
|
||||
unsigned int unref() const {
|
||||
if ( _p )
|
||||
return _p->unref();
|
||||
else
|
||||
return 0 ;
|
||||
}
|
||||
void deleteIt() {
|
||||
// if( _p )
|
||||
// cerr << "SimpleSmartPointer: Deleting object!" << endl ;
|
||||
delete _p ;
|
||||
}
|
||||
Type *_p ;
|
||||
};
|
||||
|
||||
|
||||
/** ReferenceCount is useful to ensure proper handling of the
|
||||
reference count for (objects of) classes handled through a
|
||||
SimpleSmartPointer. Subclassing ReferenceCount is all a class
|
||||
needs to become ready for being handled by
|
||||
SimpleSmartPointer. Another way is to add a ReferenceCount member
|
||||
variable to a class and write two methods 'void ref() const' and
|
||||
'unsigned int unref() const' that invoke the same methods in the
|
||||
ReferenceCount variable. */
|
||||
template< class Type >
|
||||
class ReferenceCount {
|
||||
/** SimpleSmartPointer needs to be a friend to invoke the private
|
||||
ref() and unref() methods. */
|
||||
friend class SimpleSmartPointer< Type > ;
|
||||
friend class SimpleSmartPointer< const Type > ;
|
||||
/** Type also needs to be a friend to invoke the private ref() and
|
||||
unref() methods, in case Type doesn't want to inherit
|
||||
ReferenceCount and thus needs to invoke ref() and unref()
|
||||
through forwarding member functions. */
|
||||
//
|
||||
// Originally the following template parameter was made a friend.
|
||||
// This is not allowed by the standard so comment it out:
|
||||
//
|
||||
// friend Type ;
|
||||
//
|
||||
// Initially hack things by making the necessary classes friends
|
||||
// even though we don't know really which they are. This is an
|
||||
// Hideous Hack.
|
||||
friend class FileEntry ;
|
||||
friend class Bogus ;
|
||||
|
||||
public:
|
||||
/** Constructor intializes count to zero. */
|
||||
ReferenceCount() : _ref_count( 0 ) {}
|
||||
|
||||
/** Copy-constructor intializes count to zero. It doesn't copy it
|
||||
from src. */
|
||||
ReferenceCount( const ReferenceCount & /*src*/ ) : _ref_count( 0 ) {}
|
||||
|
||||
/** The assignment operator doesn't copy the reference count, it
|
||||
leaves it unchanged. */
|
||||
const ReferenceCount &operator= ( const ReferenceCount &src ) {}
|
||||
private:
|
||||
|
||||
/** Increases the reference count. */
|
||||
void ref() const { ++_ref_count ; }
|
||||
|
||||
/** Decreases the reference count. */
|
||||
unsigned int unref() const { return --_ref_count ; }
|
||||
|
||||
/** Returns the reference count - For debugging purposes. */
|
||||
unsigned int getReferenceCount() const { return _ref_count; }
|
||||
|
||||
/** Holds the actual reference count */
|
||||
mutable unsigned short _ref_count ;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
|
||||
/** \file
|
||||
Header file that defines SimpleSmartPointer and ReferenceCount.
|
||||
*/
|
||||
|
||||
/*
|
||||
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
|
||||
*/
|
||||
@@ -0,0 +1,105 @@
|
||||
#ifndef VIRTUALSEEKER_H
|
||||
#define VIRTUALSEEKER_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
|
||||
|
||||
namespace zipios {
|
||||
|
||||
using std::ios ;
|
||||
using std::cerr ;
|
||||
using std::endl ;
|
||||
|
||||
/** VirtualSeeker is a simple class that keeps track of a set of
|
||||
specified 'virtual' file endings that mark a subset of a real
|
||||
file. An example of its use (and its reason for existence) is to
|
||||
keep track of the file endings of a Zip file embedded in another
|
||||
file. */
|
||||
class VirtualSeeker {
|
||||
public:
|
||||
inline VirtualSeeker( int start_offset = 0, int end_offset = 0) ;
|
||||
inline void setOffsets( int start_offset, int end_offset ) ;
|
||||
inline void getOffsets( int &start_offset, int &end_offset ) const ;
|
||||
inline int startOffset() const ;
|
||||
inline int endOffset() const ;
|
||||
inline void vseekg( istream &is, int offset, ios::seekdir sd ) const ;
|
||||
inline int vtellg( istream &is ) const ;
|
||||
private:
|
||||
// start and end offsets
|
||||
int _s_off, _e_off ;
|
||||
};
|
||||
|
||||
|
||||
|
||||
VirtualSeeker::VirtualSeeker( int start_offset, int end_offset )
|
||||
: _s_off( start_offset ),
|
||||
_e_off( end_offset )
|
||||
{}
|
||||
|
||||
|
||||
void VirtualSeeker::setOffsets( int start_offset, int end_offset ) {
|
||||
_s_off = start_offset ;
|
||||
_e_off = end_offset ;
|
||||
}
|
||||
|
||||
|
||||
void VirtualSeeker::getOffsets( int &start_offset, int &end_offset ) const {
|
||||
start_offset = _s_off ;
|
||||
end_offset = _e_off ;
|
||||
}
|
||||
|
||||
|
||||
int VirtualSeeker::startOffset() const {
|
||||
return _s_off ;
|
||||
}
|
||||
|
||||
|
||||
int VirtualSeeker::endOffset() const {
|
||||
return _e_off ;
|
||||
}
|
||||
|
||||
void VirtualSeeker::vseekg( istream &is, int offset, ios::seekdir sd ) const {
|
||||
if ( sd == ios::cur )
|
||||
is.seekg( offset, sd ) ;
|
||||
else if ( sd == ios::beg )
|
||||
is.seekg( offset + _s_off, sd ) ;
|
||||
else if ( sd == ios::end )
|
||||
is.seekg( offset - _e_off, sd ) ;
|
||||
else
|
||||
cerr << "VirtualSeekManager::seekg: error - not supposed to happen!" << endl ;
|
||||
}
|
||||
|
||||
|
||||
int VirtualSeeker::vtellg( istream &is ) const {
|
||||
return static_cast< int >( is.tellg() ) - _s_off ;
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
|
||||
/** \file
|
||||
Header file that defines VirtualSeeker.
|
||||
*/
|
||||
|
||||
/*
|
||||
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
|
||||
*/
|
||||
@@ -0,0 +1,105 @@
|
||||
#ifndef ZIPFILE_H
|
||||
#define ZIPFILE_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include <vector>
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
|
||||
#include "zipios++/fcoll.h"
|
||||
#include "zipios++/ziphead.h"
|
||||
#include "zipios++/virtualseeker.h"
|
||||
|
||||
namespace zipios {
|
||||
|
||||
using std::ifstream ;
|
||||
|
||||
/** \anchor zipfile_anchor
|
||||
ZipFile is a FileCollection, where the files are stored
|
||||
in a .zip file. */
|
||||
class ZipFile : public FileCollection {
|
||||
public:
|
||||
/** \anchor zipfile_openembeddedzipfile
|
||||
Opens a Zip archive embedded in another file, by writing the zip
|
||||
archive to the end of the file followed by the start offset of
|
||||
the zip file. The offset must be written in zip-file byte-order
|
||||
(little endian). The program appendzip, which is part of the
|
||||
Zipios++ distribution can be used to append a Zip archive to a
|
||||
file, e.g. a binary program.
|
||||
@throw FColException Thrown if the specified file name is not a valid zip
|
||||
archive.
|
||||
@throw IOException Thrown if an I/O problem is encountered, while the directory
|
||||
of the specified zip archive is being read. */
|
||||
static ZipFile openEmbeddedZipFile( const string &name ) ;
|
||||
|
||||
/** Default constructor.
|
||||
*/
|
||||
ZipFile() {}
|
||||
|
||||
/* Default Copy constructor and copy assignment operator are sufficient. */
|
||||
|
||||
/** Constructor. Opens the zip file name. If the zip "file" is
|
||||
embedded in a file that contains other data, e.g. a binary
|
||||
program, the offset of the zip file start and end must be
|
||||
specified.
|
||||
@param name The filename of the zip file to open.
|
||||
@param s_off Offset relative to the start of the file, that
|
||||
indicates the beginning of the zip file.
|
||||
@param e_off Offset relative to the end of the file, that
|
||||
indicates the end of the zip file. The offset is a positive number,
|
||||
even though the offset is towards the beginning of the file.
|
||||
@throw FColException Thrown if the specified file name is not a valid zip
|
||||
archive.
|
||||
@throw IOException Thrown if an I/O problem is encountered, while the directory
|
||||
of the specified zip archive is being read. */
|
||||
explicit ZipFile( const string &name, int s_off = 0, int e_off = 0
|
||||
/* , ios::open_mode mode = ios::in | ios::binary */ ) ;
|
||||
|
||||
virtual FileCollection *clone() const ;
|
||||
|
||||
/** Destructor. */
|
||||
virtual ~ZipFile() ;
|
||||
|
||||
virtual void close() ;
|
||||
|
||||
virtual istream *getInputStream( const ConstEntryPointer &entry ) ;
|
||||
virtual istream *getInputStream( const string &entry_name,
|
||||
MatchPath matchpath = MATCH ) ;
|
||||
private:
|
||||
VirtualSeeker _vs ;
|
||||
EndOfCentralDirectory _eocd ;
|
||||
|
||||
bool init( istream &_zipfile ) ;
|
||||
bool readCentralDirectory( istream &_zipfile ) ;
|
||||
bool readEndOfCentralDirectory( istream &_zipfile ) ;
|
||||
bool confirmLocalHeaders( istream &_zipfile ) ;
|
||||
void setError( string error_str ) ;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/** \file
|
||||
Header file that defines 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
|
||||
*/
|
||||
@@ -0,0 +1,271 @@
|
||||
#ifndef ZIPHEAD_H
|
||||
#define ZIPHEAD_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "zipios++/fileentry.h"
|
||||
#include "zipios++/zipios_defs.h"
|
||||
|
||||
namespace zipios {
|
||||
|
||||
using std::streampos ;
|
||||
|
||||
class ZipCDirEntry ;
|
||||
|
||||
/** A concrete implementation of the abstract FileEntry base class for
|
||||
ZipFile entries, specifically for representing the information
|
||||
present in the local headers of file entries in a zip file. */
|
||||
class ZipLocalEntry : public FileEntry {
|
||||
friend istream &operator>> ( istream &is, ZipLocalEntry &zcdh ) ;
|
||||
friend ostream &operator<< ( ostream &os, const ZipLocalEntry &zlh ) ;
|
||||
friend bool operator== ( const ZipLocalEntry &zlh, const ZipCDirEntry &ze ) ;
|
||||
public:
|
||||
inline ZipLocalEntry( const string &_filename = "",
|
||||
const vector< unsigned char > &_extra_field =
|
||||
vector< unsigned char >() )
|
||||
: gp_bitfield( 0 ),
|
||||
_valid( false ) {
|
||||
setDefaultExtract() ;
|
||||
setName( _filename ) ;
|
||||
setExtra( _extra_field ) ;
|
||||
}
|
||||
|
||||
void setDefaultExtract() ;
|
||||
inline ZipLocalEntry &operator=( const class ZipLocalEntry &src ) ;
|
||||
virtual string getComment() const ;
|
||||
virtual uint32 getCompressedSize() const ;
|
||||
virtual uint32 getCrc() const ;
|
||||
virtual vector< unsigned char > getExtra() const ;
|
||||
virtual StorageMethod getMethod() const ;
|
||||
virtual string getName() const ;
|
||||
virtual string getFileName() const ;
|
||||
virtual uint32 getSize() const ;
|
||||
virtual int getTime() const ;
|
||||
virtual bool isValid() const ;
|
||||
|
||||
virtual bool isDirectory() const ;
|
||||
|
||||
virtual void setComment( const string &comment ) ;
|
||||
virtual void setCompressedSize( uint32 size ) ;
|
||||
virtual void setCrc( uint32 crc ) ;
|
||||
virtual void setExtra( const vector< unsigned char > &extra ) ;
|
||||
virtual void setMethod( StorageMethod method ) ;
|
||||
virtual void setName( const string &name ) ;
|
||||
virtual void setSize( uint32 size ) ;
|
||||
virtual void setTime( int time ) ;
|
||||
|
||||
virtual string toString() const ;
|
||||
|
||||
int getLocalHeaderSize() const ;
|
||||
|
||||
bool trailingDataDescriptor() const ;
|
||||
|
||||
virtual FileEntry *clone() const ;
|
||||
|
||||
virtual ~ZipLocalEntry() {}
|
||||
protected:
|
||||
static const uint32 signature ;
|
||||
uint16 extract_version ;
|
||||
uint16 gp_bitfield ;
|
||||
uint16 compress_method ;
|
||||
uint16 last_mod_ftime ;
|
||||
uint16 last_mod_fdate ;
|
||||
uint32 crc_32 ;
|
||||
uint32 compress_size ;
|
||||
uint32 uncompress_size ;
|
||||
uint16 filename_len ;
|
||||
uint16 extra_field_len ;
|
||||
|
||||
string filename ;
|
||||
vector< unsigned char > extra_field ;
|
||||
|
||||
bool _valid ;
|
||||
};
|
||||
|
||||
/** A struct containing fields for the entries in a zip file data
|
||||
descriptor, that trails the compressed data in files that were
|
||||
created by streaming, ie where the zip compressor cannot seek back
|
||||
to the local header and store the data. */
|
||||
struct DataDescriptor {
|
||||
uint32 crc_32 ;
|
||||
uint32 compress_size ;
|
||||
uint32 uncompress_size ;
|
||||
};
|
||||
|
||||
/** Specialization of ZipLocalEntry, that add fields for storing the
|
||||
extra information, that is only present in the entries in the zip
|
||||
central directory and not in the local entry headers. */
|
||||
class ZipCDirEntry : public ZipLocalEntry {
|
||||
friend istream &operator>> ( istream &is, ZipCDirEntry &zcdh ) ;
|
||||
friend ostream &operator<< ( ostream &os, const ZipCDirEntry &zcdh ) ;
|
||||
friend bool operator== ( const ZipLocalEntry &zlh, const ZipCDirEntry &ze ) ;
|
||||
public:
|
||||
|
||||
inline ZipCDirEntry( const string &_filename = "",
|
||||
const string &_file_comment = "",
|
||||
const vector< unsigned char > &_extra_field =
|
||||
vector< unsigned char >() )
|
||||
: ZipLocalEntry ( _filename, _extra_field ),
|
||||
disk_num_start ( 0x0 ),
|
||||
intern_file_attr( 0x0 ),
|
||||
extern_file_attr( 0x81B40000 )
|
||||
// FIXME: I don't understand the external mapping, simply
|
||||
// copied value for a file with -rw-rw-r-- permissions
|
||||
// compressed with info-zip
|
||||
{
|
||||
setComment( _file_comment ) ;
|
||||
setDefaultWriter() ;
|
||||
}
|
||||
|
||||
void setDefaultWriter() ;
|
||||
|
||||
inline ZipCDirEntry &operator=( const class ZipCDirEntry &src ) ;
|
||||
virtual string toString() const ;
|
||||
|
||||
virtual string getComment() const ;
|
||||
|
||||
virtual void setComment( const string &comment ) ;
|
||||
|
||||
virtual uint32 getLocalHeaderOffset() const ;
|
||||
virtual void setLocalHeaderOffset( uint32 offset ) ;
|
||||
|
||||
int getCDirHeaderSize() const ;
|
||||
|
||||
virtual FileEntry *clone() const ;
|
||||
|
||||
virtual ~ZipCDirEntry() {}
|
||||
private:
|
||||
static const uint32 signature ;
|
||||
uint16 writer_version ;
|
||||
|
||||
uint16 file_comment_len ;
|
||||
uint16 disk_num_start ;
|
||||
uint16 intern_file_attr ;
|
||||
uint32 extern_file_attr ;
|
||||
|
||||
uint32 rel_offset_loc_head ;
|
||||
|
||||
string file_comment ;
|
||||
};
|
||||
|
||||
/** The end of the Central directory structure. This structure is
|
||||
stored in the end of the zipfile, and contains information about
|
||||
the zipfile, including the position of the start of the central
|
||||
directory. */
|
||||
class EndOfCentralDirectory {
|
||||
friend ostream &operator<< ( ostream &os, const EndOfCentralDirectory &eocd ) ;
|
||||
public:
|
||||
explicit EndOfCentralDirectory( const string &_zip_comment = "",
|
||||
uint16 _disk_num = 0, uint16 _cdir_disk_num = 0,
|
||||
uint16 _cdir_entries = 0,
|
||||
uint16 _cdir_tot_entries = 0,
|
||||
uint32 _cdir_size = 0, uint32 _cdir_offset = 0 )
|
||||
: disk_num ( _disk_num ),
|
||||
cdir_disk_num ( _cdir_disk_num ),
|
||||
cdir_entries ( _cdir_entries ),
|
||||
cdir_tot_entries ( _cdir_tot_entries ),
|
||||
cdir_size ( _cdir_size ),
|
||||
cdir_offset ( _cdir_offset ),
|
||||
zip_comment_len ( _zip_comment.size() ),
|
||||
zip_comment ( _zip_comment ) {}
|
||||
|
||||
uint32 offset() const { return cdir_offset ; }
|
||||
uint16 totalCount() const { return cdir_tot_entries ; }
|
||||
void setCDirSize( uint32 size ) { cdir_size = size ; }
|
||||
void setOffset( uint32 offset ) { cdir_offset = offset ; }
|
||||
|
||||
void setTotalCount( uint16 c ) { cdir_entries = c ; cdir_tot_entries = c ; }
|
||||
int eocdOffSetFromEnd() const { return eocd_offset_from_end ; }
|
||||
bool read( vector<unsigned char> &buf, int pos ) ;
|
||||
private:
|
||||
static const uint32 signature;
|
||||
uint16 disk_num ;
|
||||
uint16 cdir_disk_num ;
|
||||
uint16 cdir_entries ;
|
||||
uint16 cdir_tot_entries ;
|
||||
uint32 cdir_size ;
|
||||
uint32 cdir_offset ;
|
||||
uint16 zip_comment_len ;
|
||||
|
||||
streampos eocd_offset_from_end ; // Not a Zip defined field
|
||||
string zip_comment;
|
||||
bool checkSignature( unsigned char *buf ) const ;
|
||||
inline bool checkSignature( uint32 sig ) const ;
|
||||
};
|
||||
|
||||
|
||||
bool operator== ( const ZipLocalEntry &zlh, const ZipCDirEntry &ze ) ;
|
||||
inline bool operator== ( const ZipCDirEntry &ze, const ZipLocalEntry &zlh ) {
|
||||
return zlh == ze ;
|
||||
}
|
||||
inline bool operator!= ( const ZipLocalEntry &zlh, const ZipCDirEntry &ze ) {
|
||||
return ! ( zlh == ze ) ;
|
||||
}
|
||||
inline bool operator!= ( const ZipCDirEntry &ze, const ZipLocalEntry &zlh ) {
|
||||
return ! ( zlh == ze ) ;
|
||||
}
|
||||
|
||||
// Inline member functions
|
||||
|
||||
ZipCDirEntry &ZipCDirEntry::operator=( const class ZipCDirEntry &src ) {
|
||||
writer_version = src.writer_version ;
|
||||
extract_version = src.extract_version ;
|
||||
gp_bitfield = src.gp_bitfield ;
|
||||
compress_method = src.compress_method ;
|
||||
last_mod_ftime = src.last_mod_ftime ;
|
||||
last_mod_fdate = src.last_mod_fdate ;
|
||||
crc_32 = src.crc_32 ;
|
||||
compress_size = src.compress_size ;
|
||||
uncompress_size = src.uncompress_size ;
|
||||
filename_len = src.filename_len ;
|
||||
extra_field_len = src.extra_field_len ;
|
||||
file_comment_len = src.file_comment_len ;
|
||||
disk_num_start = src.disk_num_start ;
|
||||
intern_file_attr = src.intern_file_attr ;
|
||||
extern_file_attr = src.extern_file_attr ;
|
||||
rel_offset_loc_head = src.rel_offset_loc_head ;
|
||||
|
||||
filename = src.filename ;
|
||||
extra_field = src.extra_field ;
|
||||
file_comment = src.file_comment ;
|
||||
|
||||
return *this ;
|
||||
}
|
||||
|
||||
bool EndOfCentralDirectory::checkSignature ( uint32 sig ) const {
|
||||
return signature == sig ;
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/** \file
|
||||
Header file containing classes and functions for reading the central
|
||||
directory and local header fields in 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
|
||||
*/
|
||||
@@ -0,0 +1,192 @@
|
||||
#ifndef ZIPHEADIO_H
|
||||
#define ZIPHEADIO_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "zipios++/ziphead.h"
|
||||
#include "zipios++/zipios_defs.h"
|
||||
|
||||
namespace zipios {
|
||||
|
||||
// byte order conversion functions.
|
||||
// ztohs (zip-to-host-short)
|
||||
#ifdef MY_BIG_ENDIAN
|
||||
|
||||
inline uint16 ztohs ( unsigned char *buf ) {
|
||||
uint16 out ;
|
||||
// *( reinterpret_cast<unsigned char *>( &out ) ) = *( buf + 1 );
|
||||
// *( reinterpret_cast<unsigned char *>( &out ) + 1 ) = *( buf );
|
||||
out = ( static_cast< uint16 >( buf[ 0 ] ) << 8 ) +
|
||||
( static_cast< uint16 >( buf[ 1 ] ) ) ;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// ztohl (zip-to-host-long)
|
||||
inline uint32 ztohl ( unsigned char *buf ) {
|
||||
uint32 out;
|
||||
out = ( static_cast< uint32 >( buf[ 0 ] ) << 24 ) +
|
||||
( static_cast< uint32 >( buf[ 1 ] ) << 16 ) +
|
||||
( static_cast< uint32 >( buf[ 2 ] ) << 8 ) +
|
||||
( static_cast< uint32 >( buf[ 3 ] ) ) ;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
inline uint16 ztohs ( unsigned char *buf ) {
|
||||
uint16 out ;
|
||||
out = ( static_cast< uint16 >( buf[ 1 ] ) << 8 ) +
|
||||
( static_cast< uint16 >( buf[ 0 ] ) ) ;
|
||||
return out;
|
||||
}
|
||||
|
||||
// ztohl (zip-to-host-long)
|
||||
inline uint32 ztohl ( unsigned char *buf ) {
|
||||
uint32 out;
|
||||
out = ( static_cast< uint32 >( buf[ 3 ] ) << 24 ) +
|
||||
( static_cast< uint32 >( buf[ 2 ] ) << 16 ) +
|
||||
( static_cast< uint32 >( buf[ 1 ] ) << 8 ) +
|
||||
( static_cast< uint32 >( buf[ 0 ] ) ) ;
|
||||
// cerr << "buf : " << static_cast< int >( buf[ 0 ] ) ;
|
||||
// cerr << " " << static_cast< int >( buf[ 1 ] ) ;
|
||||
// cerr << " " << static_cast< int >( buf[ 2 ] ) ;
|
||||
// cerr << " " << static_cast< int >( buf[ 3 ] ) << endl ;
|
||||
// cerr << "uint32 " << out << endl ;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
// htozl (host-to-zip-long)
|
||||
inline uint32 htozl ( unsigned char *buf ) {
|
||||
return ztohl( buf ) ;
|
||||
}
|
||||
|
||||
// htozs (host-to-zip-short)
|
||||
inline uint16 htozs ( unsigned char *buf ) {
|
||||
return ztohs( buf ) ;
|
||||
}
|
||||
|
||||
|
||||
inline uint32 readUint32 ( istream &is ) {
|
||||
static const int buf_len = sizeof ( uint32 ) ;
|
||||
unsigned char buf [ buf_len ] ;
|
||||
int rsf = 0 ;
|
||||
while ( rsf < buf_len ) {
|
||||
is.read ( reinterpret_cast< char * >( buf ) + rsf, buf_len - rsf ) ;
|
||||
rsf += is.gcount () ;
|
||||
}
|
||||
return ztohl ( buf ) ;
|
||||
}
|
||||
|
||||
inline void writeUint32 ( uint32 host_val, ostream &os ) {
|
||||
uint32 val = htozl( reinterpret_cast< unsigned char * >( &host_val ) ) ;
|
||||
os.write( reinterpret_cast< char * >( &val ), sizeof( uint32 ) ) ;
|
||||
}
|
||||
|
||||
inline uint16 readUint16 ( istream &is ) {
|
||||
static const int buf_len = sizeof ( uint16 ) ;
|
||||
unsigned char buf [ buf_len ] ;
|
||||
int rsf = 0 ;
|
||||
while ( rsf < buf_len ) {
|
||||
is.read ( reinterpret_cast< char * >( buf ) + rsf, buf_len - rsf ) ;
|
||||
rsf += is.gcount () ;
|
||||
}
|
||||
return ztohs ( buf ) ;
|
||||
}
|
||||
|
||||
inline void writeUint16 ( uint16 host_val, ostream &os ) {
|
||||
uint16 val = htozl( reinterpret_cast< unsigned char * >( &host_val ) ) ;
|
||||
os.write( reinterpret_cast< char * >( &val ), sizeof( uint16 ) ) ;
|
||||
}
|
||||
|
||||
inline void readByteSeq ( istream &is, string &con, int count ) {
|
||||
char *buf = new char [ count + 1 ] ;
|
||||
int rsf = 0 ;
|
||||
while ( rsf < count && is ) {
|
||||
is.read ( buf + rsf, count - rsf ) ;
|
||||
rsf += is.gcount() ;
|
||||
}
|
||||
buf [ count ] = '\0' ;
|
||||
|
||||
con = buf ;
|
||||
delete [] buf ;
|
||||
}
|
||||
|
||||
inline void writeByteSeq( ostream &os, const string &con ) {
|
||||
os << con ;
|
||||
}
|
||||
|
||||
inline void readByteSeq ( istream &is, unsigned char *buf, int count ) {
|
||||
int rsf = 0 ;
|
||||
|
||||
while ( rsf < count && is ) {
|
||||
is.read ( reinterpret_cast< char * >( buf ) + rsf, count - rsf ) ;
|
||||
rsf += is.gcount() ;
|
||||
}
|
||||
}
|
||||
|
||||
inline void writeByteSeq ( ostream &os, const unsigned char *buf, int count ) {
|
||||
os.rdbuf()->sputn( reinterpret_cast< const char * >( buf ), count ) ;
|
||||
}
|
||||
|
||||
inline void readByteSeq ( istream &is, vector < unsigned char > &vec, int count ) {
|
||||
unsigned char *buf = new unsigned char [ count ] ;
|
||||
int rsf = 0 ;
|
||||
while ( rsf < count && is ) {
|
||||
is.read ( reinterpret_cast< char * >( buf ) + rsf, count - rsf ) ;
|
||||
rsf += is.gcount() ;
|
||||
}
|
||||
|
||||
vec.insert ( vec.end (), buf, buf + count ) ;
|
||||
delete [] buf ;
|
||||
}
|
||||
|
||||
inline void writeByteSeq ( ostream &os, const vector < unsigned char > &vec ) {
|
||||
os.rdbuf()->sputn( reinterpret_cast< const char * >( &( vec[ 0 ] ) ), vec.size() ) ;
|
||||
}
|
||||
|
||||
istream& operator>> ( istream &is, ZipLocalEntry &zlh ) ;
|
||||
istream& operator>> ( istream &is, DataDescriptor &dd ) ;
|
||||
istream& operator>> ( istream &is, ZipCDirEntry &zcdh ) ;
|
||||
// istream& operator>> ( istream &is, EndOfCentralDirectory &eocd ) ;
|
||||
|
||||
ostream &operator<< ( ostream &os, const ZipLocalEntry &zlh ) ;
|
||||
ostream &operator<< ( ostream &os, const ZipCDirEntry &zcdh ) ;
|
||||
ostream &operator<< ( ostream &os, const EndOfCentralDirectory &eocd ) ;
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
|
||||
/** \file
|
||||
Header file that defines 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
|
||||
*/
|
||||
@@ -0,0 +1,91 @@
|
||||
#ifndef ZIPINPUTSTREAM_H
|
||||
#define ZIPINPUTSTREAM_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
#include <string>
|
||||
|
||||
#include "zipios++/ziphead.h"
|
||||
#include "zipios++/zipinputstreambuf.h"
|
||||
|
||||
namespace zipios {
|
||||
|
||||
using std::ifstream ;
|
||||
|
||||
/** \anchor ZipInputStream_anchor
|
||||
ZipInputStream is an istream that gets it's input from a zip file. The
|
||||
interface approximates the interface of the Java
|
||||
ZipInputStream. */
|
||||
class ZipInputStream : public istream {
|
||||
public:
|
||||
|
||||
/** ZipInputStream constructor.
|
||||
@param is istream from which the compressed zip archive can be read.
|
||||
@param pos position to reposition the istream to before reading. */
|
||||
explicit ZipInputStream( istream &is, streampos pos = 0 ) ;
|
||||
|
||||
/** ZipInputStream constructor.
|
||||
@filename filename of a valid zip file.
|
||||
@param pos position to reposition the istream to before reading. */
|
||||
explicit ZipInputStream( const string &filename, streampos pos = 0 ) ;
|
||||
|
||||
int available() ;
|
||||
/** Closes the current entry, and positions the stream read pointer at
|
||||
the beginning of the next entry (if there is one). */
|
||||
void closeEntry() ;
|
||||
|
||||
/** Closes the istream. */
|
||||
void close() ;
|
||||
|
||||
// ZipLocalEntry *createZipCDirEntry( const string &name ) ;
|
||||
|
||||
/** \anchor ZipInputStream_getnextentry_anchor
|
||||
Opens the next entry in the zip archive and returns a const pointer to a
|
||||
FileEntry object for the entry.
|
||||
@return a const FileEntry * containing information about the (now) current
|
||||
entry.
|
||||
*/
|
||||
ConstEntryPointer getNextEntry() ;
|
||||
|
||||
/** Destructor. */
|
||||
virtual ~ZipInputStream() ;
|
||||
|
||||
private:
|
||||
ifstream *ifs ;
|
||||
ZipInputStreambuf *izf ;
|
||||
|
||||
/** Copy-constructor is private to prevent copying. */
|
||||
ZipInputStream( const ZipInputStream &src ) ;
|
||||
|
||||
/** Copy-assignment operator is private to prevent copying. */
|
||||
const ZipInputStream &operator= ( const ZipInputStream &src ) ;
|
||||
|
||||
};
|
||||
|
||||
} // namespace.
|
||||
|
||||
#endif
|
||||
|
||||
/** \file
|
||||
Header file that defines 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
|
||||
*/
|
||||
@@ -0,0 +1,89 @@
|
||||
#ifndef ZIPINPUTSTREAMBUF_H
|
||||
#define ZIPINPUTSTREAMBUF_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#include "zipios++/fcoll.h"
|
||||
#include "zipios++/inflateinputstreambuf.h"
|
||||
#include "zipios++/ziphead.h"
|
||||
|
||||
namespace zipios {
|
||||
|
||||
/** ZipInputStreambuf is a zip input streambuf filter.
|
||||
*/
|
||||
class ZipInputStreambuf : public InflateInputStreambuf {
|
||||
public:
|
||||
/** ZipInputStreambuf constructor.
|
||||
@param inbuf the streambuf to use for input.
|
||||
@param s_pos a position to reset the inbuf to before reading. Specify
|
||||
-1 to read from the current position.
|
||||
@param del_inbuf if true is specified inbuf will be deleted, when
|
||||
the ZipInputStreambuf is destructed.
|
||||
*/
|
||||
explicit ZipInputStreambuf( streambuf *inbuf, int s_pos = -1, bool del_inbuf = false ) ;
|
||||
|
||||
/** Closes the current entry, and positions the stream read pointer at
|
||||
the beginning of the next entry (if there is one). */
|
||||
void closeEntry() ;
|
||||
/** Closes the streambuf. */
|
||||
void close() ;
|
||||
|
||||
/** Opens the next entry in the zip archive and returns a const pointer to a
|
||||
FileEntry object for the entry.
|
||||
@return a const FileEntry * containing information about the (now) current
|
||||
entry.
|
||||
*/
|
||||
ConstEntryPointer getNextEntry() ;
|
||||
|
||||
/** Destructor. */
|
||||
virtual ~ZipInputStreambuf() ;
|
||||
protected:
|
||||
virtual int underflow() ;
|
||||
private:
|
||||
bool _open_entry ;
|
||||
ZipLocalEntry _curr_entry ;
|
||||
int _data_start ; // Don't forget entry header has a length too.
|
||||
int _remain ; // For STORED entry only. the number of bytes that
|
||||
// hasn't been put in the _outvec yet.
|
||||
|
||||
/** Copy-constructor is private to prevent copying. */
|
||||
ZipInputStreambuf( const ZipInputStreambuf &src ) ;
|
||||
|
||||
/** Copy-assignment operator is private to prevent copying. */
|
||||
const ZipInputStreambuf &operator= ( const ZipInputStreambuf &src ) ;
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/** \file
|
||||
Header file that defines 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
|
||||
*/
|
||||
@@ -0,0 +1,80 @@
|
||||
/* zipios++/zipios-config.h. Generated by configure. */
|
||||
/* zipios++/zipios-config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* define if the compiler implements namespaces */
|
||||
#define HAVE_NAMESPACES
|
||||
|
||||
/* define if the compiler supports ISO C++ standard library */
|
||||
#define HAVE_STD
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* define if the compiler has std compliant iostream library */
|
||||
#define HAVE_STD_IOSTREAM
|
||||
|
||||
/* define if the compiler supports Standard Template Library */
|
||||
#define HAVE_STL
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define if zlib has zError */
|
||||
#define HAVE_ZERROR 1
|
||||
|
||||
/* Name of package */
|
||||
#define PACKAGE "zipios++"
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT ""
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME ""
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING ""
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME ""
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION ""
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define if the std compliant iostream library should be used (if present) */
|
||||
#define USE_STD_IOSTREAM 1
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "0.1.5"
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
/* #undef const */
|
||||
|
||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
#ifndef __cplusplus
|
||||
/* #undef inline */
|
||||
#endif
|
||||
@@ -0,0 +1,79 @@
|
||||
/* zipios++/zipios-config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* define if the compiler implements namespaces */
|
||||
#undef HAVE_NAMESPACES
|
||||
|
||||
/* define if the compiler supports ISO C++ standard library */
|
||||
#undef HAVE_STD
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* define if the compiler has std compliant iostream library */
|
||||
#undef HAVE_STD_IOSTREAM
|
||||
|
||||
/* define if the compiler supports Standard Template Library */
|
||||
#undef HAVE_STL
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define if zlib has zError */
|
||||
#undef HAVE_ZERROR
|
||||
|
||||
/* Name of package */
|
||||
#undef PACKAGE
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#undef PACKAGE_BUGREPORT
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#undef PACKAGE_NAME
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#undef PACKAGE_STRING
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#undef PACKAGE_TARNAME
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Define if the std compliant iostream library should be used (if present) */
|
||||
#undef USE_STD_IOSTREAM
|
||||
|
||||
/* Version number of package */
|
||||
#undef VERSION
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
#undef const
|
||||
|
||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
#ifndef __cplusplus
|
||||
#undef inline
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef ZIPIOS_DEFS_H
|
||||
#define ZIPIOS_DEFS_H
|
||||
|
||||
namespace zipios {
|
||||
|
||||
typedef unsigned short uint16 ;
|
||||
typedef unsigned long uint32 ;
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
|
||||
/** \file
|
||||
Header file that defines some simple data types.
|
||||
*/
|
||||
|
||||
/*
|
||||
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
|
||||
*/
|
||||
@@ -0,0 +1,101 @@
|
||||
#ifndef ZIPOUTPUTSTREAM_H
|
||||
#define ZIPOUTPUTSTREAM_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include "zipios++/meta-iostreams.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "zipios++/ziphead.h"
|
||||
#include "zipios++/zipoutputstreambuf.h"
|
||||
|
||||
namespace zipios {
|
||||
|
||||
/** \anchor ZipOutputStream_anchor
|
||||
ZipOutputStream is an ostream that writes the output to a zip file. The
|
||||
interface approximates the interface of the Java ZipOutputStream. */
|
||||
class ZipOutputStream : public std::ostream {
|
||||
public:
|
||||
|
||||
/** ZipOutputStream constructor.
|
||||
@param os ostream to which the compressed zip archive is written.
|
||||
@param pos position to reposition the ostream to before reading. */
|
||||
explicit ZipOutputStream( std::ostream &os ) ;
|
||||
|
||||
/** ZipOutputStream constructor.
|
||||
@filename filename to write the zip archive to. */
|
||||
explicit ZipOutputStream( const std::string &filename ) ;
|
||||
|
||||
/** Closes the current entry updates its header with the relevant
|
||||
size information and positions the stream write pointer for the
|
||||
next entry header. Puts the stream in EOF state. Call
|
||||
putNextEntry() to clear the EOF stream state flag. */
|
||||
void closeEntry() ;
|
||||
|
||||
/** Calls finish and if the ZipOutputStream was created with a
|
||||
filename as a parameter that file is closed as well. If the
|
||||
ZipOutputStream was created with an ostream as its first
|
||||
parameter nothing but the call to finish happens. */
|
||||
void close() ;
|
||||
|
||||
/** Closes the current entry (if one is open), then writes the Zip
|
||||
Central Directory Structure closing the ZipOutputStream. The
|
||||
output stream that the zip archive is being written to is not
|
||||
closed. */
|
||||
void finish() ;
|
||||
|
||||
/** \anchor ZipOutputStream_putnextentry_anchor
|
||||
Begins writing the next entry.
|
||||
*/
|
||||
void putNextEntry( const ZipCDirEntry &entry ) ;
|
||||
|
||||
/** \anchor ZipOutputStream_putnextentry2_anchor
|
||||
Begins writing the next entry.
|
||||
*/
|
||||
void putNextEntry(const std::string& entryName);
|
||||
|
||||
/** Sets the global comment for the Zip archive. */
|
||||
void setComment( const std::string& comment ) ;
|
||||
|
||||
/** Sets the compression level to be used for subsequent entries. */
|
||||
void setLevel( int level ) ;
|
||||
|
||||
/** Sets the compression method to be used. only STORED and DEFLATED are
|
||||
supported. */
|
||||
void setMethod( StorageMethod method ) ;
|
||||
|
||||
/** Destructor. */
|
||||
virtual ~ZipOutputStream() ;
|
||||
|
||||
private:
|
||||
std::ofstream *ofs ;
|
||||
ZipOutputStreambuf *ozf ;
|
||||
};
|
||||
|
||||
} // namespace.
|
||||
|
||||
#endif
|
||||
|
||||
/** \file
|
||||
Header file that defines 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
|
||||
*/
|
||||
@@ -0,0 +1,117 @@
|
||||
#ifndef ZIPOUTPUTSTREAMBUF_H
|
||||
#define ZIPOUTPUTSTREAMBUF_H
|
||||
|
||||
#include "zipios++/zipios-config.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#include "zipios++/fcoll.h"
|
||||
#include "zipios++/deflateoutputstreambuf.h"
|
||||
#include "zipios++/ziphead.h"
|
||||
|
||||
|
||||
namespace zipios {
|
||||
|
||||
/** ZipOutputStreambuf is a zip input streambuf filter. */
|
||||
class ZipOutputStreambuf : public DeflateOutputStreambuf {
|
||||
public:
|
||||
|
||||
enum CompressionLevels { NO_COMPRESSION = Z_NO_COMPRESSION,
|
||||
BEST_SPEED = Z_BEST_SPEED,
|
||||
BEST_COMPRESSION = Z_BEST_COMPRESSION,
|
||||
DEFAULT_COMPRESSION = Z_DEFAULT_COMPRESSION } ;
|
||||
|
||||
/** ZipOutputStreambuf constructor. A newly constructed ZipOutputStreambuf
|
||||
is not ready to accept data, putNextEntry() must be invoked first.
|
||||
@param outbuf the streambuf to use for input.
|
||||
@param del_outbuf if true is specified outbuf will be deleted, when
|
||||
the ZipOutputStreambuf is destructed. */
|
||||
explicit ZipOutputStreambuf( streambuf *outbuf, bool del_outbuf = false ) ;
|
||||
|
||||
/** Closes the current entry, and positions the stream read pointer at
|
||||
the beginning of the next entry (if there is one). */
|
||||
void closeEntry() ;
|
||||
|
||||
/** Calls finish. */
|
||||
void close() ;
|
||||
|
||||
/** Closes the current entry (if one is open), then writes the Zip
|
||||
Central Directory Structure closing the ZipOutputStream. The
|
||||
output stream that the zip archive is being written to is not
|
||||
closed. */
|
||||
void finish() ;
|
||||
|
||||
/** Begins writing the next entry.
|
||||
Opens the next entry in the zip archive and returns a const pointer to a
|
||||
FileEntry object for the entry.
|
||||
@return a const FileEntry * containing information about the (now) current
|
||||
entry. */
|
||||
void putNextEntry( const ZipCDirEntry &entry ) ;
|
||||
|
||||
/** Sets the global comment for the Zip archive. */
|
||||
void setComment( const string &comment ) ;
|
||||
|
||||
/** Sets the compression level to be used for subsequent entries. */
|
||||
void setLevel( int level ) ;
|
||||
|
||||
/** Sets the compression method to be used. only STORED and DEFLATED are
|
||||
supported. */
|
||||
void setMethod( StorageMethod method ) ;
|
||||
|
||||
/** Destructor. */
|
||||
virtual ~ZipOutputStreambuf() ;
|
||||
|
||||
protected:
|
||||
virtual int overflow( int c = EOF ) ;
|
||||
virtual int sync() ;
|
||||
|
||||
void setEntryClosedState() ;
|
||||
void updateEntryHeaderInfo() ;
|
||||
|
||||
// Should/could be moved to zipheadio.h ?!
|
||||
static void writeCentralDirectory( const vector< ZipCDirEntry > &entries,
|
||||
EndOfCentralDirectory eocd,
|
||||
ostream &os ) ;
|
||||
|
||||
|
||||
|
||||
private:
|
||||
string _zip_comment ;
|
||||
vector< ZipCDirEntry > _entries ;
|
||||
bool _open_entry ;
|
||||
bool _open ;
|
||||
StorageMethod _method ;
|
||||
int _level ;
|
||||
};
|
||||
|
||||
|
||||
} // 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
|
||||
*/
|
||||
Reference in New Issue
Block a user