DirProviderRS.h
上传用户:benben_wyd
上传日期:2010-02-26
资源大小:1229k
文件大小:4k
源码类别:

书籍源码

开发平台:

Visual C++

  1. // DirProviderRS.h : Declaration of the CDirProviderRowset
  2. #ifndef __CDirProviderRowset_H_
  3. #define __CDirProviderRowset_H_
  4. #include "resource.h"       // main symbols
  5. class CDirProviderWindowsFile
  6. {
  7. public:
  8.     TCHAR    cFileName[ MAX_PATH ];
  9.     TCHAR    cShortFileName[ 14 ]; 
  10.     DWORD    nFileSize;
  11.     TCHAR    strFileAttributes[7]; 
  12. BEGIN_PROVIDER_COLUMN_MAP(CDirProviderWindowsFile)
  13.     PROVIDER_COLUMN_ENTRY("FileName",       1, cFileName)
  14.     PROVIDER_COLUMN_ENTRY("AltFileName",    2, cShortFileName)
  15.     PROVIDER_COLUMN_ENTRY("FileSize",       3, nFileSize)
  16.     PROVIDER_COLUMN_ENTRY("FileAttributes", 4, strFileAttributes)
  17. END_PROVIDER_COLUMN_MAP()
  18. };
  19. // CDirProviderCommand
  20. class ATL_NO_VTABLE CDirProviderCommand : 
  21. public CComObjectRootEx<CComSingleThreadModel>,
  22. public IAccessorImpl<CDirProviderCommand>,
  23. public ICommandTextImpl<CDirProviderCommand>,
  24. public ICommandPropertiesImpl<CDirProviderCommand>,
  25. public IObjectWithSiteImpl<CDirProviderCommand>,
  26. public IConvertTypeImpl<CDirProviderCommand>,
  27. public IColumnsInfoImpl<CDirProviderCommand>
  28. {
  29. public:
  30. BEGIN_COM_MAP(CDirProviderCommand)
  31. COM_INTERFACE_ENTRY(ICommand)
  32. COM_INTERFACE_ENTRY(IObjectWithSite)
  33. COM_INTERFACE_ENTRY(IAccessor)
  34. COM_INTERFACE_ENTRY(ICommandProperties)
  35. COM_INTERFACE_ENTRY2(ICommandText, ICommand)
  36. COM_INTERFACE_ENTRY(IColumnsInfo)
  37. COM_INTERFACE_ENTRY(IConvertType)
  38. END_COM_MAP()
  39. // ICommand
  40. public:
  41. HRESULT FinalConstruct()
  42. {
  43. HRESULT hr = CConvertHelper::FinalConstruct();
  44. if (FAILED (hr))
  45. return hr;
  46. hr = IAccessorImpl<CDirProviderCommand>::FinalConstruct();
  47. if (FAILED(hr))
  48. return hr;
  49. return CUtlProps<CDirProviderCommand>::FInit();
  50. }
  51. void FinalRelease()
  52. {
  53. IAccessorImpl<CDirProviderCommand>::FinalRelease();
  54. }
  55. HRESULT WINAPI Execute(IUnknown * pUnkOuter, REFIID riid, DBPARAMS * pParams, 
  56.   LONG * pcRowsAffected, IUnknown ** ppRowset);
  57. static ATLCOLUMNINFO* GetColumnInfo(CDirProviderCommand* pv, ULONG* pcInfo)
  58. {
  59. return CDirProviderWindowsFile::GetColumnInfo(pv,pcInfo);
  60. }
  61. BEGIN_PROPSET_MAP(CDirProviderCommand)
  62. BEGIN_PROPERTY_SET(DBPROPSET_ROWSET)
  63. PROPERTY_INFO_ENTRY(IAccessor)
  64. PROPERTY_INFO_ENTRY(IColumnsInfo)
  65. PROPERTY_INFO_ENTRY(IConvertType)
  66. PROPERTY_INFO_ENTRY(IRowset)
  67. PROPERTY_INFO_ENTRY(IRowsetIdentity)
  68. PROPERTY_INFO_ENTRY(IRowsetInfo)
  69. PROPERTY_INFO_ENTRY(IRowsetLocate)
  70. PROPERTY_INFO_ENTRY(BOOKMARKS)
  71. PROPERTY_INFO_ENTRY(BOOKMARKSKIPPED)
  72. PROPERTY_INFO_ENTRY(BOOKMARKTYPE)
  73. PROPERTY_INFO_ENTRY(CANFETCHBACKWARDS)
  74. PROPERTY_INFO_ENTRY(CANHOLDROWS)
  75. PROPERTY_INFO_ENTRY(CANSCROLLBACKWARDS)
  76. PROPERTY_INFO_ENTRY(LITERALBOOKMARKS)
  77. PROPERTY_INFO_ENTRY(ORDEREDBOOKMARKS)
  78. END_PROPERTY_SET(DBPROPSET_ROWSET)
  79. END_PROPSET_MAP()
  80. };
  81. class CDirProviderRowset : public CRowsetImpl< CDirProviderRowset, CDirProviderWindowsFile, CDirProviderCommand>
  82. {
  83. public:
  84. HRESULT Execute(DBPARAMS * pParams, LONG* pcRowsAffected)
  85. {
  86. USES_CONVERSION;
  87. BOOL bFound = FALSE;
  88. HANDLE hFile;
  89. LPTSTR  szDir = (m_strCommandText == _T("")) ? _T("*.*") : OLE2T(m_strCommandText);
  90. CDirProviderWindowsFile wf;
  91. WIN32_FIND_DATA fileInfo;
  92. hFile = FindFirstFile(szDir, &fileInfo);
  93. if (hFile == INVALID_HANDLE_VALUE)
  94. return DB_E_ERRORSINCOMMAND;
  95. LONG cFiles = 1;
  96. BOOL bMoreFiles = TRUE;
  97. while (bMoreFiles)
  98. {
  99. wf.nFileSize = fileInfo.nFileSizeLow;
  100. strcpy(wf.cFileName, fileInfo.cFileName);
  101. strcpy(wf.cShortFileName, fileInfo.cAlternateFileName);
  102. strcpy (wf.strFileAttributes, "");
  103. if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  104. strcat(wf.strFileAttributes, "D");
  105. }
  106. if (fileInfo.dwFileAttributes &  FILE_ATTRIBUTE_READONLY) {
  107. strcat(wf.strFileAttributes, "R");
  108. }
  109. if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) {
  110. strcat(wf.strFileAttributes, "S");
  111. }
  112. if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) {
  113. strcat(wf.strFileAttributes, "A");
  114. }
  115. if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) {
  116. strcat(wf.strFileAttributes, "H");
  117. if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY) {
  118. strcat(wf.strFileAttributes, "T");
  119. if (!m_rgRowData.Add(wf))
  120. return E_OUTOFMEMORY;
  121. bMoreFiles = FindNextFile(hFile, &fileInfo);
  122. cFiles++;
  123. }
  124. FindClose(hFile);
  125. if (pcRowsAffected != NULL)
  126. *pcRowsAffected = cFiles;
  127. return S_OK;
  128. }
  129. };
  130. #endif //__CDirProviderRowset_H_