📄 abarctyp.pas
字号:
Save; finally Unlock; end; end;end;{ -------------------------------------------------------------------------- }procedure TAbArchive.AddFiles(const FileMask : string; SearchAttr : Integer); {Add files to the archive where the disk filespec matches}begin AddFilesEx(FileMask, '', SearchAttr);end;{ -------------------------------------------------------------------------- }procedure TAbArchive.AddFilesEx(const FileMask, ExclusionMask : string; SearchAttr : Integer); {Add files matching Filemask except those matching ExclusionMask}var PathType : TAbPathType; IsWild : Boolean; SaveDir : string; Mask : string; MaskF : string; procedure CreateItems(Wild, Recursing : Boolean); var i : Integer; Files : TStrings; FilterList : TStringList; Item : TAbArchiveItem; begin FilterList := TStringList.Create; try if (MaskF <> '') then AbFindFilesEx(MaskF, SearchAttr and not faDirectory, FilterList, Recursing); Files := TStringList.Create; try AbFindFilesEx(Mask, SearchAttr and not faDirectory, Files, Recursing); if (Files.Count > 0) then for i := 0 to pred(Files.Count) do if FilterList.IndexOf(Files[i]) < 0 then if not Wild then begin if (Files[i] <> FArchiveName) then begin Item := CreateItem(Files[i]); Add(Item); end; end else begin if (AbAddBackSlash(FBaseDirectory) + Files[i]) <> FArchiveName then begin Item := CreateItem(Files[i]); Add(Item); end; end; finally Files.Free; end; finally FilterList.Free; end; end;begin CheckValid; IsWild := (Pos('*', FileMask) > 0) or (Pos('?', FileMask) > 0); PathType := AbGetPathType(FileMask); Mask := FileMask; AbUnfixName(Mask); MaskF := ExclusionMask; AbUnfixName(MaskF); case PathType of ptNone : begin GetDir(0, SaveDir); if BaseDirectory <> '' then ChDir(BaseDirectory); try CreateItems(IsWild, soRecurse in StoreOptions); finally if BaseDirectory <> '' then ChDir(SaveDir); end; end; ptRelative : begin GetDir(0, SaveDir); if BaseDirectory <> '' then ChDir(BaseDirectory); try CreateItems(IsWild, soRecurse in StoreOptions); finally if BaseDirectory <> '' then ChDir(SaveDir); end; end; ptAbsolute : begin CreateItems(IsWild, soRecurse in StoreOptions); end; end;end;{ -------------------------------------------------------------------------- }procedure TAbArchive.AddFromStream(const NewName : string; aStream : TStream); {Add an item to the archive directly from a TStream descendant}var Confirm : Boolean; Item : TAbArchiveItem; PT : TAbProcessType; begin Item := CreateItem(NewName); CheckValid; PT := ptAdd; if FItemList.IsActiveDupe(NewName) then begin if ((soFreshen in StoreOptions) or (soReplace in StoreOptions)) then begin Item.Free; Item := FItemList[FItemList.Find(NewName)]; PT := ptReplace; end else begin DoProcessItemFailure(Item, ptAdd, ecAbbrevia, AbDuplicateName); Item.Free; Exit; end; end; DoConfirmProcessItem(Item, PT, Confirm); if not Confirm then Exit; Lock; try FInStream := aStream; Item.Action := aaStreamAdd; if (PT = ptAdd) then FItemList.Add(Item); FIsDirty := True; Save; FInStream := nil; finally Unlock; end;end;{ -------------------------------------------------------------------------- }procedure TAbArchive.CheckValid;begin if Status = asInvalid then raise EAbNoArchive.Create;end;{ -------------------------------------------------------------------------- }procedure TAbArchive.ClearTags; {Clear all tags from the archive}var i : Integer;begin if Count > 0 then for i := 0 to pred(Count) do TAbArchiveItem(FItemList[i]).Tagged := False;end;{ -------------------------------------------------------------------------- }procedure TAbArchive.Delete(aItem : TAbArchiveItem); {delete an item from the archive}var Index : Integer;begin CheckValid; Index := FindItem(aItem); if Index <> -1 then DeleteAt(Index);end;{ -------------------------------------------------------------------------- }procedure TAbArchive.DeleteAt(Index : Integer); {delete the item at the index from the archive}var Confirm : Boolean;begin CheckValid; SaveIfNeeded(FItemList[Index]); Lock; try DoConfirmProcessItem(FItemList[Index], ptDelete, Confirm); if not Confirm then Exit; TAbArchiveItem(FItemList[Index]).Action := aaDelete; FIsDirty := True; if AutoSave then Save; finally Unlock; end;end;{ -------------------------------------------------------------------------- }procedure TAbArchive.DeleteFiles(const FileMask : string); {delete all files from the archive that match the file mask}begin DeleteFilesEx(FileMask, '');end;{ -------------------------------------------------------------------------- }procedure TAbArchive.DeleteFilesEx(const FileMask, ExclusionMask : string); {Delete files matching Filemask except those matching ExclusionMask}var i : Integer;begin CheckValid; if Count > 0 then begin for i := pred(Count) downto 0 do begin with TAbArchiveItem(FItemList[i]) do if MatchesStoredNameEx(FileMask) then if not MatchesStoredNameEx(ExclusionMask) then DeleteAt(i); end; end;end;{ -------------------------------------------------------------------------- }procedure TAbArchive.DeleteTaggedItems; {delete all tagged items from the archive}var i : Integer;begin CheckValid; if Count > 0 then begin for i := pred(Count) downto 0 do begin with TAbArchiveItem(FItemList[i]) do if Tagged then DeleteAt(i); end; end;end;{ -------------------------------------------------------------------------- }procedure TAbArchive.DoProcessItemFailure(Item : TAbArchiveItem; ProcessType : TAbProcessType; ErrorClass : TAbErrorClass; ErrorCode : Integer);begin if Assigned(FOnProcessItemFailure) then FOnProcessItemFailure(Self, Item, ProcessType, ErrorClass, ErrorCode);end;{ -------------------------------------------------------------------------- }{!!.04 - Added }procedure TAbArchive.DoArchiveSaveProgress(Progress : Byte; var Abort : Boolean);begin Abort := False; if Assigned(FOnArchiveSaveProgress) then FOnArchiveSaveProgress(Self, Progress, Abort);end;{!!.04 - Added end }{ -------------------------------------------------------------------------- }procedure TAbArchive.DoArchiveProgress(Progress : Byte; var Abort : Boolean);begin Abort := False; if Assigned(FOnArchiveProgress) then FOnArchiveProgress(Self, Progress, Abort);end;{ -------------------------------------------------------------------------- }procedure TAbArchive.DoArchiveItemProgress(Item : TAbArchiveItem; Progress : Byte; var Abort : Boolean);begin Abort := False; if Assigned(FOnArchiveItemProgress) then FOnArchiveItemProgress(Self, Item, Progress, Abort);end;{ -------------------------------------------------------------------------- }procedure TAbArchive.DoConfirmProcessItem(Item : TAbArchiveItem; const ProcessType : TAbProcessType; var Confirm : Boolean);begin Confirm := True; if Assigned(FOnConfirmProcessItem) then FOnConfirmProcessItem(Self, Item, ProcessType, Confirm); if (Confirm and FLogging) then MakeLogEntry(Item.Filename, ProcessTypeToLogType[ProcessType]);end;{ -------------------------------------------------------------------------- }procedure TAbArchive.DoConfirmSave(var Confirm : Boolean);begin Confirm := True; if Assigned(FOnConfirmSave) then FOnConfirmSave(Self, Confirm);end;{ -------------------------------------------------------------------------- }procedure TAbArchive.DoDeflateProgress(aPercentDone: integer);var Abort : Boolean;begin DoProgress(aPercentDone, Abort); if Abort then raise EAbAbortProgress.Create(AbStrRes(AbUserAbort));end;{ -------------------------------------------------------------------------- }procedure TAbArchive.DoInflateProgress(aPercentDone: integer);var Abort : Boolean;begin DoProgress(aPercentDone, Abort); if Abort then raise EAbAbortProgress.Create(AbStrRes(AbUserAbort));end;{ -------------------------------------------------------------------------- }procedure TAbArchive.DoLoad;begin if Assigned(FOnLoad) then FOnLoad(Self);end;{ -------------------------------------------------------------------------- }procedure TAbArchive.DoProgress(Progress : Byte; var Abort : Boolean);begin Abort := False; DoArchiveItemProgress(FCurrentItem, Progress, Abort);end;{ -------------------------------------------------------------------------- }procedure TAbArchive.DoSave;begin if Assigned(FOnSave) then FOnSave(Self);end;{ -------------------------------------------------------------------------- }procedure TAbArchive.Extract(aItem : TAbArchiveItem; const NewName : string); {extract an item from the archive}var Index : Integer;begin CheckValid; Index := FindItem(aItem); if Index <> -1 then ExtractAt(Index, NewName);end;{ -------------------------------------------------------------------------- }procedure TAbArchive.ExtractAt(Index : Integer; const NewName : string); {extract an item from the archive at Index}var Confirm : Boolean; ErrorClass : TAbErrorClass; ErrorCode : Integer; TempNewName : string;begin CheckValid; SaveIfNeeded(FItemList[Index]); Lock; try DoConfirmProcessItem(FItemList[Index], ptExtract, Confirm); if not Confirm then Exit; TempNewName := NewName; if (TempNewName = '') then TempNewName := TAbArchiveItem(FItemList[Index]).FileName; try FCurrentItem := FItemList[Index]; ExtractItemAt(Index, TempNewName); except on E : Exception do begin AbConvertException(E, ErrorClass, ErrorCode); DoProcessItemFailure(FItemList[Index], ptExtract, ErrorClass, ErrorCode); end; end; finally Unlock; end;end;{ -------------------------------------------------------------------------- }procedure TAbArchive.ExtractToStream(const aFileName : string; aStream : TStream); {extract an item from the archive at Index directly to a stream}var Confirm : Boolean; ErrorClass : TAbErrorClass; ErrorCode : Integer; Index : Integer;begin CheckValid; Index := FindFile(aFileName); if (Index = -1) then Exit; SaveIfNeeded(FItemList[Index]); Lock; try DoConfirmProcessItem(FItemList[Index], ptExtract, Confirm); if not Confirm then Exit; FCurrentItem := FItemList[Index]; try ExtractItemToStreamAt(Index, aStream); except on E : Exception do begin AbConvertException(E, ErrorClass, ErrorCode); DoProcessItemFailure(FItemList[Index], ptExtract, ErrorClass, ErrorCode); end; end; finally Unlock; end;end;{ -------------------------------------------------------------------------- }procedure TAbArchive.ExtractFiles(const FileMask : string); {extract all files from the archive that match the mask}begin ExtractFilesEx(FileMask, '');end;{ -------------------------------------------------------------------------- }procedure TAbArchive.ExtractFilesEx(const FileMask, ExclusionMask : string); {Extract files matching Filemask except those matching ExclusionMask}var i : Integer; Abort : Boolean;{$IFNDEF Linux} Buff : array [0..MAX_PATH] of Char; {!!.03}{$ENDIF}begin{!!.03 - Added}{$IFDEF Linux} { do nothing to BaseDirectory }{$ELSE} if AreFileApisANSI then begin StrPCopy(Buff, BaseDirectory); OEMToAnsi(Buff, Buff); BaseDirectory := StrPas(Buff); end;{$ENDIF}{!!.03 - End Added } CheckValid; if Count > 0 then begin for i := 0 to pred(Count) do begin with TAbArchiveItem(FItemList[i]) do if MatchesStoredNameEx(FileMask) then if not MatchesStoredNameEx(ExclusionMask) then ExtractAt(i, ''); DoArchiveProgress(AbPercentage(succ(i), Count), Abort); if Abort then raise EAbUserAbort.Create; end; DoArchiveProgress(100, Abort); end;end;{ -------------------------------------------------------------------------- }procedure TAbArchive.ExtractTaggedItems; {extract all tagged items from the archive}var i : Integer; Abort : Boolean;begin CheckValid; if Count > 0 then begin for i := 0 to pred(Count) do begin with TAbArchiveItem(FItemList[i]) do if Tagged then ExtractAt(i, ''); DoArchiveProgress(AbPercentage(succ(i), Count), Abort); if Abort then raise EAbUserAbort.Create; end; DoArchiveProgress(100, Abort); end;end;{ -------------------------------------------------------------------------- }procedure TAbArchive.TestTaggedItems; {test all tagged items in the archive}var i : Integer; Abort : Boolean; begin CheckValid; if Count > 0 then begin for i := 0 to pred(Count) do begin with TAbArchiveItem(FItemList[i]) do if Tagged then begin FCurrentItem := FItemList[i]; TestItemAt(i); end; DoArchiveProgress(AbPercentage(succ(i), Count), Abort); if Abort then raise EAbUserAbort.Create; end; DoArchiveProgress(100, Abort); end;end;{ -------------------------------------------------------------------------- }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -