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.

218 lines
5.2 KiB

  1. // FileSpyDoc.cpp : implementation of the CFileSpyDoc class
  2. //
  3. #include "stdafx.h"
  4. #include "FileSpyApp.h"
  5. #include "global.h"
  6. #include "FileSpyDoc.h"
  7. #include "filespyview.h"
  8. #include "fastioview.h"
  9. #include "fsfilterview.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CFileSpyDoc
  17. IMPLEMENT_DYNCREATE(CFileSpyDoc, CDocument)
  18. BEGIN_MESSAGE_MAP(CFileSpyDoc, CDocument)
  19. //{{AFX_MSG_MAP(CFileSpyDoc)
  20. ON_COMMAND(ID_FILE_SAVE, OnFileSave)
  21. //}}AFX_MSG_MAP
  22. END_MESSAGE_MAP()
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CFileSpyDoc construction/destruction
  25. CFileSpyDoc::CFileSpyDoc()
  26. {
  27. // TODO: add one-time construction code here
  28. }
  29. CFileSpyDoc::~CFileSpyDoc()
  30. {
  31. }
  32. BOOL CFileSpyDoc::OnNewDocument()
  33. {
  34. if (!CDocument::OnNewDocument())
  35. return FALSE;
  36. // TODO: add reinitialization code here
  37. // (SDI documents will reuse this document)
  38. return TRUE;
  39. }
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CFileSpyDoc serialization
  42. void CFileSpyDoc::Serialize(CArchive& ar)
  43. {
  44. if (ar.IsStoring())
  45. {
  46. // TODO: add storing code here
  47. }
  48. else
  49. {
  50. // TODO: add loading code here
  51. }
  52. }
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CFileSpyDoc diagnostics
  55. #ifdef _DEBUG
  56. void CFileSpyDoc::AssertValid() const
  57. {
  58. CDocument::AssertValid();
  59. }
  60. void CFileSpyDoc::Dump(CDumpContext& dc) const
  61. {
  62. CDocument::Dump(dc);
  63. }
  64. #endif //_DEBUG
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CFileSpyDoc commands
  67. void CFileSpyDoc::OnFileSave()
  68. {
  69. // TODO: Add your command handler code here
  70. OPENFILENAME OpenFileName;
  71. WCHAR sFilePath[1024];
  72. WCHAR sFileName[1024];
  73. WCHAR sFileStr[2048];
  74. WCHAR sStr[1024];
  75. WCHAR CRLF[3];
  76. WCHAR TAB[1];
  77. HANDLE hFile;
  78. long nSaved;
  79. int nMBRet, ti, nCount, tj;
  80. CFileSpyView *pIrp = (CFileSpyView *) pSpyView;
  81. CFastIoView *pFast = (CFastIoView *) pFastIoView;
  82. CFsFilterView *pFsFilter = (CFsFilterView *) pFsFilterView;
  83. DWORD nBytesWritten;
  84. if (pIrp->GetListCtrl().GetItemCount() == 0 && pFast->GetListCtrl().GetItemCount() == 0)
  85. {
  86. MessageBox(NULL, L"Nothing to save", L"FileSpy", MB_OK);
  87. return;
  88. }
  89. wcscpy(sFilePath, L"FILESPY.LOG");
  90. sFileName[0] = 0;
  91. OpenFileName.lStructSize = sizeof(OpenFileName);
  92. OpenFileName.hwndOwner = AfxGetMainWnd()->m_hWnd;
  93. OpenFileName.hInstance = AfxGetInstanceHandle();
  94. OpenFileName.Flags = OFN_HIDEREADONLY|OFN_NOREADONLYRETURN|OFN_PATHMUSTEXIST;
  95. OpenFileName.lpstrFilter = NULL;
  96. OpenFileName.lpstrCustomFilter = NULL;
  97. OpenFileName.nFilterIndex = 0;
  98. OpenFileName.lpstrFileTitle = sFileName;
  99. OpenFileName.nMaxFileTitle = 512;
  100. OpenFileName.lpstrInitialDir = NULL;
  101. OpenFileName.lpstrTitle = NULL;
  102. OpenFileName.lpstrDefExt = NULL;
  103. OpenFileName.lpfnHook = NULL;
  104. OpenFileName.lpstrFile = sFilePath;
  105. OpenFileName.nMaxFile = 512;
  106. if (!GetSaveFileName(&OpenFileName))
  107. {
  108. return;
  109. }
  110. hFile = CreateFile(sFilePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  111. if (hFile != INVALID_HANDLE_VALUE)
  112. {
  113. nMBRet = MessageBox(NULL, L"The selected file already exists. Do you want to append to it?", L"FileSpy", MB_YESNOCANCEL);
  114. if (nMBRet == IDCANCEL)
  115. {
  116. return;
  117. }
  118. if (nMBRet == IDYES)
  119. {
  120. SetFilePointer(hFile, 0, NULL, FILE_END);
  121. }
  122. else
  123. {
  124. CloseHandle(hFile);
  125. hFile = CreateFile(sFilePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  126. }
  127. }
  128. else
  129. {
  130. hFile = CreateFile(sFilePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  131. }
  132. if (hFile == INVALID_HANDLE_VALUE)
  133. {
  134. MessageBox(NULL, L"File creation error", L"FileSpy - Error", MB_OK);
  135. return;
  136. }
  137. CRLF[0] = 0x0D;
  138. CRLF[1] = 0x0A;
  139. CRLF[2] = 0;
  140. TAB[0] = 0x9;
  141. TAB[1] = 0;
  142. WriteFile(hFile, CRLF, 2, &nBytesWritten, NULL);
  143. //
  144. // Write IRP header string
  145. //
  146. //
  147. // Start saving the traces now
  148. // First save IRP traces and then FASTIO
  149. //
  150. nCount = pIrp->GetListCtrl().GetItemCount();
  151. for (ti = 0; ti < nCount; ti++)
  152. {
  153. pIrp->GetListCtrl().GetItemText(ti, 0, sStr, 1024);
  154. wcscpy(sFileStr, sStr);
  155. for (tj = 1; tj < 10; tj++)
  156. {
  157. wcscat(sFileStr, TAB);
  158. pIrp->GetListCtrl().GetItemText(ti, tj, sStr, 1024);
  159. wcscat(sFileStr, sStr);
  160. }
  161. wcscat(sFileStr, CRLF);
  162. WriteFile(hFile, sFileStr, wcslen(sFileStr), &nBytesWritten, NULL);
  163. }
  164. nSaved = nCount;
  165. //
  166. // FastIO View now
  167. //
  168. nCount = pFast->GetListCtrl().GetItemCount();
  169. for (ti = 0; ti < nCount; ti++)
  170. {
  171. pFast->GetListCtrl().GetItemText(ti, 0, sStr, 1024);
  172. wcscpy(sFileStr, sStr);
  173. for (tj = 1; tj < 11; tj++)
  174. {
  175. wcscat(sFileStr, TAB);
  176. pFast->GetListCtrl().GetItemText(ti, tj, sStr, 1024);
  177. wcscat(sFileStr, sStr);
  178. }
  179. wcscat(sFileStr, CRLF);
  180. WriteFile(hFile, sFileStr, wcslen(sFileStr), &nBytesWritten, NULL);
  181. }
  182. CloseHandle(hFile);
  183. nSaved += nCount;
  184. swprintf(sStr, L"%ld traces saved", nSaved);
  185. MessageBox(NULL, sStr, L"FileSpy", MB_OK);
  186. }