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.

365 lines
8.9 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1994 **
  4. //*********************************************************************
  5. //
  6. // INIT.C - WinMain and initialization code for Internet setup/signup wizard
  7. //
  8. // HISTORY:
  9. //
  10. // 11/20/94 jeremys Created.
  11. // 96/03/07 markdu Added gpEnumModem
  12. // 96/03/09 markdu Added gpRasEntry
  13. // 96/03/23 markdu Replaced CLIENTINFO references with CLIENTCONFIG.
  14. // 96/03/26 markdu Put #ifdef __cplusplus around extern "C"
  15. // 96/04/24 markdu NASH BUG 19289 Added /NOMSN command line flag
  16. // 96/05/14 markdu NASH BUG 21706 Removed BigFont functions.
  17. // 96/05/14 markdu NASH BUG 22681 Took out mail and news pages.
  18. //
  19. #include "wizard.h"
  20. #include "icwextsn.h"
  21. #include "imnext.h"
  22. #ifdef __cplusplus
  23. extern "C"
  24. {
  25. #endif // __cplusplus
  26. //
  27. // The LaunchSignupWizard APIs have a PBOOL argument also which gets
  28. // info to the calling APP whether they need to reboot
  29. // MKarki (5/4/97) - Fix for Bug #3111
  30. //
  31. VOID WINAPI LaunchSignupWizard(LPTSTR lpCmdLine,int nCmdShow, PBOOL pReboot);
  32. DWORD WINAPI LaunchSignupWizardEx(LPTSTR lpCmdLine,int nReserved, PBOOL pReboot);
  33. #ifdef __cplusplus
  34. }
  35. #endif // __cplusplus
  36. BOOL ParseCommandLine(LPTSTR lpszCommandLine,DWORD * pdwFlags);
  37. TCHAR * GetTextToNextSpace(LPTSTR pszText,TCHAR * pszOutBuf,UINT cbOutBuf);
  38. #pragma data_seg(".data")
  39. WIZARDSTATE * gpWizardState=NULL; // pointer to global wizard state struct
  40. USERINFO * gpUserInfo=NULL; // pointer to global user info struct
  41. ENUM_MODEM * gpEnumModem=NULL; // pointer modem enumeration object
  42. LPRASENTRY gpRasEntry = NULL; // pointer to RASENTRY struct to hold all data
  43. DWORD gdwRasEntrySize = 0;
  44. BOOL gfFirstNewConnection = TRUE;
  45. //
  46. // set the reboot flag to FALSE
  47. // MKarki - 5/2/97 - Fix for Bug#3111
  48. //
  49. BOOL g_bReboot = FALSE;
  50. BOOL g_bRebootAtExit = FALSE;
  51. #pragma data_seg()
  52. /*******************************************************************
  53. NAME: LaunchSignupWizard
  54. SYNOPSIS: Entry point for Internet Setup Wizard UI
  55. ********************************************************************/
  56. extern "C" VOID WINAPI
  57. LaunchSignupWizard (
  58. LPTSTR lpCmdLine,
  59. int nCmdShow,
  60. PBOOL pReboot
  61. )
  62. {
  63. BOOL fOK=TRUE;
  64. // allocate global structures
  65. gpWizardState = new WIZARDSTATE;
  66. gpUserInfo = new USERINFO;
  67. gdwRasEntrySize = sizeof(RASENTRY);
  68. gpRasEntry = (LPRASENTRY) GlobalAlloc(GPTR,gdwRasEntrySize);
  69. if (!gpWizardState ||
  70. !gpUserInfo ||
  71. !gpRasEntry)
  72. {
  73. // display an out of memory error
  74. MsgBox(NULL,IDS_ERROutOfMemory,MB_ICONEXCLAMATION,MB_OK);
  75. fOK = FALSE;
  76. // fall through and clean up any successful allocs below
  77. }
  78. if (fOK) {
  79. DWORD dwFlags = 0;
  80. ParseCommandLine(lpCmdLine,&dwFlags);
  81. if (dwFlags & RSW_UNINSTALL) {
  82. // do uninstall if we got /uninstall on command line
  83. DoUninstall();
  84. } else {
  85. RunSignupWizard(dwFlags);
  86. }
  87. }
  88. // free global structures
  89. if (gpWizardState)
  90. delete gpWizardState;
  91. if (gpUserInfo)
  92. delete gpUserInfo;
  93. if (gpEnumModem)
  94. delete gpEnumModem;
  95. if (gpRasEntry)
  96. GlobalFree(gpRasEntry);
  97. //
  98. // pass back the info, that the app needs to reboot or not
  99. // MKarki - 5/2/97 - Fix for Bug#3111
  100. //
  101. *pReboot = g_bReboot;
  102. } //end of LaunchSignupWizard API call
  103. /*******************************************************************
  104. NAME: LaunchSignupWizardEx
  105. SYNOPSIS: Entry point for Internet Setup Wizard UI with back
  106. capabilities. It will retain previous information
  107. if called multiple times. The caller *MUST* call
  108. FreeSignupWizard when done.
  109. PARAMETERS:
  110. lpCmdLine - Command line with instructions
  111. nReserved - Reserved for future use
  112. RETURNS: ERROR_SUCCESS Everything's okay, wizard finished
  113. ERROR_CONTINUE User pressed back on first page
  114. ERROR_CANCELLED User cancelled out of wizard
  115. <other> Deadly error (message already displayed)
  116. ********************************************************************/
  117. extern "C" DWORD WINAPI
  118. LaunchSignupWizardEx (
  119. LPTSTR lpCmdLine,
  120. int nReserved,
  121. PBOOL pReboot
  122. )
  123. {
  124. DWORD dwRet = ERROR_SUCCESS;
  125. BOOL fFirstTime = FALSE;
  126. // allocate global structures if needed
  127. if (!gpWizardState)
  128. {
  129. gpWizardState = new WIZARDSTATE;
  130. fFirstTime = TRUE;
  131. }
  132. else
  133. {
  134. gpWizardState->uCurrentPage = ORD_PAGE_HOWTOCONNECT;
  135. gpWizardState->uPagesCompleted = 0;
  136. }
  137. if (!gpUserInfo)
  138. {
  139. gpUserInfo = new USERINFO;
  140. fFirstTime = TRUE;
  141. }
  142. if (!gpRasEntry)
  143. {
  144. gdwRasEntrySize = sizeof(RASENTRY);
  145. gpRasEntry = (LPRASENTRY) GlobalAlloc(GPTR,gdwRasEntrySize);
  146. fFirstTime = TRUE;
  147. }
  148. if (!gpWizardState || !gpUserInfo || !gpRasEntry)
  149. {
  150. MsgBox(NULL,IDS_ERROutOfMemory,MB_ICONEXCLAMATION,MB_OK);
  151. dwRet = ERROR_NOT_ENOUGH_MEMORY;
  152. }
  153. if (ERROR_SUCCESS == dwRet)
  154. {
  155. DWORD dwFlags = 0;
  156. ParseCommandLine(lpCmdLine,&dwFlags);
  157. if (dwFlags & RSW_UNINSTALL)
  158. {
  159. // do uninstall if we got /uninstall on command line
  160. DoUninstall();
  161. }
  162. else
  163. {
  164. gfUserFinished = FALSE;
  165. gfUserBackedOut = FALSE;
  166. gfUserCancelled = FALSE;
  167. gfQuitWizard = FALSE;
  168. // On the first call, don't free the globals, we
  169. // may be called again. On subsequent calls, don't
  170. // initialize the globals either.
  171. dwFlags |= RSW_NOFREE;
  172. if (!fFirstTime)
  173. dwFlags |= RSW_NOINIT;
  174. RunSignupWizard(dwFlags);
  175. if (gfUserFinished)
  176. dwRet = ERROR_SUCCESS;
  177. else if (gfUserBackedOut)
  178. dwRet = ERROR_CONTINUE;
  179. else if (gfUserCancelled)
  180. dwRet = ERROR_CANCELLED;
  181. else
  182. dwRet = ERROR_GEN_FAILURE;
  183. }
  184. }
  185. //
  186. // pass back the info, that the app needs to reboot or not
  187. // MKarki (5/2/97) Fix for Bug #3111
  188. //
  189. *pReboot = g_bReboot;
  190. return dwRet;
  191. } // end of LaunchSignupWizardEx API
  192. /****************************************************************************
  193. NAME: FreeSignupWizard
  194. SYNOPSIS: Frees the global structures explicitely. This must be called
  195. if LaunchSignupWizardEx is used.
  196. ****************************************************************************/
  197. extern "C" VOID WINAPI FreeSignupWizard(VOID)
  198. {
  199. if (gpWizardState)
  200. {
  201. delete gpWizardState;
  202. gpWizardState = NULL;
  203. }
  204. if (gpUserInfo)
  205. {
  206. delete gpUserInfo;
  207. gpUserInfo = NULL;
  208. }
  209. if (gpRasEntry)
  210. {
  211. GlobalFree(gpRasEntry);
  212. gpRasEntry = NULL;
  213. gdwRasEntrySize = 0;
  214. }
  215. if (gpEnumModem)
  216. {
  217. delete gpEnumModem;
  218. gpEnumModem = NULL;
  219. }
  220. if (gpImnApprentice)
  221. {
  222. gpImnApprentice->Release();
  223. gpImnApprentice = NULL;
  224. }
  225. if (gfOleInitialized)
  226. CoUninitialize();
  227. }
  228. /****************************************************************************
  229. NAME: ParseCommandLine
  230. SYNOPSIS: Parses command line
  231. ****************************************************************************/
  232. BOOL ParseCommandLine(LPTSTR lpszCommandLine,DWORD * pdwFlags)
  233. {
  234. if (!lpszCommandLine || !*lpszCommandLine)
  235. return TRUE; // nothing to do
  236. ASSERT(pdwFlags);
  237. *pdwFlags = 0;
  238. while (*lpszCommandLine) {
  239. TCHAR szCommand[SMALL_BUF_LEN+1];
  240. lpszCommandLine = GetTextToNextSpace(lpszCommandLine,
  241. szCommand,sizeof(szCommand));
  242. if (!lstrcmpi(szCommand,szNOREBOOT)) {
  243. DEBUGMSG("Got /NOREBOOT command line switch");
  244. *pdwFlags |= RSW_NOREBOOT;
  245. }
  246. if (!lstrcmpi(szCommand,szUNINSTALL)) {
  247. DEBUGMSG("Got /UNINSTALL command line switch");
  248. *pdwFlags |= RSW_UNINSTALL;
  249. }
  250. if (!lstrcmpi(szCommand,szNOMSN)) {
  251. DEBUGMSG("Got /NOMSN command line switch");
  252. *pdwFlags |= RSW_NOMSN;
  253. }
  254. if (!lstrcmpi(szCommand,szNOIMN)) {
  255. DEBUGMSG("Got /NOIMN command line switch");
  256. *pdwFlags |= RSW_NOIMN;
  257. }
  258. }
  259. return TRUE;
  260. }
  261. /****************************************************************************
  262. NAME: GetTextToNextSpace
  263. SYNOPSIS: Gets text up to next space or end of string, places in
  264. output buffer
  265. ****************************************************************************/
  266. TCHAR * GetTextToNextSpace(LPTSTR pszText,TCHAR * pszOutBuf,UINT cbOutBuf)
  267. {
  268. ASSERT(pszText);
  269. ASSERT(pszOutBuf);
  270. lstrcpy(pszOutBuf,szNull);
  271. if (!pszText)
  272. return NULL;
  273. // advance past spaces
  274. while (*pszText == ' ')
  275. pszText ++;
  276. while (*pszText && (*pszText != ' ') && cbOutBuf>1) {
  277. *pszOutBuf = *pszText;
  278. pszOutBuf ++;
  279. cbOutBuf --;
  280. pszText ++;
  281. }
  282. if (cbOutBuf)
  283. *pszOutBuf = '\0'; // null-terminate
  284. while (*pszText == ' ')
  285. pszText++; // advance past spaces
  286. return pszText;
  287. }