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.

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