purge.h
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 6k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //+-------------------------------------------------------------------------
  2. //
  3. //  Microsoft Windows
  4. //
  5. //  Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. //  File:       purge.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef __CSCUI_PURGE_H
  11. #define __CSCUI_PURGE_H
  12. //
  13. // Definitions for the dwFlags bits in PurgeCache().
  14. //
  15. #define PURGE_FLAG_NONE      0x00000000
  16. #define PURGE_FLAG_PINNED    0x00000001
  17. #define PURGE_FLAG_UNPINNED  0x00000002
  18. #define PURGE_FLAG_ALL       0x00000003
  19. #define PURGE_IGNORE_ACCESS  0x80000000
  20. //
  21. // Phase identification constants specified in dwPhase argument to PurgeCache
  22. // and returned in PURGECALLBACKINFO.dwPhase.
  23. // 
  24. #define PURGE_PHASE_SCAN     0
  25. #define PURGE_PHASE_DELETE   1
  26. class CCachePurger;  // fwd decl.
  27. class CPath;         // fwd decl.
  28. //
  29. // Purge callback function pointer type.
  30. //
  31. typedef BOOL (CALLBACK * LPFNPURGECALLBACK)(CCachePurger *pPurger);
  32. class CCachePurgerSel
  33. {
  34.     public:
  35.         CCachePurgerSel(void) 
  36.             : m_dwFlags(0),
  37.               m_hdpaShares(DPA_Create(8)),
  38.               m_psidUser(NULL) { };
  39.         ~CCachePurgerSel(void);
  40.         DWORD Flags(void) const
  41.             { return m_dwFlags; }
  42.         BOOL SetUserSid(PSID psid);
  43.         PSID UserSid(void) const
  44.             { return m_psidUser; }
  45.         int ShareCount(void) const
  46.             { return m_hdpaShares ? DPA_GetPtrCount(m_hdpaShares) : 0; }
  47.         LPCTSTR ShareName(int iShare) const
  48.             { return m_hdpaShares ? (LPCTSTR)DPA_GetPtr(m_hdpaShares, iShare) : NULL; }
  49.         DWORD SetFlags(DWORD dwFlags)
  50.             { m_dwFlags = dwFlags; return m_dwFlags; }
  51.         DWORD AddFlags(DWORD dwFlags)
  52.             { m_dwFlags |= dwFlags; return m_dwFlags; }
  53.         BOOL AddShareName(LPCTSTR pszShare);
  54.     private:
  55.         DWORD m_dwFlags;
  56.         HDPA  m_hdpaShares;
  57.         PSID  m_psidUser;
  58.         LPTSTR MyStrDup(LPCTSTR psz);
  59.         //
  60.         // Prevent copy.
  61.         //
  62.         CCachePurgerSel(const CCachePurgerSel& rhs);
  63.         CCachePurgerSel& operator = (const CCachePurgerSel& rhs);
  64. };
  65. class CCachePurger
  66. {
  67.     public:
  68.         CCachePurger(const CCachePurgerSel& desc, 
  69.                      LPFNPURGECALLBACK pfnCbk, 
  70.                      LPVOID pvCbkData);
  71.         ~CCachePurger(void);
  72.         HRESULT Scan(void)
  73.             { return Process(PURGE_PHASE_SCAN); }
  74.         HRESULT Delete(void)
  75.             { return Process(PURGE_PHASE_DELETE); }
  76.         static void AskUserWhatToPurge(HWND hwndParent, CCachePurgerSel *pDesc);
  77.         ULONGLONG BytesToScan(void) const
  78.             { return m_ullBytesToScan; }
  79.         ULONGLONG BytesScanned(void) const
  80.             { return m_ullBytesScanned; }
  81.         ULONGLONG BytesToDelete(void) const
  82.             { return m_ullBytesToDelete; }
  83.         ULONGLONG BytesDeleted(void) const
  84.             { return m_ullBytesDeleted; }
  85.         ULONGLONG FileBytes(void) const
  86.             { return m_ullFileBytes; }
  87.         DWORD Phase(void) const
  88.             { return m_dwPhase; }
  89.         DWORD FilesToScan(void) const
  90.             { return m_cFilesToScan; }
  91.         DWORD FilesToDelete(void) const
  92.             { return m_cFilesToDelete; }
  93.         DWORD FilesScanned(void) const
  94.             { return m_cFilesScanned; }
  95.         DWORD FilesDeleted(void) const
  96.             { return m_cFilesDeleted; }
  97.         DWORD FileOrdinal(void) const
  98.             { return m_iFile; }
  99.         DWORD FileAttributes(void) const
  100.             { return m_dwFileAttributes; }
  101.         DWORD FileDeleteResult(void) const
  102.             { return m_dwResult; }
  103.         LPCTSTR FileName(void) const
  104.             { return m_pszFile; }
  105.         LPVOID CallbackData(void) const
  106.             { return m_pvCbkData; }
  107.         BOOL WillDeleteThisFile(void) const
  108.             { return m_bWillDelete; }
  109.     private:
  110.         //
  111.         // State information to support callback info query functions.
  112.         //
  113.         ULONGLONG m_ullBytesToScan;   // Total bytes to scan.
  114.         ULONGLONG m_ullBytesToDelete; // Total bytes to delete. Known after scanning.
  115.         ULONGLONG m_ullBytesScanned;  // Total bytes scanned.
  116.         ULONGLONG m_ullBytesDeleted;  // Total bytes deleted.
  117.         ULONGLONG m_ullFileBytes;     // Size of this file in bytes.
  118.         DWORD     m_dwPhase;          // PURGE_PHASE_XXXXXX value.
  119.         DWORD     m_cFilesToScan;     // Total files to be scanned.
  120.         DWORD     m_cFilesScanned;    // Total files actually scanned.
  121.         DWORD     m_cFilesToDelete;   // Total files to delete.  Known after scanning.
  122.         DWORD     m_cFilesDeleted;    // Total files actually deleted.
  123.         DWORD     m_iFile;            // "This" file's number [0..(n-1)].
  124.         DWORD     m_dwFileAttributes; // This file's Win32 file attributes.
  125.         DWORD     m_dwResult;         // Win32 result code from CSCDelete()
  126.         HANDLE    m_hmutexPurgeInProg;// Purge-in-progress mutex.
  127.         LPCTSTR   m_pszFile;          // This file's full path.
  128.         LPVOID    m_pvCbkData;        // App data provided in DeleteCacheFiles().
  129.         BOOL      m_bWillDelete;      // 1 == File will be deleted in delete phase.
  130.         DWORD             m_dwFlags;     // PURGE_FLAG_XXXXX flags.
  131.         LPFNPURGECALLBACK m_pfnCbk;      // Ptr to callback function.
  132.         const CCachePurgerSel& m_sel;    // Ref to selection info.
  133.         bool              m_bIsValid;    // Ctor success indicator.
  134.         bool              m_bDelPinned;  // Do dwFlags say delete "pinned"?
  135.         bool              m_bDelUnpinned;// Do dwFlags say delete "non-pinned"?
  136.         bool              m_bUserIsAnAdmin;
  137.         bool              m_bIgnoreAccess;
  138.         HRESULT Process(DWORD dwPhase);
  139.         bool ProcessDirectory(CPath *pstrPath, DWORD dwPhase, bool bShareIsOpen);
  140.         //
  141.         // Prevent copy.
  142.         //
  143.         CCachePurger(const CCachePurger& rhs);
  144.         CCachePurger& operator = (const CCachePurger& rhs);
  145. };
  146. #endif __CSCUI_PURGE_H