Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
5.0 KiB

  1. // FileIO.h
  2. //
  3. // Copyright (c) 1998-1999 Microsoft Corporation
  4. #pragma once // MSINFO_FILEIO_H
  5. #include <afx.h>
  6. // Advanced declaration of this class so we can use the pointer.
  7. class CDataSource;
  8. /*
  9. * CFileFormatException - Home-brew exception to reflect an error in a
  10. * data file.
  11. *
  12. * History: a-jsari 10/20/97 Initial version.
  13. */
  14. class CFileFormatException : public CException {
  15. };
  16. void ThrowFileFormatException();
  17. /*
  18. * CMSInfoFile - A file class which provides extended functions for
  19. * reading from a file. Provides binary versions of the files.
  20. *
  21. * History: a-jsari 10/20/97 Initial version
  22. */
  23. class CMSInfoFile {
  24. friend void ThrowFileFormatException();
  25. friend class CBufferDataSource;
  26. friend class CBufferV500DataSource;
  27. public:
  28. CMSInfoFile(LPCTSTR szFileName, UINT wFlags = CFile::shareDenyWrite
  29. | CFile::modeCreate | CFile::modeWrite | CFile::typeBinary);
  30. virtual ~CMSInfoFile();
  31. enum FileType { BINARY, REVERSE_ENDIAN, TEXT, MEMORY };
  32. virtual FileType GetType() { return BINARY; }
  33. const CString &GetFileName() { return m_strFileName; }
  34. virtual void ReadLong(long &lValue);
  35. virtual void ReadUnsignedInt(unsigned &uValue);
  36. virtual void ReadString(CString &szValue);
  37. virtual void ReadTchar(TCHAR &tcValue);
  38. void ReadByte(BYTE &bValue) { ReadByteFromCFile(m_pFile, bValue); }
  39. void ReadUnsignedLong(DWORD &dwValue);
  40. virtual void WriteHeader(CDataSource *pDataSource);
  41. virtual void WriteLong(long lValue);
  42. virtual void WriteUnsignedInt(unsigned uValue);
  43. virtual void WriteString(CString szValue);
  44. void WriteByte(BYTE bValue);
  45. void WriteUnsignedLong(DWORD dwValue);
  46. virtual void WriteTitle(CString szName) { WriteString(szName); }
  47. virtual void WriteChildMark();
  48. virtual void WriteEndMark();
  49. virtual void WriteNextMark();
  50. virtual void WriteParentMark(unsigned cIterations);
  51. static void ReadLongFromCFile(CFile *pFile, long &lValue);
  52. static void ReadUnsignedFromCFile(CFile *pFile, unsigned &uValue);
  53. static void ReadTcharFromCFile(CFile *pFile, TCHAR &tcValue);
  54. static void ReadByteFromCFile(CFile *pFile, BYTE &bValue) { ASSERT(pFile);
  55. if (pFile->Read(&bValue, sizeof(bValue)) != sizeof(bValue)) ThrowFileFormatException(); }
  56. static void GetDefaultMSInfoDirectory(LPTSTR szDefaultDirectory, DWORD dwSize);
  57. void SeekToBegin() { m_pFile->SeekToBegin(); }
  58. int FileHandle() { return (int)m_pFile->m_hFile; }
  59. void Close() { m_pFile->Close(); delete m_pFile; m_pFile = NULL; }
  60. protected:
  61. enum MagicNumber {
  62. VERSION_500_MAGIC_NUMBER = 0x00011970,
  63. VERSION_500_REVERSE_ENDIAN = 0x70190100,
  64. VERSION_410_REVERSE_ENDIAN = 0x20000000, // FIX: Place holders.
  65. VERSION_410_MAGIC_NUMBER = 0x20
  66. };
  67. CMSInfoFile(CFile *pFile = NULL);
  68. static const unsigned DefaultReadBufferSize;
  69. static CFileFormatException xptFileFormat;
  70. void ReadSignedInt(int &wValue);
  71. CFile *m_pFile;
  72. CString m_strFileName;
  73. };
  74. /*
  75. * CMSInfoTextFile - Write-methods version for text file. No read methods
  76. * are required.
  77. *
  78. * History: a-jsari 10/23/97 Initial version.
  79. */
  80. class CMSInfoTextFile : public CMSInfoFile {
  81. public:
  82. CMSInfoTextFile(LPCTSTR szName, UINT nFlags = CFile::shareDenyWrite
  83. | CFile::modeWrite | CFile::modeCreate | CFile::typeText);
  84. ~CMSInfoTextFile() { }
  85. FileType GetType() { return TEXT; }
  86. void WriteTitle(CString szString);
  87. void WriteHeader(CDataSource *pDataSource);
  88. void WriteLong(long lValue);
  89. void WriteUnsignedInt(unsigned uValue);
  90. virtual void WriteString(CString szValue);
  91. void WriteChildMark() { }
  92. void WriteEndMark() { }
  93. void WriteNextMark() { }
  94. void WriteParentMark(unsigned) { }
  95. protected:
  96. CMSInfoTextFile(CFile *pFile = NULL);
  97. };
  98. /*
  99. * CMSInfoMemoryFile - Just like a text report, but saved to a memory file.
  100. * Inherits the text write functions.
  101. *
  102. * History: a-jsari 12/26/97 Initial version
  103. */
  104. class CMSInfoMemoryFile : public CMSInfoTextFile {
  105. public:
  106. CMSInfoMemoryFile() :CMSInfoTextFile(new CMemFile) { }
  107. ~CMSInfoMemoryFile() { }
  108. FileType GetType() { return MEMORY; }
  109. void WriteTitle(CString szString) { CMSInfoTextFile::WriteTitle(szString); }
  110. void WriteHeader(CDataSource *pDataSource) { CMSInfoTextFile::WriteHeader(pDataSource); }
  111. void WriteLong(long lValue) { CMSInfoTextFile::WriteLong(lValue); }
  112. void WriteUnsignedInt(unsigned uValue) { CMSInfoTextFile::WriteUnsignedInt(uValue); }
  113. void WriteString(CString szString);
  114. };
  115. #if 0
  116. /*
  117. * CMSInfoReverseEndianFile - Read-methods version for opposite endian binary file.
  118. *
  119. * History: a-jsari 10/20/97 Initial version
  120. */
  121. class CMSInfoReverseEndianFile : public CMSInfoFile {
  122. public:
  123. CMSInfoReverseEndianFile(CFile *pFile);
  124. ~CMSInfoReverseEndianFile() {}
  125. FileType GetType() { return REVERSE_ENDIAN; }
  126. void ReadLong(long &lValue);
  127. void ReadUnsignedInt(unsigned &uValue);
  128. void ReadString(CString &szValue);
  129. static void ReadLongFromCFile(CFile *pFile, long &lValue);
  130. static void ReadUnsignedFromCFile(CFile *pFile, unsigned &uValue);
  131. };
  132. #endif
  133. /*
  134. * ThrowFileFormatException -
  135. *
  136. * History: a-jsari 10/24/97
  137. */
  138. inline void ThrowFileFormatException()
  139. {
  140. throw &CMSInfoFile::xptFileFormat;
  141. }
  142.