-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathZipMstr.pas
2213 lines (1976 loc) · 67.4 KB
/
ZipMstr.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit ZipMstr;
// ZipMstr.pas - main component
(* ***************************************************************************
TZipMaster VCL originally by Chris Vleghert, Eric W. Engler.
Present Maintainers and Authors Roger Aelbrecht and Russell Peters.
Copyright (C) 1997-2002 Chris Vleghert and Eric W. Engler
Copyright (C) 1992-2008 Eric W. Engler
Copyright (C) 2009, 2010, 2011, 2012, 2013 Russell Peters and Roger Aelbrecht
Copyright (C) 2014, 2015, 2016, 2017 Russell Peters and Roger Aelbrecht
All rights reserved.
For the purposes of Copyright and this license "DelphiZip" is the current
authors, maintainers and developers of its code:
Russell Peters and Roger Aelbrecht.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* DelphiZip reserves the names "DelphiZip", "ZipMaster", "ZipBuilder",
"DelZip" and derivatives of those names for the use in or about this
code and neither those names nor the names of its authors or
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL DELPHIZIP, IT'S AUTHORS OR CONTRIBUTERS BE
LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
contact: problems AT delphizip DOT org
updates: http://www.delphizip.org
*************************************************************************** *)
// modified 2014-02-23
{$I '.\ZipVers.inc'}
{$I '.\ZMConfig192.inc'}
interface
uses
{$IFDEF VERDXE2up}
System.Classes, VCL.Forms, System.SysUtils, VCL.Graphics, VCL.Dialogs,
WinApi.Windows, VCL.Controls,
{$ELSE}
Classes, Forms, SysUtils, Graphics, Dialogs, Windows, Controls,
{$IFDEF VERPre6} ZMCompat, {$ENDIF}
{$ENDIF}
ZMHandler;
const
ZIPMASTERBUILD: string = '1.9.2.0023';
ZIPMASTERDATE: string = '8/04/2017';
ZIPMASTERPRIV: Integer = 1920023;
DELZIPVERSION = 192;
MIN_DLL_BUILD = 1920002;
const
ZMPWLEN = 80;
type
{$IFDEF UNICODE}
TZMWideString = string;
TZMRawBytes = RawByteString;
{$ELSE}
TZMWideString = WideString;
TZMRawBytes = AnsiString;
{$ENDIF}
type
TZMStates = (ZsDisabled, ZsIdle, ZsReentered, ZsBusy, ZsReentry);
// options when editing a zip
TZMAddOptsEnum = (AddDirNames, AddRecurseDirs, AddMove, AddFreshen, AddUpdate,
AddHiddenFiles, AddArchiveOnly, AddResetArchive, AddEncrypt, AddEmptyDirs,
AddVolume, AddFromDate, AddVersion, AddNTFS);
TZMAddOpts = set of TZMAddOptsEnum;
// the EncodeAs values (writing) -
// zeoUPATH - convert to Ansi but have UTF8 proper name in data
// zeoUTF - convert to UTF8
// zeoOEM - convert to OEM
// zeoNone - store 'as is' (Ansi on Windows)
// 'default' (zeoAuto) - [in order of preference]
// is Ansi - use zeoNone
// can be converted to Ansi - use zeoUPath (unless comment also extended)
// use zeoUTF8
// Encoded (reading)
// zeoUPATH- use UPATH if available
// zeoUTF - assume name is UTF8 - convert to Ansi/Unicode
// zeoOEM - assume name is OEM - convert to Ansi/Unicode
// zeoNone - assume name is Ansi - convert to Ansi/Unicode
// zeoAuto - unless flags/versions say otherwise, or it has UTF8 name in data,
// treat it as OEM (FAT) / Ansi (NTFS)
TZMEncodingOpts = (ZeoAuto, ZeoNone, ZeoOEM, ZeoUTF8, ZeoUPath);
// When changing this enum also change the pointer array in the function AddSuffix,
// and the initialisation of ZipMaster.
TZMAddStoreSuffixEnum = (AssGIF, AssPNG, AssZ, AssZIP, AssZOO, AssARC, AssLZH,
AssARJ, AssTAZ, AssTGZ, AssLHA, AssRAR, AssACE, AssCAB, AssGZ, AssGZIP,
AssJAR, AssEXE, AssEXT, AssJPG, AssJPEG, Ass7Zp, AssMP3, AssWMV, AssWMA,
AssDVR, AssAVI);
TZMAddStoreExts = set of TZMAddStoreSuffixEnum;
TZMSpanOptsEnum = (SpNoVolumeName, SpCompatName, SpWipeFiles, SpTryFormat,
SpAnyTime, SpExactName);
TZMSpanOpts = set of TZMSpanOptsEnum;
// options for when reading a zip file
TZMExtrOptsEnum = (ExtrDirNames, ExtrOverWrite, ExtrFreshen, ExtrUpdate,
ExtrTest, ExtrForceDirs, ExtrNTFS, ExtrSafe);
TZMExtrOpts = set of TZMExtrOptsEnum;
// options for when writing a zip file
TZMWriteOptsEnum = (ZwoDiskSpan, // write multipart
ZwoZipTime, // set zip time to latest entry time
ZwoForceDest, // force destination folder
ZwoSafe, // write to temporary before replacing existing zip
ZwoSkipDup, // do not write duplicate names
ZwoAutoDup, // rename duplicates via OnWriteDupName
ZwoAllowDup, // write duplicate names
ZwoExtDup); // rename by appending {xxxx} xxxx is encoded time
TZMWriteOpts = set of TZMWriteOptsEnum;
// other options
TZMMergeOpts = (ZmoConfirm, ZmoAlways, ZmoNewer, ZmoOlder, ZmoNever,
ZmoRename);
TZMOvrOpts = (OvrAlways, OvrNever, OvrConfirm);
TZMReplaceOpts = (RplConfirm, RplAlways, RplNewer, RplNever);
TZMDeleteOpts = (HtdFinal, HtdAllowUndo);
TZMRenameOpts = (HtrDefault, HtrOnce, HtrFull);
TZMSkipTypes = (StNoSkip, StOnFreshen, StNoOverwrite, StFileExists,
StBadPassword, StBadName, StCompressionUnknown, StUnknownZipHost,
StZipFileFormatWrong, StGeneralExtractError, StUser, StCannotDo, StNotFound,
StNoShare, StNoAccess, StNoOpen, StDupName, StReadError, StSizeChange,
StNothingToDo, StCRCError, StPathError, StWarning);
TZMSkipAborts = set of TZMSkipTypes;
type
TZMProblem = class
private
protected
function GetErrCode: Integer; virtual; abstract;
function GetSkipCode: TZMSkipTypes; virtual; abstract;
public
property ErrCode: Integer read GetErrCode;
property SkipCode: TZMSkipTypes read GetSkipCode;
end;
type
TZMZipDiskStatusEnum = (ZdsEmpty, ZdsHasFiles, ZdsPreviousDisk,
ZdsSameFileName, ZdsNotEnoughSpace);
TZMZipDiskStatus = set of TZMZipDiskStatusEnum;
TZMDiskAction = (ZdaYesToAll, ZdaOk, ZdaErase, ZdaReject, ZdaCancel);
TZMDeflates = (ZmStore, ZmDeflate);
PZMDeflates = ^TZMDeflates;
TZMZHeader = (ZzNormal, ZzCompat, ZzAuto);
type
TZMSFXOpt = (SoAskCmdLine,
// allow user to prevent execution of the command line
SoAskFiles, // allow user to prevent certain files from extraction
SoHideOverWriteBox, // do not allow user to choose the overwrite mode
SoAutoRun, // start extraction + evtl. command line automatically
// only if sfx filename starts with "!" or is "setup.exe"
SoNoSuccessMsg, // don't show success message after extraction
SoExpandVariables, // expand environment variables in path/cmd line...
SoInitiallyHideFiles, // dont show file listview on startup
SoForceHideFiles, // do not allow user to show files list
// (no effect if shfInitiallyShowFiles is set)
SoCheckAutoRunFileName, // can only autorun if !... or setup.exe
SoCanBeCancelled, // extraction can be cancelled
SoCreateEmptyDirs, // recreate empty directories
SoSuccessAlways
// always give success message even if soAutoRun or soNoSuccessMsg
);
// set of TSFXOption
TZMSFXOpts = set of TZMSFXOpt;
type
TZMProgressType = (NewFile, ProgressUpdate, EndOfItem, EndOfBatch,
TotalFiles2Process, TotalSize2Process, NewExtra, ExtraUpdate);
type
TZMProgressDetails = class(TObject)
protected
function GetBytesWritten: Int64; virtual; abstract;
function GetDelta: Int64; virtual; abstract;
function GetItemName: string; virtual; abstract;
function GetItemNumber: Integer; virtual; abstract;
function GetItemPerCent: Integer;
function GetItemPosition: Int64; virtual; abstract;
function GetItemSize: Int64; virtual; abstract;
function GetOrder: TZMProgressType; virtual; abstract;
function GetStop: Boolean; virtual; abstract;
function GetTotalCount: Int64; virtual; abstract;
function GetTotalPerCent: Integer;
function GetTotalPosition: Int64; virtual; abstract;
function GetTotalSize: Int64; virtual; abstract;
procedure SetStop(const Value: Boolean); virtual; abstract;
public
property BytesWritten: Int64 read GetBytesWritten;
property Delta: Int64 read GetDelta;
property ItemName: string read GetItemName;
property ItemNumber: Integer read GetItemNumber;
property ItemPerCent: Integer read GetItemPerCent;
property ItemPosition: Int64 read GetItemPosition;
property ItemSize: Int64 read GetItemSize;
property Order: TZMProgressType read GetOrder;
property Stop: Boolean read GetStop write SetStop;
property TotalCount: Int64 read GetTotalCount;
property TotalPerCent: Integer read GetTotalPerCent;
property TotalPosition: Int64 read GetTotalPosition;
property TotalSize: Int64 read GetTotalSize;
end;
// ZipDirEntry status bit constants
const
ZsbDirty = $1;
ZsbSelected = $2;
ZsbSkipped = $4;
ZsbHail = $8;
// zsbIgnore = $8;
ZsbDirOnly = $10;
ZsbInvalid = $20;
ZsbError = $40; // processing error
ZsbDiscard = $80;
const
DefNoSkips = [StDupName, StReadError];
type
// abstract class representing a zip central record
TZMDirEntry = class
private
function GetExtraData(Tag: Word): TZMRawBytes;
function GetIsDirOnly: Boolean;
protected
function GetCompressedSize: Int64; virtual; abstract;
function GetCompressionMethod: Word; virtual; abstract;
function GetCRC32: Cardinal; virtual; abstract;
function GetDateStamp: TDateTime;
function GetDateTime: Cardinal; virtual; abstract;
function GetEncoded: TZMEncodingOpts; virtual; abstract;
function GetEncrypted: Boolean; virtual; abstract;
function GetExtFileAttrib: Longword; virtual; abstract;
function GetExtraField: TZMRawBytes; virtual; abstract;
function GetExtraFieldLength: Word; virtual; abstract;
function GetFileComment: string; virtual; abstract;
function GetFileCommentLen: Word; virtual; abstract;
function GetFileName: string; virtual; abstract;
function GetFileNameLength: Word; virtual; abstract;
function GetFlag: Word; virtual; abstract;
function GetHeaderName: TZMRawBytes; virtual; abstract;
function GetIntFileAttrib: Word; virtual; abstract;
function GetMaster: TComponent; virtual; abstract;
function GetRelOffLocalHdr: Int64; virtual; abstract;
function GetStartOnDisk: Word; virtual; abstract;
function GetStatusBits: Cardinal; virtual; abstract;
function GetUncompressedSize: Int64; virtual; abstract;
function GetVersionMadeBy: Word; virtual; abstract;
function GetVersionNeeded: Word; virtual; abstract;
function XData(const X: TZMRawBytes; Tag: Word;
var Idx, Size: Integer): Boolean;
property Master: TComponent read GetMaster;
public
function UnzipToFile(const DestName: string): Integer;
function UnzipToStream(DestStream: TStream): Integer;
property CompressedSize: Int64 read GetCompressedSize;
property CompressionMethod: Word read GetCompressionMethod;
property CRC32: Cardinal read GetCRC32;
property DateStamp: TDateTime read GetDateStamp;
property DateTime: Cardinal read GetDateTime;
property Encoded: TZMEncodingOpts read GetEncoded;
property Encrypted: Boolean read GetEncrypted;
property ExtFileAttrib: Longword read GetExtFileAttrib;
property ExtraData[Tag: Word]: TZMRawBytes read GetExtraData;
property ExtraField: TZMRawBytes read GetExtraField;
property ExtraFieldLength: Word read GetExtraFieldLength;
property FileComment: string read GetFileComment;
property FileCommentLen: Word read GetFileCommentLen;
property FileName: string read GetFileName;
property FileNameLength: Word read GetFileNameLength;
property Flag: Word read GetFlag;
property HeaderName: TZMRawBytes read GetHeaderName;
property IntFileAttrib: Word read GetIntFileAttrib;
property IsDirOnly: Boolean read GetIsDirOnly;
property RelOffLocalHdr: Int64 read GetRelOffLocalHdr;
property StartOnDisk: Word read GetStartOnDisk;
property StatusBits: Cardinal read GetStatusBits;
property UncompressedSize: Int64 read GetUncompressedSize;
property VersionMadeBy: Word read GetVersionMadeBy;
property VersionNeeded: Word read GetVersionNeeded;
end;
TZMDirRec = class(TZMDirEntry)
public
function ChangeAttrs(NAttr: Cardinal): Integer; virtual; abstract;
function ChangeComment(const Ncomment: string): Integer; virtual; abstract;
function ChangeData(Ndata: TZMRawBytes): Integer; virtual; abstract;
function ChangeDate(Ndosdate: Cardinal): Integer; virtual; abstract;
function ChangeEncoding: Integer; virtual; abstract;
function ChangeName(const Nname: string; NoCheck: Boolean = False): Integer;
virtual; abstract;
function ChangeStamp(Ndate: TDateTime): Integer;
end;
type
TZMForEachFunction = function(Rec: TZMDirEntry; var Data): Integer;
TZMChangeFunction = function(Rec: TZMDirRec; var Data): Integer;
type
TZMRenameRec = record
Source: string;
Dest: string;
Comment: string;
DateTime: Integer;
end;
PZMRenameRec = ^TZMRenameRec;
type
TZMConflictEntry = class(TZMDirEntry)
protected
function GetOriginalName: string; virtual; abstract;
function GetZipName: string; virtual; abstract;
public
property OriginalName: string read GetOriginalName;
property ZipName: string read GetZipName;
end;
type
TZMResolutions = (ZmrRename, ZmrExisting, ZmrConflicting);
TZMDupResolutions = (ZdrAuto, ZdrSkip, ZdrRename, ZdrBoth, ZdrAbort,
ZdrDefer);
type
TZMCheckTerminateEvent = procedure(Sender: TObject; var Abort: Boolean)
of object;
TZMCRC32ErrorEvent = procedure(Sender: TObject; const ForFile: string;
FoundCRC, ExpectedCRC: Longword; var DoExtract: Boolean) of object;
TZMExtractOverwriteEvent = procedure(Sender: TObject; const ForFile: string;
IsOlder: Boolean; var DoOverwrite: Boolean; DirIndex: Integer) of object;
TZMMergeZippedConflictEvent = procedure(Sender: TObject;
Existing, Conflicting: TZMConflictEntry; var Resolve: TZMResolutions)
of object;
TZMSkippedEvent = procedure(Sender: TObject; const ForFile: string;
SkipType: TZMSkipTypes; var ExtError: Integer) of object;
TZMFileCommentEvent = procedure(Sender: TObject; const ForFile: string;
var FileComment: string; var IsChanged: Boolean) of object;
TZMFileExtraEvent = procedure(Sender: TObject; const ForFile: string;
var Data: TZMRawBytes; var IsChanged: Boolean) of object;
TZMGetNextDiskEvent = procedure(Sender: TObject;
DiskSeqNo, DiskTotal: Integer; Drive: string; var AbortAction: Boolean)
of object;
TZMLoadStrEvent = procedure(Ident: Integer; var DefStr: string) of object;
TZMMessageEvent = procedure(Sender: TObject; ErrCode: Integer;
const ErrMsg: string) of object;
TZMNewNameEvent = procedure(Sender: TObject; SeqNo: Integer) of object;
TZMPasswordErrorEvent = procedure(Sender: TObject; IsZipAction: Boolean;
var NewPassword: string; const ForFile: string; var RepeatCount: Longword;
var Action: TMsgDlgBtn) of object;
TZMProgressEvent = procedure(Sender: TObject; Details: TZMProgressDetails)
of object;
TZMSetAddNameEvent = procedure(Sender: TObject; var FileName: string;
const ExtName: string; var IsChanged: Boolean) of object;
TZMSetExtNameEvent = procedure(Sender: TObject; var FileName: string;
const BaseDir: string; var IsChanged: Boolean) of object;
TZMStatusDiskEvent = procedure(Sender: TObject; PreviousDisk: Integer;
PreviousFile: string; Status: TZMZipDiskStatus; var Action: TZMDiskAction)
of object;
TZMTickEvent = procedure(Sender: TObject) of object;
TZMDialogEvent = procedure(Sender: TObject; const Title: string;
var Msg: string; var Result: Integer; Btns: TMsgDlgButtons) of object;
TZMSetCompLevel = procedure(Sender: TObject; const ForFile: string;
var Level: Integer; var IsChanged: Boolean) of object;
TZMStateChange = procedure(Sender: TObject; State: TZMStates;
var NoCursor: Boolean) of object;
TZMWriteDupNameEvent = procedure(Sender: TObject;
const Existing, Conflicting: TZMConflictEntry; var NewName: string;
var Resolve: TZMDupResolutions) of object;
// default file extensions that are best 'stored'
const
ZMDefAddStoreSuffixes = [AssGIF .. AssJAR, AssJPG .. Ass7Zp,
AssMP3 .. AssAVI];
type
{$IFDEF VERD2005up}
TCustomZipMaster = class;
TZipMasterEnumerator = class
private
FIndex: Integer;
FOwner: TCustomZipMaster;
public
constructor Create(AMaster: TCustomZipMaster);
function GetCurrent: TZMDirEntry;
function MoveNext: Boolean;
property Current: TZMDirEntry read GetCurrent;
end;
{$ENDIF}
// the main component
TCustomZipMaster = class(TComponent)
private
{ Private versions of property variables }
FDLLDirectory: string;
FFSpecArgs: TStrings;
FFSpecArgsExcl: TStrings;
FHandle: HWND;
FOnCheckTerminate: TZMCheckTerminateEvent;
FOnCRC32Error: TZMCRC32ErrorEvent;
FOnDirUpdate: TNotifyEvent;
FOnExtractOverwrite: TZMExtractOverwriteEvent;
FOnFileComment: TZMFileCommentEvent;
FOnFileExtra: TZMFileExtraEvent;
FOnGetNextDisk: TZMGetNextDiskEvent;
FOnLoadStr: TZMLoadStrEvent;
FOnMergeZippedConflict: TZMMergeZippedConflictEvent;
FOnMessage: TZMMessageEvent;
FOnNewName: TZMNewNameEvent;
FOnPasswordError: TZMPasswordErrorEvent;
FOnProgress: TZMProgressEvent;
FOnSetAddName: TZMSetAddNameEvent;
FOnSetCompLevel: TZMSetCompLevel;
FOnSetExtName: TZMSetExtNameEvent;
FOnSkipped: TZMSkippedEvent;
FOnStateChange: TZMStateChange;
FOnStatusDisk: TZMStatusDiskEvent;
FOnTick: TZMTickEvent;
FOnWriteDupName: TZMWriteDupNameEvent;
FOnZipDialog: TZMDialogEvent;
FTrace: Boolean;
FVerbose: Boolean;
procedure AuxWasChanged;
function CopyBuffer(InFile, OutFile: Integer): Integer;
function GetActive: Boolean;
function GetAddCompLevel: Integer;
function GetAddFrom: TDateTime;
function GetAddOptions: TZMAddOpts;
function GetAddStoreSuffixes: TZMAddStoreExts;
function GetBlockedCnt: Integer;
function GetBuild: Integer;
// { Property get/set functions }
function GetCancel: Boolean;
function GetConfirmErase: Boolean;
function GetCount: Integer;
function GetDirEntry(Idx: Integer): TZMDirEntry;
function GetDirOnlyCnt: Integer;
function GetDLL_Build: Integer;
function GetDLL_Load: Boolean;
function GetDLL_Path: string;
function GetDLL_Version: string;
function GetDLL_Version1(ForceLoad: Boolean): string;
function GetEncodeAs: TZMEncodingOpts;
function GetEncoding: TZMEncodingOpts;
function GetEncoding_CP: Cardinal;
function GetErrCode: Integer;
function GetErrMessage: string;
function GetExtAddStoreSuffixes: string;
function GetExtErrCode: Cardinal;
function GetExtrBaseDir: string;
function GetExtrOptions: TZMExtrOpts;
function GetExtStream: TStream;
function GetHowToDelete: TZMDeleteOpts;
function GetIsSpanned: Boolean;
function GetKeepFreeOnAllDisks: Cardinal;
function GetKeepFreeOnDisk1: Cardinal;
function GetLanguage: string;
function GetMaxVolumeSize: Int64;
function GetMaxVolumeSizeKb: Integer;
function GetMinFreeVolumeSize: Cardinal;
function GetNoReadAux: Boolean;
function GetNoSkipping: TZMSkipAborts;
function GetNotMainThread: Boolean;
function Get_Password: string;
function GetPasswordReqCount: Longword;
function GetProgressDetail: TZMProgressDetails;
function GetRootDir: string;
function GetSFXCaption: string;
function GetSFXCommandLine: string;
function GetSFXDefaultDir: string;
function GetSFXIcon: TIcon;
function GetSFXMessage: string;
function GetSFXOffset: Integer;
function GetSFXOptions: TZMSFXOpts;
function GetSFXOverwriteMode: TZMOvrOpts;
function GetSFXPath: string;
function GetSFXRegFailPath: string;
function GetSpanOptions: TZMSpanOpts;
function Getstate: TZMStates;
function GetSuccessCnt: Integer;
function GetTempDir: string;
function GetTotalSizeToProcess: Int64;
function GetUnattended: Boolean;
function GetUseDirOnlyEntries: Boolean;
{$IFNDEF UNICODE}
function GetUseUTF8: Boolean;
{$ENDIF}
function GetVersion: string;
function GetWriteOptions: TZMWriteOpts;
function GetZipComment: AnsiString;
function GetZipEOC: Int64;
function GetZipFileName: string;
function GetZipFileSize: Int64;
function GetZipSOC: Int64;
function GetZipStream: TMemoryStream;
function IsActive: Boolean;
procedure SetActive(Value: Boolean);
procedure SetAddCompLevel(const Value: Integer);
procedure SetAddFrom(const Value: TDateTime);
procedure SetAddOptions(const Value: TZMAddOpts);
procedure SetAddStoreSuffixes(const Value: TZMAddStoreExts);
procedure SetCancel(Value: Boolean);
procedure SetConfirmErase(const Value: Boolean);
procedure SetDLLDirectory(const Value: string);
procedure SetDLL_Load(const Value: Boolean);
procedure SetEncodeAs(const Value: TZMEncodingOpts);
procedure SetEncoding(const Value: TZMEncodingOpts);
procedure SetEncoding_CP(Value: Cardinal);
procedure SetErrCode(Value: Integer);
procedure SetExtAddStoreSuffixes(const Value: string);
procedure SetExtErrCode(const Value: Cardinal);
procedure SetExtrBaseDir(const Value: string);
procedure SetExtrOptions(const Value: TZMExtrOpts);
procedure SetExtStream(const Value: TStream);
procedure SetFSpecArgs(const Value: TStrings);
procedure SetFSpecArgsExcl(const Value: TStrings);
procedure SetHowToDelete(const Value: TZMDeleteOpts);
procedure SetKeepFreeOnAllDisks(const Value: Cardinal);
procedure SetKeepFreeOnDisk1(const Value: Cardinal);
procedure SetLanguage(const Value: string);
procedure SetMaxVolumeSize(const Value: Int64);
procedure SetMaxVolumeSizeKb(const Value: Integer);
procedure SetMinFreeVolumeSize(const Value: Cardinal);
procedure SetNoReadAux(const Value: Boolean);
procedure SetNoSkipping(const Value: TZMSkipAborts);
procedure SetNotMainThread(const Value: Boolean);
procedure Set_Password(const Value: string);
procedure SetPasswordReqCount(Value: Longword);
procedure SetRootDir(const Value: string);
procedure SetSFXCaption(const Value: string);
procedure SetSFXCommandLine(const Value: string);
procedure SetSFXDefaultDir(const Value: string);
procedure SetSFXIcon(Value: TIcon);
procedure SetSFXMessage(const Value: string);
procedure SetSFXOptions(const Value: TZMSFXOpts);
procedure SetSFXOverwriteMode(const Value: TZMOvrOpts);
procedure SetSFXPath(const Value: string);
procedure SetSFXRegFailPath(const Value: string);
procedure SetSpanOptions(const Value: TZMSpanOpts);
procedure SetTempDir(const Value: string);
procedure SetTrace(const Value: Boolean);
procedure SetUnattended(const Value: Boolean);
procedure SetUseDirOnlyEntries(const Value: Boolean);
{$IFNDEF UNICODE}
procedure SetUseUTF8(const Value: Boolean);
{$ENDIF}
procedure SetVerbose(const Value: Boolean);
procedure SetVersion(const Value: string);
procedure SetWriteOptions(const Value: TZMWriteOpts);
procedure SetZipComment(const Value: AnsiString);
procedure SetZipFileName(const Value: string);
protected
FBody: TZMRoot;
procedure Loaded; override;
function ReEntry: Boolean;
public
constructor Create(AOwner: TComponent); override;
procedure AbortDLL;
function Add: Integer;
function AddStreamToFile(const FileName: string;
FileDate, FileAttr: Dword): Integer;
function AddStreamToStream(InStream: TMemoryStream): TMemoryStream;
// procedure AfterConstruction; override;
function AppendSlash(const SDir: string): string;
procedure BeforeDestruction; override;
function ChangeFileDetails(Func: TZMChangeFunction; var Data): Integer;
procedure Clear;
function ConvertToSFX: Integer;
function ConvertToSpanSFX(const OutFile: string): Integer;
function ConvertToZIP: Integer;
function Copy_File(const InFileName, OutFileName: string): Integer;
function Deflate(OutStream, InStream: TStream; Length: Int64;
var Method: TZMDeflates; var CRC: Cardinal): Integer;
function Delete: Integer;
function EraseFile(const FName: string; How: TZMDeleteOpts): Integer;
function Extract: Integer;
function ExtractFileToStream(const FileName: string): TMemoryStream;
function ExtractStreamToStream(InStream: TMemoryStream; OutSize: Longword;
HeaderType: TZMZHeader = ZzNormal): TMemoryStream;
function Find(const Fspec: string; var Idx: Integer): TZMDirEntry;
function ForEach(Func: TZMForEachFunction; var Data): Integer;
function FullVersionString: string;
function GetAddPassword: string; overload;
function GetAddPassword(var Response: TMsgDlgBtn): string; overload;
{$IFDEF VERD2005up}
function GetEnumerator: TZipMasterEnumerator;
{$ENDIF}
function GetExtrPassword: string; overload;
function GetExtrPassword(var Response: TMsgDlgBtn): string; overload;
function GetPassword(const DialogCaption, MsgTxt: string;
Pwb: TMsgDlgButtons; var ResultStr: string): TMsgDlgBtn;
function IndexOf(const FName: string): Integer;
function IsZipSFX(const SFXExeName: string): Integer;
function List: Integer;
function MakeTempFileName(const Prefix, Extension: string): string;
function MergeZippedFiles(Opts: TZMMergeOpts): Integer;
function QueryZip(const FName: TFileName): Integer;
function ReadSpan(const InFileName: string;
var OutFilePath: string): Integer;
function Rename(RenameList: TList; DateTime: Integer;
How: TZMRenameOpts = HtrDefault): Integer;
procedure ShowExceptionError(const ZMExcept: Exception);
procedure ShowZipFmtMessage(Id: Integer; const Args: array of const;
Display: Boolean);
procedure ShowZipMessage(Ident: Integer; const UserStr: string);
function Undeflate(OutStream, InStream: TStream; Length: Int64;
var Method: TZMDeflates; var CRC: Cardinal): Integer;
function UnzipToFile(const Entry: TZMDirEntry; const DestName: string): Integer;
function UnzipToStream(const Entry: TZMDirEntry; DestStream: TStream): Integer;
function WriteSpan(const InFileName, OutFileName: string): Integer;
function ZipLoadStr(Id: Integer): string;
property Active: Boolean read GetActive write SetActive;
property AddCompLevel: Integer read GetAddCompLevel write SetAddCompLevel;
property AddFrom: TDateTime read GetAddFrom write SetAddFrom;
property AddOptions: TZMAddOpts read GetAddOptions write SetAddOptions;
property AddStoreSuffixes: TZMAddStoreExts read GetAddStoreSuffixes
write SetAddStoreSuffixes;
property BlockedCnt: Integer read GetBlockedCnt;
property Build: Integer read GetBuild;
property Cancel: Boolean read GetCancel write SetCancel;
property ConfirmErase: Boolean read GetConfirmErase write SetConfirmErase
default True;
property Count: Integer read GetCount;
property DirEntry[Idx: Integer]: TZMDirEntry read GetDirEntry; default;
property DirOnlyCnt: Integer read GetDirOnlyCnt;
property DLLDirectory: string read FDLLDirectory write SetDLLDirectory;
property DLL_Build: Integer read GetDLL_Build;
property DLL_Load: Boolean read GetDLL_Load write SetDLL_Load;
property DLL_Path: string read GetDLL_Path;
property DLL_Version: string read GetDLL_Version;
property EncodeAs: TZMEncodingOpts read GetEncodeAs write SetEncodeAs;
// 1 Filename and comment character encoding
property Encoding: TZMEncodingOpts read GetEncoding write SetEncoding;
// 1 codepage to use to decode filename
property Encoding_CP: Cardinal read GetEncoding_CP write SetEncoding_CP;
property ErrCode: Integer read GetErrCode write SetErrCode;
property ErrMessage: string read GetErrMessage;
property ExtAddStoreSuffixes: string read GetExtAddStoreSuffixes
write SetExtAddStoreSuffixes;
property ExtErrCode: Cardinal read GetExtErrCode write SetExtErrCode;
property ExtrBaseDir: string read GetExtrBaseDir write SetExtrBaseDir;
property ExtrOptions: TZMExtrOpts read GetExtrOptions write SetExtrOptions;
property ExtStream: TStream read GetExtStream write SetExtStream;
property FSpecArgs: TStrings read FFSpecArgs write SetFSpecArgs;
property FSpecArgsExcl: TStrings read FFSpecArgsExcl write SetFSpecArgsExcl;
property Handle: HWND read FHandle;
property HowToDelete: TZMDeleteOpts read GetHowToDelete write SetHowToDelete;
property IsSpanned: Boolean read GetIsSpanned;
property KeepFreeOnAllDisks: Cardinal read GetKeepFreeOnAllDisks
write SetKeepFreeOnAllDisks;
property KeepFreeOnDisk1: Cardinal read GetKeepFreeOnDisk1
write SetKeepFreeOnDisk1;
property Language: string read GetLanguage write SetLanguage;
property MaxVolumeSize: Int64 read GetMaxVolumeSize write SetMaxVolumeSize;
property MaxVolumeSizeKb: Integer read GetMaxVolumeSizeKb
write SetMaxVolumeSizeKb;
property MinFreeVolumeSize: Cardinal read GetMinFreeVolumeSize
write SetMinFreeVolumeSize;
property NoReadAux: Boolean read GetNoReadAux write SetNoReadAux;
property NoSkipping: TZMSkipAborts read GetNoSkipping write SetNoSkipping
default DefNoSkips;
property NotMainThread: Boolean read GetNotMainThread
write SetNotMainThread;
property Password: string read Get_Password write Set_Password;
property PasswordReqCount: Longword read GetPasswordReqCount
write SetPasswordReqCount;
property ProgressDetail: TZMProgressDetails read GetProgressDetail;
property RootDir: string read GetRootDir write SetRootDir;
property SFXCaption: string read GetSFXCaption write SetSFXCaption;
property SFXCommandLine: string read GetSFXCommandLine
write SetSFXCommandLine;
property SFXDefaultDir: string read GetSFXDefaultDir write SetSFXDefaultDir;
property SFXIcon: TIcon read GetSFXIcon write SetSFXIcon;
property SFXMessage: string read GetSFXMessage write SetSFXMessage;
property SFXOffset: Integer read GetSFXOffset;
property SFXOptions: TZMSFXOpts read GetSFXOptions write SetSFXOptions;
property SFXOverwriteMode: TZMOvrOpts read GetSFXOverwriteMode
write SetSFXOverwriteMode default OvrConfirm;
property SFXPath: string read GetSFXPath write SetSFXPath;
property SFXRegFailPath: string read GetSFXRegFailPath
write SetSFXRegFailPath;
property SpanOptions: TZMSpanOpts read GetSpanOptions write SetSpanOptions;
property State: TZMStates read Getstate;
property SuccessCnt: Integer read GetSuccessCnt;
property TempDir: string read GetTempDir write SetTempDir;
property TotalSizeToProcess: Int64 read GetTotalSizeToProcess;
property Trace: Boolean read FTrace write SetTrace;
property Unattended: Boolean read GetUnattended write SetUnattended;
property UseDirOnlyEntries: Boolean read GetUseDirOnlyEntries
write SetUseDirOnlyEntries;// default False;
{$IFNDEF UNICODE}
property UseUTF8: Boolean read GetUseUTF8 write SetUseUTF8;
{$ENDIF}
property Verbose: Boolean read FVerbose write SetVerbose;
property Version: string read GetVersion write SetVersion;
property WriteOptions: TZMWriteOpts read GetWriteOptions
write SetWriteOptions;
property ZipComment: AnsiString read GetZipComment write SetZipComment;
property ZipEOC: Int64 read GetZipEOC;
property ZipFileName: string read GetZipFileName write SetZipFileName;
property ZipFileSize: Int64 read GetZipFileSize;
property ZipSOC: Int64 read GetZipSOC;
property ZipStream: TMemoryStream read GetZipStream;
{ Events }
property OnCheckTerminate: TZMCheckTerminateEvent read FOnCheckTerminate
write FOnCheckTerminate;
property OnCRC32Error: TZMCRC32ErrorEvent read FOnCRC32Error
write FOnCRC32Error;
property OnDirUpdate: TNotifyEvent read FOnDirUpdate write FOnDirUpdate;
property OnExtractOverwrite: TZMExtractOverwriteEvent
read FOnExtractOverwrite write FOnExtractOverwrite;
property OnFileComment: TZMFileCommentEvent read FOnFileComment
write FOnFileComment;
property OnFileExtra: TZMFileExtraEvent read FOnFileExtra
write FOnFileExtra;
property OnGetNextDisk: TZMGetNextDiskEvent read FOnGetNextDisk
write FOnGetNextDisk;
property OnLoadStr: TZMLoadStrEvent read FOnLoadStr write FOnLoadStr;
property OnMergeZippedConflict: TZMMergeZippedConflictEvent
read FOnMergeZippedConflict write FOnMergeZippedConflict;
property OnMessage: TZMMessageEvent read FOnMessage write FOnMessage;
property OnNewName: TZMNewNameEvent read FOnNewName write FOnNewName;
property OnPasswordError: TZMPasswordErrorEvent read FOnPasswordError
write FOnPasswordError;
property OnProgress: TZMProgressEvent read FOnProgress write FOnProgress;
property OnSetAddName: TZMSetAddNameEvent read FOnSetAddName
write FOnSetAddName;
property OnSetCompLevel: TZMSetCompLevel read FOnSetCompLevel
write FOnSetCompLevel;
property OnSetExtName: TZMSetExtNameEvent read FOnSetExtName
write FOnSetExtName;
property OnSkipped: TZMSkippedEvent read FOnSkipped write FOnSkipped;
property OnStateChange: TZMStateChange read FOnStateChange
write FOnStateChange;
property OnStatusDisk: TZMStatusDiskEvent read FOnStatusDisk
write FOnStatusDisk;
property OnTick: TZMTickEvent read FOnTick write FOnTick;
property OnWriteDupName: TZMWriteDupNameEvent read FOnWriteDupName
write FOnWriteDupName;
property OnZipDialog: TZMDialogEvent read FOnZipDialog write FOnZipDialog;
end;
type
TZipMaster = class(TCustomZipMaster)
published
property Active default True;
property AddCompLevel default 9;
property AddFrom;
property AddOptions default [];
property AddStoreSuffixes default ZMDefAddStoreSuffixes;
property ConfirmErase default True;
property DLLDirectory;
property DLL_Load default False;
property EncodeAs default ZeoAuto;
// 1 Filename and comment character encoding
property Encoding default ZeoAuto;
property Encoding_CP default 0;
property ExtAddStoreSuffixes;
property ExtrBaseDir;
property ExtrOptions default [];
property FSpecArgs;
property FSpecArgsExcl;
property HowToDelete default HtdAllowUndo;
property KeepFreeOnAllDisks default 0;
property KeepFreeOnDisk1 default 0;
property Language;
property MaxVolumeSize default 0;
property MaxVolumeSizeKb default 0;
property MinFreeVolumeSize default 65536;
property NoReadAux default False;
property NoSkipping default DefNoSkips;
{ Events }
property OnCheckTerminate;
property OnCRC32Error;
property OnDirUpdate;
property OnExtractOverwrite;
property OnFileComment;
property OnFileExtra;
property OnGetNextDisk;
property OnLoadStr;
property OnMergeZippedConflict;
property OnMessage;
property OnNewName;
property OnPasswordError;
property OnProgress;
property OnSetAddName;
property OnSetCompLevel;
property OnSetExtName;
property OnSkipped;
property OnStatusDisk;
property OnTick;
property OnWriteDupName;
property OnZipDialog;
property Password;
property PasswordReqCount default 1;
// SFX
property RootDir;
property SFXCaption;
property SFXCommandLine;
property SFXDefaultDir;
property SFXIcon;
property SFXMessage;
property SFXOptions default [];
property SFXOverwriteMode default OvrAlways;
property SFXPath;
property SFXRegFailPath;
property SpanOptions default [];
property TempDir;
property Trace default False;
property Unattended default False;
property UseDirOnlyEntries default False;
{$IFNDEF UNICODE}
property UseUTF8 default False;
{$ENDIF}
property Verbose default False;
property Version;
property WriteOptions default [];
property ZipComment;
property ZipFileName;
end;
implementation
uses
{$IFDEF VERDXE2up}
WinApi.Messages,
{$ELSE}
Messages,
{$ENDIF}
ZMUtils, ZMBody, ZMMsg, ZMCtx, ZMOprMsgStr, ZMWinFuncs, ZMMatch,
ZMDllLoad, ZMLister, ZMOprDll, ZMCommand, ZMCore, ZMOprUnzip,
ZMOprDeflate, ZMOprDel, ZMOprCore, ZMOprMod, ZMOprMerge, ZMOprFile;
const
__UNIT__ = 1;
function ZM_Error(Line, Error: Integer): Integer;
begin
Result := -((__UNIT__ shl ZERR_UNIT_SHIFTS) + (Line shl ZERR_LINE_SHIFTS) or
AbsErr(Error));
end;
{ TZMProgressDetails }
function TZMProgressDetails.GetItemPerCent: Integer;
begin
if (ItemSize > 0) and (ItemPosition > 0) then
Result := (100 * ItemPosition) div ItemSize
else
Result := 0;
end;
function TZMProgressDetails.GetTotalPerCent: Integer;
begin
if (TotalSize > 0) and (TotalPosition > 0) then
Result := (100 * TotalPosition) div TotalSize
else
Result := 0;
end;
{ TZMDirEntry }
function TZMDirEntry.GetDateStamp: TDateTime;
begin
Result := FileDateToLocalDateTime(GetDateTime);
end;
// return first data for Tag
function TZMDirEntry.GetExtraData(Tag: Word): TZMRawBytes;
var
I: Integer;
Sz: Integer;
begin
Result := ExtraField;
if (ExtraFieldLength >= 4) and XData(Result, Word(Tag), I, Sz) then
Result := Copy(Result, 5, Sz - 4)
else
Result := '';
end;
function TZMDirEntry.GetIsDirOnly: Boolean;
begin
Result := (StatusBits and ZsbDirOnly) <> 0;
end;
function TZMDirEntry.UnzipToFile(const DestName: string): Integer;
begin
Result := (Master as TCustomZipMaster).UnzipToFile(Self, DestName);
end;
function TZMDirEntry.UnzipToStream(DestStream: TStream): Integer;
begin
Result := (Master as TCustomZipMaster).UnzipToStream(Self, DestStream);
end;
function TZMDirEntry.XData(const X: TZMRawBytes; Tag: Word;
var Idx, Size: Integer): Boolean;
var
I: Integer;
L: Integer;
Wsz: Word;
Wtg: Word;
begin
Result := False;
Idx := 0;
Size := 0;
I := 1;
L := Length(X);
while I <= L - 4 do
begin
Wtg := PWord(@X[I])^;
Wsz := PWord(@X[I + 2])^;
if Wtg = Tag then
begin
Result := (I + Wsz + 4) <= L + 1;
if Result then
begin
Idx := I;
Size := Wsz + 4;
end;
Break;
end;
I := I + Wsz + 4;
end;
end;
{ TZMDirRec }
function TZMDirRec.ChangeStamp(Ndate: TDateTime): Integer;
begin
Result := ChangeDate(DateTimeToFileDate(Ndate));
end;
{$IFDEF VERD2005up}
{ TZipMasterEnumerator }
constructor TZipMasterEnumerator.Create(AMaster: TCustomZipMaster);
begin
inherited Create;
FIndex := -1;
FOwner := AMaster;
end;
function TZipMasterEnumerator.GetCurrent: TZMDirEntry;
begin
Result := FOwner[FIndex];
end;
function TCustomZipMaster.GetEnumerator: TZipMasterEnumerator;
begin
Result := TZipMasterEnumerator.Create(Self);
end;
function TZipMasterEnumerator.MoveNext: Boolean;
begin
Result := FIndex < (FOwner.Count - 1);
if Result then
Inc(FIndex);
end;
{$ENDIF}
constructor TCustomZipMaster.Create(AOwner: TComponent);
begin
inherited;
FBody := TZMCommand.Create(Self);
FFSpecArgs := TZMStringList.Create;
FFSpecArgsExcl := TZMStringList.Create;
FHandle := Application.Handle;
end;
procedure TCustomZipMaster.AbortDLL;