123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648 |
- using System;
- using System.Text;
- using System.Threading;
- #if NETCF_1_0 || NETCF_2_0
- using System.Globalization;
- #endif
- namespace CommonMPQ.SharpZipLib.Zip
- {
- #region Enumerations
-
-
-
-
- public enum UseZip64
- {
-
-
-
-
- Off,
-
-
-
- On,
-
-
-
- Dynamic,
- }
-
-
-
-
- public enum CompressionMethod
- {
-
-
-
- Stored = 0,
-
-
-
-
-
- Deflated = 8,
-
-
-
-
- Deflate64 = 9,
-
-
-
-
- BZip2 = 11,
-
-
-
-
- WinZipAES = 99,
-
- }
-
-
-
-
- public enum EncryptionAlgorithm
- {
-
-
-
- None = 0,
-
-
-
- PkzipClassic = 1,
-
-
-
- Des = 0x6601,
-
-
-
- RC2 = 0x6602,
-
-
-
- TripleDes168 = 0x6603,
-
-
-
- TripleDes112 = 0x6609,
-
-
-
- Aes128 = 0x660e,
-
-
-
- Aes192 = 0x660f,
-
-
-
- Aes256 = 0x6610,
-
-
-
- RC2Corrected = 0x6702,
-
-
-
- Blowfish = 0x6720,
-
-
-
- Twofish = 0x6721,
-
-
-
- RC4 = 0x6801,
-
-
-
- Unknown = 0xffff
- }
-
-
-
- [Flags]
- public enum GeneralBitFlags : int
- {
-
-
-
- Encrypted = 0x0001,
-
-
-
- Method = 0x0006,
-
-
-
- Descriptor = 0x0008,
-
-
-
- ReservedPKware4 = 0x0010,
-
-
-
-
- Patched = 0x0020,
-
-
-
- StrongEncryption = 0x0040,
-
-
-
- Unused7 = 0x0080,
-
-
-
- Unused8 = 0x0100,
-
-
-
- Unused9 = 0x0200,
-
-
-
- Unused10 = 0x0400,
-
-
-
-
- UnicodeText = 0x0800,
-
-
-
- EnhancedCompress = 0x1000,
-
-
-
-
-
-
-
- HeaderMasked = 0x2000,
-
-
-
- ReservedPkware14 = 0x4000,
-
-
-
- ReservedPkware15 = 0x8000
- }
-
- #endregion
-
-
-
- public sealed class ZipConstants
- {
- #region Versions
-
-
-
-
-
-
-
- public const int VersionMadeBy = 51;
-
-
-
-
-
-
-
-
- [Obsolete("Use VersionMadeBy instead")]
- public const int VERSION_MADE_BY = 51;
-
-
-
-
- public const int VersionStrongEncryption = 50;
-
-
-
- [Obsolete("Use VersionStrongEncryption instead")]
- public const int VERSION_STRONG_ENCRYPTION = 50;
-
-
-
- public const int VERSION_AES = 51;
-
-
-
- public const int VersionZip64 = 45;
- #endregion
-
- #region Header Sizes
-
-
-
- public const int LocalHeaderBaseSize = 30;
-
-
-
-
- [Obsolete("Use LocalHeaderBaseSize instead")]
- public const int LOCHDR = 30;
-
-
-
-
- public const int Zip64DataDescriptorSize = 24;
-
-
-
-
- public const int DataDescriptorSize = 16;
-
-
-
-
- [Obsolete("Use DataDescriptorSize instead")]
- public const int EXTHDR = 16;
-
-
-
-
- public const int CentralHeaderBaseSize = 46;
-
-
-
-
- [Obsolete("Use CentralHeaderBaseSize instead")]
- public const int CENHDR = 46;
-
-
-
-
- public const int EndOfCentralRecordBaseSize = 22;
-
-
-
-
- [Obsolete("Use EndOfCentralRecordBaseSize instead")]
- public const int ENDHDR = 22;
-
-
-
-
- public const int CryptoHeaderSize = 12;
-
-
-
-
- [Obsolete("Use CryptoHeaderSize instead")]
- public const int CRYPTO_HEADER_SIZE = 12;
- #endregion
-
- #region Header Signatures
-
-
-
-
- public const int LocalHeaderSignature = 'P' | ('K' << 8) | (3 << 16) | (4 << 24);
-
-
-
- [Obsolete("Use LocalHeaderSignature instead")]
- public const int LOCSIG = 'P' | ('K' << 8) | (3 << 16) | (4 << 24);
-
-
-
- public const int SpanningSignature = 'P' | ('K' << 8) | (7 << 16) | (8 << 24);
-
-
-
-
- [Obsolete("Use SpanningSignature instead")]
- public const int SPANNINGSIG = 'P' | ('K' << 8) | (7 << 16) | (8 << 24);
-
-
-
-
- public const int SpanningTempSignature = 'P' | ('K' << 8) | ('0' << 16) | ('0' << 24);
-
-
-
-
- [Obsolete("Use SpanningTempSignature instead")]
- public const int SPANTEMPSIG = 'P' | ('K' << 8) | ('0' << 16) | ('0' << 24);
-
-
-
-
-
-
-
-
-
-
- public const int DataDescriptorSignature = 'P' | ('K' << 8) | (7 << 16) | (8 << 24);
-
-
-
-
-
-
-
-
-
-
- [Obsolete("Use DataDescriptorSignature instead")]
- public const int EXTSIG = 'P' | ('K' << 8) | (7 << 16) | (8 << 24);
-
-
-
-
- [Obsolete("Use CentralHeaderSignature instead")]
- public const int CENSIG = 'P' | ('K' << 8) | (1 << 16) | (2 << 24);
-
-
-
- public const int CentralHeaderSignature = 'P' | ('K' << 8) | (1 << 16) | (2 << 24);
-
-
-
- public const int Zip64CentralFileHeaderSignature = 'P' | ('K' << 8) | (6 << 16) | (6 << 24);
-
-
-
-
- [Obsolete("Use Zip64CentralFileHeaderSignature instead")]
- public const int CENSIG64 = 'P' | ('K' << 8) | (6 << 16) | (6 << 24);
-
-
-
-
- public const int Zip64CentralDirLocatorSignature = 'P' | ('K' << 8) | (6 << 16) | (7 << 24);
-
-
-
-
- public const int ArchiveExtraDataSignature = 'P' | ('K' << 8) | (6 << 16) | (7 << 24);
-
-
-
-
- public const int CentralHeaderDigitalSignature = 'P' | ('K' << 8) | (5 << 16) | (5 << 24);
-
-
-
-
- [Obsolete("Use CentralHeaderDigitalSignaure instead")]
- public const int CENDIGITALSIG = 'P' | ('K' << 8) | (5 << 16) | (5 << 24);
-
-
-
- public const int EndOfCentralDirectorySignature = 'P' | ('K' << 8) | (5 << 16) | (6 << 24);
-
-
-
-
- [Obsolete("Use EndOfCentralDirectorySignature instead")]
- public const int ENDSIG = 'P' | ('K' << 8) | (5 << 16) | (6 << 24);
- #endregion
-
- #if NETCF_1_0 || NETCF_2_0
-
-
-
- static int defaultCodePage = CultureInfo.CurrentCulture.TextInfo.ANSICodePage;
- #else
-
-
-
-
-
-
-
- static int defaultCodePage =
-
- ((Thread.CurrentThread.CurrentCulture.TextInfo.OEMCodePage == 1) || (Thread.CurrentThread.CurrentCulture.TextInfo.OEMCodePage == 2) || (Thread.CurrentThread.CurrentCulture.TextInfo.OEMCodePage == 3) || (Thread.CurrentThread.CurrentCulture.TextInfo.OEMCodePage == 42))
- ? 437
- : Thread.CurrentThread.CurrentCulture.TextInfo.OEMCodePage;
- #endif
-
-
-
-
-
-
-
-
- public static int DefaultCodePage {
- get {
- return defaultCodePage;
- }
- set {
- if ((value < 0) || (value > 65535) ||
- (value == 1) || (value == 2) || (value == 3) || (value == 42)) {
- throw new ArgumentOutOfRangeException("value");
- }
- defaultCodePage = value;
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
- public static string ConvertToString(byte[] data, int count)
- {
- if ( data == null ) {
- return string.Empty;
- }
-
- return Encoding.GetEncoding(DefaultCodePage).GetString(data, 0, count);
- }
-
-
-
-
-
-
-
-
-
-
- public static string ConvertToString(byte[] data)
- {
- if ( data == null ) {
- return string.Empty;
- }
- return ConvertToString(data, data.Length);
- }
-
-
-
-
-
-
-
-
-
-
-
- public static string ConvertToStringExt(int flags, byte[] data, int count)
- {
- if ( data == null ) {
- return string.Empty;
- }
-
- if ( (flags & (int)GeneralBitFlags.UnicodeText) != 0 ) {
- return Encoding.UTF8.GetString(data, 0, count);
- }
- else {
- return ConvertToString(data, count);
- }
- }
-
-
-
-
-
-
-
-
-
-
-
- public static string ConvertToStringExt(int flags, byte[] data)
- {
- if ( data == null ) {
- return string.Empty;
- }
-
- if ( (flags & (int)GeneralBitFlags.UnicodeText) != 0 ) {
- return Encoding.UTF8.GetString(data, 0, data.Length);
- }
- else {
- return ConvertToString(data, data.Length);
- }
- }
-
-
-
-
-
-
-
- public static byte[] ConvertToArray(string str)
- {
- if ( str == null ) {
- return new byte[0];
- }
-
- return Encoding.GetEncoding(DefaultCodePage).GetBytes(str);
- }
-
-
-
-
-
-
-
-
- public static byte[] ConvertToArray(int flags, string str)
- {
- if (str == null) {
- return new byte[0];
- }
- if ((flags & (int)GeneralBitFlags.UnicodeText) != 0) {
- return Encoding.UTF8.GetBytes(str);
- }
- else {
- return ConvertToArray(str);
- }
- }
-
-
-
-
-
-
-
- ZipConstants()
- {
-
- }
- }
- }
|