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.

178 lines
5.1 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. public:
  27. CMSInfoFile(LPCTSTR szFileName, UINT wFlags = CFile::shareDenyWrite
  28. | CFile::modeCreate | CFile::modeWrite | CFile::typeBinary);
  29. virtual ~CMSInfoFile();
  30. enum FileType { BINARY, REVERSE_ENDIAN, TEXT, MEMORY };
  31. //a-stephl 11/23/99
  32. void ReadCategoryHeader();
  33. virtual FileType GetType() { return BINARY; }
  34. const CString &GetFileName() { return m_strFileName; }
  35. virtual void ReadLong(long &lValue);
  36. virtual void ReadUnsignedInt(unsigned &uValue);
  37. virtual void ReadString(CString &szValue);
  38. virtual void ReadTchar(TCHAR &tcValue);
  39. void ReadByte(BYTE &bValue) { ReadByteFromCFile(m_pFile, bValue); }
  40. void ReadUnsignedLong(DWORD &dwValue);
  41. virtual void WriteHeader(CDataSource *pDataSource);
  42. virtual void WriteLong(long lValue);
  43. virtual void WriteUnsignedInt(unsigned uValue);
  44. virtual void WriteString(CString szValue);
  45. void WriteByte(BYTE bValue);
  46. void WriteUnsignedLong(DWORD dwValue);
  47. virtual void WriteTitle(CString szName) { WriteString(szName); }
  48. virtual void WriteChildMark();
  49. virtual void WriteEndMark();
  50. virtual void WriteNextMark();
  51. virtual void WriteParentMark(unsigned cIterations);
  52. static void ReadLongFromCFile(CFile *pFile, long &lValue);
  53. static void ReadUnsignedFromCFile(CFile *pFile, unsigned &uValue);
  54. static void ReadTcharFromCFile(CFile *pFile, TCHAR &tcValue);
  55. static void ReadByteFromCFile(CFile *pFile, BYTE &bValue) { ASSERT(pFile);
  56. if (pFile->Read(&bValue, sizeof(bValue)) != sizeof(bValue)) ThrowFileFormatException(); }
  57. static void GetDefaultMSInfoDirectory(LPTSTR szDefaultDirectory, DWORD dwSize);
  58. void SeekToBegin() { m_pFile->SeekToBegin(); }
  59. int FileHandle() { return (int)m_pFile->m_hFile; }
  60. void Close() { m_pFile->Close(); delete m_pFile; m_pFile = NULL; }
  61. //protected:
  62. time_t m_tsSaveTime;
  63. enum MagicNumber {
  64. VERSION_500_MAGIC_NUMBER = 0x00011970,
  65. VERSION_500_REVERSE_ENDIAN = 0x70190100,
  66. VERSION_410_REVERSE_ENDIAN = 0x20000000, // FIX: Place holders.
  67. VERSION_410_MAGIC_NUMBER = 0x20
  68. };
  69. CMSInfoFile(CFile *pFile = NULL);
  70. static const unsigned DefaultReadBufferSize;
  71. static CFileFormatException xptFileFormat;
  72. void ReadSignedInt(int &wValue);
  73. CFile *m_pFile;
  74. CString m_strFileName;
  75. };
  76. /*
  77. * CMSInfoTextFile - Write-methods version for text file. No read methods
  78. * are required.
  79. *
  80. * History: a-jsari 10/23/97 Initial version.
  81. */
  82. class CMSInfoTextFile : public CMSInfoFile {
  83. public:
  84. CMSInfoTextFile(LPCTSTR szName, UINT nFlags = CFile::shareDenyWrite
  85. | CFile::modeWrite | CFile::modeCreate | CFile::typeText);
  86. ~CMSInfoTextFile() { }
  87. FileType GetType() { return TEXT; }
  88. void WriteTitle(CString szString);
  89. void WriteHeader(CDataSource *pDataSource);
  90. void WriteLong(long lValue);
  91. void WriteUnsignedInt(unsigned uValue);
  92. virtual void WriteString(CString szValue);
  93. void WriteChildMark() { }
  94. void WriteEndMark() { }
  95. void WriteNextMark() { }
  96. void WriteParentMark(unsigned) { }
  97. CMSInfoTextFile(CFile *pFile = NULL);
  98. protected:
  99. };
  100. /*
  101. * CMSInfoMemoryFile - Just like a text report, but saved to a memory file.
  102. * Inherits the text write functions.
  103. *
  104. * History: a-jsari 12/26/97 Initial version
  105. */
  106. class CMSInfoMemoryFile : public CMSInfoTextFile {
  107. public:
  108. CMSInfoMemoryFile() :CMSInfoTextFile(new CMemFile) { }
  109. ~CMSInfoMemoryFile() { }
  110. FileType GetType() { return MEMORY; }
  111. void WriteTitle(CString szString) { CMSInfoTextFile::WriteTitle(szString); }
  112. void WriteHeader(CDataSource *pDataSource) { CMSInfoTextFile::WriteHeader(pDataSource); }
  113. void WriteLong(long lValue) { CMSInfoTextFile::WriteLong(lValue); }
  114. void WriteUnsignedInt(unsigned uValue) { CMSInfoTextFile::WriteUnsignedInt(uValue); }
  115. void WriteString(CString szString);
  116. };
  117. #if 0
  118. /*
  119. * CMSInfoReverseEndianFile - Read-methods version for opposite endian binary file.
  120. *
  121. * History: a-jsari 10/20/97 Initial version
  122. */
  123. class CMSInfoReverseEndianFile : public CMSInfoFile {
  124. public:
  125. CMSInfoReverseEndianFile(CFile *pFile);
  126. ~CMSInfoReverseEndianFile() {}
  127. FileType GetType() { return REVERSE_ENDIAN; }
  128. void ReadLong(long &lValue);
  129. void ReadUnsignedInt(unsigned &uValue);
  130. void ReadString(CString &szValue);
  131. static void ReadLongFromCFile(CFile *pFile, long &lValue);
  132. static void ReadUnsignedFromCFile(CFile *pFile, unsigned &uValue);
  133. };
  134. #endif
  135. /*
  136. * ThrowFileFormatException -
  137. *
  138. * History: a-jsari 10/24/97
  139. */
  140. inline void ThrowFileFormatException()
  141. {
  142. throw &CMSInfoFile::xptFileFormat;
  143. }