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.

138 lines
3.7 KiB

  1. /*++
  2. Copyright (C) 2000-2001 Microsoft Corporation
  3. --*/
  4. #ifndef __WMI_A51_FILECACHE_H_
  5. #define __WMI_A51_FILECACHE_H_
  6. #include "shortstg.h"
  7. #include <set>
  8. #include <string>
  9. extern DWORD g_ShutDownFlags;
  10. #include "objheap.h"
  11. #include "index.h"
  12. class CFileCache
  13. {
  14. protected:
  15. long m_lRef;
  16. BOOL m_bInit;
  17. CCritSec m_cs;
  18. //CUniquePointerArray<CShortFileStagingFile> m_apStages;
  19. //CShortFileStagingFile* m_pMainStage;
  20. CAbstractFileSource m_AbstractSource;
  21. //CFileHeap m_BaseObjHeap;
  22. //CBtrIndex m_Index;
  23. CObjectHeap m_ObjectHeap;
  24. DWORD m_dwBaseNameLen;
  25. WCHAR m_wszBaseName[MAX_PATH+1]; // be debugger friendly, live it last
  26. public:
  27. class CFileEnumerator
  28. {
  29. protected:
  30. CFileCache* m_pCache;
  31. WCHAR m_wszPrefix[MAX_PATH+1];
  32. DWORD m_dwPrefixDirLen;
  33. int m_nCurrentStage;
  34. bool m_bUseFiles;
  35. //void* m_pStageEnumerator;
  36. HANDLE m_hFileEnum;
  37. std::set<WString, WSiless> m_setSent;
  38. DWORD m_dwBaseNameLen;
  39. public:
  40. CFileEnumerator(CFileCache* pCache, DWORD dwBaseNameLen)
  41. : m_pCache(pCache), m_nCurrentStage(-1), //m_pStageEnumerator(NULL),
  42. m_hFileEnum(NULL), m_dwBaseNameLen(dwBaseNameLen)
  43. {}
  44. ~CFileEnumerator();
  45. long GetFirst(LPCWSTR wszPrefix, WIN32_FIND_DATAW* pfd,
  46. bool bNeedToContinue);
  47. long GetFirstFile(WIN32_FIND_DATAW* pfd, bool bNeedToContinue);
  48. void ComputeCanonicalName(WIN32_FIND_DATAW* pfd, wchar_t *wszFilePath);
  49. long GetNext(WIN32_FIND_DATAW* pfd, bool bNeedToContinue);
  50. long GetRawNext(WIN32_FIND_DATAW* pfd, bool bNeedToContinue);
  51. };
  52. friend CFileEnumerator;
  53. class CFindCloseMe
  54. {
  55. protected:
  56. CFileCache* m_pCache;
  57. void* m_hSearch;
  58. public:
  59. CFindCloseMe(CFileCache* pCache, void* hSearch)
  60. : m_pCache(pCache), m_hSearch(hSearch){}
  61. ~CFindCloseMe()
  62. {
  63. if(m_pCache && m_hSearch) m_pCache->FindClose(m_hSearch);
  64. }
  65. };
  66. protected:
  67. //int GetNumStages() {return m_apStages.GetSize();}
  68. //INTERNAL CShortFileStagingFile* GetStageFile(int nIndex) {return m_apStages[nIndex];}
  69. //INTERNAL CShortFileStagingFile* GetMainStagingFile() {return m_pMainStage;}
  70. public:
  71. CFileCache();
  72. ~CFileCache();
  73. private:
  74. void Clear(DWORD dwShutDownFlags);
  75. public:
  76. bool IsFullyFlushed();
  77. long Initialize(LPCWSTR wszBaseName);
  78. long Uninitialize(DWORD dwShutDownFlags);
  79. private:
  80. long InnerInitialize(LPCWSTR wszBaseName);
  81. long RepositoryExists(LPCWSTR wszBaseName);
  82. public:
  83. long WriteFile(LPCWSTR wszFileName, DWORD dwLen, BYTE* pBuffer);
  84. long ReadFile(LPCWSTR wszFileName, DWORD* pdwLen, BYTE** ppBuffer,
  85. bool bMustBeThere = false);
  86. long DeleteFile(LPCWSTR wszFileName);
  87. long RemoveDirectory(LPCWSTR wszFileName, bool bMustSucceed = true);
  88. long FindFirst(LPCWSTR wszFilePrefix, WIN32_FIND_DATAW* pfd,
  89. void** ppHandle);
  90. long FindNext(void* pHandle, WIN32_FIND_DATAW* pfd);
  91. void FindClose(void* pHandle);
  92. long FindFirstIdx(LPCWSTR wszFilePrefix, WIN32_FIND_DATAW* pfd,
  93. void** ppHandle);
  94. long FindNextIdx(void* pHandle, WIN32_FIND_DATAW* pfd);
  95. void FindCloseIdx(void* pHandle);
  96. long BeginTransaction();
  97. long CommitTransaction();
  98. long AbortTransaction();
  99. CCritSec* GetLock() {return &m_cs;}
  100. long AddRef() {return InterlockedIncrement(&m_lRef);}
  101. long Release() {long lRet = InterlockedDecrement(&m_lRef); if (!lRet) delete this;return lRet;}
  102. bool GetFlushFailure(long* plFlushStatus);
  103. CObjectHeap* GetObjectHeap() {return &m_ObjectHeap;}
  104. };
  105. #endif