Windows NT 4.0 source code leak
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.

349 lines
10 KiB

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