📄 abziptyp.pas
字号:
Read( FExtraFieldLength, sizeof( FExtraFieldLength ) ); Read( FFileCommentLength, sizeof( FFileCommentLength ) ); Read( FDiskNumberStart, sizeof( FDiskNumberStart ) ); Read( FInternalFileAttributes, sizeof( FInternalFileAttributes ) ); Read( FExternalFileAttributes, sizeof( FExternalFileAttributes ) ); Read( FRelativeOffset, sizeof( FRelativeOffset ) ); FFileName := StrAlloc( succ( FFileNameLength ) ); Read( FFileName^, FFileNameLength ); FFileName[FFileNameLength] := #0; if FExtraFieldLength > 0 then begin FExtraField := StrAlloc( succ( FExtraFieldLength ) ); Read( FExtraField^, FExtraFieldLength ); FExtraField[FExtraFieldLength] := #0; end; if FFileCommentLength > 0 then begin FFileComment := StrAlloc( succ( FFileCommentLength ) ); Read( FFileComment^, FFileCommentLength ); FFileComment[FFileCommentLength] := #0; end; end; if not IsValid then raise EAbZipInvalid.Create;end;{ -------------------------------------------------------------------------- }procedure TAbZipDirectoryFileHeader.SaveToStream( Stream : TStream );begin with Stream do begin {write the valid signature from the constant} Write( FValidSignature, sizeof( FValidSignature ) ); Write( FVersionMadeBy, sizeof( FVersionMadeBy ) ); Write( FVersionNeededToExtract, sizeof( FVersionNeededToExtract ) ); Write( FGeneralPurposeBitFlag, sizeof( FGeneralPurposeBitFlag ) ); Write( FCompressionMethod, sizeof( FCompressionMethod ) ); Write( FLastModFileTime, sizeof( FLastModFileTime ) ); Write( FLastModFileDate, sizeof( FLastModFileDate ) ); Write( FCRC32, sizeof( FCRC32 ) ); Write( FCompressedSize, sizeof( FCompressedSize ) ); Write( FUncompressedSize, sizeof( FUncompressedSize ) ); Write( FFileNameLength, sizeof( FFileNameLength ) ); Write( FExtraFieldLength, sizeof( FExtraFieldLength ) ); Write( FFileCommentLength, sizeof( FFileCommentLength ) ); Write( FDiskNumberStart, sizeof( FDiskNumberStart ) ); Write( FInternalFileAttributes, sizeof( FInternalFileAttributes ) ); Write( FExternalFileAttributes, sizeof( FExternalFileAttributes ) ); Write( FRelativeOffset, sizeof( FRelativeOffset ) ); Write( FFileName^, FFileNameLength ); Write( FExtraField^, FExtraFieldLength ); Write( FFileComment^, FFileCommentLength ); end;end;{ -------------------------------------------------------------------------- }{ TAbZipDirectoryFileFooter implementation ================================= }constructor TAbZipDirectoryFileFooter.Create;begin inherited Create; FValidSignature := Ab_ZipEndCentralDirectorySignature; FZipfileComment := nil;end;{ -------------------------------------------------------------------------- }destructor TAbZipDirectoryFileFooter.Destroy;begin if Assigned( FZipfileComment ) then StrDispose( FZipfileComment ); inherited Destroy;end;{ -------------------------------------------------------------------------- }function TAbZipDirectoryFileFooter.GetValid : Boolean;begin Result := (FSignature = FValidSignature);end;{ -------------------------------------------------------------------------- }procedure TAbZipDirectoryFileFooter.LoadFromStream( Stream : TStream );begin with Stream do begin Read( FSignature, sizeof( FSignature ) ); Read( FDiskNumber, sizeof( FDiskNumber ) ); Read( FStartDiskNumber, sizeof( FStartDiskNumber ) ); Read( FEntriesOnDisk, sizeof( FEntriesOnDisk ) ); Read( FTotalEntries, sizeof( FTotalEntries ) ); Read( FDirectorySize, sizeof( FDirectorySize ) ); Read( FDirectoryOffset, sizeof( FDirectoryOffset ) ); Read( FZipfileCommentLength, sizeof( FZipfileCommentLength ) ); if FZipfileCommentLength > 0 then begin FZipfileComment := StrAlloc( succ( FZipfileCommentLength ) ); Read( FZipfileComment^, FZipfileCommentLength ); FZipfileComment[FZipfileCommentLength] := #0; end; end; if not IsValid then raise EAbZipInvalid.Create;end;{ -------------------------------------------------------------------------- }procedure TAbZipDirectoryFileFooter.SaveToStream( Stream : TStream );begin with Stream do begin Write( FValidSignature, sizeof( FValidSignature ) ); Write( FDiskNumber, sizeof( FDiskNumber ) ); Write( FStartDiskNumber, sizeof( FStartDiskNumber ) ); Write( FEntriesOnDisk, sizeof( FEntriesOnDisk ) ); Write( FTotalEntries, sizeof( FTotalEntries ) ); Write( FDirectorySize, sizeof( FDirectorySize ) ); Write( FDirectoryOffset, sizeof( FDirectoryOffset ) ); Write( FZipfileCommentLength, sizeof( FZipfileCommentLength ) ); Write( FZipfileComment^, FZipfileCommentLength ); end;end;{ -------------------------------------------------------------------------- }{ TAbZipItem implementation ================================================ }constructor TAbZipItem.Create;begin inherited Create; FItemInfo := TAbZipDirectoryFileHeader.Create; FDecoder := nil;end;{ -------------------------------------------------------------------------- }destructor TAbZipItem.Destroy;begin FItemInfo.Free; FItemInfo := nil; FDecoder.Free; FDecoder := nil; inherited Destroy;end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetCompressedSize : Longint;begin Result := FItemInfo.CompressedSize;end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetCompressionMethod : TAbZipCompressionMethod;begin Result := FItemInfo.CompressionMethod;end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetCompressionRatio : Double;begin Result := FItemInfo.CompressionRatio;end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetCRC32 : Longint;begin Result := FItemInfo.CRC32;end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetDeflationOption : TAbZipDeflationOption;begin Result := FItemInfo.DeflationOption;end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetDictionarySize : TAbZipDictionarySize;begin Result := FItemInfo.DictionarySize;end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetGeneralPurposeBitFlag : Word;begin Result := FItemInfo.GeneralPurposeBitFlag;end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetDiskNumberStart : Word;begin Result := FItemInfo.DiskNumberStart;end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetExternalFileAttributes : Longint;begin Result := FItemInfo.ExternalFileAttributes;end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetExtraField : string;begin if Assigned( FItemInfo ) and ( FItemInfo.ExtraField <> nil ) then Result := StrPas( FItemInfo.ExtraField ) else Result := '';end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetFileComment : string;begin if Assigned( FItemInfo ) and ( FItemInfo.FileComment <> nil ) then Result := StrPas( FItemInfo.FileComment ) else Result := '';end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetFileName : string;var Buff : array [0..MAX_PATH] of Char;begin if Assigned( FItemInfo ) and ( FItemInfo.FileName <> nil ) then begin StrCopy(Buff, FItemInfo.FileName);{!!.03 - Added }{$IFDEF Linux} { do nothing to Buff }{$ELSE} if AreFileApisANSI then begin OEMToAnsi(Buff, Buff); end;{$ENDIF}{!!.03 - End Added } Result := StrPas(Buff) end else Result := '';end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetInternalFileAttributes : Word;begin Result := FItemInfo.InternalFileAttributes;end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetIsEncrypted : Boolean;begin Result := FItemInfo.IsEncrypted;end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetLastModFileDate : Word;begin Result := FItemInfo.LastModFileDate;end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetLastModFileTime : Word;begin Result := FItemInfo.LastModFileTime;end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetRelativeOffset : Longint;begin Result := FItemInfo.RelativeOffset;end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetShannonFanoTreeCount : Byte;begin Result := FItemInfo.ShannonFanoTreeCount;end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetUncompressedSize : Longint;begin Result := FItemInfo.UncompressedSize;end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetVersionMadeBy : Word;begin Result := FItemInfo.VersionMadeBy;end;{ -------------------------------------------------------------------------- }function TAbZipItem.GetVersionNeededToExtract : Word;begin Result := FItemInfo.VersionNeededToExtract;end;{ -------------------------------------------------------------------------- }procedure TAbZipItem.LoadFromStream( Stream : TStream );begin FItemInfo.LoadFromStream( Stream ); if FItemInfo.FileName <> nil then FFileName := StrPas( FItemInfo.FileName ) else FFileName := ''; LastModFileTime := FItemInfo.LastModFileTime; LastModFileDate := FItemInfo.LastModFileDate; DiskFileName := FileName; AbUnfixName( FDiskFileName ); Action := aaNone; Tagged := False;end;{ -------------------------------------------------------------------------- }procedure TAbZipItem.SaveLFHToStream( Stream : TStream );var LFH : TAbZipLocalFileHeader; Temp : PChar;begin LFH := TAbZipLocalFileHeader.Create; try LFH.VersionNeededToExtract := VersionNeededToExtract; LFH.GeneralPurposeBitFlag := GeneralPurposeBitFlag; LFH.CompressionMethod := CompressionMethod; LFH.LastModFileTime := LastModFileTime; LFH.LastModFileDate := LastModFileDate; LFH.CRC32 := CRC32; LFH.CompressedSize := CompressedSize; LFH.UncompressedSize := UncompressedSize; if Length( FileName ) > 0 then begin Temp := StrAlloc( succ( Length( FileName ) ) ); try StrPCopy( Temp, FileName ); LFH.FileName := Temp; finally StrDispose( Temp ); end; end; if Length( ExtraField ) > 0 then begin Temp := StrAlloc( succ( Length( ExtraField ) ) ); try StrPCopy( Temp, ExtraField ); LFH.ExtraField := Temp; finally StrDispose( Temp ); end; end; LFH.SaveToStream( Stream ); finally LFH.Free; end;end;{ -------------------------------------------------------------------------- }procedure TAbZipItem.SaveCDHToStream( Stream : TStream ); {-Save a ZipCentralDirectorHeader entry to Stream}begin FItemInfo.SaveToStream( Stream );end;{ -------------------------------------------------------------------------- }procedure TAbZipItem.SaveDDToStream( Stream : TStream );var DD : TAbZipDataDescriptor;begin DD := TAbZipDataDescriptor.Create; try DD.CRC32 := CRC32; DD.CompressedSize := CompressedSize; DD.UncompressedSize := UncompressedSize; DD.SaveToStream( Stream ); finally DD.Free; end;end;{ -------------------------------------------------------------------------- }procedure TAbZipItem.SetCompressedSize( const Value : Longint );begin FItemInfo.CompressedSize:= Value;end;{ -------------------------------------------------------------------------- }procedure TAbZipItem.SetCompressionMethod( Value : TAbZipCompressionMethod );begin FItemInfo.CompressionMethod := Value;end;{ -------------------------------------------------------------------------- }procedure TAbZipItem.SetCRC32( const Value : Longint );begin FItemInfo.CRC32 := Value;end;{ -------------------------------------------------------------------------- }procedure TAbZipItem.SetDiskNumberStart( Value : Word );begin FItemInfo.DiskNumberStart := Value;end;{ -------------------------------------------------------------------------- }procedure TAbZipItem.SetExternalFileAttributes( Value : Longint );begin FItemInfo.ExternalFileAttributes := Value;end;{ -------------------------------------------------------------------------- }procedure TAbZipItem.SetExtraField( Value : string );begin FItemInfo.ExtraFieldLength := Length( Value ); if Assigned( FItemInfo.FExtraField ) then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -