| 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: AbArcTyp.pas *} |
| 28 |
{*********************************************************} |
| 29 |
{* ABBREVIA: TABArchive, TABArchiveItem classes *} |
| 30 |
{*********************************************************} |
| 31 |
|
| 32 |
unit AbArcTyp; |
| 33 |
|
| 34 |
{$I AbDefine.inc} |
| 35 |
|
| 36 |
interface |
| 37 |
|
| 38 |
uses |
| 39 |
Classes, |
| 40 |
Types, |
| 41 |
DCStrUtils, |
| 42 |
AbUtils; |
| 43 |
|
| 44 |
{ ===== TAbArchiveItem ====================================================== } |
| 45 |
type |
| 46 |
TAbArchiveItem = class(TObject) |
| 47 |
protected {private} |
| 48 |
NextItem : TAbArchiveItem; |
| 49 |
FAction : TAbArchiveAction; |
| 50 |
FCompressedSize : Int64; |
| 51 |
FCRC32 : Longint; |
| 52 |
FDiskFileName : string; |
| 53 |
FExternalFileAttributes : LongWord; |
| 54 |
FFileName : string; |
| 55 |
FIsEncrypted : Boolean; |
| 56 |
FLastModFileTime : Word; |
| 57 |
FLastModFileDate : Word; |
| 58 |
FTagged : Boolean; |
| 59 |
FUncompressedSize : Int64; |
| 60 |
|
| 61 |
protected {property methods} |
| 62 |
function GetCompressedSize : Int64; virtual; |
| 63 |
function GetCRC32 : Longint; virtual; |
| 64 |
function GetDiskPath : string; |
| 65 |
function GetExternalFileAttributes : LongWord; virtual; |
| 66 |
function GetFileName : string; virtual; |
| 67 |
function GetIsDirectory: Boolean; virtual; |
| 68 |
function GetIsEncrypted : Boolean; virtual; |
| 69 |
function GetLastModFileDate : Word; virtual; |
| 70 |
function GetLastModFileTime : Word; virtual; |
| 71 |
{ This depends on in what format the attributes are stored in the archive, |
| 72 |
to which system they refer (MS-DOS, Unix, etc.) and what system |
| 73 |
we're running on (compile time). } |
| 74 |
function GetNativeFileAttributes : LongInt; virtual; |
| 75 |
{ This depends on in what format the date/time is stored in the archive |
| 76 |
(Unix, MS-DOS, ...) and what system we're running on (compile time). |
| 77 |
Returns MS-DOS local time on Windows, Unix UTC time on Unix. } |
| 78 |
function GetNativeLastModFileTime : Longint; virtual; |
| 79 |
function GetStoredPath : string; |
| 80 |
function GetUncompressedSize : Int64; virtual; |
| 81 |
procedure SetCompressedSize(const Value : Int64); virtual; |
| 82 |
procedure SetCRC32(const Value : Longint); virtual; |
| 83 |
procedure SetExternalFileAttributes( Value : LongWord ); virtual; |
| 84 |
procedure SetFileName(const Value : string); virtual; |
| 85 |
procedure SetIsEncrypted(Value : Boolean); virtual; |
| 86 |
procedure SetLastModFileDate(const Value : Word); virtual; |
| 87 |
procedure SetLastModFileTime(const Value : Word); virtual; |
| 88 |
procedure SetUncompressedSize(const Value : Int64); virtual; |
| 89 |
function GetLastModTimeAsDateTime: TDateTime; virtual; |
| 90 |
procedure SetLastModTimeAsDateTime(const Value: TDateTime); virtual; |
| 91 |
|
| 92 |
public {methods} |
| 93 |
constructor Create; |
| 94 |
destructor Destroy; override; |
| 95 |
function MatchesDiskName(const FileMask : string) : Boolean; |
| 96 |
function MatchesStoredName(const FileMask : string) : Boolean; |
| 97 |
function MatchesStoredNameEx(const FileMask : string) : Boolean; |
| 98 |
|
| 99 |
|
| 100 |
public {properties} |
| 101 |
property Action : TAbArchiveAction |
| 102 |
read FAction |
| 103 |
write FAction; |
| 104 |
property CompressedSize : Int64 |
| 105 |
read GetCompressedSize |
| 106 |
write SetCompressedSize; |
| 107 |
property CRC32 : Longint |
| 108 |
read GetCRC32 |
| 109 |
write SetCRC32; |
| 110 |
property DiskFileName : string |
| 111 |
read FDiskFileName |
| 112 |
write FDiskFileName; |
| 113 |
property DiskPath : string |
| 114 |
read GetDiskPath; |
| 115 |
property ExternalFileAttributes : LongWord |
| 116 |
read GetExternalFileAttributes |
| 117 |
write SetExternalFileAttributes; |
| 118 |
property FileName : string |
| 119 |
read GetFileName |
| 120 |
write SetFileName; |
| 121 |
property IsDirectory: Boolean |
| 122 |
read GetIsDirectory; |
| 123 |
property IsEncrypted : Boolean |
| 124 |
read GetIsEncrypted |
| 125 |
write SetIsEncrypted; |
| 126 |
property LastModFileDate : Word |
| 127 |
read GetLastModFileDate |
| 128 |
write SetLastModFileDate; |
| 129 |
property LastModFileTime : Word |
| 130 |
read GetLastModFileTime |
| 131 |
write SetLastModFileTime; |
| 132 |
property NativeFileAttributes : LongInt |
| 133 |
read GetNativeFileAttributes; |
| 134 |
property NativeLastModFileTime : Longint |
| 135 |
read GetNativeLastModFileTime; |
| 136 |
property StoredPath : string |
| 137 |
read GetStoredPath; |
| 138 |
property Tagged : Boolean |
| 139 |
read FTagged |
| 140 |
write FTagged; |
| 141 |
property UncompressedSize : Int64 |
| 142 |
read GetUncompressedSize |
| 143 |
write SetUncompressedSize; |
| 144 |
|
| 145 |
property LastModTimeAsDateTime : TDateTime |
| 146 |
read GetLastModTimeAsDateTime |
| 147 |
write SetLastModTimeAsDateTime; |
| 148 |
end; |
| 149 |
|
| 150 |
|
| 151 |
{ ===== TAbArchiveListEnumerator ============================================ } |
| 152 |
type |
| 153 |
TAbArchiveList = class; |
| 154 |
TAbArchiveListEnumerator = class |
| 155 |
private |
| 156 |
FIndex: Integer; |
| 157 |
FList: TAbArchiveList; |
| 158 |
public |
| 159 |
constructor Create(aList: TAbArchiveList); |
| 160 |
function GetCurrent: TAbArchiveItem; |
| 161 |
function MoveNext: Boolean; |
| 162 |
property Current: TAbArchiveItem read GetCurrent; |
| 163 |
end; |
| 164 |
|
| 165 |
|
| 166 |
{ ===== TAbArchiveList ====================================================== } |
| 167 |
|
| 168 |
TAbArchiveList = class |
| 169 |
protected {private} |
| 170 |
FList : TList; |
| 171 |
FOwnsItems: Boolean; |
| 172 |
HashTable : array[0..1020] of TAbArchiveItem; |
| 173 |
protected {methods} |
| 174 |
function GenerateHash(const S : string) : LongInt; |
| 175 |
function GetCount : Integer; |
| 176 |
function Get(Index : Integer) : TAbArchiveItem; |
| 177 |
procedure Put(Index : Integer; Item : TAbArchiveItem); |
| 178 |
public {methods} |
| 179 |
constructor Create(AOwnsItems: Boolean); |
| 180 |
destructor Destroy; override; |
| 181 |
function Add(Item : Pointer): Integer; |
| 182 |
procedure Clear; |
| 183 |
procedure Delete(Index : Integer); |
| 184 |
function Find(const FN : string) : Integer; |
| 185 |
function GetEnumerator: TAbArchiveListEnumerator; |
| 186 |
function IsActiveDupe(const FN : string) : Boolean; |
| 187 |
public {properties} |
| 188 |
property Count : Integer |
| 189 |
read GetCount; |
| 190 |
property Items[Index : Integer] : TAbArchiveItem |
| 191 |
read Get |
| 192 |
write Put; default; |
| 193 |
end; |
| 194 |
|
| 195 |
|
| 196 |
{ ===== TAbArchive specific types =========================================== } |
| 197 |
type |
| 198 |
TAbStoreOption = |
| 199 |
(soStripDrive, soStripPath, soRemoveDots, soRecurse, soFreshen, soReplace); |
| 200 |
TAbStoreOptions = |
| 201 |
set of TAbStoreOption; |
| 202 |
|
| 203 |
TAbExtractOption = |
| 204 |
(eoCreateDirs, eoRestorePath); |
| 205 |
TAbExtractOptions = |
| 206 |
set of TAbExtractOption; |
| 207 |
|
| 208 |
TAbArchiveStatus = |
| 209 |
(asInvalid, asIdle, asBusy); |
| 210 |
|
| 211 |
TAbArchiveEvent = |
| 212 |
procedure(Sender : TObject) of object; |
| 213 |
TAbArchiveConfirmEvent = |
| 214 |
procedure (Sender : TObject; var Confirm : Boolean) of object; |
| 215 |
TAbArchiveProgressEvent = |
| 216 |
procedure(Sender : TObject; Progress : Byte; var Abort : Boolean) of object; |
| 217 |
TAbArchiveItemEvent = |
| 218 |
procedure(Sender : TObject; Item : TAbArchiveItem) of object; |
| 219 |
TAbArchiveItemConfirmEvent = |
| 220 |
procedure(Sender : TObject; Item : TAbArchiveItem; |
| 221 |
ProcessType : TAbProcessType; var Confirm : Boolean) of object; |
| 222 |
TAbConfirmOverwriteEvent = |
| 223 |
procedure(var Name : string; var Confirm : Boolean) of object; |
| 224 |
TAbArchiveItemFailureEvent = |
| 225 |
procedure(Sender : TObject; Item : TAbArchiveItem; |
| 226 |
ProcessType : TAbProcessType; ErrorClass : TAbErrorClass; |
| 227 |
ErrorCode : Integer) of object; |
| 228 |
TAbArchiveItemExtractEvent = |
| 229 |
procedure(Sender : TObject; Item : TAbArchiveItem; |
| 230 |
const NewName : string) of object; |
| 231 |
TAbArchiveItemExtractToStreamEvent = |
| 232 |
procedure(Sender : TObject; Item : TAbArchiveItem; |
| 233 |
OutStream : TStream) of object; |
| 234 |
TAbArchiveItemTestEvent = |
| 235 |
procedure(Sender : TObject; Item : TAbArchiveItem) of object; |
| 236 |
TAbArchiveItemInsertEvent = |
| 237 |
procedure(Sender : TObject; Item : TAbArchiveItem; |
| 238 |
OutStream : TStream) of object; |
| 239 |
TAbArchiveItemInsertFromStreamEvent = |
| 240 |
procedure(Sender : TObject; Item : TAbArchiveItem; |
| 241 |
OutStream, InStream : TStream) of object; |
| 242 |
TAbArchiveItemProgressEvent = |
| 243 |
procedure(Sender : TObject; Item : TAbArchiveItem; Progress : Byte; |
| 244 |
var Abort : Boolean) of object; |
| 245 |
TAbProgressEvent = |
| 246 |
procedure(Progress : Byte; var Abort : Boolean) of object; |
| 247 |
TAbRequestDiskEvent = |
| 248 |
procedure(Sender : TObject; var Abort : Boolean) of object; |
| 249 |
TAbRequestImageEvent = |
| 250 |
procedure(Sender : TObject; ImageNumber : Integer; |
| 251 |
var ImageName : string; var Abort : Boolean) of object; |
| 252 |
TAbRequestNthDiskEvent = |
| 253 |
procedure(Sender : TObject; DiskNumber : Byte; var Abort : Boolean) of object; |
| 254 |
|
| 255 |
|
| 256 |
type |
| 257 |
TAbArchiveStreamHelper = class |
| 258 |
protected |
| 259 |
FStream : TStream; |
| 260 |
public |
| 261 |
constructor Create(AStream : TStream); |
| 262 |
procedure ExtractItemData(AStream : TStream); virtual; abstract; |
| 263 |
function FindFirstItem : Boolean; virtual; abstract; |
| 264 |
function FindNextItem : Boolean; virtual; abstract; |
| 265 |
procedure ReadHeader; virtual; abstract; |
| 266 |
procedure ReadTail; virtual; abstract; |
| 267 |
function SeekItem(Index : Integer): Boolean; virtual; abstract; |
| 268 |
procedure WriteArchiveHeader; virtual; abstract; |
| 269 |
procedure WriteArchiveItem(AStream : TStream); virtual; abstract; |
| 270 |
procedure WriteArchiveTail; virtual; abstract; |
| 271 |
function GetItemCount : Integer; virtual; abstract; |
| 272 |
end; |
| 273 |
|
| 274 |
|
| 275 |
{ ===== TAbArchive ========================================================== } |
| 276 |
type |
| 277 |
TAbArchive = class(TObject) |
| 278 |
public |
| 279 |
FStream : TStream; |
| 280 |
FStatus : TAbArchiveStatus; |
| 281 |
|
| 282 |
protected {property variables} //These break Encapsulation |
| 283 |
FArchiveName : string; |
| 284 |
FAutoSave : Boolean; |
| 285 |
FBaseDirectory : string; |
| 286 |
FCurrentItem : TAbArchiveItem; |
| 287 |
FDOSMode : Boolean; |
| 288 |
FExtractOptions : TAbExtractOptions; |
| 289 |
FImageNumber : Word; |
| 290 |
FInStream : TStream; |
| 291 |
FIsDirty : Boolean; |
| 292 |
FSpanningThreshold : Int64; |
| 293 |
FCompressionLevel : IntPtr; |
| 294 |
FCompressionMethod : IntPtr; |
| 295 |
FSuspiciousLinks : TStringList; |
| 296 |
FItemList : TAbArchiveList; |
| 297 |
FLogFile : string; |
| 298 |
FLogging : Boolean; |
| 299 |
FLogStream : TFileStream; |
| 300 |
FMode : Word; |
| 301 |
FOwnsStream : Boolean; |
| 302 |
FSpanned : Boolean; |
| 303 |
FStoreOptions : TAbStoreOptions; |
| 304 |
FTempDir : string; |
| 305 |
|
| 306 |
protected {event variables} |
| 307 |
FOnProcessItemFailure : TAbArchiveItemFailureEvent; |
| 308 |
FOnArchiveProgress : TAbArchiveProgressEvent; |
| 309 |
FOnArchiveSaveProgress : TAbArchiveProgressEvent; |
| 310 |
FOnArchiveItemProgress : TAbArchiveItemProgressEvent; |
| 311 |
FOnConfirmProcessItem : TAbArchiveItemConfirmEvent; |
| 312 |
FOnConfirmOverwrite : TAbConfirmOverwriteEvent; |
| 313 |
FOnConfirmSave : TAbArchiveConfirmEvent; |
| 314 |
FOnLoad : TAbArchiveEvent; |
| 315 |
FOnProgress : TAbProgressEvent; |
| 316 |
FOnRequestImage : TAbRequestImageEvent; |
| 317 |
FOnSave : TAbArchiveEvent; |
| 318 |
|
| 319 |
protected {methods} |
| 320 |
constructor CreateInit; |
| 321 |
procedure CheckValid; |
| 322 |
function ConfirmPath(Item : TAbArchiveItem; const NewName : string; |
| 323 |
out UseName : string) : Boolean; |
| 324 |
procedure FreshenAt(Index : Integer); |
| 325 |
function FreshenRequired(Item : TAbArchiveItem) : Boolean; |
| 326 |
procedure GetFreshenTarget(Item : TAbArchiveItem); |
| 327 |
function GetItemCount : Integer; |
| 328 |
procedure MakeLogEntry(const FN: string; LT : TAbLogType); |
| 329 |
procedure MakeFullNames(const SourceFileName: String; |
| 330 |
const ArchiveDirectory: String; |
| 331 |
out FullSourceFileName: String; |
| 332 |
out FullArchiveFileName: String); |
| 333 |
procedure ReplaceAt(Index : Integer); |
| 334 |
procedure SaveIfNeeded(aItem : TAbArchiveItem); |
| 335 |
procedure SetBaseDirectory(Value : string); |
| 336 |
procedure SetLogFile(const Value : string); |
| 337 |
procedure SetLogging(Value : Boolean); |
| 338 |
|
| 339 |
protected {abstract methods} |
| 340 |
function CreateItem(const SourceFileName : string; |
| 341 |
const ArchiveDirectory : string): TAbArchiveItem; |
| 342 |
{SourceFileName - full or relative path to a file/dir on some file system |
| 343 |
If full path, BaseDirectory is used to determine relative path} |
| 344 |
{ArchiveDirectory - path to a directory in the archive the file/dir will be in} |
| 345 |
{Example: |
| 346 |
FBaseDirectory = /dir |
| 347 |
SourceFileName = /dir/subdir/file |
| 348 |
ArchiveDirectory = files/storage (or files/storage/) |
| 349 |
-> name in archive = files/storage/subdir/file} |
| 350 |
virtual; abstract; overload; |
| 351 |
function CreateItem(const FileSpec : string): TAbArchiveItem; |
| 352 |
overload; |
| 353 |
procedure ExtractItemAt(Index : Integer; const UseName : string); |
| 354 |
virtual; abstract; |
| 355 |
procedure ExtractItemToStreamAt(Index : Integer; aStream : TStream); |
| 356 |
virtual; abstract; |
| 357 |
procedure LoadArchive; |
| 358 |
virtual; abstract; |
| 359 |
procedure SaveArchive; |
| 360 |
virtual; abstract; |
| 361 |
procedure TestItemAt(Index : Integer); |
| 362 |
virtual; abstract; |
| 363 |
|
| 364 |
protected {virtual methods} |
| 365 |
procedure DoProcessItemFailure(Item : TAbArchiveItem; |
| 366 |
ProcessType : TAbProcessType; ErrorClass : TAbErrorClass; |
| 367 |
ErrorCode : Integer); |
| 368 |
virtual; |
| 369 |
procedure DoArchiveSaveProgress(Progress : Byte; var Abort : Boolean); |
| 370 |
virtual; |
| 371 |
procedure DoArchiveProgress(Progress : Byte; var Abort : Boolean); |
| 372 |
virtual; |
| 373 |
procedure DoArchiveItemProgress(Item : TAbArchiveItem; Progress : Byte; |
| 374 |
var Abort : Boolean); |
| 375 |
virtual; |
| 376 |
procedure DoConfirmOverwrite(var FileName : string; var Confirm : Boolean); |
| 377 |
virtual; |
| 378 |
procedure DoConfirmProcessItem(Item : TAbArchiveItem; |
| 379 |
const ProcessType : TAbProcessType; var Confirm : Boolean); |
| 380 |
virtual; |
| 381 |
procedure DoConfirmSave(var Confirm : Boolean); |
| 382 |
virtual; |
| 383 |
|
| 384 |
procedure DoLoad; |
| 385 |
virtual; |
| 386 |
procedure DoProgress(Progress : Byte; var Abort : Boolean); |
| 387 |
virtual; |
| 388 |
procedure DoSave; |
| 389 |
virtual; |
| 390 |
function FixName(const Value : string) : string; |
| 391 |
virtual; |
| 392 |
function GetSpanningThreshold : Int64; |
| 393 |
virtual; |
| 394 |
function GetSupportsEmptyFolders : Boolean; |
| 395 |
virtual; |
| 396 |
procedure SetSpanningThreshold( Value : Int64 ); |
| 397 |
virtual; |
| 398 |
|
| 399 |
protected {properties and events} |
| 400 |
property InStream : TStream |
| 401 |
read FInStream; |
| 402 |
|
| 403 |
public {methods} |
| 404 |
constructor Create(const FileName : string; Mode : Word); |
| 405 |
virtual; |
| 406 |
constructor CreateFromStream(aStream : TStream; const aArchiveName : string); |
| 407 |
virtual; |
| 408 |
destructor Destroy; |
| 409 |
override; |
| 410 |
procedure Add(aItem : TAbArchiveItem); |
| 411 |
virtual; |
| 412 |
procedure AddEntry(const Path : String; const ArchiveDirectory : String); |
| 413 |
procedure AddFiles(const FileMask : string; SearchAttr : Integer); |
| 414 |
procedure AddFilesEx(const FileMask, ExclusionMask : string; |
| 415 |
SearchAttr : Integer); |
| 416 |
procedure AddFromStream(const NewName : string; aStream : TStream); |
| 417 |
procedure ClearTags; |
| 418 |
procedure Delete(aItem : TAbArchiveItem); |
| 419 |
procedure DeleteAt(Index : Integer); |
| 420 |
procedure DeleteFiles(const FileMask : string); |
| 421 |
procedure DeleteFilesEx(const FileMask, ExclusionMask : string); |
| 422 |
procedure DeleteTaggedItems; |
| 423 |
procedure Extract(aItem : TAbArchiveItem; const NewName : string); |
| 424 |
procedure ExtractAt(Index : Integer; const NewName : string); |
| 425 |
procedure ExtractFiles(const FileMask : string); |
| 426 |
procedure ExtractFilesEx(const FileMask, ExclusionMask : string); |
| 427 |
procedure ExtractTaggedItems; |
| 428 |
procedure ExtractToStream(const aFileName : string; aStream : TStream); |
| 429 |
function FindFile(const aFileName : string): Integer; |
| 430 |
function FindItem(aItem : TAbArchiveItem): Integer; |
| 431 |
procedure Freshen(aItem : TAbArchiveItem); |
| 432 |
procedure FreshenFiles(const FileMask : string); |
| 433 |
procedure FreshenFilesEx(const FileMask, ExclusionMask : string); |
| 434 |
procedure FreshenTaggedItems; |
| 435 |
procedure Load; virtual; |
| 436 |
procedure Move(aItem : TAbArchiveItem; const NewStoredPath : string); |
| 437 |
virtual; |
| 438 |
procedure Replace(aItem : TAbArchiveItem); |
| 439 |
procedure Save; |
| 440 |
virtual; |
| 441 |
procedure TagItems(const FileMask : string); |
| 442 |
procedure TestTaggedItems; |
| 443 |
procedure TestAt(Index : Integer); |
| 444 |
procedure UnTagItems(const FileMask : string); |
| 445 |
procedure VerifyItem(Item: TAbArchiveItem); |
| 446 |
|
| 447 |
|
| 448 |
procedure DoDeflateProgress(aPercentDone : integer); |
| 449 |
virtual; |
| 450 |
procedure DoInflateProgress(aPercentDone : integer); |
| 451 |
virtual; |
| 452 |
procedure DoSpanningMediaRequest(Sender : TObject; ImageNumber : Integer; |
| 453 |
var ImageName : string; var Abort : Boolean); virtual; |
| 454 |
public {properties} |
| 455 |
property OnProgress : TAbProgressEvent |
| 456 |
read FOnProgress write FOnProgress; |
| 457 |
property ArchiveName : string |
| 458 |
read FArchiveName; |
| 459 |
property AutoSave : Boolean |
| 460 |
read FAutoSave |
| 461 |
write FAutoSave; |
| 462 |
property BaseDirectory : string |
| 463 |
read FBaseDirectory |
| 464 |
write SetBaseDirectory; |
| 465 |
property Count : Integer |
| 466 |
read GetItemCount; |
| 467 |
property DOSMode : Boolean |
| 468 |
read FDOSMode |
| 469 |
write FDOSMode; |
| 470 |
property ExtractOptions : TAbExtractOptions |
| 471 |
read FExtractOptions |
| 472 |
write FExtractOptions; |
| 473 |
property IsDirty : Boolean |
| 474 |
read FIsDirty |
| 475 |
write FIsDirty; |
| 476 |
property ItemList : TAbArchiveList |
| 477 |
read FItemList; |
| 478 |
property LogFile : string |
| 479 |
read FLogFile |
| 480 |
write SetLogFile; |
| 481 |
property Logging : Boolean |
| 482 |
read FLogging |
| 483 |
write SetLogging; |
| 484 |
property Mode : Word |
| 485 |
read FMode; |
| 486 |
property Spanned : Boolean |
| 487 |
read FSpanned; |
| 488 |
property SpanningThreshold : Int64 |
| 489 |
read GetSpanningThreshold |
| 490 |
write SetSpanningThreshold; |
| 491 |
property Status : TAbArchiveStatus |
| 492 |
read FStatus; |
| 493 |
property StoreOptions : TAbStoreOptions |
| 494 |
read FStoreOptions |
| 495 |
write FStoreOptions; |
| 496 |
property SupportsEmptyFolders : Boolean |
| 497 |
read GetSupportsEmptyFolders; |
| 498 |
property TempDirectory : string |
| 499 |
read FTempDir |
| 500 |
write FTempDir; |
| 501 |
property CompressionLevel: IntPtr |
| 502 |
read FCompressionLevel |
| 503 |
write FCompressionLevel; |
| 504 |
property CompressionMethod: IntPtr |
| 505 |
read FCompressionMethod |
| 506 |
write FCompressionMethod; |
| 507 |
|
| 508 |
public {events} |
| 509 |
property OnProcessItemFailure : TAbArchiveItemFailureEvent |
| 510 |
read FOnProcessItemFailure |
| 511 |
write FOnProcessItemFailure; |
| 512 |
property OnArchiveProgress : TAbArchiveProgressEvent |
| 513 |
read FOnArchiveProgress |
| 514 |
write FOnArchiveProgress; |
| 515 |
property OnArchiveSaveProgress : TAbArchiveProgressEvent |
| 516 |
read FOnArchiveSaveProgress |
| 517 |
write FOnArchiveSaveProgress; |
| 518 |
property OnArchiveItemProgress : TAbArchiveItemProgressEvent |
| 519 |
read FOnArchiveItemProgress |
| 520 |
write FOnArchiveItemProgress; |
| 521 |
property OnConfirmProcessItem : TAbArchiveItemConfirmEvent |
| 522 |
read FOnConfirmProcessItem |
| 523 |
write FOnConfirmProcessItem; |
| 524 |
property OnConfirmOverwrite : TAbConfirmOverwriteEvent |
| 525 |
read FOnConfirmOverwrite |
| 526 |
write FOnConfirmOverwrite; |
| 527 |
property OnConfirmSave : TAbArchiveConfirmEvent |
| 528 |
read FOnConfirmSave |
| 529 |
write FOnConfirmSave; |
| 530 |
property OnLoad : TAbArchiveEvent |
| 531 |
read FOnLoad |
| 532 |
write FOnLoad; |
| 533 |
property OnRequestImage : TAbRequestImageEvent |
| 534 |
read FOnRequestImage |
| 535 |
write FOnRequestImage; |
| 536 |
property OnSave : TAbArchiveEvent |
| 537 |
read FOnSave |
| 538 |
write FOnSave; |
| 539 |
end; |
| 540 |
|
| 541 |
|
| 542 |
{ ===== TAbExtraField ======================================================= } |
| 543 |
type |
| 544 |
PAbExtraSubField = ^TAbExtraSubField; |
| 545 |
TAbExtraSubField = packed record |
| 546 |
ID : Word; |
| 547 |
Len : Word; |
| 548 |
Data : record end; |
| 549 |
end; |
| 550 |
|
| 551 |
TAbExtraField = class |
| 552 |
private {fields} |
| 553 |
FBuffer : TByteDynArray; |
| 554 |
private {methods} |
| 555 |
procedure DeleteField(aSubField : PAbExtraSubField); |
| 556 |
function FindField(aID : Word; out aSubField : PAbExtraSubField) : Boolean; |
| 557 |
function FindNext(var aCurField : PAbExtraSubField) : Boolean; |
| 558 |
function GetCount : Integer; |
| 559 |
function GetID(aIndex : Integer): Word; |
| 560 |
procedure SetBuffer(const aValue : TByteDynArray); |
| 561 |
protected {methods} |
| 562 |
procedure Changed; virtual; |
| 563 |
public {methods} |
| 564 |
procedure Assign(aSource : TAbExtraField); |
| 565 |
procedure Clear; |
| 566 |
procedure CloneFrom(aSource : TAbExtraField; aID : Word); |
| 567 |
procedure Delete(aID : Word); |
| 568 |
function Get(aID : Word; out aData : Pointer; out aDataSize : Word) : Boolean; |
| 569 |
function GetStream(aID : Word; out aStream : TStream): Boolean; |
| 570 |
function Has(aID : Word): Boolean; |
| 571 |
procedure LoadFromStream(aStream : TStream; aSize : Word); |
| 572 |
procedure Put(aID : Word; const aData; aDataSize : Word); |
| 573 |
public {properties} |
| 574 |
property Count : Integer |
| 575 |
read GetCount; |
| 576 |
property Buffer : TByteDynArray |
| 577 |
read FBuffer |
| 578 |
write SetBuffer; |
| 579 |
property IDs[aIndex : Integer]: Word |
| 580 |
read GetID; |
| 581 |
end; |
| 582 |
|
| 583 |
|
| 584 |
const |
| 585 |
AbDefAutoSave = False; |
| 586 |
AbDefExtractOptions = [eoCreateDirs]; |
| 587 |
AbDefStoreOptions = [soStripDrive, soRemoveDots]; |
| 588 |
AbBufferSize = 32768; |
| 589 |
AbLastDisk = -1; |
| 590 |
AbLastImage = -1; |
| 591 |
|
| 592 |
implementation |
| 593 |
|
| 594 |
{.$R ABRES.R32} |
| 595 |
|
| 596 |
uses |
| 597 |
RTLConsts, |
| 598 |
SysUtils, |
| 599 |
AbExcept, |
| 600 |
AbDfBase, |
| 601 |
AbConst, |
| 602 |
AbResString, |
| 603 |
DCOSUtils, |
| 604 |
DCClassesUtf8; |
| 605 |
|
| 606 |
|
| 607 |
{ TAbArchiveItem implementation ============================================ } |
| 608 |
{ TAbArchiveItem } |
| 609 |
constructor TAbArchiveItem.Create; |
| 610 |
begin |
| 611 |
inherited Create; |
| 612 |
FCompressedSize := 0; |
| 613 |
FUncompressedSize := 0; |
| 614 |
FFileName := ''; |
| 615 |
FAction := aaNone; |
| 616 |
FLastModFileTime := 0; |
| 617 |
FLastModFileDate := 0; |
| 618 |
end; |
| 619 |
{ -------------------------------------------------------------------------- } |
| 620 |
destructor TAbArchiveItem.Destroy; |
| 621 |
begin |
| 622 |
inherited Destroy; |
| 623 |
end; |
| 624 |
{ -------------------------------------------------------------------------- } |
| 625 |
function TAbArchiveItem.GetCompressedSize : Int64; |
| 626 |
begin |
| 627 |
Result := FCompressedSize; |
| 628 |
end; |
| 629 |
{ -------------------------------------------------------------------------- } |
| 630 |
function TAbArchiveItem.GetCRC32 : LongInt; |
| 631 |
begin |
| 632 |
Result := FCRC32; |
| 633 |
end; |
| 634 |
{ -------------------------------------------------------------------------- } |
| 635 |
function TAbArchiveItem.GetDiskPath : string; |
| 636 |
begin |
| 637 |
Result := ExtractFilePath(DiskFileName); |
| 638 |
end; |
| 639 |
{ -------------------------------------------------------------------------- } |
| 640 |
function TAbArchiveItem.GetExternalFileAttributes : LongWord; |
| 641 |
begin |
| 642 |
Result := FExternalFileAttributes; |
| 643 |
end; |
| 644 |
{ -------------------------------------------------------------------------- } |
| 645 |
function TAbArchiveItem.GetFileName : string; |
| 646 |
begin |
| 647 |
Result := FFileName; |
| 648 |
end; |
| 649 |
{ -------------------------------------------------------------------------- } |
| 650 |
function TAbArchiveItem.GetIsDirectory: Boolean; |
| 651 |
begin |
| 652 |
Result := False; |
| 653 |
end; |
| 654 |
{ -------------------------------------------------------------------------- } |
| 655 |
function TAbArchiveItem.GetIsEncrypted : Boolean; |
| 656 |
begin |
| 657 |
Result := FIsEncrypted; |
| 658 |
end; |
| 659 |
{ -------------------------------------------------------------------------- } |
| 660 |
function TAbArchiveItem.GetLastModFileTime : Word; |
| 661 |
begin |
| 662 |
Result := FLastModFileTime; |
| 663 |
end; |
| 664 |
{ -------------------------------------------------------------------------- } |
| 665 |
function TAbArchiveItem.GetLastModFileDate : Word; |
| 666 |
begin |
| 667 |
Result := FLastModFileDate; |
| 668 |
end; |
| 669 |
{ -------------------------------------------------------------------------- } |
| 670 |
function TAbArchiveItem.GetNativeFileAttributes : LongInt; |
| 671 |
begin |
| 672 |
{$IFDEF MSWINDOWS} |
| 673 |
if IsDirectory then |
| 674 |
Result := faDirectory |
| 675 |
else |
| 676 |
Result := 0; |
| 677 |
{$ENDIF} |
| 678 |
{$IFDEF UNIX} |
| 679 |
if IsDirectory then |
| 680 |
Result := AB_FPERMISSION_GENERIC or AB_FPERMISSION_OWNEREXECUTE |
| 681 |
else |
| 682 |
Result := AB_FPERMISSION_GENERIC; |
| 683 |
{$ENDIF} |
| 684 |
end; |
| 685 |
{ -------------------------------------------------------------------------- } |
| 686 |
function TAbArchiveItem.GetNativeLastModFileTime : Longint; |
| 687 |
begin |
| 688 |
LongRec(Result).Hi := LastModFileDate; |
| 689 |
LongRec(Result).Lo := LastModFileTime; |
| 690 |
end; |
| 691 |
{ -------------------------------------------------------------------------- } |
| 692 |
function TAbArchiveItem.GetStoredPath : string; |
| 693 |
begin |
| 694 |
Result := ExtractFilePath(DiskFileName); |
| 695 |
end; |
| 696 |
{ -------------------------------------------------------------------------- } |
| 697 |
function TAbArchiveItem.GetUnCompressedSize : Int64; |
| 698 |
begin |
| 699 |
Result := FUnCompressedSize; |
| 700 |
end; |
| 701 |
{ -------------------------------------------------------------------------- } |
| 702 |
function TAbArchiveItem.MatchesDiskName(const FileMask : string) : Boolean; |
| 703 |
var |
| 704 |
DiskName, Mask : string; |
| 705 |
begin |
| 706 |
DiskName := DiskFileName; |
| 707 |
AbUnfixName(DiskName); |
| 708 |
Mask := FileMask; |
| 709 |
AbUnfixName(Mask); |
| 710 |
Result := AbFileMatch(DiskName, Mask); |
| 711 |
end; |
| 712 |
{ -------------------------------------------------------------------------- } |
| 713 |
function TAbArchiveItem.MatchesStoredName(const FileMask : string) : Boolean; |
| 714 |
var |
| 715 |
Value : string; |
| 716 |
Drive, Dir, Name : string; |
| 717 |
begin |
| 718 |
Value := FileMask; |
| 719 |
AbUnfixName(Value); |
| 720 |
AbParseFileName(Value, Drive, Dir, Name); |
| 721 |
Value := Dir + Name; |
| 722 |
Name := FileName; |
| 723 |
AbUnfixName(Name); |
| 724 |
if IsDirectory then |
| 725 |
Name := ExcludeTrailingPathDelimiter(Name); |
| 726 |
Result := AbFileMatch(Name, Value); |
| 727 |
end; |
| 728 |
{ -------------------------------------------------------------------------- } |
| 729 |
function TAbArchiveItem.MatchesStoredNameEx(const FileMask : string) : Boolean; |
| 730 |
var |
| 731 |
I, J: Integer; |
| 732 |
MaskPart: string; |
| 733 |
begin |
| 734 |
Result := True; |
| 735 |
I := 1; |
| 736 |
while I <= Length(FileMask) do begin |
| 737 |
J := I; |
| 738 |
while (I <= Length(FileMask)) and (FileMask[I] <> PathSep {';'}) do Inc(I); |
| 739 |
MaskPart := Trim(Copy(FileMask, J, I - J)); |
| 740 |
if (I <= Length(FileMask)) and (FileMask[I] = PathSep {';'}) then Inc(I); |
| 741 |
|
| 742 |
if MatchesStoredName(MaskPart) then Exit; |
| 743 |
end; |
| 744 |
Result := False; |
| 745 |
end; |
| 746 |
{ -------------------------------------------------------------------------- } |
| 747 |
procedure TAbArchiveItem.SetCompressedSize(const Value : Int64); |
| 748 |
begin |
| 749 |
FCompressedSize := Value; |
| 750 |
end; |
| 751 |
{ -------------------------------------------------------------------------- } |
| 752 |
procedure TAbArchiveItem.SetCRC32(const Value : LongInt); |
| 753 |
begin |
| 754 |
FCRC32 := Value; |
| 755 |
end; |
| 756 |
{ -------------------------------------------------------------------------- } |
| 757 |
procedure TAbArchiveItem.SetExternalFileAttributes( Value : LongWord ); |
| 758 |
begin |
| 759 |
FExternalFileAttributes := Value; |
| 760 |
end; |
| 761 |
{ -------------------------------------------------------------------------- } |
| 762 |
procedure TAbArchiveItem.SetFileName(const Value : string); |
| 763 |
begin |
| 764 |
FFileName := Value; |
| 765 |
end; |
| 766 |
{ -------------------------------------------------------------------------- } |
| 767 |
procedure TAbArchiveItem.SetIsEncrypted(Value : Boolean); |
| 768 |
begin |
| 769 |
FIsEncrypted := Value; |
| 770 |
end; |
| 771 |
{ -------------------------------------------------------------------------- } |
| 772 |
procedure TAbArchiveItem.SetLastModFileDate(const Value : Word); |
| 773 |
begin |
| 774 |
FLastModFileDate := Value; |
| 775 |
end; |
| 776 |
{ -------------------------------------------------------------------------- } |
| 777 |
procedure TAbArchiveItem.SetLastModFileTime(const Value : Word); |
| 778 |
begin |
| 779 |
FLastModFileTime := Value; |
| 780 |
end; |
| 781 |
{ -------------------------------------------------------------------------- } |
| 782 |
procedure TAbArchiveItem.SetUnCompressedSize(const Value : Int64); |
| 783 |
begin |
| 784 |
FUnCompressedSize := Value; |
| 785 |
end; |
| 786 |
{ -------------------------------------------------------------------------- } |
| 787 |
function TAbArchiveItem.GetLastModTimeAsDateTime: TDateTime; |
| 788 |
begin |
| 789 |
Result := AbDosFileDateToDateTime(LastModFileDate, LastModFileTime); |
| 790 |
end; |
| 791 |
{ -------------------------------------------------------------------------- } |
| 792 |
procedure TAbArchiveItem.SetLastModTimeAsDateTime(const Value: TDateTime); |
| 793 |
var |
| 794 |
FileDate : Integer; |
| 795 |
begin |
| 796 |
FileDate := AbDateTimeToDosFileDate(Value); |
| 797 |
LastModFileTime := LongRec(FileDate).Lo; |
| 798 |
LastModFileDate := LongRec(FileDate).Hi; |
| 799 |
end; |
| 800 |
{ -------------------------------------------------------------------------- } |
| 801 |
|
| 802 |
{ TAbArchiveEnumeratorList implementation ================================== } |
| 803 |
{ TAbArchiveEnumeratorList } |
| 804 |
constructor TAbArchiveListEnumerator.Create(aList: TAbArchiveList); |
| 805 |
begin |
| 806 |
inherited Create; |
| 807 |
FIndex := -1; |
| 808 |
FList := aList; |
| 809 |
end; |
| 810 |
{ -------------------------------------------------------------------------- } |
| 811 |
function TAbArchiveListEnumerator.GetCurrent: TAbArchiveItem; |
| 812 |
begin |
| 813 |
Result := FList[FIndex]; |
| 814 |
end; |
| 815 |
{ -------------------------------------------------------------------------- } |
| 816 |
function TAbArchiveListEnumerator.MoveNext: Boolean; |
| 817 |
begin |
| 818 |
Result := FIndex < FList.Count - 1; |
| 819 |
if Result then |
| 820 |
Inc(FIndex); |
| 821 |
end; |
| 822 |
{ -------------------------------------------------------------------------- } |
| 823 |
|
| 824 |
{ TAbArchiveList implementation ============================================ } |
| 825 |
|
| 826 |
{ TAbArchiveList } |
| 827 |
constructor TAbArchiveList.Create(AOwnsItems: Boolean); |
| 828 |
begin |
| 829 |
inherited Create; |
| 830 |
FList := TList.Create; |
| 831 |
FOwnsItems := AOwnsItems; |
| 832 |
end; |
| 833 |
{ -------------------------------------------------------------------------- } |
| 834 |
destructor TAbArchiveList.Destroy; |
| 835 |
begin |
| 836 |
Clear; |
| 837 |
FList.Free; |
| 838 |
inherited Destroy; |
| 839 |
end; |
| 840 |
{ -------------------------------------------------------------------------- } |
| 841 |
function TAbArchiveList.Add(Item : Pointer) : Integer; |
| 842 |
var |
| 843 |
H : LongInt; |
| 844 |
begin |
| 845 |
if FOwnsItems then begin |
| 846 |
H := GenerateHash(TAbArchiveItem(Item).FileName); |
| 847 |
TAbArchiveItem(Item).NextItem := HashTable[H]; |
| 848 |
HashTable[H] := TAbArchiveItem(Item); |
| 849 |
end; |
| 850 |
Result := FList.Add(Item); |
| 851 |
end; |
| 852 |
{ -------------------------------------------------------------------------- } |
| 853 |
procedure TAbArchiveList.Clear; |
| 854 |
var |
| 855 |
i : Integer; |
| 856 |
begin |
| 857 |
if FOwnsItems then |
| 858 |
for i := 0 to Count - 1 do |
| 859 |
TObject(FList[i]).Free; |
| 860 |
FList.Clear; |
| 861 |
FillChar(HashTable, SizeOf(HashTable), #0); |
| 862 |
end; |
| 863 |
{ -------------------------------------------------------------------------- } |
| 864 |
procedure TAbArchiveList.Delete(Index: Integer); |
| 865 |
var |
| 866 |
Look : TAbArchiveItem; |
| 867 |
Last : Pointer; |
| 868 |
FN : string; |
| 869 |
begin |
| 870 |
if FOwnsItems then begin |
| 871 |
FN := TAbArchiveItem(FList[Index]).FileName; |
| 872 |
Last := @HashTable[GenerateHash(FN)]; |
| 873 |
Look := TAbArchiveItem(Last^); |
| 874 |
while Look <> nil do begin |
| 875 |
if CompareText(Look.FileName, FN) = 0 then begin |
| 876 |
Move(Look.NextItem, Last^, SizeOf(Pointer)); |
| 877 |
Break; |
| 878 |
end; |
| 879 |
Last := @Look.NextItem; |
| 880 |
Look := TAbArchiveItem(Last^); |
| 881 |
end; |
| 882 |
TObject(FList[Index]).Free; |
| 883 |
end; |
| 884 |
FList.Delete(Index); |
| 885 |
end; |
| 886 |
{ -------------------------------------------------------------------------- } |
| 887 |
function TAbArchiveList.Find(const FN : string) : Integer; |
| 888 |
var |
| 889 |
Look : TAbArchiveItem; |
| 890 |
I : Integer; |
| 891 |
begin |
| 892 |
if FOwnsItems then begin |
| 893 |
Look := HashTable[GenerateHash(FN)]; |
| 894 |
while Look <> nil do begin |
| 895 |
if CompareText(Look.FileName, FN) = 0 then begin |
| 896 |
Result := FList.IndexOf(Look); |
| 897 |
Exit; |
| 898 |
end; |
| 899 |
Look := Look.NextItem; |
| 900 |
end; |
| 901 |
end |
| 902 |
else begin |
| 903 |
for I := 0 to FList.Count - 1 do |
| 904 |
if CompareText(Items[I].FileName, FN) = 0 then begin |
| 905 |
Result := I; |
| 906 |
Exit; |
| 907 |
end; |
| 908 |
end; |
| 909 |
Result := -1; |
| 910 |
end; |
| 911 |
{ -------------------------------------------------------------------------- } |
| 912 |
{$IFOPT Q+}{$DEFINE OVERFLOW_CHECKS_ON}{$Q-}{$ENDIF} |
| 913 |
function TAbArchiveList.GenerateHash(const S : string) : LongInt; |
| 914 |
var |
| 915 |
G : LongInt; |
| 916 |
I : Integer; |
| 917 |
U : string; |
| 918 |
begin |
| 919 |
Result := 0; |
| 920 |
U := AnsiUpperCase(S); |
| 921 |
for I := 1 to Length(U) do begin |
| 922 |
Result := (Result shl 4) + Ord(U[I]); |
| 923 |
G := LongInt(Result and $F0000000); |
| 924 |
if (G <> 0) then |
| 925 |
Result := Result xor (G shr 24); |
| 926 |
Result := Result and (not G); |
| 927 |
end; |
| 928 |
Result := Result mod 1021; |
| 929 |
end; |
| 930 |
{$IFDEF OVERFLOW_CHECKS_ON}{$Q+}{$ENDIF} |
| 931 |
{ -------------------------------------------------------------------------- } |
| 932 |
function TAbArchiveList.Get(Index : Integer): TAbArchiveItem; |
| 933 |
begin |
| 934 |
Result := TAbArchiveItem(FList[Index]); |
| 935 |
end; |
| 936 |
{ -------------------------------------------------------------------------- } |
| 937 |
function TAbArchiveList.GetCount : Integer; |
| 938 |
begin |
| 939 |
Result := FList.Count; |
| 940 |
end; |
| 941 |
{ -------------------------------------------------------------------------- } |
| 942 |
function TAbArchiveList.GetEnumerator: TAbArchiveListEnumerator; |
| 943 |
begin |
| 944 |
Result := TAbArchiveListEnumerator.Create(Self); |
| 945 |
end; |
| 946 |
{ -------------------------------------------------------------------------- } |
| 947 |
function TAbArchiveList.IsActiveDupe(const FN : string) : Boolean; |
| 948 |
var |
| 949 |
Look : TAbArchiveItem; |
| 950 |
I : Integer; |
| 951 |
begin |
| 952 |
if FOwnsItems then begin |
| 953 |
Look := HashTable[GenerateHash(FN)]; |
| 954 |
while Look <> nil do begin |
| 955 |
if (CompareText(Look.FileName, FN) = 0) and |
| 956 |
(Look.Action <> aaDelete) then begin |
| 957 |
Result := True; |
| 958 |
Exit; |
| 959 |
end; |
| 960 |
Look := Look.NextItem; |
| 961 |
end; |
| 962 |
end |
| 963 |
else begin |
| 964 |
for I := 0 to Count - 1 do |
| 965 |
if (CompareText(Items[I].FileName, FN) = 0) and |
| 966 |
(Items[I].Action <> aaDelete) then begin |
| 967 |
Result := True; |
| 968 |
Exit; |
| 969 |
end; |
| 970 |
end; |
| 971 |
Result := False; |
| 972 |
end; |
| 973 |
{ -------------------------------------------------------------------------- } |
| 974 |
procedure TAbArchiveList.Put(Index : Integer; Item : TAbArchiveItem); |
| 975 |
var |
| 976 |
H : LongInt; |
| 977 |
Look : TAbArchiveItem; |
| 978 |
Last : Pointer; |
| 979 |
FN : string; |
| 980 |
begin |
| 981 |
if FOwnsItems then begin |
| 982 |
FN := TAbArchiveItem(FList[Index]).FileName; |
| 983 |
Last := @HashTable[GenerateHash(FN)]; |
| 984 |
Look := TAbArchiveItem(Last^); |
| 985 |
{ Delete old index } |
| 986 |
while Look <> nil do begin |
| 987 |
if CompareText(Look.FileName, FN) = 0 then begin |
| 988 |
Move(Look.NextItem, Last^, SizeOf(Pointer)); |
| 989 |
Break; |
| 990 |
end; |
| 991 |
Last := @Look.NextItem; |
| 992 |
Look := TAbArchiveItem(Last^); |
| 993 |
end; |
| 994 |
{ Free old instance } |
| 995 |
TObject(FList[Index]).Free; |
| 996 |
{ Add new index } |
| 997 |
H := GenerateHash(TAbArchiveItem(Item).FileName); |
| 998 |
TAbArchiveItem(Item).NextItem := HashTable[H]; |
| 999 |
HashTable[H] := TAbArchiveItem(Item); |
| 1000 |
end; |
| 1001 |
{ Replace pointer } |
| 1002 |
FList[Index] := Item; |
| 1003 |
end; |
| 1004 |
|
| 1005 |
|
| 1006 |
{ TAbArchive implementation ================================================ } |
| 1007 |
{ TAbArchive } |
| 1008 |
constructor TAbArchive.CreateInit; |
| 1009 |
begin |
| 1010 |
inherited Create; |
| 1011 |
FIsDirty := False; |
| 1012 |
FAutoSave := False; |
| 1013 |
FItemList := TAbArchiveList.Create(True); |
| 1014 |
StoreOptions := []; |
| 1015 |
ExtractOptions := []; |
| 1016 |
FStatus := asIdle; |
| 1017 |
FOnProgress := DoProgress; |
| 1018 |
// BaseDirectory := ExtractFilePath(ParamStr(0)); |
| 1019 |
end; |
| 1020 |
{ -------------------------------------------------------------------------- } |
| 1021 |
constructor TAbArchive.Create(const FileName : string; Mode : Word); |
| 1022 |
{create an archive by opening a filestream on filename with the given mode} |
| 1023 |
begin |
| 1024 |
FOwnsStream := True; |
| 1025 |
CreateFromStream(TFileStreamEx.Create(FileName, Mode), FileName); |
| 1026 |
FMode := Mode; |
| 1027 |
end; |
| 1028 |
{ -------------------------------------------------------------------------- } |
| 1029 |
constructor TAbArchive.CreateFromStream(aStream : TStream; const aArchiveName : string); |
| 1030 |
{create an archive based on an existing stream} |
| 1031 |
begin |
| 1032 |
CreateInit; |
| 1033 |
FArchiveName := aArchiveName; |
| 1034 |
FStream := aStream; |
| 1035 |
end; |
| 1036 |
{ -------------------------------------------------------------------------- } |
| 1037 |
destructor TAbArchive.Destroy; |
| 1038 |
begin |
| 1039 |
FItemList.Free; |
| 1040 |
if FOwnsStream then |
| 1041 |
FStream.Free; |
| 1042 |
FLogStream.Free; |
| 1043 |
inherited Destroy; |
| 1044 |
end; |
| 1045 |
{ -------------------------------------------------------------------------- } |
| 1046 |
procedure TAbArchive.Add(aItem : TAbArchiveItem); |
| 1047 |
var |
| 1048 |
Confirm, ItemAdded : Boolean; |
| 1049 |
begin |
| 1050 |
ItemAdded := False; |
| 1051 |
try |
| 1052 |
CheckValid; |
| 1053 |
if FItemList.IsActiveDupe(aItem.FileName) then begin |
| 1054 |
if (soFreshen in StoreOptions) then |
| 1055 |
Freshen(aItem) |
| 1056 |
else if (soReplace in StoreOptions) then |
| 1057 |
Replace(aItem) |
| 1058 |
else |
| 1059 |
DoProcessItemFailure(aItem, ptAdd, ecAbbrevia, AbDuplicateName); |
| 1060 |
Exit; |
| 1061 |
end; |
| 1062 |
DoConfirmProcessItem(aItem, ptAdd, Confirm); |
| 1063 |
if not Confirm then |
| 1064 |
Exit; |
| 1065 |
aItem.Action := aaAdd; |
| 1066 |
FItemList.Add(aItem); |
| 1067 |
ItemAdded := True; |
| 1068 |
FIsDirty := True; |
| 1069 |
if AutoSave then |
| 1070 |
Save; |
| 1071 |
finally |
| 1072 |
if not ItemAdded then |
| 1073 |
aItem.Free; |
| 1074 |
end; |
| 1075 |
end; |
| 1076 |
{ -------------------------------------------------------------------------- } |
| 1077 |
procedure TAbArchive.AddEntry(const Path : String; const ArchiveDirectory : String); |
| 1078 |
var |
| 1079 |
Item : TAbArchiveItem; |
| 1080 |
FullSourceFileName, FullArchiveFileName : String; |
| 1081 |
begin |
| 1082 |
MakeFullNames(Path, ArchiveDirectory, FullSourceFileName, FullArchiveFileName); |
| 1083 |
|
| 1084 |
if (FullSourceFileName <> FArchiveName) then begin |
| 1085 |
Item := CreateItem(Path, ArchiveDirectory); |
| 1086 |
Add(Item); |
| 1087 |
end; |
| 1088 |
end; |
| 1089 |
{ -------------------------------------------------------------------------- } |
| 1090 |
procedure TAbArchive.AddFiles(const FileMask : string; SearchAttr : Integer); |
| 1091 |
{Add files to the archive where the disk filespec matches} |
| 1092 |
begin |
| 1093 |
AddFilesEx(FileMask, '', SearchAttr); |
| 1094 |
end; |
| 1095 |
{ -------------------------------------------------------------------------- } |
| 1096 |
procedure TAbArchive.AddFilesEx(const FileMask, ExclusionMask : string; |
| 1097 |
SearchAttr : Integer); |
| 1098 |
{Add files matching Filemask except those matching ExclusionMask} |
| 1099 |
var |
| 1100 |
PathType : TAbPathType; |
| 1101 |
IsWild : Boolean; |
| 1102 |
SaveDir : string; |
| 1103 |
Mask : string; |
| 1104 |
MaskF : string; |
| 1105 |
|
| 1106 |
procedure CreateItems(Wild, Recursing : Boolean); |
| 1107 |
var |
| 1108 |
i : Integer; |
| 1109 |
Files : TStrings; |
| 1110 |
FilterList : TStringList; |
| 1111 |
Item : TAbArchiveItem; |
| 1112 |
begin |
| 1113 |
FilterList := TStringList.Create; |
| 1114 |
try |
| 1115 |
if (MaskF <> '') then |
| 1116 |
AbFindFilesEx(MaskF, SearchAttr, FilterList, Recursing); |
| 1117 |
|
| 1118 |
Files := TStringList.Create; |
| 1119 |
try |
| 1120 |
|
| 1121 |
AbFindFilesEx(Mask, SearchAttr, Files, Recursing); |
| 1122 |
if (Files.Count > 0) then |
| 1123 |
for i := 0 to pred(Files.Count) do |
| 1124 |
if FilterList.IndexOf(Files[i]) < 0 then |
| 1125 |
if not Wild then begin |
| 1126 |
if (Files[i] <> FArchiveName) then begin |
| 1127 |
Item := CreateItem(Files[i]); |
| 1128 |
Add(Item); |
| 1129 |
end; |
| 1130 |
end else begin |
| 1131 |
if (AbAddBackSlash(FBaseDirectory) + Files[i]) <> FArchiveName |
| 1132 |
then begin |
| 1133 |
Item := CreateItem(Files[i]); |
| 1134 |
Add(Item); |
| 1135 |
end; |
| 1136 |
end; |
| 1137 |
finally |
| 1138 |
Files.Free; |
| 1139 |
end; |
| 1140 |
|
| 1141 |
finally |
| 1142 |
FilterList.Free; |
| 1143 |
end; |
| 1144 |
end; |
| 1145 |
|
| 1146 |
begin |
| 1147 |
if not SupportsEmptyFolders then |
| 1148 |
SearchAttr := SearchAttr and not faDirectory; |
| 1149 |
|
| 1150 |
CheckValid; |
| 1151 |
IsWild := (Pos('*', FileMask) > 0) or (Pos('?', FileMask) > 0); |
| 1152 |
PathType := AbGetPathType(FileMask); |
| 1153 |
|
| 1154 |
Mask := FileMask; |
| 1155 |
AbUnfixName(Mask); |
| 1156 |
MaskF := ExclusionMask; |
| 1157 |
AbUnfixName(MaskF); |
| 1158 |
|
| 1159 |
case PathType of |
| 1160 |
ptNone, ptRelative : |
| 1161 |
begin |
| 1162 |
GetDir(0, SaveDir); |
| 1163 |
if BaseDirectory <> '' then |
| 1164 |
ChDir(BaseDirectory); |
| 1165 |
try |
| 1166 |
CreateItems(IsWild, soRecurse in StoreOptions); |
| 1167 |
finally |
| 1168 |
if BaseDirectory <> '' then |
| 1169 |
ChDir(SaveDir); |
| 1170 |
end; |
| 1171 |
end; |
| 1172 |
ptAbsolute : |
| 1173 |
begin |
| 1174 |
CreateItems(IsWild, soRecurse in StoreOptions); |
| 1175 |
end; |
| 1176 |
end; |
| 1177 |
end; |
| 1178 |
{ -------------------------------------------------------------------------- } |
| 1179 |
procedure TAbArchive.AddFromStream(const NewName : string; aStream : TStream); |
| 1180 |
{Add an item to the archive directly from a TStream descendant} |
| 1181 |
var |
| 1182 |
Confirm : Boolean; |
| 1183 |
Item : TAbArchiveItem; |
| 1184 |
PT : TAbProcessType; |
| 1185 |
begin |
| 1186 |
Item := CreateItem(NewName); |
| 1187 |
CheckValid; |
| 1188 |
|
| 1189 |
PT := ptAdd; |
| 1190 |
if FItemList.IsActiveDupe(NewName) then begin |
| 1191 |
if ((soFreshen in StoreOptions) or (soReplace in StoreOptions)) then begin |
| 1192 |
Item.Free; |
| 1193 |
Item := FItemList[FItemList.Find(NewName)]; |
| 1194 |
PT := ptReplace; |
| 1195 |
end else begin |
| 1196 |
DoProcessItemFailure(Item, ptAdd, ecAbbrevia, AbDuplicateName); |
| 1197 |
Item.Free; |
| 1198 |
Exit; |
| 1199 |
end; |
| 1200 |
end; |
| 1201 |
DoConfirmProcessItem(Item, PT, Confirm); |
| 1202 |
|
| 1203 |
if not Confirm then |
| 1204 |
Exit; |
| 1205 |
|
| 1206 |
FInStream := aStream; |
| 1207 |
Item.Action := aaStreamAdd; |
| 1208 |
if (PT = ptAdd) then |
| 1209 |
FItemList.Add(Item); |
| 1210 |
FIsDirty := True; |
| 1211 |
Save; |
| 1212 |
FInStream := nil; |
| 1213 |
end; |
| 1214 |
{ -------------------------------------------------------------------------- } |
| 1215 |
procedure TAbArchive.CheckValid; |
| 1216 |
begin |
| 1217 |
if Status = asInvalid then |
| 1218 |
raise EAbNoArchive.Create; |
| 1219 |
end; |
| 1220 |
{ -------------------------------------------------------------------------- } |
| 1221 |
procedure TAbArchive.ClearTags; |
| 1222 |
{Clear all tags from the archive} |
| 1223 |
var |
| 1224 |
i : Integer; |
| 1225 |
begin |
| 1226 |
if Count > 0 then |
| 1227 |
for i := 0 to pred(Count) do |
| 1228 |
TAbArchiveItem(FItemList[i]).Tagged := False; |
| 1229 |
end; |
| 1230 |
{ -------------------------------------------------------------------------- } |
| 1231 |
function TAbArchive.ConfirmPath(Item : TAbArchiveItem; const NewName : string; |
| 1232 |
out UseName : string) : Boolean; |
| 1233 |
var |
| 1234 |
Path : string; |
| 1235 |
begin |
| 1236 |
if Item.IsDirectory and not (ExtractOptions >= [eoRestorePath, eoCreateDirs]) then begin |
| 1237 |
Result := False; |
| 1238 |
Exit; |
| 1239 |
end; |
| 1240 |
if (NewName = '') then begin |
| 1241 |
UseName := Item.FileName; |
| 1242 |
AbUnfixName(UseName); |
| 1243 |
if Item.IsDirectory then |
| 1244 |
UseName := ExcludeTrailingPathDelimiter(UseName); |
| 1245 |
if (not (eoRestorePath in ExtractOptions)) then |
| 1246 |
UseName := ExtractFileName(UseName); |
| 1247 |
end |
| 1248 |
else |
| 1249 |
UseName := NewName; |
| 1250 |
if (AbGetPathType(UseName) <> ptAbsolute) then |
| 1251 |
UseName := AbAddBackSlash(BaseDirectory) + UseName; |
| 1252 |
|
| 1253 |
Path := ExtractFileDir(UseName); |
| 1254 |
if (Path <> '') and not mbDirectoryExists(Path) then |
| 1255 |
if (eoCreateDirs in ExtractOptions) then |
| 1256 |
AbCreateDirectory(Path) |
| 1257 |
else |
| 1258 |
raise EAbNoSuchDirectory.Create; |
| 1259 |
|
| 1260 |
Result := True; |
| 1261 |
if not Item.IsDirectory and mbFileExists(UseName) then |
| 1262 |
DoConfirmOverwrite(UseName, Result); |
| 1263 |
end; |
| 1264 |
{ -------------------------------------------------------------------------- } |
| 1265 |
procedure TAbArchive.Delete(aItem : TAbArchiveItem); |
| 1266 |
{delete an item from the archive} |
| 1267 |
var |
| 1268 |
Index : Integer; |
| 1269 |
begin |
| 1270 |
CheckValid; |
| 1271 |
Index := FindItem(aItem); |
| 1272 |
if Index <> -1 then |
| 1273 |
DeleteAt(Index); |
| 1274 |
end; |
| 1275 |
{ -------------------------------------------------------------------------- } |
| 1276 |
procedure TAbArchive.DeleteAt(Index : Integer); |
| 1277 |
{delete the item at the index from the archive} |
| 1278 |
var |
| 1279 |
Confirm : Boolean; |
| 1280 |
begin |
| 1281 |
CheckValid; |
| 1282 |
SaveIfNeeded(FItemList[Index]); |
| 1283 |
DoConfirmProcessItem(FItemList[Index], ptDelete, Confirm); |
| 1284 |
if not Confirm then |
| 1285 |
Exit; |
| 1286 |
|
| 1287 |
TAbArchiveItem(FItemList[Index]).Action := aaDelete; |
| 1288 |
FIsDirty := True; |
| 1289 |
if AutoSave then |
| 1290 |
Save; |
| 1291 |
end; |
| 1292 |
{ -------------------------------------------------------------------------- } |
| 1293 |
procedure TAbArchive.DeleteFiles(const FileMask : string); |
| 1294 |
{delete all files from the archive that match the file mask} |
| 1295 |
begin |
| 1296 |
DeleteFilesEx(FileMask, ''); |
| 1297 |
end; |
| 1298 |
{ -------------------------------------------------------------------------- } |
| 1299 |
procedure TAbArchive.DeleteFilesEx(const FileMask, ExclusionMask : string); |
| 1300 |
{Delete files matching Filemask except those matching ExclusionMask} |
| 1301 |
var |
| 1302 |
i : Integer; |
| 1303 |
begin |
| 1304 |
CheckValid; |
| 1305 |
if Count > 0 then begin |
| 1306 |
for i := pred(Count) downto 0 do begin |
| 1307 |
with TAbArchiveItem(FItemList[i]) do |
| 1308 |
if MatchesStoredNameEx(FileMask) then |
| 1309 |
if not MatchesStoredNameEx(ExclusionMask) then |
| 1310 |
DeleteAt(i); |
| 1311 |
end; |
| 1312 |
end; |
| 1313 |
end; |
| 1314 |
{ -------------------------------------------------------------------------- } |
| 1315 |
procedure TAbArchive.DeleteTaggedItems; |
| 1316 |
{delete all tagged items from the archive} |
| 1317 |
var |
| 1318 |
i : Integer; |
| 1319 |
begin |
| 1320 |
CheckValid; |
| 1321 |
if Count > 0 then begin |
| 1322 |
for i := pred(Count) downto 0 do begin |
| 1323 |
with TAbArchiveItem(FItemList[i]) do |
| 1324 |
if Tagged then |
| 1325 |
DeleteAt(i); |
| 1326 |
end; |
| 1327 |
end; |
| 1328 |
end; |
| 1329 |
{ -------------------------------------------------------------------------- } |
| 1330 |
procedure TAbArchive.DoProcessItemFailure(Item : TAbArchiveItem; |
| 1331 |
ProcessType : TAbProcessType; ErrorClass : TAbErrorClass; |
| 1332 |
ErrorCode : Integer); |
| 1333 |
begin |
| 1334 |
if Assigned(FOnProcessItemFailure) then |
| 1335 |
FOnProcessItemFailure(Self, Item, ProcessType, ErrorClass, ErrorCode); |
| 1336 |
end; |
| 1337 |
{ -------------------------------------------------------------------------- } |
| 1338 |
procedure TAbArchive.DoArchiveSaveProgress(Progress : Byte; var Abort : Boolean); |
| 1339 |
begin |
| 1340 |
Abort := False; |
| 1341 |
if Assigned(FOnArchiveSaveProgress) then |
| 1342 |
FOnArchiveSaveProgress(Self, Progress, Abort); |
| 1343 |
end; |
| 1344 |
{ -------------------------------------------------------------------------- } |
| 1345 |
procedure TAbArchive.DoArchiveProgress(Progress : Byte; var Abort : Boolean); |
| 1346 |
begin |
| 1347 |
Abort := False; |
| 1348 |
if Assigned(FOnArchiveProgress) then |
| 1349 |
FOnArchiveProgress(Self, Progress, Abort); |
| 1350 |
end; |
| 1351 |
{ -------------------------------------------------------------------------- } |
| 1352 |
procedure TAbArchive.DoArchiveItemProgress(Item : TAbArchiveItem; |
| 1353 |
Progress : Byte; var Abort : Boolean); |
| 1354 |
begin |
| 1355 |
Abort := False; |
| 1356 |
if Assigned(FOnArchiveItemProgress) then |
| 1357 |
FOnArchiveItemProgress(Self, Item, Progress, Abort); |
| 1358 |
end; |
| 1359 |
{ -------------------------------------------------------------------------- } |
| 1360 |
procedure TAbArchive.DoConfirmOverwrite(var FileName : string; var Confirm : Boolean); |
| 1361 |
begin |
| 1362 |
Confirm := True; |
| 1363 |
if Assigned(FOnConfirmOverwrite) then |
| 1364 |
FOnConfirmOverwrite(FileName, Confirm); |
| 1365 |
end; |
| 1366 |
{ -------------------------------------------------------------------------- } |
| 1367 |
procedure TAbArchive.DoConfirmProcessItem(Item : TAbArchiveItem; |
| 1368 |
const ProcessType : TAbProcessType; var Confirm : Boolean); |
| 1369 |
const |
| 1370 |
ProcessTypeToLogType : array[TAbProcessType] of TAbLogType = |
| 1371 |
(ltAdd, ltDelete, ltExtract, ltFreshen, ltMove, ltReplace, ltFoundUnhandled); |
| 1372 |
begin |
| 1373 |
Confirm := True; |
| 1374 |
if Assigned(FOnConfirmProcessItem) then |
| 1375 |
FOnConfirmProcessItem(Self, Item, ProcessType, Confirm); |
| 1376 |
if (Confirm and FLogging) then |
| 1377 |
MakeLogEntry(Item.Filename, ProcessTypeToLogType[ProcessType]); |
| 1378 |
end; |
| 1379 |
{ -------------------------------------------------------------------------- } |
| 1380 |
procedure TAbArchive.DoConfirmSave(var Confirm : Boolean); |
| 1381 |
begin |
| 1382 |
Confirm := True; |
| 1383 |
if Assigned(FOnConfirmSave) then |
| 1384 |
FOnConfirmSave(Self, Confirm); |
| 1385 |
end; |
| 1386 |
{ -------------------------------------------------------------------------- } |
| 1387 |
procedure TAbArchive.DoDeflateProgress(aPercentDone: integer); |
| 1388 |
var |
| 1389 |
Abort : Boolean; |
| 1390 |
begin |
| 1391 |
DoProgress(aPercentDone, Abort); |
| 1392 |
if Abort then |
| 1393 |
raise EAbAbortProgress.Create(AbUserAbortS); |
| 1394 |
end; |
| 1395 |
{ -------------------------------------------------------------------------- } |
| 1396 |
procedure TAbArchive.DoInflateProgress(aPercentDone: integer); |
| 1397 |
var |
| 1398 |
Abort : Boolean; |
| 1399 |
begin |
| 1400 |
DoProgress(aPercentDone, Abort); |
| 1401 |
if Abort then |
| 1402 |
raise EAbAbortProgress.Create(AbUserAbortS); |
| 1403 |
end; |
| 1404 |
{ -------------------------------------------------------------------------- } |
| 1405 |
procedure TAbArchive.DoLoad; |
| 1406 |
begin |
| 1407 |
if Assigned(FOnLoad) then |
| 1408 |
FOnLoad(Self); |
| 1409 |
end; |
| 1410 |
{ -------------------------------------------------------------------------- } |
| 1411 |
procedure TAbArchive.DoProgress(Progress : Byte; var Abort : Boolean); |
| 1412 |
begin |
| 1413 |
Abort := False; |
| 1414 |
DoArchiveItemProgress(FCurrentItem, Progress, Abort); |
| 1415 |
end; |
| 1416 |
{ -------------------------------------------------------------------------- } |
| 1417 |
procedure TAbArchive.DoSave; |
| 1418 |
begin |
| 1419 |
if Assigned(FOnSave) then |
| 1420 |
FOnSave(Self); |
| 1421 |
end; |
| 1422 |
{ -------------------------------------------------------------------------- } |
| 1423 |
procedure TAbArchive.Extract(aItem : TAbArchiveItem; const NewName : string); |
| 1424 |
{extract an item from the archive} |
| 1425 |
var |
| 1426 |
Index : Integer; |
| 1427 |
begin |
| 1428 |
CheckValid; |
| 1429 |
Index := FindItem(aItem); |
| 1430 |
if Index <> -1 then |
| 1431 |
ExtractAt(Index, NewName); |
| 1432 |
end; |
| 1433 |
{ -------------------------------------------------------------------------- } |
| 1434 |
procedure TAbArchive.ExtractAt(Index : Integer; const NewName : string); |
| 1435 |
{extract an item from the archive at Index} |
| 1436 |
var |
| 1437 |
Confirm : Boolean; |
| 1438 |
ErrorClass : TAbErrorClass; |
| 1439 |
ErrorCode : Integer; |
| 1440 |
UseName : string; |
| 1441 |
begin |
| 1442 |
CheckValid; |
| 1443 |
SaveIfNeeded(FItemList[Index]); |
| 1444 |
DoConfirmProcessItem(FItemList[Index], ptExtract, Confirm); |
| 1445 |
if not Confirm then |
| 1446 |
Exit; |
| 1447 |
|
| 1448 |
if not ConfirmPath(FItemList[Index], NewName, UseName) then |
| 1449 |
Exit; |
| 1450 |
|
| 1451 |
try |
| 1452 |
FCurrentItem := FItemList[Index]; |
| 1453 |
ExtractItemAt(Index, UseName); |
| 1454 |
except |
| 1455 |
on E : Exception do begin |
| 1456 |
AbConvertException(E, ErrorClass, ErrorCode); |
| 1457 |
DoProcessItemFailure(FItemList[Index], ptExtract, ErrorClass, ErrorCode); |
| 1458 |
end; |
| 1459 |
end; |
| 1460 |
end; |
| 1461 |
{ -------------------------------------------------------------------------- } |
| 1462 |
procedure TAbArchive.ExtractToStream(const aFileName : string; |
| 1463 |
aStream : TStream); |
| 1464 |
{extract an item from the archive at Index directly to a stream} |
| 1465 |
var |
| 1466 |
Confirm : Boolean; |
| 1467 |
ErrorClass : TAbErrorClass; |
| 1468 |
ErrorCode : Integer; |
| 1469 |
Index : Integer; |
| 1470 |
begin |
| 1471 |
CheckValid; |
| 1472 |
Index := FindFile(aFileName); |
| 1473 |
if (Index = -1) then |
| 1474 |
Exit; |
| 1475 |
|
| 1476 |
SaveIfNeeded(FItemList[Index]); |
| 1477 |
|
| 1478 |
DoConfirmProcessItem(FItemList[Index], ptExtract, Confirm); |
| 1479 |
if not Confirm then |
| 1480 |
Exit; |
| 1481 |
FCurrentItem := FItemList[Index]; |
| 1482 |
try |
| 1483 |
ExtractItemToStreamAt(Index, aStream); |
| 1484 |
except |
| 1485 |
on E : Exception do begin |
| 1486 |
AbConvertException(E, ErrorClass, ErrorCode); |
| 1487 |
DoProcessItemFailure(FItemList[Index], ptExtract, ErrorClass, ErrorCode); |
| 1488 |
end; |
| 1489 |
end; |
| 1490 |
end; |
| 1491 |
{ -------------------------------------------------------------------------- } |
| 1492 |
procedure TAbArchive.ExtractFiles(const FileMask : string); |
| 1493 |
{extract all files from the archive that match the mask} |
| 1494 |
begin |
| 1495 |
ExtractFilesEx(FileMask, ''); |
| 1496 |
end; |
| 1497 |
{ -------------------------------------------------------------------------- } |
| 1498 |
procedure TAbArchive.ExtractFilesEx(const FileMask, ExclusionMask : string); |
| 1499 |
{Extract files matching Filemask except those matching ExclusionMask} |
| 1500 |
var |
| 1501 |
i : Integer; |
| 1502 |
Abort : Boolean; |
| 1503 |
begin |
| 1504 |
CheckValid; |
| 1505 |
if Count > 0 then begin |
| 1506 |
for i := 0 to pred(Count) do begin |
| 1507 |
with TAbArchiveItem(FItemList[i]) do |
| 1508 |
if MatchesStoredNameEx(FileMask) and |
| 1509 |
not MatchesStoredNameEx(ExclusionMask) and |
| 1510 |
((eoCreateDirs in ExtractOptions) or not IsDirectory) then |
| 1511 |
ExtractAt(i, ''); |
| 1512 |
DoArchiveProgress(AbPercentage(succ(i), Count), Abort); |
| 1513 |
if Abort then |
| 1514 |
raise EAbUserAbort.Create; |
| 1515 |
end; |
| 1516 |
DoArchiveProgress(100, Abort); |
| 1517 |
end; |
| 1518 |
end; |
| 1519 |
{ -------------------------------------------------------------------------- } |
| 1520 |
procedure TAbArchive.ExtractTaggedItems; |
| 1521 |
{extract all tagged items from the archive} |
| 1522 |
var |
| 1523 |
i : Integer; |
| 1524 |
Abort : Boolean; |
| 1525 |
begin |
| 1526 |
CheckValid; |
| 1527 |
if Count > 0 then begin |
| 1528 |
for i := 0 to pred(Count) do begin |
| 1529 |
with TAbArchiveItem(FItemList[i]) do |
| 1530 |
if Tagged then |
| 1531 |
ExtractAt(i, ''); |
| 1532 |
DoArchiveProgress(AbPercentage(succ(i), Count), Abort); |
| 1533 |
if Abort then |
| 1534 |
raise EAbUserAbort.Create; |
| 1535 |
end; |
| 1536 |
DoArchiveProgress(100, Abort); |
| 1537 |
end; |
| 1538 |
end; |
| 1539 |
{ -------------------------------------------------------------------------- } |
| 1540 |
procedure TAbArchive.TestTaggedItems; |
| 1541 |
{test all tagged items in the archive} |
| 1542 |
var |
| 1543 |
i : Integer; |
| 1544 |
Abort : Boolean; |
| 1545 |
begin |
| 1546 |
CheckValid; |
| 1547 |
if Count > 0 then begin |
| 1548 |
for i := 0 to pred(Count) do begin |
| 1549 |
with TAbArchiveItem(FItemList[i]) do |
| 1550 |
if Tagged then begin |
| 1551 |
FCurrentItem := FItemList[i]; |
| 1552 |
TestItemAt(i); |
| 1553 |
end; |
| 1554 |
DoArchiveProgress(AbPercentage(succ(i), Count), Abort); |
| 1555 |
if Abort then |
| 1556 |
raise EAbUserAbort.Create; |
| 1557 |
end; |
| 1558 |
DoArchiveProgress(100, Abort); |
| 1559 |
end; |
| 1560 |
end; |
| 1561 |
{ -------------------------------------------------------------------------- } |
| 1562 |
procedure TAbArchive.TestAt(Index: Integer); |
| 1563 |
begin |
| 1564 |
FCurrentItem := FItemList[Index]; |
| 1565 |
TestItemAt(Index); |
| 1566 |
end; |
| 1567 |
|
| 1568 |
{ -------------------------------------------------------------------------- } |
| 1569 |
function TAbArchive.FindFile(const aFileName : string): Integer; |
| 1570 |
{find the index of the specified file} |
| 1571 |
begin |
| 1572 |
Result := FItemList.Find(aFileName); |
| 1573 |
end; |
| 1574 |
{ -------------------------------------------------------------------------- } |
| 1575 |
function TAbArchive.FindItem(aItem : TAbArchiveItem): Integer; |
| 1576 |
{find the index of the specified item} |
| 1577 |
begin |
| 1578 |
Result := FItemList.Find(aItem.FileName); |
| 1579 |
end; |
| 1580 |
{ -------------------------------------------------------------------------- } |
| 1581 |
function TAbArchive.FixName(const Value : string) : string; |
| 1582 |
var |
| 1583 |
lValue: string; |
| 1584 |
begin |
| 1585 |
lValue := Value; |
| 1586 |
{$IFDEF MSWINDOWS} |
| 1587 |
if DOSMode then begin |
| 1588 |
{Add the base directory to the filename before converting } |
| 1589 |
{the file spec to the short filespec format. } |
| 1590 |
if BaseDirectory <> '' then begin |
| 1591 |
{Does the filename contain a drive or a leading backslash? } |
| 1592 |
if not ((Pos(':', lValue) = 2) or (Pos(AbPathDelim, lValue) = 1)) then |
| 1593 |
{If not, add the BaseDirectory to the filename.} |
| 1594 |
lValue := AbAddBackSlash(BaseDirectory) + lValue; |
| 1595 |
end; |
| 1596 |
lValue := AbGetShortFileSpec(lValue); |
| 1597 |
end; |
| 1598 |
{$ENDIF} |
| 1599 |
|
| 1600 |
{strip drive stuff} |
| 1601 |
if soStripDrive in StoreOptions then |
| 1602 |
AbStripDrive(lValue); |
| 1603 |
|
| 1604 |
{check for a leading backslash} |
| 1605 |
if lValue[1] = AbPathDelim then |
| 1606 |
System.Delete(lValue, 1, 1); |
| 1607 |
|
| 1608 |
if soStripPath in StoreOptions then begin |
| 1609 |
lValue := ExtractFileName(lValue); |
| 1610 |
end; |
| 1611 |
|
| 1612 |
if soRemoveDots in StoreOptions then |
| 1613 |
AbStripDots(lValue); |
| 1614 |
|
| 1615 |
Result := lValue; |
| 1616 |
end; |
| 1617 |
{ -------------------------------------------------------------------------- } |
| 1618 |
procedure TAbArchive.Freshen(aItem : TAbArchiveItem); |
| 1619 |
{freshen the item} |
| 1620 |
var |
| 1621 |
Index : Integer; |
| 1622 |
begin |
| 1623 |
CheckValid; |
| 1624 |
Index := FindItem(aItem); |
| 1625 |
if Index <> -1 then |
| 1626 |
begin |
| 1627 |
FreshenAt(Index); |
| 1628 |
{point existing item at the new file} |
| 1629 |
if AbGetPathType(aItem.DiskFileName) = ptAbsolute then |
| 1630 |
FItemList[Index].DiskFileName := aItem.DiskFileName; |
| 1631 |
end; |
| 1632 |
end; |
| 1633 |
{ -------------------------------------------------------------------------- } |
| 1634 |
procedure TAbArchive.FreshenAt(Index : Integer); |
| 1635 |
{freshen item at index} |
| 1636 |
var |
| 1637 |
Confirm : Boolean; |
| 1638 |
FR : Boolean; |
| 1639 |
ErrorClass : TAbErrorClass; |
| 1640 |
ErrorCode : Integer; |
| 1641 |
begin |
| 1642 |
CheckValid; |
| 1643 |
SaveIfNeeded(FItemList[Index]); |
| 1644 |
|
| 1645 |
GetFreshenTarget(FItemList[Index]); |
| 1646 |
FR := False; |
| 1647 |
try |
| 1648 |
FR := FreshenRequired(FItemList[Index]); |
| 1649 |
except |
| 1650 |
on E : Exception do begin |
| 1651 |
AbConvertException(E, ErrorClass, ErrorCode); |
| 1652 |
DoProcessItemFailure(FItemList[Index], ptFreshen, ErrorClass, ErrorCode); |
| 1653 |
end; |
| 1654 |
end; |
| 1655 |
if not FR then |
| 1656 |
Exit; |
| 1657 |
DoConfirmProcessItem(FItemList[Index], ptFreshen, Confirm); |
| 1658 |
if not Confirm then |
| 1659 |
Exit; |
| 1660 |
|
| 1661 |
TAbArchiveItem(FItemList[Index]).Action := aaFreshen; |
| 1662 |
FIsDirty := True; |
| 1663 |
if AutoSave then |
| 1664 |
Save; |
| 1665 |
end; |
| 1666 |
{ -------------------------------------------------------------------------- } |
| 1667 |
procedure TAbArchive.FreshenFiles(const FileMask : string); |
| 1668 |
{freshen all items that match the file mask} |
| 1669 |
begin |
| 1670 |
FreshenFilesEx(FileMask, ''); |
| 1671 |
end; |
| 1672 |
{ -------------------------------------------------------------------------- } |
| 1673 |
procedure TAbArchive.FreshenFilesEx(const FileMask, ExclusionMask : string); |
| 1674 |
{freshen all items that match the file mask} |
| 1675 |
var |
| 1676 |
i : Integer; |
| 1677 |
begin |
| 1678 |
CheckValid; |
| 1679 |
if Count > 0 then begin |
| 1680 |
for i := pred(Count) downto 0 do begin |
| 1681 |
with TAbArchiveItem(FItemList[i]) do |
| 1682 |
if MatchesStoredNameEx(FileMask) then |
| 1683 |
if not MatchesStoredNameEx(ExclusionMask) then |
| 1684 |
FreshenAt(i); |
| 1685 |
end; |
| 1686 |
end; |
| 1687 |
end; |
| 1688 |
{ -------------------------------------------------------------------------- } |
| 1689 |
function TAbArchive.FreshenRequired(Item : TAbArchiveItem) : Boolean; |
| 1690 |
var |
| 1691 |
FS : TFileStreamEx; |
| 1692 |
DateTime : LongInt; |
| 1693 |
FileTime : Word; |
| 1694 |
FileDate : Word; |
| 1695 |
Matched : Boolean; |
| 1696 |
SaveDir : string; |
| 1697 |
begin |
| 1698 |
GetDir(0, SaveDir); |
| 1699 |
if BaseDirectory <> '' then |
| 1700 |
ChDir(BaseDirectory); |
| 1701 |
try |
| 1702 |
FS := TFileStreamEx.Create(Item.DiskFileName, |
| 1703 |
fmOpenRead or fmShareDenyWrite); |
| 1704 |
try |
| 1705 |
DateTime := FileGetDate(FS.Handle); |
| 1706 |
FileTime := LongRec(DateTime).Lo; |
| 1707 |
FileDate := LongRec(DateTime).Hi; |
| 1708 |
Matched := (Item.LastModFileDate = FileDate) and |
| 1709 |
(Item.LastModFileTime = FileTime) and |
| 1710 |
(Item.UncompressedSize = FS.Size); |
| 1711 |
Result := not Matched; |
| 1712 |
finally |
| 1713 |
FS.Free; |
| 1714 |
end; |
| 1715 |
finally |
| 1716 |
if BaseDirectory <> '' then |
| 1717 |
ChDir(SaveDir); |
| 1718 |
end; |
| 1719 |
end; |
| 1720 |
{ -------------------------------------------------------------------------- } |
| 1721 |
procedure TAbArchive.FreshenTaggedItems; |
| 1722 |
{freshen all tagged items} |
| 1723 |
var |
| 1724 |
i : Integer; |
| 1725 |
begin |
| 1726 |
CheckValid; |
| 1727 |
if Count > 0 then begin |
| 1728 |
for i := pred(Count) downto 0 do begin |
| 1729 |
with TAbArchiveItem(FItemList[i]) do |
| 1730 |
if Tagged then |
| 1731 |
FreshenAt(i); |
| 1732 |
end; |
| 1733 |
end; |
| 1734 |
end; |
| 1735 |
{ -------------------------------------------------------------------------- } |
| 1736 |
procedure TAbArchive.GetFreshenTarget(Item : TAbArchiveItem); |
| 1737 |
var |
| 1738 |
PathType : TAbPathType; |
| 1739 |
Files : TStrings; |
| 1740 |
SaveDir : string; |
| 1741 |
DName : string; |
| 1742 |
begin |
| 1743 |
PathType := AbGetPathType(Item.DiskFileName); |
| 1744 |
if (soRecurse in StoreOptions) and (PathType = ptNone) then begin |
| 1745 |
GetDir(0, SaveDir); |
| 1746 |
if BaseDirectory <> '' then |
| 1747 |
ChDir(BaseDirectory); |
| 1748 |
try |
| 1749 |
Files := TStringList.Create; |
| 1750 |
try |
| 1751 |
// even if archive supports empty folder we don't have to |
| 1752 |
// freshen it because there is no data, although, the timestamp |
| 1753 |
// can be update since the folder was added |
| 1754 |
AbFindFiles(Item.FileName, faAnyFile and not faDirectory, Files, |
| 1755 |
True); |
| 1756 |
if Files.Count > 0 then begin |
| 1757 |
DName := AbAddBackSlash(BaseDirectory) + Files[0]; |
| 1758 |
AbUnfixName(DName); |
| 1759 |
Item.DiskFileName := DName; |
| 1760 |
end |
| 1761 |
else |
| 1762 |
Item.DiskFileName := ''; |
| 1763 |
finally |
| 1764 |
Files.Free; |
| 1765 |
end; |
| 1766 |
finally |
| 1767 |
if BaseDirectory <> '' then |
| 1768 |
ChDir(SaveDir); |
| 1769 |
end; |
| 1770 |
end |
| 1771 |
else begin |
| 1772 |
if (BaseDirectory <> '') then |
| 1773 |
DName := AbAddBackSlash(BaseDirectory) + Item.FileName |
| 1774 |
else |
| 1775 |
if AbGetPathType(Item.DiskFileName) = ptAbsolute then |
| 1776 |
DName := Item.DiskFileName |
| 1777 |
else |
| 1778 |
DName := Item.FileName; |
| 1779 |
AbUnfixName(DName); |
| 1780 |
Item.DiskFileName := DName; |
| 1781 |
end; |
| 1782 |
end; |
| 1783 |
{ -------------------------------------------------------------------------- } |
| 1784 |
function TAbArchive.GetSpanningThreshold : Int64; |
| 1785 |
begin |
| 1786 |
Result := FSpanningThreshold; |
| 1787 |
end; |
| 1788 |
{ -------------------------------------------------------------------------- } |
| 1789 |
function TAbArchive.GetSupportsEmptyFolders : Boolean; |
| 1790 |
begin |
| 1791 |
Result := False; |
| 1792 |
end; |
| 1793 |
{ -------------------------------------------------------------------------- } |
| 1794 |
function TAbArchive.GetItemCount : Integer; |
| 1795 |
begin |
| 1796 |
if Assigned(FItemList) then |
| 1797 |
Result := FItemList.Count |
| 1798 |
else |
| 1799 |
Result := 0; |
| 1800 |
end; |
| 1801 |
{ -------------------------------------------------------------------------- } |
| 1802 |
procedure TAbArchive.Load; |
| 1803 |
{load the archive} |
| 1804 |
begin |
| 1805 |
try |
| 1806 |
LoadArchive; |
| 1807 |
FStatus := asIdle; |
| 1808 |
finally |
| 1809 |
DoLoad; |
| 1810 |
end; |
| 1811 |
end; |
| 1812 |
{ -------------------------------------------------------------------------- } |
| 1813 |
procedure TAbArchive.MakeLogEntry(const FN: string; LT : TAbLogType); |
| 1814 |
const |
| 1815 |
LogTypeRes : array[TAbLogType] of string = |
| 1816 |
(AbLtAddS, AbLtDeleteS, AbLtExtractS, AbLtFreshenS, AbLtMoveS, AbLtReplaceS, |
| 1817 |
AbLtStartS, AbUnhandledEntityS); |
| 1818 |
var |
| 1819 |
Buf : string; |
| 1820 |
begin |
| 1821 |
if Assigned(FLogStream) then begin |
| 1822 |
Buf := FN + LogTypeRes[LT] + DateTimeToStr(Now) + sLineBreak; |
| 1823 |
FLogStream.Write(Buf[1], Length(Buf) * SizeOf(Char)); |
| 1824 |
end; |
| 1825 |
end; |
| 1826 |
{ -------------------------------------------------------------------------- } |
| 1827 |
procedure TAbArchive.MakeFullNames(const SourceFileName: String; |
| 1828 |
const ArchiveDirectory: String; |
| 1829 |
out FullSourceFileName: String; |
| 1830 |
out FullArchiveFileName: String); |
| 1831 |
var |
| 1832 |
PathType : TAbPathType; |
| 1833 |
RelativeSourceFileName: String; |
| 1834 |
begin |
| 1835 |
PathType := AbGetPathType(SourceFileName); |
| 1836 |
case PathType of |
| 1837 |
ptNone, ptRelative : |
| 1838 |
begin |
| 1839 |
if FBaseDirectory <> '' then |
| 1840 |
FullSourceFileName := AbAddBackSlash(FBaseDirectory) + SourceFileName |
| 1841 |
else |
| 1842 |
FullSourceFileName := SourceFileName; |
| 1843 |
|
| 1844 |
RelativeSourceFileName := SourceFileName; |
| 1845 |
end; |
| 1846 |
ptAbsolute : |
| 1847 |
begin |
| 1848 |
FullSourceFileName := SourceFileName; |
| 1849 |
|
| 1850 |
if FBaseDirectory <> '' then |
| 1851 |
RelativeSourceFileName := ExtractRelativepath(AbAddBackSlash(FBaseDirectory), |
| 1852 |
SourceFileName) |
| 1853 |
else |
| 1854 |
RelativeSourceFileName := ExtractFileName(SourceFileName); |
| 1855 |
end; |
| 1856 |
end; |
| 1857 |
|
| 1858 |
if ArchiveDirectory <> '' then |
| 1859 |
FullArchiveFileName := AbAddBackSlash(ArchiveDirectory) + RelativeSourceFileName |
| 1860 |
else |
| 1861 |
FullArchiveFileName := RelativeSourceFileName; |
| 1862 |
|
| 1863 |
FullArchiveFileName := FixName(FullArchiveFileName); |
| 1864 |
end; |
| 1865 |
{ -------------------------------------------------------------------------- } |
| 1866 |
procedure TAbArchive.Move(aItem : TAbArchiveItem; const NewStoredPath : string); |
| 1867 |
var |
| 1868 |
Confirm : Boolean; |
| 1869 |
Found : Boolean; |
| 1870 |
i : Integer; |
| 1871 |
FixedPath: string; |
| 1872 |
begin |
| 1873 |
CheckValid; |
| 1874 |
FixedPath := FixName(NewStoredPath); |
| 1875 |
Found := False; |
| 1876 |
if Count > 0 then |
| 1877 |
for i := 0 to pred(Count) do |
| 1878 |
if (ItemList[i] <> aItem) and SameText(FixedPath, ItemList[i].FileName) and |
| 1879 |
(ItemList[i].Action <> aaDelete) then begin |
| 1880 |
Found := True; |
| 1881 |
Break; |
| 1882 |
end; |
| 1883 |
if Found then begin |
| 1884 |
DoProcessItemFailure(aItem, ptMove, ecAbbrevia, AbDuplicateName); |
| 1885 |
{even if something gets done in the AddItemFailure, we don't |
| 1886 |
want to continue...} |
| 1887 |
Exit; |
| 1888 |
end; |
| 1889 |
|
| 1890 |
SaveIfNeeded(aItem); |
| 1891 |
|
| 1892 |
DoConfirmProcessItem(aItem, ptMove, Confirm); |
| 1893 |
if not Confirm then |
| 1894 |
Exit; |
| 1895 |
|
| 1896 |
with aItem do begin |
| 1897 |
FileName := FixedPath; |
| 1898 |
Action := aaMove; |
| 1899 |
end; |
| 1900 |
FIsDirty := True; |
| 1901 |
if AutoSave then |
| 1902 |
Save; |
| 1903 |
end; |
| 1904 |
{ -------------------------------------------------------------------------- } |
| 1905 |
procedure TAbArchive.Replace(aItem : TAbArchiveItem); |
| 1906 |
{replace the item} |
| 1907 |
var |
| 1908 |
Index : Integer; |
| 1909 |
begin |
| 1910 |
CheckValid; |
| 1911 |
Index := FindItem(aItem); |
| 1912 |
if Index <> -1 then |
| 1913 |
begin |
| 1914 |
ReplaceAt(Index); |
| 1915 |
{point existing item at the new file} |
| 1916 |
if AbGetPathType(aItem.DiskFileName) = ptAbsolute then |
| 1917 |
FItemList[Index].DiskFileName := aItem.DiskFileName; |
| 1918 |
end; |
| 1919 |
end; |
| 1920 |
{ -------------------------------------------------------------------------- } |
| 1921 |
procedure TAbArchive.ReplaceAt(Index : Integer); |
| 1922 |
{replace item at Index} |
| 1923 |
var |
| 1924 |
Confirm : Boolean; |
| 1925 |
begin |
| 1926 |
CheckValid; |
| 1927 |
SaveIfNeeded(FItemList[Index]); |
| 1928 |
|
| 1929 |
GetFreshenTarget(FItemList[Index]); |
| 1930 |
DoConfirmProcessItem(FItemList[Index], ptReplace, Confirm); |
| 1931 |
if not Confirm then |
| 1932 |
Exit; |
| 1933 |
|
| 1934 |
TAbArchiveItem(FItemList[Index]).Action := aaReplace; |
| 1935 |
FIsDirty := True; |
| 1936 |
if AutoSave then |
| 1937 |
Save; |
| 1938 |
end; |
| 1939 |
{ -------------------------------------------------------------------------- } |
| 1940 |
procedure TAbArchive.Save; |
| 1941 |
{save the archive} |
| 1942 |
var |
| 1943 |
Confirm : Boolean; |
| 1944 |
begin |
| 1945 |
if Status = asInvalid then |
| 1946 |
Exit; |
| 1947 |
if not FIsDirty then |
| 1948 |
Exit; |
| 1949 |
|
| 1950 |
DoConfirmSave(Confirm); |
| 1951 |
if not Confirm then |
| 1952 |
Exit; |
| 1953 |
|
| 1954 |
SaveArchive; |
| 1955 |
FIsDirty := False; |
| 1956 |
DoSave; |
| 1957 |
end; |
| 1958 |
{ -------------------------------------------------------------------------- } |
| 1959 |
procedure TAbArchive.SaveIfNeeded(aItem : TAbArchiveItem); |
| 1960 |
begin |
| 1961 |
if (aItem.Action <> aaNone) then |
| 1962 |
Save; |
| 1963 |
end; |
| 1964 |
{ -------------------------------------------------------------------------- } |
| 1965 |
procedure TAbArchive.SetBaseDirectory(Value : string); |
| 1966 |
begin |
| 1967 |
if (Value <> '') then |
| 1968 |
if Value[Length(Value)] = AbPathDelim then |
| 1969 |
if (Length(Value) > 1) and (Value[Length(Value) - 1] <> ':') then |
| 1970 |
System.Delete(Value, Length(Value), 1); |
| 1971 |
if (Length(Value) = 0) or mbDirectoryExists(Value) then |
| 1972 |
FBaseDirectory := Value |
| 1973 |
else |
| 1974 |
raise EAbNoSuchDirectory.Create; |
| 1975 |
end; |
| 1976 |
{ -------------------------------------------------------------------------- } |
| 1977 |
procedure TAbArchive.SetSpanningThreshold( Value : Int64 ); |
| 1978 |
begin |
| 1979 |
FSpanningThreshold := Value; |
| 1980 |
end; |
| 1981 |
{ -------------------------------------------------------------------------- } |
| 1982 |
procedure TAbArchive.SetLogFile(const Value : string); |
| 1983 |
begin |
| 1984 |
FLogFile := Value; |
| 1985 |
end; |
| 1986 |
{ -------------------------------------------------------------------------- } |
| 1987 |
procedure TAbArchive.SetLogging(Value : Boolean); |
| 1988 |
begin |
| 1989 |
FLogging := Value; |
| 1990 |
if Assigned(FLogStream) then begin |
| 1991 |
FLogStream.Free; |
| 1992 |
FLogStream := nil; |
| 1993 |
end; |
| 1994 |
if FLogging and (FLogFile <> '') then begin |
| 1995 |
try |
| 1996 |
FLogStream := TFileStream.Create(FLogFile, fmCreate or fmOpenWrite); |
| 1997 |
MakeLogEntry(FArchiveName, ltStart); |
| 1998 |
except |
| 1999 |
raise EAbException.Create(AbLogCreateErrorS); |
| 2000 |
end; |
| 2001 |
end; |
| 2002 |
end; |
| 2003 |
{ -------------------------------------------------------------------------- } |
| 2004 |
procedure TAbArchive.TagItems(const FileMask : string); |
| 2005 |
{tag all items that match the mask} |
| 2006 |
var |
| 2007 |
i : Integer; |
| 2008 |
begin |
| 2009 |
if Count > 0 then |
| 2010 |
for i := 0 to pred(Count) do |
| 2011 |
with TAbArchiveItem(FItemList[i]) do begin |
| 2012 |
if MatchesStoredNameEx(FileMask) then |
| 2013 |
Tagged := True; |
| 2014 |
end; |
| 2015 |
end; |
| 2016 |
{ -------------------------------------------------------------------------- } |
| 2017 |
procedure TAbArchive.UnTagItems(const FileMask : string); |
| 2018 |
{clear tags for all items that match the mask} |
| 2019 |
var |
| 2020 |
i : Integer; |
| 2021 |
begin |
| 2022 |
if Count > 0 then |
| 2023 |
for i := 0 to pred(Count) do |
| 2024 |
with TAbArchiveItem(FItemList[i]) do begin |
| 2025 |
if MatchesStoredNameEx(FileMask) then |
| 2026 |
Tagged := False; |
| 2027 |
end; |
| 2028 |
end; |
| 2029 |
{ -------------------------------------------------------------------------- } |
| 2030 |
procedure TAbArchive.VerifyItem(Item: TAbArchiveItem); |
| 2031 |
var |
| 2032 |
Index: Integer; |
| 2033 |
AFileName: String; |
| 2034 |
begin |
| 2035 |
if FSuspiciousLinks.Count > 0 then |
| 2036 |
begin |
| 2037 |
AFileName := NormalizePathDelimiters(Item.FileName); |
| 2038 |
for Index := 0 to FSuspiciousLinks.Count - 1 do |
| 2039 |
begin |
| 2040 |
if IsInPath(FSuspiciousLinks[Index], AFileName, True, True) then |
| 2041 |
raise EInvalidOpException.Create(AbSuspiciousSymlinkOperation); |
| 2042 |
end; |
| 2043 |
end; |
| 2044 |
end; |
| 2045 |
{ -------------------------------------------------------------------------- } |
| 2046 |
procedure TAbArchive.DoSpanningMediaRequest(Sender: TObject; |
| 2047 |
ImageNumber: Integer; var ImageName: string; var Abort: Boolean); |
| 2048 |
begin |
| 2049 |
raise EAbSpanningNotSupported.Create; |
| 2050 |
end; |
| 2051 |
{ -------------------------------------------------------------------------- } |
| 2052 |
function TAbArchive.CreateItem(const FileSpec : string): TAbArchiveItem; |
| 2053 |
begin |
| 2054 |
// This function is used by Abbrevia. We don't use it but a dummy |
| 2055 |
// definition is needed for the code to compile successfully. |
| 2056 |
raise Exception.Create(''); |
| 2057 |
end; |
| 2058 |
{ -------------------------------------------------------------------------- } |
| 2059 |
|
| 2060 |
{ TAbExtraField implementation ============================================= } |
| 2061 |
procedure TAbExtraField.Assign(aSource : TAbExtraField); |
| 2062 |
begin |
| 2063 |
SetBuffer(aSource.Buffer); |
| 2064 |
end; |
| 2065 |
{ -------------------------------------------------------------------------- } |
| 2066 |
procedure TAbExtraField.Changed; |
| 2067 |
begin |
| 2068 |
// No-op |
| 2069 |
end; |
| 2070 |
{ -------------------------------------------------------------------------- } |
| 2071 |
procedure TAbExtraField.Clear; |
| 2072 |
begin |
| 2073 |
FBuffer := nil; |
| 2074 |
Changed; |
| 2075 |
end; |
| 2076 |
{ -------------------------------------------------------------------------- } |
| 2077 |
procedure TAbExtraField.CloneFrom(aSource : TAbExtraField; aID : Word); |
| 2078 |
var |
| 2079 |
Data : Pointer; |
| 2080 |
DataSize : Word; |
| 2081 |
begin |
| 2082 |
if aSource.Get(aID, Data, DataSize) then |
| 2083 |
Put(aID, Data, DataSize) |
| 2084 |
else Delete(aID); |
| 2085 |
end; |
| 2086 |
{ -------------------------------------------------------------------------- } |
| 2087 |
procedure TAbExtraField.Delete(aID : Word); |
| 2088 |
var |
| 2089 |
SubField : PAbExtraSubField; |
| 2090 |
begin |
| 2091 |
if FindField(aID, SubField) then begin |
| 2092 |
DeleteField(SubField); |
| 2093 |
Changed; |
| 2094 |
end; |
| 2095 |
end; |
| 2096 |
{ -------------------------------------------------------------------------- } |
| 2097 |
procedure TAbExtraField.DeleteField(aSubField : PAbExtraSubField); |
| 2098 |
var |
| 2099 |
Len, Offset : Integer; |
| 2100 |
begin |
| 2101 |
Len := SizeOf(TAbExtraSubField) + aSubField.Len; |
| 2102 |
Offset := Pointer(aSubField) - Pointer(FBuffer); |
| 2103 |
if Offset + Len < Length(FBuffer) then |
| 2104 |
Move(FBuffer[Offset + Len], aSubField^, Length(FBuffer) - Offset - Len); |
| 2105 |
SetLength(FBuffer, Length(FBuffer) - Len); |
| 2106 |
end; |
| 2107 |
{ -------------------------------------------------------------------------- } |
| 2108 |
function TAbExtraField.FindField(aID : Word; |
| 2109 |
out aSubField : PAbExtraSubField) : Boolean; |
| 2110 |
begin |
| 2111 |
Result := False; |
| 2112 |
aSubField := nil; |
| 2113 |
while FindNext(aSubField) do |
| 2114 |
if aSubField.ID = aID then begin |
| 2115 |
Result := True; |
| 2116 |
Break; |
| 2117 |
end; |
| 2118 |
end; |
| 2119 |
{ -------------------------------------------------------------------------- } |
| 2120 |
function TAbExtraField.FindNext(var aCurField : PAbExtraSubField) : Boolean; |
| 2121 |
var |
| 2122 |
BytesLeft : Integer; |
| 2123 |
begin |
| 2124 |
if aCurField = nil then begin |
| 2125 |
aCurField := PAbExtraSubField(FBuffer); |
| 2126 |
BytesLeft := Length(FBuffer); |
| 2127 |
end |
| 2128 |
else begin |
| 2129 |
BytesLeft := Length(FBuffer) - |
| 2130 |
(Pointer(aCurField) - Pointer(FBuffer)) - |
| 2131 |
SizeOf(TAbExtraSubField) - aCurField.Len; |
| 2132 |
Inc(Pointer(aCurField), aCurField.Len + SizeOf(TAbExtraSubField)); |
| 2133 |
end; |
| 2134 |
Result := (BytesLeft >= SizeOf(TAbExtraSubField)); |
| 2135 |
if Result and (BytesLeft < SizeOf(TAbExtraSubField) + aCurField.Len) then |
| 2136 |
aCurField.Len := BytesLeft - SizeOf(TAbExtraSubField); |
| 2137 |
end; |
| 2138 |
{ -------------------------------------------------------------------------- } |
| 2139 |
function TAbExtraField.Get(aID : Word; out aData : Pointer; |
| 2140 |
out aDataSize : Word) : Boolean; |
| 2141 |
var |
| 2142 |
SubField : PAbExtraSubField; |
| 2143 |
begin |
| 2144 |
Result := FindField(aID, SubField); |
| 2145 |
if Result then begin |
| 2146 |
aData := @SubField.Data; |
| 2147 |
aDataSize := SubField.Len; |
| 2148 |
end |
| 2149 |
else begin |
| 2150 |
aData := nil; |
| 2151 |
aDataSize := 0; |
| 2152 |
end; |
| 2153 |
end; |
| 2154 |
{ -------------------------------------------------------------------------- } |
| 2155 |
function TAbExtraField.GetCount : Integer; |
| 2156 |
var |
| 2157 |
SubField : PAbExtraSubField; |
| 2158 |
begin |
| 2159 |
Result := 0; |
| 2160 |
SubField := nil; |
| 2161 |
while FindNext(SubField) do |
| 2162 |
Inc(Result); |
| 2163 |
end; |
| 2164 |
{ -------------------------------------------------------------------------- } |
| 2165 |
function TAbExtraField.GetID(aIndex : Integer): Word; |
| 2166 |
var |
| 2167 |
i: Integer; |
| 2168 |
SubField : PAbExtraSubField; |
| 2169 |
begin |
| 2170 |
i := 0; |
| 2171 |
SubField := nil; |
| 2172 |
while FindNext(SubField) do |
| 2173 |
if i = aIndex then begin |
| 2174 |
Result := SubField.ID; |
| 2175 |
Exit; |
| 2176 |
end |
| 2177 |
else |
| 2178 |
Inc(i); |
| 2179 |
raise EListError.CreateFmt(SListIndexError, [aIndex]); |
| 2180 |
end; |
| 2181 |
{ -------------------------------------------------------------------------- } |
| 2182 |
function TAbExtraField.GetStream(aID : Word; out aStream : TStream): Boolean; |
| 2183 |
var |
| 2184 |
Data: Pointer; |
| 2185 |
DataSize: Word; |
| 2186 |
begin |
| 2187 |
Result := Get(aID, Data, DataSize); |
| 2188 |
if Result then begin |
| 2189 |
aStream := TMemoryStream.Create; |
| 2190 |
aStream.WriteBuffer(Data^, DataSize); |
| 2191 |
aStream.Position := 0; |
| 2192 |
end; |
| 2193 |
end; |
| 2194 |
{ -------------------------------------------------------------------------- } |
| 2195 |
function TAbExtraField.Has(aID : Word): Boolean; |
| 2196 |
var |
| 2197 |
SubField : PAbExtraSubField; |
| 2198 |
begin |
| 2199 |
Result := FindField(aID, SubField); |
| 2200 |
end; |
| 2201 |
{ -------------------------------------------------------------------------- } |
| 2202 |
procedure TAbExtraField.LoadFromStream(aStream : TStream; aSize : Word); |
| 2203 |
begin |
| 2204 |
SetLength(FBuffer, aSize); |
| 2205 |
if aSize > 0 then |
| 2206 |
aStream.ReadBuffer( FBuffer[0], aSize); |
| 2207 |
end; |
| 2208 |
{ -------------------------------------------------------------------------- } |
| 2209 |
procedure TAbExtraField.Put(aID : Word; const aData; aDataSize : Word); |
| 2210 |
var |
| 2211 |
Offset : Cardinal; |
| 2212 |
SubField : PAbExtraSubField; |
| 2213 |
begin |
| 2214 |
if FindField(aID, SubField) then begin |
| 2215 |
if SubField.Len = aDataSize then begin |
| 2216 |
Move(aData, SubField.Data, aDataSize); |
| 2217 |
Changed; |
| 2218 |
Exit; |
| 2219 |
end |
| 2220 |
else DeleteField(SubField); |
| 2221 |
end; |
| 2222 |
Offset := Length(FBuffer); |
| 2223 |
SetLength(FBuffer, Length(FBuffer) + SizeOf(TAbExtraSubField) + aDataSize); |
| 2224 |
SubField := PAbExtraSubField(@FBuffer[Offset]); |
| 2225 |
SubField.ID := aID; |
| 2226 |
SubField.Len := aDataSize; |
| 2227 |
Move(aData, SubField.Data, aDataSize); |
| 2228 |
Changed; |
| 2229 |
end; |
| 2230 |
{ -------------------------------------------------------------------------- } |
| 2231 |
procedure TAbExtraField.SetBuffer(const aValue : TByteDynArray); |
| 2232 |
begin |
| 2233 |
SetLength(FBuffer, Length(aValue)); |
| 2234 |
if Length(FBuffer) > 0 then |
| 2235 |
Move(aValue[0], FBuffer[0], Length(FBuffer)); |
| 2236 |
Changed; |
| 2237 |
end; |
| 2238 |
{ -------------------------------------------------------------------------- } |
| 2239 |
|
| 2240 |
{ ========================================================================== } |
| 2241 |
{ TAbArchiveStreamHelper } |
| 2242 |
|
| 2243 |
constructor TAbArchiveStreamHelper.Create(AStream: TStream); |
| 2244 |
begin |
| 2245 |
if Assigned(AStream) then |
| 2246 |
FStream := AStream |
| 2247 |
else |
| 2248 |
raise Exception.Create('nil stream'); |
| 2249 |
end; |
| 2250 |
|
| 2251 |
end. |