~ximion/listaller/master

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
(* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is TurboPower Abbrevia
 *
 * The Initial Developer of the Original Code is
 * TurboPower Software
 *
 * Portions created by the Initial Developer are Copyright (C) 1997-2002
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * ***** END LICENSE BLOCK ***** *)

{*********************************************************}
{* ABBREVIA: AbZBrows.pas 3.05                           *}
{*********************************************************}
{* ABBREVIA: Zip file Browser Component                  *}
{*********************************************************}

unit AbZBrows;

{$I AbDefine.inc}

interface

uses
  SysUtils, Classes,
  AbBrowse,
  AbBase, AbExcept, AbUtils, AbArcTyp, AbZipTyp, AbTarTyp, AbGzTyp, AbSpanSt;

type
  TAbCustomZipBrowser = class(TAbBaseBrowser)
  private
    function GetTarAutoHandle: Boolean;
    procedure SetTarAutoHandle(const Value: Boolean);
  protected {private}
    FSpanStream        : TAbSpanStream;
    FPassword          : string;
    FOnRequestLastDisk : TAbRequestDiskEvent;
    FOnRequestNthDisk  : TAbRequestNthDiskEvent;
    FOnRequestBlankDisk     : TAbRequestDiskEvent;
    FTarAutoHandle     : Boolean;

  protected {methods}
    function  GetItem(Index : Integer) : TAbZipItem; virtual;
    function  GetZipArchive : {TAbZipArchive} TAbArchive;
    function  GetZipfileComment : string;
    procedure InitArchive;
      override;
    procedure SetFileName(const aFileName : string);
      override;
    procedure SetOnRequestLastDisk(Value : TAbRequestDiskEvent);
    procedure SetOnRequestNthDisk(Value : TAbRequestNthDiskEvent);
    procedure SetOnRequestBlankDisk(Value : TAbRequestDiskEvent);
    procedure SetOnRequestImage(Value : TAbRequestImageEvent); override;

    procedure SetPassword(Value : string);
    procedure SetZipfileComment(Value : string);
      virtual;

  protected {properties}
    property Password : string
      read  FPassword
      write SetPassword;

  protected {events}
    property OnRequestLastDisk : TAbRequestDiskEvent
      read  FOnRequestLastDisk
      write SetOnRequestLastDisk;
    property OnRequestNthDisk : TAbRequestNthDiskEvent
      read  FOnRequestNthDisk
      write SetOnRequestNthDisk;
    property OnRequestBlankDisk : TAbRequestDiskEvent
      read  FOnRequestBlankDisk
      write SetOnRequestBlankDisk;

  public {methods}
    constructor Create(AOwner : TComponent); override;
    destructor Destroy; override;

  public {properties}
    property Items[Index : Integer] : TAbZipItem
      read  GetItem; default;
    property ZipArchive : {TAbZipArchive} TAbArchive
      read GetZipArchive;
    property ZipfileComment : string
      read GetZipfileComment
      write SetZipfileComment;

    property TarAutoHandle : Boolean
      read GetTarAutoHandle
      write SetTarAutoHandle;
  end;

  TAbZipBrowser = class(TAbCustomZipBrowser)
  published
    property ArchiveProgressMeter;
    property ItemProgressMeter;
    property BaseDirectory;
    property LogFile;
    property Logging;
    property OnArchiveProgress;
    property OnArchiveItemProgress;
    property OnChange;
    property OnConfirmProcessItem;
    property OnLoad;
    property OnProcessItemFailure;
    property OnRequestLastDisk;
    property OnRequestNthDisk;
    property Version;
    property TarAutoHandle;
    property FileName;  {must be after OnLoad}
  end;


implementation

uses
  AbConst;

{ TAbCustomZipBrowser implementation ======================================= }

{ -------------------------------------------------------------------------- }
constructor TAbCustomZipBrowser.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
end;
{ -------------------------------------------------------------------------- }
destructor TAbCustomZipBrowser.Destroy;
begin
  inherited Destroy;
end;
{ -------------------------------------------------------------------------- }
function TAbCustomZipBrowser.GetItem(Index : Integer) : TAbZipItem;
begin
  Result := TAbZipItem(ZipArchive.ItemList[Index]);
end;
{ -------------------------------------------------------------------------- }
function TAbCustomZipBrowser.GetTarAutoHandle: Boolean;
begin
  Result := False;
  if FArchive is TAbGzipArchive then begin
    Result := TAbGzipArchive(FArchive).TarAutoHandle;
  end;
end;
{ -------------------------------------------------------------------------- }
function TAbCustomZipBrowser.GetZipArchive : TAbArchive;
begin
  if Assigned(FArchive) then
    Result := FArchive
  else
    Result := nil;
end;
{ -------------------------------------------------------------------------- }
function TAbCustomZipBrowser.GetZipfileComment : string;
begin
  if (ZipArchive<> nil) then
    Result := (ZipArchive as TAbZipArchive).ZipfileComment
  else
    Result := '';
end;
{ -------------------------------------------------------------------------- }
procedure TAbCustomZipBrowser.InitArchive;
begin
  inherited InitArchive;
  if (ZipArchive<> nil) then begin
    if (ZipArchive is TAbZipArchive) then begin
      {properties}
      TAbZipArchive(ZipArchive).Password          := FPassword;
      {events}
      TAbZipArchive(ZipArchive).OnRequestLastDisk := FOnRequestLastDisk;
      TAbZipArchive(ZipArchive).OnRequestNthDisk  := FOnRequestNthDisk;
    end;
  end;
end;
{ -------------------------------------------------------------------------- }

procedure TAbCustomZipBrowser.SetFileName(const aFileName : string);
var
  ArcType : TAbArchiveType;
begin

  FFileName := aFileName;
  if csDesigning in ComponentState then
    Exit;
  try
    if Assigned(FArchive) then begin
      FArchive.Save;
    end;
  except
  end;
  FArchive.Free;
  FArchive := nil;

  if FileName <> '' then begin
    if FileExists(FileName) then begin { open it }
      ArcType := ArchiveType;
      if not ForceType then
         ArcType := AbDetermineArcType(FileName, atUnknown);

      case ArcType of
        atZip, atSpannedZip, atSelfExtZip : begin                        {!!.03}
          FArchive := TAbZipArchive.Create(FileName, fmOpenRead or fmShareDenyNone);
          InitArchive;
        end;

        atTar : begin
          FArchive := TAbTarArchive.Create(FileName, fmOpenRead or fmShareDenyNone);
          inherited InitArchive;
        end;

        atGZip : begin
          FArchive := TAbGzipArchive.Create(FileName, fmOpenRead or fmShareDenyNone);
          TAbGzipArchive(FArchive).TarAutoHandle := FTarAutoHandle;
          TAbGzipArchive(FArchive).IsGzippedTar := False;
          inherited InitArchive;
        end;

        atGZippedTar : begin
          FArchive := TAbGzipArchive.Create(FileName, fmOpenRead or fmShareDenyNone);
          TAbGzipArchive(FArchive).TarAutoHandle := FTarAutoHandle;
          TAbGzipArchive(FArchive).IsGzippedTar := True;
          inherited InitArchive;
        end;

        else
          raise EAbUnhandledType.Create;
      end {case};
      FArchive.Load;
      FArchiveType := ArcType;
    end
    else
      FArchive.FStatus := asInvalid;
  end;
  DoChange;
end;
{ -------------------------------------------------------------------------- }
procedure TAbCustomZipBrowser.SetOnRequestBlankDisk(Value : TAbRequestDiskEvent);
var
  Archive : TAbZipArchive;
begin
  FOnRequestBlankDisk := Value;
  if (ZipArchive <> nil) then begin
    Archive := (ZipArchive as TAbZipArchive);
    Archive.OnRequestBlankDisk := FOnRequestBlankDisk;
  end;
end;
{ -------------------------------------------------------------------------- }
procedure TAbCustomZipBrowser.SetOnRequestImage(Value : TAbRequestImageEvent);
begin
  inherited SetOnRequestImage(Value);
  if (ZipArchive <> nil) and Assigned(FSpanStream) then
      FSpanStream.OnRequestImage := FOnRequestImage;
end;
{ -------------------------------------------------------------------------- }
procedure TAbCustomZipBrowser.SetOnRequestLastDisk(Value : TAbRequestDiskEvent);
var
  Archive : TAbZipArchive;
begin
  FOnRequestLastDisk := Value;
  if (ZipArchive <> nil) then begin
    Archive := (ZipArchive as TAbZipArchive);
    Archive.OnRequestLastDisk := Value;
  end;
end;
{ -------------------------------------------------------------------------- }
procedure TAbCustomZipBrowser.SetOnRequestNthDisk(Value : TAbRequestNthDiskEvent);
var
  Archive : TAbZipArchive;
begin
  FOnRequestNthDisk := Value;
  if (ZipArchive <> nil) then begin
    Archive := (ZipArchive as TAbZipArchive);
    Archive.OnRequestNthDisk := FOnRequestNthDisk;
  end;
end;
{ -------------------------------------------------------------------------- }
procedure TAbCustomZipBrowser.SetPassword(Value : string);
begin
  FPassword := Value;
  if (ZipArchive <> nil) then
    (ZipArchive as TAbZipArchive).Password := Value;
end;
{ -------------------------------------------------------------------------- }
procedure TAbCustomZipBrowser.SetTarAutoHandle(const Value: Boolean);
begin
  FTarAutoHandle := Value;

  if Assigned(FArchive) and (FArchive is TAbGzipArchive) then begin
    if TAbGzipArchive(FArchive).TarAutoHandle <> Value then begin
      TAbGzipArchive(FArchive).TarAutoHandle := Value;
      InitArchive;
      FArchive.Load;
      DoChange;
    end;
  end;
end;

procedure TAbCustomZipBrowser.SetZipfileComment(Value : string);
begin
  {NOP - descendents wishing to set this property should override}
end;
{ -------------------------------------------------------------------------- }

end.