mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-16 17:10:20 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39c87c56fb | ||
|
|
afe6148ebd | ||
|
|
da34629417 | ||
|
|
c68c1bd6c0 | ||
|
|
a2d18abb30 | ||
|
|
dd7100cbbd | ||
|
|
5a6cb5ce83 | ||
|
|
a90a8752fa | ||
|
|
2cf46f9f3a | ||
|
|
d939457bb9 | ||
|
|
bc88cf65e9 | ||
|
|
11b23d5c2a | ||
|
|
fdeac5a1d2 | ||
|
|
99bc5750c0 | ||
|
|
f611271a66 | ||
|
|
ab10994d3d | ||
|
|
4d8d5cc311 | ||
|
|
46eac4f446 | ||
|
|
e21f636e8c | ||
|
|
b1b8611ecf | ||
|
|
da69c6c63c | ||
|
|
6e3884f14f | ||
|
|
0b06a8ac4c | ||
|
|
8b96bfb634 | ||
|
|
e2c9c8c0bf | ||
|
|
585d7ffd41 | ||
|
|
93359ce5b4 | ||
|
|
de8ffd34ed | ||
|
|
f82a1f85dd | ||
|
|
e3cfa1cf7c | ||
|
|
3343ab394f | ||
|
|
749975515b | ||
|
|
29bd87001f | ||
|
|
1263f41404 | ||
|
|
3389912d8f | ||
|
|
f131483ce6 | ||
|
|
f2bfd9fe48 | ||
|
|
e45a69164c | ||
|
|
1602cb9de7 | ||
|
|
d273b61a20 | ||
|
|
81e825559a | ||
|
|
b1000500d6 | ||
|
|
4557407d6d | ||
|
|
a84be32229 | ||
|
|
862d515398 | ||
|
|
27adaadb5b | ||
|
|
0820f840a5 | ||
|
|
87aa3d424c | ||
|
|
acec2a5772 | ||
|
|
c4c84f3d00 | ||
|
|
d538cb0571 | ||
|
|
9c5f8f2746 | ||
|
|
da5275f248 | ||
|
|
776110a374 | ||
|
|
386481ff06 | ||
|
|
956c67906f | ||
|
|
a9c884eaef | ||
|
|
86a295501e | ||
|
|
7ebae8306a | ||
|
|
b1853cba15 | ||
|
|
5d7664c3cc | ||
|
|
1390efe910 | ||
|
|
b5c5563b18 | ||
|
|
a02bf8816d | ||
|
|
7e9bc7847d | ||
|
|
42981c413a | ||
|
|
d31c6ef8d0 | ||
|
|
7af71bde6d | ||
|
|
53624cf702 | ||
|
|
4f900ec539 | ||
|
|
aa976d180b | ||
|
|
9221c586f1 | ||
|
|
74df29cff8 | ||
|
|
f333a7fbb7 | ||
|
|
518da7775c | ||
|
|
de1565c510 | ||
|
|
df8d224980 | ||
|
|
27e7e8ce15 | ||
|
|
c69e5cf3df | ||
|
|
88c51c34b5 | ||
|
|
a2890ef65c | ||
|
|
370c785c91 | ||
|
|
03fc690667 | ||
|
|
9027e9d1b2 | ||
|
|
e21ad29117 | ||
|
|
5cd74c6e93 | ||
|
|
f03957145f | ||
|
|
022f2a162c | ||
|
|
8bdc8dbbb8 | ||
|
|
86108c6777 | ||
|
|
782aff048c | ||
|
|
3666377b63 | ||
|
|
b20f049e63 | ||
|
|
2f31aa3e43 | ||
|
|
b18d980fab | ||
|
|
d857e242ab | ||
|
|
c716a7bd6f | ||
|
|
50ad571d70 | ||
|
|
1fc3bcc2b8 | ||
|
|
94abf32795 | ||
|
|
b47870a87b | ||
|
|
957bc1dbe3 | ||
|
|
a5d9b3f229 | ||
|
|
374bdf5cd7 | ||
|
|
fee32a49f5 | ||
|
|
c7f63eecba | ||
|
|
3920aa8c5c | ||
|
|
502882dde2 | ||
|
|
6a30d9b3c6 | ||
|
|
e1029c24e4 | ||
|
|
e6971e6673 | ||
|
|
2f8403bcf4 | ||
|
|
83c5cdea3c | ||
|
|
cd7a35cae1 | ||
|
|
b03e7fffb8 | ||
|
|
819395604c | ||
|
|
4fc67d1a14 | ||
|
|
2c47c798a5 | ||
|
|
4a791732ff | ||
|
|
a1e21f8406 | ||
|
|
942bdbd5f4 | ||
|
|
ae63609233 | ||
|
|
5e69101fb5 | ||
|
|
71e6af6bfb | ||
|
|
4cb79d4939 | ||
|
|
c299d9423a | ||
|
|
4b82041b60 | ||
|
|
fe699eac7f | ||
|
|
1a336cbb03 | ||
|
|
6cb5277b61 | ||
|
|
ac9098f000 | ||
|
|
4b541b39b1 | ||
|
|
bf7f10d598 | ||
|
|
b346b5fdd2 | ||
|
|
6dd9ea60dd | ||
|
|
3f625156e6 | ||
|
|
d311a8974f | ||
|
|
a9dc7c1423 | ||
|
|
560e4580b9 | ||
|
|
ddc29a68dc | ||
|
|
b767d8ce93 | ||
|
|
31d3a9249b | ||
|
|
31ce1e8731 | ||
|
|
0ea9548259 | ||
|
|
6966c937a7 | ||
|
|
4ed05be113 | ||
|
|
468605ade8 | ||
|
|
8e85175c9f | ||
|
|
52b617c26d | ||
|
|
33a27d220a | ||
|
|
14fd5a011c | ||
|
|
fbc5540411 | ||
|
|
5c116b3809 | ||
|
|
041074c05c | ||
|
|
2eec15c2c2 | ||
|
|
c036498ee3 | ||
|
|
348cc03c6b | ||
|
|
bf10762927 | ||
|
|
539f93dc9b | ||
|
|
100b11f54e | ||
|
|
9c5054496a | ||
|
|
44e346f730 | ||
|
|
e803963be2 | ||
|
|
00afe48c72 | ||
|
|
20205363c3 | ||
|
|
c5ee2c6e20 | ||
|
|
0462988716 | ||
|
|
9df2d2b132 | ||
|
|
ab9ac534ec | ||
|
|
443a7ccc56 | ||
|
|
bbc196f353 | ||
|
|
f712d57b1d | ||
|
|
2bba2cb921 | ||
|
|
84b44740df | ||
|
|
659bbbf9ed | ||
|
|
2f2dc9b0d1 | ||
|
|
4a36e8f8d3 | ||
|
|
df9f0d3bf7 | ||
|
|
3d8ec43e8e | ||
|
|
d9ac812f0e | ||
|
|
ccf4e0f3ad | ||
|
|
0d0977764d | ||
|
|
b7b4ddd52f | ||
|
|
be04be228d | ||
|
|
095130eca6 | ||
|
|
d18c179d5e | ||
|
|
778d849ef0 | ||
|
|
0a2fccb980 | ||
|
|
12561b45b4 | ||
|
|
4dc959ad28 | ||
|
|
37dc7f44c1 | ||
|
|
d8e15dec91 | ||
|
|
11f4b5566f | ||
|
|
4e4824afab |
No files matched your search
@@ -1,3 +1,20 @@
|
||||
2004-05-31 Gonzalo Paniagua Javier <[email protected]>
|
||||
|
||||
* configure.in: fixlets for windows.
|
||||
|
||||
2004-05-29 Zoltan Varga <[email protected]>
|
||||
|
||||
* configure.in: export CC instead of passing it to libgc/configure.
|
||||
|
||||
2004-05-28 Duncan Mak <[email protected]>
|
||||
|
||||
* runtime/Makefile.am:
|
||||
* scripts/Makefile.am: Include mono-find-provides and
|
||||
mono-find-requires.
|
||||
|
||||
* scripts/mono-find-provides.in:
|
||||
* scripts/mono-find-requires.in: New wrapper scripts.
|
||||
|
||||
2004-05-27 Zoltan Varga <[email protected]>
|
||||
|
||||
* configure.in: Pass CC to libgc configure.
|
||||
|
||||
+9
-3
@@ -1,7 +1,7 @@
|
||||
AC_INIT(README)
|
||||
AC_CANONICAL_SYSTEM
|
||||
AM_CONFIG_HEADER(config.h)
|
||||
AM_INIT_AUTOMAKE(mono,0.92)
|
||||
AM_INIT_AUTOMAKE(mono,0.95)
|
||||
AM_MAINTAINER_MODE
|
||||
|
||||
dnl
|
||||
@@ -42,12 +42,17 @@ case "$host" in
|
||||
AC_DEFINE(PLATFORM_WIN32,1,[Platform is Win32])
|
||||
CC="gcc -mno-cygwin"
|
||||
HOST_CC="gcc"
|
||||
# So libgc configure gets -mno-cygwin
|
||||
export CC
|
||||
# latest libgc already defines GC_WIN32_THREADS
|
||||
# CPPFLAGS="$CPPFLAGS -DGC_WIN32_THREADS -DWIN32_THREADS"
|
||||
CPPFLAGS="$CPPFLAGS -DWIN32_THREADS"
|
||||
libdl=
|
||||
libgc_threads=win32
|
||||
gc_default=boehm
|
||||
with_nptl=no
|
||||
with_sigaltstack=no
|
||||
|
||||
;;
|
||||
*-*-*netbsd*)
|
||||
platform_win32=no
|
||||
@@ -317,7 +322,7 @@ esac
|
||||
|
||||
|
||||
# tell libgc/configure about what we want
|
||||
ac_configure_args="$ac_configure_args --disable-embed-check --with-libgc-threads=$libgc_threads CC=$CC"
|
||||
ac_configure_args="$ac_configure_args --disable-embed-check --with-libgc-threads=$libgc_threads"
|
||||
|
||||
AM_CONDITIONAL(INCLUDED_LIBGC, test x$use_included_gc = xyes)
|
||||
AC_SUBST(LIBGC_CFLAGS)
|
||||
@@ -896,6 +901,7 @@ if test x$platform_win32 = xno; then
|
||||
AC_DEFINE_UNQUOTED(SIGVAL_PTR,$SIGVAL_PTR,[Pointer field name in 'union sigval'])
|
||||
fi
|
||||
else
|
||||
jdk_headers_found=no
|
||||
AC_CHECK_LIB(ws2_32, main, LIBS="$LIBS -lws2_32", AC_ERROR(bad mingw install?))
|
||||
AC_CHECK_LIB(psapi, main, LIBS="$LIBS -lpsapi", AC_ERROR(bad mingw install?))
|
||||
fi
|
||||
@@ -947,7 +953,7 @@ case "{$target}" in
|
||||
dnl Win32 does not have /dev/random, they have their own method...
|
||||
|
||||
*-*-mingw*|*-*-cygwin*)
|
||||
ac_cv_have_dev_random = no
|
||||
ac_cv_have_dev_random=no
|
||||
;;
|
||||
|
||||
dnl Everywhere else, it's /dev/random
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<h1>Mono 1.0 Release Notes</h1>
|
||||
|
||||
<h2>What does Mono Include</h2>
|
||||
|
||||
<h2>Missing functionality</h2>
|
||||
|
||||
<p>COM support.
|
||||
|
||||
<p>EnterpriseServices are non-existant.
|
||||
|
||||
<p>Windows.Forms is only available as a preview, it is not
|
||||
completed nor stable.
|
||||
|
||||
<h3>Assembly: System.Drawing</h3>
|
||||
|
||||
<p>System.Drawing.Printing is not supported.
|
||||
@@ -1,3 +1,8 @@
|
||||
2004-05-30 Jackson Harper <[email protected]>
|
||||
|
||||
* library.make: Install to 2.0 package if building with the
|
||||
net_2_0 profile.
|
||||
|
||||
2004-05-26 Gonzalo Paniagua Javier <[email protected]>
|
||||
|
||||
* library.make: reference nunti.core.dll and nunit.util.dll when
|
||||
|
||||
@@ -43,13 +43,13 @@ gacutil = $(topdir)/tools/gacutil/gacutil.exe
|
||||
PACKAGE = 1.0
|
||||
|
||||
ifeq ($(PROFILE), net_2_0)
|
||||
PACKAGE = 1.1
|
||||
PACKAGE = 2.0
|
||||
endif
|
||||
|
||||
all-local: $(the_lib)
|
||||
|
||||
install-local: $(the_lib) $(gacutil)
|
||||
$(RUNTIME) $(gacutil) /i $(the_lib) /f /root $(DESTDIR)$(prefix)/lib /package 1.0
|
||||
$(RUNTIME) $(gacutil) /i $(the_lib) /f /root $(DESTDIR)$(prefix)/lib /package $(PACKAGE)
|
||||
|
||||
uninstall-local: $(gacutil)
|
||||
$(RUNTIME) $(gacutil) /u $$(basename $(the_lib) .dll) ; \
|
||||
|
||||
@@ -31,7 +31,7 @@ hidden_suffix =
|
||||
|
||||
platform-check:
|
||||
@if ! type $(BOOTSTRAP_MCS) >/dev/null 2>&1 ; then \
|
||||
echo "*** You need a C# compiler installed to build MCS." ; \
|
||||
echo "*** You need a C# compiler installed to build MCS. (make sure mcs works from the command line)" ; \
|
||||
echo "*** Read INSTALL.txt for information on how to bootstrap" ; \
|
||||
echo "*** a Mono installation." ; \
|
||||
exit 1 ; \
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
dots := $(shell echo $(thisdir) |sed -e 's,[^./][^/]*,..,g')
|
||||
topdir := $(dots)
|
||||
|
||||
VERSION = 0.91.99
|
||||
VERSION = 0.93
|
||||
|
||||
USE_MCS_FLAGS = $(LOCAL_MCS_FLAGS) $(PLATFORM_MCS_FLAGS) $(PROFILE_MCS_FLAGS) $(MCS_FLAGS)
|
||||
USE_CFLAGS = $(LOCAL_CFLAGS) $(CFLAGS)
|
||||
|
||||
@@ -1,3 +1,16 @@
|
||||
2004-05-31 Atsushi Enomoto <[email protected]>
|
||||
|
||||
* RncParser.jay : now error output is disabled.
|
||||
* RncTokenizer.cs : It should not be public class.
|
||||
|
||||
2004-05-30 Atsushi Enomoto <[email protected]>
|
||||
|
||||
* RncParser.jay :
|
||||
Now RncParser.Parse() returns RelaxngPattern, not RelaxngGrammar.
|
||||
Fixed many "confusing RelaxngPattern and RelaxngPatternList"
|
||||
problems, and ditto for other "List" stuff.
|
||||
To avoid complex situations, mostly removed unused annotation stuff.
|
||||
|
||||
2004-05-09 Atsushi Enomoto <[email protected]>
|
||||
|
||||
* RncParser.jay :
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -16,7 +16,7 @@ using Commons.Xml.Relaxng;
|
||||
|
||||
namespace Commons.Xml.Relaxng.Rnc
|
||||
{
|
||||
public class RncTokenizer : Commons.Xml.Relaxng.Rnc.yyParser.yyInput
|
||||
internal class RncTokenizer : Commons.Xml.Relaxng.Rnc.yyParser.yyInput
|
||||
{
|
||||
TextReader source;
|
||||
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
2004-05-31 Atsushi Enomoto <[email protected]>
|
||||
|
||||
* Misc.cs : made Util class internal.
|
||||
* RelaxngDatatypeProvider.cs : looks commit was missing.
|
||||
* RelaxngException.cs : made one .ctor() internal that accepts
|
||||
RdpPattern.
|
||||
* RelaxngNameClas.cs : Names list should not be settable.
|
||||
* RelaxngPattern.cs : RelaxngRefPattern class is internal use only.
|
||||
* RelaxngPatternType.cs : there is not "Include" pattern.
|
||||
|
||||
2004-05-30 Atsushi Enomoto <[email protected]>
|
||||
|
||||
* RelaxngDatatypeProvider.cs : removed meaningless using alias.
|
||||
* RelaxngGrammar.cs : modified ArrayList to RelaxngGrammarContentList.
|
||||
RelaxngMergedProvider.cs : Added #if PNET switch to support non-
|
||||
xmlschema available environment.
|
||||
* RelaxngPattern.cs : added IGrammarContent and
|
||||
RelaxngGrammarContentList.
|
||||
|
||||
2004-03-17 Atsushi Enomoto <[email protected]>
|
||||
|
||||
* RelaxngNameClass.cs : Introduced RelaxngNameClassList class.
|
||||
|
||||
@@ -14,7 +14,7 @@ using Commons.Xml.Relaxng.Derivative;
|
||||
|
||||
namespace Commons.Xml.Relaxng
|
||||
{
|
||||
public class Util
|
||||
internal class Util
|
||||
{
|
||||
public static string ResolveUri (string baseUri, string href)
|
||||
{
|
||||
|
||||
@@ -10,9 +10,6 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using System.Xml.Schema;
|
||||
using Commons.Xml.Relaxng.XmlSchema;
|
||||
|
||||
using XSchema = System.Xml.Schema.XmlSchema;
|
||||
|
||||
namespace Commons.Xml.Relaxng
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Commons.Xml.Relaxng
|
||||
public RelaxngException (string message) : base (message) {}
|
||||
public RelaxngException (string message, Exception innerException)
|
||||
: base (message, innerException) {}
|
||||
public RelaxngException (string message, RdpPattern invalidatedPattern)
|
||||
internal RelaxngException (string message, RdpPattern invalidatedPattern)
|
||||
: base (message)
|
||||
{
|
||||
debugXml = RdpUtil.DebugRdpPattern (invalidatedPattern, new Hashtable ());
|
||||
|
||||
@@ -23,10 +23,10 @@ namespace Commons.Xml.Relaxng
|
||||
"http://relaxng.org/ns/structure/1.0";
|
||||
|
||||
// object model fields
|
||||
ArrayList starts = new ArrayList ();
|
||||
ArrayList defs = new ArrayList ();
|
||||
ArrayList includes = new ArrayList ();
|
||||
ArrayList divs = new ArrayList ();
|
||||
RelaxngGrammarContentList starts = new RelaxngGrammarContentList ();
|
||||
RelaxngGrammarContentList defs = new RelaxngGrammarContentList ();
|
||||
RelaxngGrammarContentList includes = new RelaxngGrammarContentList ();
|
||||
RelaxngGrammarContentList divs = new RelaxngGrammarContentList ();
|
||||
|
||||
RelaxngDatatypeProvider provider;
|
||||
|
||||
@@ -75,19 +75,19 @@ namespace Commons.Xml.Relaxng
|
||||
get { return RelaxngPatternType.Grammar; }
|
||||
}
|
||||
|
||||
public IList Starts {
|
||||
public RelaxngGrammarContentList Starts {
|
||||
get { return starts; }
|
||||
}
|
||||
|
||||
public IList Defines {
|
||||
public RelaxngGrammarContentList Defines {
|
||||
get { return defs; }
|
||||
}
|
||||
|
||||
public IList Includes {
|
||||
public RelaxngGrammarContentList Includes {
|
||||
get { return includes; }
|
||||
}
|
||||
|
||||
public IList Divs {
|
||||
public RelaxngGrammarContentList Divs {
|
||||
get { return divs; }
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,10 @@ namespace Commons.Xml.Relaxng
|
||||
static RelaxngMergedProvider ()
|
||||
{
|
||||
RelaxngMergedProvider p = new RelaxngMergedProvider ();
|
||||
#if !PNET
|
||||
p ["http://www.w3.org/2001/XMLSchema-datatypes"] = XsdDatatypeProvider.Instance;
|
||||
p [XSchema.Namespace] = XsdDatatypeProvider.Instance;
|
||||
#endif
|
||||
p [String.Empty] = RelaxngNamespaceDatatypeProvider.Instance;
|
||||
defaultProvider = p;
|
||||
}
|
||||
|
||||
@@ -260,7 +260,6 @@ namespace Commons.Xml.Relaxng
|
||||
|
||||
public RelaxngNameClassList Names {
|
||||
get { return names; }
|
||||
set { names = value; }
|
||||
}
|
||||
|
||||
public override void Write (XmlWriter writer)
|
||||
|
||||
@@ -121,7 +121,11 @@ namespace Commons.Xml.Relaxng
|
||||
#endregion
|
||||
|
||||
#region Grammatical elements
|
||||
public class RelaxngStart : RelaxngElementBase
|
||||
public interface IGrammarContent
|
||||
{
|
||||
}
|
||||
|
||||
public class RelaxngStart : RelaxngElementBase, IGrammarContent
|
||||
{
|
||||
RelaxngPattern p;
|
||||
string combine;
|
||||
@@ -155,7 +159,7 @@ namespace Commons.Xml.Relaxng
|
||||
}
|
||||
}
|
||||
|
||||
public class RelaxngDefine : RelaxngElementBase
|
||||
public class RelaxngDefine : RelaxngElementBase, IGrammarContent
|
||||
{
|
||||
string name;
|
||||
private RelaxngPatternList patterns = new RelaxngPatternList ();
|
||||
@@ -211,12 +215,12 @@ namespace Commons.Xml.Relaxng
|
||||
}
|
||||
}
|
||||
|
||||
public class RelaxngInclude : RelaxngElementBase
|
||||
public class RelaxngInclude : RelaxngElementBase, IGrammarContent
|
||||
{
|
||||
string href;
|
||||
IList starts = new ArrayList ();
|
||||
IList defines = new ArrayList ();
|
||||
IList divs = new ArrayList ();
|
||||
RelaxngGrammarContentList starts = new RelaxngGrammarContentList ();
|
||||
RelaxngGrammarContentList defines = new RelaxngGrammarContentList ();
|
||||
RelaxngGrammarContentList divs = new RelaxngGrammarContentList ();
|
||||
string ns;
|
||||
|
||||
public RelaxngInclude ()
|
||||
@@ -228,15 +232,15 @@ namespace Commons.Xml.Relaxng
|
||||
set { href = value; }
|
||||
}
|
||||
|
||||
public IList Starts {
|
||||
public RelaxngGrammarContentList Starts {
|
||||
get { return starts; }
|
||||
}
|
||||
|
||||
public IList Defines {
|
||||
public RelaxngGrammarContentList Defines {
|
||||
get { return defines; }
|
||||
}
|
||||
|
||||
public IList Divs {
|
||||
public RelaxngGrammarContentList Divs {
|
||||
get { return divs; }
|
||||
}
|
||||
|
||||
@@ -292,7 +296,7 @@ namespace Commons.Xml.Relaxng
|
||||
// starts.
|
||||
if (this.Starts.Count > 0 && g.Starts.Count == 0)
|
||||
throw new RelaxngException ("When the included grammar does not contain start components, this include component must not contain start components.");
|
||||
IList appliedStarts = (this.starts.Count > 0) ?
|
||||
RelaxngGrammarContentList appliedStarts = (this.starts.Count > 0) ?
|
||||
this.starts : g.Starts;
|
||||
|
||||
RelaxngDiv div = new RelaxngDiv ();
|
||||
@@ -325,30 +329,30 @@ namespace Commons.Xml.Relaxng
|
||||
}
|
||||
}
|
||||
|
||||
public class RelaxngDiv : RelaxngElementBase
|
||||
public class RelaxngDiv : RelaxngElementBase, IGrammarContent
|
||||
{
|
||||
IList starts = new ArrayList ();
|
||||
IList defines = new ArrayList ();
|
||||
IList includes = new ArrayList ();
|
||||
IList divs = new ArrayList ();
|
||||
RelaxngGrammarContentList starts = new RelaxngGrammarContentList ();
|
||||
RelaxngGrammarContentList defines = new RelaxngGrammarContentList ();
|
||||
RelaxngGrammarContentList includes = new RelaxngGrammarContentList ();
|
||||
RelaxngGrammarContentList divs = new RelaxngGrammarContentList ();
|
||||
|
||||
public RelaxngDiv ()
|
||||
{
|
||||
}
|
||||
|
||||
public IList Starts {
|
||||
public RelaxngGrammarContentList Starts {
|
||||
get { return starts; }
|
||||
}
|
||||
|
||||
public IList Defines {
|
||||
public RelaxngGrammarContentList Defines {
|
||||
get { return defines; }
|
||||
}
|
||||
|
||||
public IList Includes {
|
||||
public RelaxngGrammarContentList Includes {
|
||||
get { return includes; }
|
||||
}
|
||||
|
||||
public IList Divs {
|
||||
public RelaxngGrammarContentList Divs {
|
||||
get { return divs; }
|
||||
}
|
||||
|
||||
@@ -480,6 +484,33 @@ namespace Commons.Xml.Relaxng
|
||||
}
|
||||
}
|
||||
|
||||
public class RelaxngGrammarContentList : CollectionBase
|
||||
{
|
||||
public RelaxngGrammarContentList ()
|
||||
{
|
||||
}
|
||||
|
||||
public void Add (IGrammarContent p)
|
||||
{
|
||||
List.Add (p);
|
||||
}
|
||||
|
||||
public IGrammarContent this [int i] {
|
||||
get { return this.List [i] as IGrammarContent; }
|
||||
set { this.List [i] = value; }
|
||||
}
|
||||
|
||||
public void Insert (int pos, IGrammarContent p)
|
||||
{
|
||||
List.Insert (pos, p);
|
||||
}
|
||||
|
||||
public void Remove (IGrammarContent p)
|
||||
{
|
||||
List.Remove (p);
|
||||
}
|
||||
}
|
||||
|
||||
// strict to say, it's not a pattern ;)
|
||||
public class RelaxngNotAllowed : RelaxngPattern
|
||||
{
|
||||
@@ -1317,7 +1348,7 @@ namespace Commons.Xml.Relaxng
|
||||
}
|
||||
}
|
||||
|
||||
public class RelaxngRefPattern
|
||||
internal class RelaxngRefPattern
|
||||
{
|
||||
RelaxngPattern patternRef;
|
||||
string name;
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Commons.Xml.Relaxng
|
||||
ZeroOrMore = 17, // no use in derivative
|
||||
Mixed = 18, // no use in derivative
|
||||
Optional = 19, // no use in derivative
|
||||
Include = 20, // no use in derivative
|
||||
// Include = 20, // no use in derivative
|
||||
ExternalRef = 21, // no use in derivative
|
||||
ParentRef = 22, // no use in derivative
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
2004-05-30 Atsushi Enomoto <[email protected]>
|
||||
|
||||
* RncTests.cs : fixed test that got impossible to build anymore.
|
||||
|
||||
2004-05-08 Gonzalo Paniagua Javier <[email protected]>
|
||||
|
||||
* RelaxngValidatingReaderTests.cs: this compiled with mcs but fails with
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace MonoTests.Commons.Xml.Relaxng
|
||||
{
|
||||
RncParser parser = new RncParser (new NameTable ());
|
||||
using (StreamReader sr = new StreamReader ("Test/XmlFiles/relaxng.rnc")) {
|
||||
RelaxngGrammar g = parser.Parse (sr);
|
||||
RelaxngPattern g = parser.Parse (sr);
|
||||
g.Compile ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
2004-05-31 Atsushi Enomoto <[email protected]>
|
||||
|
||||
* anglia-test-runner.cs : Added support for RELAX NG compact syntax
|
||||
parser tests.
|
||||
* Makefile : added anglia-test support.
|
||||
* README : ditto.
|
||||
|
||||
2004-02-25 Atsushi Enomoto <[email protected]>
|
||||
|
||||
* Added README, Makefile, relaxngtest.cs, prep.xsl, copying.html
|
||||
|
||||
@@ -1,26 +1,44 @@
|
||||
RUNTIME = mono
|
||||
MCS_RUNTIME =
|
||||
MCS = mcs
|
||||
|
||||
TESTS = relax-ng/001/i.rng
|
||||
TEST_ARCHIVE = testSuite.zip
|
||||
|
||||
RNCTESTS = test/RNCTest.xml
|
||||
RNCTEST_ARCHIVE = anglia-test-suite.zip
|
||||
|
||||
all : relaxngtest.exe anglia-test-runner.exe
|
||||
|
||||
relaxngtest.exe : relaxngtest.cs $(TESTS)
|
||||
$(MCS_RUNTIME) $(MCS) relaxngtest.cs -r:Commons.Xml.Relaxng.dll
|
||||
$(MCS_RUNTIME) $(MCS) -debug+ relaxngtest.cs -r:Commons.Xml.Relaxng.dll
|
||||
|
||||
anglia-test-runner.exe : anglia-test-runner.cs $(RNCTESTS)
|
||||
$(MCS_RUNTIME) $(MCS) -debug+ anglia-test-runner.cs -r:Commons.Xml.Relaxng.dll
|
||||
|
||||
$(TESTS) : $(TEST_ARCHIVE) relax-ng
|
||||
cd relax-ng; unzip -n ../$(TEST_ARCHIVE); \
|
||||
xsltproc split.xsl spectest.xml; cd ..; \
|
||||
cp prep.xsl relax-ng
|
||||
|
||||
$(RNCTESTS) : $(RNCTEST_ARCHIVE)
|
||||
unzip -n anglia-test-suite.zip
|
||||
|
||||
$(TEST_ARCHIVE) :
|
||||
wget http://www.thaiopensource.com/relaxng/testSuite.zip
|
||||
|
||||
$(RNCTEST_ARCHIVE) :
|
||||
wget http://www.jeffrafter.com/anglia/anglia-test-suite.zip
|
||||
|
||||
relax-ng:
|
||||
mkdir relax-ng
|
||||
|
||||
test :
|
||||
test : relaxngtest.exe
|
||||
$(RUNTIME) relaxngtest.exe
|
||||
|
||||
anglia-test : anglia-test-runner.exe
|
||||
$(RUNTIME) anglia-test-runner.exe
|
||||
|
||||
# be careful to use it. This removes ALL files in xml-test-suite!
|
||||
# clean:
|
||||
# rm -rf xml-test-suite
|
||||
@@ -1,17 +1,41 @@
|
||||
* standalone RELAX NG test program for the Test Suite
|
||||
|
||||
** Introduction
|
||||
* Standalone test collection for Commons.Xml.Relaxng.dll
|
||||
|
||||
** standalone RELAX NG test program for the Test Suite
|
||||
|
||||
It is a test runner for James Clark's test collection.
|
||||
|
||||
prep.xsl is included in Jing (a Java implementation of RELAX NG validator).
|
||||
copying.html is license information for prep.xsl and relaxng.rng.
|
||||
prep.xsl is originally included in Jing (a Java implementation of RELAX NG
|
||||
validator). copying.html is license information for prep.xsl and relaxng.rng.
|
||||
|
||||
** Usage
|
||||
|
||||
To set up test runner, you need xsltproc, which is included in libxslt.
|
||||
** standalone RELAX NG Compact Syntax test program for the "anglia" test suite
|
||||
|
||||
It is a test runner for Jeff Rafter's "anglia" RNC test collection.
|
||||
|
||||
|
||||
** How to build
|
||||
|
||||
NOTE: To set up test runner, you need xsltproc, which is included in libxslt.
|
||||
(Since the stylesheet uses extensions, we cannot use our xslt engine.)
|
||||
|
||||
"make" will download the test collection from http://www.thaiopensource.com/relaxng/testSuite.zip , run xsltproc and create test directories and files.
|
||||
"make" will do the same as "make relaxngtest.exe" and
|
||||
"make anglia-test-runner.exe".
|
||||
|
||||
"make relaxngtest.exe" will download the test collection from
|
||||
http://www.thaiopensource.com/relaxng/testSuite.zip and then run
|
||||
xsltproc to split tests and create test directories and files, and finally
|
||||
will compile relaxngtest.cs.
|
||||
|
||||
"make anglia-test-runner.exe" will download the test collection from
|
||||
http://www.jeffrafter.com/anglia/anglia-test-suite.zip , and then will expand
|
||||
that archive, and finally will compile anglia-test-runner.cs.
|
||||
|
||||
|
||||
*** How to run
|
||||
|
||||
"make test" will run relaxngtest.exe and will output the error cases.
|
||||
|
||||
"make anglia-test" will run anglia-test-runner.exe and will output the
|
||||
error cases.
|
||||
|
||||
"make test" will run the test program and will output the error cases.
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using Commons.Xml.Relaxng;
|
||||
using Commons.Xml.Relaxng.Rnc;
|
||||
|
||||
public class Driver
|
||||
{
|
||||
public static void Main ()
|
||||
{
|
||||
try {
|
||||
XmlDocument doc = new XmlDocument ();
|
||||
doc.Load ("test/RNCTest.xml");
|
||||
int success = 0;
|
||||
int failure = 0;
|
||||
foreach (XmlElement el in doc.SelectNodes ("/RNCTestCases/TestCase")) {
|
||||
string id = el.GetAttribute ("id");
|
||||
bool isValid = el.GetAttribute ("legal") == "true";
|
||||
RncParser p = new RncParser (new NameTable ());
|
||||
try {
|
||||
string s = new StreamReader ("test" + Path.DirectorySeparatorChar + el.GetAttribute ("path")).ReadToEnd ();
|
||||
p.Parse (new StringReader (s));
|
||||
if (isValid) {
|
||||
success++;
|
||||
// Console.Error.WriteLine ("valid " + id);
|
||||
} else {
|
||||
failure++;
|
||||
Console.Error.WriteLine ("INCORRECTLY VALID " + id);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
if (isValid) {
|
||||
failure++;
|
||||
Console.Error.WriteLine ("INCORRECTLY INVALID " + id + " --> " + ex.Message);
|
||||
} else {
|
||||
success++;
|
||||
// Console.Error.WriteLine ("invalid " + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Console.Error.WriteLine ("Total success: " + success);
|
||||
Console.Error.WriteLine ("Total failure: " + failure);
|
||||
} catch (Exception ex) {
|
||||
Console.Error.WriteLine ("Unexpected Exception: " + ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
2004-05-28 Duncan Mak <[email protected]>
|
||||
|
||||
* SharpZipLib.pub: Added public key.
|
||||
@@ -1,53 +1,53 @@
|
||||
// AssemblyInfo.cs
|
||||
// Copyright (C) 2001 Mike Krueger
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program 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 General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is
|
||||
// making a combined work based on this library. Thus, the terms and
|
||||
// conditions of the GNU General Public License cover the whole
|
||||
// combination.
|
||||
//
|
||||
// As a special exception, the copyright holders of this library give you
|
||||
// permission to link this library with independent modules to produce an
|
||||
// executable, regardless of the license terms of these independent
|
||||
// modules, and to copy and distribute the resulting executable under
|
||||
// terms of your choice, provided that you also meet, for each linked
|
||||
// independent module, the terms and conditions of the license of that
|
||||
// module. An independent module is a module which is not derived from
|
||||
// or based on this library. If you modify this library, you may extend
|
||||
// this exception to your version of the library, but you are not
|
||||
// obligated to do so. If you do not wish to do so, delete this
|
||||
// exception statement from your version.
|
||||
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: AssemblyTitle("SharpZipLibrary")]
|
||||
[assembly: AssemblyDescription("free C# zlib implementation")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("#ZipLibrary")]
|
||||
[assembly: AssemblyCopyright("(c) Mike Krueger 2001-2002")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
#if NET_2_0
|
||||
[assembly: AssemblyVersion("0.31.2.0")]
|
||||
#else
|
||||
[assembly: AssemblyVersion("0.31.0.0")]
|
||||
#endif
|
||||
|
||||
[assembly: AssemblyDelaySign(false)]
|
||||
[assembly: AssemblyKeyFile("SharpZipLib.key")]
|
||||
// AssemblyInfo.cs
|
||||
// Copyright (C) 2001 Mike Krueger
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program 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 General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is
|
||||
// making a combined work based on this library. Thus, the terms and
|
||||
// conditions of the GNU General Public License cover the whole
|
||||
// combination.
|
||||
//
|
||||
// As a special exception, the copyright holders of this library give you
|
||||
// permission to link this library with independent modules to produce an
|
||||
// executable, regardless of the license terms of these independent
|
||||
// modules, and to copy and distribute the resulting executable under
|
||||
// terms of your choice, provided that you also meet, for each linked
|
||||
// independent module, the terms and conditions of the license of that
|
||||
// module. An independent module is a module which is not derived from
|
||||
// or based on this library. If you modify this library, you may extend
|
||||
// this exception to your version of the library, but you are not
|
||||
// obligated to do so. If you do not wish to do so, delete this
|
||||
// exception statement from your version.
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: CLSCompliant(true)]
|
||||
|
||||
[assembly: AssemblyTitle("ICSharpCode.SharpZipLibrary")]
|
||||
[assembly: AssemblyDescription("free C# zlib implementation")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("#ZipLibrary")]
|
||||
[assembly: AssemblyCopyright("(c) Mike Krueger 2001-2004")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
[assembly: AssemblyVersion("0.6.0.0")]
|
||||
|
||||
[assembly: AssemblyDelaySign(true)]
|
||||
[assembly: AssemblyKeyFile ("SharpZipLib.pub")]
|
||||
@@ -35,7 +35,8 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
namespace ICSharpCode.SharpZipLib.BZip2
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Does all the compress and decompress pre-operation stuff.
|
||||
@@ -46,16 +47,8 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
{
|
||||
public static void Decompress(Stream instream, Stream outstream)
|
||||
{
|
||||
BufferedStream bos = new BufferedStream(outstream);
|
||||
BufferedStream bis = new BufferedStream(instream);
|
||||
int b = bis.ReadByte();
|
||||
if (b != 'B') {
|
||||
return;
|
||||
}
|
||||
b = bis.ReadByte();
|
||||
if (b != 'Z') {
|
||||
return;
|
||||
}
|
||||
System.IO.Stream bos = outstream;
|
||||
System.IO.Stream bis = instream;
|
||||
BZip2InputStream bzis = new BZip2InputStream(bis);
|
||||
int ch = bzis.ReadByte();
|
||||
while (ch != -1) {
|
||||
@@ -66,13 +59,11 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
}
|
||||
|
||||
public static void Compress(Stream instream, Stream outstream, int blockSize)
|
||||
{
|
||||
BufferedStream bos = new BufferedStream(outstream);
|
||||
bos.WriteByte((byte)'B');
|
||||
bos.WriteByte((byte)'Z');
|
||||
BufferedStream bis = new BufferedStream(instream);
|
||||
{
|
||||
System.IO.Stream bos = outstream;
|
||||
System.IO.Stream bis = instream;
|
||||
int ch = bis.ReadByte();
|
||||
BZip2OutputStream bzos = new BZip2OutputStream(bos);
|
||||
BZip2OutputStream bzos = new BZip2OutputStream(bos, blockSize);
|
||||
while(ch != -1) {
|
||||
bzos.WriteByte((byte)ch);
|
||||
ch = bis.ReadByte();
|
||||
|
||||
@@ -32,7 +32,8 @@
|
||||
// obligated to do so. If you do not wish to do so, delete this
|
||||
// exception statement from your version.
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
namespace ICSharpCode.SharpZipLib.BZip2
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Base class for both the compress and decompress classes.
|
||||
@@ -41,59 +42,59 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
public sealed class BZip2Constants
|
||||
{
|
||||
public readonly static int[] rNums = {
|
||||
619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
|
||||
985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
|
||||
733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
|
||||
419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
|
||||
878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
|
||||
862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
|
||||
150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
|
||||
170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
|
||||
73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
|
||||
909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
|
||||
641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
|
||||
161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
|
||||
382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
|
||||
98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
|
||||
227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
|
||||
469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
|
||||
184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
|
||||
715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
|
||||
951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
|
||||
652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
|
||||
645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
|
||||
609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
|
||||
653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
|
||||
411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
|
||||
170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
|
||||
857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
|
||||
669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
|
||||
944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
|
||||
344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
|
||||
897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
|
||||
433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
|
||||
686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
|
||||
946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
|
||||
978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
|
||||
680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
|
||||
707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
|
||||
297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
|
||||
134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
|
||||
343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
|
||||
140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
|
||||
170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
|
||||
369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
|
||||
804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
|
||||
896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
|
||||
661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
|
||||
768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
|
||||
61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
|
||||
372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
|
||||
780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
|
||||
920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
|
||||
645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
|
||||
936, 638
|
||||
};
|
||||
619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
|
||||
985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
|
||||
733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
|
||||
419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
|
||||
878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
|
||||
862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
|
||||
150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
|
||||
170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
|
||||
73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
|
||||
909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
|
||||
641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
|
||||
161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
|
||||
382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
|
||||
98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
|
||||
227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
|
||||
469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
|
||||
184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
|
||||
715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
|
||||
951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
|
||||
652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
|
||||
645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
|
||||
609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
|
||||
653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
|
||||
411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
|
||||
170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
|
||||
857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
|
||||
669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
|
||||
944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
|
||||
344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
|
||||
897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
|
||||
433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
|
||||
686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
|
||||
946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
|
||||
978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
|
||||
680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
|
||||
707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
|
||||
297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
|
||||
134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
|
||||
343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
|
||||
140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
|
||||
170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
|
||||
369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
|
||||
804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
|
||||
896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
|
||||
661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
|
||||
768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
|
||||
61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
|
||||
372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
|
||||
780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
|
||||
920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
|
||||
645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
|
||||
936, 638
|
||||
};
|
||||
|
||||
public readonly static int baseBlockSize = 100000;
|
||||
|
||||
|
||||
+34
-21
@@ -37,7 +37,8 @@ using System.IO;
|
||||
|
||||
using ICSharpCode.SharpZipLib.Checksums;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
namespace ICSharpCode.SharpZipLib.BZip2
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// An input stream that decompresses from the BZip2 format (without the file
|
||||
@@ -159,23 +160,23 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
|
||||
static void Cadvise()
|
||||
{
|
||||
Console.WriteLine("CRC Error");
|
||||
//Console.WriteLine("CRC Error");
|
||||
//throw new CCoruptionError();
|
||||
}
|
||||
|
||||
static void BadBGLengths()
|
||||
{
|
||||
Console.WriteLine("bad BG lengths");
|
||||
//Console.WriteLine("bad BG lengths");
|
||||
}
|
||||
|
||||
static void bitStreamEOF()
|
||||
static void BitStreamEOF()
|
||||
{
|
||||
Console.WriteLine("bit stream eof");
|
||||
//Console.WriteLine("bit stream eof");
|
||||
}
|
||||
|
||||
static void CompressedStreamEOF()
|
||||
{
|
||||
Console.WriteLine("compressed stream eof");
|
||||
//Console.WriteLine("compressed stream eof");
|
||||
}
|
||||
|
||||
void MakeMaps()
|
||||
@@ -209,8 +210,8 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
|
||||
bool blockRandomised;
|
||||
|
||||
// private int bytesIn;
|
||||
// private int bytesOut;
|
||||
// private int bytesIn;
|
||||
// private int bytesOut;
|
||||
int bsBuff;
|
||||
int bsLive;
|
||||
IChecksum mCrc = new StrangeCRC();
|
||||
@@ -284,7 +285,7 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
public override int ReadByte()
|
||||
{
|
||||
if (streamEnd) {
|
||||
return -1;
|
||||
return -1; // ok
|
||||
}
|
||||
|
||||
int retChar = currentChar;
|
||||
@@ -313,10 +314,14 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
// -jr- 18-Nov-2003 magic1 and 2 added here so stream is fully capable on its own
|
||||
char magic1 = BsGetUChar();
|
||||
char magic2 = BsGetUChar();
|
||||
|
||||
char magic3 = BsGetUChar();
|
||||
char magic4 = BsGetUChar();
|
||||
|
||||
if (magic3 != 'h' || magic4 < '1' || magic4 > '9') {
|
||||
if (magic1 != 'B' || magic2 != 'Z' || magic3 != 'h' || magic4 < '1' || magic4 > '9') {
|
||||
streamEnd = true;
|
||||
return;
|
||||
}
|
||||
@@ -365,7 +370,7 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
CrcError();
|
||||
}
|
||||
|
||||
// 1528150659
|
||||
// 1528150659
|
||||
computedCombinedCRC = ((computedCombinedCRC << 1) & 0xFFFFFFFF) | (computedCombinedCRC >> 31);
|
||||
computedCombinedCRC = computedCombinedCRC ^ (uint)computedBlockCRC;
|
||||
}
|
||||
@@ -382,17 +387,17 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
|
||||
static void BlockOverrun()
|
||||
{
|
||||
Console.WriteLine("Block overrun");
|
||||
//Console.WriteLine("Block overrun");
|
||||
}
|
||||
|
||||
static void BadBlockHeader()
|
||||
{
|
||||
Console.WriteLine("Bad block header");
|
||||
//Console.WriteLine("Bad block header");
|
||||
}
|
||||
|
||||
static void CrcError()
|
||||
{
|
||||
Console.WriteLine("crc error");
|
||||
//Console.WriteLine("crc error");
|
||||
}
|
||||
|
||||
|
||||
@@ -518,6 +523,10 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
inUse[i * 16 + j] = (BsR(1) == 1);
|
||||
}
|
||||
} else {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
inUse[i * 16 + j] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -622,6 +631,9 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
int zj;
|
||||
|
||||
while (zvec > limit[zt][zn]) {
|
||||
if (zn > 20) { // the longest code
|
||||
throw new ApplicationException("Bzip data error"); // -jr- 17-Dec-2003 from bzip 1.02 why 20???
|
||||
}
|
||||
zn++;
|
||||
while (bsLive < 1) {
|
||||
FillBuffer();
|
||||
@@ -630,10 +642,12 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
bsLive--;
|
||||
zvec = (zvec << 1) | zj;
|
||||
}
|
||||
if (zvec - baseArray[zt][zn] < 0 || zvec - baseArray[zt][zn] >= BZip2Constants.MAX_ALPHA_SIZE) {
|
||||
throw new ApplicationException("Bzip data error"); // -jr- 17-Dec-2003 from bzip 1.02
|
||||
}
|
||||
nextSym = perm[zt][zvec - baseArray[zt][zn]];
|
||||
|
||||
while (true) {
|
||||
|
||||
if (nextSym == EOB) {
|
||||
break;
|
||||
}
|
||||
@@ -643,9 +657,9 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
int n = 1;
|
||||
do {
|
||||
if (nextSym == BZip2Constants.RUNA) {
|
||||
s += (0+1) * n;
|
||||
s += (0 + 1) * n;
|
||||
} else if (nextSym == BZip2Constants.RUNB) {
|
||||
s += (1+1) * n;
|
||||
s += (1 + 1) * n;
|
||||
}
|
||||
|
||||
n <<= 1;
|
||||
@@ -762,7 +776,7 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
|
||||
void SetupRandPartA()
|
||||
{
|
||||
if(i2 <= last) {
|
||||
if (i2 <= last) {
|
||||
chPrev = ch2;
|
||||
ch2 = ll8[tPos];
|
||||
tPos = tt[tPos];
|
||||
@@ -886,11 +900,10 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
|
||||
void SetDecompressStructureSizes(int newSize100k)
|
||||
{
|
||||
if (!(0 <= newSize100k && newSize100k <= 9 &&
|
||||
0 <= blockSize100k && blockSize100k <= 9)) {
|
||||
if (!(0 <= newSize100k && newSize100k <= 9 && 0 <= blockSize100k && blockSize100k <= 9)) {
|
||||
throw new ApplicationException("Invalid block size");
|
||||
}
|
||||
|
||||
|
||||
blockSize100k = newSize100k;
|
||||
|
||||
if (newSize100k == 0) {
|
||||
|
||||
+80
-50
@@ -37,7 +37,8 @@ using System.IO;
|
||||
|
||||
using ICSharpCode.SharpZipLib.Checksums;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
namespace ICSharpCode.SharpZipLib.BZip2
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// An output stream that compresses into the BZip2 format (without the file
|
||||
@@ -152,7 +153,7 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
|
||||
static void Panic()
|
||||
{
|
||||
Console.WriteLine("panic");
|
||||
//Console.WriteLine("panic");
|
||||
}
|
||||
|
||||
void MakeMaps()
|
||||
@@ -222,7 +223,7 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
break;
|
||||
}
|
||||
if (yy < nHeap && weight[heap[yy+1]] < weight[heap[yy]]) {
|
||||
yy++;
|
||||
yy++;
|
||||
}
|
||||
if (weight[tmp] < weight[heap[yy]]) {
|
||||
break;
|
||||
@@ -241,13 +242,15 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
tmp = heap[zz];
|
||||
while (true) {
|
||||
yy = zz << 1;
|
||||
if (yy > nHeap)
|
||||
if (yy > nHeap) {
|
||||
break;
|
||||
if (yy < nHeap &&
|
||||
weight[heap[yy+1]] < weight[heap[yy]])
|
||||
yy++;
|
||||
if (weight[tmp] < weight[heap[yy]])
|
||||
}
|
||||
if (yy < nHeap && weight[heap[yy+1]] < weight[heap[yy]]) {
|
||||
yy++;
|
||||
}
|
||||
if (weight[tmp] < weight[heap[yy]]) {
|
||||
break;
|
||||
}
|
||||
heap[zz] = heap[yy];
|
||||
zz = yy;
|
||||
}
|
||||
@@ -255,7 +258,7 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
nNodes++;
|
||||
parent[n1] = parent[n2] = nNodes;
|
||||
|
||||
weight[nNodes] = (int)((weight[n1] & 0xffffff00) + (weight[n2] & 0xffffff00)) |
|
||||
weight[nNodes] = (int)((weight[n1] & 0xffffff00) + (weight[n2] & 0xffffff00)) |
|
||||
(int)(1 + (((weight[n1] & 0x000000ff) > (weight[n2] & 0x000000ff)) ? (weight[n1] & 0x000000ff) : (weight[n2] & 0x000000ff)));
|
||||
|
||||
parent[nNodes] = -1;
|
||||
@@ -319,7 +322,7 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
|
||||
bool blockRandomised;
|
||||
|
||||
// int bytesIn;
|
||||
// int bytesIn;
|
||||
int bytesOut;
|
||||
int bsBuff;
|
||||
int bsLive;
|
||||
@@ -475,14 +478,14 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
EndBlock();
|
||||
EndCompression();
|
||||
closed = true;
|
||||
// super.close();
|
||||
// super.close();
|
||||
Flush();
|
||||
baseStream.Close();
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
// super.flush();
|
||||
// super.flush();
|
||||
baseStream.Flush();
|
||||
}
|
||||
|
||||
@@ -490,13 +493,16 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
// bytesIn = 0;
|
||||
// bytesIn = 0;
|
||||
bytesOut = 0;
|
||||
nBlocksRandomised = 0;
|
||||
|
||||
/*--- Write `magic' bytes h indicating file-format == huffmanised,
|
||||
followed by a digit indicating blockSize100k.
|
||||
---*/
|
||||
BsPutUChar('B'); // -jr- 18-Nov-2003 added to match BZ2 1.02 header already in BZip class but that sux a lot
|
||||
BsPutUChar('Z');
|
||||
|
||||
BsPutUChar('h');
|
||||
BsPutUChar('0' + blockSize100k);
|
||||
|
||||
@@ -522,6 +528,10 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
|
||||
void EndBlock()
|
||||
{
|
||||
if (last < 0) { //-jr- dont do anything for empty files, (makes empty files compatible with original Bzip)
|
||||
return;
|
||||
}
|
||||
|
||||
blockCRC = (uint)mCrc.Value;
|
||||
combinedCRC = (combinedCRC << 1) | (combinedCRC >> 31);
|
||||
combinedCRC ^= blockCRC;
|
||||
@@ -609,7 +619,8 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
|
||||
void BsFinishedWithStream()
|
||||
{
|
||||
while (bsLive > 0) {
|
||||
while (bsLive > 0)
|
||||
{
|
||||
int ch = (bsBuff >> 24);
|
||||
baseStream.WriteByte((byte)ch); // write 8-bit
|
||||
bsBuff <<= 8;
|
||||
@@ -740,7 +751,6 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
totc = 0;
|
||||
gs = 0;
|
||||
while (true) {
|
||||
|
||||
/*--- Set group start & end marks. --*/
|
||||
if (gs >= nMTF) {
|
||||
break;
|
||||
@@ -831,7 +841,6 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
Panic();
|
||||
}
|
||||
|
||||
|
||||
/*--- Compute MTF values for the selectors. ---*/
|
||||
char[] pos = new char[BZip2Constants.N_GROUPS];
|
||||
char ll_i, tmp2, tmp;
|
||||
@@ -1011,35 +1020,40 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
i++;
|
||||
|
||||
/*-- copy 2 --*/
|
||||
if (i > hi)
|
||||
if (i > hi) {
|
||||
break;
|
||||
}
|
||||
v = zptr[i];
|
||||
j = i;
|
||||
while (FullGtU ( zptr[j-h]+d, v+d )) {
|
||||
zptr[j] = zptr[j-h];
|
||||
j = j - h;
|
||||
if (j <= (lo + h - 1))
|
||||
if (j <= (lo + h - 1)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
zptr[j] = v;
|
||||
i++;
|
||||
|
||||
/*-- copy 3 --*/
|
||||
if (i > hi)
|
||||
if (i > hi) {
|
||||
break;
|
||||
}
|
||||
v = zptr[i];
|
||||
j = i;
|
||||
while (FullGtU ( zptr[j-h]+d, v+d)) {
|
||||
zptr[j] = zptr[j-h];
|
||||
j = j - h;
|
||||
if (j <= (lo + h - 1))
|
||||
if (j <= (lo + h - 1)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
zptr[j] = v;
|
||||
i++;
|
||||
|
||||
if (workDone > workLimit && firstAttempt)
|
||||
if (workDone > workLimit && firstAttempt) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1088,8 +1102,9 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
int unLo, unHi, ltLo, gtHi, med, n, m;
|
||||
int sp, lo, hi, d;
|
||||
StackElem[] stack = new StackElem[QSORT_STACK_SIZE];
|
||||
for(int count = 0; count < QSORT_STACK_SIZE; count++)
|
||||
for (int count = 0; count < QSORT_STACK_SIZE; count++) {
|
||||
stack[count] = new StackElem();
|
||||
}
|
||||
|
||||
sp = 0;
|
||||
|
||||
@@ -1110,8 +1125,9 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
|
||||
if (hi - lo < SMALL_THRESH || d > DEPTH_THRESH) {
|
||||
SimpleSort(lo, hi, d);
|
||||
if (workDone > workLimit && firstAttempt)
|
||||
if (workDone > workLimit && firstAttempt) {
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1143,8 +1159,9 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
unLo++;
|
||||
}
|
||||
while (true) {
|
||||
if (unLo > unHi)
|
||||
if (unLo > unHi) {
|
||||
break;
|
||||
}
|
||||
n = ((int)block[zptr[unHi]+d + 1]) - med;
|
||||
if (n == 0) {
|
||||
int temp = 0;
|
||||
@@ -1154,19 +1171,21 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
gtHi--;
|
||||
unHi--;
|
||||
continue;
|
||||
};
|
||||
if (n < 0)
|
||||
}
|
||||
if (n < 0) {
|
||||
break;
|
||||
}
|
||||
unHi--;
|
||||
}
|
||||
if (unLo > unHi)
|
||||
if (unLo > unHi) {
|
||||
break;
|
||||
}
|
||||
{
|
||||
int temp = zptr[unLo];
|
||||
zptr[unLo] = zptr[unHi];
|
||||
zptr[unHi] = temp;
|
||||
unLo++;
|
||||
unHi--;
|
||||
int temp = zptr[unLo];
|
||||
zptr[unLo] = zptr[unHi];
|
||||
zptr[unHi] = temp;
|
||||
unLo++;
|
||||
unHi--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1233,18 +1252,20 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
Use simpleSort(), since the full sorting mechanism
|
||||
has quite a large constant overhead.
|
||||
--*/
|
||||
for (i = 0; i <= last; i++)
|
||||
for (i = 0; i <= last; i++) {
|
||||
zptr[i] = i;
|
||||
}
|
||||
firstAttempt = false;
|
||||
workDone = workLimit = 0;
|
||||
SimpleSort(0, last, 0);
|
||||
} else {
|
||||
numQSorted = 0;
|
||||
for (i = 0; i <= 255; i++)
|
||||
for (i = 0; i <= 255; i++) {
|
||||
bigDone[i] = false;
|
||||
|
||||
for (i = 0; i <= 65536; i++)
|
||||
}
|
||||
for (i = 0; i <= 65536; i++) {
|
||||
ftab[i] = 0;
|
||||
}
|
||||
|
||||
c1 = block[0];
|
||||
for (i = 0; i <= last; i++) {
|
||||
@@ -1253,8 +1274,9 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
c1 = c2;
|
||||
}
|
||||
|
||||
for (i = 1; i <= 65536; i++)
|
||||
for (i = 1; i <= 65536; i++) {
|
||||
ftab[i] += ftab[i - 1];
|
||||
}
|
||||
|
||||
c1 = block[1];
|
||||
for (i = 0; i < last; i++) {
|
||||
@@ -1292,8 +1314,9 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
while ((ftab[((runningOrder[j-h])+1) << 8] - ftab[(runningOrder[j-h]) << 8]) > (ftab[((vv)+1) << 8] - ftab[(vv) << 8])) {
|
||||
runningOrder[j] = runningOrder[j-h];
|
||||
j = j - h;
|
||||
if (j <= (h - 1))
|
||||
if (j <= (h - 1)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
runningOrder[j] = vv;
|
||||
}
|
||||
@@ -1318,7 +1341,7 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
--*/
|
||||
for (j = 0; j <= 255; j++) {
|
||||
sb = (ss << 8) + j;
|
||||
if(!((ftab[sb] & SETMASK) == SETMASK) ) {
|
||||
if(!((ftab[sb] & SETMASK) == SETMASK)) {
|
||||
int lo = ftab[sb] & CLEARMASK;
|
||||
int hi = (ftab[sb+1] & CLEARMASK) - 1;
|
||||
if (hi > lo) {
|
||||
@@ -1393,15 +1416,17 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
int i;
|
||||
int rNToGo = 0;
|
||||
int rTPos = 0;
|
||||
for (i = 0; i < 256; i++)
|
||||
for (i = 0; i < 256; i++) {
|
||||
inUse[i] = false;
|
||||
}
|
||||
|
||||
for (i = 0; i <= last; i++) {
|
||||
if (rNToGo == 0) {
|
||||
rNToGo = (int)BZip2Constants.rNums[rTPos];
|
||||
rTPos++;
|
||||
if(rTPos == 512)
|
||||
if (rTPos == 512) {
|
||||
rTPos = 0;
|
||||
}
|
||||
}
|
||||
rNToGo--;
|
||||
block[i + 1] ^= (byte)((rNToGo == 1) ? 1 : 0);
|
||||
@@ -1482,8 +1507,9 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
|
||||
c1 = block[i1 + 1];
|
||||
c2 = block[i2 + 1];
|
||||
if (c1 != c2)
|
||||
if (c1 != c2) {
|
||||
return c1 > c2;
|
||||
}
|
||||
i1++;
|
||||
i2++;
|
||||
|
||||
@@ -1572,9 +1598,11 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
because the number of elems to sort is
|
||||
usually small, typically <= 20.
|
||||
--*/
|
||||
readonly int[] incs = new int[] { 1, 4, 13, 40, 121, 364, 1093, 3280,
|
||||
9841, 29524, 88573, 265720,
|
||||
797161, 2391484 };
|
||||
readonly int[] incs = new int[] {
|
||||
1, 4, 13, 40, 121, 364, 1093, 3280,
|
||||
9841, 29524, 88573, 265720,
|
||||
797161, 2391484
|
||||
};
|
||||
|
||||
void AllocateCompressStructures()
|
||||
{
|
||||
@@ -1636,7 +1664,7 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
|
||||
j = 0;
|
||||
tmp = yy[j];
|
||||
while ( ll_i != tmp ) {
|
||||
while (ll_i != tmp) {
|
||||
j++;
|
||||
tmp2 = tmp;
|
||||
tmp = yy[j];
|
||||
@@ -1661,11 +1689,12 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
wr++;
|
||||
mtfFreq[BZip2Constants.RUNB]++;
|
||||
break;
|
||||
};
|
||||
if (zPend < 2)
|
||||
}
|
||||
if (zPend < 2) {
|
||||
break;
|
||||
}
|
||||
zPend = (zPend - 2) / 2;
|
||||
};
|
||||
}
|
||||
zPend = 0;
|
||||
}
|
||||
szptr[wr] = (short)(j + 1);
|
||||
@@ -1689,8 +1718,9 @@ namespace ICSharpCode.SharpZipLib.BZip2 {
|
||||
mtfFreq[BZip2Constants.RUNB]++;
|
||||
break;
|
||||
}
|
||||
if (zPend < 2)
|
||||
if (zPend < 2) {
|
||||
break;
|
||||
}
|
||||
zPend = (zPend - 2) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
2004-05-28 Duncan Mak <[email protected]>
|
||||
|
||||
* AssemblyInfo.cs: Use the new SharpZipLib.pub.
|
||||
* Zip/Compression/DeflaterHuffman.cs (FlushBlock): Add some
|
||||
parenthesis to help the generics compiler read this source.
|
||||
@@ -37,7 +37,8 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Checksums {
|
||||
namespace ICSharpCode.SharpZipLib.Checksums
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Computes Adler32 checksum for a stream of data. An Adler32
|
||||
|
||||
@@ -37,7 +37,8 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Checksums {
|
||||
namespace ICSharpCode.SharpZipLib.Checksums
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
|
||||
@@ -96,7 +97,7 @@ namespace ICSharpCode.SharpZipLib.Checksums {
|
||||
0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6,
|
||||
0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615,
|
||||
0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
|
||||
0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344,
|
||||
0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344,
|
||||
0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB,
|
||||
0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A,
|
||||
0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
|
||||
@@ -118,10 +119,15 @@ namespace ICSharpCode.SharpZipLib.Checksums {
|
||||
0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
|
||||
0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605,
|
||||
0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8,
|
||||
0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B,
|
||||
0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B,
|
||||
0x2D02EF8D
|
||||
};
|
||||
|
||||
internal static uint ComputeCrc32(uint oldCrc, byte bval)
|
||||
{
|
||||
return (uint)(Crc32.CrcTable[(oldCrc ^ bval) & 0xFF] ^ (oldCrc >> 8));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The crc data checksum so far.
|
||||
/// </summary>
|
||||
@@ -134,6 +140,9 @@ namespace ICSharpCode.SharpZipLib.Checksums {
|
||||
get {
|
||||
return (long)crc;
|
||||
}
|
||||
set {
|
||||
crc = (uint)value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -35,7 +35,8 @@
|
||||
// obligated to do so. If you do not wish to do so, delete this
|
||||
// exception statement from your version.
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Checksums {
|
||||
namespace ICSharpCode.SharpZipLib.Checksums
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Interface to compute a data checksum used by checked input/output streams.
|
||||
@@ -49,7 +50,8 @@ namespace ICSharpCode.SharpZipLib.Checksums {
|
||||
/// <summary>
|
||||
/// Returns the data checksum computed so far.
|
||||
/// </summary>
|
||||
long Value {
|
||||
long Value
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,76 +38,77 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Checksums {
|
||||
namespace ICSharpCode.SharpZipLib.Checksums
|
||||
{
|
||||
|
||||
public class StrangeCRC : IChecksum
|
||||
{
|
||||
readonly static uint[] crc32Table = {
|
||||
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9,
|
||||
0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,
|
||||
0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
|
||||
0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
|
||||
0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9,
|
||||
0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,
|
||||
0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011,
|
||||
0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd,
|
||||
0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
|
||||
0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5,
|
||||
0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81,
|
||||
0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,
|
||||
0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49,
|
||||
0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,
|
||||
0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1,
|
||||
0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d,
|
||||
0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae,
|
||||
0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,
|
||||
0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16,
|
||||
0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca,
|
||||
0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde,
|
||||
0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02,
|
||||
0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066,
|
||||
0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
|
||||
0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e,
|
||||
0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692,
|
||||
0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6,
|
||||
0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a,
|
||||
0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e,
|
||||
0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,
|
||||
0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686,
|
||||
0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a,
|
||||
0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637,
|
||||
0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb,
|
||||
0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f,
|
||||
0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,
|
||||
0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47,
|
||||
0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b,
|
||||
0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
|
||||
0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623,
|
||||
0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7,
|
||||
0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,
|
||||
0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f,
|
||||
0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,
|
||||
0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7,
|
||||
0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b,
|
||||
0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f,
|
||||
0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,
|
||||
0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640,
|
||||
0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c,
|
||||
0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8,
|
||||
0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24,
|
||||
0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30,
|
||||
0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
|
||||
0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088,
|
||||
0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654,
|
||||
0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0,
|
||||
0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c,
|
||||
0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18,
|
||||
0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,
|
||||
0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0,
|
||||
0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c,
|
||||
0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,
|
||||
0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
|
||||
};
|
||||
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9,
|
||||
0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,
|
||||
0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
|
||||
0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
|
||||
0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9,
|
||||
0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,
|
||||
0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011,
|
||||
0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd,
|
||||
0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
|
||||
0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5,
|
||||
0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81,
|
||||
0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,
|
||||
0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49,
|
||||
0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,
|
||||
0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1,
|
||||
0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d,
|
||||
0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae,
|
||||
0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,
|
||||
0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16,
|
||||
0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca,
|
||||
0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde,
|
||||
0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02,
|
||||
0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066,
|
||||
0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
|
||||
0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e,
|
||||
0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692,
|
||||
0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6,
|
||||
0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a,
|
||||
0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e,
|
||||
0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,
|
||||
0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686,
|
||||
0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a,
|
||||
0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637,
|
||||
0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb,
|
||||
0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f,
|
||||
0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,
|
||||
0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47,
|
||||
0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b,
|
||||
0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
|
||||
0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623,
|
||||
0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7,
|
||||
0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,
|
||||
0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f,
|
||||
0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,
|
||||
0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7,
|
||||
0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b,
|
||||
0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f,
|
||||
0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,
|
||||
0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640,
|
||||
0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c,
|
||||
0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8,
|
||||
0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24,
|
||||
0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30,
|
||||
0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
|
||||
0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088,
|
||||
0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654,
|
||||
0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0,
|
||||
0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c,
|
||||
0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18,
|
||||
0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,
|
||||
0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0,
|
||||
0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c,
|
||||
0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,
|
||||
0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
|
||||
};
|
||||
int globalCrc;
|
||||
|
||||
public StrangeCRC()
|
||||
|
||||
@@ -35,7 +35,8 @@
|
||||
// obligated to do so. If you do not wish to do so, delete this
|
||||
// exception statement from your version.
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.GZip {
|
||||
namespace ICSharpCode.SharpZipLib.GZip
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// This class contains constants used for gzip.
|
||||
|
||||
@@ -42,7 +42,8 @@ using ICSharpCode.SharpZipLib.Checksums;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.GZip {
|
||||
namespace ICSharpCode.SharpZipLib.GZip
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// This filter stream is used to decompress a "GZIP" format stream.
|
||||
@@ -80,9 +81,6 @@ namespace ICSharpCode.SharpZipLib.GZip {
|
||||
/// </example>
|
||||
public class GZipInputStream : InflaterInputStream
|
||||
{
|
||||
|
||||
//Variables
|
||||
|
||||
/// <summary>
|
||||
/// CRC-32 value for uncompressed data
|
||||
/// </summary>
|
||||
@@ -93,6 +91,9 @@ namespace ICSharpCode.SharpZipLib.GZip {
|
||||
/// </summary>
|
||||
protected bool eos;
|
||||
|
||||
// Have we read the GZIP header yet?
|
||||
bool readGZIPHeader;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a GzipInputStream with the default buffer size
|
||||
/// </summary>
|
||||
@@ -165,8 +166,8 @@ namespace ICSharpCode.SharpZipLib.GZip {
|
||||
Crc32 headCRC = new Crc32();
|
||||
int magic = baseInputStream.ReadByte();
|
||||
if (magic < 0) {
|
||||
eos = true;
|
||||
return;
|
||||
eos = true;
|
||||
return;
|
||||
}
|
||||
headCRC.Update(magic);
|
||||
if (magic != (GZipConstants.GZIP_MAGIC >> 8)) {
|
||||
@@ -246,7 +247,8 @@ namespace ICSharpCode.SharpZipLib.GZip {
|
||||
extraLen = (len1 << 8) | len2;
|
||||
for (int i = 0; i < extraLen;i++) {
|
||||
int readByte = baseInputStream.ReadByte();
|
||||
if (readByte < 0) {
|
||||
if (readByte < 0)
|
||||
{
|
||||
throw new Exception("Early EOF baseInputStream GZIP header");
|
||||
}
|
||||
headCRC.Update(readByte);
|
||||
@@ -330,8 +332,5 @@ namespace ICSharpCode.SharpZipLib.GZip {
|
||||
*/
|
||||
eos = true;
|
||||
}
|
||||
|
||||
/* Have we read the GZIP header yet? */
|
||||
private bool readGZIPHeader;
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,8 @@ using ICSharpCode.SharpZipLib.Checksums;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.GZip {
|
||||
namespace ICSharpCode.SharpZipLib.GZip
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// This filter stream is used to compress a stream into a "GZIP" stream.
|
||||
@@ -55,7 +56,7 @@ namespace ICSharpCode.SharpZipLib.GZip {
|
||||
/// using System;
|
||||
/// using System.IO;
|
||||
///
|
||||
/// using NZlib.GZip;
|
||||
/// using ICSharpCode.SharpZipLib.GZip; // -jr- corrected
|
||||
///
|
||||
/// class MainClass
|
||||
/// {
|
||||
@@ -103,7 +104,12 @@ namespace ICSharpCode.SharpZipLib.GZip {
|
||||
/// </param>
|
||||
public GZipOutputStream(Stream baseOutputStream, int size) : base(baseOutputStream, new Deflater(Deflater.DEFAULT_COMPRESSION, true), size)
|
||||
{
|
||||
// TODO : find out correctness, orgininally this was : (int) (System.currentTimeMillis() / 1000L);
|
||||
WriteHeader();
|
||||
// System.err.println("wrote GZIP header (" + gzipHeader.length + " bytes )");
|
||||
}
|
||||
|
||||
void WriteHeader()
|
||||
{
|
||||
int mod_time = (int)(DateTime.Now.Ticks / 10000L); // Ticks give back 100ns intervals
|
||||
byte[] gzipHeader = {
|
||||
/* The two magic bytes */
|
||||
@@ -125,9 +131,7 @@ namespace ICSharpCode.SharpZipLib.GZip {
|
||||
/* The OS type (unknown) */
|
||||
(byte) 255
|
||||
};
|
||||
|
||||
baseOutputStream.Write(gzipHeader, 0, gzipHeader.Length);
|
||||
// System.err.println("wrote GZIP header (" + gzipHeader.length + " bytes )");
|
||||
}
|
||||
|
||||
public override void Write(byte[] buf, int off, int len)
|
||||
@@ -162,7 +166,7 @@ namespace ICSharpCode.SharpZipLib.GZip {
|
||||
(byte) totalin, (byte) (totalin >> 8),
|
||||
(byte) (totalin >> 16), (byte) (totalin >> 24)
|
||||
};
|
||||
|
||||
|
||||
baseOutputStream.Write(gzipFooter, 0, gzipFooter.Length);
|
||||
// System.err.println("wrote GZIP trailer (" + gzipFooter.length + " bytes )");
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// BZip2OutputStream.cs
|
||||
// InvalidHeaderException.cs
|
||||
// Copyright (C) 2001 Mike Krueger
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
|
||||
@@ -38,18 +38,18 @@ using System.Text;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Tar {
|
||||
|
||||
public delegate void ProgressMessageHandler(TarArchive archive, string message);
|
||||
public delegate void ProgressMessageHandler(TarArchive archive, TarEntry entry, string message);
|
||||
|
||||
/// <summary>
|
||||
/// The TarArchive class implements the concept of a
|
||||
/// tar archive. A tar archive is a series of entries, each of
|
||||
/// which represents a file system object. Each entry in
|
||||
/// the archive consists of a header record. Directory entries
|
||||
/// consist only of the header record, and are followed by entries
|
||||
/// the archive consists of a header block. Directory entries
|
||||
/// consist only of the header block, and are followed by entries
|
||||
/// for the directory's contents. File entries consist of a
|
||||
/// header record followed by the number of records needed to
|
||||
/// header followed by the number of blocks needed to
|
||||
/// contain the file's contents. All entries are written on
|
||||
/// record boundaries. Records are 512 bytes long.
|
||||
/// block boundaries. Blocks are 512 bytes long.
|
||||
///
|
||||
/// TarArchives are instantiated in either read or write mode,
|
||||
/// based upon whether they are instantiated with an InputStream
|
||||
@@ -63,31 +63,31 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </summary>
|
||||
public class TarArchive
|
||||
{
|
||||
protected bool verbose;
|
||||
protected bool debug;
|
||||
protected bool keepOldFiles;
|
||||
protected bool asciiTranslate;
|
||||
bool verbose;
|
||||
bool debug;
|
||||
bool keepOldFiles;
|
||||
bool asciiTranslate;
|
||||
|
||||
protected int userId;
|
||||
protected string userName;
|
||||
protected int groupId;
|
||||
protected string groupName;
|
||||
int userId;
|
||||
string userName;
|
||||
int groupId;
|
||||
string groupName;
|
||||
|
||||
protected string rootPath;
|
||||
protected string pathPrefix;
|
||||
string rootPath;
|
||||
string pathPrefix;
|
||||
|
||||
protected int recordSize;
|
||||
protected byte[] recordBuf;
|
||||
int recordSize;
|
||||
byte[] recordBuf;
|
||||
|
||||
protected TarInputStream tarIn;
|
||||
protected TarOutputStream tarOut;
|
||||
TarInputStream tarIn;
|
||||
TarOutputStream tarOut;
|
||||
|
||||
public event ProgressMessageHandler ProgressMessageEvent;
|
||||
|
||||
protected virtual void OnProgressMessageEvent(string message)
|
||||
protected virtual void OnProgressMessageEvent(TarEntry entry, string message)
|
||||
{
|
||||
if (ProgressMessageEvent != null) {
|
||||
ProgressMessageEvent(this, message);
|
||||
ProgressMessageEvent(this, entry, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,19 +103,14 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </summary>
|
||||
public static TarArchive CreateInputTarArchive(Stream inputStream)
|
||||
{
|
||||
return CreateInputTarArchive(inputStream, TarBuffer.DEFAULT_BLKSIZE);
|
||||
return CreateInputTarArchive(inputStream, TarBuffer.DefaultBlockFactor);
|
||||
}
|
||||
|
||||
public static TarArchive CreateInputTarArchive(Stream inputStream, int blockSize)
|
||||
{
|
||||
return CreateInputTarArchive(inputStream, blockSize, TarBuffer.DEFAULT_RCDSIZE);
|
||||
}
|
||||
|
||||
public static TarArchive CreateInputTarArchive(Stream inputStream, int blockSize, int recordSize)
|
||||
public static TarArchive CreateInputTarArchive(Stream inputStream, int blockFactor)
|
||||
{
|
||||
TarArchive archive = new TarArchive();
|
||||
archive.tarIn = new TarInputStream(inputStream, blockSize, recordSize);
|
||||
archive.Initialize(recordSize);
|
||||
archive.tarIn = new TarInputStream(inputStream, blockFactor);
|
||||
archive.Initialize(blockFactor * TarBuffer.BlockSize);
|
||||
return archive;
|
||||
}
|
||||
|
||||
@@ -126,28 +121,23 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </summary>
|
||||
public static TarArchive CreateOutputTarArchive(Stream outputStream)
|
||||
{
|
||||
return CreateOutputTarArchive(outputStream, TarBuffer.DEFAULT_BLKSIZE);
|
||||
return CreateOutputTarArchive(outputStream, TarBuffer.DefaultBlockFactor);
|
||||
}
|
||||
|
||||
public static TarArchive CreateOutputTarArchive(Stream outputStream, int blockSize)
|
||||
{
|
||||
return CreateOutputTarArchive(outputStream, blockSize, TarBuffer.DEFAULT_RCDSIZE);
|
||||
}
|
||||
|
||||
public static TarArchive CreateOutputTarArchive(Stream outputStream, int blockSize, int recordSize)
|
||||
public static TarArchive CreateOutputTarArchive(Stream outputStream, int blockFactor)
|
||||
{
|
||||
TarArchive archive = new TarArchive();
|
||||
archive.tarOut = new TarOutputStream(outputStream, blockSize, recordSize);
|
||||
archive.Initialize(recordSize);
|
||||
archive.tarOut = new TarOutputStream(outputStream, blockFactor);
|
||||
archive.Initialize(blockFactor * TarBuffer.BlockSize);
|
||||
return archive;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Common constructor initialization code.
|
||||
/// </summary>
|
||||
void Initialize(int recordSize)
|
||||
{
|
||||
this.recordSize = recordSize;
|
||||
this.rootPath = null;
|
||||
this.pathPrefix = null;
|
||||
|
||||
@@ -165,11 +155,11 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
this.recordBuf = new byte[RecordSize];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the debugging flag.
|
||||
*
|
||||
* @param debugF The new debug setting.
|
||||
*/
|
||||
///
|
||||
/// <summary> Set the debugging flag. </summary>
|
||||
///
|
||||
/// <param name=debugF> The new debug setting. </param>
|
||||
|
||||
public void SetDebug(bool debugF)
|
||||
{
|
||||
this.debug = debugF;
|
||||
@@ -206,7 +196,7 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the ascii file translation flag. If ascii file translatio
|
||||
/// Set the ascii file translation flag. If ascii file translation
|
||||
/// is true, then the MIME file type will be consulted to determine
|
||||
/// if the file is of type 'text/*'. If the MIME type is not found,
|
||||
/// then the TransFileTyper is consulted if it is not null. If
|
||||
@@ -214,8 +204,7 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// file, it will be translated. The translation converts the local
|
||||
/// operating system's concept of line ends into the UNIX line end,
|
||||
/// '\n', which is the defacto standard for a TAR archive. This makes
|
||||
/// text files compatible with UNIX, and since most tar implementations
|
||||
/// text files compatible with UNIX, and since most tar implementations
|
||||
/// text files compatible with UNIX.
|
||||
/// </summary>
|
||||
/// <param name= "asciiTranslate">
|
||||
/// If true, translate ascii text files.
|
||||
@@ -225,7 +214,7 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
this.asciiTranslate = asciiTranslate;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
/// <summary>
|
||||
/// Set the object that will determine if a file is of type
|
||||
/// ascii text for translation purposes.
|
||||
@@ -236,7 +225,8 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
public void SetTransFileTyper(TarTransFileTyper transTyper)
|
||||
{
|
||||
this.transTyper = transTyper;
|
||||
}*/
|
||||
}
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// Set user and group information that will be used to fill in the
|
||||
@@ -315,11 +305,11 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
|
||||
/// <summary>
|
||||
/// Get the archive's record size. Because of its history, tar
|
||||
/// supports the concept of buffered IO consisting of BLOCKS of
|
||||
/// RECORDS. This allowed tar to match the IO characteristics of
|
||||
/// supports the concept of buffered IO consisting of RECORDS of
|
||||
/// BLOCKS. This allowed tar to match the IO characteristics of
|
||||
/// the physical device being used. Of course, in the Java world,
|
||||
/// this makes no sense, WITH ONE EXCEPTION - archives are expected
|
||||
/// to be propertly "blocked". Thus, all of the horrible TarBuffer
|
||||
/// to be properly "blocked". Thus, all of the horrible TarBuffer
|
||||
/// support boils down to simply getting the "boundaries" correct.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
@@ -329,10 +319,11 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
get {
|
||||
if (this.tarIn != null) {
|
||||
return this.tarIn.GetRecordSize();
|
||||
} else if (this.tarOut != null) {
|
||||
}
|
||||
else if (this.tarOut != null) {
|
||||
return this.tarOut.GetRecordSize();
|
||||
}
|
||||
return TarBuffer.DEFAULT_RCDSIZE;
|
||||
return TarBuffer.DefaultRecordSize;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,7 +335,8 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
{
|
||||
if (this.tarIn != null) {
|
||||
this.tarIn.Close();
|
||||
} else if (this.tarOut != null) {
|
||||
}
|
||||
else if (this.tarOut != null) {
|
||||
this.tarOut.Flush();
|
||||
this.tarOut.Close();
|
||||
}
|
||||
@@ -364,11 +356,11 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
|
||||
if (entry == null) {
|
||||
if (this.debug) {
|
||||
Console.Error.WriteLine("READ EOF RECORD");
|
||||
Console.Error.WriteLine("READ EOF BLOCK");
|
||||
}
|
||||
break;
|
||||
}
|
||||
OnProgressMessageEvent(entry.Name);
|
||||
OnProgressMessageEvent(entry, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,7 +377,7 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
|
||||
if (entry == null) {
|
||||
if (this.debug) {
|
||||
Console.Error.WriteLine("READ EOF RECORD");
|
||||
Console.Error.WriteLine("READ EOF BLOCK");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -399,20 +391,22 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
if (!Directory.Exists(directoryName)) {
|
||||
try {
|
||||
Directory.CreateDirectory(directoryName);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IOException("error making directory path '" + directoryName + "', " + e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO -jr- No longer reads entire file into memory but is still a weak test!
|
||||
bool IsBinary(string filename)
|
||||
{
|
||||
FileStream fs = File.OpenRead(filename);
|
||||
|
||||
byte[] content = new byte[fs.Length];
|
||||
int sampleSize = System.Math.Min(4096, (int)fs.Length);
|
||||
byte[] content = new byte[sampleSize];
|
||||
|
||||
fs.Read(content, 0, (int)fs.Length);
|
||||
fs.Read(content, 0, sampleSize);
|
||||
fs.Close();
|
||||
|
||||
// assume that ascii 0 or
|
||||
@@ -440,7 +434,7 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
void ExtractEntry(string destDir, TarEntry entry)
|
||||
{
|
||||
if (this.verbose) {
|
||||
OnProgressMessageEvent(entry.Name);
|
||||
OnProgressMessageEvent(entry, null);
|
||||
}
|
||||
|
||||
string name = entry.Name;
|
||||
@@ -454,15 +448,17 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
|
||||
if (entry.IsDirectory) {
|
||||
EnsureDirectoryExists(destFile);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
string parentDirectory = Path.GetDirectoryName(destFile);
|
||||
EnsureDirectoryExists(parentDirectory);
|
||||
|
||||
if (this.keepOldFiles && File.Exists(destFile)) {
|
||||
if (this.verbose) {
|
||||
OnProgressMessageEvent("not overwriting " + entry.Name);
|
||||
OnProgressMessageEvent(entry, "Destination file already exists");
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
bool asciiTrans = false;
|
||||
Stream outputStream = File.Create(destFile);
|
||||
if (this.asciiTranslate) {
|
||||
@@ -512,14 +508,16 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
off = b + 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
outputStream.Write(rdbuf, 0, numRead);
|
||||
}
|
||||
}
|
||||
|
||||
if (asciiTrans) {
|
||||
outw.Close();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
outputStream.Close();
|
||||
}
|
||||
}
|
||||
@@ -551,7 +549,8 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
//
|
||||
if (eFile == null || eFile.Length == 0) {
|
||||
entry = TarEntry.CreateTarEntry(entry.Name);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
//
|
||||
// The user may have explicitly set the entry's name to
|
||||
// something other than the file's path, so we must save
|
||||
@@ -564,11 +563,12 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
}
|
||||
|
||||
if (this.verbose) {
|
||||
OnProgressMessageEvent(entry.Name);
|
||||
OnProgressMessageEvent(entry, null);
|
||||
}
|
||||
|
||||
if (this.asciiTranslate && !entry.IsDirectory) {
|
||||
asciiTrans = !IsBinary(eFile);
|
||||
|
||||
// original java source :
|
||||
// MimeType mime = null;
|
||||
// string contentType = null;
|
||||
@@ -616,6 +616,7 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
}
|
||||
|
||||
inStream.Close();
|
||||
|
||||
outStream.Flush();
|
||||
outStream.Close();
|
||||
|
||||
@@ -650,7 +651,8 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
this.WriteEntry(list[i], recurse);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
Stream inputStream = File.OpenRead(eFile);
|
||||
int numWritten = 0;
|
||||
byte[] eBuf = new byte[32 * 1024];
|
||||
@@ -664,7 +666,8 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
this.tarOut.Write(eBuf, 0, numRead);
|
||||
numWritten += numRead;
|
||||
}
|
||||
Console.WriteLine("written " + numWritten + " bytes");
|
||||
|
||||
// Console.WriteLine("written " + numWritten + " bytes");
|
||||
|
||||
inputStream.Close();
|
||||
|
||||
|
||||
@@ -36,14 +36,15 @@ using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Tar {
|
||||
namespace ICSharpCode.SharpZipLib.Tar
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The TarBuffer class implements the tar archive concept
|
||||
/// of a buffered input stream. This concept goes back to the
|
||||
/// days of blocked tape drives and special io devices. In the
|
||||
/// C# universe, the only real function that this class
|
||||
/// performs is to ensure that files have the correct "block"
|
||||
/// performs is to ensure that files have the correct "record"
|
||||
/// size, or other tars will complain.
|
||||
/// <p>
|
||||
/// You should never have a need to access this class directly.
|
||||
@@ -52,20 +53,68 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </summary>
|
||||
public class TarBuffer
|
||||
{
|
||||
public static readonly int DEFAULT_RCDSIZE = 512;
|
||||
public static readonly int DEFAULT_BLKSIZE = DEFAULT_RCDSIZE * 20;
|
||||
|
||||
/* A quote from GNU tar man file on blocking and records
|
||||
A `tar' archive file contains a series of blocks. Each block
|
||||
contains `BLOCKSIZE' bytes. Although this format may be thought of as
|
||||
being on magnetic tape, other media are often used.
|
||||
|
||||
Each file archived is represented by a header block which describes
|
||||
the file, followed by zero or more blocks which give the contents of
|
||||
the file. At the end of the archive file there may be a block filled
|
||||
with binary zeros as an end-of-file marker. A reasonable system should
|
||||
write a block of zeros at the end, but must not assume that such a
|
||||
block exists when reading an archive.
|
||||
|
||||
The blocks may be "blocked" for physical I/O operations. Each
|
||||
record of N blocks (where N is set by the `--blocking-factor=512-SIZE'
|
||||
(`-b 512-SIZE') option to `tar') is written with a single `write ()'
|
||||
operation. On magnetic tapes, the result of such a write is a single
|
||||
record. When writing an archive, the last record of blocks should be
|
||||
written at the full size, with blocks after the zero block containing
|
||||
all zeros. When reading an archive, a reasonable system should
|
||||
properly handle an archive whose last record is shorter than the rest,
|
||||
or which contains garbage records after a zero block.
|
||||
*/
|
||||
|
||||
// public static readonly int DEFAULT_RCDSIZE = 512;
|
||||
// public const int DEFAULT_BLOCKFACTOR = 20;
|
||||
// public static readonly int DEFAULT_BLKSIZE = DEFAULT_RCDSIZE * DEFAULT_BLOCKFACTOR;
|
||||
|
||||
public static readonly int BlockSize = 512;
|
||||
public static readonly int DefaultBlockFactor = 20;
|
||||
public static readonly int DefaultRecordSize = BlockSize * DefaultBlockFactor;
|
||||
|
||||
Stream inputStream;
|
||||
Stream outputStream;
|
||||
|
||||
byte[] blockBuffer;
|
||||
int currBlkIdx;
|
||||
int currRecIdx;
|
||||
int blockSize;
|
||||
int recordSize;
|
||||
int recsPerBlock;
|
||||
byte[] recordBuffer;
|
||||
int currentBlockIndex;
|
||||
int currentRecordIndex;
|
||||
|
||||
int recordSize = DefaultRecordSize;
|
||||
public int RecordSize
|
||||
{
|
||||
get { return recordSize; }
|
||||
}
|
||||
|
||||
int blockFactor = DefaultBlockFactor;
|
||||
|
||||
public int BlockFactor
|
||||
{
|
||||
get { return blockFactor; }
|
||||
}
|
||||
|
||||
bool debug = false;
|
||||
|
||||
/// <summary>
|
||||
/// Set the debugging flag for the buffer.
|
||||
/// </summary>
|
||||
public void SetDebug(bool debug)
|
||||
{
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
bool debug;
|
||||
|
||||
protected TarBuffer()
|
||||
{
|
||||
@@ -73,36 +122,30 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
|
||||
public static TarBuffer CreateInputTarBuffer(Stream inputStream)
|
||||
{
|
||||
return CreateInputTarBuffer(inputStream, TarBuffer.DEFAULT_BLKSIZE);
|
||||
return CreateInputTarBuffer(inputStream, TarBuffer.DefaultBlockFactor);
|
||||
}
|
||||
public static TarBuffer CreateInputTarBuffer(Stream inputStream, int blockSize )
|
||||
{
|
||||
return CreateInputTarBuffer(inputStream, blockSize, TarBuffer.DEFAULT_RCDSIZE);
|
||||
}
|
||||
public static TarBuffer CreateInputTarBuffer(Stream inputStream, int blockSize, int recordSize)
|
||||
|
||||
public static TarBuffer CreateInputTarBuffer(Stream inputStream, int blockFactor)
|
||||
{
|
||||
TarBuffer tarBuffer = new TarBuffer();
|
||||
tarBuffer.inputStream = inputStream;
|
||||
tarBuffer.outputStream = null;
|
||||
tarBuffer.Initialize(blockSize, recordSize);
|
||||
tarBuffer.Initialize(blockFactor);
|
||||
|
||||
return tarBuffer;
|
||||
}
|
||||
|
||||
public static TarBuffer CreateOutputTarBuffer(Stream outputStream)
|
||||
{
|
||||
return CreateOutputTarBuffer(outputStream, TarBuffer.DEFAULT_BLKSIZE);
|
||||
return CreateOutputTarBuffer(outputStream, TarBuffer.DefaultBlockFactor);
|
||||
}
|
||||
public static TarBuffer CreateOutputTarBuffer(Stream outputStream, int blockSize )
|
||||
{
|
||||
return CreateOutputTarBuffer(outputStream, blockSize, TarBuffer.DEFAULT_RCDSIZE);
|
||||
}
|
||||
public static TarBuffer CreateOutputTarBuffer(Stream outputStream, int blockSize, int recordSize)
|
||||
|
||||
public static TarBuffer CreateOutputTarBuffer(Stream outputStream, int blockFactor)
|
||||
{
|
||||
TarBuffer tarBuffer = new TarBuffer();
|
||||
tarBuffer.inputStream = null;
|
||||
tarBuffer.outputStream = outputStream;
|
||||
tarBuffer.Initialize(blockSize, recordSize);
|
||||
tarBuffer.Initialize(blockFactor);
|
||||
|
||||
return tarBuffer;
|
||||
}
|
||||
@@ -110,29 +153,32 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <summary>
|
||||
/// Initialization common to all constructors.
|
||||
/// </summary>
|
||||
void Initialize(int blockSize, int recordSize)
|
||||
void Initialize(int blockFactor)
|
||||
{
|
||||
this.debug = false;
|
||||
this.blockSize = blockSize;
|
||||
this.recordSize = recordSize;
|
||||
this.recsPerBlock = this.blockSize / this.recordSize;
|
||||
this.blockBuffer = new byte[this.blockSize];
|
||||
this.blockFactor = blockFactor;
|
||||
this.recordSize = blockFactor * BlockSize;
|
||||
|
||||
this.recordBuffer = new byte[RecordSize];
|
||||
|
||||
if (inputStream != null) {
|
||||
this.currBlkIdx = -1;
|
||||
this.currRecIdx = this.recsPerBlock;
|
||||
} else {
|
||||
this.currBlkIdx = 0;
|
||||
this.currRecIdx = 0;
|
||||
if (inputStream != null)
|
||||
{
|
||||
this.currentRecordIndex = -1;
|
||||
this.currentBlockIndex = BlockFactor;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.currentRecordIndex = 0;
|
||||
this.currentBlockIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the TAR Buffer's block size. Blocks consist of multiple records.
|
||||
/// Get the TAR Buffer's block factor
|
||||
/// </summary>
|
||||
public int GetBlockSize()
|
||||
public int GetBlockFactor()
|
||||
{
|
||||
return this.blockSize;
|
||||
return this.blockFactor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -144,24 +190,21 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the debugging flag for the buffer.
|
||||
/// Determine if an archive block indicates End of Archive. End of
|
||||
/// archive is indicated by a block that consists entirely of null bytes.
|
||||
/// All remaining blocks for the record should also be null's
|
||||
/// However some older tars only do a couple of null blocks (Old GNU tar for one)
|
||||
/// and also partial records
|
||||
/// </summary>
|
||||
public void SetDebug(bool debug)
|
||||
{
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine if an archive record indicate End of Archive. End of
|
||||
/// archive is indicated by a record that consists entirely of null bytes.
|
||||
/// </summary>
|
||||
/// <param name = "record">
|
||||
/// The record data to check.
|
||||
/// <param name = "block">
|
||||
/// The block data to check.
|
||||
/// </param>
|
||||
public bool IsEOFRecord(byte[] record)
|
||||
public bool IsEOFBlock(byte[] block)
|
||||
{
|
||||
for (int i = 0, sz = this.GetRecordSize(); i < sz; ++i) {
|
||||
if (record[i] != 0) {
|
||||
for (int i = 0, sz = BlockSize; i < sz; ++i)
|
||||
{
|
||||
if (block[i] != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -170,156 +213,175 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Skip over a record on the input stream.
|
||||
/// Skip over a block on the input stream.
|
||||
/// </summary>
|
||||
public void SkipRecord()
|
||||
public void SkipBlock()
|
||||
{
|
||||
if (this.debug) {
|
||||
Console.Error.WriteLine("SkipRecord: recIdx = " + this.currRecIdx + " blkIdx = " + this.currBlkIdx);
|
||||
if (this.debug)
|
||||
{
|
||||
//Console.WriteLine.WriteLine("SkipBlock: recIdx = " + this.currentRecordIndex + " blkIdx = " + this.currentBlockIndex);
|
||||
}
|
||||
|
||||
if (this.inputStream == null) {
|
||||
if (this.inputStream == null)
|
||||
{
|
||||
throw new System.IO.IOException("no input stream defined");
|
||||
}
|
||||
|
||||
if (this.currRecIdx >= this.recsPerBlock) {
|
||||
if (!this.ReadBlock()) {
|
||||
if (this.currentBlockIndex >= this.BlockFactor)
|
||||
{
|
||||
if (!this.ReadRecord())
|
||||
{
|
||||
return; // UNDONE
|
||||
}
|
||||
}
|
||||
|
||||
this.currRecIdx++;
|
||||
this.currentBlockIndex++;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a record from the input stream and return the data.
|
||||
/// Read a block from the input stream and return the data.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The record data.
|
||||
/// The block data.
|
||||
/// </returns>
|
||||
public byte[] ReadRecord()
|
||||
public byte[] ReadBlock()
|
||||
{
|
||||
if (this.debug) {
|
||||
Console.Error.WriteLine( "ReadRecord: recIdx = " + this.currRecIdx + " blkIdx = " + this.currBlkIdx );
|
||||
if (this.debug)
|
||||
{
|
||||
//Console.WriteLine.WriteLine( "ReadBlock: blockIndex = " + this.currentBlockIndex + " recordIndex = " + this.currentRecordIndex );
|
||||
}
|
||||
|
||||
if (this.inputStream == null) {
|
||||
throw new System.IO.IOException("no input stream defined");
|
||||
if (this.inputStream == null)
|
||||
{
|
||||
throw new ApplicationException("TarBuffer.ReadBlock - no input stream defined");
|
||||
}
|
||||
|
||||
if (this.currRecIdx >= this.recsPerBlock) {
|
||||
if (!this.ReadBlock()) {
|
||||
if (this.currentBlockIndex >= this.BlockFactor)
|
||||
{
|
||||
if (!this.ReadRecord())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
byte[] result = new byte[this.recordSize];
|
||||
byte[] result = new byte[BlockSize];
|
||||
|
||||
Array.Copy(this.blockBuffer, (this.currRecIdx * this.recordSize), result, 0, this.recordSize );
|
||||
this.currRecIdx++;
|
||||
Array.Copy(this.recordBuffer, (this.currentBlockIndex * BlockSize), result, 0, BlockSize );
|
||||
this.currentBlockIndex++;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <returns>
|
||||
/// false if End-Of-File, else true
|
||||
/// </returns>
|
||||
bool ReadBlock()
|
||||
bool ReadRecord()
|
||||
{
|
||||
Console.WriteLine(this.debug);
|
||||
if (this.debug) {
|
||||
Console.Error.WriteLine("ReadBlock: blkIdx = " + this.currBlkIdx);
|
||||
if (this.debug)
|
||||
{
|
||||
//Console.WriteLine.WriteLine("ReadRecord: recordIndex = " + this.currentRecordIndex);
|
||||
}
|
||||
|
||||
if (this.inputStream == null) {
|
||||
if (this.inputStream == null)
|
||||
{
|
||||
throw new System.IO.IOException("no input stream stream defined");
|
||||
}
|
||||
|
||||
this.currRecIdx = 0;
|
||||
this.currentBlockIndex = 0;
|
||||
|
||||
int offset = 0;
|
||||
int bytesNeeded = this.blockSize;
|
||||
for (; bytesNeeded > 0 ;) {
|
||||
long numBytes = this.inputStream.Read(this.blockBuffer, offset, bytesNeeded);
|
||||
int bytesNeeded = RecordSize;
|
||||
|
||||
while (bytesNeeded > 0)
|
||||
{
|
||||
long numBytes = this.inputStream.Read(this.recordBuffer, offset, bytesNeeded);
|
||||
|
||||
//
|
||||
// NOTE
|
||||
// We have fit EOF, and the block is not full!
|
||||
// We have found EOF, and the record is not full!
|
||||
//
|
||||
// This is a broken archive. It does not follow the standard
|
||||
// blocking algorithm. However, because we are generous, and
|
||||
// it requires little effort, we will simply ignore the error
|
||||
// and continue as if the entire block were read. This does
|
||||
// and continue as if the entire record were read. This does
|
||||
// not appear to break anything upstream. We used to return
|
||||
// false in this case.
|
||||
//
|
||||
// Thanks to '[email protected]' for this fix.
|
||||
//
|
||||
if (numBytes <= 0) {
|
||||
if (numBytes <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
offset += (int)numBytes;
|
||||
bytesNeeded -= (int)numBytes;
|
||||
if (numBytes != this.blockSize) {
|
||||
if (this.debug) {
|
||||
Console.Error.WriteLine("ReadBlock: INCOMPLETE READ " + numBytes + " of " + this.blockSize + " bytes read.");
|
||||
if (numBytes != RecordSize)
|
||||
{
|
||||
if (this.debug)
|
||||
{
|
||||
//Console.WriteLine.WriteLine("ReadRecord: INCOMPLETE READ " + numBytes + " of " + this.blockSize + " bytes read.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.currBlkIdx++;
|
||||
this.currentRecordIndex++;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the current block number, zero based.
|
||||
/// Get the current block number, within the current record, zero based.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The current zero based block number.
|
||||
/// </returns>
|
||||
public int GetCurrentBlockNum()
|
||||
{
|
||||
return this.currBlkIdx;
|
||||
return this.currentBlockIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the current record number, within the current block, zero based.
|
||||
/// Thus, current offset = (currentBlockNum * recsPerBlk) + currentRecNum.
|
||||
/// Get the current record number
|
||||
/// Absolute block number in file = (currentRecordNum * block factor) + currentBlockNum.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The current zero based record number.
|
||||
/// </returns>
|
||||
public int GetCurrentRecordNum()
|
||||
{
|
||||
return this.currRecIdx - 1;
|
||||
return this.currentRecordIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an archive record to the archive.
|
||||
/// Write an archive block to the archive.
|
||||
/// </summary>
|
||||
/// <param name="record">
|
||||
/// The record data to write to the archive.
|
||||
/// <param name="block">
|
||||
/// The data to write to the archive.
|
||||
/// </param>
|
||||
///
|
||||
public void WriteRecord(byte[] record)
|
||||
public void WriteBlock(byte[] block)
|
||||
{
|
||||
if (this.debug) {
|
||||
Console.Error.WriteLine("WriteRecord: recIdx = " + this.currRecIdx + " blkIdx = " + this.currBlkIdx );
|
||||
if (this.debug)
|
||||
{
|
||||
//Console.WriteLine.WriteLine("WriteRecord: recIdx = " + this.currentRecordIndex + " blkIdx = " + this.currentBlockIndex );
|
||||
}
|
||||
|
||||
if (this.outputStream == null) {
|
||||
throw new System.IO.IOException("no output stream defined");
|
||||
if (this.outputStream == null)
|
||||
{
|
||||
throw new ApplicationException("TarBuffer.WriteBlock - no output stream defined");
|
||||
}
|
||||
|
||||
if (record.Length != this.recordSize) {
|
||||
throw new IOException("record to write has length '" + record.Length + "' which is not the record size of '" + this.recordSize + "'" );
|
||||
if (block.Length != BlockSize)
|
||||
{
|
||||
throw new ApplicationException("TarBuffer.WriteBlock - block to write has length '" + block.Length + "' which is not the block size of '" + BlockSize + "'" );
|
||||
}
|
||||
|
||||
if (this.currRecIdx >= this.recsPerBlock) {
|
||||
this.WriteBlock();
|
||||
if (this.currentBlockIndex >= BlockFactor)
|
||||
{
|
||||
this.WriteRecord();
|
||||
}
|
||||
Array.Copy(record, 0, this.blockBuffer, (this.currRecIdx * this.recordSize), this.recordSize );
|
||||
this.currRecIdx++;
|
||||
|
||||
Array.Copy(block, 0, this.recordBuffer, (this.currentBlockIndex * BlockSize), BlockSize);
|
||||
this.currentBlockIndex++;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -333,47 +395,53 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <param name="offset">
|
||||
/// The offset of the record data within buf.
|
||||
/// </param>
|
||||
public void WriteRecord(byte[] buf, int offset)
|
||||
public void WriteBlock(byte[] buf, int offset)
|
||||
{
|
||||
if (this.debug) {
|
||||
Console.Error.WriteLine("WriteRecord: recIdx = " + this.currRecIdx + " blkIdx = " + this.currBlkIdx );
|
||||
if (this.debug)
|
||||
{
|
||||
//Console.WriteLine.WriteLine("WriteBlock: recIdx = " + this.currentRecordIndex + " blkIdx = " + this.currentBlockIndex );
|
||||
}
|
||||
|
||||
if (this.outputStream == null) {
|
||||
throw new System.IO.IOException("no output stream stream defined");
|
||||
if (this.outputStream == null)
|
||||
{
|
||||
throw new ApplicationException("TarBuffer.WriteBlock - no output stream stream defined");
|
||||
}
|
||||
|
||||
if ((offset + this.recordSize) > buf.Length) {
|
||||
throw new IOException("record has length '" + buf.Length + "' with offset '" + offset + "' which is less than the record size of '" + this.recordSize + "'" );
|
||||
if ((offset + BlockSize) > buf.Length)
|
||||
{
|
||||
throw new ApplicationException("TarBuffer.WriteBlock - record has length '" + buf.Length + "' with offset '" + offset + "' which is less than the record size of '" + this.recordSize + "'" );
|
||||
}
|
||||
|
||||
if (this.currRecIdx >= this.recsPerBlock) {
|
||||
this.WriteBlock();
|
||||
if (this.currentBlockIndex >= this.BlockFactor)
|
||||
{
|
||||
this.WriteRecord();
|
||||
}
|
||||
|
||||
Array.Copy(buf, offset, this.blockBuffer, (this.currRecIdx * this.recordSize), this.recordSize );
|
||||
Array.Copy(buf, offset, this.recordBuffer, (this.currentBlockIndex * BlockSize), BlockSize);
|
||||
|
||||
this.currRecIdx++;
|
||||
this.currentBlockIndex++;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a TarBuffer block to the archive.
|
||||
/// Write a TarBuffer record to the archive.
|
||||
/// </summary>
|
||||
void WriteBlock()
|
||||
void WriteRecord()
|
||||
{
|
||||
if (this.debug) {
|
||||
Console.Error.WriteLine("WriteBlock: blkIdx = " + this.currBlkIdx);
|
||||
if (this.debug)
|
||||
{
|
||||
//Console.WriteLine.WriteLine("Writerecord: record index = " + this.currentRecordIndex);
|
||||
}
|
||||
|
||||
if (this.outputStream == null) {
|
||||
throw new System.IO.IOException("no output stream defined");
|
||||
if (this.outputStream == null)
|
||||
{
|
||||
throw new ApplicationException("TarBuffer.WriteRecord no output stream defined");
|
||||
}
|
||||
|
||||
this.outputStream.Write(this.blockBuffer, 0, this.blockSize);
|
||||
this.outputStream.Write(this.recordBuffer, 0, RecordSize);
|
||||
this.outputStream.Flush();
|
||||
|
||||
this.currRecIdx = 0;
|
||||
this.currBlkIdx++;
|
||||
this.currentBlockIndex = 0;
|
||||
this.currentRecordIndex++;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -381,16 +449,19 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </summary>
|
||||
void Flush()
|
||||
{
|
||||
if (this.debug) {
|
||||
Console.Error.WriteLine("TarBuffer.FlushBlock() called.");
|
||||
if (this.debug)
|
||||
{
|
||||
//Console.WriteLine.WriteLine("TarBuffer.FlushBlock() called.");
|
||||
}
|
||||
|
||||
if (this.outputStream == null) {
|
||||
throw new System.IO.IOException("no output base stream defined");
|
||||
if (this.outputStream == null)
|
||||
{
|
||||
throw new ApplicationException("TarBuffer.Flush no output stream defined");
|
||||
}
|
||||
|
||||
if (this.currRecIdx > 0) {
|
||||
this.WriteBlock();
|
||||
if (this.currentBlockIndex > 0)
|
||||
{
|
||||
this.WriteRecord();
|
||||
}
|
||||
outputStream.Flush();
|
||||
}
|
||||
@@ -401,25 +472,27 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </summary>
|
||||
public void Close()
|
||||
{
|
||||
if (this.debug) {
|
||||
Console.Error.WriteLine("TarBuffer.Close().");
|
||||
if (this.debug)
|
||||
{
|
||||
//Console.WriteLine.WriteLine("TarBuffer.Close().");
|
||||
}
|
||||
|
||||
if (outputStream != null ) {
|
||||
if (outputStream != null)
|
||||
{
|
||||
Flush();
|
||||
|
||||
// if ( this.outStream != System.out
|
||||
// && this.outStream != System.err ) {
|
||||
outputStream.Close();
|
||||
outputStream = null;
|
||||
} else if (inputStream != null) {
|
||||
// if (this.inStream != System.in ) {
|
||||
}
|
||||
else if (inputStream != null)
|
||||
{
|
||||
inputStream.Close();
|
||||
inputStream = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* The original Java file had this header:
|
||||
*
|
||||
** Authored by Timothy Gerard Endres
|
||||
|
||||
@@ -36,7 +36,8 @@ using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Tar {
|
||||
namespace ICSharpCode.SharpZipLib.Tar
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// This class represents an entry in a Tar archive. It consists
|
||||
@@ -64,27 +65,6 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// other information. In this case the header fields are set to
|
||||
/// defaults and the File is set to null.</p>
|
||||
///
|
||||
/// <p>
|
||||
/// The C structure for a Tar Entry's header is:
|
||||
/// <pre>
|
||||
/// struct header {
|
||||
/// char name[NAMSIZ];
|
||||
/// char mode[8];
|
||||
/// char uid[8];
|
||||
/// char gid[8];
|
||||
/// char size[12];
|
||||
/// char mtime[12];
|
||||
/// char chksum[8];
|
||||
/// char linkflag;
|
||||
/// char linkname[NAMSIZ];
|
||||
/// char magic[8];
|
||||
/// char uname[TUNMLEN];
|
||||
/// char gname[TGNMLEN];
|
||||
/// char devmajor[8];
|
||||
/// char devminor[8];
|
||||
/// } header;
|
||||
/// </pre>
|
||||
/// </p>
|
||||
/// <see cref="TarHeader"/>
|
||||
/// </summary>
|
||||
public class TarEntry
|
||||
@@ -92,12 +72,12 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <summary>
|
||||
/// If this entry represents a File, this references it.
|
||||
/// </summary>
|
||||
protected string file;
|
||||
string file;
|
||||
|
||||
/// <summary>
|
||||
/// This is the entry's header information.
|
||||
/// </summary>
|
||||
protected TarHeader header;
|
||||
TarHeader header;
|
||||
|
||||
/// <summary>
|
||||
/// Only Create Entries with the static CreateXYZ methods or a headerBuffer.
|
||||
@@ -116,10 +96,15 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
public TarEntry(byte[] headerBuf)
|
||||
{
|
||||
this.Initialize();
|
||||
this.ParseTarHeader(this.header, headerBuf);
|
||||
this.header.ParseBuffer(headerBuf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public TarEntry(TarHeader header)
|
||||
{
|
||||
file = null;
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Construct an entry with only a name. This allows the programmer
|
||||
@@ -149,7 +134,7 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialization code common to all constructors.
|
||||
/// Initialization code common to all pseudo constructors.
|
||||
/// </summary>
|
||||
void Initialize()
|
||||
{
|
||||
@@ -166,7 +151,8 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </returns>
|
||||
public override bool Equals(object it)
|
||||
{
|
||||
if (!(it is TarEntry)) {
|
||||
if (!(it is TarEntry))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this.header.name.ToString().Equals(((TarEntry)it).header.name.ToString());
|
||||
@@ -203,8 +189,10 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <returns>
|
||||
/// This entry's TarHeader.
|
||||
/// </returns>
|
||||
public TarHeader TarHeader {
|
||||
get {
|
||||
public TarHeader TarHeader
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.header;
|
||||
}
|
||||
}
|
||||
@@ -212,11 +200,14 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <summary>
|
||||
/// Get/Set this entry's name.
|
||||
/// </summary>
|
||||
public string Name {
|
||||
get {
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.header.name.ToString();
|
||||
}
|
||||
set {
|
||||
set
|
||||
{
|
||||
this.header.name = new StringBuilder(value);
|
||||
}
|
||||
}
|
||||
@@ -224,11 +215,14 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <summary>
|
||||
/// Get/set this entry's user id.
|
||||
/// </summary>
|
||||
public int UserId {
|
||||
get {
|
||||
public int UserId
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.header.userId;
|
||||
}
|
||||
set {
|
||||
set
|
||||
{
|
||||
this.header.userId = value;
|
||||
}
|
||||
}
|
||||
@@ -236,11 +230,14 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <summary>
|
||||
/// Get/set this entry's group id.
|
||||
/// </summary>
|
||||
public int GroupId {
|
||||
get {
|
||||
public int GroupId
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.header.groupId;
|
||||
}
|
||||
set {
|
||||
set
|
||||
{
|
||||
this.header.groupId = value;
|
||||
}
|
||||
}
|
||||
@@ -248,11 +245,14 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <summary>
|
||||
/// Get/set this entry's user name.
|
||||
/// </summary>
|
||||
public string UserName {
|
||||
get {
|
||||
public string UserName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.header.userName.ToString();
|
||||
}
|
||||
set {
|
||||
set
|
||||
{
|
||||
this.header.userName = new StringBuilder(value);
|
||||
}
|
||||
}
|
||||
@@ -260,11 +260,14 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <summary>
|
||||
/// Get/set this entry's group name.
|
||||
/// </summary>
|
||||
public string GroupName {
|
||||
get {
|
||||
public string GroupName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.header.groupName.ToString();
|
||||
}
|
||||
set {
|
||||
set
|
||||
{
|
||||
this.header.groupName = new StringBuilder(value);
|
||||
}
|
||||
}
|
||||
@@ -299,17 +302,17 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
GroupName = groupName;
|
||||
}
|
||||
|
||||
// TODO :
|
||||
// /**
|
||||
// * Set this entry's modification time. The parameter passed
|
||||
// * to this method is in "Java time".
|
||||
// *
|
||||
// * @param time This entry's new modification time.
|
||||
// */
|
||||
// public void setModTime( long time )
|
||||
// {
|
||||
// this.header.modTime = time / 1000;
|
||||
// }
|
||||
// TODO :
|
||||
// /**
|
||||
// * Set this entry's modification time. The parameter passed
|
||||
// * to this method is in "Java time".
|
||||
// *
|
||||
// * @param time This entry's new modification time.
|
||||
// */
|
||||
// public void setModTime( long time )
|
||||
// {
|
||||
// this.header.modTime = time / 1000;
|
||||
// }
|
||||
|
||||
/// Convert time to DateTimes
|
||||
/**
|
||||
@@ -317,11 +320,14 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
*
|
||||
* @param time This entry's new modification time.
|
||||
*/
|
||||
public DateTime ModTime {
|
||||
get {
|
||||
public DateTime ModTime
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.header.modTime;
|
||||
}
|
||||
set {
|
||||
set
|
||||
{
|
||||
this.header.modTime = value;
|
||||
}
|
||||
}
|
||||
@@ -332,8 +338,10 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <returns>
|
||||
/// This entry's file.
|
||||
/// </returns>
|
||||
public string File {
|
||||
get {
|
||||
public string File
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.file;
|
||||
}
|
||||
}
|
||||
@@ -341,11 +349,14 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <summary>
|
||||
/// Get/set this entry's file size.
|
||||
/// </summary>
|
||||
public long Size {
|
||||
get {
|
||||
public long Size
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.header.size;
|
||||
}
|
||||
set {
|
||||
set
|
||||
{
|
||||
this.header.size = value;
|
||||
}
|
||||
}
|
||||
@@ -374,13 +385,17 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </returns>
|
||||
public bool IsDirectory
|
||||
{
|
||||
get {
|
||||
if (this.file != null) {
|
||||
get
|
||||
{
|
||||
if (this.file != null)
|
||||
{
|
||||
return Directory.Exists(file);
|
||||
}
|
||||
|
||||
if (this.header != null) {
|
||||
if (this.header.linkFlag == TarHeader.LF_DIR || this.header.name.ToString().EndsWith( "/" )) {
|
||||
if (this.header != null)
|
||||
{
|
||||
if (this.header.typeFlag == TarHeader.LF_DIR || this.header.name.ToString().EndsWith( "/" ))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -400,50 +415,61 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
public void GetFileTarHeader(TarHeader hdr, string file)
|
||||
{
|
||||
this.file = file;
|
||||
|
||||
string name = Path.GetDirectoryName(file);
|
||||
|
||||
if (Path.DirectorySeparatorChar == '\\') { // check if the OS is a windows
|
||||
|
||||
// bugfix from torhovl from #D forum:
|
||||
string name = file;
|
||||
|
||||
// -jr- 23-Jan-2004 HAK HAK HAK, GnuTar allows device names in path where the name is not local to the current directory
|
||||
if (Environment.CurrentDirectory == Path.GetDirectoryName(name))
|
||||
{
|
||||
name = Path.GetFileName(name);
|
||||
}
|
||||
/*
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
{ // check if the OS is Windows
|
||||
// Strip off drive letters!
|
||||
if (name.Length > 2) {
|
||||
if (name.Length > 2)
|
||||
{
|
||||
char ch1 = name[0];
|
||||
char ch2 = name[1];
|
||||
|
||||
if (ch2 == ':' && Char.IsLetter(ch1)) {
|
||||
if (ch2 == ':' && Char.IsLetter(ch1))
|
||||
{
|
||||
name = name.Substring(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
name = name.Replace(Path.DirectorySeparatorChar, '/');
|
||||
|
||||
name = name.Replace(Path.DirectorySeparatorChar, '/').ToLower();
|
||||
|
||||
// No absolute pathnames
|
||||
// Windows (and Posix?) paths can start with "\\NetworkDrive\",
|
||||
// Windows (and Posix?) paths can start with UNC style "\\NetworkDrive\",
|
||||
// so we loop on starting /'s.
|
||||
while (name.StartsWith("/")) {
|
||||
name = name.Substring(1);
|
||||
}
|
||||
|
||||
|
||||
hdr.linkName = new StringBuilder(String.Empty);
|
||||
hdr.name = new StringBuilder(name);
|
||||
|
||||
if (Directory.Exists(file)) {
|
||||
hdr.mode = 040755; // TODO : what does this magic number ?? Mike
|
||||
hdr.linkFlag = TarHeader.LF_DIR;
|
||||
if (hdr.name[hdr.name.Length - 1] != '/') {
|
||||
hdr.mode = 1003; // 01753 -jr- no octal constants!! 040755; // Magic number for security access for a UNIX filesystem
|
||||
hdr.typeFlag = TarHeader.LF_DIR;
|
||||
if (hdr.name.Length == 0 || hdr.name[hdr.name.Length - 1] != '/') {
|
||||
hdr.name.Append("/");
|
||||
}
|
||||
|
||||
hdr.size = 0;
|
||||
} else {
|
||||
hdr.mode = 0100644; // TODO : again a magic number
|
||||
hdr.linkFlag = TarHeader.LF_NORMAL;
|
||||
Console.WriteLine(file.Replace('/', Path.DirectorySeparatorChar));
|
||||
hdr.mode = 33216; // 0100700 -jr- // 0100644; // Magic number for security access for a UNIX filesystem
|
||||
hdr.typeFlag = TarHeader.LF_NORMAL;
|
||||
hdr.size = new FileInfo(file.Replace('/', Path.DirectorySeparatorChar)).Length;
|
||||
}
|
||||
|
||||
// UNDONE When File lets us get the userName, use it!
|
||||
hdr.modTime = System.IO.File.GetLastAccessTime(file.Replace('/', Path.DirectorySeparatorChar));
|
||||
hdr.checkSum = 0;
|
||||
hdr.modTime = System.IO.File.GetLastWriteTimeUtc(file.Replace('/', Path.DirectorySeparatorChar)); // -jr- Unix times are in UTC
|
||||
hdr.checkSum = 0;
|
||||
hdr.devMajor = 0;
|
||||
hdr.devMinor = 0;
|
||||
}
|
||||
@@ -457,44 +483,23 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </returns>
|
||||
public TarEntry[] GetDirectoryEntries()
|
||||
{
|
||||
if (this.file == null || !Directory.Exists(this.file)) {
|
||||
if (this.file == null || !Directory.Exists(this.file))
|
||||
{
|
||||
return new TarEntry[0];
|
||||
}
|
||||
|
||||
string[] list = Directory.GetFileSystemEntries(this.file);
|
||||
TarEntry[] result = new TarEntry[list.Length];
|
||||
|
||||
string dirName = file;
|
||||
if (!dirName.EndsWith(Path.DirectorySeparatorChar.ToString())) {
|
||||
dirName += Path.DirectorySeparatorChar;
|
||||
}
|
||||
|
||||
for (int i = 0; i < list.Length; ++i) {
|
||||
|
||||
for (int i = 0; i < list.Length; ++i)
|
||||
{
|
||||
result[i] = TarEntry.CreateEntryFromFile(list[i]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compute the checksum of a tar entry header.
|
||||
/// </summary>
|
||||
/// <param name = "buf">
|
||||
/// The tar entry's header buffer.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The computed checksum.
|
||||
/// </returns>
|
||||
public long ComputeCheckSum(byte[] buf)
|
||||
{
|
||||
long sum = 0;
|
||||
for (int i = 0; i < buf.Length; ++i) {
|
||||
sum += 255 & buf[i]; // TODO : I think the 255 & x isn't neccessary += buf[i] should be enough. CHECK IT!
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Write an entry's header information to a header buffer.
|
||||
/// </summary>
|
||||
/// <param name = "outbuf">
|
||||
@@ -502,120 +507,7 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </param>
|
||||
public void WriteEntryHeader(byte[] outbuf)
|
||||
{
|
||||
int offset = 0;
|
||||
|
||||
offset = TarHeader.GetNameBytes(this.header.name, outbuf, offset, TarHeader.NAMELEN);
|
||||
offset = TarHeader.GetOctalBytes(this.header.mode, outbuf, offset, TarHeader.MODELEN);
|
||||
offset = TarHeader.GetOctalBytes(this.header.userId, outbuf, offset, TarHeader.UIDLEN);
|
||||
offset = TarHeader.GetOctalBytes(this.header.groupId, outbuf, offset, TarHeader.GIDLEN);
|
||||
|
||||
long size = this.header.size;
|
||||
|
||||
offset = TarHeader.GetLongOctalBytes(size, outbuf, offset, TarHeader.SIZELEN);
|
||||
offset = TarHeader.GetLongOctalBytes(GetCTime(this.header.modTime), outbuf, offset, TarHeader.MODTIMELEN);
|
||||
|
||||
int csOffset = offset;
|
||||
for (int c = 0; c < TarHeader.CHKSUMLEN; ++c) {
|
||||
outbuf[offset++] = (byte)' ';
|
||||
}
|
||||
|
||||
outbuf[offset++] = this.header.linkFlag;
|
||||
|
||||
offset = TarHeader.GetNameBytes(this.header.linkName, outbuf, offset, TarHeader.NAMELEN);
|
||||
offset = TarHeader.GetNameBytes(this.header.magic, outbuf, offset, TarHeader.MAGICLEN);
|
||||
offset = TarHeader.GetNameBytes(this.header.userName, outbuf, offset, TarHeader.UNAMELEN);
|
||||
offset = TarHeader.GetNameBytes(this.header.groupName, outbuf, offset, TarHeader.GNAMELEN);
|
||||
|
||||
offset = TarHeader.GetOctalBytes(this.header.devMajor, outbuf, offset, TarHeader.DEVLEN);
|
||||
offset = TarHeader.GetOctalBytes(this.header.devMinor, outbuf, offset, TarHeader.DEVLEN);
|
||||
|
||||
for (; offset < outbuf.Length;) {
|
||||
outbuf[offset++] = 0;
|
||||
}
|
||||
|
||||
long checkSum = this.ComputeCheckSum(outbuf);
|
||||
|
||||
TarHeader.GetCheckSumOctalBytes(checkSum, outbuf, csOffset, TarHeader.CHKSUMLEN);
|
||||
}
|
||||
|
||||
// time conversion functions
|
||||
readonly static long timeConversionFactor = 10000000L;
|
||||
readonly static DateTime datetTime1970 = new DateTime(1970, 1, 1, 0, 0, 0, 0);
|
||||
|
||||
static int GetCTime(System.DateTime dateTime)
|
||||
{
|
||||
return (int)((dateTime.Ticks - datetTime1970.Ticks) / timeConversionFactor);
|
||||
}
|
||||
|
||||
static DateTime GetDateTimeFromCTime(long ticks)
|
||||
{
|
||||
return new DateTime(datetTime1970.Ticks + ticks * timeConversionFactor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse an entry's TarHeader information from a header buffer.
|
||||
/// </summary>
|
||||
/// <param name ="hdr">
|
||||
/// Parse an entry's TarHeader information from a header buffer.
|
||||
/// </param>
|
||||
/// <param name = "header">
|
||||
/// The tar entry header buffer to get information from.
|
||||
/// </param>
|
||||
public void ParseTarHeader(TarHeader hdr, byte[] header)
|
||||
{
|
||||
int offset = 0;
|
||||
|
||||
hdr.name = TarHeader.ParseName(header, offset, TarHeader.NAMELEN);
|
||||
|
||||
offset += TarHeader.NAMELEN;
|
||||
|
||||
hdr.mode = (int)TarHeader.ParseOctal(header, offset, TarHeader.MODELEN);
|
||||
|
||||
offset += TarHeader.MODELEN;
|
||||
|
||||
hdr.userId = (int)TarHeader.ParseOctal(header, offset, TarHeader.UIDLEN);
|
||||
|
||||
offset += TarHeader.UIDLEN;
|
||||
|
||||
hdr.groupId = (int)TarHeader.ParseOctal(header, offset, TarHeader.GIDLEN);
|
||||
|
||||
offset += TarHeader.GIDLEN;
|
||||
|
||||
hdr.size = TarHeader.ParseOctal(header, offset, TarHeader.SIZELEN);
|
||||
|
||||
offset += TarHeader.SIZELEN;
|
||||
|
||||
hdr.modTime = GetDateTimeFromCTime(TarHeader.ParseOctal(header, offset, TarHeader.MODTIMELEN));
|
||||
|
||||
offset += TarHeader.MODTIMELEN;
|
||||
|
||||
hdr.checkSum = (int)TarHeader.ParseOctal(header, offset, TarHeader.CHKSUMLEN);
|
||||
|
||||
offset += TarHeader.CHKSUMLEN;
|
||||
|
||||
hdr.linkFlag = header[ offset++ ];
|
||||
|
||||
hdr.linkName = TarHeader.ParseName(header, offset, TarHeader.NAMELEN);
|
||||
|
||||
offset += TarHeader.NAMELEN;
|
||||
|
||||
hdr.magic = TarHeader.ParseName(header, offset, TarHeader.MAGICLEN);
|
||||
|
||||
offset += TarHeader.MAGICLEN;
|
||||
|
||||
hdr.userName = TarHeader.ParseName(header, offset, TarHeader.UNAMELEN);
|
||||
|
||||
offset += TarHeader.UNAMELEN;
|
||||
|
||||
hdr.groupName = TarHeader.ParseName(header, offset, TarHeader.GNAMELEN);
|
||||
|
||||
offset += TarHeader.GNAMELEN;
|
||||
|
||||
hdr.devMajor = (int)TarHeader.ParseOctal(header, offset, TarHeader.DEVLEN);
|
||||
|
||||
offset += TarHeader.DEVLEN;
|
||||
|
||||
hdr.devMinor = (int)TarHeader.ParseOctal(header, offset, TarHeader.DEVLEN);
|
||||
this.header.WriteHeader(outbuf);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -629,22 +521,22 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </param>
|
||||
public void NameTarHeader(TarHeader hdr, string name)
|
||||
{
|
||||
bool isDir = name.EndsWith("/");
|
||||
bool isDir = name.EndsWith("/"); // -jr- this is true for BSD tar but not all others I think?
|
||||
|
||||
hdr.checkSum = 0;
|
||||
hdr.devMajor = 0;
|
||||
hdr.devMinor = 0;
|
||||
|
||||
hdr.name = new StringBuilder(name);
|
||||
hdr.mode = isDir ? 040755 : 0100644; // TODO : I think I've seen these magics before ...
|
||||
hdr.userId = 0;
|
||||
// hdr.mode = isDir ? 040755 : 0100644; // TODO : I think I've seen these magics before ...
|
||||
hdr.mode = isDir ? 1003 : 33216;
|
||||
hdr.userId = 0;
|
||||
hdr.groupId = 0;
|
||||
hdr.size = 0;
|
||||
hdr.checkSum = 0;
|
||||
|
||||
hdr.modTime = DateTime.Now;//(new java.util.Date()).getTime() / 1000;
|
||||
hdr.modTime = DateTime.UtcNow; // -jr- 24-Jan-2004 Unix times are in utc!
|
||||
// hdr.modTime = DateTime.Now; // (new java.util.Date()).getTime() / 1000;
|
||||
|
||||
hdr.linkFlag = isDir ? TarHeader.LF_DIR : TarHeader.LF_NORMAL;
|
||||
hdr.typeFlag = isDir ? TarHeader.LF_DIR : TarHeader.LF_NORMAL;
|
||||
|
||||
hdr.linkName = new StringBuilder(String.Empty);
|
||||
hdr.userName = new StringBuilder(String.Empty);
|
||||
@@ -655,6 +547,9 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* The original Java file had this header:
|
||||
*
|
||||
** Authored by Timothy Gerard Endres
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// TarHeader.cs
|
||||
//
|
||||
// Copyright (C) 2001 Mike Krueger
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
@@ -32,10 +33,41 @@
|
||||
// obligated to do so. If you do not wish to do so, delete this
|
||||
// exception statement from your version.
|
||||
|
||||
|
||||
/* The tar format and its POSIX successor PAX have a long history which makes for compatability
|
||||
issues when creating and reading files...
|
||||
|
||||
This is the ustar (Posix 1003.1) header.
|
||||
|
||||
struct header
|
||||
{
|
||||
char t_name[100]; // 0 Filename
|
||||
char t_mode[8]; // 100 Permissions
|
||||
char t_uid[8]; // 108 Numerical User ID
|
||||
char t_gid[8]; // 116 Numerical Group ID
|
||||
char t_size[12]; // 124 Filesize
|
||||
char t_mtime[12]; // 136 st_mtime
|
||||
char t_chksum[8]; // 148 Checksum
|
||||
char t_typeflag; // 156 Type of File
|
||||
char t_linkname[100]; // 157 Target of Links
|
||||
char t_magic[6]; // 257 "ustar"
|
||||
char t_version[2]; // 263 Version fixed to 00
|
||||
char t_uname[32]; // 265 User Name
|
||||
char t_gname[32]; // 297 Group Name
|
||||
char t_devmajor[8]; // 329 Major for devices
|
||||
char t_devminor[8]; // 337 Minor for devices
|
||||
char t_prefix[155]; // 345 Prefix for t_name
|
||||
// 500 End
|
||||
char t_mfill[12]; // 500 Filler up to 512
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Tar {
|
||||
namespace ICSharpCode.SharpZipLib.Tar
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -77,8 +109,13 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <summary>
|
||||
/// The length of the magic field in a header buffer.
|
||||
/// </summary>
|
||||
public readonly static int MAGICLEN = 8;
|
||||
public readonly static int MAGICLEN = 6;
|
||||
|
||||
/// <summary>
|
||||
/// The length of the version field in a header buffer.
|
||||
/// </summary>
|
||||
public readonly static int VERSIONLEN = 2;
|
||||
|
||||
/// <summary>
|
||||
/// The length of the modification time field in a header buffer.
|
||||
/// </summary>
|
||||
@@ -100,58 +137,109 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
public readonly static int DEVLEN = 8;
|
||||
|
||||
/// <summary>
|
||||
/// LF_ constants represent the "link flag" of an entry, or more commonly,
|
||||
/// the "entry type". This is the "old way" of indicating a normal file.
|
||||
/// LF_ constants represents the "type" of an entry
|
||||
/// </summary>
|
||||
public readonly static byte LF_OLDNORM = 0;
|
||||
///
|
||||
|
||||
/// <summary>
|
||||
/// This is the "old way" of indicating a normal file.
|
||||
/// </summary>
|
||||
public const byte LF_OLDNORM = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Normal file type.
|
||||
/// </summary>
|
||||
public readonly static byte LF_NORMAL = (byte) '0';
|
||||
public const byte LF_NORMAL = (byte) '0';
|
||||
|
||||
/// <summary>
|
||||
/// Link file type.
|
||||
/// </summary>
|
||||
public readonly static byte LF_LINK = (byte) '1';
|
||||
public const byte LF_LINK = (byte) '1';
|
||||
|
||||
/// <summary>
|
||||
/// Symbolic link file type.
|
||||
/// </summary>
|
||||
public readonly static byte LF_SYMLINK = (byte) '2';
|
||||
public const byte LF_SYMLINK = (byte) '2';
|
||||
|
||||
/// <summary>
|
||||
/// Character device file type.
|
||||
/// </summary>
|
||||
public readonly static byte LF_CHR = (byte) '3';
|
||||
public const byte LF_CHR = (byte) '3';
|
||||
|
||||
/// <summary>
|
||||
/// Block device file type.
|
||||
/// </summary>
|
||||
public readonly static byte LF_BLK = (byte) '4';
|
||||
public const byte LF_BLK = (byte) '4';
|
||||
|
||||
/// <summary>
|
||||
/// Directory file type.
|
||||
/// </summary>
|
||||
public readonly static byte LF_DIR = (byte) '5';
|
||||
public const byte LF_DIR = (byte) '5';
|
||||
|
||||
/// <summary>
|
||||
/// FIFO (pipe) file type.
|
||||
/// </summary>
|
||||
public readonly static byte LF_FIFO = (byte) '6';
|
||||
public const byte LF_FIFO = (byte) '6';
|
||||
|
||||
/// <summary>
|
||||
/// Contiguous file type.
|
||||
/// </summary>
|
||||
public readonly static byte LF_CONTIG = (byte) '7';
|
||||
public const byte LF_CONTIG = (byte) '7';
|
||||
|
||||
/// <summary>
|
||||
/// The magic tag representing a POSIX tar archive.
|
||||
/// Posix.1 2001 global extended header
|
||||
/// </summary>
|
||||
public readonly static string TMAGIC = "ustar";
|
||||
///
|
||||
public const byte LF_GHDR = (byte) 'g';
|
||||
|
||||
/// <summary>
|
||||
/// The magic tag representing a GNU tar archive.
|
||||
/// Posix.1 2001 extended header
|
||||
/// </summary>
|
||||
public readonly static byte LF_XHDR = (byte) 'x';
|
||||
|
||||
|
||||
|
||||
|
||||
// POSIX allows for upper case ascii type as extensions
|
||||
|
||||
// Solaris access control list
|
||||
public const byte LF_ACL = (byte) 'A';
|
||||
|
||||
// This is a dir entry that contains the names of files that were in the
|
||||
// dir at the time the dump was made
|
||||
public const byte LF_GNU_DUMPDIR = (byte) 'D';
|
||||
|
||||
// Solaris Extended Attribute File
|
||||
public const byte LF_EXTATTR = (byte) 'E' ;
|
||||
|
||||
// Inode (metadata only) no file content
|
||||
public const byte LF_META = (byte) 'I';
|
||||
|
||||
// Identifies the next file on the tape as having a long link name
|
||||
public const byte LF_GNU_LONGLINK = (byte) 'K';
|
||||
|
||||
// Identifies the next file on the tape as having a long name
|
||||
public const byte LF_GNU_LONGNAME = (byte) 'L';
|
||||
|
||||
// Continuation of a file that began on another volume
|
||||
public const byte LF_GNU_MULTIVOL = (byte) 'M';
|
||||
|
||||
// For storing filenames that dont fit in the main header (old GNU)
|
||||
public const byte LF_GNU_NAMES = (byte) 'N';
|
||||
|
||||
// Sparse file
|
||||
public const byte LF_GNU_SPARSE = (byte) 'S';
|
||||
|
||||
// Tape/volume header ignore on extraction
|
||||
public const byte LF_GNU_VOLHDR = (byte) 'V';
|
||||
|
||||
/// <summary>
|
||||
/// The magic tag representing a POSIX tar archive. (includes trailing NULL)
|
||||
/// </summary>
|
||||
public readonly static string TMAGIC = "ustar ";
|
||||
|
||||
/// <summary>
|
||||
/// The magic tag representing an old GNU tar archive where version is included in magic and overwrites it
|
||||
/// </summary>
|
||||
public readonly static string GNU_TMAGIC = "ustar ";
|
||||
|
||||
@@ -191,9 +279,9 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
public int checkSum;
|
||||
|
||||
/// <summary>
|
||||
/// The entry's link flag.
|
||||
/// The entry's type flag.
|
||||
/// </summary>
|
||||
public byte linkFlag;
|
||||
public byte typeFlag;
|
||||
|
||||
/// <summary>
|
||||
/// The entry's link name.
|
||||
@@ -205,6 +293,11 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </summary>
|
||||
public StringBuilder magic;
|
||||
|
||||
/// <summary>
|
||||
/// The entry's version.
|
||||
/// </summary>
|
||||
public StringBuilder version;
|
||||
|
||||
/// <summary>
|
||||
/// The entry's user name.
|
||||
/// </summary>
|
||||
@@ -228,20 +321,27 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
public TarHeader()
|
||||
{
|
||||
this.magic = new StringBuilder(TarHeader.TMAGIC);
|
||||
this.version = new StringBuilder(" ");
|
||||
|
||||
this.name = new StringBuilder();
|
||||
this.linkName = new StringBuilder();
|
||||
|
||||
string user = Environment.UserName;
|
||||
// string user = "PocketPC";
|
||||
// string user = "Everyone";
|
||||
|
||||
if (user.Length > 31) {
|
||||
user = user.Substring(0, 31);
|
||||
}
|
||||
|
||||
this.userId = 0;
|
||||
this.groupId = 0;
|
||||
this.userId = 1003; // -jr- was 0
|
||||
this.groupId = 513; // -jr- was 0
|
||||
this.userName = new StringBuilder(user);
|
||||
this.groupName = new StringBuilder(String.Empty);
|
||||
// -jr-
|
||||
// this.groupName = new StringBuilder(String.Empty);
|
||||
// this.groupName = new StringBuilder("Everyone"); Attempt2
|
||||
this.groupName = new StringBuilder("None"); // Gnu compatible
|
||||
this.size = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -258,9 +358,10 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
hdr.size = this.size;
|
||||
hdr.modTime = this.modTime;
|
||||
hdr.checkSum = this.checkSum;
|
||||
hdr.linkFlag = this.linkFlag;
|
||||
hdr.typeFlag = this.typeFlag;
|
||||
hdr.linkName = (this.linkName == null) ? null : new StringBuilder(this.linkName.ToString());
|
||||
hdr.magic = (this.magic == null) ? null : new StringBuilder(this.magic.ToString());
|
||||
hdr.version = (this.version == null) ? null : new StringBuilder(this.version.ToString());
|
||||
hdr.userName = (this.userName == null) ? null : new StringBuilder(this.userName.ToString());
|
||||
hdr.groupName = (this.groupName == null) ? null : new StringBuilder(this.groupName.ToString());
|
||||
hdr.devMajor = this.devMajor;
|
||||
@@ -302,17 +403,22 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
bool stillPadding = true;
|
||||
|
||||
int end = offset + length;
|
||||
for (int i = offset; i < end ; ++i) {
|
||||
if (header[i] == 0) {
|
||||
for (int i = offset; i < end ; ++i)
|
||||
{
|
||||
if (header[i] == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (header[i] == (byte)' ' || header[i] == '0') {
|
||||
if (stillPadding) {
|
||||
if (header[i] == (byte)' ' || header[i] == '0')
|
||||
{
|
||||
if (stillPadding)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (header[i] == (byte)' ') {
|
||||
if (header[i] == (byte)' ')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -344,8 +450,10 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
{
|
||||
StringBuilder result = new StringBuilder(length);
|
||||
|
||||
for (int i = offset; i < offset + length; ++i) {
|
||||
if (header[i] == 0) {
|
||||
for (int i = offset; i < offset + length; ++i)
|
||||
{
|
||||
if (header[i] == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
result.Append((char)header[i]);
|
||||
@@ -354,7 +462,24 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
public static int GetNameBytes(StringBuilder name, int nameOffset, byte[] buf, int bufferOffset, int length)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0 ; i < length && nameOffset + i < name.Length; ++i)
|
||||
{
|
||||
buf[bufferOffset + i] = (byte)name[nameOffset + i];
|
||||
}
|
||||
|
||||
for (; i < length ; ++i)
|
||||
{
|
||||
buf[bufferOffset + i] = 0;
|
||||
}
|
||||
|
||||
return bufferOffset + length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine the number of bytes in an entry name.
|
||||
/// </summary>
|
||||
/// <param name="name">
|
||||
@@ -373,17 +498,7 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </returns>
|
||||
public static int GetNameBytes(StringBuilder name, byte[] buf, int offset, int length)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0 ; i < length && i < name.Length; ++i) {
|
||||
buf[offset + i] = (byte)name[i];
|
||||
}
|
||||
|
||||
for (; i < length ; ++i) {
|
||||
buf[offset + i] = 0;
|
||||
}
|
||||
|
||||
return offset + length;
|
||||
return GetNameBytes(name, 0, buf, offset, length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -405,27 +520,26 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </returns>
|
||||
public static int GetOctalBytes(long val, byte[] buf, int offset, int length)
|
||||
{
|
||||
byte[] result = new byte[length];
|
||||
|
||||
// TODO check for values too large...
|
||||
|
||||
int idx = length - 1;
|
||||
|
||||
|
||||
// Either a space or null is valid here. We use NULL as per GNUTar
|
||||
buf[offset + idx] = 0;
|
||||
--idx;
|
||||
buf[offset + idx] = (byte)' ';
|
||||
--idx;
|
||||
|
||||
if (val == 0) {
|
||||
buf[offset + idx] = (byte)'0';
|
||||
--idx;
|
||||
} else {
|
||||
for (long v = val; idx >= 0 && v > 0; --idx) {
|
||||
|
||||
if (val > 0)
|
||||
{
|
||||
for (long v = val; idx >= 0 && v > 0; --idx)
|
||||
{
|
||||
buf[offset + idx] = (byte)((byte)'0' + (byte)(v & 7));
|
||||
v >>= 3;
|
||||
}
|
||||
}
|
||||
|
||||
for (; idx >= 0; --idx) {
|
||||
buf[offset + idx] = (byte)' ';
|
||||
for (; idx >= 0; --idx)
|
||||
{
|
||||
buf[offset + idx] = (byte)'0';
|
||||
}
|
||||
|
||||
return offset + length;
|
||||
@@ -450,37 +564,176 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </returns>
|
||||
public static int GetLongOctalBytes(long val, byte[] buf, int offset, int length)
|
||||
{
|
||||
byte[] temp = new byte[length + 1];
|
||||
TarHeader.GetOctalBytes(val, temp, 0, length + 1);
|
||||
Array.Copy(temp, 0, buf, offset, length);
|
||||
return offset + length;
|
||||
return GetOctalBytes(val, buf, offset, length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse the checksum octal integer from a header buffer.
|
||||
/// Add the checksum octal integer to header buffer.
|
||||
/// </summary>
|
||||
/// <param name = "val">
|
||||
/// </param>
|
||||
/// <param name = "buf">
|
||||
/// The header buffer from which to parse.
|
||||
/// The header buffer to set the checksum for
|
||||
/// </param>
|
||||
/// <param name = "offset">
|
||||
/// The offset into the buffer from which to parse.
|
||||
/// The offset into the buffer for the checksum
|
||||
/// </param>
|
||||
/// <param name = "length">
|
||||
/// The number of header bytes to parse.
|
||||
/// The number of header bytes to update.
|
||||
/// It's formatted differently from the other fields: it has 6 digits, a
|
||||
/// null, then a space -- rather than digits, a space, then a null.
|
||||
/// The final space is already there, from checksumming
|
||||
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The integer value of the entry's checksum.
|
||||
/// The modified buffer offset
|
||||
/// </returns>
|
||||
public static int GetCheckSumOctalBytes(long val, byte[] buf, int offset, int length)
|
||||
private static int GetCheckSumOctalBytes(long val, byte[] buf, int offset, int length)
|
||||
{
|
||||
TarHeader.GetOctalBytes(val, buf, offset, length);
|
||||
buf[offset + length - 1] = (byte)' ';
|
||||
buf[offset + length - 2] = 0;
|
||||
TarHeader.GetOctalBytes(val, buf, offset, length - 1);
|
||||
// buf[offset + length - 1] = (byte)' '; -jr- 23-Jan-2004 this causes failure!!!
|
||||
// buf[offset + length - 2] = 0;
|
||||
return offset + length;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compute the checksum for a tar entry header.
|
||||
/// The checksum field must be all spaces prior to this happening
|
||||
/// </summary>
|
||||
/// <param name = "buf">
|
||||
/// The tar entry's header buffer.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The computed checksum.
|
||||
/// </returns>
|
||||
private static long ComputeCheckSum(byte[] buf)
|
||||
{
|
||||
long sum = 0;
|
||||
for (int i = 0; i < buf.Length; ++i)
|
||||
{
|
||||
sum += buf[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
readonly static long timeConversionFactor = 10000000L; // -jr- 1 tick == 100 nanoseconds
|
||||
readonly static DateTime datetTime1970 = new DateTime(1970, 1, 1, 0, 0, 0, 0);
|
||||
// readonly static DateTime datetTime1970 = new DateTime(1970, 1, 1, 0, 0, 0, 0).ToUniversalTime(); // -jr- Should be UTC? doesnt match Gnutar if this is so though, why?
|
||||
|
||||
static int GetCTime(System.DateTime dateTime)
|
||||
{
|
||||
return (int)((dateTime.Ticks - datetTime1970.Ticks) / timeConversionFactor);
|
||||
}
|
||||
|
||||
static DateTime GetDateTimeFromCTime(long ticks)
|
||||
{
|
||||
return new DateTime(datetTime1970.Ticks + ticks * timeConversionFactor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse TarHeader information from a header buffer.
|
||||
/// </summary>
|
||||
/// <param name = "header">
|
||||
/// The tar entry header buffer to get information from.
|
||||
/// </param>
|
||||
public void ParseBuffer(byte[] header)
|
||||
{
|
||||
int offset = 0;
|
||||
|
||||
name = TarHeader.ParseName(header, offset, TarHeader.NAMELEN);
|
||||
offset += TarHeader.NAMELEN;
|
||||
|
||||
mode = (int)TarHeader.ParseOctal(header, offset, TarHeader.MODELEN);
|
||||
offset += TarHeader.MODELEN;
|
||||
|
||||
userId = (int)TarHeader.ParseOctal(header, offset, TarHeader.UIDLEN);
|
||||
offset += TarHeader.UIDLEN;
|
||||
|
||||
groupId = (int)TarHeader.ParseOctal(header, offset, TarHeader.GIDLEN);
|
||||
offset += TarHeader.GIDLEN;
|
||||
|
||||
size = TarHeader.ParseOctal(header, offset, TarHeader.SIZELEN);
|
||||
offset += TarHeader.SIZELEN;
|
||||
|
||||
modTime = GetDateTimeFromCTime(TarHeader.ParseOctal(header, offset, TarHeader.MODTIMELEN));
|
||||
offset += TarHeader.MODTIMELEN;
|
||||
|
||||
checkSum = (int)TarHeader.ParseOctal(header, offset, TarHeader.CHKSUMLEN);
|
||||
offset += TarHeader.CHKSUMLEN;
|
||||
|
||||
typeFlag = header[ offset++ ];
|
||||
|
||||
linkName = TarHeader.ParseName(header, offset, TarHeader.NAMELEN);
|
||||
offset += TarHeader.NAMELEN;
|
||||
|
||||
magic = TarHeader.ParseName(header, offset, TarHeader.MAGICLEN);
|
||||
offset += TarHeader.MAGICLEN;
|
||||
|
||||
version = TarHeader.ParseName(header, offset, TarHeader.VERSIONLEN);
|
||||
offset += TarHeader.VERSIONLEN;
|
||||
|
||||
userName = TarHeader.ParseName(header, offset, TarHeader.UNAMELEN);
|
||||
offset += TarHeader.UNAMELEN;
|
||||
|
||||
groupName = TarHeader.ParseName(header, offset, TarHeader.GNAMELEN);
|
||||
offset += TarHeader.GNAMELEN;
|
||||
|
||||
devMajor = (int)TarHeader.ParseOctal(header, offset, TarHeader.DEVLEN);
|
||||
offset += TarHeader.DEVLEN;
|
||||
|
||||
devMinor = (int)TarHeader.ParseOctal(header, offset, TarHeader.DEVLEN);
|
||||
|
||||
// Fields past this point not currently parsed or used...
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 'Write' header information to buffer provided
|
||||
/// </summary>
|
||||
/// <param name="outbuf">output buffer for header information</param>
|
||||
public void WriteHeader(byte[] outbuf)
|
||||
{
|
||||
int offset = 0;
|
||||
|
||||
offset = GetNameBytes(this.name, outbuf, offset, TarHeader.NAMELEN);
|
||||
offset = GetOctalBytes(this.mode, outbuf, offset, TarHeader.MODELEN);
|
||||
offset = GetOctalBytes(this.userId, outbuf, offset, TarHeader.UIDLEN);
|
||||
offset = GetOctalBytes(this.groupId, outbuf, offset, TarHeader.GIDLEN);
|
||||
|
||||
long size = this.size;
|
||||
|
||||
offset = GetLongOctalBytes(size, outbuf, offset, TarHeader.SIZELEN);
|
||||
offset = GetLongOctalBytes(GetCTime(this.modTime), outbuf, offset, TarHeader.MODTIMELEN);
|
||||
|
||||
int csOffset = offset;
|
||||
for (int c = 0; c < TarHeader.CHKSUMLEN; ++c)
|
||||
{
|
||||
outbuf[offset++] = (byte)' ';
|
||||
}
|
||||
|
||||
outbuf[offset++] = this.typeFlag;
|
||||
|
||||
offset = GetNameBytes(this.linkName, outbuf, offset, NAMELEN);
|
||||
offset = GetNameBytes(this.magic, outbuf, offset, MAGICLEN);
|
||||
offset = GetNameBytes(this.version, outbuf, offset, VERSIONLEN);
|
||||
offset = GetNameBytes(this.userName, outbuf, offset, UNAMELEN);
|
||||
offset = GetNameBytes(this.groupName, outbuf, offset, GNAMELEN);
|
||||
|
||||
if (this.typeFlag == LF_CHR || this.typeFlag == LF_BLK)
|
||||
{
|
||||
offset = GetOctalBytes(this.devMajor, outbuf, offset, DEVLEN);
|
||||
offset = GetOctalBytes(this.devMinor, outbuf, offset, DEVLEN);
|
||||
}
|
||||
|
||||
for ( ; offset < outbuf.Length; )
|
||||
{
|
||||
outbuf[offset++] = 0;
|
||||
}
|
||||
|
||||
long checkSum = ComputeCheckSum(outbuf);
|
||||
|
||||
GetCheckSumOctalBytes(checkSum, outbuf, csOffset, CHKSUMLEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* The original Java file had this header:
|
||||
|
||||
@@ -36,7 +36,8 @@ using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Tar {
|
||||
namespace ICSharpCode.SharpZipLib.Tar
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The TarInputStream reads a UNIX tar archive as an InputStream.
|
||||
@@ -59,11 +60,14 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
protected IEntryFactory eFactory;
|
||||
|
||||
Stream inputStream;
|
||||
|
||||
/// <summary>
|
||||
/// I needed to implement the abstract member.
|
||||
/// </summary>
|
||||
public override bool CanRead {
|
||||
get {
|
||||
public override bool CanRead
|
||||
{
|
||||
get
|
||||
{
|
||||
return inputStream.CanRead;
|
||||
}
|
||||
}
|
||||
@@ -71,8 +75,11 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <summary>
|
||||
/// I needed to implement the abstract member.
|
||||
/// </summary>
|
||||
public override bool CanSeek {
|
||||
get {
|
||||
public override bool CanSeek
|
||||
{
|
||||
// TODO is this valid? should it return false?
|
||||
get
|
||||
{
|
||||
return inputStream.CanSeek;
|
||||
}
|
||||
}
|
||||
@@ -80,8 +87,10 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <summary>
|
||||
/// I needed to implement the abstract member.
|
||||
/// </summary>
|
||||
public override bool CanWrite {
|
||||
get {
|
||||
public override bool CanWrite
|
||||
{
|
||||
get
|
||||
{
|
||||
return inputStream.CanWrite;
|
||||
}
|
||||
}
|
||||
@@ -89,8 +98,10 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <summary>
|
||||
/// I needed to implement the abstract member.
|
||||
/// </summary>
|
||||
public override long Length {
|
||||
get {
|
||||
public override long Length
|
||||
{
|
||||
get
|
||||
{
|
||||
return inputStream.Length;
|
||||
}
|
||||
}
|
||||
@@ -98,11 +109,14 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <summary>
|
||||
/// I needed to implement the abstract member.
|
||||
/// </summary>
|
||||
public override long Position {
|
||||
get {
|
||||
public override long Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return inputStream.Position;
|
||||
}
|
||||
set {
|
||||
set
|
||||
{
|
||||
inputStream.Position = value;
|
||||
}
|
||||
}
|
||||
@@ -120,6 +134,7 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </summary>
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
// TODO allow this?
|
||||
return inputStream.Seek(offset, origin);
|
||||
}
|
||||
|
||||
@@ -148,30 +163,27 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
}
|
||||
|
||||
|
||||
public TarInputStream(Stream inputStream) : this(inputStream, TarBuffer.DEFAULT_BLKSIZE, TarBuffer.DEFAULT_RCDSIZE)
|
||||
public TarInputStream(Stream inputStream) : this(inputStream, TarBuffer.DefaultBlockFactor)
|
||||
{
|
||||
}
|
||||
|
||||
public TarInputStream(Stream inputStream, int blockSize) : this(inputStream, blockSize, TarBuffer.DEFAULT_RCDSIZE)
|
||||
{
|
||||
}
|
||||
|
||||
public TarInputStream(Stream inputStream, int blockSize, int recordSize)
|
||||
public TarInputStream(Stream inputStream, int blockFactor)
|
||||
{
|
||||
this.inputStream = inputStream;
|
||||
this.buffer = TarBuffer.CreateInputTarBuffer(inputStream, blockSize, recordSize);
|
||||
this.buffer = TarBuffer.CreateInputTarBuffer(inputStream, blockFactor);
|
||||
|
||||
this.readBuf = null;
|
||||
this.readBuf = null;
|
||||
this.debug = false;
|
||||
this.hasHitEOF = false;
|
||||
this.eFactory = null;
|
||||
}
|
||||
|
||||
public void SetDebug(bool debugF)
|
||||
public void SetDebug(bool debugFlag)
|
||||
{
|
||||
this.debug = debugF;
|
||||
SetBufferDebug(debugF);
|
||||
this.debug = debugFlag;
|
||||
SetBufferDebug(debugFlag);
|
||||
}
|
||||
|
||||
public void SetBufferDebug(bool debug)
|
||||
{
|
||||
this.buffer.SetDebug(debug);
|
||||
@@ -214,8 +226,10 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <returns>
|
||||
/// The number of available bytes for the current entry.
|
||||
/// </returns>
|
||||
public int Available {
|
||||
get {
|
||||
public int Available
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.entrySize - this.entryOffset;
|
||||
}
|
||||
}
|
||||
@@ -231,16 +245,18 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </param>
|
||||
public void Skip(int numToSkip)
|
||||
{
|
||||
// REVIEW
|
||||
// TODO REVIEW
|
||||
// This is horribly inefficient, but it ensures that we
|
||||
// properly skip over bytes via the TarBuffer...
|
||||
//
|
||||
byte[] skipBuf = new byte[8 * 1024];
|
||||
|
||||
for (int num = numToSkip; num > 0;){
|
||||
for (int num = numToSkip; num > 0;)
|
||||
{
|
||||
int numRead = this.Read(skipBuf, 0, (num > skipBuf.Length ? skipBuf.Length : num));
|
||||
|
||||
if (numRead == -1) {
|
||||
if (numRead == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -251,8 +267,10 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <summary>
|
||||
/// Since we do not support marking just yet, we return false.
|
||||
/// </summary>
|
||||
public bool IsMarkSupported {
|
||||
get {
|
||||
public bool IsMarkSupported
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -273,7 +291,24 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
public void Reset()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SkipToNextEntry()
|
||||
{
|
||||
int numToSkip = this.entrySize - this.entryOffset;
|
||||
|
||||
if (this.debug)
|
||||
{
|
||||
//Console.WriteLine.WriteLine("TarInputStream: SKIP currENTRY '" + this.currEntry.Name + "' SZ " + this.entrySize + " OFF " + this.entryOffset + " skipping " + numToSkip + " bytes");
|
||||
}
|
||||
|
||||
if (numToSkip > 0)
|
||||
{
|
||||
this.Skip(numToSkip);
|
||||
}
|
||||
|
||||
this.readBuf = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the next entry in this tar archive. This will skip
|
||||
/// over any remaining data in the current entry, if there
|
||||
@@ -289,68 +324,144 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </returns>
|
||||
public TarEntry GetNextEntry()
|
||||
{
|
||||
if (this.hasHitEOF) {
|
||||
if (this.hasHitEOF)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.currEntry != null) {
|
||||
int numToSkip = this.entrySize - this.entryOffset;
|
||||
|
||||
if (this.debug) {
|
||||
Console.Error.WriteLine("TarInputStream: SKIP currENTRY '" + this.currEntry.Name + "' SZ " + this.entrySize + " OFF " + this.entryOffset + " skipping " + numToSkip + " bytes");
|
||||
}
|
||||
|
||||
if (numToSkip > 0) {
|
||||
this.Skip(numToSkip);
|
||||
}
|
||||
|
||||
this.readBuf = null;
|
||||
if (this.currEntry != null)
|
||||
{
|
||||
SkipToNextEntry();
|
||||
}
|
||||
|
||||
byte[] headerBuf = this.buffer.ReadRecord();
|
||||
byte[] headerBuf = this.buffer.ReadBlock();
|
||||
|
||||
if (headerBuf == null) {
|
||||
if (this.debug) {
|
||||
Console.Error.WriteLine("READ NULL RECORD");
|
||||
if (headerBuf == null)
|
||||
{
|
||||
if (this.debug)
|
||||
{
|
||||
//Console.WriteLine.WriteLine("READ NULL BLOCK");
|
||||
}
|
||||
|
||||
this.hasHitEOF = true;
|
||||
} else if (this.buffer.IsEOFRecord(headerBuf)) {
|
||||
if (this.debug) {
|
||||
Console.Error.WriteLine( "READ EOF RECORD" );
|
||||
}
|
||||
else if (this.buffer.IsEOFBlock(headerBuf))
|
||||
{
|
||||
if (this.debug)
|
||||
{
|
||||
//Console.WriteLine.WriteLine( "READ EOF BLOCK" );
|
||||
}
|
||||
|
||||
this.hasHitEOF = true;
|
||||
}
|
||||
|
||||
if (this.hasHitEOF) {
|
||||
if (this.hasHitEOF)
|
||||
{
|
||||
this.currEntry = null;
|
||||
} else {
|
||||
try {
|
||||
if (this.eFactory == null) {
|
||||
this.currEntry = new TarEntry(headerBuf);
|
||||
} else {
|
||||
this.currEntry = this.eFactory.CreateEntry(headerBuf);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
TarHeader header = new TarHeader();
|
||||
header.ParseBuffer(headerBuf);
|
||||
this.entryOffset = 0;
|
||||
this.entrySize = (int)header.size;
|
||||
|
||||
StringBuilder longName = null;
|
||||
|
||||
if (header.typeFlag == TarHeader.LF_GNU_LONGNAME)
|
||||
{
|
||||
Console.WriteLine("TarInputStream: Long name found '" + header.name + "' size = " + header.size); // DEBUG
|
||||
|
||||
byte[] nameBuffer = new byte[TarBuffer.BlockSize];
|
||||
|
||||
int numToRead = this.entrySize;
|
||||
|
||||
longName = new StringBuilder();
|
||||
|
||||
while (numToRead > 0)
|
||||
{
|
||||
int numRead = this.Read(nameBuffer, 0, (numToRead > nameBuffer.Length ? nameBuffer.Length : numToRead));
|
||||
|
||||
if (numRead == -1)
|
||||
{
|
||||
throw new InvalidHeaderException("Failed to read long name entry");
|
||||
}
|
||||
|
||||
longName.Append(TarHeader.ParseName(nameBuffer, 0, numRead).ToString());
|
||||
numToRead -= numRead;
|
||||
}
|
||||
|
||||
Console.WriteLine("TarInputStream: Long name is '" + longName.ToString()); // DEBUG
|
||||
|
||||
SkipToNextEntry();
|
||||
headerBuf = this.buffer.ReadBlock();
|
||||
}
|
||||
else if (header.typeFlag == TarHeader.LF_GHDR) // POSIX global extended header
|
||||
{
|
||||
// Ignore things we dont understand completely for now
|
||||
SkipToNextEntry();
|
||||
headerBuf = this.buffer.ReadBlock();
|
||||
}
|
||||
else if (header.typeFlag == TarHeader.LF_XHDR) // POSIX extended header
|
||||
{
|
||||
// Ignore things we dont understand completely for now
|
||||
SkipToNextEntry();
|
||||
headerBuf = this.buffer.ReadBlock();
|
||||
}
|
||||
else if (header.typeFlag == TarHeader.LF_GNU_VOLHDR)
|
||||
{
|
||||
// TODO could show volume name when verbose?
|
||||
SkipToNextEntry();
|
||||
headerBuf = this.buffer.ReadBlock();
|
||||
}
|
||||
else if (header.typeFlag != TarHeader.LF_NORMAL
|
||||
&& header.typeFlag != TarHeader.LF_OLDNORM)
|
||||
{
|
||||
// Ignore things we dont understand completely for now
|
||||
SkipToNextEntry();
|
||||
headerBuf = this.buffer.ReadBlock();
|
||||
}
|
||||
|
||||
if (this.eFactory == null)
|
||||
{
|
||||
this.currEntry = new TarEntry(headerBuf);
|
||||
if (longName != null)
|
||||
{
|
||||
this.currEntry.TarHeader.name.Length = 0;
|
||||
this.currEntry.TarHeader.name.Append(longName.ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.currEntry = this.eFactory.CreateEntry(headerBuf);
|
||||
}
|
||||
|
||||
if (!(headerBuf[257] == 'u' && headerBuf[258] == 's' && headerBuf[259] == 't' && headerBuf[260] == 'a' && headerBuf[261] == 'r')) {
|
||||
|
||||
// TODO -jr- ustar is not the only magic possible by any means
|
||||
// tar, xtar, ...
|
||||
if (!(headerBuf[257] == 'u' && headerBuf[258] == 's' && headerBuf[259] == 't' && headerBuf[260] == 'a' && headerBuf[261] == 'r'))
|
||||
{
|
||||
throw new InvalidHeaderException("header magic is not 'ustar', but '" + headerBuf[257] + headerBuf[258] + headerBuf[259] + headerBuf[260] + headerBuf[261] +
|
||||
"', or (dec) " + ((int)headerBuf[257]) + ", " + ((int)headerBuf[258]) + ", " + ((int)headerBuf[259]) + ", " + ((int)headerBuf[260]) + ", " + ((int)headerBuf[261]));
|
||||
"', or (dec) " + ((int)headerBuf[257]) + ", " + ((int)headerBuf[258]) + ", " + ((int)headerBuf[259]) + ", " + ((int)headerBuf[260]) + ", " + ((int)headerBuf[261]));
|
||||
}
|
||||
|
||||
if (this.debug) {
|
||||
Console.Error.WriteLine("TarInputStream: SET CURRENTRY '" + this.currEntry.Name + "' size = " + this.currEntry.Size);
|
||||
if (this.debug)
|
||||
{
|
||||
//Console.WriteLine.WriteLine("TarInputStream: SET CURRENTRY '" + this.currEntry.Name + "' size = " + this.currEntry.Size);
|
||||
}
|
||||
|
||||
this.entryOffset = 0;
|
||||
|
||||
// REVIEW How do we resolve this discrepancy?!
|
||||
// TODO REVIEW How do we resolve this discrepancy?!
|
||||
this.entrySize = (int) this.currEntry.Size;
|
||||
} catch (InvalidHeaderException ex) {
|
||||
}
|
||||
catch (InvalidHeaderException ex)
|
||||
{
|
||||
this.entrySize = 0;
|
||||
this.entryOffset = 0;
|
||||
this.currEntry = null;
|
||||
throw new InvalidHeaderException("bad header in block " + this.buffer.GetCurrentBlockNum() + " record " + this.buffer.GetCurrentRecordNum() + ", " + ex.Message);
|
||||
throw new InvalidHeaderException("bad header in record " + this.buffer.GetCurrentBlockNum() + " block " + this.buffer.GetCurrentBlockNum() + ", " + ex.Message);
|
||||
}
|
||||
}
|
||||
return this.currEntry;
|
||||
@@ -364,7 +475,8 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
{
|
||||
byte[] oneByteBuffer = new byte[1];
|
||||
int num = this.Read(oneByteBuffer, 0, 1);
|
||||
if (num <= 0) { // return -1 to indicate that no byte was read.
|
||||
if (num <= 0) // return -1 to indicate that no byte was read.
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return (int)oneByteBuffer[0];
|
||||
@@ -374,10 +486,9 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// Reads bytes from the current tar archive entry.
|
||||
///
|
||||
/// This method is aware of the boundaries of the current
|
||||
/// entry in the archive and will deal with them as if they
|
||||
/// entry in the archive and will deal with them as if they
|
||||
/// entry in the archive and will deal with them appropriately
|
||||
/// </summary>
|
||||
/// <param name="buf">
|
||||
/// <param name="outputBuffer">
|
||||
/// The buffer into which to place bytes read.
|
||||
/// </param>
|
||||
/// <param name="offset">
|
||||
@@ -387,30 +498,36 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// The number of bytes to read.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The number of bytes read, or -1 at EOF.
|
||||
/// The number of bytes read, or 0 at end of stream/EOF.
|
||||
/// </returns>
|
||||
public override int Read(byte[] buf, int offset, int numToRead)
|
||||
public override int Read(byte[] outputBuffer, int offset, int numToRead)
|
||||
{
|
||||
int totalRead = 0;
|
||||
|
||||
if (this.entryOffset >= this.entrySize) {
|
||||
return -1;
|
||||
if (this.entryOffset >= this.entrySize)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((numToRead + this.entryOffset) > this.entrySize) {
|
||||
if ((numToRead + this.entryOffset) > this.entrySize)
|
||||
{
|
||||
numToRead = this.entrySize - this.entryOffset;
|
||||
}
|
||||
|
||||
if (this.readBuf != null) {
|
||||
if (this.readBuf != null)
|
||||
{
|
||||
int sz = (numToRead > this.readBuf.Length) ? this.readBuf.Length : numToRead;
|
||||
|
||||
Array.Copy(this.readBuf, 0, buf, offset, sz);
|
||||
Array.Copy(this.readBuf, 0, outputBuffer, offset, sz);
|
||||
|
||||
if (sz >= this.readBuf.Length) {
|
||||
if (sz >= this.readBuf.Length)
|
||||
{
|
||||
this.readBuf = null;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
int newLen = this.readBuf.Length - sz;
|
||||
byte[] newBuf = new byte[ newLen ];
|
||||
byte[] newBuf = new byte[newLen];
|
||||
Array.Copy(this.readBuf, sz, newBuf, 0, newLen);
|
||||
this.readBuf = newBuf;
|
||||
}
|
||||
@@ -420,9 +537,11 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
offset += sz;
|
||||
}
|
||||
|
||||
while (numToRead > 0) {
|
||||
byte[] rec = this.buffer.ReadRecord();
|
||||
if (rec == null) {
|
||||
while (numToRead > 0)
|
||||
{
|
||||
byte[] rec = this.buffer.ReadBlock();
|
||||
if (rec == null)
|
||||
{
|
||||
// Unexpected EOF!
|
||||
throw new IOException("unexpected EOF with " + numToRead + " bytes unread");
|
||||
}
|
||||
@@ -430,13 +549,16 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
int sz = numToRead;
|
||||
int recLen = rec.Length;
|
||||
|
||||
if (recLen > sz) {
|
||||
Array.Copy(rec, 0, buf, offset, sz);
|
||||
if (recLen > sz)
|
||||
{
|
||||
Array.Copy(rec, 0, outputBuffer, offset, sz);
|
||||
this.readBuf = new byte[recLen - sz];
|
||||
Array.Copy(rec, sz, this.readBuf, 0, recLen - sz);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
sz = recLen;
|
||||
Array.Copy(rec, 0, buf, offset, recLen);
|
||||
Array.Copy(rec, 0, outputBuffer, offset, recLen);
|
||||
}
|
||||
|
||||
totalRead += sz;
|
||||
@@ -460,9 +582,11 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
{
|
||||
byte[] buf = new byte[32 * 1024];
|
||||
|
||||
while (true) {
|
||||
while (true)
|
||||
{
|
||||
int numRead = this.Read(buf, 0, buf.Length);
|
||||
if (numRead <= 0) {
|
||||
if (numRead <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
outputStream.Write(buf, 0, numRead);
|
||||
|
||||
@@ -36,7 +36,8 @@ using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Tar {
|
||||
namespace ICSharpCode.SharpZipLib.Tar
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The TarOutputStream writes a UNIX tar archive as an OutputStream.
|
||||
@@ -49,7 +50,7 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
protected bool debug;
|
||||
protected int currSize;
|
||||
protected int currBytes;
|
||||
protected byte[] recordBuf;
|
||||
protected byte[] blockBuf;
|
||||
protected int assemLen;
|
||||
protected byte[] assemBuf;
|
||||
|
||||
@@ -59,8 +60,10 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <summary>
|
||||
/// I needed to implement the abstract member.
|
||||
/// </summary>
|
||||
public override bool CanRead {
|
||||
get {
|
||||
public override bool CanRead
|
||||
{
|
||||
get
|
||||
{
|
||||
return outputStream.CanRead;
|
||||
}
|
||||
}
|
||||
@@ -68,17 +71,21 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <summary>
|
||||
/// I needed to implement the abstract member.
|
||||
/// </summary>
|
||||
public override bool CanSeek {
|
||||
get {
|
||||
return outputStream.CanSeek;
|
||||
public override bool CanSeek
|
||||
{
|
||||
get
|
||||
{
|
||||
return outputStream.CanSeek; // -jr- Should be false?
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// I needed to implement the abstract member.
|
||||
/// </summary>
|
||||
public override bool CanWrite {
|
||||
get {
|
||||
public override bool CanWrite
|
||||
{
|
||||
get
|
||||
{
|
||||
return outputStream.CanWrite;
|
||||
}
|
||||
}
|
||||
@@ -86,8 +93,10 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <summary>
|
||||
/// I needed to implement the abstract member.
|
||||
/// </summary>
|
||||
public override long Length {
|
||||
get {
|
||||
public override long Length
|
||||
{
|
||||
get
|
||||
{
|
||||
return outputStream.Length;
|
||||
}
|
||||
}
|
||||
@@ -95,11 +104,14 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// <summary>
|
||||
/// I needed to implement the abstract member.
|
||||
/// </summary>
|
||||
public override long Position {
|
||||
get {
|
||||
public override long Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return outputStream.Position;
|
||||
}
|
||||
set {
|
||||
set
|
||||
{
|
||||
outputStream.Position = value;
|
||||
}
|
||||
}
|
||||
@@ -141,35 +153,31 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
outputStream.Flush();
|
||||
}
|
||||
|
||||
public TarOutputStream(Stream outputStream) : this(outputStream, TarBuffer.DEFAULT_BLKSIZE, TarBuffer.DEFAULT_RCDSIZE)
|
||||
public TarOutputStream(Stream outputStream) : this(outputStream, TarBuffer.DefaultBlockFactor)
|
||||
{
|
||||
}
|
||||
|
||||
public TarOutputStream(Stream outputStream, int blockSize) : this(outputStream, blockSize, TarBuffer.DEFAULT_RCDSIZE)
|
||||
{
|
||||
}
|
||||
|
||||
public TarOutputStream(Stream outputStream, int blockSize, int recordSize)
|
||||
public TarOutputStream(Stream outputStream, int blockFactor)
|
||||
{
|
||||
this.outputStream = outputStream;
|
||||
this.buffer = TarBuffer.CreateOutputTarBuffer(outputStream, blockSize, recordSize);
|
||||
this.buffer = TarBuffer.CreateOutputTarBuffer(outputStream, blockFactor);
|
||||
|
||||
this.debug = false;
|
||||
this.assemLen = 0;
|
||||
this.assemBuf = new byte[recordSize];
|
||||
this.recordBuf = new byte[recordSize];
|
||||
this.assemBuf = new byte[TarBuffer.BlockSize];
|
||||
this.blockBuf = new byte[TarBuffer.BlockSize];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the debugging flag.
|
||||
/// </summary>
|
||||
/// <param name = "debugF">
|
||||
/// <param name = "debugFlag">
|
||||
/// True to turn on debugging.
|
||||
/// </param>
|
||||
public void SetDebug(bool debugF)
|
||||
public void SetDebug(bool debugFlag)
|
||||
{
|
||||
this.debug = debugF;
|
||||
SetBufferDebug(debugF);
|
||||
this.debug = debugFlag;
|
||||
SetBufferDebug(debugFlag);
|
||||
}
|
||||
|
||||
public void SetBufferDebug(bool debug)
|
||||
@@ -210,7 +218,7 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
|
||||
/// <summary>
|
||||
/// Put an entry on the output stream. This writes the entry's
|
||||
/// header record and positions the output stream for writing
|
||||
/// header and positions the output stream for writing
|
||||
/// the contents of the entry. Once this method is called, the
|
||||
/// stream is ready for calls to write() to write the entry's
|
||||
/// contents. Once the contents are written, closeEntry()
|
||||
@@ -222,12 +230,36 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </param>
|
||||
public void PutNextEntry(TarEntry entry)
|
||||
{
|
||||
if (entry.TarHeader.name.Length > TarHeader.NAMELEN) {
|
||||
throw new InvalidHeaderException("file name '" + entry.TarHeader.name + "' is too long ( > " + TarHeader.NAMELEN + " bytes )");
|
||||
if (entry.TarHeader.name.Length > TarHeader.NAMELEN)
|
||||
{
|
||||
TarHeader longHeader = new TarHeader();
|
||||
longHeader.typeFlag = TarHeader.LF_GNU_LONGNAME;
|
||||
longHeader.name.Append("././@LongLink");
|
||||
longHeader.userId = 0;
|
||||
longHeader.groupId = 0;
|
||||
longHeader.groupName.Length = 0;
|
||||
longHeader.userName.Length = 0;
|
||||
longHeader.linkName.Length = 0;
|
||||
|
||||
longHeader.size = entry.TarHeader.name.Length;
|
||||
|
||||
Console.WriteLine("TarOutputStream: PutNext entry Long name found size = " + longHeader.size); // DEBUG
|
||||
|
||||
longHeader.WriteHeader(this.blockBuf);
|
||||
this.buffer.WriteBlock(this.blockBuf); // Add special long filename header block
|
||||
|
||||
int nameCharIndex = 0;
|
||||
|
||||
while (nameCharIndex < entry.TarHeader.name.Length)
|
||||
{
|
||||
TarHeader.GetNameBytes(entry.TarHeader.name, nameCharIndex, this.blockBuf, 0, TarBuffer.BlockSize);
|
||||
nameCharIndex += TarBuffer.BlockSize;
|
||||
this.buffer.WriteBlock(this.blockBuf);
|
||||
}
|
||||
}
|
||||
|
||||
entry.WriteEntryHeader(this.recordBuf);
|
||||
this.buffer.WriteRecord(this.recordBuf);
|
||||
entry.WriteEntryHeader(this.blockBuf);
|
||||
this.buffer.WriteBlock(this.blockBuf);
|
||||
|
||||
this.currBytes = 0;
|
||||
|
||||
@@ -238,25 +270,28 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// Close an entry. This method MUST be called for all file
|
||||
/// entries that contain data. The reason is that we must
|
||||
/// buffer data written to the stream in order to satisfy
|
||||
/// the buffer's record based writes. Thus, there may be
|
||||
/// the buffer's block based writes. Thus, there may be
|
||||
/// data fragments still being assembled that must be written
|
||||
/// to the output stream before this entry is closed and the
|
||||
/// next entry written.
|
||||
/// </summary>
|
||||
public void CloseEntry()
|
||||
{
|
||||
if (this.assemLen > 0) {
|
||||
for (int i = this.assemLen; i < this.assemBuf.Length; ++i) {
|
||||
if (this.assemLen > 0)
|
||||
{
|
||||
for (int i = this.assemLen; i < this.assemBuf.Length; ++i)
|
||||
{
|
||||
this.assemBuf[i] = 0;
|
||||
}
|
||||
|
||||
this.buffer.WriteRecord(this.assemBuf);
|
||||
this.buffer.WriteBlock(this.assemBuf);
|
||||
|
||||
this.currBytes += this.assemLen;
|
||||
this.assemLen = 0;
|
||||
}
|
||||
|
||||
if (this.currBytes < this.currSize) {
|
||||
if (this.currBytes < this.currSize)
|
||||
{
|
||||
throw new IOException("entry closed at '" + this.currBytes + "' before the '" + this.currSize + "' bytes specified in the header were written");
|
||||
}
|
||||
}
|
||||
@@ -293,7 +328,8 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </param>
|
||||
public override void Write(byte[] wBuf, int wOffset, int numToWrite)
|
||||
{
|
||||
if ((this.currBytes + numToWrite) > this.currSize) {
|
||||
if ((this.currBytes + numToWrite) > this.currSize)
|
||||
{
|
||||
throw new IOException("request to write '" + numToWrite + "' bytes exceeds size in header of '" + this.currSize + "' bytes");
|
||||
}
|
||||
|
||||
@@ -304,23 +340,27 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
// REVIEW Maybe this should be in TarBuffer? Could that help to
|
||||
// eliminate some of the buffer copying.
|
||||
//
|
||||
if (this.assemLen > 0) {
|
||||
if ((this.assemLen + numToWrite ) >= this.recordBuf.Length) {
|
||||
int aLen = this.recordBuf.Length - this.assemLen;
|
||||
if (this.assemLen > 0)
|
||||
{
|
||||
if ((this.assemLen + numToWrite ) >= this.blockBuf.Length)
|
||||
{
|
||||
int aLen = this.blockBuf.Length - this.assemLen;
|
||||
|
||||
Array.Copy(this.assemBuf, 0, this.recordBuf, 0, this.assemLen);
|
||||
Array.Copy(this.assemBuf, 0, this.blockBuf, 0, this.assemLen);
|
||||
|
||||
Array.Copy(wBuf, wOffset, this.recordBuf, this.assemLen, aLen);
|
||||
Array.Copy(wBuf, wOffset, this.blockBuf, this.assemLen, aLen);
|
||||
|
||||
this.buffer.WriteRecord(this.recordBuf);
|
||||
this.buffer.WriteBlock(this.blockBuf);
|
||||
|
||||
this.currBytes += this.recordBuf.Length;
|
||||
this.currBytes += this.blockBuf.Length;
|
||||
|
||||
wOffset += aLen;
|
||||
numToWrite -= aLen;
|
||||
|
||||
this.assemLen = 0;
|
||||
} else {// ( (this.assemLen + numToWrite ) < this.recordBuf.length )
|
||||
}
|
||||
else
|
||||
{// ( (this.assemLen + numToWrite ) < this.blockBuf.length )
|
||||
Array.Copy(wBuf, wOffset, this.assemBuf, this.assemLen, numToWrite);
|
||||
wOffset += numToWrite;
|
||||
this.assemLen += numToWrite;
|
||||
@@ -333,16 +373,18 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
// o An empty "assemble" buffer.
|
||||
// o No bytes to write (numToWrite == 0)
|
||||
//
|
||||
while (numToWrite > 0) {
|
||||
if (numToWrite < this.recordBuf.Length) {
|
||||
while (numToWrite > 0)
|
||||
{
|
||||
if (numToWrite < this.blockBuf.Length)
|
||||
{
|
||||
Array.Copy(wBuf, wOffset, this.assemBuf, this.assemLen, numToWrite);
|
||||
this.assemLen += numToWrite;
|
||||
break;
|
||||
}
|
||||
|
||||
this.buffer.WriteRecord(wBuf, wOffset);
|
||||
this.buffer.WriteBlock(wBuf, wOffset);
|
||||
|
||||
int num = this.recordBuf.Length;
|
||||
int num = this.blockBuf.Length;
|
||||
this.currBytes += num;
|
||||
numToWrite -= num;
|
||||
wOffset += num;
|
||||
@@ -355,10 +397,11 @@ namespace ICSharpCode.SharpZipLib.Tar {
|
||||
/// </summary>
|
||||
void WriteEOFRecord()
|
||||
{
|
||||
for (int i = 0; i < this.recordBuf.Length; ++i) {
|
||||
this.recordBuf[i] = 0;
|
||||
for (int i = 0; i < this.blockBuf.Length; ++i)
|
||||
{
|
||||
this.blockBuf[i] = 0;
|
||||
}
|
||||
this.buffer.WriteRecord(this.recordBuf);
|
||||
this.buffer.WriteBlock(this.blockBuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -37,7 +37,8 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// This is the Deflater class. The deflater class compresses input
|
||||
@@ -119,8 +120,8 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
|
||||
private static int INIT_STATE = 0x00;
|
||||
private static int SETDICT_STATE = 0x01;
|
||||
// private static int INIT_FINISHING_STATE = 0x08;
|
||||
// private static int SETDICT_FINISHING_STATE = 0x09;
|
||||
// private static int INIT_FINISHING_STATE = 0x08;
|
||||
// private static int SETDICT_FINISHING_STATE = 0x09;
|
||||
private static int BUSY_STATE = 0x10;
|
||||
private static int FLUSHING_STATE = 0x14;
|
||||
private static int FINISHING_STATE = 0x1c;
|
||||
@@ -137,10 +138,10 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
/// </summary>
|
||||
private bool noHeader;
|
||||
|
||||
// /// <summary>
|
||||
// /// Compression strategy.
|
||||
// /// </summary>
|
||||
// private int strategy;
|
||||
// /// <summary>
|
||||
// /// Compression strategy.
|
||||
// /// </summary>
|
||||
// private int strategy;
|
||||
|
||||
/// <summary>
|
||||
/// The current state.
|
||||
@@ -360,7 +361,6 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
throw new ArgumentOutOfRangeException("lvl");
|
||||
}
|
||||
|
||||
|
||||
if (level != lvl) {
|
||||
level = lvl;
|
||||
engine.SetLevel(lvl);
|
||||
@@ -425,7 +425,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
if (state < BUSY_STATE) {
|
||||
/* output header */
|
||||
int header = (DEFLATED +
|
||||
((DeflaterConstants.MAX_WBITS - 8) << 4)) << 8;
|
||||
((DeflaterConstants.MAX_WBITS - 8) << 4)) << 8;
|
||||
int level_flags = (level - 1) >> 1;
|
||||
if (level_flags < 0 || level_flags > 3) {
|
||||
level_flags = 3;
|
||||
|
||||
+2
-1
@@ -37,7 +37,8 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// This class contains constants used for the deflater.
|
||||
|
||||
+85
-82
@@ -39,9 +39,11 @@ using System;
|
||||
|
||||
using ICSharpCode.SharpZipLib.Checksums;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression
|
||||
{
|
||||
|
||||
public enum DeflateStrategy {
|
||||
public enum DeflateStrategy
|
||||
{
|
||||
// The default strategy.
|
||||
Default = 0,
|
||||
|
||||
@@ -60,7 +62,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
static int TOO_FAR = 4096;
|
||||
|
||||
int ins_h;
|
||||
// private byte[] buffer;
|
||||
// private byte[] buffer;
|
||||
short[] head;
|
||||
short[] prev;
|
||||
|
||||
@@ -175,15 +177,15 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
max_chain = DeflaterConstants.MAX_CHAIN[lvl];
|
||||
|
||||
if (DeflaterConstants.COMPR_FUNC[lvl] != comprFunc) {
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// Console.WriteLine("Change from "+comprFunc +" to "
|
||||
// + DeflaterConstants.COMPR_FUNC[lvl]);
|
||||
// }
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// //Console.WriteLine("Change from "+comprFunc +" to "
|
||||
// + DeflaterConstants.COMPR_FUNC[lvl]);
|
||||
// }
|
||||
switch (comprFunc) {
|
||||
case DEFLATE_STORED:
|
||||
if (strstart > blockStart) {
|
||||
huffman.FlushStoredBlock(window, blockStart,
|
||||
strstart - blockStart, false);
|
||||
strstart - blockStart, false);
|
||||
blockStart = strstart;
|
||||
}
|
||||
UpdateHash();
|
||||
@@ -191,7 +193,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
case DEFLATE_FAST:
|
||||
if (strstart > blockStart) {
|
||||
huffman.FlushBlock(window, blockStart, strstart - blockStart,
|
||||
false);
|
||||
false);
|
||||
blockStart = strstart;
|
||||
}
|
||||
break;
|
||||
@@ -200,8 +202,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
huffman.TallyLit(window[strstart-1] & 0xff);
|
||||
}
|
||||
if (strstart > blockStart) {
|
||||
huffman.FlushBlock(window, blockStart, strstart - blockStart,
|
||||
false);
|
||||
huffman.FlushBlock(window, blockStart, strstart - blockStart, false);
|
||||
blockStart = strstart;
|
||||
}
|
||||
prevAvailable = false;
|
||||
@@ -212,29 +213,29 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateHash()
|
||||
void UpdateHash()
|
||||
{
|
||||
// if (DEBUGGING) {
|
||||
// Console.WriteLine("updateHash: "+strstart);
|
||||
// }
|
||||
// if (DEBUGGING) {
|
||||
// //Console.WriteLine("updateHash: "+strstart);
|
||||
// }
|
||||
ins_h = (window[strstart] << HASH_SHIFT) ^ window[strstart + 1];
|
||||
}
|
||||
|
||||
private int InsertString()
|
||||
int InsertString()
|
||||
{
|
||||
short match;
|
||||
int hash = ((ins_h << HASH_SHIFT) ^ window[strstart + (MIN_MATCH -1)]) & HASH_MASK;
|
||||
|
||||
// if (DEBUGGING) {
|
||||
// if (hash != (((window[strstart] << (2*HASH_SHIFT)) ^
|
||||
// (window[strstart + 1] << HASH_SHIFT) ^
|
||||
// (window[strstart + 2])) & HASH_MASK)) {
|
||||
// throw new Exception("hash inconsistent: "+hash+"/"
|
||||
// +window[strstart]+","
|
||||
// +window[strstart+1]+","
|
||||
// +window[strstart+2]+","+HASH_SHIFT);
|
||||
// }
|
||||
// }
|
||||
// if (DEBUGGING) {
|
||||
// if (hash != (((window[strstart] << (2*HASH_SHIFT)) ^
|
||||
// (window[strstart + 1] << HASH_SHIFT) ^
|
||||
// (window[strstart + 2])) & HASH_MASK)) {
|
||||
// throw new Exception("hash inconsistent: "+hash+"/"
|
||||
// +window[strstart]+","
|
||||
// +window[strstart+1]+","
|
||||
// +window[strstart+2]+","+HASH_SHIFT);
|
||||
// }
|
||||
// }
|
||||
|
||||
prev[strstart & WMASK] = match = head[hash];
|
||||
head[hash] = (short)strstart;
|
||||
@@ -296,7 +297,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
}
|
||||
}
|
||||
|
||||
private bool FindLongestMatch(int curMatch)
|
||||
bool FindLongestMatch(int curMatch)
|
||||
{
|
||||
int chainLength = this.max_chain;
|
||||
int niceLength = this.niceLength;
|
||||
@@ -325,7 +326,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
}
|
||||
|
||||
if (DeflaterConstants.DEBUGGING && strstart > 2 * WSIZE - MIN_LOOKAHEAD) {
|
||||
throw new InvalidOperationException("need lookahead");
|
||||
throw new InvalidOperationException("need lookahead");
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -333,10 +334,10 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
throw new InvalidOperationException("future match");
|
||||
}
|
||||
if (window[curMatch + best_len] != scan_end ||
|
||||
window[curMatch + best_len - 1] != scan_end1 ||
|
||||
window[curMatch] != window[scan] ||
|
||||
window[curMatch + 1] != window[scan + 1]) {
|
||||
continue;
|
||||
window[curMatch + best_len - 1] != scan_end1 ||
|
||||
window[curMatch] != window[scan] ||
|
||||
window[curMatch + 1] != window[scan + 1]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
match = curMatch + 2;
|
||||
@@ -345,14 +346,14 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
/* We check for insufficient lookahead only every 8th comparison;
|
||||
* the 256th check will be made at strstart+258.
|
||||
*/
|
||||
while (window[++scan] == window[++match] &&
|
||||
window[++scan] == window[++match] &&
|
||||
window[++scan] == window[++match] &&
|
||||
window[++scan] == window[++match] &&
|
||||
window[++scan] == window[++match] &&
|
||||
window[++scan] == window[++match] &&
|
||||
window[++scan] == window[++match] &&
|
||||
window[++scan] == window[++match] && scan < strend) ;
|
||||
while (window[++scan] == window[++match] &&
|
||||
window[++scan] == window[++match] &&
|
||||
window[++scan] == window[++match] &&
|
||||
window[++scan] == window[++match] &&
|
||||
window[++scan] == window[++match] &&
|
||||
window[++scan] == window[++match] &&
|
||||
window[++scan] == window[++match] &&
|
||||
window[++scan] == window[++match] && scan < strend) ;
|
||||
|
||||
if (scan > best_end) {
|
||||
// if (DeflaterConstants.DEBUGGING && ins_h == 0)
|
||||
@@ -360,6 +361,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
matchStart = curMatch;
|
||||
best_end = scan;
|
||||
best_len = scan - strstart;
|
||||
|
||||
if (best_len >= niceLength) {
|
||||
break;
|
||||
}
|
||||
@@ -400,7 +402,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
blockStart = strstart;
|
||||
}
|
||||
|
||||
private bool DeflateStored(bool flush, bool finish)
|
||||
bool DeflateStored(bool flush, bool finish)
|
||||
{
|
||||
if (!flush && lookahead == 0) {
|
||||
return false;
|
||||
@@ -420,9 +422,9 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
lastBlock = false;
|
||||
}
|
||||
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// Console.WriteLine("storedBlock["+storedLen+","+lastBlock+"]");
|
||||
// }
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// //Console.WriteLine("storedBlock["+storedLen+","+lastBlock+"]");
|
||||
// }
|
||||
|
||||
huffman.FlushStoredBlock(window, blockStart, storedLen, lastBlock);
|
||||
blockStart += storedLen;
|
||||
@@ -445,8 +447,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strstart > 2 * WSIZE - MIN_LOOKAHEAD)
|
||||
{
|
||||
if (strstart > 2 * WSIZE - MIN_LOOKAHEAD) {
|
||||
/* slide window, as findLongestMatch need this.
|
||||
* This should only happen when flushing and the window
|
||||
* is almost full.
|
||||
@@ -456,20 +457,25 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
|
||||
int hashHead;
|
||||
if (lookahead >= MIN_MATCH &&
|
||||
(hashHead = InsertString()) != 0 &&
|
||||
strategy != DeflateStrategy.HuffmanOnly &&
|
||||
strstart - hashHead <= MAX_DIST &&
|
||||
FindLongestMatch(hashHead)) {
|
||||
(hashHead = InsertString()) != 0 &&
|
||||
strategy != DeflateStrategy.HuffmanOnly &&
|
||||
strstart - hashHead <= MAX_DIST &&
|
||||
FindLongestMatch(hashHead)) {
|
||||
/* longestMatch sets matchStart and matchLen */
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// for (int i = 0 ; i < matchLen; i++) {
|
||||
// if (window[strstart+i] != window[matchStart + i]) {
|
||||
// throw new Exception();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// for (int i = 0 ; i < matchLen; i++) {
|
||||
// if (window[strstart+i] != window[matchStart + i]) {
|
||||
// throw new Exception();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
huffman.TallyDist(strstart - matchStart, matchLen);
|
||||
// -jr- Hak hak hak this stops problems with fast/low compression and index out of range
|
||||
if (huffman.TallyDist(strstart - matchStart, matchLen)) {
|
||||
bool lastBlock = finish && lookahead == 0;
|
||||
huffman.FlushBlock(window, blockStart, strstart - blockStart, lastBlock);
|
||||
blockStart = strstart;
|
||||
}
|
||||
|
||||
lookahead -= matchLen;
|
||||
if (matchLen <= max_lazy && lookahead >= MIN_MATCH) {
|
||||
@@ -495,8 +501,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
|
||||
if (huffman.IsFull()) {
|
||||
bool lastBlock = finish && lookahead == 0;
|
||||
huffman.FlushBlock(window, blockStart, strstart - blockStart,
|
||||
lastBlock);
|
||||
huffman.FlushBlock(window, blockStart, strstart - blockStart, lastBlock);
|
||||
blockStart = strstart;
|
||||
return !lastBlock;
|
||||
}
|
||||
@@ -504,7 +509,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool DeflateSlow(bool flush, bool finish)
|
||||
bool DeflateSlow(bool flush, bool finish)
|
||||
{
|
||||
if (lookahead < MIN_LOOKAHEAD && !flush) {
|
||||
return false;
|
||||
@@ -522,43 +527,41 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
throw new Exception("Not flushing, but no lookahead");
|
||||
}
|
||||
huffman.FlushBlock(window, blockStart, strstart - blockStart,
|
||||
finish);
|
||||
finish);
|
||||
blockStart = strstart;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strstart >= 2 * WSIZE - MIN_LOOKAHEAD)
|
||||
{
|
||||
if (strstart >= 2 * WSIZE - MIN_LOOKAHEAD) {
|
||||
/* slide window, as findLongestMatch need this.
|
||||
* This should only happen when flushing and the window
|
||||
* is almost full.
|
||||
*/
|
||||
SlideWindow();
|
||||
SlideWindow();
|
||||
}
|
||||
|
||||
int prevMatch = matchStart;
|
||||
int prevLen = matchLen;
|
||||
if (lookahead >= MIN_MATCH) {
|
||||
int hashHead = InsertString();
|
||||
if (strategy != DeflateStrategy.HuffmanOnly && hashHead != 0 && strstart - hashHead <= MAX_DIST && FindLongestMatch(hashHead))
|
||||
{
|
||||
/* longestMatch sets matchStart and matchLen */
|
||||
if (strategy != DeflateStrategy.HuffmanOnly && hashHead != 0 && strstart - hashHead <= MAX_DIST && FindLongestMatch(hashHead)) {
|
||||
/* longestMatch sets matchStart and matchLen */
|
||||
|
||||
/* Discard match if too small and too far away */
|
||||
if (matchLen <= 5 && (strategy == DeflateStrategy.Filtered || (matchLen == MIN_MATCH && strstart - matchStart > TOO_FAR))) {
|
||||
matchLen = MIN_MATCH - 1;
|
||||
}
|
||||
/* Discard match if too small and too far away */
|
||||
if (matchLen <= 5 && (strategy == DeflateStrategy.Filtered || (matchLen == MIN_MATCH && strstart - matchStart > TOO_FAR))) {
|
||||
matchLen = MIN_MATCH - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* previous match was better */
|
||||
if (prevLen >= MIN_MATCH && matchLen <= prevLen) {
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// for (int i = 0 ; i < matchLen; i++) {
|
||||
// if (window[strstart-1+i] != window[prevMatch + i])
|
||||
// throw new Exception();
|
||||
// }
|
||||
// }
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// for (int i = 0 ; i < matchLen; i++) {
|
||||
// if (window[strstart-1+i] != window[prevMatch + i])
|
||||
// throw new Exception();
|
||||
// }
|
||||
// }
|
||||
huffman.TallyDist(strstart - 1 - prevMatch, prevLen);
|
||||
prevLen -= 2;
|
||||
do {
|
||||
@@ -601,10 +604,10 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
do {
|
||||
FillWindow();
|
||||
bool canFlush = flush && inputOff == inputEnd;
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// Console.WriteLine("window: ["+blockStart+","+strstart+","
|
||||
// +lookahead+"], "+comprFunc+","+canFlush);
|
||||
// }
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// //Console.WriteLine("window: ["+blockStart+","+strstart+","
|
||||
// +lookahead+"], "+comprFunc+","+canFlush);
|
||||
// }
|
||||
switch (comprFunc) {
|
||||
case DEFLATE_STORED:
|
||||
progress = DeflateStored(canFlush, finish);
|
||||
|
||||
+104
-102
@@ -37,7 +37,8 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// This is the DeflaterHuffman class.
|
||||
@@ -78,15 +79,15 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
15
|
||||
};
|
||||
|
||||
|
||||
public class Tree
|
||||
{
|
||||
public short[] freqs;
|
||||
public short[] codes;
|
||||
public byte[] length;
|
||||
public int[] bl_counts;
|
||||
public int minNumCodes, numCodes;
|
||||
public int maxLength;
|
||||
|
||||
short[] codes;
|
||||
int[] bl_counts;
|
||||
int maxLength;
|
||||
DeflaterHuffman dh;
|
||||
|
||||
public Tree(DeflaterHuffman dh, int elems, int minCodes, int maxLength)
|
||||
@@ -109,10 +110,10 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
|
||||
public void WriteSymbol(int code)
|
||||
{
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// freqs[code]--;
|
||||
// // Console.Write("writeSymbol("+freqs.length+","+code+"): ");
|
||||
// }
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// freqs[code]--;
|
||||
// // Console.Write("writeSymbol("+freqs.length+","+code+"): ");
|
||||
// }
|
||||
dh.pending.WriteBits(codes[code] & 0xffff, length[code]);
|
||||
}
|
||||
|
||||
@@ -121,14 +122,14 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
bool empty = true;
|
||||
for (int i = 0; i < freqs.Length; i++) {
|
||||
if (freqs[i] != 0) {
|
||||
Console.WriteLine("freqs["+i+"] == "+freqs[i]);
|
||||
//Console.WriteLine("freqs["+i+"] == "+freqs[i]);
|
||||
empty = false;
|
||||
}
|
||||
}
|
||||
if (!empty) {
|
||||
throw new Exception();
|
||||
}
|
||||
Console.WriteLine("checkEmpty suceeded!");
|
||||
//Console.WriteLine("checkEmpty suceeded!");
|
||||
}
|
||||
|
||||
public void SetStaticCodes(short[] stCodes, byte[] stLength)
|
||||
@@ -144,17 +145,17 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
int code = 0;
|
||||
codes = new short[freqs.Length];
|
||||
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// Console.WriteLine("buildCodes: "+freqs.Length);
|
||||
// }
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// //Console.WriteLine("buildCodes: "+freqs.Length);
|
||||
// }
|
||||
|
||||
for (int bits = 0; bits < maxLength; bits++) {
|
||||
nextCode[bits] = code;
|
||||
code += bl_counts[bits] << (15 - bits);
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// Console.WriteLine("bits: "+(bits+1)+" count: "+bl_counts[bits]
|
||||
// +" nextCode: "+code); // HACK : Integer.toHexString(
|
||||
// }
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// //Console.WriteLine("bits: "+(bits+1)+" count: "+bl_counts[bits]
|
||||
// +" nextCode: "+code); // HACK : Integer.toHexString(
|
||||
// }
|
||||
}
|
||||
if (DeflaterConstants.DEBUGGING && code != 65536) {
|
||||
throw new Exception("Inconsistent bl_counts!");
|
||||
@@ -163,17 +164,17 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
for (int i=0; i < numCodes; i++) {
|
||||
int bits = length[i];
|
||||
if (bits > 0) {
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// Console.WriteLine("codes["+i+"] = rev(" + nextCode[bits-1]+")," // HACK : Integer.toHexString(
|
||||
// +bits);
|
||||
// }
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// //Console.WriteLine("codes["+i+"] = rev(" + nextCode[bits-1]+")," // HACK : Integer.toHexString(
|
||||
// +bits);
|
||||
// }
|
||||
codes[i] = BitReverse(nextCode[bits-1]);
|
||||
nextCode[bits-1] += 1 << (16 - bits);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildLength(int[] childs)
|
||||
void BuildLength(int[] childs)
|
||||
{
|
||||
this.length = new byte [freqs.Length];
|
||||
int numNodes = childs.Length / 2;
|
||||
@@ -204,13 +205,13 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
}
|
||||
}
|
||||
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// Console.WriteLine("Tree "+freqs.Length+" lengths:");
|
||||
// for (int i=0; i < numLeafs; i++) {
|
||||
// Console.WriteLine("Node "+childs[2*i]+" freq: "+freqs[childs[2*i]]
|
||||
// + " len: "+length[childs[2*i]]);
|
||||
// }
|
||||
// }
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// //Console.WriteLine("Tree "+freqs.Length+" lengths:");
|
||||
// for (int i=0; i < numLeafs; i++) {
|
||||
// //Console.WriteLine("Node "+childs[2*i]+" freq: "+freqs[childs[2*i]]
|
||||
// + " len: "+length[childs[2*i]]);
|
||||
// }
|
||||
// }
|
||||
|
||||
if (overflow == 0) {
|
||||
return;
|
||||
@@ -258,13 +259,13 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// Console.WriteLine("*** After overflow elimination. ***");
|
||||
// for (int i=0; i < numLeafs; i++) {
|
||||
// Console.WriteLine("Node "+childs[2*i]+" freq: "+freqs[childs[2*i]]
|
||||
// + " len: "+length[childs[2*i]]);
|
||||
// }
|
||||
// }
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// //Console.WriteLine("*** After overflow elimination. ***");
|
||||
// for (int i=0; i < numLeafs; i++) {
|
||||
// //Console.WriteLine("Node "+childs[2*i]+" freq: "+freqs[childs[2*i]]
|
||||
// + " len: "+length[childs[2*i]]);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
public void BuildTree()
|
||||
@@ -332,16 +333,17 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
/* Propagate the hole to the leafs of the heap */
|
||||
int ppos = 0;
|
||||
int path = 1;
|
||||
|
||||
while (path < heapLen) {
|
||||
if (path + 1 < heapLen && values[heap[path]] > values[heap[path+1]]) {
|
||||
path++;
|
||||
}
|
||||
|
||||
|
||||
heap[ppos] = heap[path];
|
||||
ppos = path;
|
||||
path = path * 2 + 1;
|
||||
}
|
||||
|
||||
|
||||
/* Now propagate the last element down along path. Normally
|
||||
* it shouldn't go too deep.
|
||||
*/
|
||||
@@ -364,16 +366,17 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
/* Again, propagate the hole to the leafs */
|
||||
ppos = 0;
|
||||
path = 1;
|
||||
|
||||
while (path < heapLen) {
|
||||
if (path + 1 < heapLen && values[heap[path]] > values[heap[path+1]]) {
|
||||
path++;
|
||||
}
|
||||
|
||||
|
||||
heap[ppos] = heap[path];
|
||||
ppos = path;
|
||||
path = ppos * 2 + 1;
|
||||
}
|
||||
|
||||
|
||||
/* Now propagate the new element down along path */
|
||||
while ((path = ppos) > 0 && values[heap[ppos = (path - 1)/2]] > lastVal) {
|
||||
heap[path] = heap[ppos];
|
||||
@@ -476,8 +479,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
while (count-- > 0) {
|
||||
blTree.WriteSymbol(curlen);
|
||||
}
|
||||
}
|
||||
else if (curlen != 0) {
|
||||
} else if (curlen != 0) {
|
||||
blTree.WriteSymbol(REP_3_6);
|
||||
dh.pending.WriteBits(count - 3, 2);
|
||||
} else if (count <= 10) {
|
||||
@@ -509,10 +511,10 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
/// </summary>
|
||||
public static short BitReverse(int value)
|
||||
{
|
||||
return (short) (bit4Reverse[value & 0xF] << 12
|
||||
| bit4Reverse[(value >> 4) & 0xF] << 8
|
||||
| bit4Reverse[(value >> 8) & 0xF] << 4
|
||||
| bit4Reverse[value >> 12]);
|
||||
return (short) (bit4Reverse[value & 0xF] << 12 |
|
||||
bit4Reverse[(value >> 4) & 0xF] << 8 |
|
||||
bit4Reverse[(value >> 8) & 0xF] << 4 |
|
||||
bit4Reverse[value >> 12]);
|
||||
}
|
||||
|
||||
|
||||
@@ -570,7 +572,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
blTree.Reset();
|
||||
}
|
||||
|
||||
private int L_code(int len)
|
||||
int Lcode(int len)
|
||||
{
|
||||
if (len == 255) {
|
||||
return 285;
|
||||
@@ -584,7 +586,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
return code + len;
|
||||
}
|
||||
|
||||
private int D_code(int distance)
|
||||
int Dcode(int distance)
|
||||
{
|
||||
int code = 0;
|
||||
while (distance >= 4) {
|
||||
@@ -607,9 +609,9 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
}
|
||||
literalTree.WriteTree(blTree);
|
||||
distTree.WriteTree(blTree);
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// blTree.CheckEmpty();
|
||||
// }
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// blTree.CheckEmpty();
|
||||
// }
|
||||
}
|
||||
|
||||
public void CompressBlock()
|
||||
@@ -618,11 +620,11 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
int litlen = l_buf[i] & 0xff;
|
||||
int dist = d_buf[i];
|
||||
if (dist-- != 0) {
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// Console.Write("["+(dist+1)+","+(litlen+3)+"]: ");
|
||||
// }
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// Console.Write("["+(dist+1)+","+(litlen+3)+"]: ");
|
||||
// }
|
||||
|
||||
int lc = L_code(litlen);
|
||||
int lc = Lcode(litlen);
|
||||
literalTree.WriteSymbol(lc);
|
||||
|
||||
int bits = (lc - 261) / 4;
|
||||
@@ -630,7 +632,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
pending.WriteBits(litlen & ((1 << bits) - 1), bits);
|
||||
}
|
||||
|
||||
int dc = D_code(dist);
|
||||
int dc = Dcode(dist);
|
||||
distTree.WriteSymbol(dc);
|
||||
|
||||
bits = dc / 2 - 1;
|
||||
@@ -638,41 +640,40 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
pending.WriteBits(dist & ((1 << bits) - 1), bits);
|
||||
}
|
||||
} else {
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// if (litlen > 32 && litlen < 127) {
|
||||
// Console.Write("("+(char)litlen+"): ");
|
||||
// } else {
|
||||
// Console.Write("{"+litlen+"}: ");
|
||||
// }
|
||||
// }
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// if (litlen > 32 && litlen < 127) {
|
||||
// Console.Write("("+(char)litlen+"): ");
|
||||
// } else {
|
||||
// Console.Write("{"+litlen+"}: ");
|
||||
// }
|
||||
// }
|
||||
literalTree.WriteSymbol(litlen);
|
||||
}
|
||||
}
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// Console.Write("EOF: ");
|
||||
// }
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// Console.Write("EOF: ");
|
||||
// }
|
||||
literalTree.WriteSymbol(EOF_SYMBOL);
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// literalTree.CheckEmpty();
|
||||
// distTree.CheckEmpty();
|
||||
// }
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// literalTree.CheckEmpty();
|
||||
// distTree.CheckEmpty();
|
||||
// }
|
||||
}
|
||||
|
||||
public void FlushStoredBlock(byte[] stored, int stored_offset, int stored_len, bool lastBlock)
|
||||
public void FlushStoredBlock(byte[] stored, int storedOffset, int storedLength, bool lastBlock)
|
||||
{
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// Console.WriteLine("Flushing stored block "+ stored_len);
|
||||
// }
|
||||
pending.WriteBits((DeflaterConstants.STORED_BLOCK << 1)
|
||||
+ (lastBlock ? 1 : 0), 3);
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// //Console.WriteLine("Flushing stored block "+ storedLength);
|
||||
// }
|
||||
pending.WriteBits((DeflaterConstants.STORED_BLOCK << 1) + (lastBlock ? 1 : 0), 3);
|
||||
pending.AlignToByte();
|
||||
pending.WriteShort(stored_len);
|
||||
pending.WriteShort(~stored_len);
|
||||
pending.WriteBlock(stored, stored_offset, stored_len);
|
||||
pending.WriteShort(storedLength);
|
||||
pending.WriteShort(~storedLength);
|
||||
pending.WriteBlock(stored, storedOffset, storedLength);
|
||||
Reset();
|
||||
}
|
||||
|
||||
public void FlushBlock(byte[] stored, int stored_offset, int stored_len, bool lastBlock)
|
||||
public void FlushBlock(byte[] stored, int storedOffset, int storedLength, bool lastBlock)
|
||||
{
|
||||
literalTree.freqs[EOF_SYMBOL]++;
|
||||
|
||||
@@ -694,8 +695,8 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
}
|
||||
}
|
||||
int opt_len = 14 + blTreeCodes * 3 + blTree.GetEncodedLength() +
|
||||
literalTree.GetEncodedLength() + distTree.GetEncodedLength() +
|
||||
extra_bits;
|
||||
literalTree.GetEncodedLength() + distTree.GetEncodedLength() +
|
||||
extra_bits;
|
||||
|
||||
int static_len = extra_bits;
|
||||
for (int i = 0; i < LITERAL_NUM; i++) {
|
||||
@@ -709,13 +710,13 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
opt_len = static_len;
|
||||
}
|
||||
|
||||
if (stored_offset >= 0 && stored_len+4 < (opt_len >> 3)) {
|
||||
if ((storedOffset >= 0) && (storedLength + 4 < (opt_len >> 3))) {
|
||||
/* Store Block */
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// Console.WriteLine("Storing, since " + stored_len + " < " + opt_len
|
||||
// + " <= " + static_len);
|
||||
// }
|
||||
FlushStoredBlock(stored, stored_offset, stored_len, lastBlock);
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// //Console.WriteLine("Storing, since " + storedLength + " < " + opt_len
|
||||
// + " <= " + static_len);
|
||||
// }
|
||||
FlushStoredBlock(stored, storedOffset, storedLength, lastBlock);
|
||||
} else if (opt_len == static_len) {
|
||||
/* Encode with static tree */
|
||||
pending.WriteBits((DeflaterConstants.STATIC_TREES << 1) + (lastBlock ? 1 : 0), 3);
|
||||
@@ -734,18 +735,19 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
|
||||
public bool IsFull()
|
||||
{
|
||||
return last_lit + 16 >= BUFSIZE; // HACK: This was == 'last_lit == BUFSIZE', but errors occured with DeflateFast
|
||||
// return last_lit + 16 >= BUFSIZE; // HACK: This was == 'last_lit == BUFSIZE', but errors occured with DeflateFast
|
||||
return last_lit >= BUFSIZE; // -jr- This is the correct form!
|
||||
}
|
||||
|
||||
public bool TallyLit(int lit)
|
||||
{
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// if (lit > 32 && lit < 127) {
|
||||
// Console.WriteLine("("+(char)lit+")");
|
||||
// } else {
|
||||
// Console.WriteLine("{"+lit+"}");
|
||||
// }
|
||||
// }
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// if (lit > 32 && lit < 127) {
|
||||
// //Console.WriteLine("("+(char)lit+")");
|
||||
// } else {
|
||||
// //Console.WriteLine("{"+lit+"}");
|
||||
// }
|
||||
// }
|
||||
d_buf[last_lit] = 0;
|
||||
l_buf[last_lit++] = (byte)lit;
|
||||
literalTree.freqs[lit]++;
|
||||
@@ -754,20 +756,20 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
|
||||
public bool TallyDist(int dist, int len)
|
||||
{
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// Console.WriteLine("["+dist+","+len+"]");
|
||||
// }
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// //Console.WriteLine("["+dist+","+len+"]");
|
||||
// }
|
||||
|
||||
d_buf[last_lit] = (short)dist;
|
||||
l_buf[last_lit++] = (byte)(len - 3);
|
||||
|
||||
int lc = L_code(len - 3);
|
||||
int lc = Lcode(len - 3);
|
||||
literalTree.freqs[lc]++;
|
||||
if (lc >= 265 && lc < 285) {
|
||||
extra_bits += (lc - 261) / 4;
|
||||
}
|
||||
|
||||
int dc = D_code(dist - 1);
|
||||
int dc = Dcode(dist - 1);
|
||||
distTree.freqs[dc]++;
|
||||
if (dc >= 4) {
|
||||
extra_bits += dc / 2 - 1;
|
||||
|
||||
+2
-1
@@ -35,7 +35,8 @@
|
||||
// obligated to do so. If you do not wish to do so, delete this
|
||||
// exception statement from your version.
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// This class stores the pending output of the Deflater.
|
||||
|
||||
+35
-31
@@ -40,7 +40,8 @@ using System;
|
||||
using ICSharpCode.SharpZipLib.Checksums;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Inflater is used to decompress data that has been compressed according
|
||||
@@ -69,35 +70,35 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
/// Copy lengths for literal codes 257..285
|
||||
/// </summary>
|
||||
private static int[] CPLENS = {
|
||||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
|
||||
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258
|
||||
};
|
||||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
|
||||
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Extra bits for literal codes 257..285
|
||||
/// </summary>
|
||||
private static int[] CPLEXT = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
|
||||
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0
|
||||
};
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
|
||||
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Copy offsets for distance codes 0..29
|
||||
/// </summary>
|
||||
private static int[] CPDIST = {
|
||||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
|
||||
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
|
||||
8193, 12289, 16385, 24577
|
||||
};
|
||||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
|
||||
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
|
||||
8193, 12289, 16385, 24577
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Extra bits for distance codes
|
||||
/// </summary>
|
||||
private static int[] CPDEXT = {
|
||||
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
|
||||
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
|
||||
12, 12, 13, 13
|
||||
};
|
||||
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
|
||||
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
|
||||
12, 12, 13, 13
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// This are the state in which the inflater can be.
|
||||
@@ -384,9 +385,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
neededBits -= 8;
|
||||
}
|
||||
if ((int) adler.Value != readAdler) {
|
||||
throw new FormatException("Adler chksum doesn't match: "
|
||||
+ (int)adler.Value
|
||||
+ " vs. " + readAdler);
|
||||
throw new FormatException("Adler chksum doesn't match: " + (int)adler.Value + " vs. " + readAdler);
|
||||
}
|
||||
mode = FINISHED;
|
||||
return false;
|
||||
@@ -433,7 +432,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
if ((type & 1) != 0) {
|
||||
isLastBlock = true;
|
||||
}
|
||||
switch (type >> 1) {
|
||||
switch (type >> 1){
|
||||
case DeflaterConstants.STORED_BLOCK:
|
||||
input.SkipToByteBoundary();
|
||||
mode = DECODE_STORED_LEN1;
|
||||
@@ -452,15 +451,17 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
}
|
||||
return true;
|
||||
|
||||
case DECODE_STORED_LEN1: {
|
||||
case DECODE_STORED_LEN1:
|
||||
{
|
||||
if ((uncomprLen = input.PeekBits(16)) < 0) {
|
||||
return false;
|
||||
}
|
||||
input.DropBits(16);
|
||||
mode = DECODE_STORED_LEN2;
|
||||
}
|
||||
goto case DECODE_STORED_LEN2; /* fall through */
|
||||
case DECODE_STORED_LEN2: {
|
||||
goto case DECODE_STORED_LEN2; /* fall through */
|
||||
case DECODE_STORED_LEN2:
|
||||
{
|
||||
int nlen = input.PeekBits(16);
|
||||
if (nlen < 0) {
|
||||
return false;
|
||||
@@ -471,8 +472,9 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
}
|
||||
mode = DECODE_STORED;
|
||||
}
|
||||
goto case DECODE_STORED;/* fall through */
|
||||
case DECODE_STORED: {
|
||||
goto case DECODE_STORED;/* fall through */
|
||||
case DECODE_STORED:
|
||||
{
|
||||
int more = outputWindow.CopyStored(input, uncomprLen);
|
||||
uncomprLen -= more;
|
||||
if (uncomprLen == 0) {
|
||||
@@ -554,7 +556,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
}
|
||||
|
||||
adler.Update(buffer, off, len);
|
||||
if ((int) adler.Value != readAdler) {
|
||||
if ((int)adler.Value != readAdler) {
|
||||
throw new ArgumentException("Wrong adler checksum");
|
||||
}
|
||||
adler.Reset();
|
||||
@@ -660,12 +662,15 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
}
|
||||
// Special case: len may be zero
|
||||
if (len == 0) {
|
||||
if (IsFinished == false) {// -jr- 08-Nov-2003 INFLATE_BUG fix..
|
||||
Decode();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/* // Check for correct buff, off, len triple
|
||||
if (off < 0 || off + len >= buf.Length) {
|
||||
throw new ArgumentException("off/len outside buf bounds");
|
||||
}*/
|
||||
/* // Check for correct buff, off, len triple
|
||||
if (off < 0 || off + len >= buf.Length) {
|
||||
throw new ArgumentException("off/len outside buf bounds");
|
||||
}*/
|
||||
int count = 0;
|
||||
int more;
|
||||
do {
|
||||
@@ -687,8 +692,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
return count;
|
||||
}
|
||||
}
|
||||
} while (Decode() || (outputWindow.GetAvailable() > 0 &&
|
||||
mode != DECODE_CHKSUM));
|
||||
} while (Decode() || (outputWindow.GetAvailable() > 0 && mode != DECODE_CHKSUM));
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
+89
-85
@@ -39,7 +39,8 @@ using System;
|
||||
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression
|
||||
{
|
||||
|
||||
class InflaterDynHeader
|
||||
{
|
||||
@@ -64,7 +65,8 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
byte lastLen;
|
||||
int ptr;
|
||||
|
||||
static readonly int[] BL_ORDER = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
|
||||
static readonly int[] BL_ORDER =
|
||||
{ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
|
||||
|
||||
public InflaterDynHeader()
|
||||
{
|
||||
@@ -73,91 +75,93 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
public bool Decode(StreamManipulator input)
|
||||
{
|
||||
decode_loop:
|
||||
for (;;) {
|
||||
switch (mode) {
|
||||
case LNUM:
|
||||
lnum = input.PeekBits(5);
|
||||
if (lnum < 0) {
|
||||
return false;
|
||||
}
|
||||
lnum += 257;
|
||||
input.DropBits(5);
|
||||
// System.err.println("LNUM: "+lnum);
|
||||
mode = DNUM;
|
||||
goto case DNUM; // fall through
|
||||
case DNUM:
|
||||
dnum = input.PeekBits(5);
|
||||
if (dnum < 0) {
|
||||
return false;
|
||||
}
|
||||
dnum++;
|
||||
input.DropBits(5);
|
||||
// System.err.println("DNUM: "+dnum);
|
||||
num = lnum+dnum;
|
||||
litdistLens = new byte[num];
|
||||
mode = BLNUM;
|
||||
goto case BLNUM; // fall through
|
||||
case BLNUM:
|
||||
blnum = input.PeekBits(4);
|
||||
if (blnum < 0) {
|
||||
return false;
|
||||
}
|
||||
blnum += 4;
|
||||
input.DropBits(4);
|
||||
blLens = new byte[19];
|
||||
ptr = 0;
|
||||
// System.err.println("BLNUM: "+blnum);
|
||||
mode = BLLENS;
|
||||
goto case BLLENS; // fall through
|
||||
case BLLENS:
|
||||
while (ptr < blnum) {
|
||||
int len = input.PeekBits(3);
|
||||
if (len < 0) {
|
||||
for (;;) {
|
||||
switch (mode) {
|
||||
case LNUM:
|
||||
lnum = input.PeekBits(5);
|
||||
if (lnum < 0) {
|
||||
return false;
|
||||
}
|
||||
input.DropBits(3);
|
||||
// System.err.println("blLens["+BL_ORDER[ptr]+"]: "+len);
|
||||
blLens[BL_ORDER[ptr]] = (byte) len;
|
||||
ptr++;
|
||||
}
|
||||
blTree = new InflaterHuffmanTree(blLens);
|
||||
blLens = null;
|
||||
ptr = 0;
|
||||
mode = LENS;
|
||||
goto case LENS; // fall through
|
||||
case LENS: {
|
||||
int symbol;
|
||||
while (((symbol = blTree.GetSymbol(input)) & ~15) == 0) {
|
||||
/* Normal case: symbol in [0..15] */
|
||||
|
||||
// System.err.println("litdistLens["+ptr+"]: "+symbol);
|
||||
litdistLens[ptr++] = lastLen = (byte)symbol;
|
||||
|
||||
if (ptr == num) {
|
||||
/* Finished */
|
||||
return true;
|
||||
lnum += 257;
|
||||
input.DropBits(5);
|
||||
// System.err.println("LNUM: "+lnum);
|
||||
mode = DNUM;
|
||||
goto case DNUM; // fall through
|
||||
case DNUM:
|
||||
dnum = input.PeekBits(5);
|
||||
if (dnum < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* need more input ? */
|
||||
if (symbol < 0)
|
||||
return false;
|
||||
|
||||
/* otherwise repeat code */
|
||||
if (symbol >= 17) {
|
||||
/* repeat zero */
|
||||
// System.err.println("repeating zero");
|
||||
lastLen = 0;
|
||||
} else {
|
||||
if (ptr == 0) {
|
||||
throw new Exception();
|
||||
dnum++;
|
||||
input.DropBits(5);
|
||||
// System.err.println("DNUM: "+dnum);
|
||||
num = lnum+dnum;
|
||||
litdistLens = new byte[num];
|
||||
mode = BLNUM;
|
||||
goto case BLNUM; // fall through
|
||||
case BLNUM:
|
||||
blnum = input.PeekBits(4);
|
||||
if (blnum < 0) {
|
||||
return false;
|
||||
}
|
||||
blnum += 4;
|
||||
input.DropBits(4);
|
||||
blLens = new byte[19];
|
||||
ptr = 0;
|
||||
// System.err.println("BLNUM: "+blnum);
|
||||
mode = BLLENS;
|
||||
goto case BLLENS; // fall through
|
||||
case BLLENS:
|
||||
while (ptr < blnum) {
|
||||
int len = input.PeekBits(3);
|
||||
if (len < 0) {
|
||||
return false;
|
||||
}
|
||||
input.DropBits(3);
|
||||
// System.err.println("blLens["+BL_ORDER[ptr]+"]: "+len);
|
||||
blLens[BL_ORDER[ptr]] = (byte) len;
|
||||
ptr++;
|
||||
}
|
||||
blTree = new InflaterHuffmanTree(blLens);
|
||||
blLens = null;
|
||||
ptr = 0;
|
||||
mode = LENS;
|
||||
goto case LENS; // fall through
|
||||
case LENS:
|
||||
{
|
||||
int symbol;
|
||||
while (((symbol = blTree.GetSymbol(input)) & ~15) == 0) {
|
||||
/* Normal case: symbol in [0..15] */
|
||||
|
||||
// System.err.println("litdistLens["+ptr+"]: "+symbol);
|
||||
litdistLens[ptr++] = lastLen = (byte)symbol;
|
||||
|
||||
if (ptr == num) {
|
||||
/* Finished */
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* need more input ? */
|
||||
if (symbol < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* otherwise repeat code */
|
||||
if (symbol >= 17) {
|
||||
/* repeat zero */
|
||||
// System.err.println("repeating zero");
|
||||
lastLen = 0;
|
||||
} else {
|
||||
if (ptr == 0) {
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
repSymbol = symbol-16;
|
||||
}
|
||||
repSymbol = symbol-16;
|
||||
}
|
||||
mode = REPS;
|
||||
goto case REPS; // fall through
|
||||
case REPS:
|
||||
mode = REPS;
|
||||
goto case REPS; // fall through
|
||||
case REPS:
|
||||
{
|
||||
int bits = repBits[repSymbol];
|
||||
int count = input.PeekBits(bits);
|
||||
@@ -180,10 +184,10 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
mode = LENS;
|
||||
goto decode_loop;
|
||||
mode = LENS;
|
||||
goto decode_loop;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public InflaterHuffmanTree BuildLitLenTree()
|
||||
|
||||
+8
-3
@@ -39,7 +39,8 @@ using System;
|
||||
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression
|
||||
{
|
||||
|
||||
public class InflaterHuffmanTree
|
||||
{
|
||||
@@ -96,8 +97,9 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
|
||||
for (int i = 0; i < codeLengths.Length; i++) {
|
||||
int bits = codeLengths[i];
|
||||
if (bits > 0)
|
||||
if (bits > 0) {
|
||||
blCount[bits]++;
|
||||
}
|
||||
}
|
||||
|
||||
int code = 0;
|
||||
@@ -112,9 +114,12 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
treeSize += (end - start) >> (16 - bits);
|
||||
}
|
||||
}
|
||||
if (code != 65536) {
|
||||
/* -jr comment this out! doesnt work for dynamic trees and pkzip 2.04g
|
||||
if (code != 65536)
|
||||
{
|
||||
throw new Exception("Code lengths don't add up properly.");
|
||||
}
|
||||
*/
|
||||
/* Now create and fill the extra tables from longest to shortest
|
||||
* bit len. This way the sub trees will be aligned.
|
||||
*/
|
||||
|
||||
+8
-6
@@ -37,7 +37,8 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// This class is general purpose class for writing data to a buffer.
|
||||
@@ -73,8 +74,9 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
|
||||
public void WriteByte(int b)
|
||||
{
|
||||
if (DeflaterConstants.DEBUGGING && start != 0)
|
||||
if (DeflaterConstants.DEBUGGING && start != 0) {
|
||||
throw new Exception();
|
||||
}
|
||||
buf[end++] = (byte) b;
|
||||
}
|
||||
|
||||
@@ -133,9 +135,9 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
if (DeflaterConstants.DEBUGGING && start != 0) {
|
||||
throw new Exception();
|
||||
}
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// Console.WriteLine("writeBits("+b+","+count+")");
|
||||
// }
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// //Console.WriteLine("writeBits("+b+","+count+")");
|
||||
// }
|
||||
bits |= (uint)(b << bitCount);
|
||||
bitCount += count;
|
||||
if (bitCount >= 16) {
|
||||
@@ -198,7 +200,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression {
|
||||
|
||||
public byte[] ToByteArray()
|
||||
{
|
||||
byte[] ret = new byte[ end - start ];
|
||||
byte[] ret = new byte[end - start];
|
||||
System.Array.Copy(buf, start, ret, 0, ret.Length);
|
||||
start = 0;
|
||||
end = 0;
|
||||
|
||||
+92
-9
@@ -37,10 +37,11 @@
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using ICSharpCode.SharpZipLib.Checksums;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// This is a special FilterOutputStream deflating the bytes that are
|
||||
@@ -80,7 +81,8 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
/// </summary>
|
||||
public override bool CanSeek {
|
||||
get {
|
||||
return baseOutputStream.CanSeek;
|
||||
return false;
|
||||
// return baseOutputStream.CanSeek;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +121,8 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
/// </summary>
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
return baseOutputStream.Seek(offset, origin);
|
||||
throw new NotSupportedException("Seek not supported"); // -jr- 01-Dec-2003
|
||||
// return baseOutputStream.Seek(offset, origin);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -145,14 +148,24 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
{
|
||||
return baseOutputStream.Read(b, off, len);
|
||||
}
|
||||
// -jr- 01-Dec-2003
|
||||
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
|
||||
{
|
||||
throw new NotSupportedException("Asynch read not currently supported");
|
||||
}
|
||||
|
||||
// -jr- 01-Dec-2003
|
||||
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
|
||||
{
|
||||
throw new NotSupportedException("Asynch write not currently supported");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deflates everything in the def's input buffers. This will call
|
||||
/// <code>def.deflate()</code> until all bytes from the input buffers
|
||||
/// are processed.
|
||||
/// </summary>
|
||||
protected void deflate()
|
||||
protected void Deflate()
|
||||
{
|
||||
while (!def.IsNeedingInput) {
|
||||
int len = def.Deflate(buf, 0, buf.Length);
|
||||
@@ -177,7 +190,6 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
/// </param>
|
||||
public DeflaterOutputStream(Stream baseOutputStream) : this(baseOutputStream, new Deflater(), 512)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -228,7 +240,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
public override void Flush()
|
||||
{
|
||||
def.Flush();
|
||||
deflate();
|
||||
Deflate();
|
||||
baseOutputStream.Flush();
|
||||
}
|
||||
|
||||
@@ -238,11 +250,18 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
public virtual void Finish()
|
||||
{
|
||||
def.Finish();
|
||||
while (!def.IsFinished) {
|
||||
while (!def.IsFinished) {
|
||||
int len = def.Deflate(buf, 0, buf.Length);
|
||||
if (len <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
// kidnthrain encryption alteration
|
||||
if (this.Password != null) {
|
||||
// plain data has been deflated. Now encrypt result
|
||||
this.EncryptBlock(buf, 0, len);
|
||||
}
|
||||
|
||||
baseOutputStream.Write(buf, 0, len);
|
||||
}
|
||||
if (!def.IsFinished) {
|
||||
@@ -289,8 +308,72 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
{
|
||||
// System.err.println("DOS with off " + off + " and len " + len);
|
||||
def.SetInput(buf, off, len);
|
||||
deflate();
|
||||
Deflate();
|
||||
}
|
||||
|
||||
#region Encryption
|
||||
string password = null;
|
||||
uint[] keys = null;
|
||||
|
||||
public string Password {
|
||||
get {
|
||||
return password;
|
||||
}
|
||||
set {
|
||||
password = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//The beauty of xor-ing bits is that
|
||||
//plain ^ key = enc
|
||||
//and enc ^ key = plain
|
||||
//accordingly, this is the exact same as the decrypt byte
|
||||
//function in InflaterInputStream
|
||||
protected byte EncryptByte()
|
||||
{
|
||||
uint temp = ((keys[2] & 0xFFFF) | 2);
|
||||
return (byte)((temp * (temp ^ 1)) >> 8);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Takes a buffer of data and uses the keys
|
||||
/// that have been previously initialized from a
|
||||
/// password and then updated via a random encryption header
|
||||
/// to encrypt that data
|
||||
/// </summary>
|
||||
protected void EncryptBlock(byte[] buf, int off, int len)
|
||||
{
|
||||
for (int i = off; i < off + len; ++i) {
|
||||
byte oldbyte = buf[i];
|
||||
buf[i] ^= EncryptByte();
|
||||
UpdateKeys(oldbyte);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes our encryption keys using a given password
|
||||
/// </summary>
|
||||
protected void InitializePassword(string password) {
|
||||
keys = new uint[] {
|
||||
0x12345678,
|
||||
0x23456789,
|
||||
0x34567890
|
||||
};
|
||||
|
||||
for (int i = 0; i < password.Length; ++i) {
|
||||
UpdateKeys((byte)password[i]);
|
||||
}
|
||||
}
|
||||
|
||||
protected void UpdateKeys(byte ch)
|
||||
{
|
||||
keys[0] = Crc32.ComputeCrc32(keys[0], ch);
|
||||
keys[1] = keys[1] + (byte)keys[0];
|
||||
keys[1] = keys[1] * 134775813 + 1;
|
||||
keys[2] = Crc32.ComputeCrc32(keys[2], (byte)(keys[1] >> 24));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+64
-25
@@ -39,8 +39,10 @@ using System;
|
||||
using System.IO;
|
||||
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression;
|
||||
using ICSharpCode.SharpZipLib.Checksums;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// This filter stream is used to decompress data compressed baseInputStream the "deflate"
|
||||
@@ -60,7 +62,6 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
/// </summary>
|
||||
protected Inflater inf;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Byte array used as a buffer
|
||||
/// </summary>
|
||||
@@ -79,6 +80,8 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
/// </summary>
|
||||
protected Stream baseInputStream;
|
||||
|
||||
protected long csize;
|
||||
|
||||
/// <summary>
|
||||
/// I needed to implement the abstract member.
|
||||
/// </summary>
|
||||
@@ -93,7 +96,8 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
/// </summary>
|
||||
public override bool CanSeek {
|
||||
get {
|
||||
return baseInputStream.CanSeek;
|
||||
return false;
|
||||
// return baseInputStream.CanSeek;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +144,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
/// </summary>
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
return baseInputStream.Seek(offset, origin);
|
||||
throw new NotSupportedException("Seek not supported"); // -jr- 01-Dec-2003
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -167,6 +171,12 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
baseInputStream.WriteByte(val);
|
||||
}
|
||||
|
||||
// -jr- 01-Dec-2003 This may be flawed for some base streams? Depends on implementation of BeginWrite
|
||||
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
|
||||
{
|
||||
throw new NotSupportedException("Asynch write not currently supported");
|
||||
}
|
||||
|
||||
//Constructors
|
||||
|
||||
/// <summary>
|
||||
@@ -193,7 +203,6 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
/// </param>
|
||||
public InflaterInputStream(Stream baseInputStream, Inflater inf) : this(baseInputStream, inf, 4096)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -215,7 +224,8 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
this.inf = inf;
|
||||
try {
|
||||
this.len = (int)baseInputStream.Length;
|
||||
} catch (Exception) { // the stream may not support .Length
|
||||
} catch (Exception) {
|
||||
// the stream may not support .Length
|
||||
this.len = 0;
|
||||
}
|
||||
|
||||
@@ -243,9 +253,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
/// </summary>
|
||||
public override void Close()
|
||||
{
|
||||
// Do not close the parent, it might be used by a ZipFile, and
|
||||
// we do not want to close the "master" source.
|
||||
// baseInputStream.Close();
|
||||
baseInputStream.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -254,8 +262,12 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
protected void Fill()
|
||||
{
|
||||
len = baseInputStream.Read(buf, 0, buf.Length);
|
||||
// decrypting crypted data
|
||||
if (cryptbuffer != null) {
|
||||
DecryptBlock(buf, 0, System.Math.Min((int)(csize - inf.TotalIn), buf.Length));
|
||||
}
|
||||
|
||||
if (len < 0) {
|
||||
if (len <= 0) {
|
||||
throw new ApplicationException("Deflated stream ends early.");
|
||||
}
|
||||
inf.SetInput(buf, 0, len);
|
||||
@@ -272,7 +284,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
if (nread > 0) {
|
||||
return onebytebuffer[0] & 0xff;
|
||||
}
|
||||
return -1;
|
||||
return -1; // ok
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -328,20 +340,47 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
if (n < len) {
|
||||
len = (int) n;
|
||||
}
|
||||
if (false && baseInputStream.CanSeek){
|
||||
baseInputStream.Seek (len, SeekOrigin.Current);
|
||||
} else {
|
||||
byte[] tmp = new byte[8192];
|
||||
|
||||
for (long i = 0; i < len; ){
|
||||
long left = len - i;
|
||||
int count = left < 8192 ? ((int) left) : 8192;
|
||||
|
||||
baseInputStream.Read (tmp, 0, count);
|
||||
i += count;
|
||||
}
|
||||
}
|
||||
return (long) len;
|
||||
byte[] tmp = new byte[len];
|
||||
return (long)baseInputStream.Read(tmp, 0, tmp.Length);
|
||||
}
|
||||
|
||||
#region Encryption stuff
|
||||
protected byte[] cryptbuffer = null;
|
||||
|
||||
uint[] keys = null;
|
||||
protected byte DecryptByte()
|
||||
{
|
||||
uint temp = ((keys[2] & 0xFFFF) | 2);
|
||||
return (byte)((temp * (temp ^ 1)) >> 8);
|
||||
}
|
||||
|
||||
protected void DecryptBlock(byte[] buf, int off, int len)
|
||||
{
|
||||
for (int i = off; i < off + len; ++i) {
|
||||
buf[i] ^= DecryptByte();
|
||||
UpdateKeys(buf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
protected void InitializePassword(string password)
|
||||
{
|
||||
keys = new uint[] {
|
||||
0x12345678,
|
||||
0x23456789,
|
||||
0x34567890
|
||||
};
|
||||
for (int i = 0; i < password.Length; ++i) {
|
||||
UpdateKeys((byte)password[i]);
|
||||
}
|
||||
}
|
||||
|
||||
protected void UpdateKeys(byte ch)
|
||||
{
|
||||
keys[0] = Crc32.ComputeCrc32(keys[0], ch);
|
||||
keys[1] = keys[1] + (byte)keys[0];
|
||||
keys[1] = keys[1] * 134775813 + 1;
|
||||
keys[2] = Crc32.ComputeCrc32(keys[2], (byte)(keys[1] >> 24));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+36
-36
@@ -37,7 +37,8 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Contains the output from the Inflation process.
|
||||
@@ -52,45 +53,45 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
private static int WINDOW_MASK = WINDOW_SIZE - 1;
|
||||
|
||||
private byte[] window = new byte[WINDOW_SIZE]; //The window is 2^15 bytes
|
||||
private int window_end = 0;
|
||||
private int window_filled = 0;
|
||||
private int windowEnd = 0;
|
||||
private int windowFilled = 0;
|
||||
|
||||
public void Write(int abyte)
|
||||
{
|
||||
if (window_filled++ == WINDOW_SIZE) {
|
||||
if (windowFilled++ == WINDOW_SIZE) {
|
||||
throw new InvalidOperationException("Window full");
|
||||
}
|
||||
window[window_end++] = (byte) abyte;
|
||||
window_end &= WINDOW_MASK;
|
||||
window[windowEnd++] = (byte) abyte;
|
||||
windowEnd &= WINDOW_MASK;
|
||||
}
|
||||
|
||||
|
||||
private void SlowRepeat(int rep_start, int len, int dist)
|
||||
private void SlowRepeat(int repStart, int len, int dist)
|
||||
{
|
||||
while (len-- > 0) {
|
||||
window[window_end++] = window[rep_start++];
|
||||
window_end &= WINDOW_MASK;
|
||||
rep_start &= WINDOW_MASK;
|
||||
window[windowEnd++] = window[repStart++];
|
||||
windowEnd &= WINDOW_MASK;
|
||||
repStart &= WINDOW_MASK;
|
||||
}
|
||||
}
|
||||
|
||||
public void Repeat(int len, int dist)
|
||||
{
|
||||
if ((window_filled += len) > WINDOW_SIZE) {
|
||||
if ((windowFilled += len) > WINDOW_SIZE) {
|
||||
throw new InvalidOperationException("Window full");
|
||||
}
|
||||
|
||||
int rep_start = (window_end - dist) & WINDOW_MASK;
|
||||
int rep_start = (windowEnd - dist) & WINDOW_MASK;
|
||||
int border = WINDOW_SIZE - len;
|
||||
if (rep_start <= border && window_end < border) {
|
||||
if (rep_start <= border && windowEnd < border) {
|
||||
if (len <= dist) {
|
||||
System.Array.Copy(window, rep_start, window, window_end, len);
|
||||
window_end += len;
|
||||
} else {
|
||||
System.Array.Copy(window, rep_start, window, windowEnd, len);
|
||||
windowEnd += len;
|
||||
} else {
|
||||
/* We have to copy manually, since the repeat pattern overlaps.
|
||||
*/
|
||||
while (len-- > 0) {
|
||||
window[window_end++] = window[rep_start++];
|
||||
window[windowEnd++] = window[rep_start++];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -100,27 +101,27 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
|
||||
public int CopyStored(StreamManipulator input, int len)
|
||||
{
|
||||
len = Math.Min(Math.Min(len, WINDOW_SIZE - window_filled), input.AvailableBytes);
|
||||
len = Math.Min(Math.Min(len, WINDOW_SIZE - windowFilled), input.AvailableBytes);
|
||||
int copied;
|
||||
|
||||
int tailLen = WINDOW_SIZE - window_end;
|
||||
int tailLen = WINDOW_SIZE - windowEnd;
|
||||
if (len > tailLen) {
|
||||
copied = input.CopyBytes(window, window_end, tailLen);
|
||||
copied = input.CopyBytes(window, windowEnd, tailLen);
|
||||
if (copied == tailLen) {
|
||||
copied += input.CopyBytes(window, 0, len - tailLen);
|
||||
}
|
||||
} else {
|
||||
copied = input.CopyBytes(window, window_end, len);
|
||||
copied = input.CopyBytes(window, windowEnd, len);
|
||||
}
|
||||
|
||||
window_end = (window_end + copied) & WINDOW_MASK;
|
||||
window_filled += copied;
|
||||
windowEnd = (windowEnd + copied) & WINDOW_MASK;
|
||||
windowFilled += copied;
|
||||
return copied;
|
||||
}
|
||||
|
||||
public void CopyDict(byte[] dict, int offset, int len)
|
||||
{
|
||||
if (window_filled > 0) {
|
||||
if (windowFilled > 0) {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
@@ -129,40 +130,39 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
len = WINDOW_SIZE;
|
||||
}
|
||||
System.Array.Copy(dict, offset, window, 0, len);
|
||||
window_end = len & WINDOW_MASK;
|
||||
windowEnd = len & WINDOW_MASK;
|
||||
}
|
||||
|
||||
public int GetFreeSpace()
|
||||
{
|
||||
return WINDOW_SIZE - window_filled;
|
||||
return WINDOW_SIZE - windowFilled;
|
||||
}
|
||||
|
||||
public int GetAvailable()
|
||||
{
|
||||
return window_filled;
|
||||
return windowFilled;
|
||||
}
|
||||
|
||||
public int CopyOutput(byte[] output, int offset, int len)
|
||||
{
|
||||
int copy_end = window_end;
|
||||
if (len > window_filled) {
|
||||
len = window_filled;
|
||||
int copy_end = windowEnd;
|
||||
if (len > windowFilled) {
|
||||
len = windowFilled;
|
||||
} else {
|
||||
copy_end = (window_end - window_filled + len) & WINDOW_MASK;
|
||||
copy_end = (windowEnd - windowFilled + len) & WINDOW_MASK;
|
||||
}
|
||||
|
||||
int copied = len;
|
||||
int tailLen = len - copy_end;
|
||||
|
||||
if (tailLen > 0) {
|
||||
System.Array.Copy(window, WINDOW_SIZE - tailLen,
|
||||
output, offset, tailLen);
|
||||
System.Array.Copy(window, WINDOW_SIZE - tailLen, output, offset, tailLen);
|
||||
offset += tailLen;
|
||||
len = copy_end;
|
||||
}
|
||||
System.Array.Copy(window, copy_end - len, output, offset, len);
|
||||
window_filled -= copied;
|
||||
if (window_filled < 0) {
|
||||
windowFilled -= copied;
|
||||
if (windowFilled < 0) {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
return copied;
|
||||
@@ -170,7 +170,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
window_filled = window_end = 0;
|
||||
windowFilled = windowEnd = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -37,7 +37,8 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// This class allows us to retrieve a specified amount of bits from
|
||||
@@ -75,7 +76,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
{
|
||||
if (bits_in_buffer < n) {
|
||||
if (window_start == window_end) {
|
||||
return -1;
|
||||
return -1; // ok
|
||||
}
|
||||
buffer |= (uint)((window[window_start++] & 0xff |
|
||||
(window[window_start++] & 0xff) << 8) << bits_in_buffer);
|
||||
@@ -174,7 +175,7 @@ namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
|
||||
if (length < 0) {
|
||||
throw new ArgumentOutOfRangeException("length negative");
|
||||
}
|
||||
if ((bits_in_buffer & 7) != 0) {
|
||||
if ((bits_in_buffer & 7) != 0) {
|
||||
/* bits_in_buffer may only be 0 or 8 */
|
||||
throw new InvalidOperationException("Bit buffer is not aligned!");
|
||||
}
|
||||
|
||||
@@ -37,7 +37,8 @@
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip {
|
||||
namespace ICSharpCode.SharpZipLib.Zip
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// This class contains constants used for zip.
|
||||
@@ -58,6 +59,9 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
public const int LOCNAM = 26;
|
||||
public const int LOCEXT = 28;
|
||||
|
||||
public const int SPANNINGSIG = 'P' | ('K' << 8) | (7 << 16) | (8 << 24);
|
||||
public const int SPANTEMPSIG = 'P' | ('K' << 8) | ('0' << 16) | ('0' << 24);
|
||||
|
||||
/* The Data descriptor */
|
||||
public const int EXTSIG = 'P' | ('K' << 8) | (7 << 16) | (8 << 24);
|
||||
public const int EXTHDR = 16;
|
||||
@@ -70,7 +74,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
public const int CENSIG = 'P' | ('K' << 8) | (1 << 16) | (2 << 24);
|
||||
|
||||
/* The central directory file header for 64bit ZIP*/
|
||||
public const int CENSIG64 = 0x06064b50;
|
||||
public const int CENSIG64 = 'P' | ('K' << 8) | (6 << 16) | (6 << 24);
|
||||
|
||||
public const int CENHDR = 46;
|
||||
|
||||
@@ -94,6 +98,9 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
public const int ENDSIG = 'P' | ('K' << 8) | (5 << 16) | (6 << 24);
|
||||
public const int ENDHDR = 22;
|
||||
|
||||
public const int HDRDIGITALSIG = 'P' | ('K' << 8) | (5 << 16) | (5 << 24);
|
||||
public const int CENDIGITALSIG = 'P' | ('K' << 8) | (5 << 16) | (5 << 24);
|
||||
|
||||
/* The following two fields are missing in SUN JDK */
|
||||
public const int ENDNRD = 4;
|
||||
public const int ENDDCD = 6;
|
||||
@@ -104,21 +111,36 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
public const int ENDOFF = 16;
|
||||
public const int ENDCOM = 20;
|
||||
|
||||
/* Using the codepage 1252 doesn't solve the 8bit ASCII problem :/
|
||||
any help would be appreciated.
|
||||
|
||||
// get encoding for latin characters (like ö, ü, ß or ô)
|
||||
static Encoding ecp1252 = Encoding.GetEncoding(1252);
|
||||
*/
|
||||
|
||||
static int defaultCodePage = 0; // 0 gives default code page, set it to whatever you like or alternatively alter it via property at runtime for more flexibility
|
||||
// Some care for compatability purposes is required as you can specify unicode code pages here.... if this way of working seems ok
|
||||
// then some protection may be added to make the interface a bit more robust perhaps.
|
||||
|
||||
public static int DefaultCodePage {
|
||||
get {
|
||||
return defaultCodePage;
|
||||
}
|
||||
set {
|
||||
defaultCodePage = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static string ConvertToString(byte[] data)
|
||||
{
|
||||
|
||||
return Encoding.ASCII.GetString(data);
|
||||
#if COMACT_FRAMEWORK
|
||||
return Encoding.ASCII.GetString(data,0, data.Length);
|
||||
#else
|
||||
return Encoding.GetEncoding(DefaultCodePage).GetString(data, 0, data.Length);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static byte[] ConvertToArray(string str)
|
||||
{
|
||||
#if COMACT_FRAMEWORK
|
||||
return Encoding.ASCII.GetBytes(str);
|
||||
#else
|
||||
return Encoding.GetEncoding(DefaultCodePage).GetBytes(str);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,8 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip {
|
||||
namespace ICSharpCode.SharpZipLib.Zip
|
||||
{
|
||||
|
||||
public enum CompressionMethod
|
||||
{
|
||||
@@ -60,22 +61,63 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
static int KNOWN_CRC = 4;
|
||||
static int KNOWN_TIME = 8;
|
||||
|
||||
DateTime cal = DateTime.Now;
|
||||
|
||||
string name;
|
||||
uint size;
|
||||
ushort version;
|
||||
uint compressedSize;
|
||||
int crc;
|
||||
uint crc;
|
||||
uint dosTime;
|
||||
|
||||
ushort known = 0;
|
||||
CompressionMethod method = CompressionMethod.Deflated;
|
||||
byte[] extra = null;
|
||||
string comment = null;
|
||||
bool isCrypted;
|
||||
|
||||
int zipFileIndex = -1; /* used by ZipFile */
|
||||
int flags; /* used by ZipOutputStream */
|
||||
int offset; /* used by ZipFile and ZipOutputStream */
|
||||
|
||||
public bool IsEncrypted {
|
||||
get {
|
||||
return (flags & 1) != 0;
|
||||
}
|
||||
set {
|
||||
if (value) {
|
||||
flags |= 1;
|
||||
} else {
|
||||
flags &= ~1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int ZipFileIndex {
|
||||
get {
|
||||
return zipFileIndex;
|
||||
}
|
||||
set {
|
||||
zipFileIndex = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int Offset {
|
||||
get {
|
||||
return offset;
|
||||
}
|
||||
set {
|
||||
offset = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int Flags { // Stops having two things represent same concept in class (flag isCrypted removed)
|
||||
get {
|
||||
return flags;
|
||||
}
|
||||
set {
|
||||
flags = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int zipFileIndex = -1; /* used by ZipFile */
|
||||
public int flags; /* used by ZipOutputStream */
|
||||
public int offset; /* used by ZipFile and ZipOutputStream */
|
||||
|
||||
/// <summary>
|
||||
/// Creates a zip entry with the given name.
|
||||
@@ -85,9 +127,10 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
/// </param>
|
||||
public ZipEntry(string name)
|
||||
{
|
||||
if (name == null) {
|
||||
if (name == null) {
|
||||
throw new System.ArgumentNullException("name");
|
||||
}
|
||||
this.DateTime = System.DateTime.Now;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@@ -99,72 +142,64 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
/// </param>
|
||||
public ZipEntry(ZipEntry e)
|
||||
{
|
||||
name = e.name;
|
||||
known = e.known;
|
||||
size = e.size;
|
||||
name = e.name;
|
||||
known = e.known;
|
||||
size = e.size;
|
||||
compressedSize = e.compressedSize;
|
||||
crc = e.crc;
|
||||
// time = e.time;
|
||||
method = e.method;
|
||||
extra = e.extra;
|
||||
comment = e.comment;
|
||||
crc = e.crc;
|
||||
dosTime = e.dosTime;
|
||||
method = e.method;
|
||||
extra = e.extra;
|
||||
comment = e.comment;
|
||||
}
|
||||
|
||||
public ushort Version {
|
||||
public int Version {
|
||||
get {
|
||||
return version;
|
||||
}
|
||||
set {
|
||||
version = value;
|
||||
version = (ushort)value;
|
||||
}
|
||||
}
|
||||
|
||||
public int DosTime {
|
||||
public long DosTime {
|
||||
get {
|
||||
// if ((known & KNOWN_TIME) == 0) {
|
||||
// return 0;
|
||||
// }
|
||||
lock (this) {
|
||||
return (cal.Year - 1980 & 0x7f) << 25 |
|
||||
(cal.Month + 1) << 21 |
|
||||
(cal.Day ) << 16 |
|
||||
(cal.Hour) << 11 |
|
||||
(cal.Minute) << 5 |
|
||||
(cal.Second) >> 1;
|
||||
if ((known & KNOWN_TIME) == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return dosTime;
|
||||
}
|
||||
}
|
||||
set {
|
||||
// Guard against invalid or missing date causing
|
||||
// IndexOutOfBoundsException.
|
||||
try {
|
||||
lock (this) {
|
||||
cal = CalculateDateTime(value);
|
||||
// time = (int) (cal.Millisecond / 1000L);
|
||||
}
|
||||
known |= (ushort)KNOWN_TIME;
|
||||
} catch (Exception) {
|
||||
/* Ignore illegal time stamp */
|
||||
known &= (ushort)~KNOWN_TIME;
|
||||
}
|
||||
this.dosTime = (uint)value;
|
||||
known |= (ushort)KNOWN_TIME;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the time of last modification of the entry.
|
||||
/// </summary>
|
||||
public DateTime DateTime {
|
||||
get {
|
||||
return cal;
|
||||
uint sec = 2 * (dosTime & 0x1f);
|
||||
uint min = (dosTime >> 5) & 0x3f;
|
||||
uint hrs = (dosTime >> 11) & 0x1f;
|
||||
uint day = (dosTime >> 16) & 0x1f;
|
||||
uint mon = ((dosTime >> 21) & 0xf);
|
||||
uint year = ((dosTime >> 25) & 0x7f) + 1980; /* since 1900 */
|
||||
return new System.DateTime((int)year, (int)mon, (int)day, (int)hrs, (int)min, (int)sec);
|
||||
}
|
||||
set {
|
||||
lock (this) {
|
||||
cal = value;
|
||||
// time = (int) (cal.Millisecond / 1000L);
|
||||
}
|
||||
known |= (ushort)KNOWN_TIME;
|
||||
DosTime = ((uint)value.Year - 1980 & 0x7f) << 25 |
|
||||
((uint)value.Month) << 21 |
|
||||
((uint)value.Day) << 16 |
|
||||
((uint)value.Hour) << 11 |
|
||||
((uint)value.Minute) << 5 |
|
||||
((uint)value.Second) >> 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns the entry name. The path components in the entry are
|
||||
/// always separated by slashes ('/').
|
||||
@@ -175,21 +210,21 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
}
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// Gets/Sets the time of last modification of the entry.
|
||||
// /// </summary>
|
||||
// /// <returns>
|
||||
// /// the time of last modification of the entry, or -1 if unknown.
|
||||
// /// </returns>
|
||||
// public long Time {
|
||||
// get {
|
||||
// return (known & KNOWN_TIME) != 0 ? time * 1000L : -1;
|
||||
// }
|
||||
// set {
|
||||
// this.time = (int) (value / 1000L);
|
||||
// this.known |= (ushort)KNOWN_TIME;
|
||||
// }
|
||||
// }
|
||||
// /// <summary>
|
||||
// /// Gets/Sets the time of last modification of the entry.
|
||||
// /// </summary>
|
||||
// /// <returns>
|
||||
// /// the time of last modification of the entry, or -1 if unknown.
|
||||
// /// </returns>
|
||||
// public long Time {
|
||||
// get {
|
||||
// return (known & KNOWN_TIME) != 0 ? time * 1000L : -1;
|
||||
// }
|
||||
// set {
|
||||
// this.time = (int) (value / 1000L);
|
||||
// this.known |= (ushort)KNOWN_TIME;
|
||||
// }
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the size of the uncompressed data.
|
||||
@@ -204,7 +239,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
get {
|
||||
return (known & KNOWN_SIZE) != 0 ? (long)size : -1L;
|
||||
}
|
||||
set {
|
||||
set {
|
||||
if (((ulong)value & 0xFFFFFFFF00000000L) != 0) {
|
||||
throw new ArgumentOutOfRangeException("size");
|
||||
}
|
||||
@@ -249,10 +284,11 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
return (known & KNOWN_CRC) != 0 ? crc & 0xffffffffL : -1L;
|
||||
}
|
||||
set {
|
||||
if (((ulong)crc & 0xffffffff00000000L) != 0) {
|
||||
if (((ulong)crc & 0xffffffff00000000L) != 0)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
this.crc = (int)value;
|
||||
this.crc = (uint)value;
|
||||
this.known |= (ushort)KNOWN_CRC;
|
||||
}
|
||||
}
|
||||
@@ -273,7 +309,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
return method;
|
||||
}
|
||||
set {
|
||||
this.method = value;
|
||||
this.method = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,13 +345,12 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
/* extended time stamp, unix format by Rainer Prem <[email protected]> */
|
||||
int flags = extra[pos];
|
||||
if ((flags & 1) != 0) {
|
||||
int iTime = ((extra[pos+1] & 0xff) |
|
||||
(extra[pos+2] & 0xff) << 8 |
|
||||
(extra[pos+3] & 0xff) << 16 |
|
||||
(extra[pos+4] & 0xff) << 24);
|
||||
int iTime = ((extra[pos+1] & 0xff) |
|
||||
(extra[pos+2] & 0xff) << 8 |
|
||||
(extra[pos+3] & 0xff) << 16 |
|
||||
(extra[pos+4] & 0xff) << 24);
|
||||
|
||||
cal = (new DateTime ( 1970, 1, 1, 0, 0, 0 ) +
|
||||
new TimeSpan ( 0, 0, 0, iTime, 0 )).ToLocalTime ();
|
||||
DateTime = (new DateTime ( 1970, 1, 1, 0, 0, 0 ) + new TimeSpan ( 0, 0, 0, iTime, 0 )).ToLocalTime ();
|
||||
known |= (ushort)KNOWN_TIME;
|
||||
}
|
||||
}
|
||||
@@ -342,7 +377,8 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
return comment;
|
||||
}
|
||||
set {
|
||||
if (value.Length > 0xffff) {
|
||||
if (value.Length > 0xffff)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
this.comment = value;
|
||||
@@ -360,6 +396,18 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
}
|
||||
}
|
||||
|
||||
/// <value>
|
||||
/// True, if the entry is encrypted.
|
||||
/// </value>
|
||||
public bool IsCrypted {
|
||||
get {
|
||||
return isCrypted;
|
||||
}
|
||||
set {
|
||||
isCrypted = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a copy of this zip entry.
|
||||
/// </summary>
|
||||
@@ -376,18 +424,5 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
DateTime CalculateDateTime(int dosTime)
|
||||
{
|
||||
int sec = 2 * (dosTime & 0x1f);
|
||||
int min = (dosTime >> 5) & 0x3f;
|
||||
int hrs = (dosTime >> 11) & 0x1f;
|
||||
int day = (dosTime >> 16) & 0x1f;
|
||||
int mon = ((dosTime >> 21) & 0xf);
|
||||
int year = ((dosTime >> 25) & 0x7f) + 1980; /* since 1900 */
|
||||
|
||||
return new DateTime(year, mon, day, hrs, min, sec);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,8 @@ using System.Text;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip {
|
||||
namespace ICSharpCode.SharpZipLib.Zip
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// This class represents a Zip archive. You can ask for the contained
|
||||
@@ -68,13 +69,13 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
/// static public void Main(string[] args)
|
||||
/// {
|
||||
/// ZipFile zFile = new ZipFile(args[0]);
|
||||
/// Console.WriteLine("Listing of : " + zFile.Name);
|
||||
/// Console.WriteLine("");
|
||||
/// Console.WriteLine("Raw Size Size Date Time Name");
|
||||
/// Console.WriteLine("-------- -------- -------- ------ ---------");
|
||||
/// //Console.WriteLine("Listing of : " + zFile.Name);
|
||||
/// //Console.WriteLine("");
|
||||
/// //Console.WriteLine("Raw Size Size Date Time Name");
|
||||
/// //Console.WriteLine("-------- -------- -------- ------ ---------");
|
||||
/// foreach (ZipEntry e in zFile) {
|
||||
/// DateTime d = e.DateTime;
|
||||
/// Console.WriteLine("{0, -10}{1, -10}{2} {3} {4}", e.Size, e.CompressedSize,
|
||||
/// //Console.WriteLine("{0, -10}{1, -10}{2} {3} {4}", e.Size, e.CompressedSize,
|
||||
/// d.ToString("dd-MM-yy"), d.ToString("t"),
|
||||
/// e.Name);
|
||||
/// }
|
||||
@@ -84,6 +85,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
public class ZipFile : IEnumerable
|
||||
{
|
||||
string name;
|
||||
string comment;
|
||||
Stream baseStream;
|
||||
ZipEntry[] entries;
|
||||
|
||||
@@ -203,6 +205,12 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
|
||||
int centralOffset = ReadLeInt();
|
||||
|
||||
// GET COMMENT SIZE (COMES AFTER CENTRALOFFSET)
|
||||
int commentSize = ReadLeShort();
|
||||
byte[] zipComment = new byte[commentSize];
|
||||
baseStream.Read(zipComment, 0, zipComment.Length);
|
||||
comment = ZipConstants.ConvertToString(zipComment);
|
||||
|
||||
entries = new ZipEntry[count];
|
||||
baseStream.Seek(centralOffset, SeekOrigin.Begin);
|
||||
for (int i = 0; i < count; i++) {
|
||||
@@ -242,7 +250,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
entry.Crc = crc & 0xffffffffL;
|
||||
entry.Size = size & 0xffffffffL;
|
||||
entry.CompressedSize = csize & 0xffffffffL;
|
||||
entry.DosTime = dostime;
|
||||
entry.DosTime = (uint)dostime;
|
||||
if (extraLen > 0) {
|
||||
byte[] extra = new byte[extraLen];
|
||||
baseStream.Read(extra, 0, extraLen);
|
||||
@@ -252,8 +260,8 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
baseStream.Read(buffer, 0, commentLen);
|
||||
entry.Comment = ZipConstants.ConvertToString(buffer);
|
||||
}
|
||||
entry.zipFileIndex = i;
|
||||
entry.offset = offset;
|
||||
entry.ZipFileIndex = i;
|
||||
entry.Offset = offset;
|
||||
entries[i] = entry;
|
||||
}
|
||||
}
|
||||
@@ -293,7 +301,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return -1; // ok
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -330,7 +338,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
long CheckLocalHeader(ZipEntry entry)
|
||||
{
|
||||
lock(baseStream) {
|
||||
baseStream.Seek(entry.offset, SeekOrigin.Begin);
|
||||
baseStream.Seek(entry.Offset, SeekOrigin.Begin);
|
||||
if (ReadLeInt() != ZipConstants.LOCSIG) {
|
||||
throw new ZipException("Wrong Local header signature");
|
||||
}
|
||||
@@ -359,7 +367,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
}
|
||||
|
||||
int extraLen = entry.Name.Length + ReadLeShort();
|
||||
return entry.offset + ZipConstants.LOCHDR + extraLen;
|
||||
return entry.Offset + ZipConstants.LOCHDR + extraLen;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,7 +391,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
throw new InvalidOperationException("ZipFile has closed");
|
||||
}
|
||||
|
||||
int index = entry.zipFileIndex;
|
||||
int index = entry.ZipFileIndex;
|
||||
if (index < 0 || index >= entries.Length || entries[index].Name != entry.Name) {
|
||||
index = GetEntryIndex(entry.Name);
|
||||
if (index < 0) {
|
||||
@@ -404,6 +412,15 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The comment for the whole zip file.
|
||||
/// </summary>
|
||||
public string ZipFileComment {
|
||||
get {
|
||||
return comment;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the name of this zip file.
|
||||
/// </summary>
|
||||
@@ -465,7 +482,8 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
end = start + len;
|
||||
}
|
||||
|
||||
public override int Available {
|
||||
public override int Available
|
||||
{
|
||||
get {
|
||||
long amount = end - filepos;
|
||||
if (amount > Int32.MaxValue) {
|
||||
@@ -479,8 +497,9 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
public override int ReadByte()
|
||||
{
|
||||
if (filepos == end) {
|
||||
return -1;
|
||||
return -1; //ok
|
||||
}
|
||||
|
||||
lock(baseStream) {
|
||||
baseStream.Seek(filepos++, SeekOrigin.Begin);
|
||||
return baseStream.ReadByte();
|
||||
@@ -492,7 +511,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
if (len > end - filepos) {
|
||||
len = (int) (end - filepos);
|
||||
if (len == 0) {
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
lock(baseStream) {
|
||||
|
||||
@@ -43,8 +43,8 @@ using ICSharpCode.SharpZipLib.Checksums;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip {
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip
|
||||
{
|
||||
/// <summary>
|
||||
/// This is a FilterInputStream that reads the files baseInputStream an zip archive
|
||||
/// one after another. It has a special method to get the zip entry of
|
||||
@@ -55,7 +55,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
/// author of the original java version : Jochen Hoenicke
|
||||
/// </summary>
|
||||
/// <example> This sample shows how to read a zip file
|
||||
/// <code>
|
||||
/// <code lang="C#">
|
||||
/// using System;
|
||||
/// using System.Text;
|
||||
/// using System.IO;
|
||||
@@ -70,7 +70,6 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
///
|
||||
/// ZipEntry theEntry;
|
||||
/// while ((theEntry = s.GetNextEntry()) != null) {
|
||||
/// Console.WriteLine("File " + theEntry.Name);
|
||||
/// int size = 2048;
|
||||
/// byte[] data = new byte[2048];
|
||||
///
|
||||
@@ -85,7 +84,6 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// Console.WriteLine();
|
||||
/// }
|
||||
/// s.Close();
|
||||
/// }
|
||||
@@ -94,34 +92,42 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
/// </example>
|
||||
public class ZipInputStream : InflaterInputStream
|
||||
{
|
||||
private Crc32 crc = new Crc32();
|
||||
private ZipEntry entry = null;
|
||||
Crc32 crc = new Crc32();
|
||||
ZipEntry entry = null;
|
||||
|
||||
private long csize;
|
||||
private long size;
|
||||
private int method;
|
||||
private int flags;
|
||||
private long avail;
|
||||
long size;
|
||||
int method;
|
||||
int flags;
|
||||
long avail;
|
||||
string password = null;
|
||||
|
||||
public string Password {
|
||||
get {
|
||||
return password;
|
||||
}
|
||||
set {
|
||||
password = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Zip input stream, reading a zip archive.
|
||||
/// </summary>
|
||||
public ZipInputStream(Stream baseInputStream) : base(baseInputStream, new Inflater(true))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void FillBuf()
|
||||
void FillBuf()
|
||||
{
|
||||
avail = len = baseInputStream.Read(buf, 0, buf.Length);
|
||||
}
|
||||
|
||||
private int ReadBuf(byte[] outBuf, int offset, int length)
|
||||
int ReadBuf(byte[] outBuf, int offset, int length)
|
||||
{
|
||||
if (avail <= 0) {
|
||||
FillBuf();
|
||||
if (avail <= 0) {
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (length > avail) {
|
||||
@@ -132,7 +138,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
return length;
|
||||
}
|
||||
|
||||
private void ReadFully(byte[] outBuf)
|
||||
void ReadFully(byte[] outBuf)
|
||||
{
|
||||
int off = 0;
|
||||
int len = outBuf.Length;
|
||||
@@ -146,7 +152,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
}
|
||||
}
|
||||
|
||||
private int ReadLeByte()
|
||||
int ReadLeByte()
|
||||
{
|
||||
if (avail <= 0) {
|
||||
FillBuf();
|
||||
@@ -160,7 +166,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
/// <summary>
|
||||
/// Read an unsigned short baseInputStream little endian byte order.
|
||||
/// </summary>
|
||||
private int ReadLeShort()
|
||||
int ReadLeShort()
|
||||
{
|
||||
return ReadLeByte() | (ReadLeByte() << 8);
|
||||
}
|
||||
@@ -168,7 +174,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
/// <summary>
|
||||
/// Read an int baseInputStream little endian byte order.
|
||||
/// </summary>
|
||||
private int ReadLeInt()
|
||||
int ReadLeInt()
|
||||
{
|
||||
return ReadLeShort() | (ReadLeShort() << 16);
|
||||
}
|
||||
@@ -176,7 +182,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
/// <summary>
|
||||
/// Read an int baseInputStream little endian byte order.
|
||||
/// </summary>
|
||||
private long ReadLeLong()
|
||||
long ReadLeLong()
|
||||
{
|
||||
return ReadLeInt() | (ReadLeInt() << 32);
|
||||
}
|
||||
@@ -194,28 +200,48 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
CloseEntry();
|
||||
}
|
||||
|
||||
if (this.cryptbuffer != null) {
|
||||
if (avail == 0 && inf.RemainingInput != 0) {
|
||||
avail = inf.RemainingInput - 16;
|
||||
inf.Reset();
|
||||
}
|
||||
baseInputStream.Position -= this.len;
|
||||
baseInputStream.Read(this.buf, 0, this.len);
|
||||
}
|
||||
|
||||
int header = ReadLeInt();
|
||||
if (header == ZipConstants.CENSIG) {
|
||||
/* Central Header reached. */
|
||||
|
||||
// -jr- added end sig for empty zip files, Zip64 end sig and digital sig for files that have them...
|
||||
if (header == ZipConstants.CENSIG ||
|
||||
header == ZipConstants.ENDSIG ||
|
||||
header == ZipConstants.CENDIGITALSIG ||
|
||||
header == ZipConstants.CENSIG64) {
|
||||
// Central Header reached or end of empty zip file
|
||||
Close();
|
||||
return null;
|
||||
}
|
||||
// -jr- 07-Dec-2003 ignore spanning temporary signatures if found
|
||||
// SPANNINGSIG is same as descriptor signature and is untested as yet.
|
||||
if (header == ZipConstants.SPANTEMPSIG || header == ZipConstants.SPANNINGSIG) {
|
||||
header = ReadLeInt();
|
||||
}
|
||||
|
||||
if (header != ZipConstants.LOCSIG) {
|
||||
throw new ZipException("Wrong Local header signature" + header);
|
||||
throw new ZipException("Wrong Local header signature: 0x" + String.Format("{0:X}", header));
|
||||
}
|
||||
|
||||
short version = (short)ReadLeShort();
|
||||
|
||||
flags = ReadLeShort();
|
||||
method = ReadLeShort();
|
||||
int dostime = ReadLeInt();
|
||||
uint dostime = (uint)ReadLeInt();
|
||||
int crc2 = ReadLeInt();
|
||||
csize = ReadLeInt();
|
||||
size = ReadLeInt();
|
||||
int nameLen = ReadLeShort();
|
||||
int extraLen = ReadLeShort();
|
||||
|
||||
if (method == ZipOutputStream.STORED && csize != size) {
|
||||
bool isCrypted = (flags & 1) == 1;
|
||||
if (method == ZipOutputStream.STORED && (!isCrypted && csize != size || (isCrypted && csize - 12 != size))) {
|
||||
throw new ZipException("Stored, but compressed != uncompressed");
|
||||
}
|
||||
|
||||
@@ -225,7 +251,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
string name = ZipConstants.ConvertToString(buffer);
|
||||
|
||||
entry = new ZipEntry(name);
|
||||
|
||||
entry.IsCrypted = isCrypted;
|
||||
entry.Version = (ushort)version;
|
||||
if (method != 0 && method != 8) {
|
||||
throw new ZipException("unknown compression method " + method);
|
||||
@@ -237,22 +263,43 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
entry.Size = size & 0xFFFFFFFFL;
|
||||
entry.CompressedSize = csize & 0xFFFFFFFFL;
|
||||
}
|
||||
|
||||
entry.DosTime = dostime;
|
||||
|
||||
if (extraLen > 0) {
|
||||
byte[] extra = new byte[extraLen];
|
||||
ReadFully(extra);
|
||||
entry.ExtraData = extra;
|
||||
}
|
||||
|
||||
// test for encryption
|
||||
if (isCrypted) {
|
||||
if (password == null) {
|
||||
throw new ZipException("No password set.");
|
||||
}
|
||||
InitializePassword(password);
|
||||
cryptbuffer = new byte[12];
|
||||
ReadFully(cryptbuffer);
|
||||
DecryptBlock(cryptbuffer, 0, cryptbuffer.Length);
|
||||
if ((flags & 8) == 0) {// -jr- 10-Feb-2004 Dont yet know correct size here....
|
||||
csize -= 12;
|
||||
}
|
||||
} else {
|
||||
cryptbuffer = null;
|
||||
}
|
||||
|
||||
if (method == ZipOutputStream.DEFLATED && avail > 0) {
|
||||
System.Array.Copy(buf, len - (int)avail, buf, 0, (int)avail);
|
||||
len = (int)avail;
|
||||
avail = 0;
|
||||
if (isCrypted) {
|
||||
DecryptBlock(buf, 0, Math.Min((int)csize, len));
|
||||
}
|
||||
inf.SetInput(buf, 0, len);
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
private void ReadDataDescr()
|
||||
{
|
||||
if (ReadLeInt() != ZipConstants.EXTSIG) {
|
||||
@@ -273,6 +320,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
if (crc == null) {
|
||||
throw new InvalidOperationException("Closed.");
|
||||
}
|
||||
|
||||
if (entry == null) {
|
||||
return;
|
||||
}
|
||||
@@ -335,7 +383,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
{
|
||||
byte[] b = new byte[1];
|
||||
if (Read(b, 0, 1) <= 0) {
|
||||
return -1;
|
||||
return -1; // ok
|
||||
}
|
||||
return b[0] & 0xff;
|
||||
}
|
||||
@@ -355,24 +403,23 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
if (crc == null) {
|
||||
throw new InvalidOperationException("Closed.");
|
||||
}
|
||||
|
||||
if (entry == null) {
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
bool finished = false;
|
||||
|
||||
switch (method) {
|
||||
case ZipOutputStream.DEFLATED:
|
||||
len = base.Read(b, off, len);
|
||||
if (len < 0) {
|
||||
if (len <= 0) { // TODO BUG1 -jr- Check this was < 0 but avail was not adjusted causing failure in later calls
|
||||
if (!inf.IsFinished) {
|
||||
throw new ZipException("Inflater not finished!?");
|
||||
}
|
||||
avail = inf.RemainingInput;
|
||||
if ((flags & 8) != 0) {
|
||||
ReadDataDescr();
|
||||
}
|
||||
|
||||
if (inf.TotalIn != csize || inf.TotalOut != size) {
|
||||
// BUG1 -jr- With bit 3 set you dont yet know the size
|
||||
if ((flags & 8) == 0 && (inf.TotalIn != csize || inf.TotalOut != size)) {
|
||||
throw new ZipException("size mismatch: " + csize + ";" + size + " <-> " + inf.TotalIn + ";" + inf.TotalOut);
|
||||
}
|
||||
inf.Reset();
|
||||
@@ -381,7 +428,6 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
break;
|
||||
|
||||
case ZipOutputStream.STORED:
|
||||
|
||||
if (len > csize && csize >= 0) {
|
||||
len = (int)csize;
|
||||
}
|
||||
@@ -398,15 +444,25 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
throw new ZipException("EOF in stored block");
|
||||
}
|
||||
}
|
||||
|
||||
// decrypting crypted data
|
||||
if (cryptbuffer != null) {
|
||||
DecryptBlock(b, off, len);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (len > 0) {
|
||||
crc.Update(b, off, len);
|
||||
}
|
||||
|
||||
if (finished) {
|
||||
if ((crc.Value & 0xFFFFFFFFL) != entry.Crc) {
|
||||
if ((flags & 8) != 0) {
|
||||
ReadDataDescr();
|
||||
}
|
||||
|
||||
if ((crc.Value & 0xFFFFFFFFL) != entry.Crc && entry.Crc != -1) {
|
||||
throw new ZipException("CRC mismatch");
|
||||
}
|
||||
crc.Reset();
|
||||
@@ -427,5 +483,6 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
crc = null;
|
||||
entry = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -44,8 +44,8 @@ using ICSharpCode.SharpZipLib.Checksums;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip {
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip
|
||||
{
|
||||
/// <summary>
|
||||
/// This is a FilterOutputStream that writes the files into a zip
|
||||
/// archive one after another. It has a special method to start a new
|
||||
@@ -107,7 +107,6 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
private byte[] zipComment = new byte[0];
|
||||
private int defaultMethod = DEFLATED;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Our Zip version is hard coded to 1.0 resp. 2.0
|
||||
/// </summary>
|
||||
@@ -212,6 +211,14 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
|
||||
|
||||
bool shouldWriteBack = false;
|
||||
// -jr- Having a hard coded flag for seek capability requires this so users can determine
|
||||
// if the entries will be patched or not.
|
||||
public bool CanPatchEntries {
|
||||
get {
|
||||
return baseOutputStream.CanSeek;
|
||||
}
|
||||
}
|
||||
|
||||
long seekPos = -1;
|
||||
/// <summary>
|
||||
/// Starts a new Zip entry. It automatically closes the previous
|
||||
@@ -237,7 +244,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
|
||||
CompressionMethod method = entry.CompressionMethod;
|
||||
int flags = 0;
|
||||
|
||||
entry.IsCrypted = Password != null;
|
||||
switch (method) {
|
||||
case CompressionMethod.Stored:
|
||||
if (entry.CompressedSize >= 0) {
|
||||
@@ -250,6 +257,10 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
entry.CompressedSize = entry.Size;
|
||||
}
|
||||
|
||||
if (entry.IsCrypted) {
|
||||
entry.CompressedSize += 12;
|
||||
}
|
||||
|
||||
if (entry.Size < 0) {
|
||||
throw new ZipException("Method STORED, but size not set");
|
||||
} else if (entry.Crc < 0) {
|
||||
@@ -267,12 +278,14 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
CloseEntry();
|
||||
}
|
||||
|
||||
// if (entry.DosTime < 0) {
|
||||
// entry.Time = System.Environment.TickCount;
|
||||
// }
|
||||
|
||||
entry.flags = flags;
|
||||
entry.offset = offset;
|
||||
// if (entry.DosTime < 0) {
|
||||
// entry.Time = System.Environment.TickCount;
|
||||
// }
|
||||
if (entry.IsCrypted) {
|
||||
flags |= 1;
|
||||
}
|
||||
entry.Flags = flags;
|
||||
entry.Offset = offset;
|
||||
entry.CompressionMethod = (CompressionMethod)method;
|
||||
|
||||
curMethod = method;
|
||||
@@ -284,7 +297,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
if ((flags & 8) == 0) {
|
||||
WriteLeShort(flags);
|
||||
WriteLeShort((byte)method);
|
||||
WriteLeInt(entry.DosTime);
|
||||
WriteLeInt((int)entry.DosTime);
|
||||
WriteLeInt((int)entry.Crc);
|
||||
WriteLeInt((int)entry.CompressedSize);
|
||||
WriteLeInt((int)entry.Size);
|
||||
@@ -297,8 +310,10 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
WriteLeShort(flags);
|
||||
}
|
||||
WriteLeShort((byte)method);
|
||||
WriteLeInt(entry.DosTime);
|
||||
seekPos = baseOutputStream.Position;
|
||||
WriteLeInt((int)entry.DosTime);
|
||||
if (baseOutputStream.CanSeek) {
|
||||
seekPos = baseOutputStream.Position;
|
||||
}
|
||||
WriteLeInt(0);
|
||||
WriteLeInt(0);
|
||||
WriteLeInt(0);
|
||||
@@ -321,6 +336,16 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
baseOutputStream.Write(name, 0, name.Length);
|
||||
baseOutputStream.Write(extra, 0, extra.Length);
|
||||
|
||||
if (Password != null) {
|
||||
InitializePassword(Password);
|
||||
byte[] cryptbuffer = new byte[12];
|
||||
Random rnd = new Random();
|
||||
for (int i = 0; i < cryptbuffer.Length; ++i) {
|
||||
cryptbuffer[i] = (byte)rnd.Next();
|
||||
}
|
||||
EncryptBlock(cryptbuffer, 0, cryptbuffer.Length);
|
||||
baseOutputStream.Write(cryptbuffer, 0, cryptbuffer.Length);
|
||||
}
|
||||
offset += ZipConstants.LOCHDR + name.Length + extra.Length;
|
||||
|
||||
/* Activate the entry. */
|
||||
@@ -357,30 +382,33 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
if (curEntry.Size < 0) {
|
||||
curEntry.Size = size;
|
||||
} else if (curEntry.Size != size) {
|
||||
throw new ZipException("size was " + size +
|
||||
", but I expected " + curEntry.Size);
|
||||
throw new ZipException("size was " + size + ", but I expected " + curEntry.Size);
|
||||
}
|
||||
|
||||
if (curEntry.IsCrypted) {
|
||||
csize += 12;
|
||||
}
|
||||
|
||||
if (curEntry.CompressedSize < 0) {
|
||||
curEntry.CompressedSize = csize;
|
||||
} else if (curEntry.CompressedSize != csize) {
|
||||
throw new ZipException("compressed size was " + csize +
|
||||
", but I expected " + curEntry.CompressedSize);
|
||||
throw new ZipException("compressed size was " + csize + ", but I expected " + curEntry.CompressedSize);
|
||||
}
|
||||
|
||||
if (curEntry.Crc < 0) {
|
||||
curEntry.Crc = crc.Value;
|
||||
} else if (curEntry.Crc != crc.Value) {
|
||||
throw new ZipException("crc was " + crc.Value +
|
||||
", but I expected " +
|
||||
curEntry.Crc);
|
||||
", but I expected " +
|
||||
curEntry.Crc);
|
||||
}
|
||||
|
||||
offset += csize;
|
||||
|
||||
/* Now write the data descriptor entry if needed. */
|
||||
if (curMethod == CompressionMethod.Deflated && (curEntry.flags & 8) != 0) {
|
||||
if (curMethod == CompressionMethod.Deflated && (curEntry.Flags & 8) != 0) {
|
||||
if (shouldWriteBack) {
|
||||
curEntry.Flags &= ~8;
|
||||
long curPos = baseOutputStream.Position;
|
||||
baseOutputStream.Seek(seekPos, SeekOrigin.Begin);
|
||||
WriteLeInt((int)curEntry.Crc);
|
||||
@@ -400,8 +428,7 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
entries.Add(curEntry);
|
||||
curEntry = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Writes the given buffer to the current entry.
|
||||
/// </summary>
|
||||
@@ -422,15 +449,21 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
base.Write(b, off, len);
|
||||
break;
|
||||
case CompressionMethod.Stored:
|
||||
baseOutputStream.Write(b, off, len);
|
||||
if (Password != null) {
|
||||
byte[] buf = new byte[len];
|
||||
Array.Copy(b, off, buf, 0, len);
|
||||
EncryptBlock(buf, 0, len);
|
||||
baseOutputStream.Write(buf, off, len);
|
||||
} else {
|
||||
baseOutputStream.Write(b, off, len);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
crc.Update(b, off, len);
|
||||
|
||||
size += len;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Finishes the stream. This will write the central directory at the
|
||||
/// end of the zip file and flush the stream.
|
||||
@@ -438,72 +471,80 @@ namespace ICSharpCode.SharpZipLib.Zip {
|
||||
/// <exception cref="System.IO.IOException">
|
||||
/// if an I/O error occured.
|
||||
/// </exception>
|
||||
public override void Finish()
|
||||
{
|
||||
if (entries == null) {
|
||||
return;
|
||||
}
|
||||
if (curEntry != null) {
|
||||
CloseEntry();
|
||||
}
|
||||
|
||||
int numEntries = 0;
|
||||
int sizeEntries = 0;
|
||||
|
||||
foreach (ZipEntry entry in entries) {
|
||||
// TODO : check the appnote file for compilance with the central directory standard
|
||||
CompressionMethod method = entry.CompressionMethod;
|
||||
WriteLeInt(ZipConstants.CENSIG);
|
||||
WriteLeShort(method == CompressionMethod.Stored ? ZIP_STORED_VERSION : ZIP_DEFLATED_VERSION);
|
||||
WriteLeShort(method == CompressionMethod.Stored ? ZIP_STORED_VERSION : ZIP_DEFLATED_VERSION);
|
||||
WriteLeShort(entry.flags);
|
||||
WriteLeShort((short)method);
|
||||
WriteLeInt(entry.DosTime);
|
||||
WriteLeInt((int)entry.Crc);
|
||||
WriteLeInt((int)entry.CompressedSize);
|
||||
WriteLeInt((int)entry.Size);
|
||||
|
||||
byte[] name = ZipConstants.ConvertToArray(entry.Name);
|
||||
|
||||
if (name.Length > 0xffff) {
|
||||
throw new ZipException("Name too long.");
|
||||
}
|
||||
byte[] extra = entry.ExtraData;
|
||||
if (extra == null) {
|
||||
extra = new byte[0];
|
||||
}
|
||||
string strComment = entry.Comment;
|
||||
byte[] comment = strComment != null ? ZipConstants.ConvertToArray(strComment) : new byte[0];
|
||||
if (comment.Length > 0xffff) {
|
||||
throw new ZipException("Comment too long.");
|
||||
}
|
||||
|
||||
WriteLeShort(name.Length);
|
||||
WriteLeShort(extra.Length);
|
||||
WriteLeShort(comment.Length);
|
||||
WriteLeShort(0); /* disk number */
|
||||
WriteLeShort(0); /* internal file attr */
|
||||
WriteLeInt(0); /* external file attr */
|
||||
WriteLeInt(entry.offset);
|
||||
|
||||
baseOutputStream.Write(name, 0, name.Length);
|
||||
baseOutputStream.Write(extra, 0, extra.Length);
|
||||
baseOutputStream.Write(comment, 0, comment.Length);
|
||||
++numEntries;
|
||||
sizeEntries += ZipConstants.CENHDR + name.Length + extra.Length + comment.Length;
|
||||
}
|
||||
|
||||
WriteLeInt(ZipConstants.ENDSIG);
|
||||
WriteLeShort(0); /* disk number */
|
||||
WriteLeShort(0); /* disk with start of central dir */
|
||||
WriteLeShort(numEntries);
|
||||
WriteLeShort(numEntries);
|
||||
WriteLeInt(sizeEntries);
|
||||
WriteLeInt(offset);
|
||||
WriteLeShort(zipComment.Length);
|
||||
baseOutputStream.Write(zipComment, 0, zipComment.Length);
|
||||
baseOutputStream.Flush();
|
||||
entries = null;
|
||||
}
|
||||
public override void Finish()
|
||||
{
|
||||
if (entries == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (curEntry != null) {
|
||||
CloseEntry();
|
||||
}
|
||||
|
||||
int numEntries = 0;
|
||||
int sizeEntries = 0;
|
||||
|
||||
foreach (ZipEntry entry in entries) {
|
||||
// TODO : check the appnote file for compilance with the central directory standard
|
||||
CompressionMethod method = entry.CompressionMethod;
|
||||
WriteLeInt(ZipConstants.CENSIG);
|
||||
WriteLeShort(method == CompressionMethod.Stored ? ZIP_STORED_VERSION : ZIP_DEFLATED_VERSION);
|
||||
WriteLeShort(method == CompressionMethod.Stored ? ZIP_STORED_VERSION : ZIP_DEFLATED_VERSION);
|
||||
|
||||
WriteLeShort(entry.Flags);
|
||||
WriteLeShort((short)method);
|
||||
WriteLeInt((int)entry.DosTime);
|
||||
WriteLeInt((int)entry.Crc);
|
||||
WriteLeInt((int)entry.CompressedSize);
|
||||
WriteLeInt((int)entry.Size);
|
||||
|
||||
byte[] name = ZipConstants.ConvertToArray(entry.Name);
|
||||
|
||||
if (name.Length > 0xffff) {
|
||||
throw new ZipException("Name too long.");
|
||||
}
|
||||
|
||||
byte[] extra = entry.ExtraData;
|
||||
if (extra == null) {
|
||||
extra = new byte[0];
|
||||
}
|
||||
|
||||
string strComment = entry.Comment;
|
||||
byte[] comment = strComment != null ? ZipConstants.ConvertToArray(strComment) : new byte[0];
|
||||
if (comment.Length > 0xffff) {
|
||||
throw new ZipException("Comment too long.");
|
||||
}
|
||||
|
||||
WriteLeShort(name.Length);
|
||||
WriteLeShort(extra.Length);
|
||||
WriteLeShort(comment.Length);
|
||||
WriteLeShort(0); // disk number
|
||||
WriteLeShort(0); // internal file attr
|
||||
if (entry.IsDirectory) { // -jr- 17-12-2003 mark entry as directory (from nikolam.AT.perfectinfo.com)
|
||||
WriteLeInt(16);
|
||||
} else {
|
||||
WriteLeInt(0); // external file attr
|
||||
}
|
||||
WriteLeInt(entry.Offset);
|
||||
|
||||
baseOutputStream.Write(name, 0, name.Length);
|
||||
baseOutputStream.Write(extra, 0, extra.Length);
|
||||
baseOutputStream.Write(comment, 0, comment.Length);
|
||||
++numEntries;
|
||||
sizeEntries += ZipConstants.CENHDR + name.Length + extra.Length + comment.Length;
|
||||
}
|
||||
|
||||
WriteLeInt(ZipConstants.ENDSIG);
|
||||
WriteLeShort(0); // disk number
|
||||
WriteLeShort(0); // disk with start of central dir
|
||||
WriteLeShort(numEntries);
|
||||
WriteLeShort(numEntries);
|
||||
WriteLeInt(sizeEntries);
|
||||
WriteLeInt(offset);
|
||||
WriteLeShort(zipComment.Length);
|
||||
baseOutputStream.Write(zipComment, 0, zipComment.Length);
|
||||
baseOutputStream.Flush();
|
||||
entries = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,8 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib {
|
||||
namespace ICSharpCode.SharpZipLib
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Is thrown during the creation or input of a zip file.
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
I imported the 0.6 version of the library. The only changes from the origional were
|
||||
the case of some of the file names -- I changed them to match the names in cvs.
|
||||
|
||||
Ben Maurer. May, 2004.
|
||||
|
||||
--------------------
|
||||
|
||||
This directory contains a local copy of the Zip library from the NZipLib project.
|
||||
|
||||
I have added this as a temporary measure to simplify the building and development
|
||||
|
||||
Binary file not shown.
@@ -1,3 +1,11 @@
|
||||
2004-05-28 Cesar Lopez Nataren <[email protected]>
|
||||
|
||||
* Statement.cs: changed parent_is_itr_stm method to ParentIsItrStm
|
||||
property. Added initial pieces for Break's Resolve. Fixed bug that
|
||||
did not let Emit the code for case clauses that came after the
|
||||
default clause (we match the jsc behavior).
|
||||
* jscript-lexer-parser.g: set parent of switch's clauses.
|
||||
|
||||
2004-05-27 Cesar Lopez Nataren <[email protected]>
|
||||
|
||||
* Statement.cs: added parent as a parameter on Continue constructor. Added parent_is_itr_stm
|
||||
|
||||
@@ -915,16 +915,27 @@ _loop15_breakloop: ;
|
||||
|
||||
match(LITERAL_switch);
|
||||
match(OPEN_PARENS);
|
||||
exp=expr(parent);
|
||||
exp=expr(sw);
|
||||
match(CLOSE_PARENS);
|
||||
clauses=case_block(parent);
|
||||
clauses=case_block(sw);
|
||||
if (0==inputState.guessing)
|
||||
{
|
||||
|
||||
sw.exp = exp;
|
||||
exp.parent = sw;
|
||||
|
||||
sw.case_clauses = clauses [0];
|
||||
sw.default_clauses = clauses [1];
|
||||
sw.sec_case_clauses = clauses [2];
|
||||
|
||||
foreach (Clause cc in sw.case_clauses)
|
||||
foreach (AST ast in cc.stm_list)
|
||||
ast.parent = sw;
|
||||
foreach (AST dc in sw.default_clauses)
|
||||
dc.parent = sw;
|
||||
foreach (Clause cc in sw.case_clauses)
|
||||
foreach (AST ast in cc.stm_list)
|
||||
ast.parent = sw;
|
||||
|
||||
}
|
||||
return sw;
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace Microsoft.JScript {
|
||||
|
||||
internal override bool Resolve (IdentificationTable context)
|
||||
{
|
||||
if ((parent == null || (!parent_is_itr_stm ())) && identifier == string.Empty)
|
||||
if ((parent == null || !ParentIsItrStm) && identifier == string.Empty)
|
||||
throw new Exception ("A continue can't be outside a iteration stm");
|
||||
return false;
|
||||
}
|
||||
@@ -104,11 +104,12 @@ namespace Microsoft.JScript {
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
private bool parent_is_itr_stm ()
|
||||
{
|
||||
if (parent is DoWhile || parent is While || parent is For || parent is ForIn)
|
||||
return true;
|
||||
return false;
|
||||
private bool ParentIsItrStm {
|
||||
get {
|
||||
if (parent is DoWhile || parent is While || parent is For || parent is ForIn)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +124,17 @@ namespace Microsoft.JScript {
|
||||
|
||||
internal override bool Resolve (IdentificationTable context)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
if ((parent == null || !ParentIsCorrect) && identifier == string.Empty)
|
||||
throw new Exception ("A break statement can't be outside a switch or iteration stm");
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool ParentIsCorrect {
|
||||
get {
|
||||
if (parent is DoWhile || parent is While || parent is For || parent is ForIn || parent is Switch)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
internal override void Emit (EmitContext ec)
|
||||
@@ -332,25 +343,45 @@ namespace Microsoft.JScript {
|
||||
{
|
||||
if (exp != null)
|
||||
exp.Emit (ec);
|
||||
|
||||
ILGenerator ig = ec.ig;
|
||||
Label init_default = ig.DefineLabel ();
|
||||
Label end_of_default = ig.DefineLabel ();
|
||||
|
||||
LocalBuilder loc = ig.DeclareLocal (typeof (object));
|
||||
ig.Emit (OpCodes.Stloc, loc);
|
||||
|
||||
foreach (Clause c in case_clauses) {
|
||||
ig.Emit (OpCodes.Ldloc, loc);
|
||||
c.EmitConditional (ec);
|
||||
}
|
||||
Label end = ig.DefineLabel ();
|
||||
ig.Emit (OpCodes.Br, end);
|
||||
|
||||
/* emit conditionals from clauses that come after the default clause */
|
||||
if (sec_case_clauses != null && sec_case_clauses.Count > 0) {
|
||||
foreach (Clause c in sec_case_clauses) {
|
||||
ig.Emit (OpCodes.Ldloc, loc);
|
||||
c.EmitConditional (ec);
|
||||
}
|
||||
}
|
||||
ig.Emit (OpCodes.Br, init_default);
|
||||
|
||||
/* emit the stms from case_clauses */
|
||||
foreach (Clause c in case_clauses) {
|
||||
ig.MarkLabel (c.matched_block);
|
||||
c.EmitStms (ec);
|
||||
}
|
||||
ig.MarkLabel (end);
|
||||
|
||||
ig.MarkLabel (init_default);
|
||||
foreach (AST ast in default_clauses)
|
||||
ast.Emit (ec);
|
||||
// FIXME: clauses after default clause are not being generated.
|
||||
foreach (Clause sc in sec_case_clauses)
|
||||
sc.Emit (ec);
|
||||
ig.MarkLabel (end_of_default);
|
||||
|
||||
if (sec_case_clauses != null && sec_case_clauses.Count > 0) {
|
||||
foreach (Clause c in sec_case_clauses) {
|
||||
ig.MarkLabel (c.matched_block);
|
||||
c.EmitStms (ec);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,6 +424,6 @@ namespace Microsoft.JScript {
|
||||
|
||||
internal override void Emit (EmitContext ec)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,12 +159,23 @@ switch_stm [AST parent] returns [Switch sw]
|
||||
AST exp = null;
|
||||
ArrayList [] clauses = null;
|
||||
}
|
||||
: "switch" OPEN_PARENS exp = expr [parent] CLOSE_PARENS clauses = case_block [parent]
|
||||
: "switch" OPEN_PARENS exp = expr [sw] CLOSE_PARENS clauses = case_block [sw]
|
||||
{
|
||||
sw.exp = exp;
|
||||
exp.parent = sw;
|
||||
|
||||
sw.case_clauses = clauses [0];
|
||||
sw.default_clauses = clauses [1];
|
||||
sw.sec_case_clauses = clauses [2];
|
||||
|
||||
foreach (Clause cc in sw.case_clauses)
|
||||
foreach (AST ast in cc.stm_list)
|
||||
ast.parent = sw;
|
||||
foreach (AST dc in sw.default_clauses)
|
||||
dc.parent = sw;
|
||||
foreach (Clause cc in sw.case_clauses)
|
||||
foreach (AST ast in cc.stm_list)
|
||||
ast.parent = sw;
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
2004-05-31 Rafael Teixeira <[email protected]>
|
||||
* Financial.cs:
|
||||
Correct IRR and MIRR method signatures and prevent public default constructor, all according to Class Status Page (corcompare)
|
||||
|
||||
2004-04-26 Rafael Teixeira <[email protected]>
|
||||
* DateAndTime.cs:
|
||||
Catch FormatException and rethrow as InvalidCastException in:
|
||||
|
||||
@@ -8,13 +8,15 @@
|
||||
//
|
||||
|
||||
using System;
|
||||
using Microsoft.VisualBasic.CompilerServices;
|
||||
|
||||
namespace Microsoft.VisualBasic
|
||||
{
|
||||
[Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute]
|
||||
[StandardModule]
|
||||
sealed public class Financial {
|
||||
// Declarations
|
||||
// Constructors
|
||||
private Financial() {} // prevent public default constructor
|
||||
// Properties
|
||||
// Methods
|
||||
[MonoTODO]
|
||||
@@ -24,9 +26,9 @@ namespace Microsoft.VisualBasic
|
||||
[MonoTODO]
|
||||
public static System.Double IPmt (System.Double Rate, System.Double Per, System.Double NPer, System.Double PV, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(0)] System.Double FV, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(0)] Microsoft.VisualBasic.DueDate Due) { throw new NotImplementedException (); }
|
||||
[MonoTODO]
|
||||
public static System.Double IRR (ref System.Double[] ValueArray, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(0.1)] ref System.Double Guess) { throw new NotImplementedException (); }
|
||||
public static System.Double IRR (ref System.Double[] ValueArray, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(0.1)] System.Double Guess) { throw new NotImplementedException (); }
|
||||
[MonoTODO]
|
||||
public static System.Double MIRR (ref System.Double[] ValueArray, ref System.Double FinanceRate, ref System.Double ReinvestRate) { throw new NotImplementedException (); }
|
||||
public static System.Double MIRR (ref System.Double[] ValueArray, System.Double FinanceRate, System.Double ReinvestRate) { throw new NotImplementedException (); }
|
||||
[MonoTODO]
|
||||
public static System.Double NPer (System.Double Rate, System.Double Pmt, System.Double PV, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(0)] System.Double FV, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(0)] Microsoft.VisualBasic.DueDate Due) { throw new NotImplementedException (); }
|
||||
[MonoTODO]
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
2004-05-30 Gonzalo Paniagua Javier <[email protected]>
|
||||
|
||||
* Mono.Data.SqliteClient.dll.sources: added SqliteTransaction.cs
|
||||
|
||||
* Mono.Data.SqliteClient/SqliteConnection.cs:
|
||||
* Mono.Data.SqliteClient/SqliteTransaction.cs: patch from
|
||||
[email protected] that adds transactions support.
|
||||
|
||||
2004-04-29 Gonzalo Paniagua Javier <[email protected]>
|
||||
|
||||
* Mono.Data.SqliteClient/SqliteCommand.cs: implement LastInsertRowId.
|
||||
|
||||
@@ -5,3 +5,4 @@ Mono.Data.SqliteClient/SqliteConnection.cs
|
||||
Mono.Data.SqliteClient/SqliteDataReader.cs
|
||||
Mono.Data.SqliteClient/SqliteParameter.cs
|
||||
Mono.Data.SqliteClient/SqliteParameterCollection.cs
|
||||
Mono.Data.SqliteClient/SqliteTransaction.cs
|
||||
@@ -174,8 +174,16 @@ namespace Mono.Data.SqliteClient
|
||||
}
|
||||
|
||||
public IDbTransaction BeginTransaction ()
|
||||
{
|
||||
return null;
|
||||
{
|
||||
if (state != ConnectionState.Open)
|
||||
throw new InvalidOperationException("Invalid operation: The connection is close");
|
||||
|
||||
SqliteTransaction t = new SqliteTransaction();
|
||||
t.Connection = this;
|
||||
SqliteCommand cmd = this.CreateCommand();
|
||||
cmd.CommandText = "BEGIN";
|
||||
cmd.ExecuteNonQuery();
|
||||
return t;
|
||||
}
|
||||
|
||||
public IDbTransaction BeginTransaction (IsolationLevel il)
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
// Mono.Data.SqliteClient data access components for .Net
|
||||
// Derived from ByteFX.Data
|
||||
// With permission from Reggie Burnett to relicense under MIT/X11
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
|
||||
namespace Mono.Data.SqliteClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a SQL transaction to be made in a Sqlite database. This class cannot be inherited.
|
||||
/// </summary>
|
||||
public sealed class SqliteTransaction : IDbTransaction
|
||||
{
|
||||
private IsolationLevel _level;
|
||||
private SqliteConnection _conn;
|
||||
private bool _open;
|
||||
|
||||
internal SqliteTransaction()
|
||||
{
|
||||
_open = true;
|
||||
}
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="SqliteConnection"/> object associated with the transaction, or a null reference (Nothing in Visual Basic) if the transaction is no longer valid.
|
||||
/// </summary>
|
||||
public IDbConnection Connection
|
||||
{
|
||||
get { return _conn; }
|
||||
set { _conn = (SqliteConnection)value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the <see cref="IsolationLevel"/> for this transaction.
|
||||
/// </summary>
|
||||
public IsolationLevel IsolationLevel
|
||||
{
|
||||
get { return _level; }
|
||||
set { _level = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
void System.IDisposable.Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Commits the database transaction.
|
||||
/// </summary>
|
||||
public void Commit()
|
||||
{
|
||||
if (_conn == null || _conn.State != ConnectionState.Open)
|
||||
throw new InvalidOperationException("Connection must be valid and open to commit transaction");
|
||||
if (!_open)
|
||||
throw new InvalidOperationException("Transaction has already been committed or is not pending");
|
||||
try
|
||||
{
|
||||
SqliteCommand cmd = _conn.CreateCommand();
|
||||
cmd.CommandText = "COMMIT";
|
||||
cmd.ExecuteNonQuery();
|
||||
_open = false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overloaded. Rolls back a transaction from a pending state.
|
||||
/// </summary>
|
||||
public void Rollback()
|
||||
{
|
||||
if (_conn == null || _conn.State != ConnectionState.Open)
|
||||
throw new InvalidOperationException("Connection must be valid and open to commit transaction");
|
||||
if (!_open)
|
||||
throw new InvalidOperationException("Transaction has already been rolled back or is not pending");
|
||||
try
|
||||
{
|
||||
SqliteCommand cmd = _conn.CreateCommand();
|
||||
cmd.CommandText = "COMMIT";
|
||||
cmd.ExecuteNonQuery();
|
||||
_open = false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,10 @@
|
||||
2004-05-31 Rafael Teixeira <[email protected]>
|
||||
* OptionDetails.cs : ShortForm member now a string to favor some simplifications, fixes for Bug 58672
|
||||
* OptionList.cs : Fixes for Bug 58672 and better handling for mixed-form options (linux/windows)
|
||||
|
||||
2004-05-31 Rafael Teixeira <[email protected]>
|
||||
* OptionDetails.cs: Assemble an one-line authors' list in about processor (also abandon after about)
|
||||
|
||||
2004-04-08 Rafael Teixeira <[email protected]>
|
||||
* OptionDetails.cs: Implemented Jonathan Pryor request for multiplicity in boolean properties
|
||||
|
||||
|
||||
@@ -28,13 +28,14 @@ namespace Mono.GetOptions
|
||||
|
||||
internal class OptionDetails : IComparable
|
||||
{
|
||||
public char ShortForm;
|
||||
public string ShortForm;
|
||||
public string LongForm;
|
||||
public string AlternateForm;
|
||||
public string ShortDescription;
|
||||
public bool NeedsParameter;
|
||||
public int MaxOccurs; // negative means there is no limit
|
||||
public int Occurs;
|
||||
public bool BooleanOption;
|
||||
public Options OptionBundle;
|
||||
public MemberInfo MemberInfo;
|
||||
public ArrayList Values;
|
||||
@@ -74,6 +75,7 @@ namespace Mono.GetOptions
|
||||
// TODO: Yet not that good
|
||||
string shortPrefix;
|
||||
string longPrefix;
|
||||
bool hasLongForm = (this.LongForm != null && this.LongForm != string.Empty);
|
||||
if(this.OptionBundle.ParsingMode == Mono.GetOptions.OptionsParsingMode.Windows)
|
||||
{
|
||||
shortPrefix = "/";
|
||||
@@ -85,11 +87,11 @@ namespace Mono.GetOptions
|
||||
longPrefix = "--";
|
||||
}
|
||||
optionHelp = " ";
|
||||
optionHelp += (this.ShortForm != ' ') ? shortPrefix+this.ShortForm+" " : " ";
|
||||
optionHelp += (this.LongForm != string.Empty && this.LongForm != null) ? longPrefix+this.LongForm : "";
|
||||
optionHelp += (this.ShortForm != string.Empty) ? shortPrefix+this.ShortForm+" " : " ";
|
||||
optionHelp += hasLongForm ? longPrefix+this.LongForm : "";
|
||||
if (NeedsParameter)
|
||||
{
|
||||
if (this.LongForm != string.Empty && this.LongForm != null)
|
||||
if (hasLongForm)
|
||||
optionHelp += ":";
|
||||
optionHelp += ParamName;
|
||||
}
|
||||
@@ -125,12 +127,13 @@ namespace Mono.GetOptions
|
||||
|
||||
public OptionDetails(MemberInfo memberInfo, OptionAttribute option, Options optionBundle)
|
||||
{
|
||||
this.ShortForm = option.ShortForm;
|
||||
this.ShortForm = ("" + option.ShortForm).Trim();
|
||||
this.LongForm = (option.LongForm == string.Empty)? memberInfo.Name:option.LongForm;
|
||||
this.AlternateForm = option.AlternateForm;
|
||||
this.ShortDescription = option.ShortDescription;
|
||||
this.Occurs = 0;
|
||||
this.OptionBundle = optionBundle;
|
||||
this.BooleanOption = false;
|
||||
this.MemberInfo = memberInfo;
|
||||
this.NeedsParameter = false;
|
||||
this.Values = null;
|
||||
@@ -166,6 +169,7 @@ namespace Mono.GetOptions
|
||||
}
|
||||
else
|
||||
{
|
||||
this.BooleanOption = true;
|
||||
if (option.MaxOccurs != 1)
|
||||
{
|
||||
if (this.MemberInfo is MethodInfo || this.MemberInfo is PropertyInfo)
|
||||
@@ -180,7 +184,7 @@ namespace Mono.GetOptions
|
||||
|
||||
internal string Key
|
||||
{
|
||||
get { return ((this.ShortForm != ' ') ? this.ShortForm + "" : "") + this.LongForm; }
|
||||
get { return this.ShortForm + this.LongForm; }
|
||||
}
|
||||
|
||||
int IComparable.CompareTo(object other)
|
||||
@@ -217,7 +221,7 @@ namespace Mono.GetOptions
|
||||
throw new IndexOutOfRangeException("Option " + ShortForm + " can be used at most " + MaxOccurs + " times");
|
||||
}
|
||||
|
||||
private void DoIt()
|
||||
private void DoIt(bool setValue)
|
||||
{
|
||||
if (!NeedsParameter)
|
||||
{
|
||||
@@ -228,12 +232,12 @@ namespace Mono.GetOptions
|
||||
|
||||
if (MemberInfo is FieldInfo)
|
||||
{
|
||||
((FieldInfo)MemberInfo).SetValue(OptionBundle, true);
|
||||
((FieldInfo)MemberInfo).SetValue(OptionBundle, setValue);
|
||||
return;
|
||||
}
|
||||
if (MemberInfo is PropertyInfo)
|
||||
{
|
||||
((PropertyInfo)MemberInfo).SetValue(OptionBundle, true, null);
|
||||
((PropertyInfo)MemberInfo).SetValue(OptionBundle, setValue, null);
|
||||
return;
|
||||
}
|
||||
if ((WhatToDoNext)((MethodInfo)MemberInfo).Invoke(OptionBundle, null) == WhatToDoNext.AbandonProgram)
|
||||
@@ -287,17 +291,12 @@ namespace Mono.GetOptions
|
||||
}
|
||||
}
|
||||
|
||||
private bool StartsLikeAnOption(string arg)
|
||||
{
|
||||
return (arg != null && arg[0] == '-');
|
||||
}
|
||||
|
||||
private bool IsThisOption(string arg)
|
||||
{
|
||||
if (StartsLikeAnOption(arg))
|
||||
if (arg != null && arg != string.Empty)
|
||||
{
|
||||
arg = arg.TrimStart('-');
|
||||
return (arg == "" + ShortForm || arg == LongForm || arg == AlternateForm);
|
||||
arg = arg.TrimStart('-', '/');
|
||||
return (arg == ShortForm || arg == LongForm || arg == AlternateForm);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -308,27 +307,19 @@ namespace Mono.GetOptions
|
||||
{
|
||||
if (!NeedsParameter)
|
||||
{
|
||||
DoIt();
|
||||
DoIt(true); // in preparation for vbc-like booleans
|
||||
return OptionProcessingResult.OptionAlone;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (StartsLikeAnOption(nextArg))
|
||||
{
|
||||
DoIt(null);
|
||||
return OptionProcessingResult.OptionAlone;
|
||||
}
|
||||
else
|
||||
{
|
||||
DoIt(nextArg);
|
||||
return OptionProcessingResult.OptionConsumedParameter;
|
||||
}
|
||||
DoIt(nextArg);
|
||||
return OptionProcessingResult.OptionConsumedParameter;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsThisOption(arg + ":" + nextArg))
|
||||
{
|
||||
DoIt();
|
||||
DoIt(true);
|
||||
return OptionProcessingResult.OptionConsumedParameter;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace Mono.GetOptions
|
||||
{
|
||||
@@ -48,6 +49,12 @@ namespace Mono.GetOptions
|
||||
private ArrayList argumentsTail = new ArrayList();
|
||||
private MethodInfo argumentProcessor = null;
|
||||
|
||||
internal bool MaybeAnOption(string arg)
|
||||
{
|
||||
return ((parsingMode & OptionsParsingMode.Windows) > 0 && arg[0] == '/') ||
|
||||
((parsingMode & OptionsParsingMode.Linux) > 0 && arg[0] == '-');
|
||||
}
|
||||
|
||||
public string Usage
|
||||
{
|
||||
get
|
||||
@@ -189,10 +196,17 @@ namespace Mono.GetOptions
|
||||
{
|
||||
ShowTitleLines();
|
||||
Console.WriteLine(appAboutDetails);
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Authors:");
|
||||
StringBuilder sb = new StringBuilder("Authors: ");
|
||||
bool first = true;
|
||||
foreach(string s in appAuthors)
|
||||
Console.WriteLine ("\t" + s);
|
||||
{
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
sb.Append(", ");
|
||||
sb.Append(s);
|
||||
}
|
||||
Console.WriteLine(sb.ToString());
|
||||
}
|
||||
|
||||
private void ShowHelp()
|
||||
@@ -209,7 +223,7 @@ namespace Mono.GetOptions
|
||||
Console.WriteLine(Usage);
|
||||
Console.Write("Short Options: ");
|
||||
foreach (OptionDetails option in list)
|
||||
Console.Write((option.ShortForm != ' ') ? option.ShortForm.ToString() : "");
|
||||
Console.Write(option.ShortForm.Trim());
|
||||
Console.WriteLine();
|
||||
|
||||
}
|
||||
@@ -229,7 +243,7 @@ namespace Mono.GetOptions
|
||||
internal WhatToDoNext DoAbout()
|
||||
{
|
||||
ShowAbout();
|
||||
return WhatToDoNext.GoAhead;
|
||||
return WhatToDoNext.AbandonProgram;
|
||||
}
|
||||
|
||||
internal WhatToDoNext DoHelp()
|
||||
@@ -296,35 +310,19 @@ namespace Mono.GetOptions
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arg[0] == '/')
|
||||
if ((parsingMode & OptionsParsingMode.Linux) > 0 &&
|
||||
arg[0] == '-' && arg[1] != '-' &&
|
||||
breakSingleDashManyLettersIntoManyOptions)
|
||||
{
|
||||
if ((parsingMode & OptionsParsingMode.Windows) > 0)
|
||||
{
|
||||
string newArg = '-' + arg.TrimStart('/');
|
||||
result.AddRange(newArg.Split(':'));
|
||||
continue;
|
||||
}
|
||||
foreach(char c in arg.Substring(1)) // many single-letter options
|
||||
result.Add("-" + c); // expand into individualized options
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((parsingMode & OptionsParsingMode.Linux) > 0)
|
||||
if (MaybeAnOption(arg))
|
||||
{
|
||||
if ((arg[0] == '-') && (arg[1] != '-'))
|
||||
{
|
||||
if (breakSingleDashManyLettersIntoManyOptions)
|
||||
{
|
||||
foreach(char c in arg.Substring(1)) // many single-letter options
|
||||
result.Add("-" + c); // expand into individualized options
|
||||
}
|
||||
else
|
||||
result.Add(arg);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arg.StartsWith("--"))
|
||||
{
|
||||
result.AddRange(arg.Split('=')); // put in the same form of one-letter options with a parameter
|
||||
continue;
|
||||
}
|
||||
result.AddRange(arg.Split(':','='));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -364,7 +362,7 @@ namespace Mono.GetOptions
|
||||
|
||||
OptionWasProcessed = false;
|
||||
|
||||
if (arg.StartsWith("-"))
|
||||
if (arg.StartsWith("-") || arg.StartsWith("/"))
|
||||
{
|
||||
foreach(OptionDetails option in list)
|
||||
{
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
2004-05-29 Francisco Figueiredo Jr. <[email protected]>
|
||||
* Npgsql/NpgsqlConnection.cs: Added workaround for redhat server versions.
|
||||
It returns 7.3.4-RH as its server version. Thanks Jaroslaw Kowalski
|
||||
([email protected]) for the patch.
|
||||
|
||||
2004-05-24 Francisco Figueiredo Jr. <[email protected]>
|
||||
* Npgsql/NpgsqlConnection.cs: Fixed bug when handling Unicode connections.
|
||||
Fixes Gborg bug 752.
|
||||
Thanks [email protected] for the patch.
|
||||
|
||||
2004-05-23 Francisco Figueiredo Jr. <[email protected]>
|
||||
|
||||
* Npgsql/NpgsqlConnection.cs: Fixed bug which prevented Npgsql to
|
||||
|
||||
@@ -698,6 +698,17 @@ namespace Npgsql
|
||||
|
||||
throw new FormatException(String.Format("Internal: Backend sent bad version string: {0}", VersionString));
|
||||
}
|
||||
|
||||
// workaround for 7.3.4-RH version from RedHat
|
||||
|
||||
|
||||
int ndx = Parts[2].IndexOf("-");
|
||||
|
||||
if (ndx != -1)
|
||||
{
|
||||
Parts[2] = Parts[2].Substring(0, ndx);
|
||||
}
|
||||
|
||||
|
||||
return new ServerVersion(
|
||||
Convert.ToInt32(Parts[0]),
|
||||
|
||||
@@ -30,7 +30,11 @@ namespace System.Data.Common {
|
||||
[Obsolete ("use DBDataPermission (PermissionState.None)", true)]
|
||||
#endif
|
||||
protected DBDataPermission ()
|
||||
#if NET_2_0
|
||||
: this (PermissionState.None)
|
||||
#else
|
||||
: this (PermissionState.None, false)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,11 @@ namespace System.Data.SqlClient {
|
||||
|
||||
[Obsolete ("Use SqlClientPermission(PermissionState.None)", true)]
|
||||
public SqlClientPermission ()
|
||||
#if NET_2_0
|
||||
: this (PermissionState.None)
|
||||
#else
|
||||
// : this (PermissionState.None, false)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
@@ -41,6 +45,9 @@ namespace System.Data.SqlClient {
|
||||
|
||||
[Obsolete ("Use SqlClientPermission(PermissionState.None)", true)]
|
||||
public SqlClientPermission (PermissionState state, bool allowBlankPassword)
|
||||
#if NET_2_0
|
||||
: this (state)
|
||||
#endif
|
||||
{
|
||||
AllowBlankPassword = allowBlankPassword;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,32 @@
|
||||
2004-05-31 Atsushi Enomoto <[email protected]>
|
||||
|
||||
* DataSet.cs : Loop-break of the last fix was incorrect.
|
||||
|
||||
2004-05-31 Atsushi Enomoto <[email protected]>
|
||||
|
||||
* DataSet.cs : When a row has no parent row but the table has parent
|
||||
relation(s), that row had been always ignored.
|
||||
|
||||
2004-05-31 Atsushi Enomoto <[email protected]>
|
||||
|
||||
* XmlDataInferenceLoader.cs : Fixed GetMappedTable() that incorrectly
|
||||
rejected same-named tables in different hierarchy. Thanks to Boris.
|
||||
|
||||
2004-05-31 Atsushi Enomoto <[email protected]>
|
||||
|
||||
* XmlDiffLoader.cs : Added some Skip() that is required not to go to
|
||||
infinite loop. Thanks to Boris for this fix.
|
||||
|
||||
2004-05-31 Atsushi Enomoto <[email protected]>
|
||||
|
||||
* XmlDataInferenceLoader.cs : XmlSchema elements should not be infered.
|
||||
Thanks to Boris for this fix.
|
||||
|
||||
2004-05-30 Atsushi Enomoto <[email protected]>
|
||||
|
||||
* DataTable.cs : serialization .ctor() should use XmlReadMode.DiffGram
|
||||
for ReadXml(). Thanks to Boris.
|
||||
|
||||
2004-05-27 Boris Kirzner <[email protected]>
|
||||
* DataRow.cs :
|
||||
- CheckReadOnlyStatus : use typed (and faster comparing).
|
||||
|
||||
@@ -1117,13 +1117,14 @@ namespace System.Data {
|
||||
//part of another table structure via a nested parent relationship
|
||||
foreach (DataTable table in tableCollection) {
|
||||
bool isTopLevel = true;
|
||||
/*
|
||||
foreach (DataRelation rel in table.ParentRelations) {
|
||||
if (rel.Nested) {
|
||||
isTopLevel = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
if (isTopLevel) {
|
||||
WriteTable ( writer, table, mode, version);
|
||||
}
|
||||
@@ -1150,8 +1151,30 @@ namespace System.Data {
|
||||
SplitColumns (table, out atts, out elements, out simple);
|
||||
//sort out the namespacing
|
||||
string nspc = table.Namespace.Length > 0 ? table.Namespace : Namespace;
|
||||
int relationCount = table.ParentRelations.Count;
|
||||
DataRelation oneRel = relationCount == 1 ? table.ParentRelations [0] : null;
|
||||
|
||||
foreach (DataRow row in rows) {
|
||||
// Skip rows that is a child of any tables.
|
||||
switch (relationCount) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
if (row.GetParentRow (oneRel) != null)
|
||||
continue;
|
||||
break;
|
||||
case 2:
|
||||
bool skip = false;
|
||||
for (int i = 0; i < table.ParentRelations.Count; i++)
|
||||
if (row.GetParentRow (table.ParentRelations [i]) != null) {
|
||||
skip = true;
|
||||
continue;
|
||||
}
|
||||
if (skip)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!row.HasVersion(version) ||
|
||||
(mode == XmlWriteMode.DiffGram && row.RowState == DataRowState.Unchanged
|
||||
&& version == DataRowVersion.Original))
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace System.Data {
|
||||
ds.Tables [0].CopyProperties (this);
|
||||
ds = new DataSet ();
|
||||
ds.Tables.Add (this);
|
||||
ds.ReadXml (new StringReader (data), XmlReadMode.IgnoreSchema);
|
||||
ds.ReadXml (new StringReader (data), XmlReadMode.DiffGram);
|
||||
ds.Tables.Remove (this);
|
||||
/* keeping for a while. With the change above, we shouldn't have to consider
|
||||
* DataTable mode in schema inference/read.
|
||||
|
||||
@@ -15,6 +15,7 @@ using System.Data;
|
||||
using System.IO; // for Driver
|
||||
using System.Text; // for Driver
|
||||
using System.Xml;
|
||||
using System.Xml.Schema;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace System.Data
|
||||
@@ -165,9 +166,12 @@ namespace System.Data
|
||||
dataset.DataSetName = localName;
|
||||
dataset.Namespace = el.NamespaceURI;
|
||||
dataset.Prefix = el.Prefix;
|
||||
foreach (XmlNode n in el.ChildNodes)
|
||||
foreach (XmlNode n in el.ChildNodes) {
|
||||
if (n.NamespaceURI == XmlSchema.Namespace)
|
||||
continue;
|
||||
if (n.NodeType == XmlNodeType.Element)
|
||||
InferTopLevelTable (n as XmlElement);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (TableMapping map in tables) {
|
||||
@@ -374,7 +378,7 @@ namespace System.Data
|
||||
{
|
||||
TableMapping map = tables [tableName];
|
||||
if (map != null) {
|
||||
if (map.ParentTable != parent)
|
||||
if (parent != null && map.ParentTable != null && map.ParentTable != parent)
|
||||
throw new DataException (String.Format ("The table {0} is already allocated as another table's child table.", tableName));
|
||||
} else {
|
||||
map = new TableMapping (tableName, ns);
|
||||
|
||||
@@ -93,8 +93,10 @@ namespace System.Data {
|
||||
|
||||
private void LoadCurrent (XmlReader reader)
|
||||
{
|
||||
if (reader.IsEmptyElement) return;
|
||||
|
||||
if (reader.IsEmptyElement) {
|
||||
reader.Skip ();
|
||||
return;
|
||||
}
|
||||
reader.ReadStartElement (); // Dataset root
|
||||
reader.MoveToContent ();
|
||||
|
||||
@@ -122,8 +124,10 @@ namespace System.Data {
|
||||
|
||||
private void LoadBefore (XmlReader reader)
|
||||
{
|
||||
if (reader.IsEmptyElement) return;
|
||||
|
||||
if (reader.IsEmptyElement) {
|
||||
reader.Skip ();
|
||||
return;
|
||||
}
|
||||
reader.ReadStartElement ();
|
||||
reader.MoveToContent ();
|
||||
|
||||
@@ -147,8 +151,10 @@ namespace System.Data {
|
||||
|
||||
private void LoadErrors (XmlReader reader)
|
||||
{
|
||||
if (reader.IsEmptyElement) return;
|
||||
|
||||
if (reader.IsEmptyElement) {
|
||||
reader.Skip ();
|
||||
return;
|
||||
}
|
||||
reader.ReadStartElement ();
|
||||
reader.MoveToContent ();
|
||||
|
||||
@@ -184,8 +190,10 @@ namespace System.Data {
|
||||
|
||||
private void LoadColumns (DataTable Table, DataRow Row, XmlReader reader, DataRowVersion loadType)
|
||||
{
|
||||
if (reader.IsEmptyElement) return;
|
||||
|
||||
if (reader.IsEmptyElement) {
|
||||
reader.Skip ();
|
||||
return;
|
||||
}
|
||||
reader.ReadStartElement ();
|
||||
reader.MoveToContent ();
|
||||
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
2004-05-31 Atsushi Enomoto <[email protected]>
|
||||
|
||||
* DataTableTest.cs : Added test for serialization by Boris Kirzner.
|
||||
* DataSetInferXmlSchemaTest.cs : Added test for schema element skip
|
||||
by Boris Kirzner.
|
||||
|
||||
2004-05-27 Nick Drochak <[email protected]>
|
||||
|
||||
* DataRelationCollectionTest.cs: Fixed build when using csc.
|
||||
|
||||
@@ -475,5 +475,35 @@ namespace MonoTests.System.Data
|
||||
// a:foo is ignored
|
||||
AssertDataTable ("dt", ds.Tables [0], "root", 1, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContainsSchema ()
|
||||
{
|
||||
DataSet ds = new DataSet();
|
||||
DataTable dt1 = new DataTable();
|
||||
ds.Tables.Add(dt1);
|
||||
DataColumn dc1 = new DataColumn("Col1");
|
||||
dt1.Columns.Add(dc1);
|
||||
dt1.Rows.Add(new string[] { "aaa" } );
|
||||
DataTable dt2 = new DataTable();
|
||||
ds.Tables.Add(dt2);
|
||||
DataColumn dc2 = new DataColumn("Col2");
|
||||
dt2.Columns.Add(dc2);
|
||||
dt2.Rows.Add(new string[] { "bbb" } );
|
||||
|
||||
DataRelation rel = new DataRelation("Rel1",dc1,dc2,false);
|
||||
ds.Relations.Add(rel);
|
||||
|
||||
StringWriter sw = new StringWriter ();
|
||||
ds.WriteXml(sw, XmlWriteMode.WriteSchema);
|
||||
|
||||
ds = new DataSet();
|
||||
ds.ReadXml(new StringReader (sw.ToString ()));
|
||||
sw = new StringWriter ();
|
||||
ds.WriteXml(sw);
|
||||
XmlDocument doc = new XmlDocument ();
|
||||
doc.LoadXml (sw.ToString ());
|
||||
AssertEquals (2, doc.DocumentElement.ChildNodes.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,9 @@ using NUnit.Framework;
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Xml;
|
||||
|
||||
namespace MonoTests.System.Data
|
||||
{
|
||||
@@ -1169,5 +1172,54 @@ namespace MonoTests.System.Data
|
||||
#endif
|
||||
AssertEquals ("#A05", 0, table.ChildRelations.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Serialize ()
|
||||
{
|
||||
MemoryStream fs = new MemoryStream ();
|
||||
|
||||
// Construct a BinaryFormatter and use it
|
||||
// to serialize the data to the stream.
|
||||
BinaryFormatter formatter = new BinaryFormatter();
|
||||
|
||||
// Create an array with multiple elements refering to
|
||||
// the one Singleton object.
|
||||
DataTable dt = new DataTable();
|
||||
|
||||
|
||||
dt.Columns.Add(new DataColumn("Id", typeof(string)));
|
||||
dt.Columns.Add(new DataColumn("ContactName", typeof(string)));
|
||||
dt.Columns.Add(new DataColumn("ContactTitle", typeof(string)));
|
||||
dt.Columns.Add(new DataColumn("ContactAreaCode", typeof(string)));
|
||||
dt.Columns.Add(new DataColumn("ContactPhone", typeof(string)));
|
||||
|
||||
DataRow loRowToAdd;
|
||||
loRowToAdd = dt.NewRow();
|
||||
loRowToAdd[0] = "a";
|
||||
loRowToAdd[1] = "b";
|
||||
loRowToAdd[2] = "c";
|
||||
loRowToAdd[3] = "d";
|
||||
loRowToAdd[4] = "e";
|
||||
|
||||
dt.Rows.Add(loRowToAdd);
|
||||
|
||||
DataTable[] dtarr = new DataTable[] {dt};
|
||||
|
||||
// Serialize the array elements.
|
||||
formatter.Serialize(fs, dtarr);
|
||||
|
||||
// Deserialize the array elements.
|
||||
fs.Position = 0;
|
||||
DataTable[] a2 = (DataTable[]) formatter.Deserialize(fs);
|
||||
|
||||
DataSet ds = new DataSet();
|
||||
ds.Tables.Add(a2[0]);
|
||||
|
||||
StringWriter sw = new StringWriter ();
|
||||
ds.WriteXml(sw);
|
||||
XmlDocument doc = new XmlDocument ();
|
||||
doc.LoadXml (sw.ToString ());
|
||||
AssertEquals (5, doc.DocumentElement.FirstChild.ChildNodes.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,9 @@
|
||||
2004-05-31 Ravindra <[email protected]>
|
||||
|
||||
* pie.cs: Made the output image little organized and added a
|
||||
case where DrawPie and FillPie were crashing the system. It
|
||||
was happening with zero degree sweep angle.
|
||||
|
||||
2004-05-04 Ravindra <[email protected]>
|
||||
|
||||
* ImageRotateFlip.cs: Changed text color from white to
|
||||
|
||||
@@ -17,7 +17,7 @@ public class graphicsUI
|
||||
public static void Main ()
|
||||
{
|
||||
|
||||
Bitmap bmp = new Bitmap (300, 300);
|
||||
Bitmap bmp = new Bitmap (400, 600);
|
||||
Graphics dc = Graphics.FromImage (bmp);
|
||||
|
||||
// Clears and set the background color to red
|
||||
@@ -28,34 +28,44 @@ public class graphicsUI
|
||||
SolidBrush yellowBrush = new SolidBrush (Color.Yellow);
|
||||
SolidBrush whiteBrush = new SolidBrush (Color.White);
|
||||
Pen bluePen = new Pen (Color.Blue);
|
||||
|
||||
Rectangle rect1 = new Rectangle (0,0, 75, 75);
|
||||
dc.DrawPie (bluePen, rect1, 10, 60);
|
||||
|
||||
Rectangle rect2 = new Rectangle (100,100, 75, 75);
|
||||
dc.DrawPie (bluePen, rect2, 100, 75);
|
||||
|
||||
Rectangle rect2a = new Rectangle (100, 200, 75, 75);
|
||||
dc.DrawPie (bluePen, rect2a, 100, 400);
|
||||
// We have a column starting at x=50 for Draw operations
|
||||
// and another column starting at x=200 for Fill operations.
|
||||
// Both the columns grow downwards.
|
||||
|
||||
// Column 1
|
||||
Rectangle rect11 = new Rectangle (50, 0, 75, 75);
|
||||
dc.DrawPie (bluePen, rect11, 10, 60);
|
||||
|
||||
Rectangle rect3 = new Rectangle (100, 0, 75, 75);
|
||||
dc.FillPie (yellowBrush, rect3, 0, 300);
|
||||
Rectangle rect12 = new Rectangle (50,100, 75, 75);
|
||||
dc.DrawPie (bluePen, rect12, 100, 75);
|
||||
|
||||
Rectangle rect13 = new Rectangle (50, 200, 75, 75);
|
||||
dc.DrawPie (bluePen, rect13, 100, 400);
|
||||
|
||||
Rectangle rect14 = new Rectangle (50, 300, 75, 75);
|
||||
dc.DrawPie (bluePen, rect14, 0, 0);
|
||||
|
||||
// Column 2
|
||||
Rectangle rect21 = new Rectangle (200, 0, 75, 75);
|
||||
dc.FillPie (yellowBrush, rect21, 0, 300);
|
||||
|
||||
Rectangle rect4 = new Rectangle (0, 100, 75, 75);
|
||||
dc.FillPie (whiteBrush, rect4, 200, 30);
|
||||
Rectangle rect22 = new Rectangle (200, 100, 75, 75);
|
||||
dc.FillPie (whiteBrush, rect22, 200, 30);
|
||||
|
||||
Rectangle rect4a = new Rectangle (0, 100, 75, 75);
|
||||
dc.FillPie (whiteBrush, rect4a, 200, 400);
|
||||
Rectangle rect23 = new Rectangle (200, 200, 75, 75);
|
||||
dc.FillPie (whiteBrush, rect23, 200, 400);
|
||||
|
||||
Rectangle rect5 = new Rectangle (200, 0, 75, 75);
|
||||
dc.FillPie (yellowBrush, rect5, 190, 300);
|
||||
Rectangle rect24 = new Rectangle (200, 300, 75, 75);
|
||||
dc.FillPie (yellowBrush, rect24, 190, 300);
|
||||
|
||||
Rectangle rect6 = new Rectangle (200, 100, 75, 75);
|
||||
dc.FillPie (whiteBrush, rect6, 200, 20);
|
||||
Rectangle rect25 = new Rectangle (200, 400, 75, 75);
|
||||
dc.FillPie (whiteBrush, rect25, 200, 20);
|
||||
|
||||
bmp.Save("fillpie.png", ImageFormat.Png);
|
||||
}
|
||||
Rectangle rect26 = new Rectangle (200, 500, 75, 75);
|
||||
dc.FillPie (yellowBrush, rect26, 50, 0);
|
||||
|
||||
bmp.Save("fillpie.png", ImageFormat.Png);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,10 @@
|
||||
2004-05-29 Gert Driesen ([email protected])
|
||||
|
||||
* System.Messaging/Acknowledgment.cs: added/corrected values,
|
||||
removed TODO
|
||||
* System.Messaging/MessageQueueErrorCode.cs: fixed typo
|
||||
* System.Messaging/MessageQueueAccessRights.cs: removed extra
|
||||
enum field
|
||||
|
||||
2003-02-23 Rafael Teixeira <[email protected]>
|
||||
* added just files enough to compile a dummy DLL for now
|
||||
@@ -9,24 +9,26 @@
|
||||
using System;
|
||||
|
||||
namespace System.Messaging
|
||||
{
|
||||
[MonoTODO("Have to force the right specific values for each element")]
|
||||
{
|
||||
[Serializable]
|
||||
public enum Acknowledgment
|
||||
{
|
||||
AccessDenied,
|
||||
BadDestinationQueue,
|
||||
BadEncryption,
|
||||
BadSignature,
|
||||
CouldNotEncrypt,
|
||||
HopCountExceeded,
|
||||
None,
|
||||
NotTransactionalMessage,
|
||||
NotTransactionQueue,
|
||||
Purged,
|
||||
ReachQueue,
|
||||
ReachQueueTimeout,
|
||||
Receive,
|
||||
ReceiveTimeout
|
||||
AccessDenied = 32772,
|
||||
BadDestinationQueue = 32768,
|
||||
BadEncryption = 32775,
|
||||
BadSignature = 32774,
|
||||
CouldNotEncrypt = 32776,
|
||||
HopCountExceeded = 32773,
|
||||
None = 0,
|
||||
NotTransactionalMessage = 32778,
|
||||
NotTransactionalQueue = 32777,
|
||||
Purged = 32769,
|
||||
QueueDeleted = 49152,
|
||||
QueueExceedMaximumSize = 32771,
|
||||
QueuePurged = 49153,
|
||||
ReachQueue = 2,
|
||||
ReachQueueTimeout = 32770,
|
||||
Receive = 16384,
|
||||
ReceiveTimeout = 49154
|
||||
}
|
||||
}
|
||||
@@ -10,26 +10,24 @@ using System;
|
||||
|
||||
namespace System.Messaging
|
||||
{
|
||||
[MonoTODO("Have to force the right specific values for each element")]
|
||||
[Flags]
|
||||
[Serializable]
|
||||
public enum MessageQueueAccessRights
|
||||
public enum MessageQueueAccessRights
|
||||
{
|
||||
ChangeQueuePermissions,
|
||||
DeleteJournalMessage,
|
||||
DeleteMessage,
|
||||
DeleteQueue,
|
||||
FullControl,
|
||||
GenericRead,
|
||||
GenericWrite,
|
||||
GetQueuePermissions,
|
||||
GetQueueProperties,
|
||||
PeekMessage,
|
||||
ReceiveJournalMessage,
|
||||
ReceiveMessage,
|
||||
SetQueueProperties,
|
||||
TakeQueueProperties,
|
||||
TakeQueueOwnership,
|
||||
WriteMessage
|
||||
ChangeQueuePermissions = 262144,
|
||||
DeleteJournalMessage = 8,
|
||||
DeleteMessage = 1,
|
||||
DeleteQueue = 65536,
|
||||
FullControl = 983103,
|
||||
GenericRead = 131115,
|
||||
GenericWrite = 131108,
|
||||
GetQueuePermissions = 131072,
|
||||
GetQueueProperties = 32,
|
||||
PeekMessage = 2,
|
||||
ReceiveJournalMessage = 10,
|
||||
ReceiveMessage = 3,
|
||||
SetQueueProperties = 16,
|
||||
TakeQueueOwnership = 524288,
|
||||
WriteMessage = 4
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ namespace System.Messaging
|
||||
CannotJoinDomain,
|
||||
CannotLoadMsmqOcm,
|
||||
CannotOpenCertificateStore,
|
||||
CannotSetCryptographicSecurityDescription,
|
||||
CannotSetCryptographicSecurityDescriptor,
|
||||
CannotSignDataEx,
|
||||
CertificateNotProvided,
|
||||
ComputerDoesNotSupportEncryption,
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
2004-05-31 Atsushi Enomoto <[email protected]>
|
||||
|
||||
* SignedXml.cs : partial fix for bug #59165 that does not output
|
||||
namespace that conflicts with element's namespace.
|
||||
|
||||
2004-05-13 Sebastien Pouliot <[email protected]>
|
||||
|
||||
* SignedXml.cs: Update TODO informations.
|
||||
|
||||
@@ -315,9 +315,10 @@ namespace System.Security.Cryptography.Xml {
|
||||
continue;
|
||||
if (attr.LocalName == "xml")
|
||||
continue;
|
||||
if (attr.Prefix == el.Prefix)
|
||||
continue;
|
||||
attr.WriteTo (xtw);
|
||||
}
|
||||
|
||||
foreach (XmlNode attr in el.Attributes)
|
||||
attr.WriteTo (xtw);
|
||||
foreach (XmlNode n in el.ChildNodes)
|
||||
|
||||
Loaded 100 of 222 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user