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.

476 lines
14 KiB

  1. #include "perfmon.h"
  2. #include "cderr.h"
  3. #include "alert.h" // for OpenAlert
  4. #include "fileutil.h" // for FileOpen, FileRead
  5. #include "grafdata.h" // for OpenChart
  6. #include "log.h" // for OpenLog
  7. #include "report.h" // for OpenReport
  8. #include "utils.h" // for strempty
  9. #include "perfmops.h" // for OpenWorkspace
  10. #include "pmhelpid.h" // Help IDs
  11. #include <dlgs.h> // for pshHelp
  12. #define OptionsOFNStyle \
  13. (OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ENABLEHOOK | OFN_EXPLORER)
  14. // (OFN_HIDEREADONLY | OFN_SHOWHELP | OFN_OVERWRITEPROMPT | OFN_ENABLEHOOK)
  15. #define ExportOptionsOFNStyle \
  16. (OFN_ENABLETEMPLATE | OFN_HIDEREADONLY | \
  17. OFN_ENABLEHOOK | OFN_OVERWRITEPROMPT | OFN_EXPLORER)
  18. // OFN_SHOWHELP | OFN_ENABLEHOOK | OFN_OVERWRITEPROMPT)
  19. extern BOOL APIENTRY ExportOptionsHookProc (HWND hDlg, UINT iMessage,
  20. WPARAM wParam, LPARAM lParam) ;
  21. BOOL APIENTRY FileOpenHookProc (HWND hDlg,
  22. UINT iMessage,
  23. WPARAM wParam,
  24. LPARAM lParam)
  25. {
  26. BOOL bHandled = FALSE ;
  27. // only intercept the Help button and bring up our WinHelp data
  28. if (iMessage == WM_COMMAND && wParam == pshHelp)
  29. {
  30. CallWinHelp (dwCurrentDlgID, hDlg) ;
  31. bHandled = TRUE ;
  32. }
  33. else if (iMessage == WM_INITDIALOG)
  34. {
  35. WindowCenter (hDlg) ;
  36. bHandled = TRUE ;
  37. }
  38. #if WINVER >= 0x0400
  39. else if (iMessage == WM_NOTIFY)
  40. {
  41. LPOFNOTIFY pOfn;
  42. pOfn = (LPOFNOTIFY)lParam;
  43. switch (pOfn->hdr.code) {
  44. case CDN_INITDONE:
  45. WindowCenter (pOfn->hdr.hwndFrom) ;
  46. break;
  47. default:
  48. break;
  49. }
  50. }
  51. #endif
  52. return (bHandled) ;
  53. }
  54. BOOL FileOpen (HWND hWndParent, int nStringResourceID, LPTSTR lpInputFileName)
  55. {
  56. OPENFILENAME ofn ;
  57. TCHAR szFileSpec [FilePathLen] ;
  58. TCHAR szFileTitle [FilePathLen] ;
  59. TCHAR szDialogTitle [FilePathLen] ;
  60. HANDLE hFile ;
  61. PERFFILEHEADER FileHeader ;
  62. TCHAR aszOpenFilter[LongTextLen] ;
  63. int StringLength ;
  64. BOOL retCode ;
  65. LPTSTR pFileName = NULL ;
  66. BOOL bNoFile = FALSE;
  67. if (lpInputFileName == NULL) {
  68. bNoFile = TRUE;
  69. }
  70. else if (strempty(lpInputFileName)) {
  71. bNoFile = TRUE;
  72. }
  73. aszOpenFilter[0] = 0;
  74. if (bNoFile)
  75. {
  76. dwCurrentDlgID = HC_PM_idDlgFileOpen ;
  77. // get the file extension strings
  78. LoadString (hInstance, nStringResourceID, aszOpenFilter,
  79. sizeof(aszOpenFilter) / sizeof(TCHAR)) ;
  80. StringLength = lstrlen (aszOpenFilter) + 1 ;
  81. LoadString (hInstance, nStringResourceID+1,
  82. &aszOpenFilter[StringLength],
  83. sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
  84. StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1 ;
  85. #ifdef ADVANCED_PERFMON
  86. // get workspace file extension strings
  87. LoadString (hInstance, IDS_WORKSPACEFILE,
  88. &aszOpenFilter[StringLength],
  89. sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
  90. StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1 ;
  91. LoadString (hInstance, IDS_WORKSPACEFILEEXT,
  92. &aszOpenFilter[StringLength],
  93. sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
  94. StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1;
  95. #endif
  96. // get all file extension strings
  97. LoadString (hInstance, IDS_ALLFILES,
  98. &aszOpenFilter[StringLength],
  99. sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
  100. StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1 ;
  101. LoadString (hInstance, IDS_ALLFILESEXT,
  102. &aszOpenFilter[StringLength],
  103. sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
  104. StringLength += lstrlen (&aszOpenFilter[StringLength]) ;
  105. // setup the end strings
  106. aszOpenFilter[StringLength+1] = aszOpenFilter[StringLength+2] = TEXT('\0') ;
  107. strclr (szFileSpec) ;
  108. strclr (szFileTitle) ;
  109. StringLoad (IDS_FILEOPEN_TITLE, szDialogTitle) ;
  110. memset (&ofn, 0, sizeof(OPENFILENAME)) ;
  111. ofn.lStructSize = sizeof(OPENFILENAME) ;
  112. ofn.hwndOwner = hWndParent ;
  113. ofn.hInstance = hInstance;
  114. ofn.lpstrTitle = szDialogTitle ;
  115. ofn.lpstrFilter = aszOpenFilter ;
  116. ofn.nFilterIndex = 1L ;
  117. ofn.lpstrFile = szFileSpec;
  118. ofn.nMaxFile = sizeof(szFileSpec);
  119. ofn.lpstrFileTitle = szFileTitle;
  120. ofn.nMaxFileTitle = sizeof(szFileTitle);
  121. // ofn.Flags = OFN_HIDEREADONLY | OFN_SHOWHELP | OFN_FILEMUSTEXIST | OFN_ENABLEHOOK ;
  122. ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_ENABLEHOOK | OFN_EXPLORER;
  123. ofn.lpfnHook = (LPOFNHOOKPROC) FileOpenHookProc ;
  124. if (!GetOpenFileName(&ofn))
  125. {
  126. dwCurrentDlgID = 0 ;
  127. return (FALSE) ;
  128. }
  129. dwCurrentDlgID = 0 ;
  130. hFile = FileHandleOpen (szFileSpec) ;
  131. pFileName = szFileSpec ;
  132. } // NULL lpFileName
  133. else
  134. {
  135. // open the input file
  136. hFile = FileHandleOpen (lpInputFileName) ;
  137. if (hFile && hFile != INVALID_HANDLE_VALUE &&
  138. SearchPath (NULL, lpInputFileName, NULL,
  139. sizeof(szFileSpec)/sizeof(TCHAR) - 1,
  140. szFileSpec, &pFileName))
  141. {
  142. pFileName = szFileSpec ;
  143. }
  144. else
  145. {
  146. pFileName = NULL ;
  147. }
  148. }
  149. if (!hFile || hFile == INVALID_HANDLE_VALUE)
  150. {
  151. return (FALSE) ;
  152. }
  153. if (!FileRead (hFile, &FileHeader, sizeof (FileHeader)))
  154. {
  155. CloseHandle (hFile) ;
  156. if (bNoFile)
  157. {
  158. DlgErrorBox (hWndParent, ERR_BAD_SETTING_FILE, pFileName) ;
  159. }
  160. return (FALSE) ;
  161. }
  162. //=============================//
  163. // Chart File? //
  164. //=============================//
  165. if (strsame (FileHeader.szSignature, szPerfChartSignature))
  166. {
  167. retCode = OpenChart (hWndGraph,
  168. hFile,
  169. FileHeader.dwMajorVersion,
  170. FileHeader.dwMinorVersion,
  171. TRUE) ;
  172. if (retCode)
  173. {
  174. ChangeSaveFileName (pFileName, IDM_VIEWCHART) ;
  175. }
  176. else
  177. {
  178. goto ErrExit ;
  179. }
  180. return (retCode) ;
  181. }
  182. #ifdef ADVANCED_PERFMON
  183. //=============================//
  184. // Alert File? //
  185. //=============================//
  186. if (strsame (FileHeader.szSignature, szPerfAlertSignature))
  187. {
  188. retCode = OpenAlert (hWndAlert,
  189. hFile,
  190. FileHeader.dwMajorVersion,
  191. FileHeader.dwMinorVersion,
  192. TRUE) ;
  193. if (retCode)
  194. {
  195. ChangeSaveFileName (pFileName, IDM_VIEWALERT) ;
  196. }
  197. else
  198. {
  199. goto ErrExit ;
  200. }
  201. return (retCode) ;
  202. }
  203. //=============================//
  204. // Log File? //
  205. //=============================//
  206. if (strsame (FileHeader.szSignature, szPerfLogSignature))
  207. {
  208. retCode = OpenLog (hWndLog,
  209. hFile,
  210. FileHeader.dwMajorVersion,
  211. FileHeader.dwMinorVersion,
  212. TRUE) ;
  213. if (retCode)
  214. {
  215. ChangeSaveFileName (pFileName, IDM_VIEWLOG) ;
  216. }
  217. else
  218. {
  219. goto ErrExit ;
  220. }
  221. return (retCode) ;
  222. }
  223. //=============================//
  224. // Report File? //
  225. //=============================//
  226. if (strsame (FileHeader.szSignature, szPerfReportSignature))
  227. {
  228. retCode = OpenReport (hWndReport,
  229. hFile,
  230. FileHeader.dwMajorVersion,
  231. FileHeader.dwMinorVersion,
  232. TRUE) ;
  233. if (retCode)
  234. {
  235. ChangeSaveFileName (pFileName, IDM_VIEWREPORT) ;
  236. }
  237. else
  238. {
  239. goto ErrExit ;
  240. }
  241. return (retCode) ;
  242. }
  243. //=============================//
  244. // Workspace File? //
  245. //=============================//
  246. if (strsame (FileHeader.szSignature, szPerfWorkspaceSignature))
  247. {
  248. retCode = OpenWorkspace (hFile,
  249. FileHeader.dwMajorVersion,
  250. FileHeader.dwMinorVersion) ;
  251. if (retCode)
  252. {
  253. ChangeSaveFileName (pFileName, IDM_WORKSPACE) ;
  254. return (TRUE) ;
  255. }
  256. else
  257. {
  258. goto ErrExit ;
  259. }
  260. }
  261. #endif
  262. //=============================//
  263. // Unknown file type //
  264. //=============================//
  265. CloseHandle (hFile) ;
  266. ErrExit:
  267. DlgErrorBox (hWndParent, ERR_BAD_SETTING_FILE, pFileName) ;
  268. return (FALSE) ;
  269. } // FileOpen
  270. BOOL FileGetName (HWND hWndParent, int nStringResourceID, LPTSTR lpFileName)
  271. {
  272. OPENFILENAME ofn ;
  273. TCHAR szFileSpec [FilePathLen] ;
  274. TCHAR szFileTitle [FilePathLen] ;
  275. TCHAR szDialogTitle [FilePathLen] ;
  276. TCHAR aszOpenFilter[LongTextLen] ;
  277. TCHAR aszDefaultExt[FileExtLen];
  278. int StringLength ;
  279. int nExportExtId = 0;
  280. aszOpenFilter[0] = 0;
  281. if (lpFileName)
  282. {
  283. if (nStringResourceID != IDS_EXPORTFILE)
  284. {
  285. // get the file extension strings
  286. LoadString (hInstance, nStringResourceID,
  287. aszOpenFilter,
  288. sizeof(aszOpenFilter) / sizeof(TCHAR) ) ;
  289. StringLength = lstrlen (aszOpenFilter) + 1 ;
  290. LoadString (hInstance, nStringResourceID+1,
  291. &aszOpenFilter[StringLength],
  292. sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
  293. StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1 ;
  294. // get all file extension strings
  295. LoadString (hInstance, IDS_ALLFILES,
  296. &aszOpenFilter[StringLength],
  297. sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
  298. StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1 ;
  299. LoadString (hInstance, IDS_ALLFILESEXT,
  300. &aszOpenFilter[StringLength],
  301. sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
  302. }
  303. else
  304. {
  305. // get the Export file extension based on the current delimiter
  306. int FirstExtensionID, SecondExtensionID ;
  307. if (pDelimiter == TabStr)
  308. {
  309. FirstExtensionID = IDS_EXPORTFILETSV ;
  310. SecondExtensionID = IDS_EXPORTFILE ;
  311. nExportExtId = IDS_DEF_EXPORT_TSV;
  312. }
  313. else
  314. {
  315. FirstExtensionID = IDS_EXPORTFILE ;
  316. SecondExtensionID = IDS_EXPORTFILETSV ;
  317. nExportExtId = IDS_DEF_EXPORT_CSV;
  318. }
  319. LoadString (hInstance, FirstExtensionID,
  320. aszOpenFilter,
  321. sizeof(aszOpenFilter) / sizeof(TCHAR) ) ;
  322. StringLength = lstrlen (aszOpenFilter) + 1 ;
  323. LoadString (hInstance, FirstExtensionID+1,
  324. &aszOpenFilter[StringLength],
  325. sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
  326. StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1 ;
  327. // get all file extension strings
  328. LoadString (hInstance, SecondExtensionID,
  329. &aszOpenFilter[StringLength],
  330. sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
  331. StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1 ;
  332. LoadString (hInstance, SecondExtensionID+1,
  333. &aszOpenFilter[StringLength],
  334. sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
  335. }
  336. // setup the end strings
  337. StringLength += lstrlen (&aszOpenFilter[StringLength]) ;
  338. aszOpenFilter[StringLength+1] = aszOpenFilter[StringLength+2] = TEXT('\0') ;
  339. strclr (szFileSpec) ;
  340. strclr (szFileTitle) ;
  341. if (nStringResourceID == IDS_EXPORTFILE)
  342. {
  343. dwCurrentDlgID = HC_PM_idDlgFileExport ;
  344. StringLoad (IDS_EXPORTAS_TITLE, szDialogTitle) ;
  345. }
  346. else if (nStringResourceID == IDS_WORKSPACEFILE)
  347. {
  348. dwCurrentDlgID = HC_PM_idDlgFileSaveWorkSpace ;
  349. StringLoad (IDS_SAVEASW_TITLE, szDialogTitle) ;
  350. }
  351. else
  352. {
  353. dwCurrentDlgID = HC_PM_idDlgFileSaveAs ;
  354. StringLoad (IDS_SAVEAS_TITLE, szDialogTitle) ;
  355. }
  356. memset (&ofn, 0, sizeof(OPENFILENAME)) ;
  357. ofn.lStructSize = sizeof(OPENFILENAME) ;
  358. ofn.hwndOwner = hWndParent ;
  359. ofn.hInstance = hInstance;
  360. ofn.lpstrTitle = szDialogTitle ;
  361. ofn.lpstrFilter = aszOpenFilter ;
  362. ofn.nFilterIndex = 1L ;
  363. ofn.lpstrFile = szFileSpec;
  364. ofn.nMaxFile = sizeof(szFileSpec);
  365. ofn.lpstrFileTitle = szFileTitle;
  366. ofn.nMaxFileTitle = sizeof(szFileTitle);
  367. if (nStringResourceID == IDS_EXPORTFILE)
  368. {
  369. // get default file extension
  370. if (LoadString (hInstance, nExportExtId,
  371. aszDefaultExt,
  372. sizeof(aszDefaultExt) / sizeof(TCHAR)) > 0) {
  373. ofn.lpstrDefExt = aszDefaultExt;
  374. } else {
  375. ofn.lpstrDefExt = NULL; // no default extenstion
  376. }
  377. ofn.Flags = ExportOptionsOFNStyle ;
  378. ofn.lpfnHook = (LPOFNHOOKPROC) ExportOptionsHookProc ;
  379. ofn.lpTemplateName = idDlgExportOptions ;
  380. }
  381. else
  382. {
  383. // get default file extension
  384. if (LoadString (hInstance, nStringResourceID+2,
  385. aszDefaultExt,
  386. sizeof(aszDefaultExt) / sizeof(TCHAR)) > 0) {
  387. ofn.lpstrDefExt = aszDefaultExt;
  388. } else {
  389. ofn.lpstrDefExt = NULL; // no default extenstion
  390. }
  391. ofn.Flags = OptionsOFNStyle ;
  392. ofn.lpfnHook = (LPOFNHOOKPROC) FileOpenHookProc ;
  393. }
  394. if (!GetSaveFileName(&ofn))
  395. {
  396. dwCurrentDlgID = 0 ;
  397. return (FALSE) ;
  398. }
  399. dwCurrentDlgID = 0 ;
  400. }
  401. else
  402. {
  403. return (FALSE) ;
  404. }
  405. lstrcpy (lpFileName, ofn.lpstrFile) ;
  406. return (TRUE) ;
  407. } // FileGetName