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.

1578 lines
48 KiB

  1. /*-----------------------------------------------------------------------------
  2. misc.cpp
  3. service functions
  4. History:
  5. 1/7/98 DONALDM Moved to new ICW project and string
  6. and nuked 16 bit stuff
  7. -----------------------------------------------------------------------------*/
  8. #include "stdafx.h"
  9. #include <stdio.h>
  10. #if defined (DEBUG)
  11. #include "refdial.h"
  12. #endif
  13. #define DIR_SIGNUP TEXT("signup")
  14. #define DIR_WINDOWS TEXT("windows")
  15. #define DIR_SYSTEM TEXT("system")
  16. #define DIR_TEMP TEXT("temp")
  17. BOOL g_bGotProxy=FALSE;
  18. #if defined (DEBUG)
  19. extern TCHAR g_BINTOHEXLookup[16];
  20. #endif
  21. //+---------------------------------------------------------------------------
  22. //
  23. // Function: ProcessDBCS
  24. //
  25. // Synopsis: Converts control to use DBCS compatible font
  26. // Use this at the beginning of the dialog procedure
  27. //
  28. // Note that this is required due to a bug in Win95-J that prevents
  29. // it from properly mapping MS Shell Dlg. This hack is not needed
  30. // under winNT.
  31. //
  32. // Arguments: hwnd - Window handle of the dialog
  33. // cltID - ID of the control you want changed.
  34. //
  35. // Returns: ERROR_SUCCESS
  36. //
  37. // History: 4/31/97 a-frankh Created
  38. // 5/13/97 jmazner Stole from CM to use here
  39. //----------------------------------------------------------------------------
  40. void ProcessDBCS(HWND hDlg, int ctlID)
  41. {
  42. HFONT hFont = NULL;
  43. if( IsNT() )
  44. {
  45. return;
  46. }
  47. hFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
  48. if (hFont == NULL)
  49. hFont = (HFONT) GetStockObject(SYSTEM_FONT);
  50. if (hFont != NULL)
  51. SendMessage(GetDlgItem(hDlg,ctlID), WM_SETFONT, (WPARAM) hFont, MAKELPARAM(TRUE, 0));
  52. }
  53. // ############################################################################
  54. // StoreInSignUpReg
  55. //
  56. // Created 3/18/96, Chris Kauffman
  57. // ############################################################################
  58. HRESULT StoreInSignUpReg(LPBYTE lpbData, DWORD dwSize, DWORD dwType, LPCTSTR pszKey)
  59. {
  60. HRESULT hr = ERROR_ACCESS_DENIED;
  61. HKEY hKey;
  62. hr = RegCreateKey(HKEY_LOCAL_MACHINE,SIGNUPKEY,&hKey);
  63. if (hr != ERROR_SUCCESS) goto StoreInSignUpRegExit;
  64. hr = RegSetValueEx(hKey,pszKey,0,dwType,lpbData,sizeof(TCHAR)*dwSize);
  65. RegCloseKey(hKey);
  66. StoreInSignUpRegExit:
  67. return hr;
  68. }
  69. HRESULT ReadSignUpReg(LPBYTE lpbData, DWORD *pdwSize, DWORD dwType, LPCTSTR pszKey)
  70. {
  71. HRESULT hr = ERROR_ACCESS_DENIED;
  72. HKEY hKey = 0;
  73. hr = RegOpenKey(HKEY_LOCAL_MACHINE,SIGNUPKEY,&hKey);
  74. if (hr != ERROR_SUCCESS) goto ReadSignUpRegExit;
  75. hr = RegQueryValueEx(hKey,pszKey,0,&dwType,lpbData,pdwSize);
  76. ReadSignUpRegExit:
  77. if (hKey) RegCloseKey (hKey);
  78. return hr;
  79. }
  80. // ############################################################################
  81. // GetDataFromISPFile
  82. //
  83. // This function will read a specific piece of information from an ISP file.
  84. //
  85. // Created 3/16/96, Chris Kauffman
  86. // ############################################################################
  87. HRESULT GetDataFromISPFile
  88. (
  89. LPTSTR pszISPCode,
  90. LPTSTR pszSection,
  91. LPTSTR pszDataName,
  92. LPTSTR pszOutput,
  93. DWORD dwOutputLength)
  94. {
  95. LPTSTR pszTemp;
  96. HRESULT hr = ERROR_SUCCESS;
  97. TCHAR szTempPath[MAX_PATH];
  98. TCHAR szBuff256[256];
  99. // Locate ISP file
  100. if (!SearchPath(NULL,pszISPCode,INF_SUFFIX,MAX_PATH,szTempPath,&pszTemp))
  101. {
  102. wsprintf(szBuff256,TEXT("Can not find:%s%s (%d) (connect.exe)"),pszISPCode,INF_SUFFIX,GetLastError());
  103. AssertMsg(0,szBuff256);
  104. lstrcpyn(szTempPath,pszISPCode,MAX_PATH);
  105. lstrcpyn(&szTempPath[lstrlen(szTempPath)],INF_SUFFIX,MAX_PATH-lstrlen(szTempPath));
  106. wsprintf(szBuff256,GetSz(IDS_CANTLOADINETCFG),szTempPath);
  107. MessageBox(NULL,szBuff256,GetSz(IDS_TITLE),MB_MYERROR);
  108. hr = ERROR_FILE_NOT_FOUND;
  109. } else if (!GetPrivateProfileString(pszSection,pszDataName,INF_DEFAULT,
  110. pszOutput, (int)dwOutputLength,szTempPath))
  111. {
  112. TraceMsg(TF_GENERAL, TEXT("ICWHELP: %s not specified in ISP file.\n"),pszDataName);
  113. hr = ERROR_FILE_NOT_FOUND;
  114. }
  115. // 10/23/96 jmazner Normandy #9921
  116. // CompareString does _not_ have same return values as lsrtcmp!
  117. // Return value of 2 indicates strings are equal.
  118. //if (!CompareString(LOCALE_SYSTEM_DEFAULT,0,INF_DEFAULT,lstrlen(INF_DEFAULT),pszOutput,lstrlen(pszOutput)))
  119. if (2 == CompareString(LOCALE_SYSTEM_DEFAULT,0,INF_DEFAULT,lstrlen(INF_DEFAULT),pszOutput,lstrlen(pszOutput)))
  120. {
  121. hr = ERROR_FILE_NOT_FOUND;
  122. }
  123. if (hr != ERROR_SUCCESS && dwOutputLength)
  124. *pszOutput = TEXT('\0');
  125. return hr;
  126. }
  127. // ############################################################################
  128. // GetINTFromISPFile
  129. //
  130. // This function will read a specific integer from an ISP file.
  131. //
  132. //
  133. // ############################################################################
  134. HRESULT GetINTFromISPFile
  135. (
  136. LPTSTR pszISPCode,
  137. LPTSTR pszSection,
  138. LPTSTR pszDataName,
  139. int far *lpData,
  140. int iDefaultValue
  141. )
  142. {
  143. LPTSTR pszTemp;
  144. HRESULT hr = ERROR_SUCCESS;
  145. TCHAR szTempPath[MAX_PATH];
  146. TCHAR szBuff256[256];
  147. // Locate ISP file
  148. if (!SearchPath(NULL,pszISPCode,INF_SUFFIX,MAX_PATH,szTempPath,&pszTemp))
  149. {
  150. wsprintf(szBuff256,TEXT("Can not find:%s%s (%d) (connect.exe)"),pszISPCode,INF_SUFFIX,GetLastError());
  151. AssertMsg(0,szBuff256);
  152. lstrcpyn(szTempPath,pszISPCode,MAX_PATH);
  153. lstrcpyn(&szTempPath[lstrlen(szTempPath)],INF_SUFFIX,MAX_PATH-lstrlen(szTempPath));
  154. wsprintf(szBuff256,GetSz(IDS_CANTLOADINETCFG),szTempPath);
  155. MessageBox(NULL,szBuff256,GetSz(IDS_TITLE),MB_MYERROR);
  156. hr = ERROR_FILE_NOT_FOUND;
  157. }
  158. *lpData = GetPrivateProfileInt(pszSection,
  159. pszDataName,
  160. iDefaultValue,
  161. szTempPath);
  162. return hr;
  163. }
  164. //+-------------------------------------------------------------------
  165. //
  166. // Function: IsNT
  167. //
  168. // Synopsis: findout If we are running on NT
  169. //
  170. // Arguements: none
  171. //
  172. // Return: TRUE - Yes
  173. // FALSE - No
  174. //
  175. //--------------------------------------------------------------------
  176. BOOL
  177. IsNT (
  178. VOID
  179. )
  180. {
  181. OSVERSIONINFO OsVersionInfo;
  182. ZeroMemory(&OsVersionInfo, sizeof(OSVERSIONINFO));
  183. OsVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  184. GetVersionEx(&OsVersionInfo);
  185. return (VER_PLATFORM_WIN32_NT == OsVersionInfo.dwPlatformId);
  186. } //end of IsNT function call
  187. //+-------------------------------------------------------------------
  188. //
  189. // Function: IsNT4SP3Lower
  190. //
  191. // Synopsis: findout If we are running on NTSP3 or lower
  192. //
  193. // Arguements: none
  194. //
  195. // Return: TRUE - Yes
  196. // FALSE - No
  197. //
  198. //--------------------------------------------------------------------
  199. BOOL IsNT4SP3Lower()
  200. {
  201. OSVERSIONINFO os;
  202. os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  203. GetVersionEx(&os);
  204. if(os.dwPlatformId != VER_PLATFORM_WIN32_NT)
  205. return FALSE;
  206. // Exclude NT5 or higher
  207. if(os.dwMajorVersion > 4)
  208. return FALSE;
  209. if(os.dwMajorVersion < 4)
  210. return TRUE;
  211. // version 4.0
  212. if ( os.dwMinorVersion > 0)
  213. return FALSE; // assume that sp3 is not needed for nt 4.1 or higher
  214. int nServicePack;
  215. if(_stscanf(os.szCSDVersion, TEXT("Service Pack %d"), &nServicePack) != 1)
  216. return TRUE;
  217. if(nServicePack < 4)
  218. return TRUE;
  219. return FALSE;
  220. }
  221. //+---------------------------------------------------------------------------
  222. //
  223. // Function: MyGetTempPath()
  224. //
  225. // Synopsis: Gets the path to temporary directory
  226. // - Use GetTempFileName to get a file name
  227. // and strips off the filename portion to get the temp path
  228. //
  229. // Arguments: [uiLength - Length of buffer to contain the temp path]
  230. // [szPath - Buffer in which temp path will be returned]
  231. //
  232. // Returns: Length of temp path if successful
  233. // 0 otherwise
  234. //
  235. // History: 7/6/96 VetriV Created
  236. // 8/23/96 VetriV Delete the temp file
  237. // 12/4/96 jmazner Modified to serve as a wrapper of sorts;
  238. // if TMP or TEMP don't exist, setEnv our own
  239. // vars that point to conn1's installed path
  240. // (Normandy #12193)
  241. //
  242. //----------------------------------------------------------------------------
  243. DWORD MyGetTempPath(UINT uiLength, LPTSTR szPath)
  244. {
  245. # define ICWHELPPATHKEY TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\ICWHELP.EXE")
  246. # define PATHKEYNAME TEXT("Path")
  247. TCHAR szEnvVarName[MAX_PATH + 1] = TEXT("\0unitialized szEnvVarName\0");
  248. DWORD dwFileAttr = 0;
  249. lstrcpyn( szPath, TEXT("\0unitialized szPath\0"), 20 );
  250. // is the TMP variable set?
  251. lstrcpyn(szEnvVarName,GetSz(IDS_TMPVAR),ARRAYSIZE(szEnvVarName));
  252. if( GetEnvironmentVariable( szEnvVarName, szPath, uiLength ) )
  253. {
  254. // 1/7/96 jmazner Normandy #12193
  255. // verify validity of directory name
  256. dwFileAttr = GetFileAttributes(szPath);
  257. // if there was any error, this directory isn't valid.
  258. if( 0xFFFFFFFF != dwFileAttr )
  259. {
  260. if( FILE_ATTRIBUTE_DIRECTORY & dwFileAttr )
  261. {
  262. return( lstrlen(szPath) );
  263. }
  264. }
  265. }
  266. lstrcpyn( szEnvVarName, TEXT("\0unitialized again\0"), 19 );
  267. // if not, is the TEMP variable set?
  268. lstrcpyn(szEnvVarName,GetSz(IDS_TEMPVAR),ARRAYSIZE(szEnvVarName));
  269. if( GetEnvironmentVariable( szEnvVarName, szPath, uiLength ) )
  270. {
  271. // 1/7/96 jmazner Normandy #12193
  272. // verify validity of directory name
  273. dwFileAttr = GetFileAttributes(szPath);
  274. if( 0xFFFFFFFF != dwFileAttr )
  275. {
  276. if( FILE_ATTRIBUTE_DIRECTORY & dwFileAttr )
  277. {
  278. return( lstrlen(szPath) );
  279. }
  280. }
  281. }
  282. // neither one is set, so let's use the path to the installed icwhelp.dll
  283. // from the registry SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ICWHELP.DLL\Path
  284. HKEY hkey = NULL;
  285. #ifdef UNICODE
  286. uiLength = sizeof(TCHAR)*uiLength;
  287. #endif
  288. if ((RegOpenKeyEx(HKEY_LOCAL_MACHINE,ICWHELPPATHKEY, 0, KEY_QUERY_VALUE, &hkey)) == ERROR_SUCCESS)
  289. RegQueryValueEx(hkey, PATHKEYNAME, NULL, NULL, (LPBYTE)szPath, (DWORD *)&uiLength);
  290. if (hkey)
  291. {
  292. RegCloseKey(hkey);
  293. }
  294. //The path variable is supposed to have a semicolon at the end of it.
  295. // if it's there, remove it.
  296. if( TEXT(';') == szPath[uiLength - 2] )
  297. szPath[uiLength - 2] = TEXT('\0');
  298. TraceMsg(TF_GENERAL, TEXT("ICWHELP: using path %s\r\n"), szPath);
  299. // go ahead and set the TEMP variable for future reference
  300. // (only effects currently running process)
  301. if( szEnvVarName[0] )
  302. {
  303. SetEnvironmentVariable( szEnvVarName, szPath );
  304. }
  305. else
  306. {
  307. lstrcpyn( szPath, TEXT("\0unitialized again\0"), 19 );
  308. return( 0 );
  309. }
  310. return( uiLength );
  311. }
  312. // ############################################################################
  313. HRESULT ClearProxySettings()
  314. {
  315. HINSTANCE hinst = NULL;
  316. FARPROC fp;
  317. HRESULT hr = ERROR_SUCCESS;
  318. hinst = LoadLibrary(TEXT("INETCFG.DLL"));
  319. if (hinst)
  320. {
  321. fp = GetProcAddress(hinst,"InetGetProxy");
  322. if (!fp)
  323. {
  324. hr = GetLastError();
  325. goto ClearProxySettingsExit;
  326. }
  327. hr = ((PFNINETGETPROXY)fp)(&g_bProxy,NULL,0,NULL,0);
  328. if (hr == ERROR_SUCCESS)
  329. g_bGotProxy = TRUE;
  330. else
  331. goto ClearProxySettingsExit;
  332. if (g_bProxy)
  333. {
  334. fp = GetProcAddress(hinst, "InetSetProxy");
  335. if (!fp)
  336. {
  337. hr = GetLastError();
  338. goto ClearProxySettingsExit;
  339. }
  340. ((PFNINETSETPROXY)fp)(FALSE,NULL,NULL);
  341. }
  342. } else {
  343. hr = GetLastError();
  344. }
  345. ClearProxySettingsExit:
  346. if (hinst)
  347. FreeLibrary(hinst);
  348. return hr;
  349. }
  350. // ############################################################################
  351. HRESULT RestoreProxySettings()
  352. {
  353. HINSTANCE hinst = NULL;
  354. FARPROC fp;
  355. HRESULT hr = ERROR_SUCCESS;
  356. hinst = LoadLibrary(TEXT("INETCFG.DLL"));
  357. if (hinst && g_bGotProxy)
  358. {
  359. fp = GetProcAddress(hinst, "InetSetProxy");
  360. if (!fp)
  361. {
  362. hr = GetLastError();
  363. goto RestoreProxySettingsExit;
  364. }
  365. ((PFNINETSETPROXY)fp)(g_bProxy,NULL,NULL);
  366. } else {
  367. hr = GetLastError();
  368. }
  369. RestoreProxySettingsExit:
  370. if (hinst)
  371. FreeLibrary(hinst);
  372. return hr;
  373. }
  374. // ############################################################################
  375. BOOL FSz2Dw(LPCTSTR pSz,LPDWORD dw)
  376. {
  377. DWORD val = 0;
  378. while (*pSz && *pSz != TEXT('.'))
  379. {
  380. if (*pSz >= TEXT('0') && *pSz <= TEXT('9'))
  381. {
  382. val *= 10;
  383. val += *pSz++ - TEXT('0');
  384. }
  385. else
  386. {
  387. return FALSE; //bad number
  388. }
  389. }
  390. *dw = val;
  391. return (TRUE);
  392. }
  393. // ############################################################################
  394. LPTSTR GetNextNumericChunk(LPTSTR psz, LPTSTR pszLim, LPTSTR* ppszNext)
  395. {
  396. LPTSTR pszEnd;
  397. // init for error case
  398. *ppszNext = NULL;
  399. // skip non numerics if any to start of next numeric chunk
  400. while(*psz<TEXT('0') || *psz>TEXT('9'))
  401. {
  402. if(psz >= pszLim) return NULL;
  403. psz++;
  404. }
  405. // skip all numerics to end of country code
  406. for(pszEnd=psz; *pszEnd>=TEXT('0') && *pszEnd<=TEXT('9') && pszEnd<pszLim; pszEnd++)
  407. ;
  408. // zap whatever delimiter there was to terminate this chunk
  409. *pszEnd++ = TEXT('\0');
  410. // return ptr to next chunk (pszEnd now points to it)
  411. if(pszEnd<pszLim)
  412. *ppszNext = pszEnd;
  413. return psz; // return ptr to start of chunk
  414. }
  415. // ############################################################################
  416. BOOL BreakUpPhoneNumber(LPRASENTRY prasentry, LPTSTR pszPhone)
  417. {
  418. LPTSTR pszStart,pszNext, pszLim, pszArea;
  419. // LPPHONENUM ppn;
  420. if (!pszPhone) return FALSE; // skip if no number
  421. pszLim = pszPhone + lstrlen(pszPhone); // find end of string
  422. //ppn = (fMain) ? &(pic->PhoneNum) : &(pic->PhoneNum2);
  423. ////Get the country ID...
  424. //ppn->dwCountryID = PBKDWCountryId();
  425. // Get Country Code from phone number...
  426. pszStart = _tcschr(pszPhone,TEXT('+'));
  427. if(!pszStart) goto error; // bad format
  428. // get country code
  429. pszStart = GetNextNumericChunk(pszStart, pszLim, &pszNext);
  430. if(!pszStart) goto error; // bad format
  431. //ppn->dwCountryCode = Sz2Dw(pszStart);
  432. FSz2Dw(pszStart,&prasentry->dwCountryCode);
  433. pszStart = pszNext;
  434. //Now get the area code
  435. if(!pszStart) goto error; // bad format
  436. pszStart = GetNextNumericChunk(pszStart, pszLim, &pszNext);
  437. if(!pszStart) goto error; // bad format //icw bug 8950
  438. //lstrcpy(ppn->szAreaCode, pszStart);
  439. lstrcpyn(prasentry->szAreaCode,pszStart,ARRAYSIZE(prasentry->szAreaCode));
  440. //
  441. // Keep track of the start of the area code, because it may actually be the
  442. // local phone number.
  443. //
  444. pszArea = pszStart;
  445. pszStart = pszNext;
  446. // If pszStart is NULL then we don't have an area code, just a country code and a local
  447. // phone number. Therefore we will copy what we thought was the area code into the
  448. // phone number and replace the area code with a space (which seems to make RAS happy).
  449. //
  450. if (pszStart)
  451. {
  452. //now the local phone number (everything from here to : or end)
  453. pszNext = _tcschr(pszStart, TEXT(':'));
  454. if(pszNext) *pszNext=TEXT('\0');
  455. lstrcpyn(prasentry->szLocalPhoneNumber,pszStart,ARRAYSIZE(prasentry->szLocalPhoneNumber));
  456. } else {
  457. //
  458. // Turns out that there is no area code. So copy what we thought was the area code
  459. // into the local phone number and make the area code NULL
  460. //
  461. lstrcpyn(prasentry->szLocalPhoneNumber,pszArea,ARRAYSIZE(prasentry->szLocalPhoneNumber));
  462. //lstrcpyn(prasentry->szAreaCode," ",sizeof(prasentry->szAreaCode));
  463. prasentry->szAreaCode[0] = TEXT('\0');
  464. }
  465. //no extension. what is extension?
  466. //ppn->szExtension[0] = TEXT('\0');
  467. //LocalFree(pszPhone);
  468. return TRUE;
  469. error:
  470. // This means number is not canonical. Set it as local number anyway!
  471. // memset(ppn, 0, sizeof(*ppn));
  472. // Bug#422: need to strip stuff after : or dial fails!!
  473. pszNext = _tcschr(pszPhone, TEXT(':'));
  474. if(pszNext) *pszNext=TEXT('\0');
  475. //lstrcpy(ppn->szLocal,pszPhone);
  476. lstrcpy(prasentry->szLocalPhoneNumber,pszPhone);
  477. //LocalFree(pszPhone);
  478. return TRUE;
  479. }
  480. // ############################################################################
  481. int Sz2W (LPCTSTR szBuf)
  482. {
  483. DWORD dw;
  484. if (FSz2Dw(szBuf,&dw))
  485. {
  486. return (WORD)dw;
  487. }
  488. return 0;
  489. }
  490. // ############################################################################
  491. int FIsDigit( int c )
  492. {
  493. TCHAR szIn[2];
  494. WORD rwOut[2];
  495. szIn[0] = (TCHAR)c;
  496. szIn[1] = TEXT('\0');
  497. GetStringTypeEx(LOCALE_USER_DEFAULT,CT_CTYPE1,szIn,-1,rwOut);
  498. return rwOut[0] & C1_DIGIT;
  499. }
  500. // ############################################################################
  501. LPBYTE MyMemSet(LPBYTE dest,int c, size_t count)
  502. {
  503. LPVOID pv = dest;
  504. LPVOID pvEnd = (LPVOID)(dest + (WORD)count);
  505. while (pv < pvEnd)
  506. {
  507. *(LPINT)pv = c;
  508. //((WORD)pv)++;
  509. pv=((LPINT)pv)+1;
  510. }
  511. return dest;
  512. }
  513. // ############################################################################
  514. LPBYTE MyMemCpy(LPBYTE dest,const LPBYTE src, size_t count)
  515. {
  516. LPBYTE pbDest = (LPBYTE)dest;
  517. LPBYTE pbSrc = (LPBYTE)src;
  518. LPBYTE pbEnd = (LPBYTE)((DWORD_PTR)src + count);
  519. while (pbSrc < pbEnd)
  520. {
  521. *pbDest = *pbSrc;
  522. pbSrc++;
  523. pbDest++;
  524. }
  525. return dest;
  526. }
  527. // ############################################################################
  528. BOOL ShowControl(HWND hDlg,int idControl,BOOL fShow)
  529. {
  530. HWND hWnd;
  531. if (NULL == hDlg)
  532. {
  533. AssertMsg(0,TEXT("Null Param"));
  534. return FALSE;
  535. }
  536. hWnd = GetDlgItem(hDlg,idControl);
  537. if (hWnd)
  538. {
  539. ShowWindow(hWnd,fShow ? SW_SHOW : SW_HIDE);
  540. }
  541. return TRUE;
  542. }
  543. BOOL isAlnum(TCHAR c)
  544. {
  545. if ((c >= TEXT('0') && c <= TEXT('9') ) ||
  546. (c >= TEXT('a') && c <= TEXT('z') ) ||
  547. (c >= TEXT('A') && c <= TEXT('Z') ))
  548. return TRUE;
  549. return FALSE;
  550. }
  551. // ############################################################################
  552. HRESULT ANSI2URLValue(TCHAR *s, TCHAR *buf, UINT uiLen)
  553. {
  554. HRESULT hr;
  555. TCHAR *t;
  556. hr = ERROR_SUCCESS;
  557. for (t=buf;*s; s++)
  558. {
  559. if (*s == TEXT(' ')) *t++ = TEXT('+');
  560. else if (isAlnum(*s)) *t++ = *s;
  561. else {
  562. wsprintf(t, TEXT("%%%02X"), (unsigned char) *s);
  563. t += 3;
  564. }
  565. }
  566. *t = TEXT('\0');
  567. return hr;
  568. }
  569. // ############################################################################
  570. LPTSTR FileToPath(LPTSTR pszFile)
  571. {
  572. TCHAR szBuf[MAX_PATH+1];
  573. TCHAR szTemp[MAX_PATH+1];
  574. LPTSTR pszTemp;
  575. LPTSTR pszTemp2;
  576. LPTSTR pszHold = pszFile;
  577. int j;
  578. for(j=0; *pszFile; pszFile++)
  579. {
  580. if(j>=MAX_PATH)
  581. return NULL;
  582. if(*pszFile==TEXT('%'))
  583. {
  584. pszFile++;
  585. pszTemp = _tcschr(pszFile, TEXT('%'));
  586. if(!pszTemp)
  587. return NULL;
  588. *pszTemp = 0;
  589. if(lstrcmpi(pszFile, DIR_SIGNUP)==0)
  590. {
  591. LPTSTR pszCmdLine = GetCommandLine();
  592. _tcsncpy(szTemp, pszCmdLine, MAX_PATH);
  593. szBuf[MAX_PATH] = 0;
  594. pszTemp = _tcstok(szTemp, TEXT(" \t\r\n"));
  595. pszTemp2 = _tcsrchr(pszTemp, TEXT('\\'));
  596. if(!pszTemp2) pszTemp2 = _tcsrchr(pszTemp, TEXT('/'));
  597. if(pszTemp2)
  598. {
  599. *pszTemp2 = 0;
  600. lstrcpy(szBuf+j, pszTemp);
  601. }
  602. else
  603. {
  604. Assert(FALSE);
  605. GetCurrentDirectory(MAX_PATH, szTemp);
  606. szTemp[MAX_PATH] = 0;
  607. lstrcpy(szBuf+j, pszTemp);
  608. }
  609. j+= lstrlen(pszTemp);
  610. }
  611. else if(lstrcmpi(pszFile, DIR_WINDOWS)==0)
  612. {
  613. GetWindowsDirectory(szTemp, MAX_PATH);
  614. szTemp[MAX_PATH] = 0;
  615. lstrcpy(szBuf+j, szTemp);
  616. j+= lstrlen(szTemp);
  617. }
  618. else if(lstrcmpi(pszFile, DIR_SYSTEM)==0)
  619. {
  620. GetSystemDirectory(szTemp, MAX_PATH);
  621. szTemp[MAX_PATH] = 0;
  622. lstrcpy(szBuf+j, szTemp);
  623. j+= lstrlen(szTemp);
  624. }
  625. else if(lstrcmpi(pszFile, DIR_TEMP)==0)
  626. {
  627. // 3/18/97 ChrisK Olympus 304
  628. MyGetTempPath(MAX_PATH, &szTemp[0]);
  629. szTemp[MAX_PATH] = 0;
  630. if(szTemp[lstrlen(szTemp)-1]==TEXT('\\'))
  631. szTemp[lstrlen(szTemp)-1]=0;
  632. lstrcpy(szBuf+j, szTemp);
  633. j+= lstrlen(szTemp);
  634. }
  635. else
  636. return NULL;
  637. pszFile=pszTemp;
  638. }
  639. else
  640. szBuf[j++] = *pszFile;
  641. }
  642. szBuf[j] = 0;
  643. TraceMsg(TF_GENERAL, TEXT("CONNECT:File to Path output ,%s.\n"),szBuf);
  644. return lstrcpy(pszHold,&szBuf[0]);
  645. }
  646. // ############################################################################
  647. BOOL FShouldRetry2(HRESULT hrErr)
  648. {
  649. BOOL bRC;
  650. if (hrErr == ERROR_LINE_BUSY ||
  651. hrErr == ERROR_VOICE_ANSWER ||
  652. hrErr == ERROR_NO_ANSWER ||
  653. hrErr == ERROR_NO_CARRIER ||
  654. hrErr == ERROR_AUTHENTICATION_FAILURE ||
  655. hrErr == ERROR_PPP_TIMEOUT ||
  656. hrErr == ERROR_REMOTE_DISCONNECTION ||
  657. hrErr == ERROR_AUTH_INTERNAL ||
  658. hrErr == ERROR_PROTOCOL_NOT_CONFIGURED ||
  659. hrErr == ERROR_PPP_NO_PROTOCOLS_CONFIGURED)
  660. {
  661. bRC = TRUE;
  662. } else {
  663. bRC = FALSE;
  664. }
  665. return bRC;
  666. }
  667. #if 0
  668. // DJM I don't this we will need this
  669. //+----------------------------------------------------------------------------
  670. //
  671. // Function: FGetSystemShutdownPrivledge
  672. //
  673. // Synopsis: For windows NT the process must explicitly ask for permission
  674. // to reboot the system.
  675. //
  676. // Arguements: none
  677. //
  678. // Return: TRUE - privledges granted
  679. // FALSE - DENIED
  680. //
  681. // History: 8/14/96 ChrisK Created
  682. //
  683. // Note: BUGBUG for Win95 we are going to have to softlink to these
  684. // entry points. Otherwise the app won't even load.
  685. // Also, this code was originally lifted out of MSDN July96
  686. // "Shutting down the system"
  687. //-----------------------------------------------------------------------------
  688. BOOL FGetSystemShutdownPrivledge()
  689. {
  690. HANDLE hToken = NULL;
  691. TOKEN_PRIVILEGES tkp;
  692. BOOL bRC = FALSE;
  693. if (VER_PLATFORM_WIN32_NT == g_dwPlatform)
  694. {
  695. //
  696. // Get the current process token handle
  697. // so we can get shutdown privilege.
  698. //
  699. if (!OpenProcessToken(GetCurrentProcess(),
  700. TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
  701. goto FGetSystemShutdownPrivledgeExit;
  702. //
  703. // Get the LUID for shutdown privilege.
  704. //
  705. ZeroMemory(&tkp,sizeof(tkp));
  706. LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
  707. &tkp.Privileges[0].Luid);
  708. tkp.PrivilegeCount = 1; /* one privilege to set */
  709. tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  710. //
  711. // Get shutdown privilege for this process.
  712. //
  713. AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
  714. (PTOKEN_PRIVILEGES) NULL, 0);
  715. if (ERROR_SUCCESS == GetLastError())
  716. bRC = TRUE;
  717. }
  718. else
  719. {
  720. bRC = TRUE;
  721. }
  722. FGetSystemShutdownPrivledgeExit:
  723. if (hToken) CloseHandle(hToken);
  724. return bRC;
  725. }
  726. #endif
  727. //+----------------------------------------------------------------------------
  728. //
  729. // Function: LoadTestingLocaleOverride
  730. //
  731. // Synopsis: Allow the testers to override the locale information sent to
  732. // the referal server
  733. //
  734. // Arguments: lpdwCountryID - pointer to country ID
  735. // lplcid - pointer to current lcid
  736. //
  737. // Returns: none
  738. //
  739. // History: 8/15/96 ChrisK Created
  740. //
  741. //-----------------------------------------------------------------------------
  742. #if defined(DEBUG)
  743. void LoadTestingLocaleOverride(LPDWORD lpdwCountryID, LCID FAR *lplcid)
  744. {
  745. HKEY hkey = NULL;
  746. LONG lRC = ERROR_SUCCESS;
  747. DWORD dwTemp = 0;
  748. LCID lcidTemp = 0;
  749. DWORD dwSize = 0;
  750. DWORD dwType = 0;
  751. BOOL fWarn = FALSE;
  752. Assert(lpdwCountryID && lplcid);
  753. //
  754. // Open debug key
  755. //
  756. lRC = RegOpenKey(HKEY_LOCAL_MACHINE,TEXT("Software\\Microsoft\\ISignup\\Debug"),&hkey);
  757. if (ERROR_SUCCESS != lRC)
  758. goto LoadTestingLocaleOverrideExit;
  759. //
  760. // Get CountryID
  761. //
  762. dwSize = sizeof(dwTemp);
  763. lRC = RegQueryValueEx(hkey,TEXT("CountryID"),0,&dwType,(LPBYTE)&dwTemp,&dwSize);
  764. AssertMsg(lRC || REG_DWORD == dwType,TEXT("Wrong value type for CountryID. Must be DWORD.\r\n"));
  765. if (ERROR_SUCCESS==lRC)
  766. {
  767. *lpdwCountryID = dwTemp;
  768. fWarn = TRUE;
  769. }
  770. //
  771. // Get LCID
  772. //
  773. dwSize = sizeof(lcidTemp);
  774. lRC = RegQueryValueEx(hkey,TEXT("LCID"),0,&dwType,(LPBYTE)&lcidTemp,&dwSize);
  775. AssertMsg(lRC || REG_DWORD == dwType,TEXT("Wrong value type for LCID. Must be DWORD.\r\n"));
  776. if (ERROR_SUCCESS==lRC)
  777. {
  778. *lplcid = lcidTemp;
  779. fWarn = TRUE;
  780. }
  781. //
  782. // Inform the user that overrides have been used
  783. //
  784. if (fWarn)
  785. {
  786. MessageBox(NULL,TEXT("DEBUG ONLY: LCID and/or CountryID overrides from the registry are now being used."),TEXT("Testing Override"),0);
  787. }
  788. LoadTestingLocaleOverrideExit:
  789. if (hkey)
  790. RegCloseKey(hkey);
  791. hkey = NULL;
  792. return;
  793. }
  794. #endif //DEBUG
  795. //+----------------------------------------------------------------------------
  796. //
  797. // Function: FCampusNetOverride
  798. //
  799. // Synopsis: Detect if the dial should be skipped for the campus network
  800. //
  801. // Arguments: None
  802. //
  803. // Returns: TRUE - overide enabled
  804. //
  805. // History: 8/15/96 ChrisK Created
  806. //
  807. //-----------------------------------------------------------------------------
  808. #if defined(DEBUG)
  809. BOOL FCampusNetOverride()
  810. {
  811. HKEY hkey = NULL;
  812. BOOL bRC = FALSE;
  813. DWORD dwType = 0;
  814. DWORD dwSize = 0;
  815. DWORD dwData = 0;
  816. if (ERROR_SUCCESS != RegOpenKey(HKEY_LOCAL_MACHINE,
  817. TEXT("Software\\Microsoft\\ISignup\\Debug"),&hkey))
  818. goto FCampusNetOverrideExit;
  819. dwSize = sizeof(dwData);
  820. if (ERROR_SUCCESS != RegQueryValueEx(hkey,TEXT("CampusNet"),0,&dwType,
  821. (LPBYTE)&dwData,&dwSize))
  822. goto FCampusNetOverrideExit;
  823. AssertMsg(REG_DWORD == dwType,TEXT("Wrong value type for CampusNet. Must be DWORD.\r\n"));
  824. bRC = (0 != dwData);
  825. if (bRC)
  826. {
  827. if (IDOK != MessageBox(NULL,TEXT("DEBUG ONLY: CampusNet will be used."),TEXT("Testing Override"),MB_OKCANCEL))
  828. bRC = FALSE;
  829. }
  830. FCampusNetOverrideExit:
  831. if (hkey)
  832. RegCloseKey(hkey);
  833. return bRC;
  834. }
  835. #endif //DEBUG
  836. #if defined(DEBUG)
  837. BOOL FRefURLOverride()
  838. {
  839. HKEY hkey = NULL;
  840. BOOL bRC = FALSE;
  841. DWORD dwType = 0;
  842. DWORD dwSize = 0;
  843. DWORD dwData = 0;
  844. if (ERROR_SUCCESS != RegOpenKey(HKEY_LOCAL_MACHINE,
  845. TEXT("Software\\Microsoft\\ISignup\\Debug"),&hkey))
  846. goto FRefURLOverrideExit;
  847. dwSize = sizeof(dwData);
  848. if (ERROR_SUCCESS != RegQueryValueEx(hkey,TEXT("TweakURL"),0,&dwType,
  849. (LPBYTE)&dwData,&dwSize))
  850. goto FRefURLOverrideExit;
  851. AssertMsg(REG_DWORD == dwType,TEXT("Wrong value type for TweakURL. Must be DWORD.\r\n"));
  852. bRC = (0 != dwData);
  853. if (bRC)
  854. {
  855. if (IDOK != MessageBox(NULL,TEXT("DEBUG ONLY: TweakURL settings will be used."),TEXT("Testing Override"),MB_OKCANCEL))
  856. bRC = FALSE;
  857. }
  858. FRefURLOverrideExit:
  859. if (hkey)
  860. RegCloseKey(hkey);
  861. return bRC;
  862. }
  863. void TweakRefURL( TCHAR* szUrl,
  864. LCID* lcid,
  865. DWORD* dwOS,
  866. DWORD* dwMajorVersion,
  867. DWORD* dwMinorVersion,
  868. WORD* wArchitecture,
  869. TCHAR* szPromo,
  870. TCHAR* szOEM,
  871. TCHAR* szArea,
  872. DWORD* dwCountry,
  873. TCHAR* szSUVersion,//&m_lpGatherInfo->m_szSUVersion[0],
  874. TCHAR* szProd,
  875. DWORD* dwBuildNumber,
  876. TCHAR* szRelProd,
  877. TCHAR* szRelProdVer,
  878. DWORD* dwCONNWIZVersion,
  879. TCHAR* szPID,
  880. long* lAllOffers)
  881. {
  882. HKEY hKey = NULL;
  883. BOOL bRC = FALSE;
  884. BYTE bData[MAX_PATH*3];
  885. DWORD cbData = MAX_PATH*3;
  886. DWORD dwType = 0;
  887. DWORD dwSize = 0;
  888. DWORD dwData = 0;
  889. dwSize = sizeof(dwData);
  890. if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\ISignup\\Debug\\TweakURLValues"),&hKey))
  891. {
  892. //szURL
  893. if (ERROR_SUCCESS == RegQueryValueEx(hKey,TEXT("URL"), NULL ,&dwType, bData, &cbData))
  894. {
  895. if ((cbData > 1) && (cbData <= MAX_PATH))
  896. {
  897. lstrcpy(szUrl, (TCHAR*)&bData);
  898. }
  899. }
  900. //lcid
  901. if (ERROR_SUCCESS == RegQueryValueEx(hKey,TEXT("LCID"),0,&dwType, (LPBYTE)&dwData, &dwSize))
  902. {
  903. if (dwData != 0)
  904. *lcid = dwData;
  905. }
  906. //dwOS
  907. if (ERROR_SUCCESS == RegQueryValueEx(hKey,TEXT("OS"),0,&dwType, (LPBYTE)&dwData, &dwSize))
  908. {
  909. if (dwData != 0)
  910. *dwOS = dwData;
  911. }
  912. //dwMajorVersion
  913. if (ERROR_SUCCESS == RegQueryValueEx(hKey,TEXT("MajorVer"),0,&dwType, (LPBYTE)&dwData, &dwSize))
  914. {
  915. if (dwData != 0)
  916. *dwMajorVersion = dwData;
  917. }
  918. //dwMinorVersion
  919. if (ERROR_SUCCESS == RegQueryValueEx(hKey,TEXT("MinorVer"),0,&dwType, (LPBYTE)&dwData, &dwSize))
  920. {
  921. if (dwData != 0)
  922. *dwMinorVersion = dwData;
  923. }
  924. //wArchitecture
  925. if (ERROR_SUCCESS == RegQueryValueEx(hKey,TEXT("SysArch"),0,&dwType, (LPBYTE)&dwData, &dwSize))
  926. {
  927. if (dwData != 0)
  928. *wArchitecture = (WORD)dwData;
  929. }
  930. //szPromo
  931. cbData = sizeof(TCHAR)*(MAX_PATH*3);
  932. if (ERROR_SUCCESS == RegQueryValueEx(hKey,TEXT("Promo"),0,&dwType, bData, &cbData))
  933. {
  934. if ((cbData > 1) && (cbData <= MAX_PATH))
  935. {
  936. lstrcpy(szPromo, (TCHAR*)&bData);
  937. }
  938. }
  939. //szOEM
  940. cbData = sizeof(TCHAR)*(MAX_PATH*3);
  941. if (ERROR_SUCCESS == RegQueryValueEx(hKey,TEXT("OEM"),0,&dwType, bData, &cbData))
  942. {
  943. if ((cbData > 1) && (cbData <= MAX_PATH))
  944. {
  945. lstrcpy(szOEM, (TCHAR*)&bData);
  946. }
  947. }
  948. //szArea
  949. cbData = sizeof(TCHAR)*(MAX_PATH*3);
  950. if (ERROR_SUCCESS == RegQueryValueEx(hKey,TEXT("Area"),0,&dwType, bData, &cbData))
  951. {
  952. if ((cbData > 1) && (cbData <= MAX_PATH))
  953. {
  954. lstrcpy(szArea, (TCHAR*)&bData);
  955. }
  956. }
  957. //dwCountry
  958. if (ERROR_SUCCESS == RegQueryValueEx(hKey,TEXT("Country"),0,&dwType, (LPBYTE)&dwData, &dwSize))
  959. {
  960. if (dwData != 0)
  961. *dwCountry = dwData;
  962. }
  963. //szSUVersion
  964. cbData = sizeof(TCHAR)*(MAX_PATH*3);
  965. if (ERROR_SUCCESS == RegQueryValueEx(hKey,TEXT("SUVer"),0,&dwType, bData, &cbData))
  966. {
  967. if ((cbData > 1) && (cbData <= MAX_VERSION_LEN))
  968. {
  969. lstrcpy(szSUVersion, (TCHAR*)&bData);
  970. }
  971. }
  972. //szProd
  973. cbData = sizeof(TCHAR)*(MAX_PATH*3);
  974. if (ERROR_SUCCESS == RegQueryValueEx(hKey,TEXT("Product"),0,&dwType, bData, &cbData))
  975. {
  976. if ((cbData > 1) && (cbData <= MAX_PATH))
  977. {
  978. lstrcpy(szProd, (TCHAR*)&bData);
  979. }
  980. }
  981. //dwBuildNumber
  982. if (ERROR_SUCCESS == RegQueryValueEx(hKey,TEXT("BuildNum"),0,&dwType, (LPBYTE)&dwData, &dwSize))
  983. {
  984. if (dwData != 0)
  985. *dwBuildNumber = dwData;
  986. }
  987. //szRelProd
  988. cbData = sizeof(TCHAR)*(MAX_PATH*3);
  989. if (ERROR_SUCCESS == RegQueryValueEx(hKey,TEXT("RelProd"),0,&dwType, bData, &cbData))
  990. {
  991. if ((cbData > 1) && (cbData <= MAX_PATH))
  992. {
  993. lstrcpy(szRelProd, (TCHAR*)&bData);
  994. }
  995. }
  996. //szRelProdVer
  997. cbData = sizeof(TCHAR)*(MAX_PATH*3);
  998. if (ERROR_SUCCESS == RegQueryValueEx(hKey,TEXT("RelProdVer"),0,&dwType, bData, &cbData))
  999. {
  1000. if ((cbData > 1) && (cbData <= MAX_PATH))
  1001. {
  1002. lstrcpy(szRelProdVer, (TCHAR*)&bData);
  1003. }
  1004. }
  1005. //dwCONNWIZVersion
  1006. if (ERROR_SUCCESS == RegQueryValueEx(hKey,TEXT("ConnwizVer"),0,&dwType, (LPBYTE)&dwData, &dwSize))
  1007. {
  1008. if (dwData != 0)
  1009. *dwCONNWIZVersion = dwData;
  1010. }
  1011. //szPID
  1012. BYTE byDigitalPID[MAX_DIGITAL_PID];
  1013. DWORD dwType2 = REG_BINARY;
  1014. DWORD dwSize2 = sizeof(byDigitalPID);
  1015. if (RegQueryValueEx(hKey,
  1016. TEXT("PID"),
  1017. NULL,
  1018. &dwType2,
  1019. (LPBYTE)byDigitalPID,
  1020. &dwSize2) == ERROR_SUCCESS)
  1021. {
  1022. if ((dwSize2 > 1) && (dwSize2 <= ((MAX_DIGITAL_PID * 2) + 1)))
  1023. {
  1024. // BINHEX the digital PID data so we can send it to the ref_server
  1025. int i = 0;
  1026. BYTE by;
  1027. for (DWORD dwX = 0; dwX < dwSize2; dwX++)
  1028. {
  1029. by = byDigitalPID[dwX];
  1030. szPID[i++] = g_BINTOHEXLookup[((by & 0xF0) >> 4)];
  1031. szPID[i++] = g_BINTOHEXLookup[(by & 0x0F)];
  1032. }
  1033. szPID[i] = TEXT('\0');
  1034. }
  1035. else
  1036. {
  1037. szPID[0] = TEXT('\0');
  1038. }
  1039. }
  1040. //lAllOffers
  1041. if (ERROR_SUCCESS == RegQueryValueEx(hKey,TEXT("AllOffers"),0,&dwType, (LPBYTE)&dwData, &dwSize))
  1042. {
  1043. if (dwData != 0)
  1044. *lAllOffers = dwData;
  1045. }
  1046. }
  1047. if (hKey)
  1048. RegCloseKey(hKey);
  1049. }
  1050. #endif //DEBUG
  1051. //+----------------------------------------------------------------------------
  1052. // Function CopyUntil
  1053. //
  1054. // Synopsis Copy from source until destination until running out of source
  1055. // or until the next character of the source is the chend character
  1056. //
  1057. // Arguments dest - buffer to recieve characters
  1058. // src - source buffer
  1059. // lpdwLen - length of dest buffer
  1060. // chend - the terminating character
  1061. //
  1062. // Returns FALSE - ran out of room in dest buffer
  1063. //
  1064. // Histroy 10/25/96 ChrisK Created
  1065. //-----------------------------------------------------------------------------
  1066. static BOOL CopyUntil(LPTSTR *dest, LPTSTR *src, LPDWORD lpdwLen, TCHAR chend)
  1067. {
  1068. while ((TEXT('\0') != **src) && (chend != **src) && (0 != *lpdwLen))
  1069. {
  1070. **dest = **src;
  1071. (*lpdwLen)--;
  1072. (*dest)++;
  1073. (*src)++;
  1074. }
  1075. return (0 != *lpdwLen);
  1076. }
  1077. //+----------------------------------------------------------------------------
  1078. // Function ConvertToLongFilename
  1079. //
  1080. // Synopsis convert a file to the full long file name
  1081. // ie. c:\progra~1\icw-in~1\isignup.exe becomes
  1082. // c:\program files\icw-internet connection wizard\isignup.exe
  1083. //
  1084. // Arguments szOut - output buffer
  1085. // szIn - filename to be converted
  1086. // dwSize - size of the output buffer
  1087. //
  1088. // Returns TRUE - success
  1089. //
  1090. // History 10/25/96 ChrisK Created
  1091. //-----------------------------------------------------------------------------
  1092. BOOL ConvertToLongFilename(LPTSTR szOut, LPTSTR szIn, DWORD dwSize)
  1093. {
  1094. BOOL bRC = FALSE;
  1095. LPTSTR pCur = szIn;
  1096. LPTSTR pCurOut = szOut;
  1097. LPTSTR pCurOutFilename = NULL;
  1098. WIN32_FIND_DATA fd;
  1099. DWORD dwSizeTemp;
  1100. LPTSTR pTemp = NULL;
  1101. ZeroMemory(pCurOut,dwSize);
  1102. //
  1103. // Validate parameters
  1104. //
  1105. if (NULL != pCurOut && NULL != pCur && 0 != dwSize)
  1106. {
  1107. //
  1108. // Copy drive letter
  1109. //
  1110. if (!CopyUntil(&pCurOut,&pCur,&dwSize,TEXT('\\')))
  1111. goto ConvertToLongFilenameExit;
  1112. pCurOut[0] = TEXT('\\');
  1113. dwSize--;
  1114. pCur++;
  1115. pCurOut++;
  1116. pCurOutFilename = pCurOut;
  1117. while (*pCur)
  1118. {
  1119. //
  1120. // Copy over possibly short name
  1121. //
  1122. pCurOut = pCurOutFilename;
  1123. dwSizeTemp = dwSize;
  1124. if (!CopyUntil(&pCurOut,&pCur,&dwSize,TEXT('\\')))
  1125. goto ConvertToLongFilenameExit;
  1126. ZeroMemory(&fd, sizeof(fd));
  1127. //
  1128. // Get long filename
  1129. //
  1130. if (INVALID_HANDLE_VALUE != FindFirstFile(szOut,&fd))
  1131. {
  1132. //
  1133. // Replace short filename with long filename
  1134. //
  1135. dwSize = dwSizeTemp;
  1136. pTemp = &(fd.cFileName[0]);
  1137. if (!CopyUntil(&pCurOutFilename,&pTemp,&dwSize,TEXT('\0')))
  1138. goto ConvertToLongFilenameExit;
  1139. if (*pCur)
  1140. {
  1141. //
  1142. // If there is another section then we just copied a directory
  1143. // name. Append a \ character;
  1144. //
  1145. pTemp = (LPTSTR)memcpy(TEXT("\\X"),TEXT("\\X"),0);
  1146. if (!CopyUntil(&pCurOutFilename,&pTemp,&dwSize,TEXT('X')))
  1147. goto ConvertToLongFilenameExit;
  1148. pCur++;
  1149. }
  1150. }
  1151. else
  1152. {
  1153. break;
  1154. }
  1155. }
  1156. //
  1157. // Did we get to the end (TRUE) or fail before that (FALSE)?
  1158. //
  1159. bRC = (TEXT('\0') == *pCur);
  1160. }
  1161. ConvertToLongFilenameExit:
  1162. return bRC;
  1163. }
  1164. #if 0
  1165. // DJM I don't think we need this
  1166. //+----------------------------------------------------------------------------
  1167. //
  1168. // Function: GetIEVersion
  1169. //
  1170. // Synopsis: Gets the major and minor version # of the installed copy of Internet Explorer
  1171. //
  1172. // Arguments: pdwVerNumMS - pointer to a DWORD;
  1173. // On succesful return, the top 16 bits will contain the major version number,
  1174. // and the lower 16 bits will contain the minor version number
  1175. // (this is the data in VS_FIXEDFILEINFO.dwProductVersionMS)
  1176. // pdwVerNumLS - pointer to a DWORD;
  1177. // On succesful return, the top 16 bits will contain the release number,
  1178. // and the lower 16 bits will contain the build number
  1179. // (this is the data in VS_FIXEDFILEINFO.dwProductVersionLS)
  1180. //
  1181. // Returns: TRUE - Success. *pdwVerNumMS and LS contains installed IE version number
  1182. // FALSE - Failure. *pdVerNumMS == *pdVerNumLS == 0
  1183. //
  1184. // History: jmazner Created 8/19/96 (as fix for Normandy #4571)
  1185. // jmazner updated to deal with release.build as well 10/11/96
  1186. // jmazner stolen from isign32\isignup.cpp 11/21/96
  1187. // (for Normandy #11812)
  1188. //
  1189. //-----------------------------------------------------------------------------
  1190. BOOL GetIEVersion(PDWORD pdwVerNumMS, PDWORD pdwVerNumLS)
  1191. {
  1192. HRESULT hr;
  1193. HKEY hKey = 0;
  1194. LPVOID lpVerInfoBlock;
  1195. VS_FIXEDFILEINFO *lpTheVerInfo;
  1196. UINT uTheVerInfoSize;
  1197. DWORD dwVerInfoBlockSize, dwUnused, dwPathSize;
  1198. TCHAR szIELocalPath[MAX_PATH + 1] = TEXT("");
  1199. *pdwVerNumMS = 0;
  1200. *pdwVerNumLS = 0;
  1201. // get path to the IE executable
  1202. hr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, IE_PATHKEY,0, KEY_READ, &hKey);
  1203. if (hr != ERROR_SUCCESS) return( FALSE );
  1204. dwPathSize = sizeof (szIELocalPath);
  1205. hr = RegQueryValueEx(hKey, NULL, NULL, NULL, (LPBYTE) szIELocalPath, &dwPathSize);
  1206. RegCloseKey( hKey );
  1207. if (hr != ERROR_SUCCESS) return( FALSE );
  1208. // now go through the convoluted process of digging up the version info
  1209. dwVerInfoBlockSize = GetFileVersionInfoSize( szIELocalPath, &dwUnused );
  1210. if ( 0 == dwVerInfoBlockSize ) return( FALSE );
  1211. lpVerInfoBlock = GlobalAlloc( GPTR, dwVerInfoBlockSize );
  1212. if( NULL == lpVerInfoBlock ) return( FALSE );
  1213. if( !GetFileVersionInfo( szIELocalPath, NULL, dwVerInfoBlockSize, lpVerInfoBlock ) )
  1214. return( FALSE );
  1215. if( !VerQueryValue(lpVerInfoBlock, TEXT("\\"), (void **)&lpTheVerInfo, &uTheVerInfoSize) )
  1216. return( FALSE );
  1217. *pdwVerNumMS = lpTheVerInfo->dwProductVersionMS;
  1218. *pdwVerNumLS = lpTheVerInfo->dwProductVersionLS;
  1219. GlobalFree( lpVerInfoBlock );
  1220. return( TRUE );
  1221. }
  1222. #endif
  1223. //+---------------------------------------------------------------------------
  1224. //
  1225. // Function: GenericMsg
  1226. //
  1227. //----------------------------------------------------------------------------
  1228. void GenericMsg
  1229. (
  1230. HWND hwnd,
  1231. UINT uId,
  1232. LPCTSTR lpszArg,
  1233. UINT uType
  1234. )
  1235. {
  1236. TCHAR szTemp[MAX_STRING + 1];
  1237. TCHAR szMsg[MAX_STRING + MAX_PATH + 1];
  1238. Assert( lstrlen( GetSz((USHORT)uId) ) <= MAX_STRING );
  1239. lstrcpy( szTemp, GetSz( (USHORT)uId ) );
  1240. if (lpszArg)
  1241. {
  1242. Assert( lstrlen( lpszArg ) <= MAX_PATH );
  1243. wsprintf(szMsg, szTemp, lpszArg);
  1244. }
  1245. else
  1246. {
  1247. lstrcpy(szMsg, szTemp);
  1248. }
  1249. MessageBox(hwnd,
  1250. szMsg,
  1251. GetSz(IDS_TITLE),
  1252. uType);
  1253. }
  1254. //+---------------------------------------------------------------------------
  1255. //
  1256. // Function: ErrorMsg1()
  1257. //
  1258. // Synopsis: 1 stop shopping for showing a msgBox when you need to wsprintf the string to be displayed
  1259. //
  1260. // Displays an error dialog from a string resource with a "%s" format command,
  1261. // and a string argument to stick into it.
  1262. //
  1263. // Arguments: hwnd -- Handle of parent window
  1264. // uID -- ID of a string resource with a %s argument
  1265. // lpszArg -- pointer to a string to fill into the %s in uID string
  1266. //
  1267. //
  1268. // History: 9/18/96 jmazner copied from isign32\utils.cpp (for Normandy 7537)
  1269. // modified to work in conn1
  1270. //
  1271. //----------------------------------------------------------------------------
  1272. void ErrorMsg1(HWND hwnd, UINT uId, LPCTSTR lpszArg)
  1273. {
  1274. GenericMsg(hwnd,
  1275. uId,
  1276. lpszArg,
  1277. MB_ICONERROR | MB_SETFOREGROUND | MB_OK | MB_APPLMODAL);
  1278. }
  1279. //+---------------------------------------------------------------------------
  1280. //
  1281. // Function: InfoMsg1()
  1282. //
  1283. //----------------------------------------------------------------------------
  1284. void InfoMsg1(HWND hwnd, UINT uId, LPCTSTR lpszArg)
  1285. {
  1286. GenericMsg(hwnd,
  1287. uId,
  1288. lpszArg,
  1289. MB_ICONINFORMATION | MB_SETFOREGROUND | MB_OK | MB_APPLMODAL);
  1290. }
  1291. //=--------------------------------------------------------------------------=
  1292. // MakeWideFromAnsi
  1293. //=--------------------------------------------------------------------------=
  1294. // given a string, make a BSTR out of it.
  1295. //
  1296. // Parameters:
  1297. // LPTSTR - [in]
  1298. // BYTE - [in]
  1299. //
  1300. // Output:
  1301. // LPWSTR - needs to be cast to final desired result
  1302. //
  1303. // Notes:
  1304. //
  1305. LPWSTR MakeWideStrFromAnsi
  1306. (
  1307. LPSTR psz,
  1308. BYTE bType
  1309. )
  1310. {
  1311. LPWSTR pwsz;
  1312. int i;
  1313. // arg checking.
  1314. //
  1315. if (!psz)
  1316. return NULL;
  1317. // compute the length of the required BSTR
  1318. //
  1319. i = MultiByteToWideChar(CP_ACP, 0, psz, -1, NULL, 0);
  1320. if (i <= 0) return NULL;
  1321. // allocate the widestr
  1322. //
  1323. switch (bType) {
  1324. case STR_BSTR:
  1325. // -1 since it'll add it's own space for a NULL terminator
  1326. //
  1327. pwsz = (LPWSTR) SysAllocStringLen(NULL, i - 1);
  1328. break;
  1329. case STR_OLESTR:
  1330. pwsz = (LPWSTR) CoTaskMemAlloc(i * sizeof(WCHAR));
  1331. break;
  1332. default:
  1333. AssertMsg(0,TEXT("Bogus String Type."));
  1334. }
  1335. if (!pwsz) return NULL;
  1336. MultiByteToWideChar(CP_ACP, 0, psz, -1, pwsz, i);
  1337. pwsz[i - 1] = 0;
  1338. return pwsz;
  1339. }
  1340. //=--------------------------------------------------------------------------=
  1341. // MakeWideStrFromResId
  1342. //=--------------------------------------------------------------------------=
  1343. // given a resource ID, load it, and allocate a wide string for it.
  1344. //
  1345. // Parameters:
  1346. // WORD - [in] resource id.
  1347. // BYTE - [in] type of string desired.
  1348. //
  1349. // Output:
  1350. // LPWSTR - needs to be cast to desired string type.
  1351. //
  1352. // Notes:
  1353. //
  1354. #ifndef UNICODE // this module is not necessary for Unicode.
  1355. LPWSTR MakeWideStrFromResourceId
  1356. (
  1357. WORD wId,
  1358. BYTE bType
  1359. )
  1360. {
  1361. int i;
  1362. TCHAR szTmp[512];
  1363. // load the string from the resources.
  1364. //
  1365. i = LoadString(_Module.GetModuleInstance(), wId, szTmp, 512);
  1366. if (!i) return NULL;
  1367. return MakeWideStrFromAnsi(szTmp, bType);
  1368. }
  1369. #endif
  1370. //=--------------------------------------------------------------------------=
  1371. // MakeWideStrFromWide
  1372. //=--------------------------------------------------------------------------=
  1373. // given a wide string, make a new wide string with it of the given type.
  1374. //
  1375. // Parameters:
  1376. // LPWSTR - [in] current wide str.
  1377. // BYTE - [in] desired type of string.
  1378. //
  1379. // Output:
  1380. // LPWSTR
  1381. //
  1382. // Notes:
  1383. //
  1384. LPWSTR MakeWideStrFromWide
  1385. (
  1386. LPWSTR pwsz,
  1387. BYTE bType
  1388. )
  1389. {
  1390. LPWSTR pwszTmp;
  1391. int i;
  1392. if (!pwsz) return NULL;
  1393. // just copy the string, depending on what type they want.
  1394. //
  1395. switch (bType) {
  1396. case STR_OLESTR:
  1397. i = lstrlenW(pwsz);
  1398. pwszTmp = (LPWSTR)CoTaskMemAlloc((i * sizeof(WCHAR)) + sizeof(WCHAR));
  1399. if (!pwszTmp) return NULL;
  1400. memcpy(pwszTmp, pwsz, (sizeof(WCHAR) * i) + sizeof(WCHAR));
  1401. break;
  1402. case STR_BSTR:
  1403. pwszTmp = (LPWSTR)SysAllocString(pwsz);
  1404. break;
  1405. }
  1406. return pwszTmp;
  1407. }