Leaked source code of windows server 2003
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.

426 lines
16 KiB

  1. //=============================================================================
  2. // This include file contains definitions of structures and classes used to
  3. // implement the categories, as well as the rows and columns of information
  4. // displayed and saved in MSInfo (regardless of the data source).
  5. //=============================================================================
  6. #pragma once
  7. #include "version5extension.h"
  8. //-----------------------------------------------------------------------------
  9. // A prototype for a function used for sorting the contents of the list.
  10. //-----------------------------------------------------------------------------
  11. extern int CALLBACK ListSortFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
  12. //-----------------------------------------------------------------------------
  13. // An enumeration for all the available places we might get data. Also an
  14. // enumeration for environments a category supports.
  15. //-----------------------------------------------------------------------------
  16. typedef enum { LIVE_DATA, NFO_410, NFO_500, XML_SNAPSHOT, XML_DELTA, NFO_700 } DataSourceType;
  17. typedef enum { ALL_ENVIRONMENTS, NT_ONLY, MILLENNIUM_ONLY } CategoryEnvironment;
  18. //-----------------------------------------------------------------------------
  19. // A column description - this is used internally to the CMSInfoCategory
  20. // category, and won't concern the calling code.
  21. //-----------------------------------------------------------------------------
  22. class CMSInfoColumn
  23. {
  24. public:
  25. CMSInfoColumn();
  26. CMSInfoColumn(UINT uiCaption, UINT uiWidth, BOOL fSorts = TRUE, BOOL fLexical = TRUE, BOOL fAdvanced = FALSE);
  27. virtual ~CMSInfoColumn();
  28. UINT m_uiCaption;
  29. CString m_strCaption;
  30. UINT m_uiWidth;
  31. BOOL m_fSorts;
  32. BOOL m_fLexical;
  33. BOOL m_fAdvanced;
  34. CMSInfoColumn(LPCTSTR szCaption, UINT uiWidth, BOOL fSorts = TRUE, BOOL fLexical = TRUE, BOOL fAdvanced = FALSE) :
  35. m_uiCaption(0),
  36. m_strCaption(szCaption),
  37. m_uiWidth(uiWidth),
  38. m_fSorts(fSorts),
  39. m_fLexical(fLexical),
  40. m_fAdvanced(fAdvanced)
  41. {
  42. }
  43. };
  44. //-----------------------------------------------------------------------------
  45. // The CMSInfoCategory class corresponds to a category in the tree view. This
  46. // is an abstract base class for subclasses which implement categories for
  47. // various situations (such as live WMI data, XML Snapshot, XML Delta, etc.).
  48. //
  49. // Note - the view functionality (BASIC/ADVANCED) is included in this base
  50. // class because it's used by so many of the subclasses. Subclasses which
  51. // don't use the view (XML Delta, for example) should make all of their
  52. // columns basic.
  53. //-----------------------------------------------------------------------------
  54. class CMSInfoFile;
  55. class CMSInfoTextFile;
  56. class CMSInfoPrintHelper;
  57. class CMSInfoCategory
  58. {
  59. friend class CDataSource; // TBD fix this
  60. friend class CManageExtensionCategories;
  61. public:
  62. CMSInfoCategory() :
  63. m_uiCaption(0),
  64. m_pParent(NULL),
  65. m_pPrevSibling(NULL),
  66. m_pFirstChild(NULL),
  67. m_pNextSibling(NULL),
  68. m_acolumns(NULL),
  69. m_astrData(NULL),
  70. m_adwData(NULL),
  71. m_afRowAdvanced(NULL),
  72. m_hrError(S_OK),
  73. m_fDynamicColumns(TRUE),
  74. m_iSortColumn(-1),
  75. m_hti(NULL),
  76. m_fSkipCategory(FALSE),
  77. m_fShowCategory(TRUE)
  78. {
  79. }
  80. CMSInfoCategory(UINT uiCaption, LPCTSTR szName, CMSInfoCategory * pParent, CMSInfoCategory * pPrevious, CMSInfoColumn * pColumns = NULL, BOOL fDynamicColumns = TRUE, CategoryEnvironment environment = ALL_ENVIRONMENTS) :
  81. m_uiCaption(uiCaption),
  82. m_pParent(pParent),
  83. m_pPrevSibling(pPrevious),
  84. m_pFirstChild(NULL),
  85. m_pNextSibling(NULL),
  86. m_acolumns(pColumns),
  87. m_astrData(NULL),
  88. m_adwData(NULL),
  89. m_afRowAdvanced(NULL),
  90. m_strName(szName),
  91. m_hrError(S_OK),
  92. m_fDynamicColumns(fDynamicColumns),
  93. m_iRowCount(0),
  94. m_iColCount(0),
  95. m_iSortColumn(-1),
  96. m_hti(NULL),
  97. m_fSkipCategory(FALSE),
  98. m_fShowCategory(TRUE)
  99. {
  100. for (CMSInfoColumn * pColumn = m_acolumns; (pColumn && (pColumn->m_uiCaption || !pColumn->m_strCaption.IsEmpty())); m_iColCount++, pColumn++);
  101. if (m_acolumns && m_acolumns->m_fSorts)
  102. {
  103. m_iSortColumn = 0;
  104. m_fSortAscending = TRUE;
  105. m_fSortLexical = m_acolumns->m_fLexical;
  106. }
  107. // Check to see if this category belongs in this environment.
  108. if (environment != ALL_ENVIRONMENTS)
  109. {
  110. OSVERSIONINFO osv;
  111. osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  112. if (GetVersionEx(&osv))
  113. {
  114. if (environment == NT_ONLY)
  115. m_fSkipCategory = (osv.dwPlatformId != VER_PLATFORM_WIN32_NT);
  116. else
  117. m_fSkipCategory = (osv.dwPlatformId == VER_PLATFORM_WIN32_NT);
  118. }
  119. }
  120. }
  121. virtual ~CMSInfoCategory()
  122. {
  123. DeleteAllContent();
  124. };
  125. // Navigation functions for moving around in the category tree. Note, these
  126. // are included for convenience (and for cases with no UI), since you should
  127. // be able to do all of this using the actual tree control.
  128. virtual CMSInfoCategory * GetParent() { return m_pParent; };
  129. virtual CMSInfoCategory * GetFirstChild()
  130. {
  131. CMSInfoCategory * pChild = m_pFirstChild;
  132. while (pChild && (pChild->m_fSkipCategory || !pChild->m_fShowCategory))
  133. pChild = pChild->m_pNextSibling;
  134. return pChild;
  135. };
  136. virtual CMSInfoCategory * GetNextSibling()
  137. {
  138. CMSInfoCategory * pNext = m_pNextSibling;
  139. while (pNext && (pNext->m_fSkipCategory || !pNext->m_fShowCategory))
  140. pNext = pNext->m_pNextSibling;
  141. return pNext;
  142. };
  143. virtual CMSInfoCategory * GetPrevSibling()
  144. {
  145. CMSInfoCategory * pPrev = m_pPrevSibling;
  146. while (pPrev && (pPrev->m_fSkipCategory || !pPrev->m_fShowCategory))
  147. pPrev = pPrev->m_pPrevSibling;
  148. return pPrev;
  149. };
  150. // Return the count of categories in the subtree with this category as the root.
  151. int GetCategoryCount()
  152. {
  153. int nCount = 1;
  154. CMSInfoCategory * pChild = GetFirstChild();
  155. while (pChild)
  156. {
  157. nCount += pChild->GetCategoryCount();
  158. pChild = pChild->GetNextSibling();
  159. }
  160. return nCount;
  161. }
  162. // This function is used to control whether or not this category (and all
  163. // of its children) are shown or not. This will be called by the code which
  164. // processes the "/categories" command line flag.
  165. void SetShowCategory(BOOL fShow, BOOL fSetParent = TRUE)
  166. {
  167. // If we are supposed to show this category, then we had better
  168. // make sure all the parents are shown too.
  169. if (fShow && fSetParent)
  170. for (CMSInfoCategory * pParent = m_pParent; pParent; pParent = pParent->m_pParent)
  171. pParent->m_fShowCategory = TRUE;
  172. // Set the new flag for this category and each of this category's children.
  173. m_fShowCategory = fShow;
  174. for (CMSInfoCategory * pChild = m_pFirstChild; pChild; pChild = pChild->m_pNextSibling)
  175. pChild->SetShowCategory(fShow, FALSE);
  176. }
  177. // These functions are useful for associating a HTREEITEM with the
  178. // given category (very useful in find operations).
  179. protected:
  180. HTREEITEM m_hti;
  181. public:
  182. void SetHTREEITEM(HTREEITEM hti) { m_hti = hti; };
  183. HTREEITEM GetHTREEITEM() { return m_hti; };
  184. // Functions to get information for the data stored in this category.
  185. virtual void GetNames(CString * pstrCaption, CString * pstrName);
  186. virtual BOOL GetCategoryDimensions(int * piColumnCount, int * piRowCount);
  187. virtual BOOL IsRowAdvanced(int iRow);
  188. virtual BOOL IsColumnAdvanced(int iColumn);
  189. virtual BOOL GetColumnInfo(int iColumn, CString * pstrCaption, UINT * puiWidth, BOOL * pfSorts, BOOL * pfLexical);
  190. virtual BOOL GetData(int iRow, int iCol, CString ** ppstrData, DWORD * pdwData);
  191. virtual void SetColumnWidth(int iCol, int iWidth);
  192. // Return from where this category is getting its data. Also a function
  193. // to reset the state of the category (in case it's going to be reused,
  194. // and it's static).
  195. virtual DataSourceType GetDataSourceType() = 0;
  196. virtual void ResetCategory() { };
  197. // Get the current HRESULT for this category (set during refresh, for instance).
  198. virtual HRESULT GetHRESULT() { return m_hrError; };
  199. virtual void GetErrorText(CString * pstrTitle, CString * pstrMessage);
  200. virtual CString GetHelpTopic() { return CString(_T("")); };
  201. // Saving to disk and printing Functions a-stephl
  202. // Functions that take as parameters file HANDLES or HDC's are the ones that will normally be
  203. // called by the shell; the functions that take CMSInfo objects as parameters are used for
  204. // recursing the operation over the category's children
  205. public:
  206. static BOOL SaveNFO(HANDLE hFile,CMSInfoCategory* pCategory, BOOL fRecursive);
  207. virtual void Print(HDC hDC, BOOL bRecursive,int nStartPage = 0, int nEndPage = 0, LPTSTR lpMachineName = NULL);
  208. virtual BOOL SaveAsText(HANDLE hFile, BOOL bRecursive, LPTSTR lpMachineName = NULL);
  209. //virtual BOOL SaveAsXml(HANDLE hFile, BOOL bRecursive);
  210. virtual BOOL SaveXML(HANDLE hFile);
  211. protected:
  212. virtual BOOL SaveToNFO(CMSInfoFile* pFile);
  213. virtual void SaveElements(CMSInfoFile *pFile);
  214. virtual BOOL SaveAsText(CMSInfoTextFile* pTxtFile, BOOL bRecursive);
  215. //virtual BOOL SaveAsXml(CMSInfoTextFile* pTxtFile, BOOL bRecursive);
  216. virtual void Print(CMSInfoPrintHelper* pPrintHelper, BOOL bRecursive);
  217. virtual BOOL SaveXML(CMSInfoTextFile* pTxtFile);
  218. public:
  219. CMSInfoCategory * m_pParent;
  220. CMSInfoCategory * m_pFirstChild;
  221. CMSInfoCategory * m_pNextSibling;
  222. CMSInfoCategory * m_pPrevSibling;
  223. int m_iSortColumn; // currently sorting by this column
  224. BOOL m_fSortLexical; // sort the current column lexically
  225. BOOL m_fSortAscending; // sort the current column ascending
  226. protected:
  227. BOOL m_fSkipCategory; // skip this category (wrong environment)
  228. BOOL m_fShowCategory; // show this category (defaults to true)
  229. int m_iRowCount, m_iColCount; // dimensions of the data
  230. CMSInfoColumn * m_acolumns; // should be [m_iColCount]
  231. BOOL m_fDynamicColumns; // true if m_acolumns should be deleted
  232. CString * m_astrData; // should be [m_iRowCount * m_iColCount]
  233. DWORD * m_adwData; // should be [m_iRowCount * m_iColCount]
  234. BOOL * m_afRowAdvanced; // should be [m_iRowCount]
  235. UINT m_uiCaption; // resource ID for the caption string, used to load...
  236. CString m_strCaption; // the caption (display) string
  237. CString m_strName; // internal category name (non-localized)
  238. HRESULT m_hrError; // HRESULT for a possible category-wide error
  239. void DeleteAllContent();
  240. void DeleteContent();
  241. void AllocateAllContent(int iRowCount, int iColCount);
  242. void AllocateContent(int iRowCount);
  243. void SetData(int iRow, int iCol, const CString & strData, DWORD dwData);
  244. void SetAdvancedFlag(int iRow, BOOL fAdvanced);
  245. };
  246. //-----------------------------------------------------------------------------
  247. // The CMSInfoLiveCategory class implements categories for live data view.
  248. // This is done primarily by adding a Refresh() function and a constructor
  249. // which takes a function pointer for refreshing the category and pointers
  250. // to category relatives.
  251. //
  252. // This class has a member variable which is a pointer to a refresh function.
  253. // This function returns an HRESULT, and takes the following values:
  254. //
  255. // pWMI a CWMIHelper object, which abstracts data access
  256. // dwIndex a category specific value which the refresh function can
  257. // use to determine which of multiple categories to refresh
  258. // pfCancel a flag indicating that the refresh should be cancelled
  259. // which should be checked frequently during the refresh
  260. // aColValues an array of CPtrList objects, which should contain the
  261. // results of the refresh, in the form of a list of CMSIValue
  262. // instances (each list is for a given column, and should contain
  263. // entries equal to the number of rows)
  264. // iColCount the number of entries in the aColValues array
  265. // ppCache a pointer to a void pointer which the function can use to save
  266. // cached information - changes to this pointer will be saved
  267. // through multiple calls to the refresh function (note: if the
  268. // refresh function is called with a NULL value for pWMI, the
  269. // function should free whatever's been allocated into the
  270. // ppCache pointer)
  271. //-----------------------------------------------------------------------------
  272. struct CMSIValue
  273. {
  274. CMSIValue(LPCTSTR szValue, DWORD dwValue, BOOL fAdvanced = FALSE) :
  275. m_strValue(szValue),
  276. m_dwValue(dwValue),
  277. m_fAdvanced(fAdvanced)
  278. {
  279. }
  280. CString m_strValue;
  281. DWORD m_dwValue;
  282. BOOL m_fAdvanced;
  283. };
  284. class CLiveDataSource;
  285. class CWMIHelper;
  286. typedef HRESULT (*RefreshFunction)(CWMIHelper * pWMI,
  287. DWORD dwIndex,
  288. volatile BOOL * pfCancel,
  289. CPtrList * aColValues,
  290. int iColCount,
  291. void ** ppCache);
  292. class CMSInfoLiveCategory : public CMSInfoCategory
  293. {
  294. friend DWORD WINAPI ThreadRefresh(void * pArg);
  295. friend class CXMLDataSource;
  296. friend class CXMLSnapshotCategory;
  297. public:
  298. // Functions overridden from the base class:
  299. virtual ~CMSInfoLiveCategory();
  300. virtual DataSourceType GetDataSourceType() { return LIVE_DATA; };
  301. void GetErrorText(CString * pstrTitle, CString * pstrMessage);
  302. // Functions specific to the subclass:
  303. CMSInfoLiveCategory(UINT uiCaption, LPCTSTR szName, RefreshFunction pFunction, DWORD dwRefreshIndex, CMSInfoCategory * pParent, CMSInfoCategory * pPrevious, const CString & strHelpTopic = _T(""), CMSInfoColumn * pColumns = NULL, BOOL fDynamicColumns = TRUE, CategoryEnvironment environment = ALL_ENVIRONMENTS);
  304. CMSInfoLiveCategory(CMSInfoLiveCategory & copyfrom);
  305. CMSInfoLiveCategory(INTERNAL_CATEGORY * pinternalcat);
  306. virtual BOOL Refresh(CLiveDataSource * pSource, BOOL fRecursive);
  307. BOOL RefreshSynchronous(CLiveDataSource * pSource, BOOL fRecursive);
  308. BOOL RefreshSynchronousUI(CLiveDataSource * pSource, BOOL fRecursive, UINT uiMessage, HWND hwnd);
  309. BOOL EverBeenRefreshed() { return (m_dwLastRefresh != 0); }
  310. void ResetCategory() { m_dwLastRefresh = 0; };
  311. void SetMachine(LPCTSTR szMachine) { m_strMachine = szMachine; m_hrError = S_OK; };
  312. CString GetHelpTopic() { return m_strHelpTopic; };
  313. protected:
  314. DWORD m_dwLastRefresh;
  315. DWORD m_dwRefreshIndex;
  316. RefreshFunction m_pRefreshFunction;
  317. CString m_strMachine;
  318. CString m_strHelpTopic;
  319. };
  320. //-----------------------------------------------------------------------------
  321. // The CMSInfoHistoryCategory class implements categories for the view
  322. // of history data.
  323. //-----------------------------------------------------------------------------
  324. class CMSInfoHistoryCategory : public CMSInfoLiveCategory
  325. {
  326. public:
  327. CMSInfoHistoryCategory(UINT uiCaption, LPCTSTR szName, CMSInfoCategory * pParent, CMSInfoCategory * pPrevious, CMSInfoColumn * pColumns = NULL, BOOL fDynamicColumns = TRUE) :
  328. CMSInfoLiveCategory(uiCaption, szName, NULL, 0, pParent, pPrevious, _T(""), pColumns, fDynamicColumns, ALL_ENVIRONMENTS),
  329. m_iDeltaIndex(-1)
  330. {
  331. }
  332. void UpdateDeltaIndex(int iIndex)
  333. {
  334. m_dwLastRefresh = 0;
  335. CMSInfoHistoryCategory * pChild = (CMSInfoHistoryCategory *)GetFirstChild();
  336. while (pChild)
  337. {
  338. pChild->UpdateDeltaIndex(iIndex);
  339. pChild = (CMSInfoHistoryCategory *)pChild->GetNextSibling();
  340. }
  341. m_iDeltaIndex = iIndex;
  342. }
  343. BOOL Refresh(CLiveDataSource * pSource, BOOL fRecursive);
  344. public:
  345. CPtrList m_aValList[5];
  346. void ClearLines();
  347. /*void InsertChangeLine(int nDays, LPCTSTR szType, LPCTSTR szName, LPCTSTR szProperty, LPCTSTR szFromVal, LPCTSTR szToVal);
  348. void InsertAddLine(int nDays, LPCTSTR szType, LPCTSTR szName);
  349. void InsertRemoveLine(int nDays, LPCTSTR szType, LPCTSTR szName);
  350. void InsertLine(int nDays, LPCTSTR szType, LPCTSTR szName, LPCTSTR szProperty, LPCTSTR szDetails = NULL);*/
  351. void InsertChangeLine(CTime tm, LPCTSTR szType, LPCTSTR szName, LPCTSTR szProperty, LPCTSTR szFromVal, LPCTSTR szToVal);
  352. void InsertAddLine(CTime tm, LPCTSTR szType, LPCTSTR szName);
  353. void InsertRemoveLine(CTime tm, LPCTSTR szType, LPCTSTR szName);
  354. void InsertLine(CTime tm, LPCTSTR szType, LPCTSTR szName, LPCTSTR szProperty, LPCTSTR szDetails = NULL);
  355. void CommitLines();
  356. int m_iDeltaIndex;
  357. private:
  358. };