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.

276 lines
7.9 KiB

  1. #include "setedit.h"
  2. #include "cderr.h"
  3. #include "fileutil.h" // for FileOpen, FileRead
  4. #include "grafdata.h" // for OpenChart
  5. #include "utils.h" // for strempty
  6. #include "perfmops.h" // for OpenWorkspace
  7. #include "pmhelpid.h" // Help IDs
  8. #include <dlgs.h> // for pshHelp
  9. #define OptionsOFNStyle \
  10. (OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ENABLEHOOK)
  11. BOOL APIENTRY FileOpenHookProc (HWND hDlg,
  12. UINT iMessage,
  13. WPARAM wParam,
  14. LPARAM lParam)
  15. {
  16. BOOL bHandled = FALSE ;
  17. // only intercept the Help button and bring up our WinHelp data
  18. if (iMessage == WM_COMMAND && wParam == pshHelp)
  19. {
  20. // CallWinHelp (dwCurrentDlgID) ;
  21. bHandled = TRUE ;
  22. }
  23. else if (iMessage == WM_INITDIALOG)
  24. {
  25. WindowCenter (hDlg) ;
  26. bHandled = TRUE ;
  27. }
  28. return (bHandled) ;
  29. }
  30. BOOL FileOpen (HWND hWndParent, int nStringResourceID, LPTSTR lpInputFileName)
  31. {
  32. OPENFILENAME ofn ;
  33. TCHAR szFileSpec [256] ;
  34. TCHAR szFileTitle [80] ;
  35. TCHAR szDialogTitle [80] ;
  36. HANDLE hFile ;
  37. PERFFILEHEADER FileHeader ;
  38. TCHAR aszOpenFilter[LongTextLen] ;
  39. int StringLength ;
  40. BOOL retCode ;
  41. LPTSTR pFileName = NULL ;
  42. BOOL bNoFile = FALSE;
  43. if (lpInputFileName == NULL) {
  44. bNoFile = TRUE;
  45. }
  46. else if (strempty(lpInputFileName)) {
  47. bNoFile = TRUE;
  48. }
  49. aszOpenFilter[0] = 0;
  50. if (bNoFile)
  51. {
  52. dwCurrentDlgID = HC_PM_idDlgFileOpen ;
  53. // get the file extension strings
  54. LoadString (hInstance, nStringResourceID, aszOpenFilter,
  55. sizeof(aszOpenFilter) / sizeof(TCHAR)) ;
  56. StringLength = lstrlen (aszOpenFilter) + 1 ;
  57. LoadString (hInstance, nStringResourceID+1,
  58. &aszOpenFilter[StringLength],
  59. sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
  60. StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1 ;
  61. #ifdef ADVANCED_PERFMON
  62. // get workspace file extension strings
  63. LoadString (hInstance, IDS_WORKSPACEFILE,
  64. &aszOpenFilter[StringLength],
  65. sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
  66. StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1 ;
  67. LoadString (hInstance, IDS_WORKSPACEFILEEXT,
  68. &aszOpenFilter[StringLength],
  69. sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
  70. StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1;
  71. #endif
  72. // get all file extension strings
  73. LoadString (hInstance, IDS_ALLFILES,
  74. &aszOpenFilter[StringLength],
  75. sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
  76. StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1 ;
  77. LoadString (hInstance, IDS_ALLFILESEXT,
  78. &aszOpenFilter[StringLength],
  79. sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
  80. StringLength += lstrlen (&aszOpenFilter[StringLength]) ;
  81. // setup the end strings
  82. aszOpenFilter[StringLength+1] = aszOpenFilter[StringLength+2] = TEXT('\0') ;
  83. strclr (szFileSpec) ;
  84. strclr (szFileTitle) ;
  85. StringLoad (IDS_FILEOPEN_TITLE, szDialogTitle) ;
  86. memset (&ofn, 0, sizeof(OPENFILENAME)) ;
  87. ofn.lStructSize = sizeof(OPENFILENAME) ;
  88. ofn.hwndOwner = hWndParent ;
  89. ofn.hInstance = hInstance;
  90. ofn.lpstrTitle = szDialogTitle ;
  91. ofn.lpstrFilter = aszOpenFilter ;
  92. ofn.nFilterIndex = 1L ;
  93. ofn.lpstrFile = szFileSpec;
  94. ofn.nMaxFile = sizeof(szFileSpec);
  95. ofn.lpstrFileTitle = szFileTitle;
  96. ofn.nMaxFileTitle = sizeof(szFileTitle);
  97. ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_ENABLEHOOK ;
  98. ofn.lpfnHook = (LPOFNHOOKPROC) FileOpenHookProc ;
  99. if (!GetOpenFileName(&ofn))
  100. {
  101. dwCurrentDlgID = 0 ;
  102. return (FALSE) ;
  103. }
  104. dwCurrentDlgID = 0 ;
  105. hFile = FileHandleOpen (szFileSpec) ;
  106. pFileName = szFileSpec ;
  107. } // NULL lpFileName
  108. else
  109. {
  110. // open the input file
  111. hFile = FileHandleOpen (lpInputFileName) ;
  112. if (hFile && hFile != INVALID_HANDLE_VALUE &&
  113. SearchPath (NULL, lpInputFileName, NULL,
  114. sizeof(szFileSpec)/sizeof(TCHAR) - 1,
  115. szFileSpec, &pFileName))
  116. {
  117. pFileName = szFileSpec ;
  118. }
  119. else
  120. {
  121. pFileName = NULL ;
  122. }
  123. }
  124. if (!hFile || hFile == INVALID_HANDLE_VALUE)
  125. {
  126. return (FALSE) ;
  127. }
  128. if (!FileRead (hFile, &FileHeader, sizeof (FileHeader)))
  129. {
  130. CloseHandle (hFile) ;
  131. if (strempty(lpInputFileName))
  132. {
  133. DlgErrorBox (hWndParent, ERR_BAD_SETTING_FILE, pFileName) ;
  134. }
  135. return (FALSE) ;
  136. }
  137. //=============================//
  138. // Chart File? //
  139. //=============================//
  140. if (strsame (FileHeader.szSignature, szPerfChartSignature))
  141. {
  142. retCode = OpenChart (hWndGraph,
  143. hFile,
  144. FileHeader.dwMajorVersion,
  145. FileHeader.dwMinorVersion,
  146. TRUE) ;
  147. if (retCode)
  148. {
  149. ChangeSaveFileName (pFileName, IDM_VIEWCHART) ;
  150. }
  151. else
  152. {
  153. goto ErrExit ;
  154. }
  155. return (retCode) ;
  156. }
  157. //=============================//
  158. // Unknown file type //
  159. //=============================//
  160. CloseHandle (hFile) ;
  161. ErrExit:
  162. DlgErrorBox (hWndParent, ERR_BAD_SETTING_FILE, pFileName) ;
  163. return (FALSE) ;
  164. } // FileOpen
  165. BOOL FileGetName (HWND hWndParent, int nStringResourceID, LPTSTR lpFileName)
  166. {
  167. OPENFILENAME ofn ;
  168. TCHAR szFileSpec [256] ;
  169. TCHAR szFileTitle [80] ;
  170. TCHAR szDialogTitle [80] ;
  171. TCHAR aszOpenFilter[LongTextLen] ;
  172. int StringLength = 0;
  173. if (lpFileName)
  174. {
  175. if (nStringResourceID != IDS_EXPORTFILE)
  176. {
  177. // get the file extension strings
  178. LoadString (hInstance, nStringResourceID,
  179. aszOpenFilter,
  180. sizeof(aszOpenFilter) / sizeof(TCHAR) ) ;
  181. StringLength = lstrlen (aszOpenFilter) + 1 ;
  182. LoadString (hInstance, nStringResourceID+1,
  183. &aszOpenFilter[StringLength],
  184. sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
  185. StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1 ;
  186. // get all file extension strings
  187. LoadString (hInstance, IDS_ALLFILES,
  188. &aszOpenFilter[StringLength],
  189. sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
  190. StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1 ;
  191. LoadString (hInstance, IDS_ALLFILESEXT,
  192. &aszOpenFilter[StringLength],
  193. sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
  194. }
  195. // setup the end strings
  196. StringLength += lstrlen (&aszOpenFilter[StringLength]) ;
  197. aszOpenFilter[StringLength+1] = aszOpenFilter[StringLength+2] = TEXT('\0') ;
  198. strclr (szFileSpec) ;
  199. strclr (szFileTitle) ;
  200. dwCurrentDlgID = HC_PM_idDlgFileSaveAs ;
  201. StringLoad (IDS_SAVEAS_TITLE, szDialogTitle) ;
  202. memset (&ofn, 0, sizeof(OPENFILENAME)) ;
  203. ofn.lStructSize = sizeof(OPENFILENAME) ;
  204. ofn.hwndOwner = hWndParent ;
  205. ofn.hInstance = hInstance;
  206. ofn.lpstrTitle = szDialogTitle ;
  207. ofn.lpstrFilter = aszOpenFilter ;
  208. ofn.nFilterIndex = 1L ;
  209. ofn.lpstrFile = szFileSpec;
  210. ofn.nMaxFile = sizeof(szFileSpec);
  211. ofn.lpstrFileTitle = szFileTitle;
  212. ofn.nMaxFileTitle = sizeof(szFileTitle);
  213. ofn.Flags = OptionsOFNStyle ;
  214. ofn.lpfnHook = (LPOFNHOOKPROC) FileOpenHookProc ;
  215. if (!GetSaveFileName(&ofn))
  216. {
  217. dwCurrentDlgID = 0 ;
  218. return (FALSE) ;
  219. }
  220. dwCurrentDlgID = 0 ;
  221. }
  222. else
  223. {
  224. return (FALSE) ;
  225. }
  226. lstrcpy (lpFileName, ofn.lpstrFile) ;
  227. return (TRUE) ;
  228. } // FileGetName