Einzelnen Beitrag anzeigen

Benutzerbild von FriFra
FriFra

Registriert seit: 19. Apr 2003
1.291 Beiträge
 
Delphi 2005 Professional
 
#72

Re: Eindeutiger Vergleich für große Dateien gesucht

  Alt 4. Aug 2005, 10:59
@negah: Ich hab auch mal versucht Deinen Code umzusetzen... leider kommt es beim Vergleich hin und wieder zu Fehlern...
Delphi-Quellcode:
Result := False;
    FileHandle1 := FileOpen(FileName1, fmOpenRead or fmShareDenyWrite);
    if FileHandle1 <> INVALID_HANDLE_VALUE then
    try
      FileHandle2 := FileOpen(FileName2, fmOpenRead or fmShareDenyWrite);
      if FileHandle2 <> INVALID_HANDLE_VALUE then
      try
        FileSize := GetFileSize(FileHandle1, nil);
        if FileSize = GetFileSize(FileHandle2, nil) then
        begin
          Result := True;
          if FileSize > 0 then
          begin
            MapHandle1 := CreateFileMapping(FileHandle1, nil, PAGE_READONLY, 0,
              0, nil);
            if MapHandle1 <> INVALID_HANDLE_VALUE then
            try
              MapHandle2 := CreateFileMapping(FileHandle2, nil, PAGE_READONLY,
                0, 0, nil);
              if MapHandle2 <> INVALID_HANDLE_VALUE then
              try
                CurSize := FileSize mod AllocGran;
                if CurSize = 0 then
                  CurSize := AllocGran;
                CurPos := FileSize - CurSize;
                repeat
                  CurPosHi := CurPos div 4294967296;
                  CurPosLo := CurPos mod 4294967296;
                  P1 := MapViewOfFile(MapHandle1, FILE_MAP_READ, CurPosHi,
                    CurPosLo, CurSize);
                  if P1 <> nil then
                  try
                    P2 := MapViewOfFile(MapHandle2, FILE_MAP_READ, CurPosHi,
                      CurPosLo, CurSize);
                    if P2 <> nil then
                    try
                      Result := CompareMem(P1, P2, CurSize);
                    finally
                      UnmapViewOfFile(P2);
                    end
                    else
                      RaiseLastWin32Error;
                  finally
                    UnmapViewOfFile(P1);
                  end
                  else
                    RaiseLastWin32Error;
                  CurPos := CurPos - CurSize;
                  CurSize := AllocGran;
                until (CurPos < 0) or not Result;
              finally
                CloseHandle(MapHandle2);
              end
              else
                RaiseLastWin32Error;
            finally
              CloseHandle(MapHandle1);
            end
            else
              RaiseLastWin32Error; // <------------ Hier wird der Fehler angezeigt
                                    // MapHandle1 ist also INVALID_HANDLE_VALUE
                                    // Warum?
          end;
        end;
      finally
        FileClose(FileHandle2);
      end
      else
        RaiseLastWin32Error;
    finally
      FileClose(FileHandle1);
    end
    else
      RaiseLastWin32Error;
Elektronische Bauelemente funktionieren mit Rauch. Kommt der Rauch raus, geht das Bauteil nicht mehr.
  Mit Zitat antworten Zitat