Модуль "P2KApi" (часть 33) - TP2KAPI.File_Write

Рубрика: Исходники
Среда, 21 апреля 2010 г.
Просмотров: 156
последняя версия: 3.0.9 build 961 beta
от 07 декабря 2007 г.
function TP2KAPI.File_Write(AFileName: string; ASize: dword; AStream: TStream; ADest: string; AfrmProgress: TfrmProgress): boolean;
var
  pFSACWrite: PTCIFSACStruct;
  pFSACWrite05: PTCIPacket05;
  pAnswerData: pbytearray;
  TCICmd_code: word;
  ssize: word;
  xSize: integer;
  LoadSize: integer;
  f: integer;
  curOper: string;
  xx: dword;

begin
  result:= false;
  if not TelStatus then exit;
  New(pFSACWrite);
  New(pFSACWrite05);
  pAnswerData:= AllocMem($FA4);
  try
    TCICmd_code:= $4A;
    FillTCIFSACStruct(ssize, TCICmd_Code, pFSACWrite);
    FillTCIFSACStructEx(ssize, TCICmd_Code, pFSACWrite05);
    FillMemory(@pFSACWrite^.OtherData, 8 + 1024, 0);
    FillMemory(@pFSACWrite05^.OtherData, 8 + 1024, 0);
    f:= convert_word(FSACWRITEFL);
    CopyMemory(@pFSACWrite^.OtherData[2], @f, 2);
    CopyMemory(@pFSACWrite05^.OtherData[2], @f, 2);
    //pFileBuff:= AllocMem(1024);
    xSize:= 0;
    while xSize<ASize do
      begin
        if ((ASize-xSize)<1024)  and ((ASize-xSize)>0)
          then begin
                 ssize:= $8 +(ASize-xSize);
                 LoadSize:=ASize-xSize;
                 xSize:=xSize+(ASize-xSize);
               end
          else begin
                 ssize:= 8 + 1024;
                 xSize:=xSize+1024;
                 LoadSize:=1024;
               end;
        f:= Random(MaxInt);
        pFSACWrite^.PackedSize:= ssize + 8;
        ///pFSACWrite05^.PackedSize:= ssize + 8 + 4;
        pFSACWrite^.PackedID:= convert_word(f);
        pFSACWrite05^.ID:= convert_word(f);
        pFSACWrite^.cmdSize:= convert_word(ssize);
        pFSACWrite05^.cmdSize:= convert_word(ssize);        
        f:= convert_word(LoadSize);;
        CopyMemory(@pFSACWrite^.OtherData[6], @f, 2);
        CopyMemory(@pFSACWrite05^.OtherData[6], @f, 2);
        if iP2KCF = 0 then AStream.Read(pFSACWrite^.OtherData[8], LoadSize)
                      else AStream.Read(pFSACWrite05^.OtherData[8], LoadSize);
        FillMemory(pAnswerData, 26, 0);
        xx:= 26;
        if iP2KCF = 0
          then begin
                 result:= SendCommand(pFSACWrite, ssize+$10, Pointer(pAnswerData), xx, xP2KTimeOut);
               end
          else begin
                 result:= SendCommand05(TCICmd_code, pFSACWrite05, ssize, Pointer(pAnswerData), xx, xP2KTimeOut);
               end;  
        AfrmProgress.AdvProgressBar1.Value:=  xSize;
        AfrmProgress.AdvProgressBar2.Value:=  AfrmProgress.AdvProgressBar2.Value + LoadSize;
        Application.ProcessMessages;
        //$$AfrmProgress.Update;
      end;
  finally
    FreeMem(pAnswerData, $FA4);
    Dispose(pFSACWrite);
    Dispose(pFSACWrite05);    
  end;
end;
Rambler's Top100