Leaked source code of windows server 2003
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.

408 lines
13 KiB

  1. /****************************************************************************\
  2. HELPCENT.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 "helpcenter" wizard page.
  8. 12/99 - Stephen Lodwick (STELO)
  9. Added this page
  10. \****************************************************************************/
  11. //
  12. // Include File(s):
  13. //
  14. #include "pch.h"
  15. #include "wizard.h"
  16. #include "resource.h"
  17. //
  18. // Internal Defined Value(s):
  19. //
  20. #define REG_HCUPDATE_OEM _T(";HKLM, \"Software\\Microsoft\\Windows\\CurrentVersion\\OEMRunOnce\", \"01_PC Health OEM Signature\",, \"START /M C:\\WINDOWS\\OPTIONS\\CABS\\HCU.VBS C:\\WINDOWS\\OPTIONS\\CABS\\PCH_OEM.CAB\"")
  21. #define REG_HCUPDATE_HELP_CENTER _T("HKLM, \"Software\\Microsoft\\Windows\\CurrentVersion\\OEMRunOnce\", \"02_PC Health Help Center\",, \"START /M C:\\WINDOWS\\OPTIONS\\CABS\\HCU.VBS C:\\WINDOWS\\OPTIONS\\CABS\\%s\"")
  22. #define REG_HCUPDATE_SUPPORT _T("HKLM, \"Software\\Microsoft\\Windows\\CurrentVersion\\OEMRunOnce\", \"03_PC Health Support\",, \"START /M C:\\WINDOWS\\OPTIONS\\CABS\\HCU.VBS C:\\WINDOWS\\OPTIONS\\CABS\\%s\"")
  23. #define REG_HCUPDATE_BRANDING _T("HKLM, \"Software\\Microsoft\\Windows\\CurrentVersion\\OEMRunOnce\", \"04_PC Health Branding\",, \"START /M C:\\WINDOWS\\OPTIONS\\CABS\\HCU.VBS C:\\WINDOWS\\OPTIONS\\CABS\\%s\"")
  24. #define INF_SEC_HELPCENTER_ADDREG _T("HelpCenter.AddReg")
  25. //
  26. // Internal Function Prototype(s):
  27. //
  28. static BOOL OnInit(HWND, HWND, LPARAM);
  29. static void OnCommand(HWND, INT, HWND, UINT);
  30. static BOOL ValidData(HWND);
  31. static void SaveData(HWND);
  32. static void EnableControls(HWND, UINT);
  33. //
  34. // External Function(s):
  35. //
  36. LRESULT CALLBACK HelpCenterDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  37. {
  38. switch (uMsg)
  39. {
  40. HANDLE_MSG(hwnd, WM_INITDIALOG, OnInit);
  41. HANDLE_MSG(hwnd, WM_COMMAND, OnCommand);
  42. case WM_NOTIFY:
  43. switch ( ((NMHDR FAR *) lParam)->code )
  44. {
  45. case PSN_KILLACTIVE:
  46. case PSN_RESET:
  47. case PSN_WIZBACK:
  48. case PSN_WIZFINISH:
  49. break;
  50. case PSN_WIZNEXT:
  51. if(ValidData(hwnd))
  52. SaveData(hwnd);
  53. else
  54. WIZ_FAIL(hwnd);
  55. break;
  56. case PSN_QUERYCANCEL:
  57. WIZ_CANCEL(hwnd);
  58. break;
  59. case PSN_SETACTIVE:
  60. g_App.dwCurrentHelp = IDH_HELPCENT;
  61. WIZ_BUTTONS(hwnd, PSWIZB_BACK | PSWIZB_NEXT);
  62. // Press next if the user is in auto mode
  63. //
  64. WIZ_NEXTONAUTO(hwnd, PSBTN_NEXT);
  65. break;
  66. case PSN_HELP:
  67. WIZ_HELP();
  68. break;
  69. default:
  70. return FALSE;
  71. }
  72. break;
  73. default:
  74. return FALSE;
  75. }
  76. return TRUE;
  77. }
  78. //
  79. // Internal Function(s):
  80. //
  81. static BOOL OnInit(HWND hwnd, HWND hwndFocus, LPARAM lParam)
  82. {
  83. TCHAR szData[MAX_PATH] = NULLSTR;
  84. // Get the string for Help Center customization
  85. //
  86. szData[0] = NULLCHR;
  87. GetPrivateProfileString(INI_SEC_OPTIONS, INI_KEY_HELP_CENTER, NULLSTR, szData, STRSIZE(szData), g_App.szOpkWizIniFile);
  88. // If the field exists, then check the hardware box and populate the directory
  89. //
  90. if (szData[0])
  91. {
  92. CheckDlgButton(hwnd, IDC_HELP_CHK, TRUE);
  93. SetDlgItemText(hwnd, IDC_HELP_DIR, szData);
  94. EnableControls(hwnd, IDC_HELP_CHK);
  95. }
  96. // Get the string for Support customization
  97. //
  98. szData[0] = NULLCHR;
  99. GetPrivateProfileString(INI_SEC_OPTIONS, INI_KEY_SUPPORT_CENTER, NULLSTR, szData, STRSIZE(szData), g_App.szOpkWizIniFile);
  100. // If the field exists, then check the hardware box and populate the directory
  101. //
  102. if (szData[0])
  103. {
  104. CheckDlgButton(hwnd, IDC_SUPPORT_CHK, TRUE);
  105. SetDlgItemText(hwnd, IDC_SUPPORT_DIR, szData);
  106. EnableControls(hwnd, IDC_SUPPORT_CHK);
  107. }
  108. // Get the string for Help Center co-branding
  109. //
  110. szData[0] = NULLCHR;
  111. GetPrivateProfileString(INI_SEC_OPTIONS, INI_KEY_HELP_BRANDING, NULLSTR, szData, STRSIZE(szData), g_App.szOpkWizIniFile);
  112. // If the field exists, then check the hardware box and populate the directory
  113. //
  114. if (szData[0])
  115. {
  116. CheckDlgButton(hwnd, IDC_BRANDING_CHK, TRUE);
  117. SetDlgItemText(hwnd, IDC_BRANDING_DIR, szData);
  118. EnableControls(hwnd, IDC_BRANDING_CHK);
  119. }
  120. // Always return false to WM_INITDIALOG.
  121. //
  122. return FALSE;
  123. }
  124. static void OnCommand(HWND hwnd, INT id, HWND hwndCtl, UINT codeNotify)
  125. {
  126. TCHAR szPath[MAX_PATH];
  127. switch ( id )
  128. {
  129. // Which browse button was pressed
  130. //
  131. case IDC_HELP_BROWSE:
  132. case IDC_SUPPORT_BROWSE:
  133. {
  134. szPath[0] = NULLCHR;
  135. GetDlgItemText(hwnd, ( id == IDC_HELP_BROWSE ) ? IDC_HELP_DIR : IDC_SUPPORT_DIR, szPath, STRSIZE(szPath));
  136. if ( BrowseForFile(hwnd, IDS_BROWSE, IDS_CABFILTER, IDS_CAB, szPath, STRSIZE(szPath), g_App.szOpkDir, 0) )
  137. SetDlgItemText(hwnd, ( id == IDC_HELP_BROWSE ) ? IDC_HELP_DIR : IDC_SUPPORT_DIR, szPath);
  138. }
  139. break;
  140. case IDC_BRANDING_BROWSE:
  141. {
  142. szPath[0] = NULLCHR;
  143. // Get the current directory, if any, in the directory control
  144. //
  145. GetDlgItemText(hwnd, IDC_BRANDING_DIR, szPath, STRSIZE(szPath));
  146. // Browse for the folder
  147. //
  148. if ( BrowseForFile(hwnd, IDS_BROWSE, IDS_CABFILTER, IDS_CAB, szPath, STRSIZE(szPath), g_App.szOpkDir, 0) )
  149. SetDlgItemText(hwnd, IDC_BRANDING_DIR, szPath);
  150. }
  151. break;
  152. case IDC_HELP_CHK:
  153. case IDC_SUPPORT_CHK:
  154. case IDC_BRANDING_CHK:
  155. // They checked one of the check boxes, enable/disable the appropriate controls
  156. //
  157. EnableControls(hwnd, id);
  158. break;
  159. }
  160. }
  161. static BOOL ValidData(HWND hwnd)
  162. {
  163. TCHAR szPath[MAX_PATH];
  164. // Let's check and make sure that the Help Center file is there
  165. //
  166. if ( IsDlgButtonChecked(hwnd, IDC_HELP_CHK) == BST_CHECKED )
  167. {
  168. // Check for a valid Help Center file
  169. //
  170. szPath[0] = NULLCHR;
  171. GetDlgItemText(hwnd, IDC_HELP_DIR, szPath, STRSIZE(szPath));
  172. if ( !FileExists(szPath) )
  173. {
  174. MsgBox(GetParent(hwnd), IDS_HELP_ERROR, IDS_APPNAME, MB_ERRORBOX);
  175. SetFocus(GetDlgItem(hwnd, IDC_HELP_DIR));
  176. return FALSE;
  177. }
  178. }
  179. // Let's check and make sure that the support file is there
  180. //
  181. if ( IsDlgButtonChecked(hwnd, IDC_SUPPORT_CHK) == BST_CHECKED )
  182. {
  183. // Check for a valid Support file
  184. //
  185. szPath[0] = NULLCHR;
  186. GetDlgItemText(hwnd, IDC_SUPPORT_DIR, szPath, STRSIZE(szPath));
  187. if ( !FileExists(szPath) )
  188. {
  189. MsgBox(GetParent(hwnd), IDS_SUPPORT_ERROR, IDS_APPNAME, MB_ERRORBOX);
  190. SetFocus(GetDlgItem(hwnd, IDC_SUPPORT_DIR));
  191. return FALSE;
  192. }
  193. }
  194. // Let's check and make sure that the branding directory is valid
  195. //
  196. if ( IsDlgButtonChecked(hwnd, IDC_BRANDING_CHK) == BST_CHECKED )
  197. {
  198. // Let's check to make sure the branding directory contains a specific .cab file
  199. // that we're looking for
  200. //
  201. szPath[0] = NULLCHR;
  202. GetDlgItemText(hwnd, IDC_BRANDING_DIR, szPath, STRSIZE(szPath));
  203. if ( !FileExists(szPath) )
  204. {
  205. MsgBox(GetParent(hwnd), IDS_BRANDING_ERROR, IDS_APPNAME, MB_ERRORBOX);
  206. SetFocus(GetDlgItem(hwnd, IDC_BRANDING_DIR));
  207. return FALSE;
  208. }
  209. }
  210. return TRUE;
  211. }
  212. static void SaveData(HWND hwnd)
  213. {
  214. TCHAR szPath[MAX_PATH] = NULLSTR,
  215. szFullPath[MAX_PATH] = NULLSTR,
  216. szRegEntry[MAX_PATH] = NULLSTR;
  217. LPTSTR lpIndex,
  218. lpSection,
  219. lpBuffer,
  220. lpRegEntry;
  221. DWORD dwIndex = 0,
  222. dwDir = 0,
  223. dwCheck = 0;
  224. BOOL bComment = TRUE;
  225. HRESULT hrPrintf;
  226. // Save the Help Center CAB file
  227. //
  228. szPath[0] = NULLCHR;
  229. GetDlgItemText(hwnd, IDC_HELP_DIR, szPath, STRSIZE(szPath));
  230. WritePrivateProfileString(INI_SEC_OPTIONS, INI_KEY_HELP_CENTER, ( IsDlgButtonChecked(hwnd, IDC_HELP_CHK) == BST_CHECKED ) ? szPath : NULL, g_App.szOpkWizIniFile);
  231. // Save the Support CAB file
  232. //
  233. szPath[0] = NULLCHR;
  234. GetDlgItemText(hwnd, IDC_SUPPORT_DIR, szPath, STRSIZE(szPath));
  235. WritePrivateProfileString(INI_SEC_OPTIONS, INI_KEY_SUPPORT_CENTER, ( IsDlgButtonChecked(hwnd, IDC_SUPPORT_CHK) == BST_CHECKED ) ? szPath : NULL, g_App.szOpkWizIniFile);
  236. // Save the Branding directory
  237. szPath[0] = NULLCHR;
  238. GetDlgItemText(hwnd, IDC_BRANDING_DIR, szPath, STRSIZE(szPath));
  239. WritePrivateProfileString(INI_SEC_OPTIONS, INI_KEY_HELP_BRANDING, ( IsDlgButtonChecked(hwnd, IDC_BRANDING_CHK) == BST_CHECKED ) ? szPath : NULL, g_App.szOpkWizIniFile);
  240. // Allocate memory necessary to store the OemRunOnce section
  241. //
  242. if ( (lpSection = MALLOC(MAX_SECTION * sizeof(TCHAR))) == NULL )
  243. {
  244. MsgBox(GetParent(hwnd), IDS_OUTOFMEM, IDS_APPNAME, MB_ERRORBOX);
  245. WIZ_EXIT(hwnd);
  246. return;
  247. }
  248. // Set the index of the section
  249. //
  250. lpIndex = lpSection;
  251. // We have three possible keys that we're going to write out - HELP CENTER, SUPPORT, and BRANDING
  252. //
  253. for (dwIndex = 0; dwIndex <= 2; dwIndex++)
  254. {
  255. switch ( dwIndex )
  256. {
  257. case 0:
  258. dwDir = IDC_HELP_DIR;
  259. dwCheck = IDC_HELP_CHK;
  260. lpRegEntry = REG_HCUPDATE_HELP_CENTER;
  261. break;
  262. case 1:
  263. dwDir = IDC_SUPPORT_DIR;
  264. dwCheck = IDC_SUPPORT_CHK;
  265. lpRegEntry = REG_HCUPDATE_SUPPORT;
  266. break;
  267. case 2:
  268. dwDir = IDC_BRANDING_DIR;
  269. dwCheck = IDC_BRANDING_CHK;
  270. lpRegEntry = REG_HCUPDATE_BRANDING;
  271. break;
  272. }
  273. szFullPath[0] = NULLCHR;
  274. // Get the text under the checkbox
  275. //
  276. GetDlgItemText(hwnd, dwDir, szFullPath, STRSIZE(szFullPath));
  277. // If the correct check box is checked and we can get the file name, then add a reg entry to the section
  278. //
  279. if ( (IsDlgButtonChecked(hwnd, dwCheck) == BST_CHECKED) &&
  280. (GetFullPathName(szFullPath, STRSIZE(szFullPath), szPath, &lpBuffer)) &&
  281. (lpBuffer) )
  282. {
  283. // Write the comment if we haven't yet.
  284. //
  285. if ( bComment )
  286. {
  287. lstrcpyn(lpIndex, REG_HCUPDATE_OEM, MAX_SECTION);
  288. lpIndex += lstrlen(lpIndex) + 1;
  289. bComment = FALSE;
  290. }
  291. hrPrintf=StringCchPrintf(lpIndex, (MAX_SECTION-(lpIndex-lpSection)), lpRegEntry, lpBuffer);
  292. lpIndex+= lstrlen(lpIndex);
  293. // Move past the NULL pointer
  294. //
  295. lpIndex++;
  296. }
  297. }
  298. // Add a second NULL pointer to end the section
  299. //
  300. *lpIndex = NULLCHR;
  301. WritePrivateProfileSection(INF_SEC_HELPCENTER_ADDREG, lpSection, g_App.szWinBomIniFile);
  302. // Clean up the allocated memory
  303. //
  304. FREE(lpSection);
  305. }
  306. static void EnableControls(HWND hwnd, UINT uId)
  307. {
  308. // Determine if the control is checked or not
  309. //
  310. BOOL fEnable = ( IsDlgButtonChecked(hwnd, uId) == BST_CHECKED );
  311. // Which control do we want to enable/disable
  312. //
  313. switch ( uId )
  314. {
  315. case IDC_HELP_CHK:
  316. EnableWindow(GetDlgItem(hwnd, IDC_HELP_CAPTION), fEnable);
  317. EnableWindow(GetDlgItem(hwnd, IDC_HELP_DIR), fEnable);
  318. EnableWindow(GetDlgItem(hwnd, IDC_HELP_BROWSE), fEnable);
  319. break;
  320. case IDC_SUPPORT_CHK:
  321. EnableWindow(GetDlgItem(hwnd, IDC_SUPPORT_CAPTION), fEnable);
  322. EnableWindow(GetDlgItem(hwnd, IDC_SUPPORT_DIR), fEnable);
  323. EnableWindow(GetDlgItem(hwnd, IDC_SUPPORT_BROWSE), fEnable);
  324. break;
  325. case IDC_BRANDING_CHK:
  326. EnableWindow(GetDlgItem(hwnd, IDC_BRANDING_CAPTION), fEnable);
  327. EnableWindow(GetDlgItem(hwnd, IDC_BRANDING_DIR), fEnable);
  328. EnableWindow(GetDlgItem(hwnd, IDC_BRANDING_BROWSE), fEnable);
  329. break;
  330. }
  331. }