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

Windows Kernel

Development Platform:

Visual C++

  1. #ifndef _BITBUCK_INC
  2. #define _BITBUCK_INC
  3. #include "ids.h"
  4. #include "undo.h"
  5. #include "idlcomm.h" // for HIDA
  6. #include "mrsw.h" // for MRSW
  7. //
  8. // whacky #defines
  9. //
  10. #define DELETEMAX 100000
  11. #define MAX_BITBUCKETS 27
  12. #define MAX_DRIVES 26
  13. #define OPENFILERETRYTIME 500
  14. #define OPENFILERETRYCOUNT 10
  15. #define SERVERDRIVE 26
  16. #define MAX_EMPTY_FILES     100     // if we have more that MAX_EMPTY_FILES then we use the generic "do you want to empty" message.  
  17. #define TF_BITBUCKET 0x10000000
  18. // #define TF_BITBUCKET TF_ERROR
  19. #ifdef DEBUG
  20. #define BB_DELETED_ENTRY_MAX 10     // smaller to force compaction more often
  21. #else
  22. #define BB_DELETED_ENTRY_MAX 100
  23. #endif
  24. #define BITBUCKET_DATAFILE_VERSION  0       // Ansi Win95 wastebasket
  25. #define BITBUCKET_DATAFILE_VERSION2 2       // Unicode Win96/Cairo wastebasket
  26. #define BITBUCKET_NT4_VERSION       2
  27. #define BITBUCKET_WIN95_VERSION 0
  28. #define BITBUCKET_CURRENT_WIN_VERSION  4    // win9x + IE4 integrated, win98
  29. #define BITBUCKET_CURRENT_NT_VERSION  5     // NT4 + IE4 integrated, NT5
  30. #define OPENBBINFO_READ                 0x00000000
  31. #define OPENBBINFO_WRITE                0x00000001
  32. #define OPENBBINFO_CREATE               0x00000003
  33. #ifdef WINNT
  34. #define BITBUCKET_CURRENT_VERSION BITBUCKET_CURRENT_NT_VERSION
  35. #else
  36. #define BITBUCKET_CURRENT_VERSION BITBUCKET_CURRENT_WIN_VERSION
  37. #endif
  38. #define PIDLTODATAENTRYID(pidl) ((LPBBDATAENTRYIDA)(((LPBYTE)pidl) + (((LPCITEMIDLIST)(pidl))->mkid.cb - SIZEOF(BBDATAENTRYIDA))))
  39. #define BB_IsRealID(pidl) ( ((LPBYTE)pidl) < ((LPBYTE)PIDLTODATAENTRYID(pidl)))
  40. #define DATAENTRYIDATOW(pbbidl) ((LPBBDATAENTRYIDW)(((LPBYTE)pbbidl) - FIELD_OFFSET(BBDATAENTRYIDW,cb)))
  41. #define IsDeletedEntry(pbbde) (! (((BBDATAENTRYA*)pbbde)->szOriginal[0]) )
  42. #define MarkEntryDeleted(pbbde) ((BBDATAENTRYA*)pbbde)->szOriginal[0] = '';
  43. #define CHECK_PURGE_MAX 500
  44. // the maximum we'll write to the info file at one time
  45. #define MAX_WRITE_SIZE (((CHECK_PURGE_MAX + 1) * SIZEOF(BBDATAENTRY)) + SIZEOF(BBDATAHEADER))
  46. //
  47. // struct definitions
  48. //
  49. //
  50. // BitBucketShellFolder stuff
  51. //
  52. typedef struct _CBitBucket      // dxi
  53. {
  54. #ifdef __cplusplus
  55.     void *              ipf;
  56.     void *              isf;
  57.     void *              icm;
  58.     void *              ips;
  59.     void *              isei;
  60. #else // __cplusplus
  61.     IPersistFolder2     ipf;
  62.     IShellFolder2       isf;
  63.     IContextMenu        icm;
  64.     IShellPropSheetExt  ips;
  65.     IShellExtInit       isei;
  66. #endif // __cplusplus
  67.     UINT                cRef;
  68.     LPITEMIDLIST        pidl;
  69. } CBitBucket;
  70. // this is the old (win95) data header.  it's maintained in the info file
  71. // but only used for verification.  for current stuff look at the driveinfo,
  72. // which is kept in the registry.
  73. typedef struct {
  74.     int idVersion;
  75.     int cFiles;                     // the # of items in this drive's recycle bin
  76.     int cCurrent;                   // the current file number.
  77.     UINT cbDataEntrySize;           // size of each entry
  78.     DWORD dwSize;                   // total size of this recycle bin drive
  79. } BBDATAHEADER, * LPBBDATAHEADER;
  80. typedef struct {
  81.     CHAR szOriginal[MAX_PATH];  // original filename (if szOriginal[0] is 0, then it's a deleted entry)
  82.     int  iIndex;                // index (key to name)
  83.     int idDrive;                // which drive bucket it's currently in
  84.     FILETIME ft;
  85.     DWORD dwSize;
  86.     // shouldn't need file attributes because we did a move file
  87.     // which should have preserved them.
  88. } BBDATAENTRYA, * LPBBDATAENTRYA;
  89. typedef struct {
  90.     CHAR szShortName[MAX_PATH]; // original filename, shortened (if szOriginal[0] is 0, then it's a deleted entry)
  91.     int iIndex;                 // index (key to name)
  92.     int idDrive;                // which drive bucket it's currently in
  93.     FILETIME ft;
  94.     DWORD dwSize;
  95.     WCHAR szOriginal[MAX_PATH]; // original filename
  96. } BBDATAENTRYW, * LPBBDATAENTRYW;
  97. typedef struct {
  98.     WORD cb;
  99.     BBDATAENTRYA bbde;
  100. } BBDATAENTRYIDA;
  101. typedef UNALIGNED BBDATAENTRYIDA * LPBBDATAENTRYIDA;
  102. typedef struct {
  103.     WCHAR wszOriginal[MAX_PATH];
  104.     WORD cb;
  105.     BBDATAENTRYA bbde;
  106. } BBDATAENTRYIDW;
  107. typedef UNALIGNED BBDATAENTRYIDW * LPBBDATAENTRYIDW;
  108. #ifdef UNICODE
  109. #define BBDATAENTRY     BBDATAENTRYW
  110. #define LPBBDATAENTRY   LPBBDATAENTRYW
  111. #define BBDATAENTRYID   BBDATAENTRYIDW
  112. #define LPBBDATAENTRYID LPBBDATAENTRYIDW
  113. #else
  114. #define BBDATAENTRY     BBDATAENTRYA
  115. #define LPBBDATAENTRY   LPBBDATAENTRYA
  116. #define BBDATAENTRYID   BBDATAENTRYIDA
  117. #define LPBBDATAENTRYID LPBBDATAENTRYIDA
  118. #endif
  119. // On NT5 we are finally going to have cross-process syncrhonization to 
  120. // the Recycle Bin. We replaced the global LPBBDRIVEINFO array with an
  121. // array of the following structures:
  122. typedef struct {
  123.     BOOL fInited;               // is this particular BBSYNCOBJECT fully inited (needed when we race to create it)
  124. #ifdef BB_USE_MRSW
  125.     PMRSW pmrsw;                // Multiple-Reader-Single-Writer syncronization object for this bitbucket
  126. #endif // BB_USE_MRSW
  127.     HANDLE hgcNextFileNum;      // a global counter that garuntees unique deleted file names
  128.     HANDLE hgcDirtyCount;       // a global counter to tell us if we need to re-read the bitbucket settings from the registry (percent, max size, etc)
  129.     LONG lCurrentDirtyCount;    // out current dirty count; we compare this to hgcDirtyCount to see if we need to update the settings from the registry
  130.     HKEY hkey;                  // HKLM reg key, under which we store the settings for this specific bucket (iPercent and fNukeOnDelete).
  131.     HKEY hkeyPerUser;           // HKCU reg key, under which we have volital reg values indicatiog if there is a need to purge or compact this bucket
  132.     BOOL fIsUnicode;            // is this a bitbucket on a drive whose INFO2 file uses BBDATAENTRYW structs?
  133.     int iPercent;               // % of the drive to use for the bitbucket
  134.     DWORD cbMaxSize;            // maximum size of bitbucket (in bytes), NOTE: we use a dword because the biggest the BB can ever grow to is 4 gigabytes.
  135.     DWORD dwClusterSize;        // cluster size of this volume, needed to round all the file sizes
  136.     ULONGLONG qwDiskSize;       // total size of the disk - takes into account quotas on NTFS
  137.     BOOL fNukeOnDelete;         // I love the smell of napalm in the morning.
  138.     LPITEMIDLIST pidl;          // pidl = bitbucket dir for this drive
  139.     int cchBBDir;               // # of characters that makes up the bitbucket directory.
  140. } BBSYNCOBJECT, *PBBSYNCOBJECT;
  141. // The bitbucket datafile (INFO on win95, INFO2 on IE4/NT5) format is as follows:
  142. //
  143. // (binary writes)
  144. //
  145. //      BITBUCKETDATAHEADER     // header
  146. //      BBDATAENTRY[X]          // array of BBDATAENTRYies
  147. //
  148. typedef struct _BitBucketDriveInfo
  149. {
  150.     int         cFiles;             // # of items in this drive's recycle bin)
  151.     int         cCurrent;           // counts the current "delete operation"
  152.     DWORD       dwSize;             // how much stuff is in this bit bucket
  153.     UINT        cbDataEntrySize;    // size of each data entry
  154.     int         iPercent;           // what percent of the drive to use
  155.     ULONGLONG   cbMaxSize;          // maximum size of bitbucket (in bytes)
  156.     DWORD       dwClusterSize;
  157.     DWORD       dwTotalClusters;
  158.     BOOL        fNukeOnDelete;
  159.     LPITEMIDLIST pidl;              // points to the BitBucket dir for this drive
  160. } BBDRIVEINFO, *LPBBDRIVEINFO;
  161. typedef struct _RegBBDriveInfo // this is the info as stored in the registry
  162. {
  163.     int idVersion;
  164.     BBDRIVEINFO bbdi;
  165. } BBREGDRIVEINFO, *LPBBREGDRIVEINFO;
  166. typedef struct {
  167.     DWORD dwSize;
  168.     BOOL fGlobal;
  169.     WORD  wUsePercent[MAX_BITBUCKETS + 1];
  170.     DWORD dwNukeOnDelete;  // BITFIELD
  171.     DWORD dwDummy; // to force a new size
  172. } BBREGINFO;
  173. typedef struct {
  174.     PROPSHEETPAGE psp;
  175.     HIDA hida;
  176.     LPCITEMIDLIST pidl;
  177. } BBFILEPROPINFO;
  178. typedef struct {
  179.     CBitBucket *pbb;
  180.     LPBBDATAENTRY lpbbde;
  181.     DWORD grfFlags;
  182.     HDPA hdpa;
  183.     int nItem;
  184.     // keep track of files not found but in info file
  185.     DWORD unused1;
  186.     DWORD unused2;
  187.     DWORD dwUnused;
  188.     int iUnused;
  189. } ENUMDELETED, *LPENUMDELETED;
  190. typedef struct _BB_FIND_DATA {
  191.     int iIndex;
  192.     DWORD dwFileAttributes;
  193.     FILETIME ftCreationTime;
  194.     FILETIME ftLastAccessTime;
  195.     FILETIME ftLastWriteTime;
  196.     DWORD nFileSizeHigh;
  197.     DWORD nFileSizeLow;
  198.     TCHAR   szType[ 5 ];        // Only the short filetype really (".xyz" + Nul)
  199. } BBFINDDATA, *LPBBFINDDATA;
  200. typedef struct {
  201.     BOOL            bProcessedRoot; // tells if we are the first call in the recursive chain and we need to do root-specific processing
  202.     int             cchBBDir;       // count of characters in the recycle bin dir (eg "C:Recycler<sid>")
  203.     int             cchDelta;       // count of characters that the path will increase (or decrease if negative) by when moved under the recycle bin directory
  204.     ULONGLONG       cbSize;         // size of the folder
  205.     TCHAR           szNonDeletableFile[MAX_PATH];   // an output buffer that holds the name of the file that cannot be deleted, if one exists
  206.     TCHAR           szPath[MAX_PATH];   // scratch buffer for stack savings when recursing
  207.     WIN32_FIND_DATA fd;             // also for stack savings
  208. } FOLDERDELETEINFO, *LPFOLDERDELETEINFO;
  209. //
  210. // constants
  211. //
  212. #define c_szInfo2           TEXT("INFO2")    // version 2 of the db file (used in IE4, win98, NT5, ...)
  213. #define c_szInfo            TEXT("INFO")     // version 1 of the db file (used in win95, osr2, NT4)
  214. #define c_szRecycled        TEXT("Recycled")
  215. #define c_szPurgeInfo       TEXT("PurgeInfo")
  216. #define c_szDStarDotStar    TEXT("D*.*")
  217. #define c_szBitBucket       TEXT("BitBucket")
  218. #define c_szRegRealMode     TEXT("Network\Real Mode Net")
  219. #define c_szWinDir          REGSTR_VAL_WINDIR
  220. #define c_szRegSetup        REGSTR_PATH_SETUP
  221. //
  222. // globals
  223. //
  224. extern PBBSYNCOBJECT g_pBitBucket[MAX_BITBUCKETS];
  225. extern HKEY g_hkBitBucket;
  226. extern HANDLE g_hgcNumDeleters;
  227. //
  228. // prototypes (used mostly by bitbuck.c, bitbcksf.c and bitbuck1.cpp)
  229. //
  230. BOOL InitBBGlobals();
  231. void BitBucket_Terminate();
  232. STDAPI_(BOOL) IsBitBucketableDrive(int idDrive);
  233. int DriveIDFromBBPath(LPNCTSTR pszPath);
  234. void UpdateIcon(BOOL fFull);
  235. void NukeFileInfoBeforePoint(HANDLE hfile, LPBBDATAENTRYW pbbdew, DWORD dwDataEntrySize);
  236. BOOL ReadNextDataEntry(HANDLE hfile, LPBBDATAENTRYW pbbde, BOOL fSkipDeleted, DWORD dwDataEntrySize, int idDrive);
  237. void CloseBBInfoFile(HANDLE hFile, int idDrive);
  238. HANDLE OpenBBInfoFile(int idDrive, DWORD dwFlags, int iRetryCount);
  239. int BBPathToIndex(LPCTSTR pszPath);
  240. void GetDeletedFileName(LPTSTR pszFileName, int idDrive, int iIndex, LPNTSTR pszOriginal);
  241. void DriveIDToBBPath(int idDrive, LPTSTR pszPath);
  242. IShellFolderViewCB* BitBucket_CreateSFVCB(IShellFolder* psf, CBitBucket* pBBFolder);
  243. void DriveIDToBBRoot(int idDrive, LPTSTR szPath);
  244. void DriveIDToBBVolumeRoot(int idDrive, LPTSTR szPath);
  245. BOOL GetNetHomeDir(LPTSTR pszPath);
  246. BOOL PersistBBDriveSettings(int idDrive, int iPercent, BOOL fNukeOnDelete);
  247. BOOL MakeBitBucket(int idDrive);
  248. DWORD PurgeBBFiles(int idDrive);
  249. BOOL PersistGlobalSettings(BOOL fUseGlobalSettings, BOOL fNukeOnDelete, int iPercent);
  250. BOOL RefreshAllBBDriveSettings();
  251. BOOL RefreshBBDriveSettings(int idDrive);
  252. void CheckCompactAndPurge();
  253. void BBPurgeAll(CBitBucket * that, HWND hwndOwner, DWORD dwFlags);
  254. void BBSort(HWND hwndOwner, int id);
  255. STDAPI BBHandleFSNotify(HWND hwndOwner, LONG lEvent, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2);
  256. void BBInitializeViewWindow(HWND hwndView);
  257. BOOL BBDeleteFile(LPTSTR lpszFile, LPINT lpiReturn, LPUNDOATOM lpua, BOOL fIsDir, WIN32_FIND_DATA *pfd);
  258. BOOL IsFileInBitBucket(LPCTSTR pszPath);
  259. void UndoBBFileDelete(LPCTSTR lpszOriginal, LPCTSTR lpszDelFile);
  260. BOOL BBWillRecycle(LPCTSTR lpszFile, INT* piRet);
  261. void BBCheckRestoredFiles(LPTSTR lpszSrc);
  262. STDAPI_(void) LaunchDiskCleanup(HWND hwnd, int idDrive);
  263. STDAPI_(BOOL) GetDiskCleanupPath(LPTSTR pszBuf, UINT cbSize);
  264. STDAPI_(BOOL) IsRecycleBinEmpty();
  265. STDAPI_(void) SHUpdateRecycleBinIcon();
  266. STDAPI_(void) SaveRecycleBinInfo();
  267. #endif // _BITBUCK_INC