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.

242 lines
6.2 KiB

  1. // PropPageDumpFiles.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "emshell.h"
  5. #include "PropPageDumpFiles.h"
  6. #include <comdef.h>
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CPropPageDumpFiles property page
  14. IMPLEMENT_DYNCREATE(CPropPageDumpFiles, CPropertyPage)
  15. extern BSTR CopyBSTR( LPBYTE pb, ULONG cb );
  16. extern PEmObject GetEmObj(BSTR bstrEmObj);
  17. CPropPageDumpFiles::CPropPageDumpFiles() : CPropertyPage(CPropPageDumpFiles::IDD)
  18. {
  19. //{{AFX_DATA_INIT(CPropPageDumpFiles)
  20. // NOTE: the ClassWizard will add member initialization here
  21. //}}AFX_DATA_INIT
  22. }
  23. CPropPageDumpFiles::~CPropPageDumpFiles()
  24. {
  25. }
  26. void CPropPageDumpFiles::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CPropertyPage::DoDataExchange(pDX);
  29. //{{AFX_DATA_MAP(CPropPageDumpFiles)
  30. DDX_Control(pDX, IDC_LIST_DUMPFILES, m_ListCtrl);
  31. //}}AFX_DATA_MAP
  32. }
  33. BEGIN_MESSAGE_MAP(CPropPageDumpFiles, CPropertyPage)
  34. //{{AFX_MSG_MAP(CPropPageDumpFiles)
  35. ON_BN_CLICKED(IDC_BUTTON_EXPORT, OnButtonExport)
  36. //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CPropPageDumpFiles message handlers
  40. BOOL CPropPageDumpFiles::OnInitDialog()
  41. {
  42. CPropertyPage::OnInitDialog();
  43. // TODO: Add extra initialization here
  44. //Load the string resources for the CListCtrl columns
  45. CString strFileName, strSize, strTime;
  46. strFileName.LoadString(IDS_LC_FILENAME);
  47. strSize.LoadString(IDS_LC_FILESIZE);
  48. strTime.LoadString(IDS_LC_FILETIME);
  49. //Add the columns to the list control
  50. m_ListCtrl.BeginSetColumn(3);
  51. m_ListCtrl.AddColumn(strFileName);
  52. m_ListCtrl.AddColumn(strSize, VT_I4);
  53. m_ListCtrl.AddColumn(strTime);
  54. m_ListCtrl.EndSetColumn();
  55. //Populate the dump list control
  56. PopulateDumpType();
  57. m_ListCtrl.ResizeColumnsFitScreen();
  58. m_ListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT);
  59. return TRUE; // return TRUE unless you set the focus to a control
  60. // EXCEPTION: OCX Property Pages should return FALSE
  61. }
  62. void CPropPageDumpFiles::PopulateDumpType()
  63. {
  64. _variant_t var; //This will create and initialize the var variant
  65. HRESULT hr = E_FAIL;
  66. LONG lLBound = 0;
  67. LONG lUBound = 0;
  68. BSTR bstrEmObj = NULL;
  69. BSTR bstrEmObjectFilter = NULL;
  70. EmObject *pCurrentObj = NULL;
  71. EmObject EmObjectFilter;
  72. memset(&EmObjectFilter, 0, sizeof( EmObject ) );
  73. do {
  74. memcpy( &EmObjectFilter, m_pEmObject, sizeof( EmObject ) );
  75. EmObjectFilter.type = EMOBJ_MINIDUMP;
  76. bstrEmObjectFilter = CopyBSTR ( (LPBYTE)&EmObjectFilter, sizeof( EmObject ) );
  77. //Populate the list control based on the EmObjectType
  78. //Enumerate all the objects and stick them in the variant
  79. hr = m_pIEmManager->EnumObjectsEx(bstrEmObjectFilter, &var);
  80. if(FAILED(hr)) break;
  81. //Get the lower and upper bounds of the variant array
  82. hr = SafeArrayGetLBound(var.parray, 1, &lLBound);
  83. if(FAILED(hr)) break;
  84. hr = SafeArrayGetUBound(var.parray, 1, &lUBound);
  85. if(FAILED(hr)) break;
  86. //There are elements at both the lower bound and upper bound, so include them
  87. for(; lLBound <= lUBound; lLBound++)
  88. {
  89. //Get a BSTR object from the safe array
  90. hr = SafeArrayGetElement(var.parray, &lLBound, &bstrEmObj);
  91. if (FAILED(hr)) break;
  92. //Create a local copy of the EmObject (there aren't any pointers in
  93. //EmObject structure, so don't worry about doing a deep copy
  94. pCurrentObj = ((CEmshellApp*)AfxGetApp())->AllocEmObject();
  95. if (pCurrentObj != NULL) {
  96. *pCurrentObj = *GetEmObj(bstrEmObj);
  97. }
  98. SysFreeString( bstrEmObj );
  99. //Unallocate the EmObject if it has an hr of E_FAIL
  100. if (FAILED(pCurrentObj->hr)) {
  101. ((CEmshellApp*)AfxGetApp())->DeAllocEmObject(pCurrentObj);
  102. continue;
  103. }
  104. //Convert the BSTR object to an EmObject and pass it to DisplayData
  105. DisplayDumpData(pCurrentObj);
  106. }
  107. } while (FALSE);
  108. SafeArrayDestroyData(var.parray);
  109. SysFreeString( bstrEmObj );
  110. SysFreeString ( bstrEmObjectFilter );
  111. if (FAILED(hr)) {
  112. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  113. }
  114. }
  115. HRESULT CPropPageDumpFiles::DisplayDumpData(PEmObject pEmObject)
  116. {
  117. _ASSERTE(pEmObject != NULL);
  118. HRESULT hr = E_FAIL;
  119. CString strFileSize;
  120. CString strStartDate;
  121. LONG lRow = 0L;
  122. int nImage = 0;
  123. int nImageOffset = 0;
  124. do
  125. {
  126. if( pEmObject == NULL ){
  127. hr = E_INVALIDARG;
  128. break;
  129. }
  130. strFileSize.Format(_T("%d"), pEmObject->dwBucket1);
  131. strStartDate.Format(_T("%d"), pEmObject->dateStart);
  132. lRow = m_ListCtrl.SetItemText(-1, 0, pEmObject->szName);
  133. if(lRow == -1L){
  134. hr = E_FAIL;
  135. break;
  136. }
  137. //Set the itemData
  138. m_ListCtrl.SetItemData(lRow, (ULONG_PTR) pEmObject);
  139. //Get the correct offset into the bitmap for the current status
  140. // nImageOffset = GetImageOffsetFromStatus((EmSessionStatus)pEmObject->nStatus);
  141. //Call SetItem() with the index and image to show based on the state of pEmObject
  142. m_ListCtrl.SetItem(lRow, 0, LVIF_IMAGE, NULL, nImageOffset, 0, 0, 0);
  143. lRow = m_ListCtrl.SetItemText(lRow, 1, strFileSize);
  144. if(lRow == -1L){
  145. hr = E_FAIL;
  146. break;
  147. }
  148. //
  149. // a-mando
  150. //
  151. if( pEmObject->dateStart != 0L ) {
  152. COleDateTime oleDtTm(pEmObject->dateStart);
  153. strStartDate = oleDtTm.Format(_T("%c"));
  154. lRow = m_ListCtrl.SetItemText(lRow, 2, strStartDate);
  155. if(lRow == -1L){
  156. hr = E_FAIL;
  157. break;
  158. }
  159. }
  160. // a-mando
  161. hr = S_OK;
  162. }
  163. while( false );
  164. return hr;
  165. }
  166. void CPropPageDumpFiles::OnButtonExport()
  167. {
  168. PEmObject pEmObject = NULL;
  169. HRESULT hr = S_OK;
  170. CString strDirPath;
  171. //Iterate through each element in the m_ListCtrl, getting it's pEmObject and calling ExportLog() on it.
  172. //Step through every item in the list control
  173. int nCount = m_ListCtrl.GetItemCount();
  174. //Get the path
  175. if ( ( (CEmshellApp*) AfxGetApp() )->AskForPath( strDirPath ) ) {
  176. for (int i = 0;i < nCount; i++) {
  177. pEmObject = (PEmObject)m_ListCtrl.GetItemData(i);
  178. if (pEmObject == NULL) {
  179. hr = E_FAIL;
  180. break;
  181. }
  182. //Export the file
  183. hr = ((CEmshellApp*)AfxGetApp())->ExportLog( pEmObject, strDirPath, m_pIEmManager );
  184. }
  185. }
  186. if (FAILED(hr)) {
  187. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  188. }
  189. }