| 1 | // ZipConstants.cs
|
|---|
| 2 | //
|
|---|
| 3 | // Copyright (C) 2001 Mike Krueger
|
|---|
| 4 | // Copyright (C) 2004 John Reilly
|
|---|
| 5 | //
|
|---|
| 6 | // This file was translated from java, it was part of the GNU Classpath
|
|---|
| 7 | // Copyright (C) 2001 Free Software Foundation, Inc.
|
|---|
| 8 | //
|
|---|
| 9 | // This program is free software; you can redistribute it and/or
|
|---|
| 10 | // modify it under the terms of the GNU General Public License
|
|---|
| 11 | // as published by the Free Software Foundation; either version 2
|
|---|
| 12 | // of the License, or (at your option) any later version.
|
|---|
| 13 | //
|
|---|
| 14 | // This program is distributed in the hope that it will be useful,
|
|---|
| 15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 17 | // GNU General Public License for more details.
|
|---|
| 18 | //
|
|---|
| 19 | // You should have received a copy of the GNU General Public License
|
|---|
| 20 | // along with this program; if not, write to the Free Software
|
|---|
| 21 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|---|
| 22 | //
|
|---|
| 23 | // Linking this library statically or dynamically with other modules is
|
|---|
| 24 | // making a combined work based on this library. Thus, the terms and
|
|---|
| 25 | // conditions of the GNU General Public License cover the whole
|
|---|
| 26 | // combination.
|
|---|
| 27 | //
|
|---|
| 28 | // As a special exception, the copyright holders of this library give you
|
|---|
| 29 | // permission to link this library with independent modules to produce an
|
|---|
| 30 | // executable, regardless of the license terms of these independent
|
|---|
| 31 | // modules, and to copy and distribute the resulting executable under
|
|---|
| 32 | // terms of your choice, provided that you also meet, for each linked
|
|---|
| 33 | // independent module, the terms and conditions of the license of that
|
|---|
| 34 | // module. An independent module is a module which is not derived from
|
|---|
| 35 | // or based on this library. If you modify this library, you may extend
|
|---|
| 36 | // this exception to your version of the library, but you are not
|
|---|
| 37 | // obligated to do so. If you do not wish to do so, delete this
|
|---|
| 38 | // exception statement from your version.
|
|---|
| 39 |
|
|---|
| 40 | using System;
|
|---|
| 41 | using System.Text;
|
|---|
| 42 | using System.Threading;
|
|---|
| 43 |
|
|---|
| 44 | #if NETCF_1_0 || NETCF_2_0
|
|---|
| 45 | using System.Globalization;
|
|---|
| 46 | #endif
|
|---|
| 47 |
|
|---|
| 48 | namespace ICSharpCode.SharpZipLib.Zip
|
|---|
| 49 | {
|
|---|
| 50 |
|
|---|
| 51 | #region Enumerations
|
|---|
| 52 |
|
|---|
| 53 | /// <summary>
|
|---|
| 54 | /// Determines how entries are tested to see if they should use Zip64 extensions or not.
|
|---|
| 55 | /// </summary>
|
|---|
| 56 | public enum UseZip64
|
|---|
| 57 | {
|
|---|
| 58 | /// <summary>
|
|---|
| 59 | /// Zip64 will not be forced on entries during processing.
|
|---|
| 60 | /// </summary>
|
|---|
| 61 | /// <remarks>An entry can have this overridden if required <see cref="ZipEntry.ForceZip64"></see></remarks>
|
|---|
| 62 | Off,
|
|---|
| 63 | /// <summary>
|
|---|
| 64 | /// Zip64 should always be used.
|
|---|
| 65 | /// </summary>
|
|---|
| 66 | On,
|
|---|
| 67 | /// <summary>
|
|---|
| 68 | /// #ZipLib will determine use based on entry values when added to archive.
|
|---|
| 69 | /// </summary>
|
|---|
| 70 | Dynamic,
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | /// <summary>
|
|---|
| 74 | /// The kind of compression used for an entry in an archive
|
|---|
| 75 | /// </summary>
|
|---|
| 76 | public enum CompressionMethod
|
|---|
| 77 | {
|
|---|
| 78 | /// <summary>
|
|---|
| 79 | /// A direct copy of the file contents is held in the archive
|
|---|
| 80 | /// </summary>
|
|---|
| 81 | Stored = 0,
|
|---|
| 82 |
|
|---|
| 83 | /// <summary>
|
|---|
| 84 | /// Common Zip compression method using a sliding dictionary
|
|---|
| 85 | /// of up to 32KB and secondary compression from Huffman/Shannon-Fano trees
|
|---|
| 86 | /// </summary>
|
|---|
| 87 | Deflated = 8,
|
|---|
| 88 |
|
|---|
| 89 | /// <summary>
|
|---|
| 90 | /// An extension to deflate with a 64KB window. Not supported by #Zip currently
|
|---|
| 91 | /// </summary>
|
|---|
| 92 | Deflate64 = 9,
|
|---|
| 93 |
|
|---|
| 94 | /// <summary>
|
|---|
| 95 | /// BZip2 compression. Not supported by #Zip.
|
|---|
| 96 | /// </summary>
|
|---|
| 97 | BZip2 = 11,
|
|---|
| 98 |
|
|---|
| 99 | /// <summary>
|
|---|
| 100 | /// WinZip special for AES encryption, Not supported by #Zip.
|
|---|
| 101 | /// </summary>
|
|---|
| 102 | WinZipAES = 99,
|
|---|
| 103 |
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | /// <summary>
|
|---|
| 107 | /// Identifies the encryption algorithm used for an entry
|
|---|
| 108 | /// </summary>
|
|---|
| 109 | public enum EncryptionAlgorithm
|
|---|
| 110 | {
|
|---|
| 111 | /// <summary>
|
|---|
| 112 | /// No encryption has been used.
|
|---|
| 113 | /// </summary>
|
|---|
| 114 | None = 0,
|
|---|
| 115 | /// <summary>
|
|---|
| 116 | /// Encrypted using PKZIP 2.0 or 'classic' encryption.
|
|---|
| 117 | /// </summary>
|
|---|
| 118 | PkzipClassic = 1,
|
|---|
| 119 | /// <summary>
|
|---|
| 120 | /// DES encryption has been used.
|
|---|
| 121 | /// </summary>
|
|---|
| 122 | Des = 0x6601,
|
|---|
| 123 | /// <summary>
|
|---|
| 124 | /// RCS encryption has been used for encryption.
|
|---|
| 125 | /// </summary>
|
|---|
| 126 | RC2 = 0x6602,
|
|---|
| 127 | /// <summary>
|
|---|
| 128 | /// Triple DES encryption with 168 bit keys has been used for this entry.
|
|---|
| 129 | /// </summary>
|
|---|
| 130 | TripleDes168 = 0x6603,
|
|---|
| 131 | /// <summary>
|
|---|
| 132 | /// Triple DES with 112 bit keys has been used for this entry.
|
|---|
| 133 | /// </summary>
|
|---|
| 134 | TripleDes112 = 0x6609,
|
|---|
| 135 | /// <summary>
|
|---|
| 136 | /// AES 128 has been used for encryption.
|
|---|
| 137 | /// </summary>
|
|---|
| 138 | Aes128 = 0x660e,
|
|---|
| 139 | /// <summary>
|
|---|
| 140 | /// AES 192 has been used for encryption.
|
|---|
| 141 | /// </summary>
|
|---|
| 142 | Aes192 = 0x660f,
|
|---|
| 143 | /// <summary>
|
|---|
| 144 | /// AES 256 has been used for encryption.
|
|---|
| 145 | /// </summary>
|
|---|
| 146 | Aes256 = 0x6610,
|
|---|
| 147 | /// <summary>
|
|---|
| 148 | /// RC2 corrected has been used for encryption.
|
|---|
| 149 | /// </summary>
|
|---|
| 150 | RC2Corrected = 0x6702,
|
|---|
| 151 | /// <summary>
|
|---|
| 152 | /// Blowfish has been used for encryption.
|
|---|
| 153 | /// </summary>
|
|---|
| 154 | Blowfish = 0x6720,
|
|---|
| 155 | /// <summary>
|
|---|
| 156 | /// Twofish has been used for encryption.
|
|---|
| 157 | /// </summary>
|
|---|
| 158 | Twofish = 0x6721,
|
|---|
| 159 | /// <summary>
|
|---|
| 160 | /// RC4 has been used for encryption.
|
|---|
| 161 | /// </summary>
|
|---|
| 162 | RC4 = 0x6801,
|
|---|
| 163 | /// <summary>
|
|---|
| 164 | /// An unknown algorithm has been used for encryption.
|
|---|
| 165 | /// </summary>
|
|---|
| 166 | Unknown = 0xffff
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | /// <summary>
|
|---|
| 170 | /// Defines the contents of the general bit flags field for an archive entry.
|
|---|
| 171 | /// </summary>
|
|---|
| 172 | [Flags]
|
|---|
| 173 | public enum GeneralBitFlags : int
|
|---|
| 174 | {
|
|---|
| 175 | /// <summary>
|
|---|
| 176 | /// Bit 0 if set indicates that the file is encrypted
|
|---|
| 177 | /// </summary>
|
|---|
| 178 | Encrypted = 0x0001,
|
|---|
| 179 | /// <summary>
|
|---|
| 180 | /// Bits 1 and 2 - Two bits defining the compression method (only for Method 6 Imploding and 8,9 Deflating)
|
|---|
| 181 | /// </summary>
|
|---|
| 182 | Method = 0x0006,
|
|---|
| 183 | /// <summary>
|
|---|
| 184 | /// Bit 3 if set indicates a trailing data desciptor is appended to the entry data
|
|---|
| 185 | /// </summary>
|
|---|
| 186 | Descriptor = 0x0008,
|
|---|
| 187 | /// <summary>
|
|---|
| 188 | /// Bit 4 is reserved for use with method 8 for enhanced deflation
|
|---|
| 189 | /// </summary>
|
|---|
| 190 | ReservedPKware4 = 0x0010,
|
|---|
| 191 | /// <summary>
|
|---|
| 192 | /// Bit 5 if set indicates the file contains Pkzip compressed patched data.
|
|---|
| 193 | /// Requires version 2.7 or greater.
|
|---|
| 194 | /// </summary>
|
|---|
| 195 | Patched = 0x0020,
|
|---|
| 196 | /// <summary>
|
|---|
| 197 | /// Bit 6 if set strong encryption has been used for this entry.
|
|---|
| 198 | /// </summary>
|
|---|
| 199 | StrongEncryption = 0x0040,
|
|---|
| 200 | /// <summary>
|
|---|
| 201 | /// Bit 7 is currently unused
|
|---|
| 202 | /// </summary>
|
|---|
| 203 | Unused7 = 0x0080,
|
|---|
| 204 | /// <summary>
|
|---|
| 205 | /// Bit 8 is currently unused
|
|---|
| 206 | /// </summary>
|
|---|
| 207 | Unused8 = 0x0100,
|
|---|
| 208 | /// <summary>
|
|---|
| 209 | /// Bit 9 is currently unused
|
|---|
| 210 | /// </summary>
|
|---|
| 211 | Unused9 = 0x0200,
|
|---|
| 212 | /// <summary>
|
|---|
| 213 | /// Bit 10 is currently unused
|
|---|
| 214 | /// </summary>
|
|---|
| 215 | Unused10 = 0x0400,
|
|---|
| 216 | /// <summary>
|
|---|
| 217 | /// Bit 11 if set indicates the filename and
|
|---|
| 218 | /// comment fields for this file must be encoded using UTF-8.
|
|---|
| 219 | /// </summary>
|
|---|
| 220 | UnicodeText = 0x0800,
|
|---|
| 221 | /// <summary>
|
|---|
| 222 | /// Bit 12 is documented as being reserved by PKware for enhanced compression.
|
|---|
| 223 | /// </summary>
|
|---|
| 224 | EnhancedCompress = 0x1000,
|
|---|
| 225 | /// <summary>
|
|---|
| 226 | /// Bit 13 if set indicates that values in the local header are masked to hide
|
|---|
| 227 | /// their actual values, and the central directory is encrypted.
|
|---|
| 228 | /// </summary>
|
|---|
| 229 | /// <remarks>
|
|---|
| 230 | /// Used when encrypting the central directory contents.
|
|---|
| 231 | /// </remarks>
|
|---|
| 232 | HeaderMasked = 0x2000,
|
|---|
| 233 | /// <summary>
|
|---|
| 234 | /// Bit 14 is documented as being reserved for use by PKware
|
|---|
| 235 | /// </summary>
|
|---|
| 236 | ReservedPkware14 = 0x4000,
|
|---|
| 237 | /// <summary>
|
|---|
| 238 | /// Bit 15 is documented as being reserved for use by PKware
|
|---|
| 239 | /// </summary>
|
|---|
| 240 | ReservedPkware15 = 0x8000
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | #endregion
|
|---|
| 244 |
|
|---|
| 245 | /// <summary>
|
|---|
| 246 | /// This class contains constants used for Zip format files
|
|---|
| 247 | /// </summary>
|
|---|
| 248 | public sealed class ZipConstants
|
|---|
| 249 | {
|
|---|
| 250 | #region Versions
|
|---|
| 251 | /// <summary>
|
|---|
| 252 | /// The version made by field for entries in the central header when created by this library
|
|---|
| 253 | /// </summary>
|
|---|
| 254 | /// <remarks>
|
|---|
| 255 | /// This is also the Zip version for the library when comparing against the version required to extract
|
|---|
| 256 | /// for an entry. See <see cref="ZipEntry.CanDecompress"/>.
|
|---|
| 257 | /// </remarks>
|
|---|
| 258 | public const int VersionMadeBy = 45;
|
|---|
| 259 |
|
|---|
| 260 | /// <summary>
|
|---|
| 261 | /// The version made by field for entries in the central header when created by this library
|
|---|
| 262 | /// </summary>
|
|---|
| 263 | /// <remarks>
|
|---|
| 264 | /// This is also the Zip version for the library when comparing against the version required to extract
|
|---|
| 265 | /// for an entry. See <see cref="ZipInputStream.CanDecompressEntry">ZipInputStream.CanDecompressEntry</see>.
|
|---|
| 266 | /// </remarks>
|
|---|
| 267 | [Obsolete("Use VersionMadeBy instead")]
|
|---|
| 268 | public const int VERSION_MADE_BY = 45;
|
|---|
| 269 |
|
|---|
| 270 | /// <summary>
|
|---|
| 271 | /// The minimum version required to support strong encryption
|
|---|
| 272 | /// </summary>
|
|---|
| 273 | public const int VersionStrongEncryption = 50;
|
|---|
| 274 |
|
|---|
| 275 | /// <summary>
|
|---|
| 276 | /// The minimum version required to support strong encryption
|
|---|
| 277 | /// </summary>
|
|---|
| 278 | [Obsolete("Use VersionStrongEncryption instead")]
|
|---|
| 279 | public const int VERSION_STRONG_ENCRYPTION = 50;
|
|---|
| 280 |
|
|---|
| 281 | /// <summary>
|
|---|
| 282 | /// The version required for Zip64 extensions
|
|---|
| 283 | /// </summary>
|
|---|
| 284 | public const int VersionZip64 = 45;
|
|---|
| 285 | #endregion
|
|---|
| 286 |
|
|---|
| 287 | #region Header Sizes
|
|---|
| 288 | /// <summary>
|
|---|
| 289 | /// Size of local entry header (excluding variable length fields at end)
|
|---|
| 290 | /// </summary>
|
|---|
| 291 | public const int LocalHeaderBaseSize = 30;
|
|---|
| 292 |
|
|---|
| 293 | /// <summary>
|
|---|
| 294 | /// Size of local entry header (excluding variable length fields at end)
|
|---|
| 295 | /// </summary>
|
|---|
| 296 | [Obsolete("Use LocalHeaderBaseSize instead")]
|
|---|
| 297 | public const int LOCHDR = 30;
|
|---|
| 298 |
|
|---|
| 299 | /// <summary>
|
|---|
| 300 | /// Size of Zip64 data descriptor
|
|---|
| 301 | /// </summary>
|
|---|
| 302 | public const int Zip64DataDescriptorSize = 24;
|
|---|
| 303 |
|
|---|
| 304 | /// <summary>
|
|---|
| 305 | /// Size of data descriptor
|
|---|
| 306 | /// </summary>
|
|---|
| 307 | public const int DataDescriptorSize = 16;
|
|---|
| 308 |
|
|---|
| 309 | /// <summary>
|
|---|
| 310 | /// Size of data descriptor
|
|---|
| 311 | /// </summary>
|
|---|
| 312 | [Obsolete("Use DataDescriptorSize instead")]
|
|---|
| 313 | public const int EXTHDR = 16;
|
|---|
| 314 |
|
|---|
| 315 | /// <summary>
|
|---|
| 316 | /// Size of central header entry (excluding variable fields)
|
|---|
| 317 | /// </summary>
|
|---|
| 318 | public const int CentralHeaderBaseSize = 46;
|
|---|
| 319 |
|
|---|
| 320 | /// <summary>
|
|---|
| 321 | /// Size of central header entry
|
|---|
| 322 | /// </summary>
|
|---|
| 323 | [Obsolete("Use CentralHeaderBaseSize instead")]
|
|---|
| 324 | public const int CENHDR = 46;
|
|---|
| 325 |
|
|---|
| 326 | /// <summary>
|
|---|
| 327 | /// Size of end of central record (excluding variable fields)
|
|---|
| 328 | /// </summary>
|
|---|
| 329 | public const int EndOfCentralRecordBaseSize = 22;
|
|---|
| 330 |
|
|---|
| 331 | /// <summary>
|
|---|
| 332 | /// Size of end of central record (excluding variable fields)
|
|---|
| 333 | /// </summary>
|
|---|
| 334 | [Obsolete("Use EndOfCentralRecordBaseSize instead")]
|
|---|
| 335 | public const int ENDHDR = 22;
|
|---|
| 336 |
|
|---|
| 337 | /// <summary>
|
|---|
| 338 | /// Size of 'classic' cryptographic header stored before any entry data
|
|---|
| 339 | /// </summary>
|
|---|
| 340 | public const int CryptoHeaderSize = 12;
|
|---|
| 341 |
|
|---|
| 342 | /// <summary>
|
|---|
| 343 | /// Size of cryptographic header stored before entry data
|
|---|
| 344 | /// </summary>
|
|---|
| 345 | [Obsolete("Use CryptoHeaderSize instead")]
|
|---|
| 346 | public const int CRYPTO_HEADER_SIZE = 12;
|
|---|
| 347 | #endregion
|
|---|
| 348 |
|
|---|
| 349 | #region Header Signatures
|
|---|
| 350 |
|
|---|
| 351 | /// <summary>
|
|---|
| 352 | /// Signature for local entry header
|
|---|
| 353 | /// </summary>
|
|---|
| 354 | public const int LocalHeaderSignature = 'P' | ('K' << 8) | (3 << 16) | (4 << 24);
|
|---|
| 355 |
|
|---|
| 356 | /// <summary>
|
|---|
| 357 | /// Signature for local entry header
|
|---|
| 358 | /// </summary>
|
|---|
| 359 | [Obsolete("Use LocalHeaderSignature instead")]
|
|---|
| 360 | public const int LOCSIG = 'P' | ('K' << 8) | (3 << 16) | (4 << 24);
|
|---|
| 361 |
|
|---|
| 362 | /// <summary>
|
|---|
| 363 | /// Signature for spanning entry
|
|---|
| 364 | /// </summary>
|
|---|
| 365 | public const int SpanningSignature = 'P' | ('K' << 8) | (7 << 16) | (8 << 24);
|
|---|
| 366 |
|
|---|
| 367 | /// <summary>
|
|---|
| 368 | /// Signature for spanning entry
|
|---|
| 369 | /// </summary>
|
|---|
| 370 | [Obsolete("Use SpanningSignature instead")]
|
|---|
| 371 | public const int SPANNINGSIG = 'P' | ('K' << 8) | (7 << 16) | (8 << 24);
|
|---|
| 372 |
|
|---|
| 373 | /// <summary>
|
|---|
| 374 | /// Signature for temporary spanning entry
|
|---|
| 375 | /// </summary>
|
|---|
| 376 | public const int SpanningTempSignature = 'P' | ('K' << 8) | ('0' << 16) | ('0' << 24);
|
|---|
| 377 |
|
|---|
| 378 | /// <summary>
|
|---|
| 379 | /// Signature for temporary spanning entry
|
|---|
| 380 | /// </summary>
|
|---|
| 381 | [Obsolete("Use SpanningTempSignature instead")]
|
|---|
| 382 | public const int SPANTEMPSIG = 'P' | ('K' << 8) | ('0' << 16) | ('0' << 24);
|
|---|
| 383 |
|
|---|
| 384 | /// <summary>
|
|---|
| 385 | /// Signature for data descriptor
|
|---|
| 386 | /// </summary>
|
|---|
| 387 | /// <remarks>
|
|---|
| 388 | /// This is only used where the length, Crc, or compressed size isnt known when the
|
|---|
| 389 | /// entry is created and the output stream doesnt support seeking.
|
|---|
| 390 | /// The local entry cannot be 'patched' with the correct values in this case
|
|---|
| 391 | /// so the values are recorded after the data prefixed by this header, as well as in the central directory.
|
|---|
| 392 | /// </remarks>
|
|---|
| 393 | public const int DataDescriptorSignature = 'P' | ('K' << 8) | (7 << 16) | (8 << 24);
|
|---|
| 394 |
|
|---|
| 395 | /// <summary>
|
|---|
| 396 | /// Signature for data descriptor
|
|---|
| 397 | /// </summary>
|
|---|
| 398 | /// <remarks>
|
|---|
| 399 | /// This is only used where the length, Crc, or compressed size isnt known when the
|
|---|
| 400 | /// entry is created and the output stream doesnt support seeking.
|
|---|
| 401 | /// The local entry cannot be 'patched' with the correct values in this case
|
|---|
| 402 | /// so the values are recorded after the data prefixed by this header, as well as in the central directory.
|
|---|
| 403 | /// </remarks>
|
|---|
| 404 | [Obsolete("Use DataDescriptorSignature instead")]
|
|---|
| 405 | public const int EXTSIG = 'P' | ('K' << 8) | (7 << 16) | (8 << 24);
|
|---|
| 406 |
|
|---|
| 407 | /// <summary>
|
|---|
| 408 | /// Signature for central header
|
|---|
| 409 | /// </summary>
|
|---|
| 410 | [Obsolete("Use CentralHeaderSignature instead")]
|
|---|
| 411 | public const int CENSIG = 'P' | ('K' << 8) | (1 << 16) | (2 << 24);
|
|---|
| 412 |
|
|---|
| 413 | /// <summary>
|
|---|
| 414 | /// Signature for central header
|
|---|
| 415 | /// </summary>
|
|---|
| 416 | public const int CentralHeaderSignature = 'P' | ('K' << 8) | (1 << 16) | (2 << 24);
|
|---|
| 417 |
|
|---|
| 418 | /// <summary>
|
|---|
| 419 | /// Signature for Zip64 central file header
|
|---|
| 420 | /// </summary>
|
|---|
| 421 | public const int Zip64CentralFileHeaderSignature = 'P' | ('K' << 8) | (6 << 16) | (6 << 24);
|
|---|
| 422 |
|
|---|
| 423 | /// <summary>
|
|---|
| 424 | /// Signature for Zip64 central file header
|
|---|
| 425 | /// </summary>
|
|---|
| 426 | [Obsolete("Use Zip64CentralFileHeaderSignature instead")]
|
|---|
| 427 | public const int CENSIG64 = 'P' | ('K' << 8) | (6 << 16) | (6 << 24);
|
|---|
| 428 |
|
|---|
| 429 | /// <summary>
|
|---|
| 430 | /// Signature for Zip64 central directory locator
|
|---|
| 431 | /// </summary>
|
|---|
| 432 | public const int Zip64CentralDirLocatorSignature = 'P' | ('K' << 8) | (6 << 16) | (7 << 24);
|
|---|
| 433 |
|
|---|
| 434 | /// <summary>
|
|---|
| 435 | /// Signature for archive extra data signature (were headers are encrypted).
|
|---|
| 436 | /// </summary>
|
|---|
| 437 | public const int ArchiveExtraDataSignature = 'P' | ('K' << 8) | (6 << 16) | (7 << 24);
|
|---|
| 438 |
|
|---|
| 439 | /// <summary>
|
|---|
| 440 | /// Central header digitial signature
|
|---|
| 441 | /// </summary>
|
|---|
| 442 | public const int CentralHeaderDigitalSignature = 'P' | ('K' << 8) | (5 << 16) | (5 << 24);
|
|---|
| 443 |
|
|---|
| 444 | /// <summary>
|
|---|
| 445 | /// Central header digitial signature
|
|---|
| 446 | /// </summary>
|
|---|
| 447 | [Obsolete("Use CentralHeaderDigitalSignaure instead")]
|
|---|
| 448 | public const int CENDIGITALSIG = 'P' | ('K' << 8) | (5 << 16) | (5 << 24);
|
|---|
| 449 |
|
|---|
| 450 | /// <summary>
|
|---|
| 451 | /// End of central directory record signature
|
|---|
| 452 | /// </summary>
|
|---|
| 453 | public const int EndOfCentralDirectorySignature = 'P' | ('K' << 8) | (5 << 16) | (6 << 24);
|
|---|
| 454 |
|
|---|
| 455 | /// <summary>
|
|---|
| 456 | /// End of central directory record signature
|
|---|
| 457 | /// </summary>
|
|---|
| 458 | [Obsolete("Use EndOfCentralDirectorySignature instead")]
|
|---|
| 459 | public const int ENDSIG = 'P' | ('K' << 8) | (5 << 16) | (6 << 24);
|
|---|
| 460 | #endregion
|
|---|
| 461 |
|
|---|
| 462 | #if NETCF_1_0 || NETCF_2_0
|
|---|
| 463 | // This isnt so great but is better than nothing.
|
|---|
| 464 | // Trying to work out an appropriate OEM code page would be good.
|
|---|
| 465 | // 850 is a good default for english speakers particularly in Europe.
|
|---|
| 466 | static int defaultCodePage = CultureInfo.CurrentCulture.TextInfo.ANSICodePage;
|
|---|
| 467 | #else
|
|---|
| 468 | static int defaultCodePage = Thread.CurrentThread.CurrentCulture.TextInfo.OEMCodePage;
|
|---|
| 469 | #endif
|
|---|
| 470 |
|
|---|
| 471 | /// <summary>
|
|---|
| 472 | /// Default encoding used for string conversion. 0 gives the default system OEM code page.
|
|---|
| 473 | /// Dont use unicode encodings if you want to be Zip compatible!
|
|---|
| 474 | /// Using the default code page isnt the full solution neccessarily
|
|---|
| 475 | /// there are many variable factors, codepage 850 is often a good choice for
|
|---|
| 476 | /// European users, however be careful about compatability.
|
|---|
| 477 | /// </summary>
|
|---|
| 478 | public static int DefaultCodePage {
|
|---|
| 479 | get {
|
|---|
| 480 | return defaultCodePage;
|
|---|
| 481 | }
|
|---|
| 482 | set {
|
|---|
| 483 | defaultCodePage = value;
|
|---|
| 484 | }
|
|---|
| 485 | }
|
|---|
| 486 |
|
|---|
| 487 | /// <summary>
|
|---|
| 488 | /// Convert a portion of a byte array to a string.
|
|---|
| 489 | /// </summary>
|
|---|
| 490 | /// <param name="data">
|
|---|
| 491 | /// Data to convert to string
|
|---|
| 492 | /// </param>
|
|---|
| 493 | /// <param name="count">
|
|---|
| 494 | /// Number of bytes to convert starting from index 0
|
|---|
| 495 | /// </param>
|
|---|
| 496 | /// <returns>
|
|---|
| 497 | /// data[0]..data[length - 1] converted to a string
|
|---|
| 498 | /// </returns>
|
|---|
| 499 | public static string ConvertToString(byte[] data, int count)
|
|---|
| 500 | {
|
|---|
| 501 | if ( data == null ) {
|
|---|
| 502 | return string.Empty;
|
|---|
| 503 | }
|
|---|
| 504 |
|
|---|
| 505 | return Encoding.GetEncoding(DefaultCodePage).GetString(data, 0, count);
|
|---|
| 506 | }
|
|---|
| 507 |
|
|---|
| 508 | /// <summary>
|
|---|
| 509 | /// Convert a byte array to string
|
|---|
| 510 | /// </summary>
|
|---|
| 511 | /// <param name="data">
|
|---|
| 512 | /// Byte array to convert
|
|---|
| 513 | /// </param>
|
|---|
| 514 | /// <returns>
|
|---|
| 515 | /// <paramref name="data">data</paramref>converted to a string
|
|---|
| 516 | /// </returns>
|
|---|
| 517 | public static string ConvertToString(byte[] data)
|
|---|
| 518 | {
|
|---|
| 519 | if ( data == null ) {
|
|---|
| 520 | return string.Empty;
|
|---|
| 521 | }
|
|---|
| 522 | return ConvertToString(data, data.Length);
|
|---|
| 523 | }
|
|---|
| 524 |
|
|---|
| 525 | /// <summary>
|
|---|
| 526 | /// Convert a byte array to string
|
|---|
| 527 | /// </summary>
|
|---|
| 528 | /// <param name="flags">The applicable general purpose bits flags</param>
|
|---|
| 529 | /// <param name="data">
|
|---|
| 530 | /// Byte array to convert
|
|---|
| 531 | /// </param>
|
|---|
| 532 | /// <param name="count">The number of bytes to convert.</param>
|
|---|
| 533 | /// <returns>
|
|---|
| 534 | /// <paramref name="data">data</paramref>converted to a string
|
|---|
| 535 | /// </returns>
|
|---|
| 536 | public static string ConvertToStringExt(int flags, byte[] data, int count)
|
|---|
| 537 | {
|
|---|
| 538 | if ( data == null ) {
|
|---|
| 539 | return string.Empty;
|
|---|
| 540 | }
|
|---|
| 541 |
|
|---|
| 542 | if ( (flags & (int)GeneralBitFlags.UnicodeText) != 0 ) {
|
|---|
| 543 | return Encoding.UTF8.GetString(data, 0, count);
|
|---|
| 544 | }
|
|---|
| 545 | else {
|
|---|
| 546 | return ConvertToString(data, count);
|
|---|
| 547 | }
|
|---|
| 548 | }
|
|---|
| 549 |
|
|---|
| 550 | /// <summary>
|
|---|
| 551 | /// Convert a byte array to string
|
|---|
| 552 | /// </summary>
|
|---|
| 553 | /// <param name="data">
|
|---|
| 554 | /// Byte array to convert
|
|---|
| 555 | /// </param>
|
|---|
| 556 | /// <param name="flags">The applicable general purpose bits flags</param>
|
|---|
| 557 | /// <returns>
|
|---|
| 558 | /// <paramref name="data">data</paramref>converted to a string
|
|---|
| 559 | /// </returns>
|
|---|
| 560 | public static string ConvertToStringExt(int flags, byte[] data)
|
|---|
| 561 | {
|
|---|
| 562 | if ( data == null ) {
|
|---|
| 563 | return string.Empty;
|
|---|
| 564 | }
|
|---|
| 565 |
|
|---|
| 566 | if ( (flags & (int)GeneralBitFlags.UnicodeText) != 0 ) {
|
|---|
| 567 | return Encoding.UTF8.GetString(data, 0, data.Length);
|
|---|
| 568 | }
|
|---|
| 569 | else {
|
|---|
| 570 | return ConvertToString(data, data.Length);
|
|---|
| 571 | }
|
|---|
| 572 | }
|
|---|
| 573 |
|
|---|
| 574 | /// <summary>
|
|---|
| 575 | /// Convert a string to a byte array
|
|---|
| 576 | /// </summary>
|
|---|
| 577 | /// <param name="str">
|
|---|
| 578 | /// String to convert to an array
|
|---|
| 579 | /// </param>
|
|---|
| 580 | /// <returns>Converted array</returns>
|
|---|
| 581 | public static byte[] ConvertToArray(string str)
|
|---|
| 582 | {
|
|---|
| 583 | if ( str == null ) {
|
|---|
| 584 | return new byte[0];
|
|---|
| 585 | }
|
|---|
| 586 |
|
|---|
| 587 | return Encoding.GetEncoding(DefaultCodePage).GetBytes(str);
|
|---|
| 588 | }
|
|---|
| 589 |
|
|---|
| 590 | /// <summary>
|
|---|
| 591 | /// Convert a string to a byte array
|
|---|
| 592 | /// </summary>
|
|---|
| 593 | /// <param name="flags">The applicable <see cref="GeneralBitFlags">general purpose bits flags</see></param>
|
|---|
| 594 | /// <param name="str">
|
|---|
| 595 | /// String to convert to an array
|
|---|
| 596 | /// </param>
|
|---|
| 597 | /// <returns>Converted array</returns>
|
|---|
| 598 | public static byte[] ConvertToArray(int flags, string str)
|
|---|
| 599 | {
|
|---|
| 600 | if (str == null) {
|
|---|
| 601 | return new byte[0];
|
|---|
| 602 | }
|
|---|
| 603 |
|
|---|
| 604 | if ((flags & (int)GeneralBitFlags.UnicodeText) != 0) {
|
|---|
| 605 | return Encoding.UTF8.GetBytes(str);
|
|---|
| 606 | }
|
|---|
| 607 | else {
|
|---|
| 608 | return ConvertToArray(str);
|
|---|
| 609 | }
|
|---|
| 610 | }
|
|---|
| 611 |
|
|---|
| 612 |
|
|---|
| 613 | /// <summary>
|
|---|
| 614 | /// Initialise default instance of <see cref="ZipConstants">ZipConstants</see>
|
|---|
| 615 | /// </summary>
|
|---|
| 616 | /// <remarks>
|
|---|
| 617 | /// Private to prevent instances being created.
|
|---|
| 618 | /// </remarks>
|
|---|
| 619 | ZipConstants()
|
|---|
| 620 | {
|
|---|
| 621 | // Do nothing
|
|---|
| 622 | }
|
|---|
| 623 | }
|
|---|
| 624 | }
|
|---|