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.

316 lines
7.8 KiB

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