Changes between Version 1 and Version 2 of HashSourceCodes


Ignore:
Timestamp:
Sep 24, 2008, 8:35:43 PM (16 years ago)
Author:
guest
Comment:

Replaced original Delphi code with 4GB+ fixed version [Majky]

Legend:

Unmodified
Added
Removed
Modified
  • HashSourceCodes

    v1 v2  
    159159               
    160160                while (longBuffer.hasRemaining()) {
     161
    161162                        hash += longBuffer.get();
    162163                }
     
    335336
    336337{{{
    337 function CalcGabestHash(const Filename: string): string;
     338function CalcGabestHash(const fname: string): string;
    338339var
    339   i: Integer;
    340   f: File;
    341   s: Array[1..8] of char;
    342   tmp: Int64 absolute s;
    343   hash: Int64;
    344   readed: Integer;
    345   OldFM: Byte;
     340  i : integer;
     341  s : array[1..8] of char;
     342  tmp       : Int64 absolute s;
     343  hash      : Int64;
     344  readed    : integer;
     345
     346  aStream: TFileStream;
    346347begin
    347   Result := '';
    348   if FileExists(Filename) then begin
    349     { Open file }
    350     OldFM := FileMode;
    351     try
    352       FileMode := fmShareDenyNone;
    353       AssignFile(f,Filename);
    354       Reset(f,1);
    355       try
    356         { Start hashing }
    357         hash := filesize(f);
    358         { Read from begining }
    359         for i := 0 to 8191 do begin
    360           blockread(f,s,sizeof(s),readed);
    361           if readed > 0 then hash := hash + tmp else break;
    362         end;
    363         { Read from the end }
    364         seek(f,Max(0,filesize(f)-65536));
    365         for i := 0 to 8191 do begin
    366           blockread(f,s,sizeof(s),readed);
    367           if readed > 0 then hash := hash + tmp else break;
    368         end;
    369         { Finished }
    370         Result := Format('%.16x',[hash]);
    371       finally
    372         CloseFile(f);
    373       end;
    374     finally
    375       FileMode := OldFM;
     348  result := '';
     349  if not FileExists(fname) then Exit;
     350
     351  aStream := TFileStream.Create(fName, fmShareDenyNone);
     352  hash := aStream.Size;
     353
     354  i := 0; readed := 1;
     355  while ((i < 8192) and (readed > 0)) do begin
     356    readed := aStream.Read(s, sizeof(s));
     357    if readed > 0 then
     358    begin
     359      hash := hash + tmp;
    376360    end;
     361    i := i + 1;
    377362  end;
     363
     364  aStream.Seek(-65536, soFromEnd); // 65536
     365
     366  i := 0; readed:= 1;
     367  while ((i < 8192) and (readed > 0)) do begin
     368    readed := aStream.Read(s, sizeof(s));
     369    if readed > 0 then
     370      hash := hash + tmp;
     371    i := i + 1;
     372  end;
     373  aStream.Free;
     374  result := Format('%.16x',[hash]);
    378375end;
    379376}}}