FileIO.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Windows/FileIO.h
  2. #ifndef __WINDOWS_FILEIO_H
  3. #define __WINDOWS_FILEIO_H
  4. #include "../Common/Types.h"
  5. namespace NWindows {
  6. namespace NFile {
  7. namespace NIO {
  8. struct CByHandleFileInfo
  9. {
  10. DWORD Attributes;
  11. FILETIME CreationTime;
  12. FILETIME LastAccessTime;
  13. FILETIME LastWriteTime;
  14. DWORD VolumeSerialNumber;
  15. UInt64 Size;
  16. DWORD NumberOfLinks;
  17. UInt64 FileIndex;
  18. };
  19. class CFileBase
  20. {
  21. protected:
  22. HANDLE _handle;
  23. bool Create(LPCTSTR fileName, DWORD desiredAccess,
  24. DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
  25. #ifndef _UNICODE
  26. bool Create(LPCWSTR fileName, DWORD desiredAccess,
  27. DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
  28. #endif
  29. public:
  30. CFileBase(): _handle(INVALID_HANDLE_VALUE){};
  31. ~CFileBase();
  32. bool Close();
  33. bool GetPosition(UInt64 &position) const;
  34. bool GetLength(UInt64 &length) const;
  35. bool Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const;
  36. bool Seek(UInt64 position, UInt64 &newPosition);
  37. bool SeekToBegin();
  38. bool SeekToEnd(UInt64 &newPosition);
  39. bool GetFileInformation(CByHandleFileInfo &fileInfo) const;
  40. };
  41. class CInFile: public CFileBase
  42. {
  43. public:
  44. bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
  45. bool OpenShared(LPCTSTR fileName, bool shareForWrite);
  46. bool Open(LPCTSTR fileName);
  47. #ifndef _UNICODE
  48. bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
  49. bool OpenShared(LPCWSTR fileName, bool shareForWrite);
  50. bool Open(LPCWSTR fileName);
  51. #endif
  52. bool ReadPart(void *data, UInt32 size, UInt32 &processedSize);
  53. bool Read(void *data, UInt32 size, UInt32 &processedSize);
  54. };
  55. class COutFile: public CFileBase
  56. {
  57. // DWORD m_CreationDisposition;
  58. public:
  59. // COutFile(): m_CreationDisposition(CREATE_NEW){};
  60. bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
  61. bool Open(LPCTSTR fileName, DWORD creationDisposition);
  62. bool Create(LPCTSTR fileName, bool createAlways);
  63. #ifndef _UNICODE
  64. bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
  65. bool Open(LPCWSTR fileName, DWORD creationDisposition);
  66. bool Create(LPCWSTR fileName, bool createAlways);
  67. #endif
  68. /*
  69. void SetOpenCreationDisposition(DWORD creationDisposition)
  70. { m_CreationDisposition = creationDisposition; }
  71. void SetOpenCreationDispositionCreateAlways()
  72. { m_CreationDisposition = CREATE_ALWAYS; }
  73. */
  74. bool SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime);
  75. bool SetLastWriteTime(const FILETIME *lastWriteTime);
  76. bool WritePart(const void *data, UInt32 size, UInt32 &processedSize);
  77. bool Write(const void *data, UInt32 size, UInt32 &processedSize);
  78. bool SetEndOfFile();
  79. bool SetLength(UInt64 length);
  80. };
  81. }}}
  82. #endif