Subversion Repositories autosfx

Rev

Blame | Last modification | View Log | RSS feed

  1. //---------------------------------------------------------------------------
  2. #ifndef CommonH
  3. #define CommonH
  4. //---------------------------------------------------------------------------
  5.  
  6. /*
  7.   Common.h - common definitions and functions
  8.  
  9.   Copyright (c) 1990-2007 Info-ZIP.  All rights reserved.
  10.  
  11.   See the accompanying file LICENSE, version 2007-Mar-4 or later
  12.   (the contents of which are also included in zip.h) for terms of use.
  13.   If, for some reason, all these files are missing, the Info-ZIP license
  14.   also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html
  15.  
  16.   parts Copyright (C) 1997 Mike White, Eric W. Engler
  17. ************************************************************************
  18.  Copyright (C) 2009, 2010  by Russell J. Peters, Roger Aelbrecht
  19.  
  20.    This file is part of TZipMaster Version 1.9.
  21.  
  22.     TZipMaster is free software: you can redistribute it and/or modify
  23.     it under the terms of the GNU Lesser General Public License as published by
  24.     the Free Software Foundation, either version 3 of the License, or
  25.     (at your option) any later version.
  26.  
  27.     TZipMaster is distributed in the hope that it will be useful,
  28.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  29.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  30.     GNU Lesser General Public License for more details.
  31.  
  32.     You should have received a copy of the GNU Lesser General Public License
  33.     along with TZipMaster.  If not, see <http://www.gnu.org/licenses/>.
  34.  
  35.     contact: problems@delphizip.org (include ZipMaster in the subject).
  36.     updates: http://www.delphizip.org
  37.     DelphiZip maillist subscribe at http://www.freelists.org/list/delphizip
  38. ************************************************************************/
  39.  
  40. #ifdef __MT__
  41.     #define MULTITHREAD
  42. #else
  43. #undef MULTITHREAD
  44.     #error no Multithread
  45. #endif
  46.  
  47. #define  MAX_UNSIGNED 0xFFFFFFFFul
  48. #define  MAX_WORD 0xFFFFu
  49. #define  MAX_BYTE = 0xFFu
  50. #ifndef MAXINT
  51.     #define MAXINT      0x7fffffff
  52. #endif
  53. #ifndef MAXLONG
  54.     #define MAXLONG     0x7fffffffl
  55. #endif
  56.  
  57. #include "DelZip.h"
  58. #include "dz_msgs.h"
  59.  
  60. __int64 SetFilePointer64(HANDLE hf, __int64 ofs, int from);
  61.  
  62. typedef unsigned char   uch;          /* unsigned 8-bit value */
  63. typedef unsigned short  ush;          /* unsigned 16-bit value */
  64. typedef unsigned long   ulg;          /* unsigned 32-bit value */
  65. typedef size_t  extent;
  66.  
  67. typedef char zchar;
  68.  
  69. extern HINSTANCE ModuleInst;
  70.  
  71. typedef unsigned long OperKeys;
  72.  
  73. #ifndef _FORCE_Z64_
  74. #define Z64THRESHOLD 0xFFED0000u
  75. #else
  76. #define Z64THRESHOLD 0x400u
  77. #endif
  78.  
  79. //                       these are stored in reverse order
  80. #define  CentralFileHeaderSig   0x02014B50   // 'PK'12
  81. #define  LocalFileHeaderSig     0x04034B50   // 'PK'34  (in file: 504b0304)
  82. #define  CentralDigSig          0x05054B50   // 'PK'55
  83. #define  EndCentralDirSig       0x06054B50   // 'PK'56
  84. #define  ExtLocalSig            0x08074B50   // 'PK'78
  85. #define  EndCentral64Sig        0x06064B50   // 'PK'66
  86. #define  EOC64LocatorSig        0x07064B50   // 'PK'67
  87.  
  88. typedef __int64 ZInt64;
  89. /*  The zipfile format is defined as below:
  90.  *
  91.  *   [Extra Extended Signature]
  92.  *   NumberOfFiles *{ local header + Filename + [extra data] + [file data] + [data_descriptor] }
  93.  *   NumberOfFiles *{ central directory + Filename + [extra data] + [filecomment] }
  94.  *   End Of Central directory + [ZipFile comment]
  95.  */
  96. #pragma pack(push, 1)
  97. typedef struct _ZipLocalHeader
  98. {
  99.     unsigned long   HeaderSig;        // Should be 0x04034B50
  100.     union
  101.     {
  102.         unsigned char VersionNeeded[2];
  103.         unsigned short VersionNeed;
  104.     };
  105.     unsigned short  Flag;
  106.     unsigned short  ComprMethod;
  107.     union
  108.     {
  109.  
  110.         struct
  111.         {
  112.             unsigned short  ModifTime;
  113.             unsigned short  ModifDate;
  114.         };
  115.  
  116.         unsigned long ModifStamp;
  117.     };
  118.     unsigned long   CRC32;
  119.     unsigned long   ComprSize;
  120.     unsigned long   UnComprSize;
  121.     unsigned short  FileNameLen;
  122.     unsigned short  ExtraLen;
  123.  
  124.     // ... and the filename itself,
  125.     // ... and the extra data.
  126. }ZipLocalHeader;
  127. #pragma pack(pop)
  128.  
  129. #pragma pack(push, 1)
  130. typedef struct _ZipDataDescriptor
  131. {
  132.     unsigned long DataDescSig;        // Should be 0x08074B50
  133.     unsigned long CRC32;
  134.     unsigned long ComprSize;
  135.     unsigned long UnComprSize;
  136. } ZipDataDescriptor;
  137. #pragma pack(pop)
  138.  
  139. #pragma pack(push, 1)
  140. struct ZipCentralHeader
  141. {
  142.     unsigned long HeaderSig;          // Should be 0x02014B50
  143.     union
  144.     {
  145.         struct
  146.         {
  147.             unsigned char MadeByVersion;  // Made by version number
  148.             unsigned char MadeByHost;     // Made by host number
  149.         };
  150.         unsigned short  MadeBy;
  151.     };
  152.     union
  153.     {
  154.         unsigned char VersionNeeded[2];
  155.         unsigned short VersionNeed;
  156.     };
  157. //  unsigned short  VersionNeed;
  158.     unsigned short  Flag;
  159.     unsigned short  ComprMethod;
  160.     union
  161.     {
  162.         struct
  163.         {
  164.             unsigned short  ModifTime;
  165.             unsigned short  ModifDate;
  166.         };
  167.         unsigned long ModifStamp;
  168.     };
  169.     unsigned long   CRC32;
  170.     unsigned long   ComprSize;
  171.     unsigned long   UnComprSize;
  172.     unsigned short  FileNameLen;
  173.     unsigned short  ExtraLen;
  174.     unsigned short  FileComLen;
  175.     unsigned short  DiskStart;        // The number of the disk on which this file begins.
  176.     unsigned short  IntFileAtt;
  177.     unsigned long   ExtFileAtt;
  178.     unsigned long   RelOffLocal;      // This is the offset from the start of the first disk on
  179.  
  180.     // which this file appears, to where the local header
  181.     // should be found.
  182.     // ... and the filename itself,
  183.     // ... and the extra data,
  184.     // ... and the file comment.
  185. };
  186. #pragma pack(pop)
  187.  
  188. #pragma pack(push, 1)
  189. typedef struct _ZipEndOfCentral
  190. {
  191.     unsigned long   HeaderSig;        // Should be 0x06054B50
  192.     unsigned short  ThisDiskNo;
  193.     unsigned short  CentralDiskNo;
  194.     unsigned short  CentralEntries;   // Total number of entries in the central dir on this disk.
  195.     unsigned short  TotalEntries;     // Total number of entries in the central dir.
  196.     unsigned long   CentralSize;
  197.     unsigned long   CentralOffset;    // Offset of start of central directory with respect to the starting disk number.
  198.     unsigned short  ZipCommentLen;
  199.     // And the comment itself.
  200. } ZipEndOfCentral;
  201. #pragma pack(pop)
  202.  
  203. #pragma pack(push, 1)
  204. // must be same disk as EOC
  205. typedef struct _Zip64EOCLocator
  206. {
  207.     unsigned long   HeaderSig;        // (4) Should be 0x07064B50
  208.     unsigned long   EOC64DiskStt;     // (4)
  209.     ZInt64          EOC64RelOfs;      // (8) relative to start of it's disk
  210.     unsigned long   NumberDisks;      // (4) total disks
  211. }Zip64EOCLocator;
  212. #pragma pack(pop)
  213.  
  214. #pragma pack(push, 1)
  215. typedef struct _ZipEOC64
  216. {
  217.     unsigned long   HeaderSig;            // (4) should be 0x06064b50
  218.     ZInt64          vsize;                // (8)    size of variable part
  219.     // variable part   - fields as needed? (old field = 0XFFFF or 0XFF)
  220.     unsigned short  VersionMade;          // (2)
  221.     unsigned short  VersionNeed;          // (2)
  222.     unsigned long   ThisDiskNo;           // (4)
  223.     unsigned long   CentralDiskNo;        // (4)
  224.     ZInt64          CentralEntries;       // (8) Number of central dir entries on this disk
  225.     ZInt64          TotalEntries;         // (8) Number of entries in central dir
  226.     ZInt64          CentralSize;          // (8) Size of central directory
  227.     ZInt64          CentralOffSet;        // (8) offsett of central dir on 1st disk
  228. //  zip64 extensible data sector    (variable size)
  229. }ZipEOC64;
  230. #pragma pack(pop)
  231.  
  232. #pragma pack(push, 1)
  233. typedef struct _ZipDataDescriptor64
  234. {
  235.     unsigned long DataDescSig;        // Should be 0x08074B50
  236.     unsigned long CRC32;
  237.     ZInt64 ComprSize;
  238.     ZInt64 UnComprSize;
  239. }ZipDataDescriptor64;
  240. #pragma pack(pop)
  241.  
  242.  
  243. #pragma pack(push, 1)
  244. typedef struct _ZipCentralDigitSignature
  245. {
  246.     unsigned long   HeaderSig;            // (4) should be 0x05054b50
  247.     unsigned short  vsize;                // (2)
  248. //    data[vsize]
  249. }ZipCentralDigitSignature;
  250. #pragma pack(pop)
  251.  
  252. #pragma pack(push, 1)
  253. union XDataHead //Zip64_xdata
  254. {
  255.     struct
  256.     {
  257.         unsigned short Tag;                   // (2) should be 0x0001
  258.         unsigned short vsize;                 // (2)
  259.     };
  260.     unsigned long _head;
  261.     // data[vsize]
  262. };
  263. #pragma pack(pop)
  264.  
  265. #pragma pack(push, 1)
  266. struct UPhead
  267. {
  268.     XDataHead hed;
  269.     unsigned char ver;         // 1
  270.     unsigned long crc;          // crc of orig field
  271. //        char u;
  272. };
  273. #pragma pack(pop)
  274.  
  275. #pragma pack(push, 1)
  276. struct XNTFSData
  277. {
  278.     _FILETIME MTime;
  279.     _FILETIME ATime;
  280.     _FILETIME CTime;
  281. };
  282. #pragma pack(pop)
  283.  
  284. #pragma pack(push, 1)
  285. struct XNTFSHead
  286. {
  287.         XDataHead hed;
  288.         unsigned  rsrvd;
  289.         unsigned short Tg1;       // (2) should be 0x0001
  290.         unsigned short Sz1;       // (2) should be 24
  291.         XNTFSData times;
  292. };
  293. #pragma pack(pop)
  294.  
  295. #pragma pack(push, 1)
  296. struct X_NTFSHeader
  297. {
  298.         XDataHead hed;
  299.         unsigned  rsrvd;
  300. //      unsigned short Tg1;       // (2) should be 0x0001
  301. //      unsigned short Sz1;       // (2) should be 24
  302. //      XNTFSData times;
  303. };
  304. #pragma pack(pop)
  305.  
  306.  
  307. #define  ZIP64_XDATA_TAG 0x0001     // Zip64 extra field tag
  308. #define  UPATH_XDATA_TAG 0x7075
  309. #define  UCMNT_XDATA_TAG 0x6375
  310. #define  NTFS_STAMP_TAG 0x000A      // NTFS time stamps
  311.  
  312. const unsigned char* __fastcall FindTag(WORD tag, const unsigned char *p, unsigned &siz);
  313.  
  314. #define FS_FAT 0
  315. #define FS_HPFS 6
  316. #define FS_NTFS 11
  317. #define OS_NTFS 0x0B00
  318. #define FLAG_ENCRYPT_BIT 0x0001
  319. #define FLAG_EXTEND_BIT 0x0008
  320. #define FLAG_UTF8_BIT 0x0800
  321.  
  322. #ifndef MAX
  323. #  define MAX(a, b)   ((a) > (b) ? (a) : (b))
  324. #endif
  325. #ifndef MIN
  326. #  define MIN(a, b)  ((a) < (b) ? (a) : (b))
  327. #endif
  328.  
  329.  
  330. extern const ulg crc_table[];
  331.  
  332. ulg __fastcall crc32(ulg crc, const uch *buf, int len);
  333.  
  334. int __fastcall Close_Handle(HANDLE *h);
  335.  
  336. time_t          dos2unixtime(ulg dostime);
  337. ulg             dostime(int, int, int, int, int, int);
  338. ulg             unix2dostime(time_t *);
  339.  
  340. char * __fastcall zstrdupB(const char* from);
  341. TCHAR * __fastcall zstrdup(const TCHAR* from);
  342.  
  343. #endif
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.