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.

145 lines
3.7 KiB

  1. #ifndef __A51_INDEX__H_
  2. #define __A51_INDEX__H_
  3. #include "heap.h"
  4. #include "btr.h"
  5. class CAbstractIndex
  6. {
  7. public:
  8. virtual ~CAbstractIndex(){}
  9. virtual long Create(LPCWSTR wszFileName) = 0;
  10. virtual long Delete(LPCWSTR wszFileName) = 0;
  11. virtual long FindFirst(LPCWSTR wszPrefix, WIN32_FIND_DATAW* pfd,
  12. void** ppHandle) = 0;
  13. virtual long FindNext(void* pHandle, WIN32_FIND_DATAW* pfd) = 0;
  14. virtual long FindClose(void* pHandle) = 0;
  15. };
  16. typedef DWORD TDirectoryId;
  17. #define ROSWELL_MAX_COMPONENT_LENGTH 50
  18. #define ROSWELL_MAX_PREFIX_LENGTH ROSWELL_MAX_COMPONENT_LENGTH
  19. struct CFileKey
  20. {
  21. TDirectoryId m_nDirectoryId;
  22. char m_szComponentName[ROSWELL_MAX_COMPONENT_LENGTH];
  23. };
  24. struct CFileValue
  25. {
  26. TDirectoryId m_nId;
  27. TOffset m_nOffset;
  28. DWORD m_dwLength;
  29. };
  30. class CFileKeyCompare
  31. {
  32. public:
  33. bool operator()(const CFileKey& keyFirst, const CFileKey& keySecond) const
  34. {
  35. if(keyFirst.m_nDirectoryId != keySecond.m_nDirectoryId)
  36. return (keyFirst.m_nDirectoryId < keySecond.m_nDirectoryId);
  37. else
  38. return (strcmp(keyFirst.m_szComponentName,
  39. keySecond.m_szComponentName) < 0);
  40. }
  41. };
  42. class CIndex : public CAbstractIndex
  43. {
  44. public:
  45. CFileHeap* m_pHeap;
  46. CCritSec m_cs;
  47. DWORD m_dwPrefixLength;
  48. TDirectoryId m_nNextId;
  49. typedef std::map<CFileKey, CFileValue, CFileKeyCompare> TDirectoryMap;
  50. typedef TDirectoryMap::iterator TDirectoryIterator;
  51. TDirectoryMap m_map;
  52. public:
  53. CIndex(CFileHeap* pHeap)
  54. : m_pHeap(pHeap), m_nNextId(1), m_dwPrefixLength(0)
  55. {}
  56. long Initialize(DWORD dwPrefixLength);
  57. long Create(LPCWSTR wszFileName);
  58. long Delete(LPCWSTR wszFileName);
  59. long FindFirst(LPCWSTR wszPrefix, WIN32_FIND_DATAW* pfd, void** ppHandle);
  60. long FindNext(void* pHandle, WIN32_FIND_DATAW* pfd);
  61. long FindClose(void* pHandle);
  62. protected:
  63. long ConvertInputToAscii(LPCWSTR wszFileName, char* szFileName);
  64. long CreateRecord(TDirectoryId nParentId, char* szComponentName,
  65. TDirectoryId* pnChildId);
  66. TDirectoryId GetNewDirectoryId();
  67. friend class CIndexIterator;
  68. };
  69. class CIndexIterator
  70. {
  71. protected:
  72. CIndex::TDirectoryMap& m_rMap;
  73. CIndex::TDirectoryIterator m_it;
  74. TDirectoryId m_nParentId;
  75. char m_szPrefix[ROSWELL_MAX_PREFIX_LENGTH];
  76. long m_lPrefixLen;
  77. public:
  78. CIndexIterator(TDirectoryId nParentId, char* szPrefix,
  79. CIndex::TDirectoryIterator it, CIndex::TDirectoryMap& rMap);
  80. long FindNext(WIN32_FIND_DATAW* pfd);
  81. };
  82. class COldIndex : public CAbstractIndex
  83. {
  84. public:
  85. COldIndex(CFileHeap* pHeap){}
  86. long Initialize(bool bNewFile, DWORD dwPrefixLength);
  87. long Create(LPCWSTR wszFileName);
  88. long Delete(LPCWSTR wszFileName);
  89. long FindFirst(LPCWSTR wszPrefix, WIN32_FIND_DATAW* pfd, void** ppHandle);
  90. long FindNext(void* pHandle, WIN32_FIND_DATAW* pfd);
  91. long FindClose(void* pHandle);
  92. };
  93. class CBtrIndex : public CAbstractIndex
  94. {
  95. DWORD m_dwPrefixLength;
  96. CRITICAL_SECTION m_cs;
  97. CBTree bt;
  98. CPageSource ps;
  99. BOOL CopyStringToWIN32_FIND_DATA(
  100. LPSTR pszSource,
  101. WIN32_FIND_DATAW* pfd
  102. );
  103. public:
  104. CBtrIndex();
  105. ~CBtrIndex();
  106. long Shutdown(DWORD dwShutDownFlags);
  107. long Initialize(DWORD dwPrefixLength, LPCWSTR wszRepositoryDir,
  108. CAbstractFileSource* pSource );
  109. long Create(LPCWSTR wszFileName);
  110. long Delete(LPCWSTR wszFileName);
  111. long FindFirst(LPCWSTR wszPrefix, WIN32_FIND_DATAW* pfd, void** ppHandle);
  112. long FindNext(void* pHandle, WIN32_FIND_DATAW* pfd);
  113. long FindClose(void* pHandle);
  114. long InvalidateCache();
  115. CBTree& GetTree() {return bt;}
  116. };
  117. #endif