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.

387 lines
12 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1994 **
  4. //*********************************************************************
  5. //
  6. // ISPSEL.CPP - Functions for
  7. //
  8. // HISTORY:
  9. //
  10. // 05/13/98 donaldm Created.
  11. //
  12. //*********************************************************************
  13. #include "pre.h"
  14. #include "exdisp.h"
  15. #include "shldisp.h"
  16. #include <htiframe.h>
  17. #include <mshtml.h>
  18. const TCHAR cszISPINFOPath[] = TEXT("download\\ispinfo.csv");
  19. int iNumOfAutoConfigOffers = 0;
  20. BOOL g_bSkipSelPage = FALSE;
  21. // Convert a supplied icon from it's GIF format to an ICO format
  22. extern void ConvertISPIcon(LPTSTR lpszLogoPath, HICON* hIcon);
  23. extern BOOL AddItemToISPList
  24. (
  25. HWND hListView,
  26. int iItemIndex,
  27. LPTSTR lpszIspName,
  28. int iIspLogoIndex,
  29. BOOL bCNS,
  30. LPARAM lParam,
  31. BOOL bFilterDupe
  32. );
  33. extern BOOL InitListView(HWND hListView);
  34. extern BOOL ResetListView(HWND hListView);
  35. extern BOOL CALLBACK ValidateISP(HWND hDlg);
  36. /*******************************************************************
  37. NAME: ParseISPInfo
  38. SYNOPSIS: Called when page is displayed
  39. ENTRY: hDlg - dialog window
  40. fFirstInit - TRUE if this is the first time the dialog
  41. is initialized, FALSE if this InitProc has been called
  42. before (e.g. went past this page and backed up)
  43. ********************************************************************/
  44. BOOL CALLBACK ParseISPInfo
  45. (
  46. HWND hDlg,
  47. TCHAR *pszCSVFileName,
  48. BOOL bCheckDupe
  49. )
  50. {
  51. // On the first init, we will read the ISPINFO.CSV file, and populate the ISP LISTVIEW
  52. CCSVFile far *pcCSVFile;
  53. CISPCSV far *pcISPCSV;
  54. BOOL bRet = TRUE;
  55. BOOL bHaveCNSOffer = FALSE;
  56. HICON hISPLogo;
  57. int iImage;
  58. HRESULT hr;
  59. // Open and process the CSV file
  60. pcCSVFile = new CCSVFile;
  61. if (!pcCSVFile)
  62. {
  63. // BUGBUG: Show Error Message
  64. return (FALSE);
  65. }
  66. if (!pcCSVFile->Open(pszCSVFileName))
  67. {
  68. // BUGBUG: Show Error Message
  69. AssertMsg(0,"Can not open ISPINFO.CSV file");
  70. delete pcCSVFile;
  71. pcCSVFile = NULL;
  72. return (FALSE);
  73. }
  74. // Read the first line, since it contains field headers
  75. pcISPCSV = new CISPCSV;
  76. if (!pcISPCSV)
  77. {
  78. // BUGBUG Show error message
  79. delete pcCSVFile;
  80. //iNumOfAutoConfigOffers = ISP_INFO_NO_VALIDOFFER;
  81. return (FALSE);
  82. }
  83. if (ERROR_SUCCESS != (hr = pcISPCSV->ReadFirstLine(pcCSVFile)))
  84. {
  85. // Handle the error case
  86. delete pcCSVFile;
  87. //iNumOfAutoConfigOffers = ISP_INFO_NO_VALIDOFFER;
  88. pcCSVFile = NULL;
  89. return (FALSE);
  90. }
  91. delete pcISPCSV; // Don't need this one any more
  92. do {
  93. // Allocate a new ISP record
  94. pcISPCSV = new CISPCSV;
  95. if (!pcISPCSV)
  96. {
  97. // BUGBUG Show error message
  98. bRet = FALSE;
  99. //iNumOfAutoConfigOffers = ISP_INFO_NO_VALIDOFFER;
  100. break;
  101. }
  102. // Read a line from the ISPINFO file
  103. hr = pcISPCSV->ReadOneLine(pcCSVFile);
  104. if (hr == ERROR_SUCCESS)
  105. {
  106. // If this line contains a nooffer flag, then leave now
  107. if (!(pcISPCSV->get_dwCFGFlag() & ICW_CFGFLAG_OFFERS))
  108. {
  109. //iNumOfAutoConfigOffers = 0;
  110. break;
  111. }
  112. if ((pcISPCSV->get_dwCFGFlag() & ICW_CFGFLAG_AUTOCONFIG) &&
  113. (gpWizardState->bISDNMode ? (pcISPCSV->get_dwCFGFlag() & ICW_CFGFLAG_ISDN_OFFER) : TRUE) )
  114. {
  115. // Convert the ISP logo from a GIF to an ICON, and add it to the Image List
  116. ConvertISPIcon(pcISPCSV->get_szISPLogoPath(), &hISPLogo);
  117. iImage = ImageList_AddIcon(gpWizardState->himlIspSelect, hISPLogo);
  118. DestroyIcon(hISPLogo);
  119. pcISPCSV->set_ISPLogoImageIndex(iImage);
  120. // Add the entry to the list view
  121. if (AddItemToISPList( GetDlgItem(hDlg, IDC_ISPLIST),
  122. iNumOfAutoConfigOffers,
  123. pcISPCSV->get_szISPName(),
  124. pcISPCSV->get_ISPLogoIndex(),
  125. FALSE,
  126. (LPARAM)pcISPCSV,
  127. bCheckDupe))
  128. {
  129. ++iNumOfAutoConfigOffers;
  130. }
  131. }
  132. else
  133. {
  134. delete pcISPCSV;
  135. }
  136. }
  137. else if (hr == ERROR_NO_MORE_ITEMS)
  138. {
  139. delete pcISPCSV; // We don't need this one
  140. break;
  141. }
  142. else if (hr == ERROR_FILE_NOT_FOUND)
  143. {
  144. // do not show this ISP when its data is invalid
  145. // we don't want to halt everything. Just let it contine
  146. delete pcISPCSV;
  147. }
  148. else
  149. {
  150. // Show error message Later
  151. delete pcISPCSV;
  152. //iNumOfAutoConfigOffers = ISP_INFO_NO_VALIDOFFER;
  153. bRet = FALSE;
  154. break;
  155. }
  156. } while (TRUE);
  157. delete pcCSVFile;
  158. return bRet;
  159. }
  160. /*******************************************************************
  161. NAME: ISPAutoSelectInitProc
  162. SYNOPSIS: Called when page is displayed
  163. ENTRY: hDlg - dialog window
  164. fFirstInit - TRUE if this is the first time the dialog
  165. is initialized, FALSE if this InitProc has been called
  166. before (e.g. went past this page and backed up)
  167. ********************************************************************/
  168. BOOL CALLBACK ISPAutoSelectInitProc
  169. (
  170. HWND hDlg,
  171. BOOL fFirstInit,
  172. UINT *puNextPage
  173. )
  174. {
  175. if (fFirstInit)
  176. {
  177. // Initialize the List View
  178. InitListView(GetDlgItem(hDlg, IDC_ISPLIST));
  179. gpWizardState->cmnStateData.bParseIspinfo = TRUE;
  180. }
  181. else
  182. {
  183. gpWizardState->bISDNMode = gpWizardState->cmnStateData.bIsISDNDevice;
  184. if (g_bSkipSelPage)
  185. {
  186. g_bSkipSelPage = FALSE;
  187. *puNextPage = ORD_PAGE_ISP_AUTOCONFIG_NOOFFER;
  188. }
  189. if (gpWizardState->cmnStateData.bParseIspinfo)
  190. {
  191. // If there are items in the list view, clear them
  192. ListView_DeleteAllItems(GetDlgItem(hDlg, IDC_ISPLIST));
  193. // Initialize the number of autocfg offers to zero
  194. iNumOfAutoConfigOffers = 0;
  195. gpWizardState->lpSelectedISPInfo = NULL;
  196. // Always try to parse offline folder. If there is nothing there,
  197. // it will simple return FALSE.
  198. if (gpWizardState->cmnStateData.bOEMOffline)
  199. ParseISPInfo(hDlg, ICW_OEMINFOPath, TRUE);
  200. // Read and parse the download folder.
  201. ParseISPInfo(hDlg, ICW_ISPINFOPath, TRUE);
  202. // Create a "other" selection in the list view for unlisted ISPs
  203. if (iNumOfAutoConfigOffers > 0 )
  204. {
  205. // Adding Other
  206. TCHAR szOther [MAX_RES_LEN+1] = TEXT("\0");
  207. LoadString(ghInstanceResDll, IDS_ISP_AUTOCONFIG_OTHER, szOther, ARRAYSIZE(szOther));
  208. AddItemToISPList( GetDlgItem(hDlg, IDC_ISPLIST),
  209. iNumOfAutoConfigOffers,
  210. szOther,
  211. -1,
  212. FALSE,
  213. (LPARAM)NULL,
  214. FALSE);
  215. ResetListView(GetDlgItem(hDlg, IDC_ISPLIST));
  216. }
  217. }
  218. // The following 3 Cases can happen at this point:
  219. // 1) The ispinfo.csv contains a line says no offer, we go to nooffer page
  220. // 2) The ispinfo.csv contains no line of valid offer and no no-offer entry
  221. // This may happen in calling the old referral.dll that ICW 3 client calls
  222. // 3) There are many offers but no ISDN offers, we go to ISDN offer pages
  223. // 4) Normal situation, some valid offers where we're in ISDN or not
  224. if (0 == iNumOfAutoConfigOffers)
  225. {
  226. *puNextPage = ORD_PAGE_ISP_AUTOCONFIG_NOOFFER;
  227. }
  228. else if (ISP_INFO_NO_VALIDOFFER == iNumOfAutoConfigOffers)
  229. {
  230. // Error in ISPINFO.CSV if there is no offers and no no-offer entry
  231. // critical error
  232. *puNextPage = g_uExternUINext;
  233. gpWizardState->cmnStateData.bParseIspinfo = TRUE;
  234. return FALSE;
  235. }
  236. else
  237. {
  238. if (0 == ListView_GetSelectedCount(GetDlgItem(hDlg, IDC_ISPLIST)))
  239. {
  240. // Select the First Item in the Listview
  241. ListView_SetItemState(GetDlgItem(hDlg, IDC_ISPLIST), 0, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
  242. }
  243. }
  244. gpWizardState->cmnStateData.bParseIspinfo = FALSE;
  245. gpWizardState->uCurrentPage = ORD_PAGE_ISP_AUTOCONFIG;
  246. }
  247. return TRUE;
  248. }
  249. /*******************************************************************
  250. NAME: ISPAutoSelectOKProc
  251. SYNOPSIS: Called when Next or Back btns pressed from page
  252. ENTRY: hDlg - dialog window
  253. fForward - TRUE if 'Next' was pressed, FALSE if 'Back'
  254. puNextPage - if 'Next' was pressed,
  255. proc can fill this in with next page to go to. This
  256. parameter is ingored if 'Back' was pressed.
  257. pfKeepHistory - page will not be kept in history if
  258. proc fills this in with FALSE.
  259. EXIT: returns TRUE to allow page to be turned, FALSE
  260. to keep the same page.
  261. ********************************************************************/
  262. BOOL CALLBACK ISPAutoSelectOKProc
  263. (
  264. HWND hDlg,
  265. BOOL fForward,
  266. UINT *puNextPage,
  267. BOOL *pfKeepHistory
  268. )
  269. {
  270. ASSERT(puNextPage);
  271. if (fForward)
  272. {
  273. if (gpWizardState->lpSelectedISPInfo == NULL)
  274. {
  275. *puNextPage = ORD_PAGE_ISP_AUTOCONFIG_NOOFFER;
  276. return TRUE;
  277. }
  278. *puNextPage = ORD_PAGE_ISPDIAL;
  279. }
  280. return TRUE;
  281. }
  282. BOOL CALLBACK ISPAutoSelectNotifyProc
  283. (
  284. HWND hDlg,
  285. WPARAM wParam,
  286. LPARAM lParam
  287. )
  288. {
  289. CISPCSV *pcISPCSV;
  290. // Process ListView notifications
  291. switch(((LV_DISPINFO *)lParam)->hdr.code)
  292. {
  293. case NM_DBLCLK:
  294. TraceMsg(TF_ISPSELECT, "ISPSELECT: WM_NOTIFY - NM_DBLCLK");
  295. PropSheet_PressButton(GetParent(hDlg),PSBTN_NEXT);
  296. break;
  297. case NM_SETFOCUS:
  298. case NM_KILLFOCUS:
  299. // update list view
  300. break;
  301. case LVN_ITEMCHANGED:
  302. TraceMsg(TF_ISPSELECT, "ISPSELECT: WM_NOTIFY - LVN_ITEMCHANGED");
  303. if((((NM_LISTVIEW *)lParam)->uChanged & LVIF_STATE) &&
  304. ((NM_LISTVIEW *)lParam)->uNewState & (LVIS_FOCUSED | LVIS_SELECTED))
  305. {
  306. // IF an Item just became selected, then render it's HTML content
  307. pcISPCSV = (CISPCSV *)((NM_LISTVIEW *)lParam)->lParam;
  308. // Remember the selected item for later use
  309. gpWizardState->lpSelectedISPInfo = pcISPCSV;
  310. }
  311. break;
  312. // The listview is being emptied, or destroyed, either way, our lpSelectedISPInfo
  313. // is no longer valid, since the list view underlying data will be freed.
  314. case LVN_DELETEALLITEMS:
  315. gpWizardState->lpSelectedISPInfo = NULL;
  316. SetPropSheetResult(hDlg,TRUE);
  317. break;
  318. case LVN_DELETEITEM:
  319. // We were notified that an item was deleted.
  320. // so delete the underlying data that it is pointing
  321. // to.
  322. if (((NM_LISTVIEW*)lParam)->lParam)
  323. delete (CISPCSV *)((NM_LISTVIEW *)lParam)->lParam;
  324. break;
  325. }
  326. return TRUE;
  327. }