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.

1516 lines
38 KiB

4 years ago
  1. #include "perfmon.h"
  2. #include <lmcons.h>
  3. #include <lmerr.h>
  4. #include <lmapibuf.h>
  5. #include <lmwksta.h>
  6. #include <uiexport.h>
  7. #include <stdio.h> // for sprintf
  8. #include <locale.h> // for setlocale
  9. #include "utils.h"
  10. #include "perfdata.h" // for OpenSystemPerfData
  11. #include "alert.h" // for AlertInsertLine
  12. #include "report.h" // for ReportInsertLine
  13. #include "grafdata.h" // for GraphInsertLine
  14. #include "log.h" // for OpenLog
  15. #include "fileopen.h" // for FileGetName
  16. #include "fileutil.h" // for FileRead etc
  17. #include "command.h" // for PrepareMenu
  18. #include "playback.h" // for PlayingBackLog & LogPositionSystemTime
  19. #include "system.h"
  20. #include "globals.h"
  21. #include "pmemory.h" // for MemoryFree
  22. #include "status.h" // for StatusLineReady
  23. #include "pmhelpid.h"
  24. // test for delimiter, end of line and non-digit characters
  25. // used by IsNumberInUnicodeList routine
  26. //
  27. #define DIGIT 1
  28. #define DELIMITER 2
  29. #define INVALID 3
  30. // globals used for International Date and Time formats
  31. enum DATE_STYLE
  32. {
  33. YEAR_FIRST, // YYMMDD
  34. DAY_FIRST, // DDMMYY
  35. MONTH_FIRST // MMDDYY
  36. } DateStyle ;
  37. TCHAR szInternational[] = TEXT("Intl") ;
  38. TCHAR sz1159[6] ; // AM String
  39. TCHAR sz2359[6] ; // PM String
  40. int iTime ; // = 0 for 12-hour format, <> 0 for 24-hour format
  41. int YearCharCount ; // = 4 for 1990, = 2 for 90
  42. TCHAR szDateFormat[ResourceStringLen] ;
  43. TCHAR szTimeFormat[ResourceStringLen] ; // time format including msec
  44. TCHAR szTimeFormat1[ResourceStringLen] ; // time format without msec
  45. TCHAR LeadingZeroStr [] = TEXT("%02d") ;
  46. TCHAR NoLeadingZeroStr [] = TEXT("%d") ;
  47. TCHAR szDecimal [2] ;
  48. TCHAR szCurrentDecimal [2] ;
  49. #define EvalThisChar(c,d) ( \
  50. (c == d) ? DELIMITER : \
  51. (c == 0) ? DELIMITER : \
  52. (c < (WCHAR)'0') ? INVALID : \
  53. (c > (WCHAR)'9') ? INVALID : \
  54. DIGIT)
  55. #define SIZE_OF_BIGGEST_INTEGER 16
  56. // #define SIZE_OF_BIGGEST_INTEGER (16*sizeof(WCHAR))
  57. //==========================================================================//
  58. // Typedefs //
  59. //==========================================================================//
  60. BOOL AddObjectToSystem ( PLINE , PPERFSYSTEM );
  61. BOOL GetLogFileComputer (HWND hWndParent, LPTSTR lpComputerName, DWORD BufferSize) ;
  62. HWND PerfmonViewWindow (void)
  63. /*
  64. Effect: Return the current data window, i.e. the window currently
  65. visible as the client area of Perfmon. This is either a
  66. chart, log, alert, or report window.
  67. */
  68. { // PerfmonDataWindow
  69. switch (iPerfmonView)
  70. { // switch
  71. case IDM_VIEWLOG:
  72. return (hWndLog) ;
  73. case IDM_VIEWALERT:
  74. return (hWndAlert) ;
  75. case IDM_VIEWREPORT:
  76. return (hWndReport) ;
  77. // case IDM_VIEWCHART:
  78. default:
  79. return (hWndGraph) ;
  80. } // switch
  81. } // PerfmonViewWindow
  82. #define szChooseComputerLibrary TEXT("ntlanman.dll")
  83. #define szChooseComputerFunction "I_SystemFocusDialog"
  84. BOOL ChooseComputer (HWND hWndParent, LPTSTR lpszComputer)
  85. /*
  86. Effect: Display the choose Domain/Computer dialog provided by
  87. network services. If the user selects a computer,
  88. copy the computer name to lpszComputer and return
  89. nonnull. If the user cancels, return FALSE.
  90. Internals: This dialog and code is currently not an exported
  91. routine regularly found on any user's system. Right
  92. now, we dynamically load and call the routine.
  93. This is definitely temporary code that will be
  94. rewritten when NT stabilizes. The callers of this
  95. routine, however, will not need to be modified.
  96. Also, the Domain/Computer dialog currently allows
  97. a domain to be selected, which we cannot use. We
  98. therefore loop until the user cancels or selects
  99. a computer, putting up a message if the user selects
  100. a domain.
  101. Assert: lpszComputer is at least MAX_SYSTEM_NAME_LENGTH + 1
  102. characters.
  103. */
  104. { // ChooseComputer
  105. BOOL bSuccess ;
  106. WCHAR wszWideComputer[MAX_PATH + 3] ;
  107. HLIBRARY hLibrary ;
  108. LPFNI_SYSTEMFOCUSDIALOG lpfnChooseComputer ;
  109. LONG lError ;
  110. if (!PlayingBackLog())
  111. {
  112. // bring up the select network computer dialog
  113. hLibrary = LoadLibrary (szChooseComputerLibrary) ;
  114. if (!hLibrary || hLibrary == INVALID_HANDLE_VALUE)
  115. {
  116. return (FALSE) ;
  117. }
  118. lpfnChooseComputer = (LPFNI_SYSTEMFOCUSDIALOG)
  119. GetProcAddress (hLibrary, szChooseComputerFunction) ;
  120. if (!lpfnChooseComputer)
  121. {
  122. FreeLibrary (hLibrary) ;
  123. return (FALSE) ;
  124. }
  125. lError = (*lpfnChooseComputer) (hWndParent,
  126. FOCUSDLG_SERVERS_ONLY | FOCUSDLG_BROWSE_ALL_DOMAINS,
  127. wszWideComputer,
  128. sizeof(wszWideComputer) / sizeof(WCHAR),
  129. &bSuccess,
  130. pszHelpFile,
  131. HC_PM_idDlgSelectNetworkComputer) ;
  132. FreeLibrary (hLibrary) ;
  133. }
  134. else
  135. {
  136. // bring up the select Log Computer dialog
  137. bSuccess = GetLogFileComputer (hWndParent,
  138. wszWideComputer,
  139. sizeof(wszWideComputer) / sizeof(WCHAR)) ;
  140. }
  141. if (bSuccess)
  142. {
  143. lstrcpy (lpszComputer, wszWideComputer) ;
  144. }
  145. return (bSuccess) ;
  146. } // ChooseComputer
  147. void SystemTimeDateString (SYSTEMTIME *pSystemTime,
  148. LPTSTR lpszDate)
  149. {
  150. int wYear ;
  151. wYear = pSystemTime->wYear ;
  152. if (YearCharCount == 2)
  153. {
  154. wYear %= 100 ;
  155. }
  156. switch (DateStyle)
  157. {
  158. case YEAR_FIRST:
  159. TSPRINTF (lpszDate, szDateFormat,
  160. wYear, pSystemTime->wMonth, pSystemTime->wDay) ;
  161. break ;
  162. case DAY_FIRST:
  163. TSPRINTF (lpszDate, szDateFormat,
  164. pSystemTime->wDay, pSystemTime->wMonth, wYear) ;
  165. break ;
  166. case MONTH_FIRST:
  167. default:
  168. TSPRINTF (lpszDate, szDateFormat,
  169. pSystemTime->wMonth, pSystemTime->wDay, wYear) ;
  170. break ;
  171. }
  172. }
  173. void SystemTimeTimeString (SYSTEMTIME *pSystemTime,
  174. LPTSTR lpszTime,
  175. BOOL bOutputMsec)
  176. {
  177. int iHour ;
  178. BOOL bPM ;
  179. if (iTime)
  180. {
  181. // 24 hor format
  182. if (bOutputMsec)
  183. {
  184. TSPRINTF (lpszTime, szTimeFormat,
  185. pSystemTime->wHour,
  186. pSystemTime->wMinute,
  187. (FLOAT)pSystemTime->wSecond +
  188. (FLOAT)pSystemTime->wMilliseconds / (FLOAT) 1000.0) ;
  189. }
  190. else
  191. {
  192. TSPRINTF (lpszTime, szTimeFormat1,
  193. pSystemTime->wHour,
  194. pSystemTime->wMinute,
  195. pSystemTime->wSecond) ;
  196. }
  197. }
  198. else
  199. {
  200. // 12 hour format
  201. iHour = pSystemTime->wHour ;
  202. bPM = (iHour >= 12) ;
  203. if (iHour > 12)
  204. iHour -= 12 ;
  205. else if (!iHour)
  206. iHour = 12 ;
  207. if (bOutputMsec)
  208. {
  209. TSPRINTF (lpszTime, szTimeFormat,
  210. iHour, pSystemTime->wMinute,
  211. (FLOAT)pSystemTime->wSecond +
  212. (FLOAT)pSystemTime->wMilliseconds / (FLOAT) 1000.0 ,
  213. bPM ? sz2359 : sz1159) ;
  214. }
  215. else
  216. {
  217. TSPRINTF (lpszTime, szTimeFormat1,
  218. iHour, pSystemTime->wMinute,
  219. pSystemTime->wSecond,
  220. bPM ? sz2359 : sz1159) ;
  221. }
  222. }
  223. }
  224. void ShowPerfmonWindowText ()
  225. {
  226. LPTSTR *ppFileName ;
  227. TCHAR szApplication [MessageLen] ;
  228. switch (iPerfmonView)
  229. {
  230. case IDM_VIEWCHART:
  231. ppFileName = &pChartFileName ;
  232. break ;
  233. case IDM_VIEWALERT:
  234. ppFileName = &pAlertFileName ;
  235. break ;
  236. case IDM_VIEWREPORT:
  237. ppFileName = &pReportFileName ;
  238. break ;
  239. case IDM_VIEWLOG:
  240. ppFileName = &pLogFileName ;
  241. break ;
  242. default:
  243. ppFileName = NULL ;
  244. break ;
  245. }
  246. if (ppFileName == NULL)
  247. {
  248. ppFileName = &pWorkSpaceFileName ;
  249. }
  250. // display the name file name on the Title bar.
  251. StringLoad (IDS_APPNAME, szApplication) ;
  252. if (*ppFileName)
  253. {
  254. lstrcat (szApplication, TEXT(" - ")) ;
  255. lstrcat (szApplication, *ppFileName) ;
  256. }
  257. SetWindowText (hWndMain, szApplication) ;
  258. }
  259. void ShowPerfmonMenu (BOOL bMenu)
  260. { // ShowPerfmonMenu
  261. if (!bMenu)
  262. {
  263. WindowEnableTitle (hWndMain, FALSE) ;
  264. // SetMenu(hWndMain, NULL) ;
  265. }
  266. else
  267. {
  268. WindowEnableTitle (hWndMain, TRUE) ;
  269. switch (iPerfmonView)
  270. { // switch
  271. case IDM_VIEWCHART:
  272. SetMenu (hWndMain, hMenuChart) ;
  273. break ;
  274. case IDM_VIEWALERT:
  275. SetMenu (hWndMain, hMenuAlert) ;
  276. break ;
  277. case IDM_VIEWLOG:
  278. SetMenu (hWndMain, hMenuLog) ;
  279. break ;
  280. case IDM_VIEWREPORT:
  281. SetMenu (hWndMain, hMenuReport) ;
  282. break ;
  283. } // switch
  284. } // else
  285. if (bMenu != Options.bMenubar)
  286. {
  287. PrepareMenu (GetMenu (hWndMain)) ;
  288. }
  289. Options.bMenubar = bMenu ;
  290. // Show Window Text
  291. if (bMenu)
  292. {
  293. ShowPerfmonWindowText () ;
  294. }
  295. } // ShowPerfmonMenu
  296. void SmallFileSizeString (int iFileSize,
  297. LPTSTR lpszFileText)
  298. { // SmallFileSizeString
  299. if (iFileSize < 1000000)
  300. TSPRINTF (lpszFileText, TEXT(" %1.1fK "), ((FLOAT) iFileSize) / 1000.0f) ;
  301. else
  302. TSPRINTF (lpszFileText, TEXT(" %1.1fM "), ((FLOAT) iFileSize) / 1000000.0f) ;
  303. } // SmallFileSizeString
  304. BOOL DoWindowDrag (HWND hWnd, LPARAM lParam)
  305. {
  306. POINT lPoint ;
  307. if (!Options.bMenubar && !IsZoomed (hWndMain))
  308. {
  309. // convert lParam from client to screen
  310. lPoint.x = LOWORD (lParam) ;
  311. lPoint.y = HIWORD (lParam) ;
  312. ClientToScreen (hWnd, &lPoint) ;
  313. lParam = MAKELONG (lPoint.x, lPoint.y) ;
  314. SendMessage (hWndMain, WM_NCLBUTTONDOWN, HTCAPTION, lParam) ;
  315. return (TRUE) ;
  316. }
  317. else
  318. return (FALSE) ;
  319. }
  320. // Filetimes are in 100NS units
  321. #define FILETIMES_PER_SECOND 10000000
  322. int SystemTimeDifference (SYSTEMTIME *pst1, SYSTEMTIME *pst2, BOOL bAbs)
  323. {
  324. LARGE_INTEGER li1, li2 ;
  325. LARGE_INTEGER liDifference, liDifferenceSeconds ;
  326. DWORD uRemainder ;
  327. int RetInteger;
  328. BOOL bNegative;
  329. li1.HighPart = li1.LowPart = 0 ;
  330. li2.HighPart = li2.LowPart = 0 ;
  331. SystemTimeToFileTime (pst1, (FILETIME *) &li1) ;
  332. SystemTimeToFileTime (pst2, (FILETIME *) &li2) ;
  333. // check for special cases when the time can be 0
  334. if (li2.HighPart == 0 && li2.LowPart == 0)
  335. {
  336. if (li1.HighPart == 0 && li1.LowPart == 0)
  337. {
  338. return 0 ;
  339. }
  340. else
  341. {
  342. return -INT_MAX ;
  343. }
  344. }
  345. else if (li1.HighPart == 0 && li1.LowPart == 0)
  346. {
  347. return INT_MAX ;
  348. }
  349. liDifference.QuadPart = li2.QuadPart - li1.QuadPart ;
  350. bNegative = liDifference.QuadPart < 0 ;
  351. // add the round-off factor before doing the division
  352. if (bNegative)
  353. {
  354. liDifferenceSeconds.QuadPart = (LONGLONG)(- FILETIMES_PER_SECOND / 2) ;
  355. }
  356. else
  357. {
  358. liDifferenceSeconds.QuadPart = (LONGLONG)(FILETIMES_PER_SECOND / 2) ;
  359. }
  360. liDifferenceSeconds.QuadPart = liDifferenceSeconds.QuadPart +
  361. liDifference.QuadPart ;
  362. liDifferenceSeconds.QuadPart = liDifferenceSeconds.QuadPart /
  363. FILETIMES_PER_SECOND;
  364. RetInteger = liDifferenceSeconds.LowPart;
  365. if (bNegative && bAbs)
  366. {
  367. return (-RetInteger) ;
  368. }
  369. else
  370. {
  371. return (RetInteger) ;
  372. }
  373. }
  374. BOOL InsertLine (PLINE pLine)
  375. { // InsertLine
  376. BOOL bReturn = FALSE;
  377. switch (pLine->iLineType) { // switch
  378. case LineTypeChart:
  379. bReturn = ChartInsertLine (pGraphs, pLine) ;
  380. break ;
  381. case LineTypeAlert:
  382. bReturn = AlertInsertLine (hWndAlert, pLine) ;
  383. break ;
  384. case LineTypeReport:
  385. bReturn = ReportInsertLine (hWndReport, pLine) ;
  386. break ;
  387. } // switch
  388. return bReturn;
  389. } // InsertLine
  390. BOOL OpenWorkspace (HANDLE hFile, DWORD dwMajorVersion, DWORD dwMinorVersion)
  391. {
  392. DISKWORKSPACE DiskWorkspace ;
  393. if (!FileRead (hFile, &DiskWorkspace, sizeof(DiskWorkspace)))
  394. {
  395. goto Exit0 ;
  396. }
  397. if (DiskWorkspace.ChartOffset == 0 &&
  398. DiskWorkspace.AlertOffset == 0 &&
  399. DiskWorkspace.LogOffset == 0 &&
  400. DiskWorkspace.ReportOffset == 0)
  401. {
  402. goto Exit0 ;
  403. }
  404. switch (dwMajorVersion)
  405. { // switch
  406. case (1):
  407. if (dwMinorVersion >= 1)
  408. {
  409. // setup the window position and size
  410. DiskWorkspace.WindowPlacement.length = sizeof(WINDOWPLACEMENT);
  411. DiskWorkspace.WindowPlacement.flags = WPF_SETMINPOSITION;
  412. if (!SetWindowPlacement (hWndMain, &(DiskWorkspace.WindowPlacement)))
  413. {
  414. goto Exit0 ;
  415. }
  416. }
  417. // change to the view as stored in the workspace file
  418. SendMessage (hWndMain, WM_COMMAND,
  419. (LONG)DiskWorkspace.iPerfmonView, 0L) ;
  420. iPerfmonView = DiskWorkspace.iPerfmonView ;
  421. if (DiskWorkspace.ChartOffset)
  422. {
  423. if (FileSeekBegin(hFile, DiskWorkspace.ChartOffset) == 0xFFFFFFFF)
  424. {
  425. goto Exit0 ;
  426. }
  427. if (!OpenChart (hWndGraph,
  428. hFile,
  429. dwMajorVersion,
  430. dwMinorVersion,
  431. FALSE))
  432. {
  433. goto Exit0 ;
  434. }
  435. }
  436. if (DiskWorkspace.AlertOffset)
  437. {
  438. if (FileSeekBegin(hFile, DiskWorkspace.AlertOffset) == 0xffffffff)
  439. {
  440. goto Exit0 ;
  441. }
  442. if (!OpenAlert (hWndAlert,
  443. hFile,
  444. dwMajorVersion,
  445. dwMinorVersion,
  446. FALSE))
  447. {
  448. goto Exit0 ;
  449. }
  450. }
  451. if (DiskWorkspace.LogOffset)
  452. {
  453. if (FileSeekBegin(hFile, DiskWorkspace.LogOffset) == 0xffffffff)
  454. {
  455. goto Exit0 ;
  456. }
  457. if (!OpenLog (hWndLog,
  458. hFile,
  459. dwMajorVersion,
  460. dwMinorVersion,
  461. FALSE))
  462. {
  463. goto Exit0 ;
  464. }
  465. }
  466. if (DiskWorkspace.ReportOffset)
  467. {
  468. if (FileSeekBegin(hFile, DiskWorkspace.ReportOffset) == 0xffffffff)
  469. {
  470. goto Exit0 ;
  471. }
  472. if (!OpenReport (hWndReport,
  473. hFile,
  474. dwMajorVersion,
  475. dwMinorVersion,
  476. FALSE))
  477. {
  478. goto Exit0 ;
  479. }
  480. }
  481. break ;
  482. default:
  483. goto Exit0 ;
  484. break ;
  485. }
  486. CloseHandle (hFile) ;
  487. return (TRUE) ;
  488. Exit0:
  489. CloseHandle (hFile) ;
  490. return (FALSE) ;
  491. } // OpenWorkspace
  492. BOOL SaveWorkspace (void)
  493. {
  494. DISKWORKSPACE DiskWorkspace ;
  495. PERFFILEHEADER FileHeader ;
  496. HANDLE hFile ;
  497. long DiskWorkspacePosition ;
  498. TCHAR szFileName[FilePathLen] ;
  499. BOOL bWriteErr = TRUE ;
  500. if (!FileGetName (PerfmonViewWindow(), IDS_WORKSPACEFILE, szFileName))
  501. {
  502. return (FALSE) ;
  503. }
  504. hFile = FileHandleCreate (szFileName) ;
  505. if (!hFile)
  506. {
  507. DlgErrorBox (PerfmonViewWindow (), ERR_CANT_OPEN, szFileName) ;
  508. return (FALSE) ;
  509. }
  510. memset (&FileHeader, 0, sizeof (FileHeader)) ;
  511. lstrcpy (FileHeader.szSignature, szPerfWorkspaceSignature) ;
  512. FileHeader.dwMajorVersion = WorkspaceMajorVersion ;
  513. FileHeader.dwMinorVersion = WorkspaceMinorVersion ;
  514. if (!FileWrite (hFile, &FileHeader, sizeof (PERFFILEHEADER)))
  515. {
  516. goto Exit0 ;
  517. }
  518. // reserve space in the file. We will fill up info
  519. // and write into this guy later.
  520. memset (&DiskWorkspace, 0, sizeof(DiskWorkspace)) ;
  521. DiskWorkspacePosition = FileTell (hFile) ;
  522. DiskWorkspace.WindowPlacement.length = sizeof(WINDOWPLACEMENT);
  523. if (!GetWindowPlacement (hWndMain, &(DiskWorkspace.WindowPlacement)))
  524. {
  525. goto Exit0 ;
  526. }
  527. if (!FileWrite (hFile, &DiskWorkspace, sizeof (DISKWORKSPACE)))
  528. {
  529. goto Exit0 ;
  530. }
  531. // put in chart data
  532. DiskWorkspace.ChartOffset = FileTell (hFile) ;
  533. if (!SaveChart (hWndGraph, hFile, 0))
  534. {
  535. goto Exit0 ;
  536. }
  537. // put in alert data
  538. DiskWorkspace.AlertOffset = FileTell (hFile) ;
  539. if (!SaveAlert (hWndAlert, hFile, 0))
  540. {
  541. goto Exit0 ;
  542. }
  543. // put in log data
  544. DiskWorkspace.LogOffset = FileTell (hFile) ;
  545. if (!SaveLog (hWndLog, hFile, 0))
  546. {
  547. goto Exit0 ;
  548. }
  549. // put in report data
  550. DiskWorkspace.ReportOffset = FileTell (hFile) ;
  551. if (!SaveReport (hWndReport, hFile, 0))
  552. {
  553. goto Exit0 ;
  554. }
  555. // put in the disk header info
  556. DiskWorkspace.iPerfmonView = iPerfmonView ;
  557. FileSeekBegin (hFile, DiskWorkspacePosition) ;
  558. if (!FileWrite (hFile, &DiskWorkspace, sizeof (DISKWORKSPACE)))
  559. {
  560. goto Exit0 ;
  561. }
  562. bWriteErr = FALSE ;
  563. Exit0:
  564. if (bWriteErr)
  565. {
  566. DlgErrorBox (PerfmonViewWindow (), ERR_SETTING_FILE, szFileName) ;
  567. }
  568. CloseHandle (hFile) ;
  569. return TRUE;
  570. } // SaveWorkspace
  571. void SetPerfmonOptions (OPTIONS *pOptions)
  572. {
  573. Options = *pOptions ;
  574. ShowPerfmonMenu (Options.bMenubar) ;
  575. SizePerfmonComponents () ;
  576. WindowSetTopmost (hWndMain, Options.bAlwaysOnTop) ;
  577. } // SetPerfmonOptions
  578. void ChangeSaveFileName (LPTSTR szFileName, int iPMView)
  579. {
  580. LPTSTR *ppFullName = NULL;
  581. LPTSTR *ppFileName = NULL;
  582. BOOL errorInput = FALSE ;
  583. TCHAR szApplication [MessageLen] ;
  584. switch (iPMView)
  585. {
  586. case IDM_VIEWCHART:
  587. ppFileName = &pChartFileName ;
  588. ppFullName = &pChartFullFileName ;
  589. break ;
  590. case IDM_VIEWALERT:
  591. ppFileName = &pAlertFileName ;
  592. ppFullName = &pAlertFullFileName ;
  593. break ;
  594. case IDM_VIEWREPORT:
  595. ppFileName = &pReportFileName ;
  596. ppFullName = &pReportFullFileName ;
  597. break ;
  598. case IDM_VIEWLOG:
  599. ppFileName = &pLogFileName ;
  600. ppFullName = &pLogFullFileName ;
  601. break ;
  602. case IDM_WORKSPACE:
  603. // not a view but a define
  604. ppFileName = &pWorkSpaceFileName ;
  605. ppFullName = &pWorkSpaceFullFileName ;
  606. break ;
  607. default:
  608. errorInput = TRUE ;
  609. break ;
  610. }
  611. if (errorInput)
  612. {
  613. return ;
  614. }
  615. // release last filename
  616. if (*ppFullName)
  617. {
  618. MemoryFree (*ppFullName) ;
  619. *ppFileName = NULL ;
  620. *ppFullName = NULL ;
  621. }
  622. // allocate new file name and display it
  623. if (szFileName && (*ppFullName = StringAllocate (szFileName)))
  624. {
  625. *ppFileName = ExtractFileName (*ppFullName) ;
  626. }
  627. if (iPerfmonView == iPMView || iPMView == IDM_WORKSPACE)
  628. {
  629. StatusLineReady (hWndStatus) ;
  630. if (Options.bMenubar)
  631. {
  632. // display the name file name on the Title bar.
  633. StringLoad (IDS_APPNAME, szApplication) ;
  634. if (*ppFileName == NULL)
  635. {
  636. ppFileName = &pWorkSpaceFileName ;
  637. }
  638. if (*ppFileName)
  639. {
  640. lstrcat (szApplication, TEXT(" - ")) ;
  641. lstrcat (szApplication, *ppFileName) ;
  642. }
  643. SetWindowText (hWndMain, szApplication) ;
  644. }
  645. }
  646. } // ChangeSaveFileName
  647. BOOL
  648. IsNumberInUnicodeList (
  649. IN DWORD dwNumber,
  650. IN LPTSTR lpwszUnicodeList
  651. )
  652. /*++
  653. IsNumberInUnicodeList
  654. Arguments:
  655. IN dwNumber
  656. DWORD number to find in list
  657. IN lpwszUnicodeList
  658. Null terminated, Space delimited list of decimal numbers
  659. Return Value:
  660. TRUE:
  661. dwNumber was found in the list of unicode number strings
  662. FALSE:
  663. dwNumber was not found in the list.
  664. --*/
  665. {
  666. DWORD dwThisNumber;
  667. WCHAR *pwcThisChar;
  668. BOOL bValidNumber;
  669. BOOL bNewItem;
  670. WCHAR wcDelimiter; // could be an argument to be more flexible
  671. if (lpwszUnicodeList == 0) return FALSE; // null pointer, # not founde
  672. pwcThisChar = lpwszUnicodeList;
  673. dwThisNumber = 0;
  674. wcDelimiter = (WCHAR)' ';
  675. bValidNumber = FALSE;
  676. bNewItem = TRUE;
  677. while (TRUE) {
  678. switch (EvalThisChar (*pwcThisChar, wcDelimiter)) {
  679. case DIGIT:
  680. // if this is the first digit after a delimiter, then
  681. // set flags to start computing the new number
  682. if (bNewItem) {
  683. bNewItem = FALSE;
  684. bValidNumber = TRUE;
  685. }
  686. if (bValidNumber) {
  687. dwThisNumber *= 10;
  688. dwThisNumber += (*pwcThisChar - (WCHAR)'0');
  689. }
  690. break;
  691. case DELIMITER:
  692. // a delimter is either the delimiter character or the
  693. // end of the string ('\0') if when the delimiter has been
  694. // reached a valid number was found, then compare it to the
  695. // number from the argument list. if this is the end of the
  696. // string and no match was found, then return.
  697. //
  698. if (bValidNumber) {
  699. if (dwThisNumber == dwNumber) return TRUE;
  700. bValidNumber = FALSE;
  701. }
  702. if (*pwcThisChar == 0) {
  703. return FALSE;
  704. } else {
  705. bNewItem = TRUE;
  706. dwThisNumber = 0;
  707. }
  708. break;
  709. case INVALID:
  710. // if an invalid character was encountered, ignore all
  711. // characters up to the next delimiter and then start fresh.
  712. // the invalid number is not compared.
  713. bValidNumber = FALSE;
  714. break;
  715. default:
  716. break;
  717. }
  718. pwcThisChar++;
  719. }
  720. } // IsNumberInUnicodeList
  721. BOOL
  722. AppendObjectToValueList (
  723. DWORD dwObjectId,
  724. PWSTR pwszValueList
  725. )
  726. /*++
  727. AppendObjectToValueList
  728. Arguments:
  729. IN dwNumber
  730. DWORD number to insert in list
  731. IN PUNICODE_STRING
  732. pointer to unicode string structure that contains buffer that is
  733. Null terminated, Space delimited list of decimal numbers that
  734. may have this number appended to.
  735. Return Value:
  736. TRUE:
  737. dwNumber was added to list
  738. FALSE:
  739. dwNumber was not added. (because it's already there or
  740. an error occured)
  741. --*/
  742. {
  743. WCHAR tempString [SIZE_OF_BIGGEST_INTEGER] ;
  744. DWORD dwStrLen, dwNewStrLen;
  745. LPTSTR szFormatString;
  746. if (!pwszValueList) {
  747. return FALSE;
  748. }
  749. if (IsNumberInUnicodeList(dwObjectId, pwszValueList)) {
  750. return FALSE; // object already in list
  751. } else {
  752. // append the new object id the value list
  753. // if this is the first string to enter then don't
  754. // prefix with a space character otherwise do
  755. szFormatString = (*pwszValueList == 0) ? TEXT("%d") : TEXT(" %d");
  756. TSPRINTF (tempString, szFormatString, dwObjectId) ;
  757. // see if string will fit (compare in bytes)
  758. dwStrLen = MemorySize (pwszValueList) - sizeof (UNICODE_NULL);
  759. dwNewStrLen = (lstrlen (pwszValueList) + lstrlen (tempString)) *
  760. sizeof (WCHAR);
  761. if (dwNewStrLen <= dwStrLen) {
  762. lstrcat (pwszValueList, tempString);
  763. return TRUE;
  764. } else {
  765. SetLastError (ERROR_OUTOFMEMORY);
  766. return FALSE;
  767. }
  768. }
  769. }
  770. BOOL
  771. AddObjectToSystem (
  772. PLINE pLine,
  773. PPERFSYSTEM pFirstSystem
  774. )
  775. {
  776. PPERFSYSTEM pSystem;
  777. if ((ARGUMENT_PRESENT (pLine)) && (ARGUMENT_PRESENT(pFirstSystem))) {
  778. pSystem = SystemGet (pFirstSystem, pLine->lnSystemName);
  779. if (pSystem) {
  780. return AppendObjectToValueList (
  781. pLine->lnObject.ObjectNameTitleIndex,
  782. pSystem->lpszValue);
  783. } else {
  784. return FALSE;
  785. }
  786. } else {
  787. return FALSE;
  788. }
  789. }
  790. BOOL
  791. RemoveObjectsFromSystem (
  792. PPERFSYSTEM pSystem
  793. )
  794. {
  795. DWORD dwBufferSize = 0;
  796. if (ARGUMENT_PRESENT (pSystem)) {
  797. // don't do foreign computers
  798. if (pSystem->lpszValue && (_wcsnicmp(pSystem->lpszValue, L"Foreign", 7) != 0)){
  799. dwBufferSize = MemorySize (pSystem->lpszValue);
  800. memset (pSystem->lpszValue, 0, dwBufferSize);
  801. return TRUE;
  802. } else {
  803. return FALSE;
  804. }
  805. } else {
  806. return FALSE;
  807. }
  808. }
  809. BOOL
  810. BuildValueListForSystems (
  811. PPERFSYSTEM pSystemListHead,
  812. PLINE pLineListHead
  813. )
  814. /*++
  815. BuildValueListForSystem
  816. Abstract:
  817. Walks down line list and builds the list of objects to query from
  818. that system containing that line.
  819. Arguments:
  820. pSystemListHead
  821. head of system linked list
  822. each system will have it's "Value Name" list appended
  823. pLineListHead
  824. head of line list that will be searched for creating the new
  825. valuelist.
  826. Return Value:
  827. --*/
  828. {
  829. PPERFSYSTEM pSystem; // system that contains current line
  830. PLINE pThisLine; // current line
  831. if ((ARGUMENT_PRESENT (pLineListHead)) && (ARGUMENT_PRESENT(pSystemListHead))) {
  832. // clear system entries:
  833. for (pSystem = pSystemListHead; pSystem; pSystem = pSystem->pSystemNext) {
  834. if (pSystem && pSystem->FailureTime == 0) {
  835. RemoveObjectsFromSystem (pSystem);
  836. }
  837. }
  838. // add new enties
  839. for (pThisLine = pLineListHead; pThisLine; pThisLine = pThisLine->pLineNext) {
  840. pSystem = SystemGet (pSystemListHead, pThisLine->lnSystemName);
  841. if (pSystem && pSystem->FailureTime == 0) {
  842. AppendObjectToValueList (
  843. pThisLine->lnObject.ObjectNameTitleIndex,
  844. pSystem->lpszValue);
  845. }
  846. }
  847. return TRUE;
  848. } else { // argument(s) missing
  849. return FALSE;
  850. }
  851. }
  852. // define in Addline.c
  853. extern PLINESTRUCT pLineEdit ;
  854. #define bEditLine (pLineEdit != NULL)
  855. BOOL
  856. SetSystemValueNameToGlobal (
  857. PPERFSYSTEM pSystem
  858. )
  859. {
  860. if (!bEditLine && ARGUMENT_PRESENT(pSystem)) {
  861. if (pSystem->lpszValue && RemoveObjectsFromSystem(pSystem)) {
  862. if (pSystem->lpszValue && (_wcsnicmp(pSystem->lpszValue, L"Foreign",7) != 0)){
  863. // don't change foreign computer strings
  864. lstrcpy (
  865. pSystem->lpszValue,
  866. TEXT("Global")) ;
  867. }
  868. return TRUE;
  869. } else {
  870. return FALSE;
  871. }
  872. } else {
  873. return FALSE;
  874. }
  875. }
  876. BOOL
  877. RemoveUnusedSystems (
  878. PPERFSYSTEM pSystemHead,
  879. PLINE pLineHead
  880. )
  881. /*++
  882. walks system list and removes systems with no lines from list
  883. --*/
  884. {
  885. PPERFSYSTEM pSystem;
  886. PPERFSYSTEM pLastSystem;
  887. PLINE pLine;
  888. BOOL bSystemFound;
  889. pLastSystem = NULL;
  890. if ((ARGUMENT_PRESENT (pLineHead)) && (ARGUMENT_PRESENT(pSystemHead))) {
  891. for (pSystem = pSystemHead;
  892. pSystem;
  893. pLastSystem = pSystem, pSystem = pSystem->pSystemNext) {
  894. if (pSystem) {
  895. bSystemFound = FALSE;
  896. // walk lines to see if this system has a line
  897. for (pLine = pLineHead; pLine; pLine = pLine->pLineNext) {
  898. // if system in line is this system, then bailout
  899. if (strsame (pLine->lnSystemName, pSystem->sysName)) {
  900. bSystemFound = TRUE;
  901. break;
  902. }
  903. }
  904. if (!bSystemFound) { // delete this unused system
  905. // fix pointers
  906. pLastSystem->pSystemNext = pSystem->pSystemNext;
  907. SystemFree (pSystem, TRUE);
  908. // set pointer back to a valid structure
  909. pSystem = pLastSystem;
  910. }
  911. }
  912. }
  913. }
  914. return TRUE;
  915. }
  916. void CreatePerfmonSystemObjects ()
  917. {
  918. ColorBtnFace = GetSysColor (COLOR_BTNFACE) ;
  919. hBrushFace = CreateSolidBrush (ColorBtnFace) ;
  920. hPenHighlight = CreatePen (PS_SOLID, 1, GetSysColor (COLOR_BTNHIGHLIGHT)) ;
  921. hPenShadow = CreatePen (PS_SOLID, 1, GetSysColor (COLOR_BTNSHADOW)) ;
  922. SetClassLong (hWndMain, GCL_HBRBACKGROUND, (LONG)hBrushFace);
  923. }
  924. void DeletePerfmonSystemObjects ()
  925. {
  926. if (hBrushFace)
  927. {
  928. DeleteBrush (hBrushFace) ;
  929. hBrushFace = 0 ;
  930. }
  931. if (hPenHighlight)
  932. {
  933. DeletePen (hPenHighlight) ;
  934. hPenHighlight = 0 ;
  935. }
  936. if (hPenShadow)
  937. {
  938. DeletePen (hPenShadow) ;
  939. hPenShadow = 0 ;
  940. }
  941. }
  942. // This routine count the number of the same charatcer in the input string
  943. int SameCharCount (LPTSTR pInputString)
  944. {
  945. int Count = 0 ;
  946. TCHAR InputChar = *pInputString ;
  947. if (InputChar)
  948. {
  949. while (InputChar == *pInputString)
  950. {
  951. Count ++ ;
  952. pInputString ++ ;
  953. }
  954. }
  955. return (Count) ;
  956. }
  957. // create the format to be used in SystemTimeDateString()
  958. BOOL CreateDateFormat (LPTSTR pShortDate)
  959. {
  960. int iIndex ;
  961. int iDayCount ;
  962. int iMonthCount ;
  963. int DateSeparatorCount ;
  964. TCHAR szDateSeparator [10] ;
  965. BOOL bFirstLeading, bSecondLeading, bThirdLeading ;
  966. // get the date format based on the first char
  967. if (*pShortDate == TEXT('M') || *pShortDate == TEXT('m'))
  968. {
  969. DateStyle = MONTH_FIRST ;
  970. }
  971. else if (*pShortDate == TEXT('D') || *pShortDate == TEXT('d'))
  972. {
  973. DateStyle = DAY_FIRST ;
  974. }
  975. else if (*pShortDate == TEXT('Y') || *pShortDate == TEXT('y'))
  976. {
  977. DateStyle = YEAR_FIRST ;
  978. }
  979. else
  980. {
  981. // bad format
  982. return FALSE ;
  983. }
  984. bFirstLeading = bSecondLeading = bThirdLeading = FALSE ;
  985. switch (DateStyle)
  986. {
  987. case YEAR_FIRST:
  988. // YYYY-MM-DD
  989. YearCharCount = SameCharCount (pShortDate) ;
  990. pShortDate += YearCharCount ;
  991. DateSeparatorCount = SameCharCount (pShortDate) ;
  992. // get the separator string
  993. for (iIndex = 0; iIndex < DateSeparatorCount; iIndex ++)
  994. {
  995. szDateSeparator [iIndex] = *pShortDate++ ;
  996. }
  997. szDateSeparator [iIndex] = TEXT('\0') ;
  998. iMonthCount = SameCharCount (pShortDate) ;
  999. pShortDate += iMonthCount + DateSeparatorCount ;
  1000. iDayCount = SameCharCount (pShortDate) ;
  1001. if (YearCharCount == 2)
  1002. {
  1003. bFirstLeading = TRUE ;
  1004. }
  1005. if (iMonthCount == 2)
  1006. {
  1007. bSecondLeading = TRUE ;
  1008. }
  1009. if (iDayCount == 2)
  1010. {
  1011. bThirdLeading = TRUE ;
  1012. }
  1013. break ;
  1014. case MONTH_FIRST:
  1015. // MM-DD-YYYY
  1016. iMonthCount = SameCharCount (pShortDate) ;
  1017. pShortDate += iMonthCount ;
  1018. DateSeparatorCount = SameCharCount (pShortDate) ;
  1019. // get the separator string
  1020. for (iIndex = 0; iIndex < DateSeparatorCount; iIndex ++)
  1021. {
  1022. szDateSeparator [iIndex] = *pShortDate++ ;
  1023. }
  1024. szDateSeparator [iIndex] = TEXT('\0') ;
  1025. iDayCount = SameCharCount (pShortDate) ;
  1026. pShortDate += iMonthCount + DateSeparatorCount ;
  1027. YearCharCount = SameCharCount (pShortDate) ;
  1028. if (iMonthCount == 2)
  1029. {
  1030. bFirstLeading = TRUE ;
  1031. }
  1032. if (iDayCount == 2)
  1033. {
  1034. bSecondLeading = TRUE ;
  1035. }
  1036. if (YearCharCount == 2)
  1037. {
  1038. bThirdLeading = TRUE ;
  1039. }
  1040. break ;
  1041. case DAY_FIRST:
  1042. // DD-MM-YYYY
  1043. iDayCount = SameCharCount (pShortDate) ;
  1044. pShortDate += iDayCount ;
  1045. DateSeparatorCount = SameCharCount (pShortDate) ;
  1046. // get the separator string
  1047. for (iIndex = 0; iIndex < DateSeparatorCount; iIndex ++)
  1048. {
  1049. szDateSeparator [iIndex] = *pShortDate++ ;
  1050. }
  1051. szDateSeparator [iIndex] = TEXT('\0') ;
  1052. iMonthCount = SameCharCount (pShortDate) ;
  1053. pShortDate += iMonthCount + DateSeparatorCount ;
  1054. YearCharCount = SameCharCount (pShortDate) ;
  1055. if (iDayCount == 2)
  1056. {
  1057. bFirstLeading = TRUE ;
  1058. }
  1059. if (iMonthCount == 2)
  1060. {
  1061. bSecondLeading = TRUE ;
  1062. }
  1063. if (YearCharCount == 2)
  1064. {
  1065. bThirdLeading = TRUE ;
  1066. }
  1067. break ;
  1068. }
  1069. // now generate the date format
  1070. lstrcpy (szDateFormat, bFirstLeading ? LeadingZeroStr : NoLeadingZeroStr) ;
  1071. lstrcat (szDateFormat, szDateSeparator) ;
  1072. lstrcat (szDateFormat, bSecondLeading ? LeadingZeroStr : NoLeadingZeroStr) ;
  1073. lstrcat (szDateFormat, szDateSeparator) ;
  1074. lstrcat (szDateFormat, bThirdLeading ? LeadingZeroStr : NoLeadingZeroStr) ;
  1075. return TRUE ;
  1076. }
  1077. BOOL CreateTimeFormat (LPTSTR pTimeSeparator, int iLeadingZero)
  1078. {
  1079. // create the format to be used in SystemTimeTimeString
  1080. if (iLeadingZero)
  1081. {
  1082. lstrcpy (szTimeFormat, LeadingZeroStr) ;
  1083. }
  1084. else
  1085. {
  1086. lstrcpy (szTimeFormat, NoLeadingZeroStr) ;
  1087. }
  1088. lstrcat (szTimeFormat, pTimeSeparator) ;
  1089. lstrcat (szTimeFormat, LeadingZeroStr) ;
  1090. lstrcat (szTimeFormat, pTimeSeparator) ;
  1091. // lstrcat (szTimeFormat, LeadingZeroStr) ;
  1092. // Duplicate the format without the msec field (for export use)
  1093. lstrcpy (szTimeFormat1, szTimeFormat) ;
  1094. // for the msec
  1095. lstrcat (szTimeFormat, TEXT("%02.1f")) ;
  1096. // for sec without msec
  1097. lstrcat (szTimeFormat1, TEXT("%02d")) ;
  1098. if (iTime == 0)
  1099. {
  1100. lstrcat (szTimeFormat, TEXT(" %s ")) ;
  1101. lstrcat (szTimeFormat1, TEXT(" %s ")) ;
  1102. }
  1103. return TRUE ;
  1104. } // CreateTimeFormats
  1105. BOOL GetInternational()
  1106. {
  1107. TCHAR szShortDate[40] ;
  1108. TCHAR szTime[40] ; // time separator
  1109. DWORD RetCode ;
  1110. int iTLZero = 0 ; // = 0 for no leading zero, <> 0 for leading zero
  1111. CHAR aLanguageStr [2] ;
  1112. LPSTR pRetStr ;
  1113. LPTSTR lpStr ;
  1114. // read the data from the win.ini (which i smapped to registry)
  1115. RetCode = GetProfileString(szInternational,
  1116. TEXT("sShortDate"), szShortDate, szShortDate, sizeof(szShortDate)/sizeof(TCHAR));
  1117. if (RetCode)
  1118. {
  1119. RetCode = GetProfileString(szInternational,
  1120. TEXT("sTime"), szTime, szTime, sizeof(szTime)/sizeof(TCHAR));
  1121. }
  1122. if (RetCode)
  1123. {
  1124. iTime = GetProfileInt(szInternational, TEXT("iTime"), iTime);
  1125. iTLZero = GetProfileInt(szInternational, TEXT("iTLZero"), iTLZero);
  1126. GetProfileString(szInternational, TEXT("sDecimal"), szDecimal, szDecimal, sizeof(szDecimal)/sizeof(TCHAR));
  1127. if (iTime == 0)
  1128. {
  1129. // get the AM PM strings for 12-hour format.
  1130. // These two strings could be NULL.
  1131. sz1159[0] = sz2359[0] = TEXT('\0') ;
  1132. GetProfileString(szInternational,
  1133. TEXT("s1159"), sz1159, sz1159, sizeof(sz1159)/sizeof(TCHAR));
  1134. GetProfileString(szInternational,
  1135. TEXT("s2359"), sz2359, sz2359, sizeof(sz2359)/sizeof(TCHAR));
  1136. }
  1137. }
  1138. // create the two formats
  1139. if (RetCode)
  1140. {
  1141. RetCode = (DWORD) CreateDateFormat (szShortDate) ;
  1142. }
  1143. if (RetCode)
  1144. {
  1145. RetCode = (DWORD) CreateTimeFormat (szTime, iTLZero) ;
  1146. }
  1147. // use the system default language numeric
  1148. aLanguageStr[0] = '\0' ;
  1149. pRetStr = setlocale(LC_NUMERIC, aLanguageStr);
  1150. // get current decimal point used by C-runtime
  1151. TSPRINTF (szShortDate, TEXT("%f"), (FLOAT)1.0) ;
  1152. lpStr = szShortDate ;
  1153. szCurrentDecimal [0] = TEXT('\0') ;
  1154. while (*lpStr != TEXT('\0'))
  1155. {
  1156. if (*lpStr == TEXT('1'))
  1157. {
  1158. lpStr++ ;
  1159. szCurrentDecimal [0] = *lpStr ;
  1160. break ;
  1161. }
  1162. lpStr++ ;
  1163. }
  1164. if (szCurrentDecimal[0] == TEXT('\0'))
  1165. {
  1166. szCurrentDecimal [0] = TEXT('.') ;
  1167. }
  1168. return (RetCode != 0) ;
  1169. } // GetInternational
  1170. // this routine is called to get the date/time formats either
  1171. // for the resource or from the registry.
  1172. void GetDateTimeFormats ()
  1173. {
  1174. PALERT pAlert ;
  1175. PLOG pLog ;
  1176. if (!GetInternational())
  1177. {
  1178. // GetInternational failed, then get default formats from resource
  1179. iTime = 0 ;
  1180. DateStyle = MONTH_FIRST ;
  1181. YearCharCount = 4 ;
  1182. StringLoad (IDS_S1159, sz1159) ;
  1183. StringLoad (IDS_S2359, sz2359) ;
  1184. StringLoad (IDS_TIME_FORMAT, szTimeFormat) ;
  1185. StringLoad (IDS_SHORT_DATE_FORMAT, szDateFormat) ;
  1186. }
  1187. WindowInvalidate (PerfmonViewWindow()) ;
  1188. // reset all the field taht may be affected by the
  1189. // language numberic changes
  1190. pAlert = AlertData (hWndMain) ;
  1191. pLog = LogData (hWndMain) ;
  1192. if (pAlert)
  1193. {
  1194. DialogSetInterval (hWndAlert, IDD_ALERTINTERVAL, pAlert->iIntervalMSecs) ;
  1195. }
  1196. if (pLog)
  1197. {
  1198. DialogSetInterval (hWndLog, IDD_LOGINTERVAL, pLog->iIntervalMSecs) ;
  1199. }
  1200. } // GetDateTimeFormats
  1201. void ConvertDecimalPoint (LPTSTR lpFloatPointStr)
  1202. {
  1203. if (szCurrentDecimal[0] == szDecimal[0])
  1204. {
  1205. // no need to convert anything
  1206. return ;
  1207. }
  1208. while (*lpFloatPointStr)
  1209. {
  1210. if (*lpFloatPointStr == szCurrentDecimal[0])
  1211. {
  1212. *lpFloatPointStr = szDecimal[0] ;
  1213. break ;
  1214. }
  1215. ++lpFloatPointStr ;
  1216. }
  1217. } // ConvertDecimalPoint
  1218. void ReconvertDecimalPoint (LPTSTR lpFloatPointStr)
  1219. {
  1220. if (szCurrentDecimal[0] == szDecimal[0])
  1221. {
  1222. // no need to convert anything
  1223. return ;
  1224. }
  1225. while (*lpFloatPointStr)
  1226. {
  1227. if (*lpFloatPointStr == szDecimal[0])
  1228. {
  1229. *lpFloatPointStr = szCurrentDecimal[0] ;
  1230. break ;
  1231. }
  1232. ++lpFloatPointStr ;
  1233. }
  1234. } // ReconvertDecimalPoint