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.

103 lines
2.8 KiB

  1. /*++
  2. Copyright (C) 2000-2001 Microsoft Corporation
  3. --*/
  4. #ifndef __WMI_A51_FILECACHE_H_
  5. #define __WMI_A51_FILECACHE_H_
  6. #include "stage.h"
  7. #include <set>
  8. #include <string>
  9. class CFileCache
  10. {
  11. protected:
  12. CCritSec m_cs;
  13. WCHAR m_wszBaseName[MAX_PATH+1];
  14. DWORD m_dwBaseNameLen;
  15. CUniquePointerArray<CStagingFile> m_apStages;
  16. CRealStagingFile* m_pMainStage;
  17. long m_lRef;
  18. public:
  19. class CFileEnumerator
  20. {
  21. protected:
  22. CFileCache* m_pCache;
  23. WCHAR m_wszPrefix[MAX_PATH+1];
  24. DWORD m_dwPrefixDirLen;
  25. int m_nCurrentStage;
  26. bool m_bUseFiles;
  27. void* m_pStageEnumerator;
  28. HANDLE m_hFileEnum;
  29. std::set<WString, WSiless> m_setSent;
  30. DWORD m_dwBaseNameLen;
  31. public:
  32. CFileEnumerator(CFileCache* pCache, DWORD dwBaseNameLen)
  33. : m_pCache(pCache), m_nCurrentStage(-1), m_pStageEnumerator(NULL),
  34. m_hFileEnum(NULL), m_dwBaseNameLen(dwBaseNameLen)
  35. {}
  36. ~CFileEnumerator();
  37. long GetFirst(LPCWSTR wszPrefix, WIN32_FIND_DATAW* pfd);
  38. long GetFirstFile(WIN32_FIND_DATAW* pfd);
  39. void ComputeCanonicalName(WIN32_FIND_DATAW* pfd, wchar_t *wszFilePath);
  40. long GetNext(WIN32_FIND_DATAW* pfd);
  41. long GetRawNext(WIN32_FIND_DATAW* pfd);
  42. };
  43. friend CFileEnumerator;
  44. class CFindCloseMe
  45. {
  46. protected:
  47. CFileCache* m_pCache;
  48. void* m_hSearch;
  49. public:
  50. CFindCloseMe(CFileCache* pCache, void* hSearch)
  51. : m_pCache(pCache), m_hSearch(hSearch){}
  52. ~CFindCloseMe()
  53. {
  54. if(m_pCache && m_hSearch) m_pCache->FindClose(m_hSearch);
  55. }
  56. };
  57. protected:
  58. int GetNumStages() {return m_apStages.GetSize();}
  59. INTERNAL CStagingFile* GetStageFile(int nIndex) {return m_apStages[nIndex];}
  60. INTERNAL CStagingFile* GetMainStagingFile() {return m_pMainStage;}
  61. public:
  62. CFileCache();
  63. ~CFileCache();
  64. void Clear();
  65. bool IsFullyFlushed();
  66. long Initialize(LPCWSTR wszBaseName);
  67. long RepositoryExists(LPCWSTR wszBaseName);
  68. long WriteFile(LPCWSTR wszFileName, DWORD dwLen, BYTE* pBuffer);
  69. long ReadFile(LPCWSTR wszFileName, DWORD* pdwLen, BYTE** ppBuffer,
  70. bool bMustBeThere = false);
  71. long DeleteFile(LPCWSTR wszFileName);
  72. long RemoveDirectory(LPCWSTR wszFileName, bool bMustSucceed = true);
  73. long FindFirst(LPCWSTR wszFilePrefix, WIN32_FIND_DATAW* pfd,
  74. void** ppHandle);
  75. long FindNext(void* pHandle, WIN32_FIND_DATAW* pfd);
  76. void FindClose(void* pHandle);
  77. long BeginTransaction();
  78. long CommitTransaction();
  79. long AbortTransaction();
  80. CCritSec* GetLock() {return &m_cs;}
  81. long AddRef() {return InterlockedIncrement(&m_lRef);}
  82. long Release() {long lRet = InterlockedDecrement(&m_lRef); if (!lRet) delete this; return lRet;}
  83. };
  84. #endif