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.

454 lines
13 KiB

  1. /****************************************************************************\
  2. SCREENS.C / OPK Wizard (OPKWIZ.EXE)
  3. Microsoft Confidential
  4. Copyright (c) Microsoft Corporation 1998
  5. All rights reserved
  6. Source file for the OPK Wizard that contains the external and internal
  7. functions used by the "screens" wizard page.
  8. 3/99 - Jason Cohen (JCOHEN)
  9. Updated this old source file for the OPK Wizard as part of the OOBE
  10. update. This file was totally re-written.
  11. 5/99 - Jason Cohen (JCOHEN)
  12. Got rid of the global variables and cleaned up the code some more.
  13. 09/2000 - Stephen Lodwick (STELO)
  14. Ported OPK Wizard to Whistler
  15. 02/2000 - Jason Cohen (JCOHEN)
  16. Added back in the mouse stuff since the OOBE guys now decided that
  17. the still need it.
  18. \****************************************************************************/
  19. //
  20. // Include File(s):
  21. //
  22. #include "pch.h"
  23. #include "wizard.h"
  24. #include "resource.h"
  25. //
  26. // Internal Defined Value(s):
  27. //
  28. #define FILE_MOUSE_HTM _T("MOUSE.HTM")
  29. #define FILE_IME_HTM _T("IMETUT1.HTM")
  30. #define DIR_MOUSE DIR_OEM_OOBE _T("\\HTML\\Mouse")
  31. #define DIR_IME DIR_OEM_OOBE _T("\\HTML\\IME")
  32. //
  33. // Internal Function Prototype(s):
  34. //
  35. static BOOL OnInit(HWND, HWND, LPARAM);
  36. static void OnCommand(HWND, INT, HWND, UINT);
  37. static BOOL OnNext(HWND hwnd);
  38. static void EnableControls(HWND, UINT);
  39. static BOOL BrowseCopy(HWND hwnd, LPTSTR lpszPath, INT id, BOOL bBatch);
  40. //
  41. // External Function(s):
  42. //
  43. LRESULT CALLBACK ScreensDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  44. {
  45. switch (uMsg)
  46. {
  47. HANDLE_MSG(hwnd, WM_INITDIALOG, OnInit);
  48. HANDLE_MSG(hwnd, WM_COMMAND, OnCommand);
  49. case WM_NOTIFY:
  50. switch ( ((NMHDR FAR *) lParam)->code )
  51. {
  52. case PSN_KILLACTIVE:
  53. case PSN_RESET:
  54. case PSN_WIZBACK:
  55. case PSN_WIZFINISH:
  56. break;
  57. case PSN_WIZNEXT:
  58. if ( !OnNext(hwnd) )
  59. WIZ_FAIL(hwnd);
  60. break;
  61. case PSN_QUERYCANCEL:
  62. WIZ_CANCEL(hwnd);
  63. break;
  64. case PSN_SETACTIVE:
  65. g_App.dwCurrentHelp = IDH_SCREENS;
  66. WIZ_BUTTONS(hwnd, PSWIZB_BACK | PSWIZB_NEXT);
  67. // Press next if the user is in auto mode
  68. //
  69. WIZ_NEXTONAUTO(hwnd, PSBTN_NEXT);
  70. break;
  71. case PSN_HELP:
  72. WIZ_HELP();
  73. break;
  74. default:
  75. return FALSE;
  76. }
  77. break;
  78. default:
  79. return FALSE;
  80. }
  81. return TRUE;
  82. }
  83. //
  84. // Internal Function(s):
  85. //
  86. static BOOL OnInit(HWND hwnd, HWND hwndFocus, LPARAM lParam)
  87. {
  88. TCHAR szCustDir[MAX_PATH] = NULLSTR,
  89. szCustomIMEDir[MAX_PATH] = NULLSTR;
  90. DWORD dwUseIMETutorial;
  91. //
  92. // Mouse tutorial:
  93. //
  94. // Check if mouse tutor is in use!
  95. //
  96. if ( GetPrivateProfileInt(INI_SEC_OPTIONS, INI_KEY_MOUSE, 0, GET_FLAG(OPK_BATCHMODE) ? g_App.szOpkWizIniFile : g_App.szOobeInfoIniFile) == 2 )
  97. {
  98. // 2 is a custom mouse tutorial, need to get the custom
  99. // dir.
  100. //
  101. CheckRadioButton(hwnd, IDC_MOUSE_NO, IDC_MOUSE_CUSTOM, IDC_MOUSE_CUSTOM);
  102. GetPrivateProfileString(INI_SEC_OPTIONS, INI_KEY_CUSTMOUSE, NULLSTR, szCustDir, AS(szCustDir), g_App.szOpkWizIniFile);
  103. // Must simulate a copy if this is batch mode.
  104. //
  105. if ( GET_FLAG(OPK_BATCHMODE) )
  106. BrowseCopy(hwnd, szCustDir, IDC_MOUSE_BROWSE, TRUE);
  107. }
  108. else
  109. {
  110. // 0, or default is no mouse tutorial.
  111. //
  112. CheckRadioButton(hwnd, IDC_MOUSE_NO, IDC_MOUSE_CUSTOM, IDC_MOUSE_NO);
  113. }
  114. // Now init the mouse tutorial fields.
  115. //
  116. SetDlgItemText(hwnd, IDC_MOUSE_DIR, szCustDir);
  117. EnableControls(hwnd, IDC_MOUSE_CUSTOM);
  118. //
  119. // IME TUTORIAL
  120. //
  121. // Do we display the tutorial
  122. //
  123. if ( !GET_FLAG(OPK_DBCS) )
  124. {
  125. // Check the default radio button for Non-DBCS builds
  126. //
  127. CheckRadioButton(hwnd, IDC_IME_NO, IDC_IME_CUSTOM, IDC_IME_NO);
  128. // Hide the options is not DBCS
  129. //
  130. ShowEnableWindow(GetDlgItem(hwnd, IDC_IME_NO), FALSE);
  131. ShowEnableWindow(GetDlgItem(hwnd, IDC_IME_CUSTOM), FALSE);
  132. ShowEnableWindow(GetDlgItem(hwnd, IDC_STATIC_IME), FALSE);
  133. ShowEnableWindow(GetDlgItem(hwnd, IDC_IME_DIR), FALSE);
  134. ShowEnableWindow(GetDlgItem(hwnd, IDC_IME_BROWSE), FALSE);
  135. }
  136. else
  137. {
  138. // Get the custom directory from the opkwiz.inf
  139. //
  140. GetPrivateProfileString(INI_SEC_OPTIONS, INI_KEY_IMECUSTDIR, NULLSTR, szCustomIMEDir, AS(szCustomIMEDir), g_App.szOpkWizIniFile);
  141. // See if we are going to use the tutorial
  142. //
  143. dwUseIMETutorial = GetPrivateProfileInt(INI_SEC_OPTIONS, INI_KEY_IMETUT, 0, GET_FLAG(OPK_BATCHMODE) ? g_App. szOpkWizIniFile : g_App.szOobeInfoIniFile);
  144. // Select the proper IME Tutorial
  145. //
  146. if ( szCustomIMEDir[0] && dwUseIMETutorial )
  147. {
  148. CheckRadioButton(hwnd, IDC_IME_NO, IDC_IME_CUSTOM, IDC_IME_CUSTOM);
  149. // Must simulate a copy if this is batch mode.
  150. //
  151. if ( GET_FLAG(OPK_BATCHMODE) )
  152. BrowseCopy(hwnd, szCustDir, IDC_IME_BROWSE, TRUE);
  153. }
  154. else
  155. CheckRadioButton(hwnd, IDC_IME_NO, IDC_IME_CUSTOM, IDC_IME_NO);
  156. SetDlgItemText(hwnd, IDC_IME_DIR, szCustomIMEDir);
  157. EnableControls(hwnd, IDC_IME_CUSTOM);
  158. }
  159. // Always return false to WM_INITDIALOG.
  160. //
  161. return FALSE;
  162. }
  163. static void OnCommand(HWND hwnd, INT id, HWND hwndCtl, UINT codeNotify)
  164. {
  165. TCHAR szPath[MAX_PATH];
  166. switch ( id )
  167. {
  168. case IDC_MOUSE_NO:
  169. case IDC_MOUSE_CUSTOM:
  170. case IDC_IME_NO:
  171. case IDC_IME_CUSTOM:
  172. EnableControls(hwnd, id);
  173. break;
  174. case IDC_MOUSE_BROWSE:
  175. case IDC_IME_BROWSE:
  176. // Try to use their current folder as the default.
  177. //
  178. szPath[0] = NULLCHR;
  179. GetDlgItemText(hwnd, ( id == IDC_MOUSE_BROWSE ) ? IDC_MOUSE_DIR : IDC_IME_DIR, szPath, AS(szPath));
  180. // If there is no current folder, just use the global browse default.
  181. //
  182. if ( szPath[0] == NULLCHR )
  183. lstrcpyn(szPath, g_App.szBrowseFolder,AS(szPath));
  184. // Now bring up the browse for folder dialog.
  185. //
  186. if ( BrowseForFolder(hwnd, IDS_BROWSEFOLDER, szPath, BIF_RETURNONLYFSDIRS | BIF_EDITBOX | BIF_VALIDATE) )
  187. BrowseCopy(hwnd, szPath, id, FALSE);
  188. break;
  189. }
  190. }
  191. static BOOL OnNext(HWND hwnd)
  192. {
  193. TCHAR szFullPath[MAX_PATH],
  194. szImeDir[MAX_PATH] = NULLSTR,
  195. szMouseDir[MAX_PATH] = NULLSTR;
  196. LPTSTR lpMouseOption;
  197. //
  198. // Verify the mouse tutorial settings.
  199. //
  200. // Create the path to the directory that needs to be removed, or
  201. // must exist depending on the option selected.
  202. //
  203. lstrcpyn(szFullPath, g_App.szTempDir,AS(szFullPath));
  204. AddPathN(szFullPath, DIR_MOUSE,AS(szFullPath));
  205. // If we are doing a custom mouse tutorial, check for a valid directory.
  206. // Otherwise, setup the correct values to write to the config files.
  207. //
  208. if ( IsDlgButtonChecked(hwnd, IDC_MOUSE_CUSTOM) == BST_CHECKED )
  209. {
  210. // Make sure we have a valid directory.
  211. //
  212. GetDlgItemText(hwnd, IDC_MOUSE_DIR, szMouseDir, AS(szMouseDir));
  213. if ( !( szMouseDir[0] && DirectoryExists(szFullPath) ) )
  214. {
  215. MsgBox(GetParent(hwnd), IDS_ERR_MOUSEDIR, IDS_APPNAME, MB_ERRORBOX);
  216. SetFocus(GetDlgItem(hwnd, IDC_MOUSE_BROWSE));
  217. return FALSE;
  218. }
  219. // This is what we write out to the oobeinfo and batch file.
  220. //
  221. lpMouseOption = STR_2;
  222. }
  223. else
  224. {
  225. // This is what we write out to the oobeinfo and batch file.
  226. //
  227. lpMouseOption = STR_0;
  228. // Remove the custom files that might already be there.
  229. //
  230. if ( DirectoryExists(szFullPath) )
  231. DeletePath(szFullPath);
  232. // Clear out the display box(es) so we know the files are
  233. // all gone now.
  234. //
  235. SetDlgItemText(hwnd, IDC_MOUSE_DIR, NULLSTR);
  236. }
  237. //
  238. // Verify the IME tutorial settings.
  239. //
  240. // Create the path to the directory that needs to be removed, or
  241. // must exist depending on the option selected.
  242. //
  243. lstrcpyn(szFullPath, g_App.szTempDir,AS(szFullPath));
  244. AddPathN(szFullPath, DIR_IME,AS(szFullPath));
  245. // If we are doing a custom IME tutorial, check for a valid directory.
  246. //
  247. if ( ( GET_FLAG(OPK_DBCS) ) &&
  248. ( IsDlgButtonChecked(hwnd, IDC_IME_CUSTOM) == BST_CHECKED ) )
  249. {
  250. // Make sure we have a valid directory.
  251. //
  252. GetDlgItemText(hwnd, IDC_IME_DIR, szImeDir, AS(szImeDir));
  253. if ( !( szImeDir[0] && DirectoryExists(szFullPath) ) )
  254. {
  255. MsgBox(GetParent(hwnd), IDS_ERR_IMEDIR, IDS_APPNAME, MB_ERRORBOX);
  256. SetFocus(GetDlgItem(hwnd, IDC_IME_BROWSE));
  257. return FALSE;
  258. }
  259. }
  260. else
  261. {
  262. // Remove the files that might be there.
  263. //
  264. if ( DirectoryExists(szFullPath) )
  265. DeletePath(szFullPath);
  266. // Clear out the display box(es) so we know the files are
  267. // all gone now.
  268. //
  269. SetDlgItemText(hwnd, IDC_IME_DIR, NULLSTR);
  270. }
  271. //
  272. // Save the mouse tutorial settings:
  273. //
  274. // Write the custom mouse path.
  275. //
  276. WritePrivateProfileString(INI_SEC_OPTIONS, INI_KEY_CUSTMOUSE, szMouseDir[0] ? szMouseDir : NULL, g_App.szOpkWizIniFile);
  277. // Write the data back to the config files.
  278. //
  279. WritePrivateProfileString(INI_SEC_OPTIONS, INI_KEY_MOUSE, lpMouseOption, g_App.szOobeInfoIniFile);
  280. WritePrivateProfileString(INI_SEC_OPTIONS, INI_KEY_MOUSE, lpMouseOption, g_App.szOpkWizIniFile);
  281. //
  282. // Save the IME tutorial settings:
  283. //
  284. // If the IME tutorial should not be used, then write out STR_ZERO
  285. //
  286. WritePrivateProfileString(INI_SEC_OPTIONS, INI_KEY_IMETUT, szImeDir[0] ? STR_1 : STR_0, g_App.szOobeInfoIniFile);
  287. WritePrivateProfileString(INI_SEC_OPTIONS, INI_KEY_IMETUT, szImeDir[0] ? STR_1 : STR_0, g_App.szOpkWizIniFile);
  288. // Write out the IME tutorial custom directory if it's being used
  289. //
  290. WritePrivateProfileString(INI_SEC_OPTIONS, INI_KEY_IMECUSTDIR, szImeDir[0] ? szImeDir : NULL, g_App.szOpkWizIniFile);
  291. // Always return TRUE if we got this far.
  292. //
  293. return TRUE;
  294. }
  295. static void EnableControls(HWND hwnd, UINT uId)
  296. {
  297. BOOL fEnable;
  298. switch ( uId )
  299. {
  300. case IDC_MOUSE_NO:
  301. case IDC_MOUSE_CUSTOM:
  302. fEnable = ( IsDlgButtonChecked(hwnd, IDC_MOUSE_CUSTOM) == BST_CHECKED );
  303. EnableWindow(GetDlgItem(hwnd, IDC_STATIC_MOUSE), fEnable);
  304. EnableWindow(GetDlgItem(hwnd, IDC_MOUSE_DIR), fEnable);
  305. EnableWindow(GetDlgItem(hwnd, IDC_MOUSE_BROWSE), fEnable);
  306. break;
  307. case IDC_IME_NO:
  308. case IDC_IME_CUSTOM:
  309. fEnable = ( IsDlgButtonChecked(hwnd, IDC_IME_CUSTOM) == BST_CHECKED );
  310. EnableWindow(GetDlgItem(hwnd, IDC_STATIC_IME), fEnable);
  311. EnableWindow(GetDlgItem(hwnd, IDC_IME_DIR), fEnable);
  312. EnableWindow(GetDlgItem(hwnd, IDC_IME_BROWSE), fEnable);
  313. break;
  314. }
  315. }
  316. static BOOL BrowseCopy(HWND hwnd, LPTSTR lpszPath, INT id, BOOL bBatch)
  317. {
  318. BOOL bRet = FALSE;
  319. TCHAR szDst[MAX_PATH];
  320. LPTSTR lpEnd,
  321. lpFilename;
  322. // If the pressed OK, save off the path in our last browse folder buffer.
  323. //
  324. if ( !bBatch )
  325. lstrcpyn(g_App.szBrowseFolder, lpszPath, AS(g_App.szBrowseFolder));
  326. // We need to create the path to the destination directory where
  327. // we are going to copy all the files.
  328. //
  329. lstrcpyn(szDst, g_App.szTempDir,AS(szDst));
  330. AddPathN(szDst, ( id == IDC_MOUSE_BROWSE ) ? DIR_MOUSE : DIR_IME,AS(szDst));
  331. // Check for required file.
  332. //
  333. lpEnd = lpszPath + lstrlen(lpszPath);
  334. lpFilename = ( id == IDC_MOUSE_BROWSE ) ? FILE_MOUSE_HTM : FILE_IME_HTM;
  335. AddPath(lpszPath, lpFilename);
  336. if ( ( bBatch ) ||
  337. ( FileExists(lpszPath) ) ||
  338. ( MsgBox(GetParent(hwnd), ( id == IDC_MOUSE_BROWSE ) ? IDS_ERR_MOUSEFILES : IDS_ERR_IMEFILES, IDS_APPNAME, MB_ICONSTOP | MB_OKCANCEL | MB_APPLMODAL, lpFilename) == IDOK ) )
  339. {
  340. // Chop that file name off so we just have the path again.
  341. //
  342. *lpEnd = NULLCHR;
  343. // Make sure that any exsisting files are removed.
  344. //
  345. if ( DirectoryExists(szDst) )
  346. DeletePath(szDst);
  347. // Now try to copy all the new files over.
  348. //
  349. if ( !CopyDirectoryDialog(g_App.hInstance, hwnd, lpszPath, szDst) )
  350. {
  351. DeletePath(szDst);
  352. MsgBox(GetParent(hwnd), IDS_ERR_COPYINGFILES, IDS_APPNAME, MB_ERRORBOX, szDst[0], lpszPath);
  353. *lpszPath = NULLCHR;
  354. }
  355. else
  356. bRet = TRUE;
  357. // Reset the path display boxes.
  358. //
  359. SetDlgItemText(hwnd, ( id == IDC_MOUSE_BROWSE ) ? IDC_MOUSE_DIR : IDC_IME_DIR, lpszPath);
  360. }
  361. return bRet;
  362. }