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.

359 lines
10 KiB

  1. //==========================================================================//
  2. // Includes //
  3. //==========================================================================//
  4. #include "perfmon.h"
  5. #include "datasrc.h" // External declarations for this file
  6. #include "fileutil.h" // for FileErrorMessageBox (whatever)
  7. #include "grafdata.h" // for ResetGraph
  8. #include "alert.h" // for ResetAlert
  9. #include "log.h" // for ResetLog
  10. #include "report.h" // for ResetReport
  11. #include "playback.h"
  12. #include "status.h"
  13. #include "utils.h"
  14. #include "pmhelpid.h" // Help IDs
  15. #include "fileopen.h" // FileOpneHookProc
  16. #include "pmemory.h" // for MemoryAllocate & MemoryFree
  17. #include "perfmops.h" // for ShowPerfmonWindowText
  18. //==========================================================================//
  19. // Local Data //
  20. //==========================================================================//
  21. BOOL bIgnoreFirstChange ;
  22. BOOL bDataSourceNow ;
  23. BOOL bDataSourcePrevious ;
  24. BOOL bLogFileNameChanged ;
  25. LPTSTR pszLogFilePath ;
  26. LPTSTR pszLogFileTitle ;
  27. //TCHAR szLogFilePath [FilePathLen + 1] ;
  28. //TCHAR szLogFileTitle [FilePathLen + 1] ;
  29. //==========================================================================//
  30. // Local Functions //
  31. //==========================================================================//
  32. void static UpdateLogName (HDLG hDlg)
  33. {
  34. DialogSetString (hDlg, IDD_DATASOURCEFILENAME, pszLogFilePath) ;
  35. // DialogSetString (hDlg, IDD_DATASOURCEFILENAME, pszLogFileTitle) ;
  36. }
  37. void OnChangeLog (HWND hWndParent)
  38. { // OnChangeLog
  39. OPENFILENAME ofn ;
  40. TCHAR szOpenLog [WindowCaptionLen + 1] ;
  41. TCHAR aszOpenFilter[LongTextLen] ;
  42. TCHAR szMyLogFilePath [FilePathLen + 1] ;
  43. int StringLength ;
  44. DWORD SaveCurrentDlgID = dwCurrentDlgID ;
  45. //=============================//
  46. // Get Log File //
  47. //=============================//
  48. aszOpenFilter[0] = 0;
  49. StringLoad (IDS_OPENLOG, szOpenLog) ;
  50. StringLoad (IDS_SAVELOGFILEEXT, szMyLogFilePath) ;
  51. // load the log file extension
  52. LoadString (hInstance, IDS_SAVELOGFILE, aszOpenFilter,
  53. sizeof(aszOpenFilter) / sizeof(TCHAR)) ;
  54. StringLength = lstrlen (aszOpenFilter) + 1 ;
  55. LoadString (hInstance, IDS_SAVELOGFILEEXT,
  56. &aszOpenFilter[StringLength],
  57. sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
  58. StringLength += lstrlen (&aszOpenFilter[StringLength]) ;
  59. // setup the end strings
  60. aszOpenFilter[StringLength+1] = aszOpenFilter[StringLength+2] = TEXT('\0') ;
  61. ofn.lStructSize = sizeof (OPENFILENAME) ;
  62. ofn.hwndOwner = hWndParent ;
  63. ofn.hInstance = hInstance ;
  64. ofn.lpstrFilter = aszOpenFilter ;
  65. ofn.lpstrCustomFilter = NULL ;
  66. ofn.nMaxCustFilter = 0 ;
  67. ofn.nFilterIndex = 1;
  68. ofn.lpstrFile = szMyLogFilePath ;
  69. ofn.nMaxFile = FilePathLen * sizeof (TCHAR) ;
  70. ofn.lpstrFileTitle = pszLogFileTitle ;
  71. ofn.nMaxFileTitle = FilePathLen * sizeof (TCHAR) ;
  72. ofn.lpstrInitialDir = NULL ;
  73. ofn.lpstrTitle = szOpenLog ;
  74. ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY |
  75. // OFN_PATHMUSTEXIST | OFN_SHOWHELP | OFN_ENABLEHOOK ;
  76. OFN_PATHMUSTEXIST | OFN_ENABLEHOOK | OFN_EXPLORER;
  77. ofn.lCustData = 0L ;
  78. ofn.lpfnHook = (LPOFNHOOKPROC) FileOpenHookProc ;
  79. ofn.lpstrDefExt = (LPTSTR)NULL;
  80. dwCurrentDlgID = HC_PM_idDlgOptionOpenLogFile ;
  81. if (GetOpenFileName (&ofn))
  82. {
  83. if (!strsame(pszLogFilePath, szMyLogFilePath))
  84. {
  85. INT_PTR FileNameOffset ;
  86. LPTSTR pFileName ;
  87. bLogFileNameChanged |= TRUE ;
  88. lstrcpy (pszLogFilePath, szMyLogFilePath) ;
  89. lstrcpy (pszLogFileTitle, ofn.lpstrFileTitle) ;
  90. pFileName = ExtractFileName (szMyLogFilePath) ;
  91. if (pFileName != szMyLogFilePath)
  92. {
  93. FileNameOffset = pFileName - szMyLogFilePath ;
  94. szMyLogFilePath[FileNameOffset] = TEXT('\0') ;
  95. SetCurrentDirectory (szMyLogFilePath) ;
  96. }
  97. UpdateLogName (hWndParent) ;
  98. }
  99. }
  100. // restore the global before exit
  101. dwCurrentDlgID = SaveCurrentDlgID ;
  102. } // OnChangeLog
  103. //==========================================================================//
  104. // Message Handlers //
  105. //==========================================================================//
  106. void static OnInitDialog (HDLG hDlg)
  107. {
  108. bLogFileNameChanged = FALSE ;
  109. bIgnoreFirstChange = TRUE ;
  110. bDataSourcePrevious = bDataSourceNow = !PlayingBackLog () ;
  111. CheckRadioButton (hDlg, IDD_DATASOURCENOW, IDD_DATASOURCEFILE,
  112. bDataSourceNow ? IDD_DATASOURCENOW : IDD_DATASOURCEFILE) ;
  113. UpdateLogName (hDlg) ;
  114. EditSetLimit (GetDlgItem(hDlg, IDD_DATASOURCEFILENAME),
  115. FilePathLen - 1) ;
  116. WindowCenter (hDlg) ;
  117. dwCurrentDlgID = HC_PM_idDlgOptionDataFrom ;
  118. }
  119. void /*static*/ OnDataSourceOK (HDLG hDlg)
  120. { // OnOK
  121. BOOL bHaveResetPerfmon ;
  122. INT RetCode = 0 ;
  123. bHaveResetPerfmon = FALSE;
  124. if (!BoolEqual (bDataSourceNow, bDataSourcePrevious) ||
  125. (bLogFileNameChanged && !bDataSourceNow) )
  126. {
  127. if (PlayingBackLog () && bDataSourceNow | bLogFileNameChanged)
  128. {
  129. CloseInputLog (hWndMain) ;
  130. bHaveResetPerfmon = TRUE ;
  131. }
  132. if (!bDataSourceNow)
  133. {
  134. if (!bHaveResetPerfmon)
  135. {
  136. ResetGraphView (hWndGraph) ;
  137. ResetAlertView (hWndAlert) ;
  138. ResetLogView (hWndLog) ;
  139. ResetReportView (hWndReport) ;
  140. if (pWorkSpaceFullFileName)
  141. {
  142. MemoryFree (pWorkSpaceFullFileName) ;
  143. pWorkSpaceFileName = NULL ;
  144. pWorkSpaceFullFileName = NULL ;
  145. }
  146. ShowPerfmonWindowText () ;
  147. }
  148. GetDlgItemText (hDlg, IDD_DATASOURCEFILENAME,
  149. pszLogFilePath, FilePathLen - 1) ;
  150. lstrcpy (pszLogFileTitle, pszLogFilePath);
  151. if (RetCode = OpenPlayback (pszLogFilePath, pszLogFileTitle))
  152. {
  153. DlgErrorBox (hDlg, RetCode, pszLogFileTitle) ;
  154. }
  155. }
  156. StatusLineReady (hWndStatus) ;
  157. }
  158. if (!BoolEqual (bDataSourceNow, bDataSourcePrevious))
  159. {
  160. if (bDataSourceNow)
  161. {
  162. // Set Priority high
  163. SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS) ;
  164. SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST) ;
  165. }
  166. else
  167. {
  168. // Use a lower priority for Playing back log
  169. SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS) ;
  170. SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL) ;
  171. }
  172. }
  173. if (RetCode == 0)
  174. {
  175. EndDialog (hDlg, 1) ;
  176. }
  177. } // OnOK
  178. //==========================================================================//
  179. // Exported Functions //
  180. //==========================================================================//
  181. INT_PTR
  182. FAR
  183. WINAPI
  184. DataSourceDlgProc (
  185. HWND hDlg,
  186. unsigned iMessage,
  187. WPARAM wParam,
  188. LPARAM lParam
  189. )
  190. {
  191. BOOL bHandled ;
  192. bHandled = TRUE ;
  193. switch (iMessage)
  194. {
  195. case WM_INITDIALOG:
  196. OnInitDialog (hDlg) ;
  197. return (TRUE) ;
  198. case WM_CLOSE:
  199. EndDialog (hDlg, 0) ;
  200. break ;
  201. case WM_DESTROY:
  202. dwCurrentDlgID = 0 ;
  203. break;
  204. case WM_COMMAND:
  205. switch(LOWORD(wParam))
  206. {
  207. case IDD_DATASOURCEFILENAME:
  208. if (bIgnoreFirstChange)
  209. {
  210. bIgnoreFirstChange = FALSE;
  211. }
  212. else if (HIWORD(wParam) == EN_UPDATE && !bLogFileNameChanged)
  213. {
  214. bLogFileNameChanged = TRUE;
  215. CheckRadioButton (hDlg,
  216. IDD_DATASOURCENOW,
  217. IDD_DATASOURCEFILE,
  218. IDD_DATASOURCEFILE) ;
  219. bDataSourceNow = FALSE ;
  220. }
  221. break ;
  222. case IDD_DATASOURCECHANGEFILE:
  223. OnChangeLog (hDlg) ;
  224. if (bLogFileNameChanged)
  225. {
  226. CheckRadioButton (hDlg,
  227. IDD_DATASOURCENOW,
  228. IDD_DATASOURCEFILE,
  229. IDD_DATASOURCEFILE) ;
  230. bDataSourceNow = FALSE ;
  231. }
  232. break ;
  233. case IDD_DATASOURCEFILE:
  234. bDataSourceNow = FALSE ;
  235. break ;
  236. case IDD_DATASOURCENOW:
  237. bDataSourceNow = TRUE ;
  238. break ;
  239. case IDD_OK:
  240. OnDataSourceOK (hDlg) ;
  241. break ;
  242. case IDD_CANCEL:
  243. EndDialog (hDlg, 0) ;
  244. break ;
  245. case IDD_DATASOURCEHELP:
  246. CallWinHelp (dwCurrentDlgID, hDlg) ;
  247. break ;
  248. default:
  249. bHandled = FALSE ;
  250. break;
  251. }
  252. break;
  253. default:
  254. bHandled = FALSE ;
  255. break ;
  256. } // switch
  257. return (bHandled) ;
  258. } // DataSourceDlgProc
  259. BOOL
  260. DisplayDataSourceOptions (
  261. HWND hWndParent
  262. )
  263. /*
  264. Effect: Put up Perfmon's Data Source Options Display dialog,
  265. which allows
  266. the user to select the source of data input: real
  267. time or log file.
  268. */
  269. { // DisplayDisplayOptions
  270. BOOL retCode ;
  271. pszLogFilePath = (LPTSTR) MemoryAllocate (FilePathLen * sizeof(TCHAR)) ;
  272. if (pszLogFilePath == NULL)
  273. return FALSE;
  274. pszLogFileTitle = (LPTSTR) MemoryAllocate (FilePathLen * sizeof(TCHAR)) ;
  275. if (pszLogFileTitle == NULL) {
  276. MemoryFree(pszLogFilePath);
  277. return FALSE;
  278. }
  279. lstrcpy (pszLogFilePath, PlaybackLog.szFilePath) ;
  280. lstrcpy (pszLogFileTitle, PlaybackLog.szFileTitle) ;
  281. retCode = DialogBox (hInstance, idDlgDataSource, hWndParent, DataSourceDlgProc) ? TRUE : FALSE;
  282. MemoryFree (pszLogFilePath) ;
  283. MemoryFree (pszLogFileTitle) ;
  284. return (retCode) ;
  285. } // DisplayDisplayOptions