| 1 |
(* ***** BEGIN LICENSE BLOCK ***** |
| 2 |
* Version: MPL 1.1 |
| 3 |
* |
| 4 |
* The contents of this file are subject to the Mozilla Public License Version |
| 5 |
* 1.1 (the "License"); you may not use this file except in compliance with |
| 6 |
* the License. You may obtain a copy of the License at |
| 7 |
* http://www.mozilla.org/MPL/ |
| 8 |
* |
| 9 |
* Software distributed under the License is distributed on an "AS IS" basis, |
| 10 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 11 |
* for the specific language governing rights and limitations under the |
| 12 |
* License. |
| 13 |
* |
| 14 |
* The Original Code is TurboPower Abbrevia |
| 15 |
* |
| 16 |
* The Initial Developer of the Original Code is |
| 17 |
* TurboPower Software |
| 18 |
* |
| 19 |
* Portions created by the Initial Developer are Copyright (C) 1997-2002 |
| 20 |
* the Initial Developer. All Rights Reserved. |
| 21 |
* |
| 22 |
* Contributor(s): |
| 23 |
* |
| 24 |
* ***** END LICENSE BLOCK ***** *) |
| 25 |
|
| 26 |
{*********************************************************} |
| 27 |
{* ABBREVIA: AbZipKit.pas *} |
| 28 |
{*********************************************************} |
| 29 |
{* ABBREVIA: TABZipKit component *} |
| 30 |
{*********************************************************} |
| 31 |
|
| 32 |
unit AbZipKit; |
| 33 |
|
| 34 |
{$I AbDefine.inc} |
| 35 |
|
| 36 |
interface |
| 37 |
|
| 38 |
uses |
| 39 |
Classes, AbZipper, AbArcTyp, AbZipTyp; |
| 40 |
|
| 41 |
type |
| 42 |
TAbCustomZipKit = class(TAbCustomZipper) |
| 43 |
protected {private} |
| 44 |
FExtractOptions : TAbExtractOptions; |
| 45 |
FOnConfirmOverwrite : TAbConfirmOverwriteEvent; |
| 46 |
FOnNeedPassword : TAbNeedPasswordEvent; |
| 47 |
FPasswordRetries : Byte; |
| 48 |
|
| 49 |
protected {methods} |
| 50 |
procedure DoConfirmOverwrite(var Name : string; var Confirm : Boolean); |
| 51 |
virtual; |
| 52 |
procedure DoNeedPassword(Sender : TObject; var NewPassword : AnsiString); |
| 53 |
virtual; |
| 54 |
procedure InitArchive; |
| 55 |
override; |
| 56 |
procedure SetExtractOptions(Value : TAbExtractOptions); |
| 57 |
procedure SetPasswordRetries(Value : Byte); |
| 58 |
procedure UnzipProc(Sender : TObject; Item : TAbArchiveItem; |
| 59 |
const NewName : string ); |
| 60 |
procedure UnzipToStreamProc(Sender : TObject; Item : TAbArchiveItem; |
| 61 |
OutStream : TStream); |
| 62 |
procedure TestItemProc(Sender : TObject; Item : TAbArchiveItem); |
| 63 |
|
| 64 |
protected {properties} |
| 65 |
property ExtractOptions : TAbExtractOptions |
| 66 |
read FExtractOptions |
| 67 |
write SetExtractOptions |
| 68 |
default AbDefExtractOptions; |
| 69 |
property PasswordRetries : Byte |
| 70 |
read FPasswordRetries |
| 71 |
write SetPasswordRetries |
| 72 |
default AbDefPasswordRetries; |
| 73 |
|
| 74 |
protected {events} |
| 75 |
property OnConfirmOverwrite : TAbConfirmOverwriteEvent |
| 76 |
read FOnConfirmOverwrite |
| 77 |
write FOnConfirmOverwrite; |
| 78 |
property OnNeedPassword : TAbNeedPasswordEvent |
| 79 |
read FOnNeedPassword |
| 80 |
write FOnNeedPassword; |
| 81 |
|
| 82 |
public {methods} |
| 83 |
constructor Create(AOwner : TComponent); |
| 84 |
override; |
| 85 |
destructor Destroy; |
| 86 |
override; |
| 87 |
procedure ExtractAt(Index : Integer; const NewName : string); |
| 88 |
procedure ExtractFiles(const FileMask : string); |
| 89 |
{extract all files from the archive that match the mask} |
| 90 |
procedure ExtractFilesEx(const FileMask, ExclusionMask : string); |
| 91 |
{extract files matching FileMask except those matching ExclusionMask} |
| 92 |
procedure ExtractTaggedItems; |
| 93 |
{extract all tagged items from the archive} |
| 94 |
procedure ExtractToStream(const aFileName : string; ToStream : TStream); |
| 95 |
{extract the specified item to TStream descendant} |
| 96 |
procedure TestTaggedItems; |
| 97 |
{test all tagged items in the archive} |
| 98 |
|
| 99 |
public {property} |
| 100 |
property Spanned; |
| 101 |
end; |
| 102 |
|
| 103 |
TAbZipKit = class(TAbCustomZipKit) |
| 104 |
published |
| 105 |
property ArchiveProgressMeter; |
| 106 |
property ArchiveSaveProgressMeter; |
| 107 |
property AutoSave; |
| 108 |
property BaseDirectory; |
| 109 |
property CompressionMethodToUse; |
| 110 |
property DeflationOption; |
| 111 |
{$IFDEF MSWINDOWS} |
| 112 |
property DOSMode; |
| 113 |
{$ENDIF} |
| 114 |
property ExtractOptions; |
| 115 |
property SpanningThreshold; |
| 116 |
property ItemProgressMeter; |
| 117 |
property LogFile; |
| 118 |
property Logging; |
| 119 |
property OnArchiveProgress; |
| 120 |
property OnArchiveSaveProgress; |
| 121 |
property OnArchiveItemProgress; |
| 122 |
property OnChange; |
| 123 |
property OnConfirmOverwrite; |
| 124 |
property OnConfirmProcessItem; |
| 125 |
property OnConfirmSave; |
| 126 |
property OnLoad; |
| 127 |
property OnNeedPassword; |
| 128 |
property OnProcessItemFailure; |
| 129 |
property OnRequestBlankDisk; |
| 130 |
property OnRequestImage; |
| 131 |
property OnRequestLastDisk; |
| 132 |
property OnRequestNthDisk; |
| 133 |
property OnSave; |
| 134 |
property Password; |
| 135 |
property PasswordRetries; |
| 136 |
property StoreOptions; |
| 137 |
property TempDirectory; |
| 138 |
property Version; |
| 139 |
property FileName; {must be after OnLoad} |
| 140 |
end; |
| 141 |
|
| 142 |
|
| 143 |
implementation |
| 144 |
|
| 145 |
uses |
| 146 |
AbExcept, |
| 147 |
AbUnzPrc, |
| 148 |
AbZBrows; |
| 149 |
|
| 150 |
{ -------------------------------------------------------------------------- } |
| 151 |
constructor TAbCustomZipKit.Create( AOwner : TComponent ); |
| 152 |
begin |
| 153 |
inherited Create( AOwner ); |
| 154 |
PasswordRetries := AbDefPasswordRetries; |
| 155 |
end; |
| 156 |
{ -------------------------------------------------------------------------- } |
| 157 |
destructor TAbCustomZipKit.Destroy; |
| 158 |
begin |
| 159 |
inherited Destroy; |
| 160 |
end; |
| 161 |
{ -------------------------------------------------------------------------- } |
| 162 |
procedure TAbCustomZipKit.DoConfirmOverwrite( var Name : string; |
| 163 |
var Confirm : Boolean ); |
| 164 |
begin |
| 165 |
Confirm := True; |
| 166 |
if Assigned( FOnConfirmOverwrite ) then |
| 167 |
FOnConfirmOverwrite( Name, Confirm ); |
| 168 |
end; |
| 169 |
{ -------------------------------------------------------------------------- } |
| 170 |
procedure TAbCustomZipKit.DoNeedPassword( Sender : TObject; |
| 171 |
var NewPassword : AnsiString ); |
| 172 |
begin |
| 173 |
if Assigned( FOnNeedPassword ) then begin |
| 174 |
FOnNeedPassword( Self, NewPassword ); |
| 175 |
FPassword := NewPassword; |
| 176 |
end; |
| 177 |
end; |
| 178 |
{ -------------------------------------------------------------------------- } |
| 179 |
procedure TAbCustomZipKit.ExtractAt(Index : Integer; const NewName : string); |
| 180 |
{extract a file from the archive that match the index} |
| 181 |
begin |
| 182 |
if (ZipArchive <> nil) then |
| 183 |
ZipArchive.ExtractAt( Index, NewName ) |
| 184 |
else |
| 185 |
raise EAbNoArchive.Create; |
| 186 |
end; |
| 187 |
{ -------------------------------------------------------------------------- } |
| 188 |
procedure TAbCustomZipKit.ExtractFiles(const FileMask : string); |
| 189 |
{extract all files from the archive that match the mask} |
| 190 |
begin |
| 191 |
if (ZipArchive <> nil) then |
| 192 |
ZipArchive.ExtractFiles( FileMask ) |
| 193 |
else |
| 194 |
raise EAbNoArchive.Create; |
| 195 |
end; |
| 196 |
{ -------------------------------------------------------------------------- } |
| 197 |
procedure TAbCustomZipKit.ExtractFilesEx(const FileMask, ExclusionMask : string); |
| 198 |
{extract files matching FileMask except those matching ExclusionMask} |
| 199 |
begin |
| 200 |
if (ZipArchive <> nil) then |
| 201 |
ZipArchive.ExtractFilesEx( FileMask, ExclusionMask ) |
| 202 |
else |
| 203 |
raise EAbNoArchive.Create; |
| 204 |
end; |
| 205 |
{ -------------------------------------------------------------------------- } |
| 206 |
procedure TAbCustomZipKit.ExtractTaggedItems; |
| 207 |
{extract all tagged items from the archive} |
| 208 |
begin |
| 209 |
if (ZipArchive <> nil) then |
| 210 |
ZipArchive.ExtractTaggedItems |
| 211 |
else |
| 212 |
raise EAbNoArchive.Create; |
| 213 |
end; |
| 214 |
{ -------------------------------------------------------------------------- } |
| 215 |
procedure TAbCustomZipKit.ExtractToStream(const aFileName : string; |
| 216 |
ToStream : TStream); |
| 217 |
begin |
| 218 |
if (ZipArchive <> nil) then |
| 219 |
ZipArchive.ExtractToStream(aFileName, ToStream) |
| 220 |
else |
| 221 |
raise EAbNoArchive.Create; |
| 222 |
end; |
| 223 |
{ -------------------------------------------------------------------------- } |
| 224 |
procedure TAbCustomZipKit.InitArchive; |
| 225 |
begin |
| 226 |
inherited InitArchive; |
| 227 |
if (ZipArchive <> nil) then begin |
| 228 |
if ZipArchive is TAbZipArchive then begin |
| 229 |
{properties} |
| 230 |
ZipArchive.ExtractOptions := FExtractOptions; |
| 231 |
TAbZipArchive(ZipArchive).PasswordRetries := FPasswordRetries; |
| 232 |
{events} |
| 233 |
ZipArchive.OnConfirmOverwrite := DoConfirmOverwrite; |
| 234 |
TAbZipArchive(ZipArchive).OnNeedPassword := DoNeedPassword; |
| 235 |
TAbZipArchive(ZipArchive).ExtractHelper := UnzipProc; |
| 236 |
TAbZipArchive(ZipArchive).ExtractToStreamHelper := UnzipToStreamProc; |
| 237 |
TAbZipArchive(ZipArchive).TestHelper := TestItemProc; |
| 238 |
end; |
| 239 |
end; |
| 240 |
end; |
| 241 |
{ -------------------------------------------------------------------------- } |
| 242 |
procedure TAbCustomZipKit.SetExtractOptions( Value : TAbExtractOptions ); |
| 243 |
begin |
| 244 |
FExtractOptions := Value; |
| 245 |
if (ZipArchive <> nil) then |
| 246 |
ZipArchive.ExtractOptions := Value; |
| 247 |
end; |
| 248 |
{ -------------------------------------------------------------------------- } |
| 249 |
procedure TAbCustomZipKit.SetPasswordRetries( Value : Byte ); |
| 250 |
begin |
| 251 |
FPasswordRetries := Value; |
| 252 |
if (ZipArchive <> nil) then |
| 253 |
(ZipArchive as TAbZipArchive).PasswordRetries := Value; |
| 254 |
end; |
| 255 |
{ -------------------------------------------------------------------------- } |
| 256 |
procedure TAbCustomZipKit.TestTaggedItems; |
| 257 |
{test all tagged items in the archive} |
| 258 |
begin |
| 259 |
if (ZipArchive <> nil) then |
| 260 |
ZipArchive.TestTaggedItems |
| 261 |
else |
| 262 |
raise EAbNoArchive.Create; |
| 263 |
end; |
| 264 |
{ -------------------------------------------------------------------------- } |
| 265 |
procedure TAbCustomZipKit.UnzipProc( Sender : TObject; Item : TAbArchiveItem; |
| 266 |
const NewName : string ); |
| 267 |
begin |
| 268 |
AbUnzip( TAbZipArchive(Sender), TAbZipItem(Item), NewName); |
| 269 |
end; |
| 270 |
{ -------------------------------------------------------------------------- } |
| 271 |
procedure TAbCustomZipKit.UnzipToStreamProc(Sender : TObject; Item : TAbArchiveItem; |
| 272 |
OutStream : TStream); |
| 273 |
begin |
| 274 |
AbUnzipToStream(TAbZipArchive(Sender), TAbZipItem(Item), OutStream); |
| 275 |
end; |
| 276 |
{ -------------------------------------------------------------------------- } |
| 277 |
procedure TAbCustomZipKit.TestItemProc(Sender : TObject; Item : TAbArchiveItem); |
| 278 |
begin |
| 279 |
AbTestZipItem(TAbZipArchive(Sender), TAbZipItem(Item)); |
| 280 |
end; |
| 281 |
{ -------------------------------------------------------------------------- } |
| 282 |
|
| 283 |
end. |
| 284 |
|