Einzelnen Beitrag anzeigen

wurzelzwerg

Registriert seit: 19. Jun 2011
Ort: Ilmenau
111 Beiträge
 
Delphi XE5 Enterprise
 
#3

AW: CopyFileEx und Codeoptimierung XE5

  Alt 11. Apr 2014, 08:09
Wozu sourcecode? Der ist ja kaum falsch wenn es ohne Optimierung funktioniert.
Ausserdem ist der älter, d.h. in 2006 gabs auch mit Optimierung keine Fehler.

Delphi-Quellcode:
[B]
function TFileCopier.DoFolderFiles( const ASourcePath, ATargetPath: string;
                                    const Op: TFolderOp): Int64;

var
  StrName,
  MySearchPath,
  MyTargetPath,
  MySourcePath: string;
  FindRec: TSearchRec;
  i: Integer;
  Cancelled: Boolean;
  Attrs: integer;
  CopyIt: boolean;
begin
  Result := 0;
  Cancelled := False;
  MyTargetPath := AddBackSlash(ATargetPath);
  MySourcePath := AddBackSlash(ASourcePath);
  MySearchPath := AddBackSlash(ASourcePath) + '*.*';
  i := FindFirst(MySearchPath, 0 , FindRec);

  try
    while (i = 0) and (Result <> -1) do
    begin
      try
      case op of
       foCopy: begin
          StrName := MySourcePath + FindRec.Name;
          CopyIt:= CopyAll or (FindRec.Attr and faArchive = faArchive);
          if CopyIt then
          begin
            //Cancelled:= false;
            if CopyFileEx(PWideChar(StrName), PWideChar(MyTargetPath + FindRec.Name), @fCallBack, Pointer(fHandle), @Cancelled, 0) then
            begin
              Attrs := FileGetAttr(StrName);
              FileSetAttr(StrName, Attrs and not faArchive);
              inc(Result);
              inc(fCopyCount);
              TUtils.WriteLogFile(eData, StrName + ' saved to ' + MyTargetPath + FindRec.Name);
              Sleep(50);
            end
            else
            begin
              Result := -1;
              TUtils.WriteLogFile(eError, StrName + ' not saved' + #13#10 + SysErrorMessage (GetLastError));
            end;
          end;
        end;
       foCount:
       begin
         Inc(Result);
         Inc(fFileCount);
       end;
       foSize:
       begin
         Result := Result + FindRec.Size;
         fFileSize := fFileSize + FindRec.Size;
       end;
      end; // case
      except
        Result := -1;
      end;
      i := FindNext(FindRec);
    end;
  finally
    FindClose(FindRec);
  end;

end;

[/B]

Geändert von wurzelzwerg (11. Apr 2014 um 08:51 Uhr) Grund: Cancel entfernt, war nur zum Test drin
  Mit Zitat antworten Zitat