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.

298 lines
9.4 KiB

  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 "utils.h"
  9. #include "perfmops.h" // for SystemTimeDateString
  10. #include "fileopen.h" // for FileGetName
  11. #include "fileutil.h" // for FileRead etc
  12. #include "playback.h" // for PlayingBackLog & LogPositionSystemTime
  13. #include "dlgs.h" // common dialog control IDs
  14. #include "pmhelpid.h" // Help IDs
  15. // This routine opens the export file and put in the header info.
  16. // It is used by ExportChart, ExportAlert, & ExportReport.
  17. INT
  18. ExportFileOpen (
  19. HWND hWnd,
  20. HANDLE *phFile,
  21. int IntervalMSecs,
  22. LPTSTR *ppFileName
  23. )
  24. {
  25. CHAR TempBuff [LongTextLen*2] ; // The maximum number of bytes that can be stored in the multibyte output string is twice as the number of wide-charcter string.
  26. TCHAR UnicodeBuff [LongTextLen] ;
  27. TCHAR UnicodeBuff1 [MiscTextLen] ;
  28. SYSTEMTIME SystemTime ;
  29. int StringLen ;
  30. INT ErrCode = 0 ;
  31. FLOAT eIntervalSecs ;
  32. HANDLE hFile;
  33. // defined and setup in status.c
  34. extern TCHAR szCurrentActivity [] ;
  35. extern TCHAR szStatusFormat [] ;
  36. if (phFile == NULL)
  37. ErrCode = ERR_EXPORT_FILE;
  38. *phFile = 0 ;
  39. if (!FileGetName (hWnd, IDS_EXPORTFILE, UnicodeBuff)) {
  40. // user cancel
  41. goto Exit0 ;
  42. }
  43. *ppFileName = StringAllocate (UnicodeBuff) ;
  44. // open the file..
  45. hFile = FileHandleCreate (UnicodeBuff);
  46. if (!hFile || hFile == INVALID_HANDLE_VALUE) {
  47. // can't open the file
  48. ErrCode = ERR_CANT_OPEN ;
  49. goto Exit0 ;
  50. }
  51. *phFile = hFile;
  52. // export header
  53. StringLoad (IDS_REPORT_HEADER, UnicodeBuff) ;
  54. ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  55. StringLen = strlen (TempBuff) ;
  56. ConvertUnicodeStr (&TempBuff[StringLen], LocalComputerName) ;
  57. strcat (TempBuff, LineEndStr) ;
  58. if (!FileWrite (hFile, TempBuff, strlen(TempBuff))) {
  59. ErrCode = ERR_EXPORT_FILE ;
  60. goto Exit0 ;
  61. }
  62. // export today's date time
  63. GetLocalTime (&SystemTime) ;
  64. StringLoad (IDS_EXPORT_DATE, UnicodeBuff) ;
  65. StringLen = lstrlen (UnicodeBuff) ;
  66. UnicodeBuff[StringLen] = TEXT(':') ;
  67. UnicodeBuff[StringLen+1] = TEXT(' ') ;
  68. SystemTimeDateString (&SystemTime, &UnicodeBuff[StringLen+2]) ;
  69. ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  70. strcat (TempBuff, LineEndStr) ;
  71. if (!FileWrite (hFile, TempBuff, strlen(TempBuff))) {
  72. ErrCode = ERR_EXPORT_FILE ;
  73. goto Exit0 ;
  74. }
  75. StringLoad (IDS_EXPORT_TIME, UnicodeBuff) ;
  76. StringLen = lstrlen (UnicodeBuff) ;
  77. UnicodeBuff[StringLen] = TEXT(':') ;
  78. UnicodeBuff[StringLen+1] = TEXT(' ') ;
  79. SystemTimeTimeString (&SystemTime, &UnicodeBuff[StringLen+2], FALSE) ;
  80. ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  81. strcat (TempBuff, LineEndStr) ;
  82. if (!FileWrite (hFile, TempBuff, strlen(TempBuff))) {
  83. ErrCode = ERR_EXPORT_FILE ;
  84. goto Exit0 ;
  85. }
  86. // export data source
  87. TSPRINTF (UnicodeBuff, szStatusFormat,
  88. PlayingBackLog () ?
  89. PlaybackLog.szFileTitle : szCurrentActivity) ;
  90. ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  91. strcat (TempBuff, LineEndStr) ;
  92. if (!FileWrite (hFile, TempBuff, strlen(TempBuff))) {
  93. ErrCode = ERR_EXPORT_FILE ;
  94. goto Exit0 ;
  95. }
  96. if (!PlayingBackLog()) {
  97. eIntervalSecs = (FLOAT)IntervalMSecs / (FLOAT) 1000.0 ;
  98. StringLoad (IDS_CHARTINT_FORMAT, UnicodeBuff1) ;
  99. TSPRINTF (UnicodeBuff, UnicodeBuff1, eIntervalSecs) ;
  100. ConvertDecimalPoint (UnicodeBuff) ;
  101. ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  102. strcat (TempBuff, LineEndStr) ;
  103. if (!FileWrite (hFile, TempBuff, strlen(TempBuff))) {
  104. ErrCode = ERR_EXPORT_FILE ;
  105. goto Exit0 ;
  106. }
  107. } else {
  108. // export the log start and stop date/time
  109. StringLoad (IDS_START_TEXT, UnicodeBuff) ;
  110. StringLen = lstrlen (UnicodeBuff) ;
  111. LogPositionSystemTime (&(PlaybackLog.StartIndexPos), &SystemTime) ;
  112. SystemTimeDateString (&SystemTime, &UnicodeBuff[StringLen]) ;
  113. StringLen = lstrlen (UnicodeBuff) ;
  114. UnicodeBuff[StringLen] = TEXT(' ') ;
  115. StringLen++ ;
  116. SystemTimeTimeString (&SystemTime, &UnicodeBuff[StringLen], FALSE) ;
  117. ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  118. strcat (TempBuff, LineEndStr) ;
  119. if (!FileWrite (hFile, TempBuff, strlen(TempBuff))) {
  120. ErrCode = ERR_EXPORT_FILE ;
  121. goto Exit0 ;
  122. }
  123. StringLoad (IDS_STOP_TEXT, UnicodeBuff) ;
  124. StringLen = lstrlen (UnicodeBuff) ;
  125. LogPositionSystemTime (&(PlaybackLog.StopIndexPos), &SystemTime) ;
  126. SystemTimeDateString (&SystemTime, &UnicodeBuff[StringLen]) ;
  127. StringLen = lstrlen (UnicodeBuff) ;
  128. UnicodeBuff[StringLen] = TEXT(' ') ;
  129. StringLen++ ;
  130. SystemTimeTimeString (&SystemTime, &UnicodeBuff[StringLen], FALSE) ;
  131. ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  132. strcat (TempBuff, LineEndStr) ;
  133. if (!FileWrite (hFile, TempBuff, strlen(TempBuff))) {
  134. ErrCode = ERR_EXPORT_FILE ;
  135. goto Exit0 ;
  136. }
  137. if (hWnd == hWndAlert) {
  138. eIntervalSecs = (FLOAT)IntervalMSecs / (FLOAT) 1000.0 ;
  139. StringLoad (IDS_CHARTINT_FORMAT, UnicodeBuff1) ;
  140. TSPRINTF (UnicodeBuff, UnicodeBuff1, eIntervalSecs) ;
  141. ConvertDecimalPoint (UnicodeBuff) ;
  142. ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  143. strcat (TempBuff, LineEndStr) ;
  144. if (!FileWrite (hFile, TempBuff, strlen(TempBuff))) {
  145. ErrCode = ERR_EXPORT_FILE ;
  146. goto Exit0 ;
  147. }
  148. }
  149. }
  150. return (0) ;
  151. Exit0:
  152. return (ErrCode) ;
  153. } // ExportFileOpen
  154. BOOL
  155. APIENTRY
  156. ExportOptionsHookProc (
  157. HWND hDlg,
  158. UINT iMessage,
  159. WPARAM wParam,
  160. LPARAM lParam
  161. )
  162. {
  163. BOOL bHandled ;
  164. bHandled = TRUE ;
  165. switch (iMessage) {
  166. case WM_INITDIALOG:
  167. CheckRadioButton (hDlg, IDD_EXPORTCOMMAS, IDD_EXPORTTAB,
  168. pDelimiter == TabStr ? IDD_EXPORTTAB : IDD_EXPORTCOMMAS ) ;
  169. WindowCenter (hDlg) ;
  170. break ;
  171. #if WINVER >= 0x0400
  172. case WM_NOTIFY:
  173. {
  174. LPOFNOTIFY pOfn;
  175. pOfn = (LPOFNOTIFY)lParam;
  176. switch (pOfn->hdr.code) {
  177. case CDN_INITDONE:
  178. WindowCenter (pOfn->hdr.hwndFrom) ;
  179. break;
  180. case CDN_FILEOK:
  181. {
  182. INT_PTR iFileIndex ;
  183. HWND hWndCBox;
  184. hWndCBox = GetDlgItem (pOfn->hdr.hwndFrom, cmb1); // Type combo box
  185. iFileIndex = CBSelection (hWndCBox) ;
  186. // the order of the entries in the combo box depends on
  187. // the current delimiter character
  188. if (pDelimiter == TabStr) {
  189. pDelimiter = iFileIndex == 0 ? // 0 = TSV, 1=CSV
  190. TabStr : CommasStr;
  191. } else {
  192. pDelimiter = iFileIndex == 0 ? // 0 = TSV, 1=CSV
  193. CommasStr : TabStr;
  194. }
  195. }
  196. break;
  197. default:
  198. break;
  199. }
  200. }
  201. break;
  202. #endif
  203. case WM_COMMAND:
  204. switch (LOWORD(wParam)) {
  205. case IDD_EXPORTCOMMAS:
  206. case IDD_EXPORTTAB:
  207. // toggle between the 2 radio buttons..
  208. CheckRadioButton (hDlg, IDD_EXPORTCOMMAS, IDD_EXPORTTAB,
  209. LOWORD(wParam) == IDD_EXPORTTAB ?
  210. IDD_EXPORTTAB : IDD_EXPORTCOMMAS ) ;
  211. break ;
  212. case IDD_OK:
  213. pDelimiter = IsDlgButtonChecked (hDlg, IDD_EXPORTCOMMAS) ?
  214. CommasStr : TabStr ;
  215. bHandled = FALSE ;
  216. break ;
  217. case IDD_EXPORTHELP:
  218. CallWinHelp (dwCurrentDlgID, hDlg) ;
  219. break ;
  220. case cmb1:
  221. if (HIWORD (wParam) == CBN_SELCHANGE) {
  222. INT_PTR iFileIndex ;
  223. HWND hWndCBox = (HWND) lParam ;
  224. // a diff. selection from the file type, change
  225. // the delimiter accordingly.
  226. iFileIndex = CBSelection (hWndCBox) ;
  227. CheckRadioButton (hDlg, IDD_EXPORTCOMMAS, IDD_EXPORTTAB,
  228. iFileIndex == 0 ?
  229. IDD_EXPORTTAB : IDD_EXPORTCOMMAS ) ;
  230. } else {
  231. bHandled = FALSE ;
  232. }
  233. break ;
  234. default:
  235. bHandled = FALSE ;
  236. }
  237. break;
  238. default:
  239. bHandled = FALSE ;
  240. break;
  241. }
  242. return (bHandled) ;
  243. }