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.

1687 lines
49 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1994 **
  4. //*********************************************************************
  5. //
  6. // UTIL.C - common utility functions
  7. //
  8. // HISTORY:
  9. //
  10. // 12/21/94 jeremys Created.
  11. // 96/03/24 markdu Replaced memset with ZeroMemory for consistency.
  12. // 96/04/06 markdu NASH BUG 15653 Use exported autodial API.
  13. // Need to keep a modified SetInternetConnectoid to set the
  14. // MSN backup connectoid.
  15. // 96/05/14 markdu NASH BUG 21706 Removed BigFont functions.
  16. //
  17. #include "wizard.h"
  18. #if 0
  19. #include "string.h"
  20. #endif
  21. #define MAX_MSG_PARAM 8
  22. #include "winver.h"
  23. BOOL GetIEVersion(PDWORD pdwVerNumMS, PDWORD pdwVerNumLS);
  24. // IE 4 has major.minor version 4.71
  25. // IE 3 golden has major.minor.release.build version # > 4.70.0.1155
  26. // IE 2 has major.minor of 4.40
  27. #define IE4_MAJOR_VERSION (UINT) 4
  28. #define IE4_MINOR_VERSION (UINT) 71
  29. #define IE4_VERSIONMS (DWORD) ((IE4_MAJOR_VERSION << 16) | IE4_MINOR_VERSION)
  30. // function prototypes
  31. VOID _cdecl FormatErrorMessage(TCHAR * pszMsg,DWORD cbMsg,TCHAR * pszFmt,LPTSTR szArg);
  32. extern VOID GetRNAErrorText(UINT uErr,TCHAR * pszErrText,DWORD cbErrText);
  33. extern VOID GetMAPIErrorText(UINT uErr,TCHAR * pszErrText,DWORD cbErrText);
  34. extern GETSETUPXERRORTEXT lpGetSETUPXErrorText;
  35. #ifdef WIN32
  36. VOID Win95JMoveDlgItem( HWND hwndParent, HWND hwndItem, int iUp );
  37. #endif
  38. void GetCmdLineToken(LPTSTR *ppszCmd,LPTSTR pszOut);
  39. #define NUMICWFILENAMES 4
  40. TCHAR *g_ppszICWFileNames[NUMICWFILENAMES] = { TEXT("ICWCONN1.EXE\0"),
  41. TEXT("ISIGNUP.EXE\0"),
  42. TEXT("INETWIZ.EXE\0"),
  43. TEXT("ICWCONN2.EXE\0") };
  44. /*******************************************************************
  45. NAME: MsgBox
  46. SYNOPSIS: Displays a message box with the specified string ID
  47. ********************************************************************/
  48. int MsgBox(HWND hWnd,UINT nMsgID,UINT uIcon,UINT uButtons)
  49. {
  50. TCHAR szMsgBuf[MAX_RES_LEN+1];
  51. TCHAR szSmallBuf[SMALL_BUF_LEN+1];
  52. LoadSz(IDS_APPNAME,szSmallBuf,sizeof(szSmallBuf));
  53. LoadSz(nMsgID,szMsgBuf,sizeof(szMsgBuf));
  54. return (MessageBox(hWnd,szMsgBuf,szSmallBuf,uIcon | uButtons));
  55. }
  56. /*******************************************************************
  57. NAME: MsgBoxSz
  58. SYNOPSIS: Displays a message box with the specified text
  59. ********************************************************************/
  60. int MsgBoxSz(HWND hWnd,LPTSTR szText,UINT uIcon,UINT uButtons)
  61. {
  62. TCHAR szSmallBuf[SMALL_BUF_LEN+1];
  63. LoadSz(IDS_APPNAME,szSmallBuf,sizeof(szSmallBuf));
  64. return (MessageBox(hWnd,szText,szSmallBuf,uIcon | uButtons));
  65. }
  66. /*******************************************************************
  67. NAME: MsgBoxParam
  68. SYNOPSIS: Displays a message box with the specified string ID
  69. NOTES: //extra parameters are string pointers inserted into nMsgID.
  70. jmazner 11/6/96 For RISC compatability, we don't want
  71. to use va_list; since current source code never uses more than
  72. one string parameter anyways, just change function signature
  73. to explicitly include that one parameter.
  74. ********************************************************************/
  75. int _cdecl MsgBoxParam(HWND hWnd,UINT nMsgID,UINT uIcon,UINT uButtons,LPTSTR szParam)
  76. {
  77. BUFFER Msg(3*MAX_RES_LEN+1); // nice n' big for room for inserts
  78. BUFFER MsgFmt(MAX_RES_LEN+1);
  79. //va_list args;
  80. if (!Msg || !MsgFmt) {
  81. return MsgBox(hWnd,IDS_ERROutOfMemory,MB_ICONSTOP,MB_OK);
  82. }
  83. LoadSz(nMsgID,MsgFmt.QueryPtr(),MsgFmt.QuerySize());
  84. //va_start(args,uButtons);
  85. //FormatErrorMessage(Msg.QueryPtr(),Msg.QuerySize(),
  86. // MsgFmt.QueryPtr(),args);
  87. FormatErrorMessage(Msg.QueryPtr(),Msg.QuerySize(),
  88. MsgFmt.QueryPtr(),szParam);
  89. return MsgBoxSz(hWnd,Msg.QueryPtr(),uIcon,uButtons);
  90. }
  91. BOOL EnableDlgItem(HWND hDlg,UINT uID,BOOL fEnable)
  92. {
  93. return EnableWindow(GetDlgItem(hDlg,uID),fEnable);
  94. }
  95. /*******************************************************************
  96. NAME: LoadSz
  97. SYNOPSIS: Loads specified string resource into buffer
  98. EXIT: returns a pointer to the passed-in buffer
  99. NOTES: If this function fails (most likely due to low
  100. memory), the returned buffer will have a leading NULL
  101. so it is generally safe to use this without checking for
  102. failure.
  103. ********************************************************************/
  104. LPTSTR LoadSz(UINT idString,LPTSTR lpszBuf,UINT cbBuf)
  105. {
  106. ASSERT(lpszBuf);
  107. // Clear the buffer and load the string
  108. if ( lpszBuf )
  109. {
  110. *lpszBuf = '\0';
  111. LoadString( ghInstance, idString, lpszBuf, cbBuf );
  112. }
  113. return lpszBuf;
  114. }
  115. /*******************************************************************
  116. NAME: GetErrorDescription
  117. SYNOPSIS: Retrieves the text description for a given error code
  118. and class of error (standard, setupx)
  119. ********************************************************************/
  120. VOID GetErrorDescription(TCHAR * pszErrorDesc,UINT cbErrorDesc,
  121. UINT uError,UINT uErrorClass)
  122. {
  123. ASSERT(pszErrorDesc);
  124. // set a leading null in error description
  125. *pszErrorDesc = '\0';
  126. switch (uErrorClass) {
  127. case ERRCLS_STANDARD:
  128. if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,
  129. uError,0,pszErrorDesc,cbErrorDesc,NULL)) {
  130. // if getting system text fails, make a string a la
  131. // "error <n> occurred"
  132. TCHAR szFmt[SMALL_BUF_LEN+1];
  133. LoadSz(IDS_ERRFORMAT,szFmt,sizeof(szFmt));
  134. wsprintf(pszErrorDesc,szFmt,uError);
  135. }
  136. break;
  137. case ERRCLS_SETUPX:
  138. lpGetSETUPXErrorText(uError,pszErrorDesc,cbErrorDesc);
  139. break;
  140. case ERRCLS_RNA:
  141. GetRNAErrorText(uError,pszErrorDesc,cbErrorDesc);
  142. break;
  143. case ERRCLS_MAPI:
  144. GetMAPIErrorText(uError,pszErrorDesc,cbErrorDesc);
  145. break;
  146. default:
  147. DEBUGTRAP("Unknown error class %lu in GetErrorDescription",
  148. uErrorClass);
  149. }
  150. }
  151. /*******************************************************************
  152. NAME: FormatErrorMessage
  153. SYNOPSIS: Builds an error message by calling FormatMessage
  154. NOTES: Worker function for DisplayErrorMessage
  155. ********************************************************************/
  156. VOID _cdecl FormatErrorMessage(TCHAR * pszMsg,DWORD cbMsg,TCHAR * pszFmt,LPTSTR szArg)
  157. {
  158. ASSERT(pszMsg);
  159. ASSERT(pszFmt);
  160. // build the message into the pszMsg buffer
  161. DWORD dwCount = FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  162. pszFmt,0,0,pszMsg,cbMsg,(va_list*) &szArg);
  163. ASSERT(dwCount > 0);
  164. }
  165. /*******************************************************************
  166. NAME: DisplayErrorMessage
  167. SYNOPSIS: Displays an error message for given error
  168. ENTRY: hWnd - parent window
  169. uStrID - ID of string resource with message format.
  170. Should contain %1 to be replaced by error text,
  171. additional parameters can be specified as well.
  172. uError - error code for error to display
  173. uErrorClass - ERRCLS_xxx ID of class of error that
  174. uError belongs to (standard, setupx)
  175. uIcon - icon to display
  176. //... - additional parameters to be inserted in string
  177. // specified by uStrID
  178. jmazner 11/6/96 change to just one parameter for
  179. RISC compatability.
  180. ********************************************************************/
  181. VOID _cdecl DisplayErrorMessage(HWND hWnd,UINT uStrID,UINT uError,
  182. UINT uErrorClass,UINT uIcon,LPTSTR szArg)
  183. {
  184. // dynamically allocate buffers for messages
  185. BUFFER ErrorDesc(MAX_RES_LEN+1);
  186. BUFFER ErrorFmt(MAX_RES_LEN+1);
  187. BUFFER ErrorMsg(2*MAX_RES_LEN+1);
  188. if (!ErrorDesc || !ErrorFmt || !ErrorMsg) {
  189. // if can't allocate buffers, display out of memory error
  190. MsgBox(hWnd,IDS_ERROutOfMemory,MB_ICONEXCLAMATION,MB_OK);
  191. return;
  192. }
  193. // get a text description based on the error code and the class
  194. // of error it is
  195. GetErrorDescription(ErrorDesc.QueryPtr(),
  196. ErrorDesc.QuerySize(),uError,uErrorClass);
  197. // load the string for the message format
  198. LoadSz(uStrID,ErrorFmt.QueryPtr(),ErrorFmt.QuerySize());
  199. //LPSTR args[MAX_MSG_PARAM];
  200. //args[0] = (LPSTR) ErrorDesc.QueryPtr();
  201. //memcpy(&args[1],((TCHAR *) &uIcon) + sizeof(uIcon),(MAX_MSG_PARAM - 1) * sizeof(LPSTR));
  202. //FormatErrorMessage(ErrorMsg.QueryPtr(),ErrorMsg.QuerySize(),
  203. // ErrorFmt.QueryPtr(),(va_list) &args[0]);
  204. FormatErrorMessage(ErrorMsg.QueryPtr(),ErrorMsg.QuerySize(),
  205. ErrorFmt.QueryPtr(),ErrorDesc.QueryPtr());
  206. // display the message
  207. MsgBoxSz(hWnd,ErrorMsg.QueryPtr(),uIcon,MB_OK);
  208. }
  209. /*******************************************************************
  210. NAME: WarnFieldIsEmpty
  211. SYNOPSIS: Pops up a warning message if the user tries to leave
  212. a page without filling out a text field and asks if she
  213. wants to continue.
  214. ENTRY: hDlg - parent windows
  215. uCtrlID - ID of control left blank
  216. uStrID - ID of string resource with warning message
  217. EXIT: returns TRUE if user wants to continue anyway, FALSE
  218. if user wants to stay on same page.
  219. ********************************************************************/
  220. BOOL WarnFieldIsEmpty(HWND hDlg,UINT uCtrlID,UINT uStrID)
  221. {
  222. // warn the user
  223. if (MsgBox(hDlg,uStrID,MB_ICONEXCLAMATION,
  224. MB_YESNO | MB_DEFBUTTON2) == IDNO) {
  225. // user chose no, wants to stay on same page
  226. // set focus to control in question
  227. SetFocus(GetDlgItem(hDlg,uCtrlID));
  228. return FALSE;
  229. }
  230. return TRUE;
  231. }
  232. BOOL TweakAutoRun(BOOL bEnable)
  233. {
  234. HKEY hKey = NULL;
  235. DWORD dwType = 0;
  236. DWORD dwSize = 0;
  237. DWORD dwVal = 0;
  238. BOOL bWasEnabled = FALSE;
  239. RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"), 0, KEY_ALL_ACCESS, &hKey);
  240. if (hKey)
  241. {
  242. RegQueryValueEx(hKey, (LPTSTR)TEXT("NoDriveTypeAutoRun"), 0, &dwType, (LPBYTE)&dwVal, &dwSize);
  243. RegQueryValueEx(hKey, (LPTSTR)TEXT("NoDriveTypeAutoRun"), 0, &dwType, (LPBYTE)&dwVal, &dwSize);
  244. if (dwVal & DRIVE_CDROM)
  245. bWasEnabled = TRUE;
  246. if (bEnable)
  247. dwVal |= DRIVE_CDROM;
  248. else
  249. dwVal &=~DRIVE_CDROM;
  250. RegSetValueEx(hKey, (LPTSTR)TEXT("NoDriveTypeAutoRun"), 0, dwType, (LPBYTE)&dwVal, dwSize);
  251. CloseHandle(hKey);
  252. }
  253. return bWasEnabled;
  254. }
  255. /*******************************************************************
  256. NAME: DisplayFieldErrorMsg
  257. SYNOPSIS: Pops up a warning message about a field, sets focus to
  258. the field and selects any text in it.
  259. ENTRY: hDlg - parent windows
  260. uCtrlID - ID of control left blank
  261. uStrID - ID of string resource with warning message
  262. ********************************************************************/
  263. VOID DisplayFieldErrorMsg(HWND hDlg,UINT uCtrlID,UINT uStrID)
  264. {
  265. MsgBox(hDlg,uStrID,MB_ICONEXCLAMATION,MB_OK);
  266. SetFocus(GetDlgItem(hDlg,uCtrlID));
  267. SendDlgItemMessage(hDlg,uCtrlID,EM_SETSEL,0,-1);
  268. }
  269. /*******************************************************************
  270. NAME: SetBackupInternetConnectoid
  271. SYNOPSIS: Sets the name of the backup connectoid used to autodial to the
  272. Internet
  273. ENTRY: pszEntryName - name of connectoid to set. If NULL,
  274. then the registry entry is removed.
  275. NOTES: sets value in registry
  276. ********************************************************************/
  277. VOID SetBackupInternetConnectoid(LPCTSTR pszEntryName)
  278. {
  279. RegEntry re(szRegPathRNAWizard,HKEY_CURRENT_USER);
  280. if (re.GetError() == ERROR_SUCCESS)
  281. {
  282. if (pszEntryName)
  283. {
  284. re.SetValue(szRegValBkupInternetProfile,pszEntryName);
  285. }
  286. else
  287. {
  288. re.DeleteValue(szRegValBkupInternetProfile);
  289. }
  290. }
  291. }
  292. /*******************************************************************
  293. NAME: myatoi
  294. SYNOPSIS: Converts numeric string to numeric value
  295. NOTES: implementation of atoi to avoid pulling in C runtime
  296. ********************************************************************/
  297. UINT myatoi (TCHAR * szVal)
  298. {
  299. TCHAR * lpch;
  300. WORD wDigitVal=1,wTotal=0;
  301. for (lpch = szVal + lstrlen(szVal)-1; lpch >= szVal ; lpch --,
  302. wDigitVal *= 10)
  303. if ( *lpch >= '0' && *lpch <= '9')
  304. wTotal += (*lpch - '0') * wDigitVal;
  305. return (UINT) wTotal;
  306. }
  307. /*******************************************************************
  308. NAME: MsgWaitForMultipleObjectsLoop
  309. SYNOPSIS: Blocks until the specified object is signaled, while
  310. still dispatching messages to the main thread.
  311. ********************************************************************/
  312. DWORD MsgWaitForMultipleObjectsLoop(HANDLE hEvent)
  313. {
  314. MSG msg;
  315. DWORD dwObject;
  316. while (1)
  317. {
  318. // NB We need to let the run dialog become active so we have to half handle sent
  319. // messages but we don't want to handle any input events or we'll swallow the
  320. // type-ahead.
  321. dwObject = MsgWaitForMultipleObjects(1, &hEvent, FALSE,INFINITE, QS_ALLINPUT);
  322. // Are we done waiting?
  323. switch (dwObject) {
  324. case WAIT_OBJECT_0:
  325. case WAIT_FAILED:
  326. return dwObject;
  327. case WAIT_OBJECT_0 + 1:
  328. // got a message, dispatch it and wait again
  329. while (PeekMessage(&msg, NULL,0, 0, PM_REMOVE)) {
  330. DispatchMessage(&msg);
  331. }
  332. break;
  333. }
  334. }
  335. // never gets here
  336. }
  337. /*******************************************************************
  338. // //10/24/96 jmazner Normandy 6968
  339. // //No longer neccessary thanks to Valdon's hooks for invoking ICW.
  340. // 11/21/96 jmazner Normandy 11812
  341. // oops, it _is_ neccessary, since if user downgrades from IE 4 to IE 3,
  342. // ICW 1.1 needs to morph the IE 3 icon.
  343. NAME: SetDesktopInternetIconToBrowser
  344. SYNOPSIS: "Points" The Internet desktop icon to web browser
  345. (Internet Explorer)
  346. NOTES: For IE 3, the Internet icon may initially "point" at this wizard,
  347. we need to set it to launch web browser once we complete
  348. successfully.
  349. ********************************************************************/
  350. BOOL SetDesktopInternetIconToBrowser(VOID)
  351. {
  352. TCHAR szAppPath[MAX_PATH+1]=TEXT("");
  353. BOOL fRet = FALSE;
  354. DWORD dwVerMS, dwVerLS;
  355. if( !GetIEVersion( &dwVerMS, &dwVerLS ) )
  356. {
  357. return( FALSE );
  358. }
  359. if( (dwVerMS >= IE4_VERSIONMS) )
  360. {
  361. // we're dealing with IE 4, don't touch the icon stuff
  362. return( TRUE );
  363. }
  364. // look in the app path section in registry to get path to internet
  365. // explorer
  366. RegEntry reAppPath(szRegPathIexploreAppPath,HKEY_LOCAL_MACHINE);
  367. ASSERT(reAppPath.GetError() == ERROR_SUCCESS);
  368. if (reAppPath.GetError() == ERROR_SUCCESS) {
  369. reAppPath.GetString(szNull,szAppPath,sizeof(szAppPath));
  370. ASSERT(reAppPath.GetError() == ERROR_SUCCESS);
  371. }
  372. // set the path to internet explorer as the open command for the
  373. // internet desktop icon
  374. if (lstrlen(szAppPath)) {
  375. RegEntry reIconOpenCmd(szRegPathInternetIconCommand,HKEY_CLASSES_ROOT);
  376. ASSERT(reIconOpenCmd.GetError() == ERROR_SUCCESS);
  377. if (reIconOpenCmd.GetError() == ERROR_SUCCESS) {
  378. UINT uErr = reIconOpenCmd.SetValue(szNull,szAppPath);
  379. ASSERT(uErr == ERROR_SUCCESS);
  380. fRet = (uErr == ERROR_SUCCESS);
  381. }
  382. }
  383. return fRet;
  384. }
  385. //+----------------------------------------------------------------------------
  386. //
  387. // Function IsDialableString
  388. //
  389. // Synopsis Determines whether a string has any non dialable characters.
  390. //
  391. // Arguments szBuff - the string to check.
  392. //
  393. // Returns TRUE is no chars other than 0123456789ABCDabcdPpTtWw!@$-.()+*#,& and <space>
  394. // FALSE otherwise.
  395. //
  396. // History 11/11/96 jmazner created for Normandy #7623
  397. //
  398. //-----------------------------------------------------------------------------
  399. BOOL IsDialableString(LPTSTR szBuff)
  400. {
  401. LPTSTR szDialableChars = TEXT("0123456789ABCDabcdPpTtWw!@$-.()+*#,& ");
  402. int i = 0;
  403. for( i = 0; szBuff[i]; i++ )
  404. {
  405. if( !_tcschr(szDialableChars, szBuff[i]) )
  406. return FALSE;
  407. }
  408. return TRUE;
  409. }
  410. //+----------------------------------------------------------------------------
  411. //
  412. // Function: GetIEVersion
  413. //
  414. // Synopsis: Gets the major and minor version # of the installed copy of Internet Explorer
  415. //
  416. // Arguments: pdwVerNumMS - pointer to a DWORD;
  417. // On succesful return, the top 16 bits will contain the major version number,
  418. // and the lower 16 bits will contain the minor version number
  419. // (this is the data in VS_FIXEDFILEINFO.dwProductVersionMS)
  420. // pdwVerNumLS - pointer to a DWORD;
  421. // On succesful return, the top 16 bits will contain the release number,
  422. // and the lower 16 bits will contain the build number
  423. // (this is the data in VS_FIXEDFILEINFO.dwProductVersionLS)
  424. //
  425. // Returns: TRUE - Success. *pdwVerNumMS and LS contains installed IE version number
  426. // FALSE - Failure. *pdVerNumMS == *pdVerNumLS == 0
  427. //
  428. // History: jmazner Created 8/19/96 (as fix for Normandy #4571)
  429. // jmazner updated to deal with release.build as well 10/11/96
  430. // jmazner stolen from isign32\isignup.cpp 11/21/96
  431. // (for Normandy #11812)
  432. //
  433. //-----------------------------------------------------------------------------
  434. BOOL GetIEVersion(PDWORD pdwVerNumMS, PDWORD pdwVerNumLS)
  435. {
  436. HRESULT hr;
  437. HKEY hKey = 0;
  438. LPVOID lpVerInfoBlock;
  439. VS_FIXEDFILEINFO *lpTheVerInfo;
  440. UINT uTheVerInfoSize;
  441. DWORD dwVerInfoBlockSize, dwUnused, dwPathSize;
  442. TCHAR szIELocalPath[MAX_PATH + 1] = TEXT("");
  443. *pdwVerNumMS = 0;
  444. *pdwVerNumLS = 0;
  445. // get path to the IE executable
  446. hr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegPathIexploreAppPath,0, KEY_READ, &hKey);
  447. if (hr != ERROR_SUCCESS) return( FALSE );
  448. dwPathSize = sizeof (szIELocalPath);
  449. hr = RegQueryValueEx(hKey, NULL, NULL, NULL, (LPBYTE) szIELocalPath, &dwPathSize);
  450. RegCloseKey( hKey );
  451. if (hr != ERROR_SUCCESS) return( FALSE );
  452. // now go through the convoluted process of digging up the version info
  453. dwVerInfoBlockSize = GetFileVersionInfoSize( szIELocalPath, &dwUnused );
  454. if ( 0 == dwVerInfoBlockSize ) return( FALSE );
  455. lpVerInfoBlock = GlobalAlloc( GPTR, dwVerInfoBlockSize );
  456. if( NULL == lpVerInfoBlock ) return( FALSE );
  457. if( !GetFileVersionInfo( szIELocalPath, NULL, dwVerInfoBlockSize, lpVerInfoBlock ) )
  458. return( FALSE );
  459. if( !VerQueryValue(lpVerInfoBlock, TEXT("\\"), (void **)&lpTheVerInfo, &uTheVerInfoSize) )
  460. return( FALSE );
  461. *pdwVerNumMS = lpTheVerInfo->dwProductVersionMS;
  462. *pdwVerNumLS = lpTheVerInfo->dwProductVersionLS;
  463. GlobalFree( lpVerInfoBlock );
  464. return( TRUE );
  465. }
  466. //+----------------------------------------------------------------------------
  467. //
  468. // Function: Win95JMoveDlgItem
  469. //
  470. // Synopsis: Moves a particular dialog item on a non-localized ICW
  471. // up or down on Win 95 J systems
  472. // to work around a w95J rendering glitch that mis-sizes our
  473. // wizard window.
  474. //
  475. // Arguments: hwndParent - Handle to parent window which contains the hwndItem
  476. // hwndItem -- Handle to dlg item to move
  477. // iUp -- number of units upward the item should be shifted. A
  478. // negative value here implies that the item should be shifted
  479. // downward.
  480. //
  481. // Returns: VOID
  482. //
  483. // History: 6/6/97 jmazner Created for Olympus #5413
  484. // 6/29/97 jmazner Updated to only do this on English ICW (Oly #5413)
  485. //
  486. //
  487. //-----------------------------------------------------------------------------
  488. #ifdef WIN32
  489. DWORD GetBuildLCID();
  490. VOID Win95JMoveDlgItem( HWND hwndParent, HWND hwndItem, int iUp )
  491. {
  492. LCID LangID = 0x409; // default to English
  493. // 0x411 is Japanese
  494. LangID = GetUserDefaultLCID();
  495. //
  496. // IE v 4.1 bug 37072 ChrisK 8/19/97
  497. // The fix for 5413 incorrectly compared the primary language ID with the
  498. // full LCID for the build. The result was 9 != x409 when it should have
  499. // been equal. This fix was to use the primary language id from the build
  500. // instead of the full LCID
  501. //
  502. if( (0x411 == LangID) &&
  503. !(IsNT()) &&
  504. (LANG_ENGLISH == PRIMARYLANGID(GetBuildLCID())))
  505. {
  506. // assume that if it's Japanese, and it's not NT, it must be win95J!
  507. RECT itemRect;
  508. POINT thePoint;
  509. GetWindowRect(hwndItem, &itemRect);
  510. // need to convert the coords from global to local client,
  511. // since MoveWindow below will expext client coords.
  512. thePoint.x = itemRect.left;
  513. thePoint.y = itemRect.top;
  514. ScreenToClient(hwndParent, &thePoint );
  515. itemRect.left = thePoint.x;
  516. itemRect.top = thePoint.y;
  517. thePoint.x = itemRect.right;
  518. thePoint.y = itemRect.bottom;
  519. ScreenToClient(hwndParent, &thePoint );
  520. itemRect.right = thePoint.x;
  521. itemRect.bottom = thePoint.y;
  522. MoveWindow(hwndItem,
  523. itemRect.left,
  524. itemRect.top - iUp,
  525. (itemRect.right - itemRect.left),
  526. (itemRect.bottom - itemRect.top), TRUE);
  527. }
  528. }
  529. //+----------------------------------------------------------------------------
  530. //
  531. // Function: GetBuildLCID
  532. //
  533. // Synopsis: return the LCID of the file that this function resides in
  534. //
  535. // Arguments: none
  536. //
  537. // Returns: DWORD - LCID of the file or 0 if it failed
  538. //
  539. // History: ChrisK 6/25/97 Created
  540. // jmazner 6/29/97 Ported from Conn1 for Olympus 5413
  541. //
  542. //-----------------------------------------------------------------------------
  543. DWORD GetBuildLCID()
  544. {
  545. DWORD dw = 0;
  546. HMODULE hMod = NULL;
  547. TCHAR szFileName[MAX_PATH +1] = TEXT("\0uninit");
  548. DWORD dwSize = 0;
  549. LPVOID lpv = NULL;
  550. LPVOID lpvVerValue = NULL;
  551. UINT uLen = 0;
  552. DWORD dwRC = 0;
  553. DEBUGMSG("INETCFG: GetBuildLCID.\n");
  554. //
  555. // Get the name of this file
  556. //
  557. hMod = GetModuleHandle(NULL);
  558. if (NULL == hMod)
  559. {
  560. goto GetBuildLCIDExit;
  561. }
  562. if (0 == GetModuleFileName(hMod, szFileName, MAX_PATH))
  563. {
  564. goto GetBuildLCIDExit;
  565. }
  566. //
  567. // Get size and value of version structure
  568. //
  569. dwSize = GetFileVersionInfoSize(szFileName,&dw);
  570. if (0 == dwSize )
  571. {
  572. goto GetBuildLCIDExit;
  573. }
  574. lpv = (LPVOID)GlobalAlloc(GPTR, dwSize);
  575. if (NULL == lpv)
  576. {
  577. goto GetBuildLCIDExit;
  578. }
  579. if ( FALSE == GetFileVersionInfo(szFileName,0,dwSize,lpv))
  580. {
  581. goto GetBuildLCIDExit;
  582. }
  583. if ( 0 == VerQueryValue(lpv,TEXT("\\VarFileInfo\\Translation"),&lpvVerValue,&uLen))
  584. {
  585. goto GetBuildLCIDExit;
  586. }
  587. //
  588. // separate version information from character set
  589. //
  590. dwRC = (LOWORD(*(DWORD*)lpvVerValue));
  591. GetBuildLCIDExit:
  592. if (NULL != lpv)
  593. {
  594. GlobalFree(lpv);
  595. lpv = NULL;
  596. }
  597. return dwRC;
  598. }
  599. #endif
  600. //+----------------------------------------------------------------------------
  601. //
  602. // Function: GetCmdLineToken
  603. //
  604. // Synopsis: Returns the first token in a string
  605. //
  606. // Arguements:
  607. // ppszCmd [in] -- pointer to head of string
  608. // ppszCmd [out] -- pointer to second token in string
  609. // pszOut [out] -- contains the first token in the passed in string.
  610. //
  611. // Returns: None
  612. //
  613. // Notes: Considers the space character ' ' to delineate tokens, but
  614. // treats anything between double quotes as one token.
  615. // For example, the following consists of five tokens:
  616. // first second "this is the third token" fourth "fifth"
  617. //
  618. // History: 7/9/97 jmazner stolen from icwconn1\connmain.cpp for #9170
  619. //
  620. //-----------------------------------------------------------------------------
  621. void GetCmdLineToken(LPTSTR *ppszCmd,LPTSTR pszOut)
  622. {
  623. TCHAR *c;
  624. int i = 0;
  625. BOOL fInQuote = FALSE;
  626. c = *ppszCmd;
  627. pszOut[0] = *c;
  628. if (!*c) return;
  629. if (*c == ' ')
  630. {
  631. pszOut[1] = '\0';
  632. *ppszCmd = c+1;
  633. return;
  634. }
  635. else if( '"' == *c )
  636. {
  637. fInQuote = TRUE;
  638. }
  639. NextChar:
  640. i++;
  641. c++;
  642. if( !*c || (!fInQuote && (*c == ' ')) )
  643. {
  644. pszOut[i] = '\0';
  645. *ppszCmd = c;
  646. return;
  647. }
  648. else if( fInQuote && (*c == '"') )
  649. {
  650. fInQuote = FALSE;
  651. pszOut[i] = *c;
  652. i++;
  653. c++;
  654. pszOut[i] = '\0';
  655. *ppszCmd = c;
  656. return;
  657. }
  658. else
  659. {
  660. pszOut[i] = *c;
  661. goto NextChar;
  662. }
  663. }
  664. //+----------------------------------------------------------------------------
  665. //
  666. // Function: ValidateProductSuite
  667. //
  668. // Synopsis: Check registry for a particular Product Suite string
  669. //
  670. // Arguments: SuiteName - name of product suite to look for
  671. //
  672. // Returns: TRUE - the suite exists
  673. //
  674. // History: 6/5/97 ChrisK Inherited
  675. //
  676. //-----------------------------------------------------------------------------
  677. BOOL
  678. ValidateProductSuite(LPTSTR SuiteName)
  679. {
  680. BOOL rVal = FALSE;
  681. LONG Rslt;
  682. HKEY hKey = NULL;
  683. DWORD Type = 0;
  684. DWORD Size = 0;
  685. LPTSTR ProductSuite = NULL;
  686. LPTSTR p;
  687. DEBUGMSG("INETCFG: ValidateProductSuite\n");
  688. //
  689. // Determine the size required to read registry values
  690. //
  691. Rslt = RegOpenKey(
  692. HKEY_LOCAL_MACHINE,
  693. TEXT("System\\CurrentControlSet\\Control\\ProductOptions"),
  694. &hKey
  695. );
  696. if (Rslt != ERROR_SUCCESS)
  697. {
  698. goto ValidateProductSuiteExit;
  699. }
  700. Rslt = RegQueryValueEx(
  701. hKey,
  702. TEXT("ProductSuite"),
  703. NULL,
  704. &Type,
  705. NULL,
  706. &Size
  707. );
  708. if (Rslt != ERROR_SUCCESS)
  709. {
  710. goto ValidateProductSuiteExit;
  711. }
  712. if (!Size)
  713. {
  714. goto ValidateProductSuiteExit;
  715. }
  716. ProductSuite = (LPTSTR) GlobalAlloc( GPTR, Size );
  717. if (!ProductSuite)
  718. {
  719. goto ValidateProductSuiteExit;
  720. }
  721. //
  722. // Read ProductSuite information
  723. //
  724. Rslt = RegQueryValueEx(
  725. hKey,
  726. TEXT("ProductSuite"),
  727. NULL,
  728. &Type,
  729. (LPBYTE) ProductSuite,
  730. &Size
  731. );
  732. if (Rslt != ERROR_SUCCESS)
  733. {
  734. goto ValidateProductSuiteExit;
  735. }
  736. if (Type != REG_MULTI_SZ)
  737. {
  738. goto ValidateProductSuiteExit;
  739. }
  740. //
  741. // Look for a particular string in the data returned
  742. // Note: data is terminiated with two NULLs
  743. //
  744. p = ProductSuite;
  745. while (*p) {
  746. if (_tcsstr( p, SuiteName ))
  747. {
  748. rVal = TRUE;
  749. break;
  750. }
  751. p += (lstrlen( p ) + 1);
  752. }
  753. ValidateProductSuiteExit:
  754. if (ProductSuite)
  755. {
  756. GlobalFree( ProductSuite );
  757. }
  758. if (hKey)
  759. {
  760. RegCloseKey( hKey );
  761. }
  762. return rVal;
  763. }
  764. //+----------------------------------------------------------------------------
  765. //
  766. // Function: GetFileVersion
  767. //
  768. // Synopsis: Gets the major and minor version # of a file
  769. //
  770. // Arguments: pdwVerNumMS - pointer to a DWORD;
  771. // On succesful return, the top 16 bits will contain the major version number,
  772. // and the lower 16 bits will contain the minor version number
  773. // (this is the data in VS_FIXEDFILEINFO.dwProductVersionMS)
  774. // pdwVerNumLS - pointer to a DWORD;
  775. // On succesful return, the top 16 bits will contain the release number,
  776. // and the lower 16 bits will contain the build number
  777. // (this is the data in VS_FIXEDFILEINFO.dwProductVersionLS)
  778. //
  779. // Returns: TRUE - Success. *pdwVerNumMS and LS contains version number
  780. // FALSE - Failure. *pdVerNumMS == *pdVerNumLS == 0
  781. //
  782. // History: jmazner Created 8/19/96 (as fix for Normandy #4571)
  783. // jmazner updated to deal with release.build as well 10/11/96
  784. // jmazner 7/22/97 ported from isign32 for bug 9903
  785. //
  786. //-----------------------------------------------------------------------------
  787. BOOL GetFileVersion(LPTSTR lpszFilePath, PDWORD pdwVerNumMS, PDWORD pdwVerNumLS)
  788. {
  789. HRESULT hr;
  790. HKEY hKey = 0;
  791. LPVOID lpVerInfoBlock;
  792. VS_FIXEDFILEINFO *lpTheVerInfo;
  793. UINT uTheVerInfoSize;
  794. DWORD dwVerInfoBlockSize, dwUnused, dwPathSize;
  795. DWORD fRet = TRUE;
  796. ASSERT( pdwVerNumMS );
  797. ASSERT( pdwVerNumLS );
  798. ASSERT( lpszFilePath );
  799. if( !pdwVerNumMS || !pdwVerNumLS || !lpszFilePath )
  800. {
  801. DEBUGMSG("GetFileVersion: invalid parameters!");
  802. return FALSE;
  803. }
  804. *pdwVerNumMS = 0;
  805. *pdwVerNumLS = 0;
  806. //
  807. // go through the convoluted process of digging up the version info
  808. //
  809. dwVerInfoBlockSize = GetFileVersionInfoSize( lpszFilePath, &dwUnused );
  810. if ( 0 == dwVerInfoBlockSize ) return( FALSE );
  811. lpVerInfoBlock = GlobalAlloc( GPTR, dwVerInfoBlockSize );
  812. if( NULL == lpVerInfoBlock ) return( FALSE );
  813. if( !GetFileVersionInfo( lpszFilePath, NULL, dwVerInfoBlockSize, lpVerInfoBlock ) )
  814. {
  815. fRet = FALSE;
  816. goto GetFileVersionExit;
  817. }
  818. if( !VerQueryValue(lpVerInfoBlock, TEXT("\\"), (void **)&lpTheVerInfo, &uTheVerInfoSize) )
  819. {
  820. fRet = FALSE;
  821. goto GetFileVersionExit;
  822. }
  823. *pdwVerNumMS = lpTheVerInfo->dwProductVersionMS;
  824. *pdwVerNumLS = lpTheVerInfo->dwProductVersionLS;
  825. GetFileVersionExit:
  826. if( lpVerInfoBlock )
  827. {
  828. GlobalFree( lpVerInfoBlock );
  829. lpVerInfoBlock = NULL;
  830. }
  831. return( fRet );
  832. }
  833. //+----------------------------------------------------------------------------
  834. //
  835. // Function: ExtractFilenameFromPath
  836. //
  837. // Synopsis: Divides a full path into path and filename parts
  838. //
  839. // Arguments:
  840. // szPath [in] -- fully qualified path and filename
  841. // lplpszFilename [in] -- pointer to a LPSTR. On entry, the LPSTR
  842. // to which it points should be NULL.
  843. // lplpszFilename [out] -- The LPSTR to which it points is set to the
  844. // first character of the filename in szPath.
  845. //
  846. //
  847. // Returns: FALSE - Parameters are invalid.
  848. // TRUE - Success.
  849. //
  850. // History: 7/22/97 jmazner Created for Olympus #9903
  851. //
  852. //-----------------------------------------------------------------------------
  853. BOOL ExtractFilenameFromPath( TCHAR szPath[MAX_PATH + 1], LPTSTR *lplpszFilename )
  854. {
  855. ASSERT( szPath[0] );
  856. ASSERT( lplpszFilename );
  857. ASSERT( *lplpszFilename == NULL );
  858. if( !szPath[0] || !lplpszFilename )
  859. {
  860. return FALSE;
  861. }
  862. //
  863. // extract the executable name from the full path
  864. //
  865. *lplpszFilename = &(szPath[ lstrlen(szPath) ]);
  866. while( ('\\' != **lplpszFilename) && (*lplpszFilename > szPath) )
  867. {
  868. *lplpszFilename = CharPrev( szPath, *lplpszFilename );
  869. ASSERT( *lplpszFilename > szPath );
  870. }
  871. //
  872. // now szFilename should point to the \, so do a char next.
  873. //
  874. if( '\\' == **lplpszFilename )
  875. {
  876. *lplpszFilename = CharNext( *lplpszFilename );
  877. }
  878. else
  879. {
  880. DEBUGMSG("ExtractFilenameFromPath: bogus path passed in, %s", szPath);
  881. return FALSE;
  882. }
  883. return TRUE;
  884. }
  885. //+----------------------------------------------------------------------------
  886. //
  887. // Function: IsParentICW10
  888. //
  889. // Synopsis: Determines whether the parent of this module is an ICW 1.0
  890. // executable (isignup, icwconn1, icwconn2 or inetwiz)
  891. //
  892. // Arguments: none
  893. //
  894. // Returns: TRUE - Parent module is an ICW 1.0 component
  895. // FALSE - Parent module is not an ICW 1.0 component, -or-
  896. // parent module could not be determined
  897. //
  898. // History: 7/22/97 jmazner Created for Olympus #9903
  899. //
  900. //-----------------------------------------------------------------------------
  901. BOOL IsParentICW10( )
  902. {
  903. HMODULE hParentModule = GetModuleHandle( NULL );
  904. LPTSTR lpszParentFullPath = NULL;
  905. LPTSTR lpszTemp = NULL;
  906. int i = 0;
  907. BOOL fMatchFound = FALSE;
  908. BOOL fRet = FALSE;
  909. lpszParentFullPath = (LPTSTR)GlobalAlloc(GPTR, (MAX_PATH + 1)*sizeof(TCHAR));
  910. if( NULL == lpszParentFullPath )
  911. {
  912. DEBUGMSG("IsParentICW10 Out of memory!");
  913. goto IsParentICW10Exit;
  914. }
  915. GetModuleFileName( hParentModule, lpszParentFullPath, MAX_PATH );
  916. DEBUGMSG("IsParentICW10 parent module is %s", lpszParentFullPath);
  917. if( NULL == lpszParentFullPath[0] )
  918. {
  919. fRet = FALSE;
  920. goto IsParentICW10Exit;
  921. }
  922. ExtractFilenameFromPath( lpszParentFullPath, &lpszTemp );
  923. //
  924. // walk through the array of ICW binary names, see if anything matches
  925. //
  926. for( i = 0; i < NUMICWFILENAMES; i++ )
  927. {
  928. if ( 0 == lstrcmpi(g_ppszICWFileNames[i], lpszTemp) )
  929. {
  930. fMatchFound = TRUE;
  931. DEBUGMSG("IsParentICW10 Match found for %s", lpszTemp);
  932. break;
  933. }
  934. }
  935. if( !fMatchFound )
  936. {
  937. fRet = FALSE;
  938. goto IsParentICW10Exit;
  939. }
  940. else
  941. {
  942. //
  943. // we have one of the four binaries we're interested in; now check
  944. // its version number
  945. //
  946. DWORD dwMS = 0;
  947. DWORD dwLS = 0;
  948. GetFileVersion( lpszParentFullPath, &dwMS, &dwLS );
  949. DEBUGMSG("IsParentICW10: file version is %d.%d", HIWORD(dwMS), LOWORD(dwMS) );
  950. if( dwMS < ICW_MINIMUM_VERSIONMS )
  951. {
  952. fRet = TRUE;
  953. }
  954. }
  955. IsParentICW10Exit:
  956. if( lpszParentFullPath )
  957. {
  958. GlobalFree( lpszParentFullPath );
  959. lpszParentFullPath = NULL;
  960. }
  961. return fRet;
  962. }
  963. //+----------------------------------------------------------------------------
  964. //
  965. // Function: SetICWRegKeysToPath
  966. //
  967. // Synopsis: Sets all ICW reg keys to point to binaries in the given path
  968. //
  969. // Arguments: lpszICWPath -- pointer to a string containing the full path
  970. // to a directory containing ICW components
  971. //
  972. // Returns: void
  973. //
  974. // Notes: Sets the following reg keys:
  975. // HKCR\x-internet-signup\Shell\Open\command, (default)=[path]\isignup.exe %1
  976. // HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ICWCONN1.EXE, (default) = [path]\ICWCONN1.EXE
  977. // HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ICWCONN1.EXE, Path = [path];
  978. // HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ISIGNUP.EXE, (default) = [path]\ISIGNUP.EXE
  979. // HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ISIGNUP.EXE, Path = [path];
  980. // HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\INETWIZ.EXE, (default) = [path]\INETWIZ.EXE
  981. // HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\INETWIZ.EXE, Path = [path];
  982. // HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ICWCONN2.EXE, (default) = [path]\ICWCONN2.EXE
  983. // HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ICWCONN2.EXE, Path = [path];
  984. //
  985. // History: 7/22/97 jmazner Created for Olympus #9903
  986. //
  987. //-----------------------------------------------------------------------------
  988. void SetICWRegKeysToPath( LPTSTR lpszICWPath )
  989. {
  990. DWORD dwResult = ERROR_SUCCESS;
  991. TCHAR szBuffer[MAX_PATH + 4];
  992. TCHAR szAppPathsBuffer[MAX_PATH + 1];
  993. TCHAR szThePath[MAX_PATH + 2];
  994. UINT i=0;
  995. ASSERT( lpszICWPath );
  996. if( !lpszICWPath )
  997. {
  998. DEBUGMSG("SetICWRegKeysToPath: invalid parameter!!");
  999. return;
  1000. }
  1001. //
  1002. // make sure last character is neither \ nor ;
  1003. //
  1004. switch( lpszICWPath[lstrlen(lpszICWPath) - 1] )
  1005. {
  1006. case '\\':
  1007. case ';':
  1008. ASSERTSZ(0, "Path given to SetICWRegKeysToPath is a bit malformed!");
  1009. lpszICWPath[lstrlen(lpszICWPath) - 1] = '\0';
  1010. }
  1011. //
  1012. // HKCR\x-internet-signup\Shell\Open\command, (default)=path\isignup.exe %1
  1013. //
  1014. DEBUGMSG("SetICWRegKeysToPath: setting %s", cszRegPathXInternetSignup);
  1015. lstrcpy( szBuffer, lpszICWPath );
  1016. lstrcat( szBuffer, TEXT("\\") );
  1017. lstrcat( szBuffer, szISignupICWFileName );
  1018. lstrcat( szBuffer, TEXT(" %1"));
  1019. RegEntry re(cszRegPathXInternetSignup,HKEY_CLASSES_ROOT);
  1020. dwResult = re.GetError();
  1021. if (ERROR_SUCCESS == dwResult)
  1022. {
  1023. re.SetValue(NULL, szBuffer);
  1024. DEBUGMSG("SetICWRegKeysToPath: set %s, %s = %s (error %d)",
  1025. cszRegPathXInternetSignup, "(default)", szBuffer, re.GetError());
  1026. }
  1027. else
  1028. {
  1029. DEBUGMSG("SetICWRegKeysToPath: FAILED with %d: %s, NULL = %s",
  1030. dwResult, cszRegPathXInternetSignup, szBuffer);
  1031. }
  1032. //
  1033. // HKLM\software\microsoft\windows\currentVersion\App Paths
  1034. //
  1035. DEBUGMSG("SetICWRegKeysToPath: setting %s", cszRegPathAppPaths);
  1036. lstrcpy( szThePath, lpszICWPath );
  1037. lstrcat( szThePath, TEXT(";") );
  1038. for( i=0; i<NUMICWFILENAMES; i++ )
  1039. {
  1040. lstrcpy( szAppPathsBuffer, cszRegPathAppPaths );
  1041. lstrcat( szAppPathsBuffer, TEXT("\\"));
  1042. lstrcat( szAppPathsBuffer, g_ppszICWFileNames[i] );
  1043. lstrcpy( szBuffer, lpszICWPath );
  1044. lstrcat( szBuffer, TEXT("\\") );
  1045. lstrcat( szBuffer, g_ppszICWFileNames[i] );
  1046. RegEntry re(szAppPathsBuffer,HKEY_LOCAL_MACHINE);
  1047. dwResult = re.GetError();
  1048. if (ERROR_SUCCESS == dwResult)
  1049. {
  1050. re.SetValue(NULL, szBuffer);
  1051. DEBUGMSG("SetICWRegKeysToPath: set %s, %s = %s (error %d)",
  1052. szAppPathsBuffer, TEXT("(default)"), szBuffer, re.GetError());
  1053. re.SetValue(cszPath, szThePath);
  1054. DEBUGMSG("SetICWRegKeysToPath: set %s, %s = %s (error %d)",
  1055. szAppPathsBuffer, cszPath, szThePath, re.GetError());
  1056. }
  1057. else
  1058. {
  1059. DEBUGMSG("SetICWRegKeysToPath: FAILED with %d: %s, NULL = %s",
  1060. dwResult, szAppPathsBuffer, szBuffer);
  1061. }
  1062. }
  1063. }
  1064. //+----------------------------------------------------------------------------
  1065. //
  1066. // Function: GetICW11Path
  1067. //
  1068. // Synopsis: Finds the path to the ICW 1.1 installation directory
  1069. //
  1070. // Arguments:
  1071. // szPath [out] -- on succesfull exit, contains path to ICW 1.1
  1072. // directory. Path does _not_ terminate in \ or ;
  1073. // fPathSetTo11 [out] -- indicates whether the App Paths\ICWCONN1.EXE
  1074. // currently points to the ICW 1.1 installation
  1075. // directory
  1076. //
  1077. // Returns:
  1078. // Function results are determined by looking at both parameters
  1079. // szPath: "", *fPathSetTo11: FALSE indicates App Paths\Icwconn1 does not
  1080. // currently point to 1.1 files, and that a path to the 1.1
  1081. // files could not be determined
  1082. //
  1083. // szPath: non-empty, *fPathSetTo11: FALSE indicates App Paths\ICWCONN1
  1084. // does not currently point to 1.1 files. The path to the 1.1 files
  1085. // is contained in szPath
  1086. //
  1087. // szPath: non-empty, *fPathSetTo11: TRUE indicates that App Path\ICWCONN1
  1088. // currently points to 1.1 files. The path to the files is contained
  1089. // in szPath
  1090. //
  1091. //
  1092. // History: 7/22/97 jmazner Created for Olympus #9903
  1093. //
  1094. //-----------------------------------------------------------------------------
  1095. void GetICW11Path( TCHAR szPath[MAX_PATH + 1], BOOL *fPathSetTo11 )
  1096. {
  1097. TCHAR szAppPathsBuffer[MAX_PATH + 1];
  1098. LPTSTR lpszTemp = NULL;
  1099. DWORD dwResult = ERROR_SUCCESS;
  1100. DWORD dwMS = 0;
  1101. DWORD dwLS = 0;
  1102. ASSERT( fPathSetTo11 );
  1103. ASSERT( szPath );
  1104. if( !fPathSetTo11 || !szPath )
  1105. {
  1106. DEBUGMSG("GetICW11Path: invalid parameter!");
  1107. return;
  1108. }
  1109. ZeroMemory( szPath, sizeof(szPath) );
  1110. *fPathSetTo11 = FALSE;
  1111. //
  1112. // first let's check whether the App Path for ICW is currently pointing
  1113. // to the 1.1 files
  1114. //
  1115. lstrcpy( szAppPathsBuffer, cszRegPathAppPaths );
  1116. lstrcat( szAppPathsBuffer, TEXT("\\"));
  1117. lstrcat( szAppPathsBuffer, g_ppszICWFileNames[0] );
  1118. RegEntry reICWAppPath(szAppPathsBuffer, HKEY_LOCAL_MACHINE);
  1119. dwResult = reICWAppPath.GetError();
  1120. if (ERROR_SUCCESS == dwResult)
  1121. {
  1122. reICWAppPath.GetString(NULL, szPath, sizeof(TCHAR)*(MAX_PATH + 1));
  1123. }
  1124. if( szPath[0] )
  1125. {
  1126. GetFileVersion( szPath, &dwMS, &dwLS );
  1127. DEBUGMSG("GetICW11Path: reg key %s = %s, which has file version %d.%d",
  1128. szAppPathsBuffer, szPath, HIWORD(dwMS), LOWORD(dwMS) );
  1129. if( dwMS >= ICW_MINIMUM_VERSIONMS )
  1130. {
  1131. //
  1132. // App Path is already pointing to 1.1 binaries!
  1133. //
  1134. *fPathSetTo11 = TRUE;
  1135. //
  1136. // for completness' sake, strip the .exe name out of
  1137. // szPath so that it will in fact contain just the path
  1138. // to the ICW 1.1 files.
  1139. ExtractFilenameFromPath( szPath, &lpszTemp );
  1140. szPath[lstrlen(szPath) - lstrlen(lpszTemp) - 1] = '\0';
  1141. //
  1142. // return values:
  1143. // szPath = path to ICW 1.1 binaries, no terminating \ or ;
  1144. // fPathSetTo11 = TRUE
  1145. //
  1146. return;
  1147. }
  1148. }
  1149. else
  1150. {
  1151. DEBUGMSG("GetICW11Path: unable to read current AppPath key %s", szAppPathsBuffer);
  1152. }
  1153. //
  1154. // look for the Installation Directory value in
  1155. // HKLM\Software\Microsoft\Internet Connection Wizard
  1156. // If it's there, it should point to the directory where the
  1157. // 1.1 binaries are installed.
  1158. //
  1159. RegEntry re11Path(szRegPathICWSettings, HKEY_LOCAL_MACHINE);
  1160. dwResult = re11Path.GetError();
  1161. if (ERROR_SUCCESS == dwResult)
  1162. {
  1163. re11Path.GetString(cszInstallationDirectory, szPath, sizeof(TCHAR)*(MAX_PATH + 1));
  1164. }
  1165. if( NULL == szPath[0] )
  1166. {
  1167. DEBUGMSG("GetICW11Path: unable to read reg key %s", szRegPathICWSettings);
  1168. //
  1169. // return values:
  1170. // szPath = ""
  1171. // fPathSetTo11 = FALSE
  1172. //
  1173. return;
  1174. }
  1175. else
  1176. {
  1177. DEBUGMSG("GetICW11Path: %s, %s = %s",
  1178. szRegPathICWSettings, cszInstallationDirectory, szPath);
  1179. //
  1180. // okay, we got a path -- now let's make sure that the thing
  1181. // it points to is in fact a 1.1 binary.
  1182. //
  1183. //
  1184. // chop off the terminating semicolon if it's there
  1185. //
  1186. if( ';' == szPath[ lstrlen(szPath) ] )
  1187. {
  1188. szPath[ lstrlen(szPath) ] = '\0';
  1189. }
  1190. //
  1191. // do we have a terminating \ now? if not, add it in
  1192. //
  1193. if( '\\' != szPath[ lstrlen(szPath) ] )
  1194. {
  1195. lstrcat( szPath, TEXT("\\") );
  1196. }
  1197. //
  1198. // add in a binary filename to use for the version check
  1199. // (just use whatever's first in our filename array)
  1200. //
  1201. lstrcat( szPath, g_ppszICWFileNames[0] );
  1202. //
  1203. // now check the version number of the file
  1204. //
  1205. GetFileVersion( szPath, &dwMS, &dwLS );
  1206. DEBUGMSG("GetICW11Path: %s has file version %d.%d",
  1207. szPath, HIWORD(dwMS), LOWORD(dwMS) );
  1208. if( dwMS >= ICW_MINIMUM_VERSIONMS )
  1209. {
  1210. //
  1211. // Yes, this path is valid!
  1212. // now hack off the filename so that we're back to just a
  1213. // path with no terminating \ or ;
  1214. //
  1215. ExtractFilenameFromPath( szPath, &lpszTemp );
  1216. szPath[lstrlen(szPath) - lstrlen(lpszTemp) - 1] = '\0';
  1217. //
  1218. // return values:
  1219. // szPath = path to ICW 1.1 binaries, no terminating \ or ;
  1220. // fPathSetTo11 = FALSE
  1221. //
  1222. return;
  1223. }
  1224. else
  1225. {
  1226. DEBUGMSG("GetICW11Path %s doesn't actually point to a 1.1 binary!",
  1227. szPath);
  1228. szPath[0] = '\0';
  1229. //
  1230. // return values:
  1231. // szPath = ""
  1232. // fPathSetTo11 = FALSE
  1233. //
  1234. return;
  1235. }
  1236. }
  1237. }
  1238. #ifdef UNICODE
  1239. PWCHAR ToUnicodeWithAlloc
  1240. (
  1241. LPCSTR lpszSrc
  1242. )
  1243. {
  1244. PWCHAR lpWChar;
  1245. INT iLength = 0;
  1246. DWORD dwResult;
  1247. if (lpszSrc == NULL)
  1248. {
  1249. return NULL;
  1250. }
  1251. iLength = MultiByteToWideChar( CP_ACP,
  1252. 0,
  1253. lpszSrc,
  1254. -1,
  1255. NULL,
  1256. 0 );
  1257. if(iLength == 0)
  1258. return NULL;
  1259. lpWChar = (WCHAR *) GlobalAlloc( GPTR, sizeof(WCHAR) * iLength );
  1260. if(!lpWChar)
  1261. return NULL;
  1262. dwResult = MultiByteToWideChar( CP_ACP,
  1263. 0,
  1264. lpszSrc,
  1265. -1,
  1266. lpWChar,
  1267. iLength );
  1268. if(!dwResult)
  1269. {
  1270. GlobalFree(lpWChar);
  1271. return NULL;
  1272. }
  1273. return lpWChar;
  1274. }
  1275. VOID ToAnsiClientInfo
  1276. (
  1277. LPINETCLIENTINFOA lpInetClientInfoA,
  1278. LPINETCLIENTINFOW lpInetClientInfoW
  1279. )
  1280. {
  1281. if(lpInetClientInfoW == NULL || lpInetClientInfoA == NULL)
  1282. return;
  1283. lpInetClientInfoA->dwSize = lpInetClientInfoW->dwSize;
  1284. lpInetClientInfoA->dwFlags = lpInetClientInfoW->dwFlags;
  1285. lpInetClientInfoA->iIncomingProtocol = lpInetClientInfoW->iIncomingProtocol;
  1286. lpInetClientInfoA->fMailLogonSPA = lpInetClientInfoW->fMailLogonSPA;
  1287. lpInetClientInfoA->fNewsLogonSPA = lpInetClientInfoW->fNewsLogonSPA;
  1288. lpInetClientInfoA->fLDAPLogonSPA = lpInetClientInfoW->fLDAPLogonSPA;
  1289. lpInetClientInfoA->fLDAPResolve = lpInetClientInfoW->fLDAPResolve;
  1290. wcstombs(lpInetClientInfoA->szEMailName,
  1291. lpInetClientInfoW->szEMailName,
  1292. MAX_EMAIL_NAME+1);
  1293. wcstombs(lpInetClientInfoA->szEMailAddress,
  1294. lpInetClientInfoW->szEMailAddress,
  1295. MAX_EMAIL_ADDRESS+1);
  1296. wcstombs(lpInetClientInfoA->szPOPLogonName,
  1297. lpInetClientInfoW->szPOPLogonName,
  1298. MAX_LOGON_NAME+1);
  1299. wcstombs(lpInetClientInfoA->szPOPLogonPassword,
  1300. lpInetClientInfoW->szPOPLogonPassword,
  1301. MAX_LOGON_PASSWORD+1);
  1302. wcstombs(lpInetClientInfoA->szPOPServer,
  1303. lpInetClientInfoW->szPOPServer,
  1304. MAX_SERVER_NAME+1);
  1305. wcstombs(lpInetClientInfoA->szSMTPServer,
  1306. lpInetClientInfoW->szSMTPServer,
  1307. MAX_SERVER_NAME+1);
  1308. wcstombs(lpInetClientInfoA->szNNTPLogonName,
  1309. lpInetClientInfoW->szNNTPLogonName,
  1310. MAX_LOGON_NAME+1);
  1311. wcstombs(lpInetClientInfoA->szNNTPLogonPassword,
  1312. lpInetClientInfoW->szNNTPLogonPassword,
  1313. MAX_LOGON_PASSWORD+1);
  1314. wcstombs(lpInetClientInfoA->szNNTPServer,
  1315. lpInetClientInfoW->szNNTPServer,
  1316. MAX_SERVER_NAME+1);
  1317. wcstombs(lpInetClientInfoA->szNNTPName,
  1318. lpInetClientInfoW->szNNTPName,
  1319. MAX_EMAIL_NAME+1);
  1320. wcstombs(lpInetClientInfoA->szNNTPAddress,
  1321. lpInetClientInfoW->szNNTPAddress,
  1322. MAX_EMAIL_ADDRESS+1);
  1323. wcstombs(lpInetClientInfoA->szIncomingMailLogonName,
  1324. lpInetClientInfoW->szIncomingMailLogonName,
  1325. MAX_LOGON_NAME+1);
  1326. wcstombs(lpInetClientInfoA->szIncomingMailLogonPassword,
  1327. lpInetClientInfoW->szIncomingMailLogonPassword,
  1328. MAX_LOGON_PASSWORD+1);
  1329. wcstombs(lpInetClientInfoA->szIncomingMailServer,
  1330. lpInetClientInfoW->szIncomingMailServer,
  1331. MAX_SERVER_NAME+1);
  1332. wcstombs(lpInetClientInfoA->szLDAPLogonName,
  1333. lpInetClientInfoW->szLDAPLogonName,
  1334. MAX_LOGON_NAME+1);
  1335. wcstombs(lpInetClientInfoA->szLDAPLogonPassword,
  1336. lpInetClientInfoW->szLDAPLogonPassword,
  1337. MAX_LOGON_PASSWORD+1);
  1338. wcstombs(lpInetClientInfoA->szLDAPServer,
  1339. lpInetClientInfoW->szLDAPServer,
  1340. MAX_SERVER_NAME+1);
  1341. }
  1342. VOID ToUnicodeClientInfo
  1343. (
  1344. LPINETCLIENTINFOW lpInetClientInfoW,
  1345. LPINETCLIENTINFOA lpInetClientInfoA
  1346. )
  1347. {
  1348. if(lpInetClientInfoW == NULL || lpInetClientInfoA == NULL)
  1349. return;
  1350. lpInetClientInfoW->dwSize = lpInetClientInfoA->dwSize;
  1351. lpInetClientInfoW->dwFlags = lpInetClientInfoA->dwFlags;
  1352. lpInetClientInfoW->iIncomingProtocol = lpInetClientInfoA->iIncomingProtocol;
  1353. lpInetClientInfoW->fMailLogonSPA = lpInetClientInfoA->fMailLogonSPA;
  1354. lpInetClientInfoW->fNewsLogonSPA = lpInetClientInfoA->fNewsLogonSPA;
  1355. lpInetClientInfoW->fLDAPLogonSPA = lpInetClientInfoA->fLDAPLogonSPA;
  1356. lpInetClientInfoW->fLDAPResolve = lpInetClientInfoA->fLDAPResolve;
  1357. mbstowcs(lpInetClientInfoW->szEMailName,
  1358. lpInetClientInfoA->szEMailName,
  1359. lstrlenA(lpInetClientInfoA->szEMailName)+1);
  1360. mbstowcs(lpInetClientInfoW->szEMailAddress,
  1361. lpInetClientInfoA->szEMailAddress,
  1362. lstrlenA(lpInetClientInfoA->szEMailAddress)+1);
  1363. mbstowcs(lpInetClientInfoW->szPOPLogonName,
  1364. lpInetClientInfoA->szPOPLogonName,
  1365. lstrlenA(lpInetClientInfoA->szPOPLogonName)+1);
  1366. mbstowcs(lpInetClientInfoW->szPOPLogonPassword,
  1367. lpInetClientInfoA->szPOPLogonPassword,
  1368. lstrlenA(lpInetClientInfoA->szPOPLogonPassword)+1);
  1369. mbstowcs(lpInetClientInfoW->szPOPServer,
  1370. lpInetClientInfoA->szPOPServer,
  1371. lstrlenA(lpInetClientInfoA->szPOPServer)+1);
  1372. mbstowcs(lpInetClientInfoW->szSMTPServer,
  1373. lpInetClientInfoA->szSMTPServer,
  1374. lstrlenA(lpInetClientInfoA->szSMTPServer)+1);
  1375. mbstowcs(lpInetClientInfoW->szNNTPLogonName,
  1376. lpInetClientInfoA->szNNTPLogonName,
  1377. lstrlenA(lpInetClientInfoA->szNNTPLogonName)+1);
  1378. mbstowcs(lpInetClientInfoW->szNNTPLogonPassword,
  1379. lpInetClientInfoA->szNNTPLogonPassword,
  1380. lstrlenA(lpInetClientInfoA->szNNTPLogonPassword)+1);
  1381. mbstowcs(lpInetClientInfoW->szNNTPServer,
  1382. lpInetClientInfoA->szNNTPServer,
  1383. lstrlenA(lpInetClientInfoA->szNNTPServer)+1);
  1384. mbstowcs(lpInetClientInfoW->szNNTPName,
  1385. lpInetClientInfoA->szNNTPName,
  1386. lstrlenA(lpInetClientInfoA->szNNTPName)+1);
  1387. mbstowcs(lpInetClientInfoW->szNNTPAddress,
  1388. lpInetClientInfoA->szNNTPAddress,
  1389. lstrlenA(lpInetClientInfoA->szNNTPAddress)+1);
  1390. mbstowcs(lpInetClientInfoW->szIncomingMailLogonName,
  1391. lpInetClientInfoA->szIncomingMailLogonName,
  1392. lstrlenA(lpInetClientInfoA->szIncomingMailLogonName)+1);
  1393. mbstowcs(lpInetClientInfoW->szIncomingMailLogonPassword,
  1394. lpInetClientInfoA->szIncomingMailLogonPassword,
  1395. lstrlenA(lpInetClientInfoA->szIncomingMailLogonPassword)+1);
  1396. mbstowcs(lpInetClientInfoW->szIncomingMailServer,
  1397. lpInetClientInfoA->szIncomingMailServer,
  1398. lstrlenA(lpInetClientInfoA->szIncomingMailServer)+1);
  1399. mbstowcs(lpInetClientInfoW->szLDAPLogonName,
  1400. lpInetClientInfoA->szLDAPLogonName,
  1401. lstrlenA(lpInetClientInfoA->szLDAPLogonName)+1);
  1402. mbstowcs(lpInetClientInfoW->szLDAPLogonPassword,
  1403. lpInetClientInfoA->szLDAPLogonPassword,
  1404. lstrlenA(lpInetClientInfoA->szLDAPLogonPassword)+1);
  1405. mbstowcs(lpInetClientInfoW->szLDAPServer,
  1406. lpInetClientInfoA->szLDAPServer,
  1407. lstrlenA(lpInetClientInfoA->szLDAPServer)+1);
  1408. }
  1409. #endif