| 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 |
* Craig Peterson <[email protected]> |
| 24 |
* |
| 25 |
* ***** END LICENSE BLOCK ***** *) |
| 26 |
|
| 27 |
{*********************************************************} |
| 28 |
{* ABBREVIA: AbZBrows.pas *} |
| 29 |
{*********************************************************} |
| 30 |
{* ABBREVIA: Zip file Browser Component *} |
| 31 |
{*********************************************************} |
| 32 |
|
| 33 |
unit AbZBrows; |
| 34 |
|
| 35 |
{$I AbDefine.inc} |
| 36 |
|
| 37 |
interface |
| 38 |
|
| 39 |
uses |
| 40 |
Classes, |
| 41 |
AbArcTyp, AbBrowse, AbSpanSt, AbZipTyp; |
| 42 |
|
| 43 |
type |
| 44 |
TAbCustomZipBrowser = class(TAbBaseBrowser) |
| 45 |
private |
| 46 |
function GetTarAutoHandle: Boolean; |
| 47 |
procedure SetTarAutoHandle(const Value: Boolean); |
| 48 |
protected {private} |
| 49 |
FPassword : AnsiString; |
| 50 |
FOnRequestLastDisk : TAbRequestDiskEvent; |
| 51 |
FOnRequestNthDisk : TAbRequestNthDiskEvent; |
| 52 |
FOnRequestBlankDisk : TAbRequestDiskEvent; |
| 53 |
FTarAutoHandle : Boolean; |
| 54 |
|
| 55 |
protected {methods} |
| 56 |
function GetItem(Index : Integer) : TAbZipItem; virtual; |
| 57 |
function GetStream: TStream; |
| 58 |
function GetZipfileComment : AnsiString; |
| 59 |
procedure InitArchive; |
| 60 |
override; |
| 61 |
procedure SetFileName(const aFileName : string); |
| 62 |
override; |
| 63 |
procedure SetStream(aValue: TStream); |
| 64 |
procedure SetOnRequestLastDisk(Value : TAbRequestDiskEvent); |
| 65 |
procedure SetOnRequestNthDisk(Value : TAbRequestNthDiskEvent); |
| 66 |
procedure SetOnRequestBlankDisk(Value : TAbRequestDiskEvent); |
| 67 |
|
| 68 |
procedure SetPassword(const Value : AnsiString); |
| 69 |
procedure SetZipfileComment(const Value : AnsiString); |
| 70 |
virtual; |
| 71 |
|
| 72 |
protected {properties} |
| 73 |
property Password : AnsiString |
| 74 |
read FPassword |
| 75 |
write SetPassword; |
| 76 |
|
| 77 |
protected {events} |
| 78 |
property OnRequestLastDisk : TAbRequestDiskEvent |
| 79 |
read FOnRequestLastDisk |
| 80 |
write SetOnRequestLastDisk; |
| 81 |
property OnRequestNthDisk : TAbRequestNthDiskEvent |
| 82 |
read FOnRequestNthDisk |
| 83 |
write SetOnRequestNthDisk; |
| 84 |
property OnRequestBlankDisk : TAbRequestDiskEvent |
| 85 |
read FOnRequestBlankDisk |
| 86 |
write SetOnRequestBlankDisk; |
| 87 |
|
| 88 |
public {methods} |
| 89 |
constructor Create(AOwner : TComponent); override; |
| 90 |
destructor Destroy; override; |
| 91 |
|
| 92 |
public {properties} |
| 93 |
property Items[Index : Integer] : TAbZipItem |
| 94 |
read GetItem; default; |
| 95 |
property Stream : TStream // This can be used instead of Filename |
| 96 |
read GetStream write SetStream; |
| 97 |
property ZipArchive : {TAbZipArchive} TAbArchive |
| 98 |
read FArchive; |
| 99 |
property ZipfileComment : AnsiString |
| 100 |
read GetZipfileComment |
| 101 |
write SetZipfileComment; |
| 102 |
|
| 103 |
property TarAutoHandle : Boolean |
| 104 |
read GetTarAutoHandle |
| 105 |
write SetTarAutoHandle; |
| 106 |
end; |
| 107 |
|
| 108 |
TAbZipBrowser = class(TAbCustomZipBrowser) |
| 109 |
published |
| 110 |
property ArchiveProgressMeter; |
| 111 |
property ItemProgressMeter; |
| 112 |
property BaseDirectory; |
| 113 |
property LogFile; |
| 114 |
property Logging; |
| 115 |
property OnArchiveProgress; |
| 116 |
property OnArchiveItemProgress; |
| 117 |
property OnChange; |
| 118 |
property OnConfirmProcessItem; |
| 119 |
property OnLoad; |
| 120 |
property OnProcessItemFailure; |
| 121 |
property OnRequestLastDisk; |
| 122 |
property OnRequestNthDisk; |
| 123 |
property Version; |
| 124 |
property TarAutoHandle; |
| 125 |
property FileName; {must be after OnLoad} |
| 126 |
end; |
| 127 |
|
| 128 |
|
| 129 |
implementation |
| 130 |
|
| 131 |
uses |
| 132 |
SysUtils, AbBzip2Typ, AbExcept, AbGzTyp, AbTarTyp, AbUtils, DCOSUtils; |
| 133 |
|
| 134 |
{ TAbCustomZipBrowser implementation ======================================= } |
| 135 |
|
| 136 |
{ -------------------------------------------------------------------------- } |
| 137 |
constructor TAbCustomZipBrowser.Create(AOwner : TComponent); |
| 138 |
begin |
| 139 |
inherited Create(AOwner); |
| 140 |
end; |
| 141 |
{ -------------------------------------------------------------------------- } |
| 142 |
destructor TAbCustomZipBrowser.Destroy; |
| 143 |
begin |
| 144 |
inherited Destroy; |
| 145 |
end; |
| 146 |
{ -------------------------------------------------------------------------- } |
| 147 |
function TAbCustomZipBrowser.GetItem(Index : Integer) : TAbZipItem; |
| 148 |
begin |
| 149 |
Result := TAbZipItem(ZipArchive.ItemList[Index]); |
| 150 |
end; |
| 151 |
{ -------------------------------------------------------------------------- } |
| 152 |
function TAbCustomZipBrowser.GetStream: TStream; |
| 153 |
begin |
| 154 |
if FArchive <> nil then |
| 155 |
Result := FArchive.FStream |
| 156 |
else |
| 157 |
Result := nil |
| 158 |
end; |
| 159 |
{ -------------------------------------------------------------------------- } |
| 160 |
function TAbCustomZipBrowser.GetTarAutoHandle: Boolean; |
| 161 |
begin |
| 162 |
Result := False; |
| 163 |
if FArchive is TAbGzipArchive then |
| 164 |
Result := TAbGzipArchive(FArchive).TarAutoHandle |
| 165 |
else if FArchive is TAbBzip2Archive then |
| 166 |
Result := TAbBzip2Archive(FArchive).TarAutoHandle; |
| 167 |
end; |
| 168 |
{ -------------------------------------------------------------------------- } |
| 169 |
function TAbCustomZipBrowser.GetZipfileComment : AnsiString; |
| 170 |
begin |
| 171 |
if ZipArchive is TAbZipArchive then |
| 172 |
Result := TAbZipArchive(ZipArchive).ZipfileComment |
| 173 |
else |
| 174 |
Result := ''; |
| 175 |
end; |
| 176 |
{ -------------------------------------------------------------------------- } |
| 177 |
procedure TAbCustomZipBrowser.InitArchive; |
| 178 |
begin |
| 179 |
inherited InitArchive; |
| 180 |
if ZipArchive is TAbZipArchive then begin |
| 181 |
{properties} |
| 182 |
TAbZipArchive(ZipArchive).Password := FPassword; |
| 183 |
{events} |
| 184 |
TAbZipArchive(ZipArchive).OnRequestLastDisk := FOnRequestLastDisk; |
| 185 |
TAbZipArchive(ZipArchive).OnRequestNthDisk := FOnRequestNthDisk; |
| 186 |
end; |
| 187 |
end; |
| 188 |
{ -------------------------------------------------------------------------- } |
| 189 |
|
| 190 |
procedure TAbCustomZipBrowser.SetFileName(const aFileName : string); |
| 191 |
var |
| 192 |
ArcType : TAbArchiveType; |
| 193 |
begin |
| 194 |
|
| 195 |
FFileName := aFileName; |
| 196 |
if csDesigning in ComponentState then |
| 197 |
Exit; |
| 198 |
try |
| 199 |
if Assigned(FArchive) then begin |
| 200 |
FArchive.Save; |
| 201 |
end; |
| 202 |
except |
| 203 |
end; |
| 204 |
FArchive.Free; |
| 205 |
FArchive := nil; |
| 206 |
|
| 207 |
if FileName <> '' then begin |
| 208 |
if mbFileExists(FileName) then begin { open it } |
| 209 |
ArcType := ArchiveType; |
| 210 |
if not ForceType then |
| 211 |
ArcType := AbDetermineArcType(FileName, atUnknown); |
| 212 |
|
| 213 |
case ArcType of |
| 214 |
atZip, atSpannedZip, atSelfExtZip : begin |
| 215 |
FArchive := TAbZipArchive.Create(FileName, fmOpenRead or fmShareDenyNone); |
| 216 |
InitArchive; |
| 217 |
end; |
| 218 |
|
| 219 |
atTar : begin |
| 220 |
FArchive := TAbTarArchive.Create(FileName, fmOpenRead or fmShareDenyNone); |
| 221 |
inherited InitArchive; |
| 222 |
end; |
| 223 |
|
| 224 |
atGZip : begin |
| 225 |
FArchive := TAbGzipArchive.Create(FileName, fmOpenRead or fmShareDenyNone); |
| 226 |
TAbGzipArchive(FArchive).TarAutoHandle := FTarAutoHandle; |
| 227 |
TAbGzipArchive(FArchive).IsGzippedTar := False; |
| 228 |
inherited InitArchive; |
| 229 |
end; |
| 230 |
|
| 231 |
atGZippedTar : begin |
| 232 |
FArchive := TAbGzipArchive.Create(FileName, fmOpenRead or fmShareDenyNone); |
| 233 |
TAbGzipArchive(FArchive).TarAutoHandle := FTarAutoHandle; |
| 234 |
TAbGzipArchive(FArchive).IsGzippedTar := True; |
| 235 |
inherited InitArchive; |
| 236 |
end; |
| 237 |
|
| 238 |
atBzip2 : begin |
| 239 |
FArchive := TAbBzip2Archive.Create(FileName, fmOpenRead or fmShareDenyNone); |
| 240 |
TAbBzip2Archive(FArchive).TarAutoHandle := FTarAutoHandle; |
| 241 |
TAbBzip2Archive(FArchive).IsBzippedTar := False; |
| 242 |
inherited InitArchive; |
| 243 |
end; |
| 244 |
|
| 245 |
atBzippedTar : begin |
| 246 |
FArchive := TAbBzip2Archive.Create(FileName, fmOpenRead or fmShareDenyNone); |
| 247 |
TAbBzip2Archive(FArchive).TarAutoHandle := FTarAutoHandle; |
| 248 |
TAbBzip2Archive(FArchive).IsBzippedTar := True; |
| 249 |
inherited InitArchive; |
| 250 |
end; |
| 251 |
|
| 252 |
else |
| 253 |
raise EAbUnhandledType.Create; |
| 254 |
end {case}; |
| 255 |
FArchive.Load; |
| 256 |
FArchiveType := ArcType; |
| 257 |
end; |
| 258 |
end; |
| 259 |
DoChange; |
| 260 |
end; |
| 261 |
{ -------------------------------------------------------------------------- } |
| 262 |
procedure TAbCustomZipBrowser.SetStream(aValue: TStream); |
| 263 |
var |
| 264 |
ArcType : TAbArchiveType; |
| 265 |
begin |
| 266 |
FFileName := ''; |
| 267 |
try |
| 268 |
if FArchive <> nil then |
| 269 |
FArchive.Save; |
| 270 |
except |
| 271 |
end; |
| 272 |
FreeAndNil(FArchive); |
| 273 |
|
| 274 |
if aValue <> nil then begin |
| 275 |
ArcType := ArchiveType; |
| 276 |
if not ForceType then |
| 277 |
ArcType := AbDetermineArcType(aValue); |
| 278 |
|
| 279 |
case ArcType of |
| 280 |
atZip, atSpannedZip, atSelfExtZip : begin |
| 281 |
FArchive := TAbZipArchive.CreateFromStream(aValue, ''); |
| 282 |
end; |
| 283 |
|
| 284 |
atTar : begin |
| 285 |
FArchive := TAbTarArchive.CreateFromStream(aValue, ''); |
| 286 |
end; |
| 287 |
|
| 288 |
atGZip, atGZippedTar : begin |
| 289 |
FArchive := TAbGzipArchive.CreateFromStream(aValue, ''); |
| 290 |
TAbGzipArchive(FArchive).TarAutoHandle := FTarAutoHandle; |
| 291 |
TAbGzipArchive(FArchive).IsGzippedTar := (ArcType = atGZippedTar); |
| 292 |
end; |
| 293 |
|
| 294 |
atBzip2, atBzippedTar : begin |
| 295 |
FArchive := TAbBzip2Archive.CreateFromStream(aValue, ''); |
| 296 |
TAbBzip2Archive(FArchive).TarAutoHandle := FTarAutoHandle; |
| 297 |
TAbBzip2Archive(FArchive).IsBzippedTar := (ArcType = atBzippedTar); |
| 298 |
end; |
| 299 |
|
| 300 |
else |
| 301 |
raise EAbUnhandledType.Create; |
| 302 |
end {case}; |
| 303 |
InitArchive; |
| 304 |
FArchive.Load; |
| 305 |
FArchiveType := ArcType; |
| 306 |
end; |
| 307 |
DoChange; |
| 308 |
end; |
| 309 |
{ -------------------------------------------------------------------------- } |
| 310 |
procedure TAbCustomZipBrowser.SetOnRequestBlankDisk(Value : TAbRequestDiskEvent); |
| 311 |
begin |
| 312 |
FOnRequestBlankDisk := Value; |
| 313 |
if ZipArchive is TAbZipArchive then |
| 314 |
TAbZipArchive(ZipArchive).OnRequestBlankDisk := FOnRequestBlankDisk; |
| 315 |
end; |
| 316 |
{ -------------------------------------------------------------------------- } |
| 317 |
procedure TAbCustomZipBrowser.SetOnRequestLastDisk(Value : TAbRequestDiskEvent); |
| 318 |
begin |
| 319 |
FOnRequestLastDisk := Value; |
| 320 |
if ZipArchive is TAbZipArchive then |
| 321 |
TAbZipArchive(ZipArchive).OnRequestLastDisk := FOnRequestLastDisk; |
| 322 |
end; |
| 323 |
{ -------------------------------------------------------------------------- } |
| 324 |
procedure TAbCustomZipBrowser.SetOnRequestNthDisk(Value : TAbRequestNthDiskEvent); |
| 325 |
begin |
| 326 |
FOnRequestNthDisk := Value; |
| 327 |
if ZipArchive is TAbZipArchive then |
| 328 |
TAbZipArchive(ZipArchive).OnRequestNthDisk := FOnRequestNthDisk; |
| 329 |
end; |
| 330 |
{ -------------------------------------------------------------------------- } |
| 331 |
procedure TAbCustomZipBrowser.SetPassword(const Value : AnsiString); |
| 332 |
begin |
| 333 |
FPassword := Value; |
| 334 |
if ZipArchive is TAbZipArchive then |
| 335 |
TAbZipArchive(ZipArchive).Password := Value; |
| 336 |
end; |
| 337 |
{ -------------------------------------------------------------------------- } |
| 338 |
procedure TAbCustomZipBrowser.SetTarAutoHandle(const Value: Boolean); |
| 339 |
begin |
| 340 |
FTarAutoHandle := Value; |
| 341 |
|
| 342 |
if FArchive is TAbGzipArchive then begin |
| 343 |
if TAbGzipArchive(FArchive).TarAutoHandle <> Value then begin |
| 344 |
TAbGzipArchive(FArchive).TarAutoHandle := Value; |
| 345 |
InitArchive; |
| 346 |
FArchive.Load; |
| 347 |
DoChange; |
| 348 |
end; |
| 349 |
end; |
| 350 |
if FArchive is TAbBzip2Archive then begin |
| 351 |
if TAbBzip2Archive(FArchive).TarAutoHandle <> Value then begin |
| 352 |
TAbBzip2Archive(FArchive).TarAutoHandle := Value; |
| 353 |
InitArchive; |
| 354 |
FArchive.Load; |
| 355 |
DoChange; |
| 356 |
end; |
| 357 |
end; |
| 358 |
end; |
| 359 |
|
| 360 |
procedure TAbCustomZipBrowser.SetZipfileComment(const Value : AnsiString); |
| 361 |
begin |
| 362 |
{NOP - descendents wishing to set this property should override} |
| 363 |
end; |
| 364 |
{ -------------------------------------------------------------------------- } |
| 365 |
|
| 366 |
end. |