Subversion Repositories checksum-tools

Rev

Rev 3 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. unit LongFilenameOperations;
  2.  
  3. interface
  4.  
  5. // These procedures should replace the Delphi internal AssignFile(), Reset(), etc.
  6. // functions. These functions should be able to support long file names
  7. // by using the WinAPI (the "long filename" mode is switched when the file
  8. // name format \\?\ is used).
  9.  
  10. procedure MyAssignFile(var hFile: THandle; filename: string);
  11. procedure MyReset(hFile: THandle);
  12. procedure MyReadLn(hFile: THandle; var s: string);
  13. procedure MyCloseFile(hFile: THandle);
  14. function MyEOF(hFile: THandle): boolean;
  15. procedure MyBlockRead(var hFile: THandle; var Buffer; RecordCount: integer; var RecordsRead: integer);
  16.  
  17. implementation
  18.  
  19. uses
  20.   Windows, SysUtils;
  21.  
  22. procedure MyAssignFile(var hFile: THandle; filename: string);
  23. begin
  24.   hFile := CreateFile(PChar(filename), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, 0);
  25.   if hFile = INVALID_HANDLE_VALUE then RaiseLastOSError;
  26. end;
  27.  
  28. procedure MyReset(hFile: THandle);
  29. begin
  30.   SetFilePointer(hFile, 0, nil, FILE_BEGIN);
  31. end;
  32.  
  33. procedure MyReadLn(hFile: THandle; var s: string);
  34. var
  35.   buf: array [0..0] of ansichar;
  36.   dwread: LongWord;
  37. begin
  38.   s := '';
  39.   ReadFile(hFile, buf, 1, dwread, nil);
  40.   while (dwread > 0) do
  41.   begin
  42.     if buf[0] <> #10 then
  43.     begin
  44.       if buf[0] = #13 then exit;
  45.       s := s + string(buf[0]);
  46.     end;
  47.     Readfile(hFile, buf, 1, dwread, nil);
  48.   end;
  49. end;
  50.  
  51. procedure MyCloseFile(hFile: THandle);
  52. begin
  53.   CloseHandle(hFile);
  54. end;
  55.  
  56. function MyEOF(hFile: THandle): boolean;
  57. var
  58.   buf: array [0..0] of ansichar;
  59.   dwread: LongWord;
  60. begin
  61.   Readfile(hFile, buf, 1, dwread, nil);
  62.   if dwread > 0 then
  63.   begin
  64.     SetFilePointer(hFile, -dwread, nil, FILE_CURRENT);
  65.     result := false;
  66.   end
  67.   else
  68.   begin
  69.     result := true;
  70.   end;
  71. end;
  72.  
  73. procedure MyBlockRead(var hFile: THandle; var Buffer; RecordCount: integer; var RecordsRead: integer);
  74. var
  75.   RecordCount2, RecordsRead2: Cardinal;
  76. begin
  77.   RecordCount2 := RecordCount;
  78.   RecordsRead2 := RecordsRead;
  79.   ReadFile(hFile, Buffer, RecordCount2, RecordsRead2, nil);
  80.   //RecordCount := RecordCount2;
  81.   RecordsRead := RecordsRead2;
  82. end;
  83.  
  84. end.
  85.