FileStreams.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // FileStreams.h
  2. #ifndef __FILESTREAMS_H
  3. #define __FILESTREAMS_H
  4. #ifdef _WIN32
  5. #define USE_WIN_FILE
  6. #endif
  7. #ifdef USE_WIN_FILE
  8. #include "../../Windows/FileIO.h"
  9. #else
  10. #include "../../Common/C_FileIO.h"
  11. #endif
  12. #include "../IStream.h"
  13. #include "../../Common/MyCom.h"
  14. class CInFileStream:
  15. public IInStream,
  16. public IStreamGetSize,
  17. public CMyUnknownImp
  18. {
  19. public:
  20. #ifdef USE_WIN_FILE
  21. NWindows::NFile::NIO::CInFile File;
  22. #else
  23. NC::NFile::NIO::CInFile File;
  24. #endif
  25. CInFileStream() {}
  26. virtual ~CInFileStream() {}
  27. bool Open(LPCTSTR fileName);
  28. #ifdef USE_WIN_FILE
  29. #ifndef _UNICODE
  30. bool Open(LPCWSTR fileName);
  31. #endif
  32. #endif
  33. bool OpenShared(LPCTSTR fileName, bool shareForWrite);
  34. #ifdef USE_WIN_FILE
  35. #ifndef _UNICODE
  36. bool OpenShared(LPCWSTR fileName, bool shareForWrite);
  37. #endif
  38. #endif
  39. MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)
  40. STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
  41. STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
  42. STDMETHOD(GetSize)(UInt64 *size);
  43. };
  44. #ifndef _WIN32_WCE
  45. class CStdInFileStream:
  46. public ISequentialInStream,
  47. public CMyUnknownImp
  48. {
  49. public:
  50. // HANDLE File;
  51. // CStdInFileStream() File(INVALID_HANDLE_VALUE): {}
  52. // void Open() { File = GetStdHandle(STD_INPUT_HANDLE); };
  53. MY_UNKNOWN_IMP
  54. virtual ~CStdInFileStream() {}
  55. STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
  56. };
  57. #endif
  58. class COutFileStream:
  59. public IOutStream,
  60. public CMyUnknownImp
  61. {
  62. #ifdef USE_WIN_FILE
  63. NWindows::NFile::NIO::COutFile File;
  64. #else
  65. NC::NFile::NIO::COutFile File;
  66. #endif
  67. public:
  68. virtual ~COutFileStream() {}
  69. bool Create(LPCTSTR fileName, bool createAlways)
  70. {
  71. ProcessedSize = 0;
  72. return File.Create(fileName, createAlways);
  73. }
  74. bool Open(LPCTSTR fileName, DWORD creationDisposition)
  75. {
  76. ProcessedSize = 0;
  77. return File.Open(fileName, creationDisposition);
  78. }
  79. #ifdef USE_WIN_FILE
  80. #ifndef _UNICODE
  81. bool Create(LPCWSTR fileName, bool createAlways)
  82. {
  83. ProcessedSize = 0;
  84. return File.Create(fileName, createAlways);
  85. }
  86. bool Open(LPCWSTR fileName, DWORD creationDisposition)
  87. {
  88. ProcessedSize = 0;
  89. return File.Open(fileName, creationDisposition);
  90. }
  91. #endif
  92. #endif
  93. HRESULT Close();
  94. UInt64 ProcessedSize;
  95. #ifdef USE_WIN_FILE
  96. bool SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime)
  97. {
  98. return File.SetTime(creationTime, lastAccessTime, lastWriteTime);
  99. }
  100. bool SetLastWriteTime(const FILETIME *lastWriteTime)
  101. {
  102. return File.SetLastWriteTime(lastWriteTime);
  103. }
  104. #endif
  105. MY_UNKNOWN_IMP1(IOutStream)
  106. STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
  107. STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
  108. STDMETHOD(SetSize)(Int64 newSize);
  109. };
  110. #ifndef _WIN32_WCE
  111. class CStdOutFileStream:
  112. public ISequentialOutStream,
  113. public CMyUnknownImp
  114. {
  115. public:
  116. MY_UNKNOWN_IMP
  117. virtual ~CStdOutFileStream() {}
  118. STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
  119. };
  120. #endif
  121. #endif