⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kpzipobj.pas

📁 delphi实现 webservice的例子.有服务端和客户段 利用xml交互.
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    finfo.ecrec := Fecrec;
    if (Fecrec.zip_comment_length > 0) and (FZipComment <> nil) then
    begin
      if finfo.ZipComment <> nil then
        StrDispose(finfo.ZipComment);
      finfo.ZipComment := StrAlloc(StrLen(FZipComment) + 1);
      StrCopy(finfo.ZipComment, FZipComment);
      finfo.zip_comment_length := StrLen(finfo.ZipComment);
    end;
    finfo.ZipCommentPos := FZipCommentPos;
  end
  else
    inherited AssignTo(Dest);
end;

procedure TEndCentral.Assign(Source: TPersistent);
var
  finfo: TEndCentral;
begin
  if Source is TEndCentral then
  begin
    finfo := TEndCentral(Source);
    Fecrec := finfo.ecrec;
    if (finfo.zip_comment_length > 0) and (finfo.ZipComment <> nil) then
    begin
      if FZipComment <> nil then
        StrDispose(FZipComment);
      FZipComment := StrAlloc(StrLen(finfo.ZipComment) + 1);
      StrCopy(FZipComment, finfo.ZipComment);
      Fecrec.zip_comment_length := StrLen(FZipComment);
    end;
    FZipCommentPos := finfo.ZipCommentPos;
  end
  else
    inherited Assign(Source);
end;

procedure TEndCentral.SetFromEndCentral(crec: end_of_centralPtr);
begin
  Fecrec := crec^;
  FZipCommentPos := 0;
  if FZipComment <> nil then
    StrDispose(FZipComment);
  FZipComment := nil;
end;

procedure TEndCentral.Clear;
begin
  with Fecrec do
  begin
    ID := ENDSIG;
    this_disk := 0;
    start_central_disk := 0;
    num_entries_this_disk := 0;
    num_entries := 0;
    size_central := 0;
    offset_central := 0;
    zip_comment_length := 0;
  end;
  if (FZipComment <> nil) then
    StrDispose(FZipComment);
  FZipComment := nil;
  FZipCommentPos := 0;
  FModified := False;
end;

procedure TEndCentral.SaveToStream(S: TkpStream);
var
  Zip64Needed: Boolean;
begin
{ DONE :
Add code to check to see if there SHOULD be a zip64 end of central
record at all. }
  if (FZip64EOC <> nil) then
  begin
    Zip64Needed := False;
    FZip64EOCL_Instance^.offset_zip64_end_central := S.Position;
    FZip64EOCL_Instance^.num_disk_start_zip64_end_central := Fecrec.this_disk;
    FZip64EOCL_Instance^.num_disks := Fecrec.this_disk + 1;
    if (Fecrec.start_central_disk <> $FFFF) then
      FZip64EOC^.start_central_disk := Fecrec.start_central_disk
    else
      Zip64Needed := True;
    if (Fecrec.this_disk <> $FFFF) then
      FZip64EOC^.this_disk := Fecrec.this_disk
    else
      Zip64Needed := True;
    if (Fecrec.num_entries_this_disk <> $FFFF) then
      FZip64EOC^.num_entries_this_disk := Fecrec.num_entries_this_disk
    else
      Zip64Needed := True;
    if (Fecrec.num_entries <> $FFFF) then
      FZip64EOC^.num_entries := Fecrec.num_entries
    else
      Zip64Needed := True;
    if (Fecrec.size_central <> $FFFFFFFF) then
      FZip64EOC^.size_central := Fecrec.size_central
    else
      Zip64Needed := True;
    if (Fecrec.offset_central <> $FFFFFFFF) then
      FZip64EOC^.offset_central := Fecrec.offset_central
    else
      Zip64Needed := True;
    if (Zip64Needed) then
    begin
      S.Write(FZip64EOC^, SizeOf(zip64_end_of_central));
      S.Write(FZip64EOCL^, Sizeof(zip64_end_of_central_locator));
    end
    else
    begin
      FreeMem(FZip64EOC, sizeof(zip64_end_of_central));
      FZip64EOC := nil;
      FreeMem(FZip64EOCL, sizeof(zip64_end_of_central_locator));
      FZip64EOCL := nil;
    end;
  end;
  S.Write(Fecrec, SizeOf(Fecrec));
  if (Fecrec.zip_comment_length > 0) and (FZipComment <> nil) then
    S.Write(FZipComment^, StrLen(FZipComment));
end;

function TEndCentral.ReadFromStream(S: TkpStream): Boolean;
var
  tmpBuff: PChar;
  tmpBuffsize: LongInt;
  peoc: end_of_centralPtr;
  j: LongInt;
  AmtRead: LongInt;
  zip64Locator: zip64_end_of_central_locatorPtr;

const
{$IFDEF WIN32} { 5/23/99 2.18+ }
  TBUFFSIZE = 65535 + SizeOf(end_of_central);
{$ELSE}
  TBUFFSIZE = $FFF8;
{$ENDIF}
begin
  Result := False;
  if S.Size < sizeof(end_of_central) then
  begin
    if S.Size = 0 then { 7/31/99 2.18+ }
      Result := True; { handle 0 length files }
    exit; { 1/28/98 v2.00+}
  end;
  tmpBuffsize := kpmin(S.Size, TBUFFSIZE);
  S.Seek(-tmpBuffsize, soEnd);
  GetMem(tmpBuff, tmpBuffsize);
  try
    AmtRead := S.Read(tmpBuff^, tmpBuffsize);
    if AmtRead <> tmpBuffsize then
      exit;
    j := tmpBuffsize - (sizeof(end_of_central));
    peoc := nil;
    while (j >= 0) and (peoc = nil) do
    begin
      while (j >= 0) and (Byte(tmpBuff[j]) <> END4) do
        Dec(j);
      if (j < 0) then
        break;
      peoc := end_of_centralPtr(@tmpBuff[j]); { added typecast 5/18/98  2.13 }
      if peoc^.ID <> ENDSIG then
      begin
        Dec(j);
        peoc := nil;
      end;
    end;
    if peoc = nil then
      exit;
    with Fecrec do
    begin
      this_disk := peoc^.this_disk;
      start_central_disk := peoc^.start_central_disk;
      num_entries_this_disk := peoc^.num_entries_this_disk;
      num_entries := peoc^.num_entries;
      size_central := peoc^.size_central;
      offset_central := peoc^.offset_central;
      zip_comment_length := peoc^.zip_comment_length;
     {FZipHasComment := ecrec.zip_comment_length > 0;}
     {ZipCommentPos := S.Size -  Fecrec.zip_comment_length;}{ 06/03/00 2.21b2+ }
      ZipCommentPos := S.Size - tmpBuffsize + j + sizeof(end_of_central);
    end;
    //if (Fecrec.offset_central = $FFFFFFFF) or (FEcrec.num_entries = $FFFF) then
    begin
      j := j - SizeOf(zip64_end_of_central_locator);
      zip64Locator := zip64_end_of_central_locatorPtr(@tmpBuff[j]);
      if (zip64Locator^.ID = ZIP64EOCL) then
      begin
            // FZip64EOCL := AllocMem(SizeOf(zip64_end_of_central_locator));
        FZip64EOCL_Instance^.ID := zip64Locator^.ID;
        FZip64EOCL_Instance^.num_disk_start_zip64_end_central :=
          zip64Locator^.num_disk_start_zip64_end_central;
        FZip64EOCL_Instance^.offset_zip64_end_central :=
          zip64Locator^.offset_zip64_end_central;
        FZip64EOCL_Instance^.num_disks := zip64Locator^.num_disks;
        S.Seek(FZip64EOCL_Instance^.offset_zip64_end_central, soBeginning);
        S.Read(FZip64EOC_Instance^, SizeOf(zip64_end_of_central));
      end;
    end;
    Result := True;
  finally
    FreeMem(tmpBuff, tmpBuffsize);
  end;
end;

function TEndCentral.GetZipHasComment: Boolean;
begin
  Result := (zip_comment_length > 0);
end;

procedure TEndCentral.SetNewZipComment(NewComment: string);
begin
  if FZipComment <> nil then
    StrDispose(FZipComment);
  FZipComment := StrToPChar(NewComment);
  Fecrec.zip_comment_length := Length(NewComment);
end;

function TEndCentral.GetZipComment(S: TkpStream): PChar;
begin
  if Fecrec.zip_comment_length = 0 then
    Result := nil
  else if FZipComment <> nil then
    Result := FZipComment
  else
    with Fecrec do
    begin
      S.Seek(FZipCommentPos, soBeginning);
      Result := StrAlloc(zip_comment_length + 1);
      S.Read(Result^, zip_comment_length);
      Result[zip_comment_length] := #0;
    end;
end;

function TEndCentral.GetEndCentralSize: LongInt;
begin
  Result := SizeOf(end_of_central) + Fecrec.zip_comment_length;
end;

function TEndCentral.GetThis_Disk: LongWord;
begin
  if (Fecrec.this_disk = $FFFF) and (FZip64EOC <> nil) then
    Result := FZip64EOC^.this_disk
  else
    Result := Fecrec.this_disk;
end;

procedure TEndCentral.SetThis_Disk(disk: LongWord);
begin
  if (disk <= $FFFE) then
    Fecrec.This_Disk := disk
  else
  begin
    FZip64EOC_Instance^.This_Disk := disk;
    Fecrec.This_Disk := $FFFF;
  end;
end;

function TEndCentral.GetStart_Central_Disk: LongWord;
begin
  if (Fecrec.start_central_disk = $FFFF) and (FZip64EOC <> nil) then
    Result := FZip64EOC^.start_central_disk
  else
    Result := Fecrec.start_central_disk;
end;

procedure TEndCentral.SetStart_Central_Disk(disk: LongWord);
begin
  if (disk <= $FFFE) then
    Fecrec.Start_Central_Disk := disk
  else
  begin
    FZip64EOC_Instance^.Start_Central_Disk := disk;
    Fecrec.Start_Central_Disk := $FFFF;
  end;
end;

function TEndCentral.GetNum_Entries_This_Disk: LongWord;
begin
  if (Fecrec.num_entries_this_disk = $FFFF) and (FZip64EOC <> nil) then
    Result := FZip64EOC^.num_entries_this_disk
  else
    Result := Fecrec.num_entries_this_disk;
end;

procedure TEndCentral.SetNum_Entries_This_Disk(entries: LongWord);
begin
  if (entries <= $FFFE) then
  begin
    Fecrec.Num_Entries_This_Disk := entries;
    if (FZip64EOC <> nil) then
      FZip64EOC^.num_entries_this_disk := entries;
  end
  else
  begin
    FZip64EOC_Instance^.Num_Entries_This_Disk := entries;
    Fecrec.Num_Entries_This_Disk := $FFFF;
  end;
end;

function TEndCentral.GetNum_Entries: BIGINT;
begin
  if (Fecrec.num_entries = $FFFF) and (FZip64EOC <> nil) then
    Result := FZip64EOC^.num_entries
  else
    Result := Fecrec.num_entries;
end;

procedure TEndCentral.SetNum_Entries(entries: BIGINT);
begin
  if (entries <= $FFFE) then
  begin
    Fecrec.Num_Entries := entries;
    if (FZip64EOC <> nil) then
      FZip64EOC^.num_entries := entries;
  end
  else
  begin
    FZip64EOC_Instance^.Num_Entries := entries;
    Fecrec.Num_Entries := $FFFF;
  end;
end;

function TEndCentral.GetSize_Central: BIGINT;
begin
  if (Fecrec.size_central = $FFFFFFFF) and (FZip64EOC <> nil) then
    Result := FZip64EOC^.size_central
  else
    Result := Fecrec.size_central;
end;

procedure TEndCentral.SetSize_Central(size: BIGINT);
begin
  if (size <= $FFFFFFFE) then
  begin
    Fecrec.Size_Central := size;
    if (FZip64EOC <> nil) then
      FZip64EOC^.size_central := size;
  end
  else
  begin
    FZip64EOC_Instance^.Size_Central := size;
    Fecrec.Size_Central := $FFFFFFFF;
  end;
end;


function TEndCentral.GetOffset_Central: BIGINT;
begin
  if (Fecrec.offset_central = $FFFFFFFF) and (FZip64EOC <> nil) then
    Result := FZip64EOC^.offset_central
  else
    Result := Fecrec.offset_central;
end;

procedure TEndCentral.SetOffset_Central(offset: BIGINT);
begin
  if (offset <= $FFFFFFFE) then
    Fecrec.offset_central := offset
  else
  begin
    FZip64EOC_Instance^.offset_central := offset;
    Fecrec.offset_central := $FFFFFFFF;
  end;
end;

function TEndCentral.Getnum_disk_start_zip64_end_central: LongWord;
begin
  Result := 0;
  if (FZip64EOCL <> nil) then
    Result := FZip64EOCL^.num_disk_start_zip64_end_central;
end;

procedure TEndCentral.Setnum_disk_start_zip64_end_central(numDisk: LongWord);
begin
  FZip64EOCL_Instance^.num_disk_start_zip64_end_central := numDisk;
end;

function TEndCentral.Getoffset_zip64_end_central: BIGINT;
begin
  Result := 0;
  if (FZip64EOCL <> nil) then
    Result := FZip64EOCL^.offset_zip64_end_central;
end;

procedure TEndCentral.Setoffset_zip64_end_central(offset: BIGINT);
begin
  FZip64EOCL_Instance^.offset_zip64_end_central := offset;
end;

function TEndCentral.Getnum_disks: LongWord;
begin
  Result := 0;
  if (FZip64EOCL <> nil) then
    Result := FZip64EOCL^.num_disks;
end;

procedure TEndCentral.Setnum_disks(numDisks: LongWord);
begin
  FZip64EOCL_Instance^.num_disks := numDisks;
end;

function TEndCentral.GetNewFZip64EOC: zip64_end_of_centralPtr;
begin
  Result := AllocMem(SizeOf(zip64_end_of_central));
  Result^.ID := DEF_ZIP64ENDSIG;
  Result^.size := 44;
  Result^.version_made_by := 45;
  Result^.version_needed := 45;
  Result^.this_disk := 0;
  Result^.start_central_disk := 0;
  Result^.num_entries_this_disk := 0;
  Result^.num_entries := 0;
  Result^.size_central := 0;
  Result^.offset_central := 0;
end;

function TEndCentral.GetNewFZip64EOCL: zip64_end_of_central_locatorPtr;
begin
  Result := AllocMem(SizeOf(zip64_end_of_central_locator));
  Result^.ID := DEF_ZIP64LOCATOR;
  Result^.num_disk_start_zip64_end_central := 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -