📄 abcabtyp.pas
字号:
(* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is TurboPower Abbrevia * * The Initial Developer of the Original Code is * TurboPower Software * * Portions created by the Initial Developer are Copyright (C) 1997-2002 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * ***** END LICENSE BLOCK ***** *){*********************************************************}{* ABBREVIA: AbCabTyp.pas 3.05 *}{*********************************************************}{* ABBREVIA: Cabinet Archive *}{* Based on info from the FCI/FDI Library Description, *}{* included in the Microsoft Cabinet SDK *}{*********************************************************}{$I AbDefine.inc}unit AbCabTyp;interfaceuses{$ifndef LINUX} Windows,{$else} Libc, {$endif} SysUtils, Classes, AbFciFdi, AbArcTyp, AbUtils, AbConst, AbExcept;type TAbCabItem = class(TAbArchiveItem) protected {private} FPartialFile : Boolean; public property PartialFile : Boolean read FPartialFile write FPartialFile; end;type TAbCabCompressionType = (ctNone, ctMSZIP, ctLZX); TAbCabinetMode = (cmRead, cmWrite); TAbCabStatus = (csFile, csFolder, csCabinet);const faExtractAndExecute = $040; AbDefCabSpanningThreshold = 0; AbDefFolderThreshold = 0; AbDefCompressionType = ctMSZIP; AbDefReserveHeaderSize = 0; AbDefReserveFolderSize = 0; AbDefReserveDataSize = 0; AbDefLZXWindowSize = 18; CompressionTypeMap : array[TAbCabCompressionType] of Word = (0, 1, 4611);type TAbCabArchive = class(TAbArchive) protected {private} {internal variables} FCabName : array[0..255] of Char; FCabPath : array[0..255] of Char; FFCICabInfo : FCICabInfo; FFCIContext : HFCI; FFDIContext : HFDI; FFDICabInfo : FDICabInfo; FErrors : CabErrorRecord; FFileHandle : Integer; FItemInProgress : TAbCabItem; FItemProgress : DWord; FNextCabinet : string; FNextDisk : string; FTempFileID : Integer; {property variables} FCurrentCab : Word; FCabSize : Longint; FCompressionType : TAbCabCompressionType; FFileCount : Word; FFolderThreshold : Longint; FFolderCount : Word; FHasPrev : Boolean; FHasNext : Boolean; FSetID : Word; {internal methods} procedure CloseCabFile; procedure CreateCabFile; function CreateItem( const FileSpec : string ): TAbArchiveItem; override; procedure DoCabItemProcessed; procedure DoCabItemProgress(BytesCompressed : DWord; var Abort : Boolean); procedure DoConfirmOverwrite(var FileName : string; var Confirm : Boolean); virtual; procedure DoGetNextCabinet(CabIndex : Integer; var CabName : string; var Abort : Boolean); procedure ExtractItemAt(Index : Integer; const NewName : string); override; procedure ExtractItemToStreamAt(Index : Integer; OutStream : TStream); override; function GetItem(ItemIndex : Integer) : TAbCabItem; procedure LoadArchive; override; procedure OpenCabFile; procedure PutItem( Index : Integer; Value : TAbCabItem ); procedure SaveArchive; override; procedure SetFolderThreshold(Value : Longint); procedure SetSetID(Value : Word); procedure SetSpanningThreshold(Value : Longint); override; procedure TestItemAt(Index : Integer); override; public {methods} constructor Create(FileName : string; Mode : Word); override; destructor Destroy; override; procedure Add(aItem : TAbArchiveItem); override; procedure NewCabinet; procedure NewFolder; public {properties} property CurrentCab : Word read FCurrentCab; property CabSize : Longint read FCabSize; property CompressionType : TAbCabCompressionType read FCompressionType write FCompressionType; property FolderThreshold : Longint read FFolderThreshold write SetFolderThreshold; property FolderCount : Word read FFolderCount; property HasPrev : Boolean read FHasPrev; property HasNext : Boolean read FHasNext; property Items[Index : Integer] : TAbCabItem read GetItem write PutItem; default; property ItemProgress : DWord read FItemProgress write FItemProgress; property SetID : Word read FSetID write SetSetID; end;function VerifyCab(const Fn : string) : TAbArchiveType;implementationtype PWord = ^Word; PInteger = ^Integer;function VerifyCab(const Fn : string) : TAbArchiveType;var CabArchive : TAbCabArchive;begin Result := atCab; CabArchive := TAbCabArchive.Create(Fn, fmOpenRead or fmShareDenyNone); try CabArchive.LoadArchive; except on EAbFDICreateError do Result := atUnknown; end;end;{ == FDI/FCI Callback Functions - cdecl calling convention ================= }function FXI_GetMem(uBytes : Integer) : Pointer; cdecl; {allocate memory}begin Result := nil; if (uBytes > 0) then GetMem(Result, uBytes);end;{ -------------------------------------------------------------------------- }procedure FXI_FreeMem(lpBuffer : Pointer); cdecl; {free memory}begin Dispose(lpBuffer);end;{ == FCI Callback Functions - cdecl calling convention ===================== }function FCI_FileOpen(lpPathName: PChar; Flag, Mode: Integer; PError: PInteger; Archive: TAbCabArchive) : HFILE; cdecl; {open a file}begin Result := _lcreat(lpPathName, 0); if (Result = HFILE_ERROR) then raise EAbFCIFileOpenError.Create;end;{ -------------------------------------------------------------------------- }function FCI_FileRead(hFile: HFILE; lpBuffer: Pointer; uBytes: UINT; PError: PInteger; Archive: TAbCabArchive) : HFILE; cdecl; {read from a file}begin Result := _lread(hFile, lpBuffer, uBytes); if (Result = HFILE_ERROR) then raise EAbFCIFileReadError.Create;end;{ -------------------------------------------------------------------------- }function FCI_FileWrite(hFile: HFILE; lpBuffer: Pointer; uBytes: UINT; PError: PInteger; Archive: TAbCabArchive) : HFILE; cdecl; {write to a file}begin Result := _lwrite(hFile, lpBuffer, uBytes); if (Result = HFILE_ERROR) then raise EAbFCIFileWriteError.Create;end;{ -------------------------------------------------------------------------- }function FCI_FileClose(hFile: HFILE; PError: PInteger; Archive: TAbCabArchive) : HFILE; cdecl; {close a file}begin Result := _lclose(hFile); if (Result = HFILE_ERROR) then raise EAbFCIFileCloseError.Create;end;{ -------------------------------------------------------------------------- }function FCI_FileSeek(hFile: HFILE; Offset: Longint; Origin: Integer; PError: PInteger; Archive: TAbCabArchive) : Longint; cdecl; {reposition file pointer}begin Result := _llseek(hFile, Offset, Origin); if (Result = -1) then raise EAbFCIFileSeekError.Create;end;{ -------------------------------------------------------------------------- }function FCI_FileDelete(lpFilename: PChar; PError: PInteger; Archive: TAbCabArchive) : Boolean; cdecl; {delete a file}begin Result := SysUtils.DeleteFile(StrPas(lpFilename)); if (Result = False) then raise EAbFCIFileDeleteError.Create;end;{ -------------------------------------------------------------------------- }function FCI_GetNextCab(lpCCab: PFCICabInfo; PrevCab: Longint; Archive: TAbCabArchive) : Boolean; cdecl; {get next cabinet filename}var CabName : string; Abort : Boolean;begin Abort := False; with lpCCab^ do begin CabName := StrPas(szCab); {!!.02} {obtain next cabinet. Make index zero-based} Archive.DoGetNextCabinet(Pred(iCab), CabName, Abort); if not Abort then StrPCopy(szCab, CabName); {!!.02} end; Result := not Abort;end;{ -------------------------------------------------------------------------- }function FCI_FileDest(PCCab: PFCICabInfo; PFilename: PChar; cbFile: Longint; Continuation: Boolean; Archive: TAbCabArchive) : Integer; cdecl; {currently not used}begin Result := 0;end;{ -------------------------------------------------------------------------- }function FCI_GetOpenInfo(lpPathname: PChar; PDate, PTime, PAttribs : PWord; PError: PInteger; Archive: TAbCabArchive) : Integer; cdecl; {open a file and return date/attributes}var DT : Integer;begin Result := _lopen(lpPathname, OF_READ or OF_SHARE_DENY_NONE); if (Result = -1) then raise EAbFCIFileOpenError.Create; PAttribs^ := AbFileGetAttr(StrPas(lpPathname)); DT := FileGetDate(Result); PDate^ := DT shr 16; PTime^ := DT and $0FFFF; Archive.ItemProgress := 0;end;{ -------------------------------------------------------------------------- }function FCI_Status(Status: Word; cb1, cb2: DWord; Archive: TAbCabArchive) : Longint; cdecl; {keep archive informed}var Abort : Boolean;begin Result := 0; if (Status = Word(csCabinet)) then begin Archive.DoSave; Archive.FCabSize := cb2; Result := cb2; end else if (Status = Word(csFolder)) then Archive.FCabSize := Archive.FCabSize + Longint(cb2) else if (Status = Word(csFile)) then begin Archive.DoCabItemProgress(cb2, Abort); Result := Longint(Abort); end;end;{ -------------------------------------------------------------------------- }function FCI_GetTempFile(lpTempName: PChar; TempNameSize: Integer; Archive: TAbCabArchive) : Integer; cdecl; {obtain temporary filename}var TempPath : array[0..255] of Char; Prefix : array[0..10] of Char;begin Archive.FTempFileID := Archive.FTempFileID + 1; StrPCopy(Prefix, 'VMS'); if (Archive.TempDirectory <> '') then StrPCopy(TempPath, Archive.TempDirectory) {!!.02} else GetTempPath(255, TempPath); {!!.02} GetTempFileName(TempPath, Prefix, Archive.FTempFileID, lpTempName); {!!.02} Result := 1;end;{ == FDI Callback Functions - cdecl calling convention ===================== }function FDI_FileOpen(lpPathName: PChar; Flag, Mode: Integer) : Integer; cdecl; {open a file}begin Result := _lopen(lpPathName, Mode);end;{ -------------------------------------------------------------------------- }function FDI_FileRead(hFile: HFILE; lpBuffer: Pointer; uBytes: UINT) : UINT; cdecl; {read from a file}begin Result := _lread(hFile, lpBuffer, uBytes);end;{ -------------------------------------------------------------------------- }function FDI_FileWrite(hFile: HFILE; lpBuffer: Pointer; uBytes: UINT) : UINT; cdecl; {write to a file}begin Result := _lwrite(hFile, lpBuffer, uBytes);end;{ -------------------------------------------------------------------------- }procedure FDI_FileClose(hFile : HFILE); cdecl; {close a file}begin _lclose(hFile);end;{ -------------------------------------------------------------------------- }function FDI_FileSeek(hFile : HFILE; Offset : Longint; Origin : Integer) : Longint; cdecl; {reposition file pointer}begin Result := _llseek(hFile, Offset, Origin);end;{ -------------------------------------------------------------------------- }function FDI_EnumerateFiles(fdint : FDINOTIFICATIONTYPE; pfdin : PFDINotification) : Integer; cdecl; {Enumerate the files and build the archive file list}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -