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.

412 lines
12 KiB

  1. /*------------------------------------------------------------------------
  2. | nt40.c - nt4.0 non-pnp setup.exe code - WinMain, etc.
  3. 12-11-98 - use szAppTitle(.rc str) instead of aptitle for prop sheet title.
  4. |------------------------------------------------------------------------*/
  5. #include "precomp.h"
  6. /*----------------------- local vars ---------------------------------*/
  7. static int unattended_flag = 0;
  8. static int test_mode = 0;
  9. static HMENU hMenuMain;
  10. int do_progman_add = 0;
  11. static int auto_install(void);
  12. // for nt4.0, we are a .EXE, so we need a WinMain...
  13. /*------------------------------------------------------------------------
  14. | WinMain - Main program entry for NT4.0 EXE setup program.
  15. |------------------------------------------------------------------------*/
  16. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  17. LPSTR lpCmdLine, int nCmdShow)
  18. {
  19. MSG msg;
  20. WNDCLASS wc;
  21. HWND hwnd;
  22. HACCEL hAccel;
  23. char *buf;
  24. int i, stat;
  25. #if DBG
  26. DebugLevel |= (D_Test | D_Error) ;
  27. #endif
  28. glob_hinst = hInstance; // ptr to dll hinstance
  29. if (hPrevInstance) // Other instances of app running?
  30. {
  31. MessageBox(0,"Program is already running!","",MB_OK);
  32. return 0;
  33. }
  34. InitCommonControls(); // Initialize the common control library.
  35. if (setup_init())
  36. {
  37. return 0;
  38. }
  39. buf = lpCmdLine;
  40. i=0;
  41. while ((*buf != 0) && (i < 80))
  42. {
  43. if ((*buf == '-') || (*buf == '/'))
  44. {
  45. ++buf;
  46. ++i;
  47. switch(toupper(*buf++))
  48. {
  49. case 'A': // auto-install
  50. unattended_flag = 1;
  51. break;
  52. //return stat;
  53. case 'H': // help
  54. our_help(&wi->ip, WIN_NT);
  55. return 0;
  56. case 'P': // add program manager group
  57. do_progman_add = 1; // add progman group
  58. break;
  59. case 'N':
  60. wi->install_style = INS_SIMPLE; // default to original nt4.0 style
  61. break;
  62. case 'R': // remove driver and files
  63. // stat = our_message(&wi->ip,
  64. //"Would you like this setup program to remove this driver and related files?",
  65. // MB_YESNO);
  66. // if (stat == IDYES)
  67. if (toupper(*buf) == 'A')
  68. remove_driver(1);
  69. else
  70. remove_driver(0);
  71. return 0;
  72. case 'T': // test mode, run only to test ui
  73. test_mode = 1;
  74. break;
  75. case 'Z': // test mode, run only to test
  76. if (toupper(*buf) == 'I')
  77. setup_service(OUR_INSTALL_START, OUR_SERVICE); // do a remove on the service
  78. else
  79. setup_service(OUR_REMOVE, OUR_SERVICE); // do a remove on the service
  80. return 0;
  81. case '?': // our help
  82. stat = our_message(&wi->ip,
  83. "options>SETUP /options\n \
  84. A - auto install routine\n \
  85. P - add program manager group\n \
  86. N - no inf file, simple install\n \
  87. H - display driver help info\n \
  88. R - remove driver(should do from control-panel first)",
  89. MB_OK);
  90. return 0;
  91. } // switch
  92. } // if (option)
  93. ++i;
  94. ++buf;
  95. } // while options
  96. if (unattended_flag)
  97. {
  98. unattended_add_port_entries(&wi->ip,
  99. 8, // num_entries
  100. 5); // start_port:com5
  101. stat = auto_install();
  102. return stat;
  103. }
  104. if (!hPrevInstance) // Other instances of app running?
  105. {
  106. // MAIN WINDOW
  107. wc.style = CS_HREDRAW | CS_VREDRAW; // Class style(s).
  108. wc.lpfnWndProc = MainWndProc;
  109. wc.cbClsExtra = 0; // No per-class extra data.
  110. wc.cbWndExtra = 0; // No per-window extra data.
  111. wc.hInstance = hInstance; // Application that owns the class.
  112. wc.hIcon = LoadIcon(hInstance, "SETUPICON");
  113. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  114. wc.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE + 1);
  115. wc.lpszMenuName = NULL; // Name of menu resource in .RC file.
  116. wc.lpszClassName = szAppName; // Name used in call to CreateWindow.
  117. RegisterClass(&wc);
  118. }
  119. hMenuMain = LoadMenu (glob_hinst, "MAIN_MENU");
  120. hAccel = LoadAccelerators (glob_hinst, "SetupAccel") ;
  121. /* Create a main window for this application instance. */
  122. hwnd = CreateWindowEx(
  123. WS_EX_CONTEXTHELP, // gives question mark help thing
  124. szAppName, // See RegisterClass() call.
  125. // Text for window title bar.
  126. szAppTitle,
  127. WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPCHILDREN,
  128. // WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, // Window style.
  129. // CW_USEDEFAULT, CW_USEDEFAULT, // Def. horz, vert pos.
  130. 0,0, // Def. horz, vert pos.
  131. 300, 200, // Default width, height
  132. // 455, 435, // Default width, height
  133. NULL, // No Parent Window
  134. hMenuMain, // Use the window class menu.
  135. hInstance, // This instance owns this window.
  136. NULL); // Pointer not needed.
  137. //ShowWindow (hwnd, nCmdShow);
  138. //UpdateWindow (hwnd);
  139. // Enter the modified message loop
  140. while (GetMessage(&msg, NULL, 0, 0))
  141. {
  142. if (!TranslateAccelerator (hwnd, hAccel, &msg))
  143. {
  144. if (glob_hDlg == 0 || !IsDialogMessage(glob_hDlg, &msg))
  145. {
  146. TranslateMessage(&msg);
  147. DispatchMessage(&msg);
  148. }
  149. }
  150. }
  151. return msg.wParam;
  152. }
  153. /*------------------------------------------------------------------------
  154. | MainWndProc - Main Window Proc.
  155. |------------------------------------------------------------------------*/
  156. LRESULT FAR PASCAL MainWndProc(HWND hwnd, UINT message,
  157. WPARAM wParam, LPARAM lParam)
  158. {
  159. HDC hdc;
  160. PAINTSTRUCT ps;
  161. int stat;
  162. int QuitFlag = 0;
  163. switch (message)
  164. {
  165. case WM_CREATE: // Initialize Global vars
  166. glob_hwnd = hwnd;
  167. wi->NumDevices = 0;
  168. get_nt_config(wi); // Read the configuration information from the registry.
  169. copy_setup_init(); // make a copy of config data for change detection
  170. validate_config(1); // validate and auto-fixup if config hosed
  171. // src_dir should always equal dest_dir since
  172. // INF copies files over files in NT. Otherwise they
  173. // are running setup.exe before doing network install
  174. if (my_lstricmp(wi->ip.src_dir, wi->ip.dest_dir) != 0)
  175. {
  176. if (wi->ip.major_ver < 5) // NT5.0 does not support 4.0 network inf files
  177. {
  178. if (wi->install_style != INS_SIMPLE)
  179. {
  180. // if they didn't explicitly ask for a non-adapter install
  181. // then: ask them(if allowed), or tell them about the control
  182. // panel/network to install correctly.
  183. #ifdef ALLOW_NON_NET_INSTALL
  184. stat = our_message(&wi->ip,
  185. "Would you like to install this software?",
  186. MB_YESNO);
  187. if (stat != IDYES)
  188. {
  189. stat = our_message(&wi->ip,
  190. "Would you like to view the help information?",MB_YESNO);
  191. if (stat == IDYES)
  192. our_help(&wi->ip, WIN_NT);
  193. QuitFlag = 1;
  194. PostQuitMessage(0); // end the setup program.
  195. }
  196. wi->install_style = INS_SIMPLE; // non-network adapter install
  197. do_progman_add = 1; // force full install
  198. #else
  199. if (!test_mode) // test mode to allow us to continue(for programmers)
  200. {
  201. stat = our_message(&wi->ip,
  202. "The software should be added as a network adapter in the control panel. \
  203. Would you like to view the help information?",MB_YESNO);
  204. if (stat == IDYES)
  205. our_help(&wi->ip, WIN_NT);
  206. QuitFlag = 1;
  207. PostQuitMessage(0); // end the setup program.
  208. }
  209. #endif
  210. }
  211. } // not nt5.0 or above
  212. if (wi->nt_reg_flags & 1) // not installed(missing important reg entries)
  213. {
  214. wi->install_style = INS_SIMPLE;
  215. // do full install since we are not running out of cur dir.
  216. do_progman_add = 1;
  217. }
  218. else // is installed, but running setup somewhere besides rocket dir
  219. {
  220. // just update the thing.
  221. wi->install_style = INS_SIMPLE;
  222. // do full install since we are not running out of cur dir.
  223. do_progman_add = 1;
  224. }
  225. }
  226. // if registry not setup correctly, and not asking for a simple
  227. // install, then tell them the registry is screwed up.
  228. if ( (wi->nt_reg_flags & 1) && (!(wi->install_style == INS_SIMPLE)))
  229. {
  230. stat = our_message(&wi->ip,
  231. "Some Registry entries are missing for this Software, You may need to \
  232. reinstall it from the Control Panel, Network applet. Are you sure you \
  233. want to continue?", MB_YESNO);
  234. if (stat != IDYES) {
  235. QuitFlag = 1;
  236. PostQuitMessage(0); // end the setup program.
  237. }
  238. }
  239. // the NT install INF file copys files to our install directory,
  240. // so the following check is not good indicator if it is "reinstall"
  241. if (my_lstricmp(wi->ip.src_dir, wi->ip.dest_dir) != 0)
  242. do_progman_add = 1;
  243. //----- fire up the main level of property sheets.
  244. if (!QuitFlag)
  245. // eliminate the flash of showing and erasing the property sheet
  246. DoDriverPropPages(hwnd); // in nt40.c
  247. // end the program.
  248. PostQuitMessage(0); // end the setup program.
  249. return 0;
  250. case WM_SETFOCUS:
  251. SetFocus(glob_hDlg);
  252. return 0;
  253. case WM_COMMAND: // message: command from application menu
  254. switch(wParam)
  255. {
  256. case IDM_F1:
  257. our_help(&wi->ip, WIN_NT);
  258. break;
  259. case IDM_ADVANCED_MODEM_INF:
  260. update_modem_inf(1);
  261. break;
  262. case IDM_PM: // Try out the add pm group dde stuff
  263. stat = make_progman_group(progman_list_nt, wi->ip.dest_dir);
  264. if (stat)
  265. {
  266. our_message(&wi->ip,"Error setting up Program group",MB_OK);
  267. return 0;
  268. }
  269. break;
  270. #ifdef COMMENT_OUT
  271. case IDM_ADVANCED:
  272. DialogBox(glob_hinst,
  273. MAKEINTRESOURCE(IDD_DRIVER_OPTIONS),
  274. hwnd,
  275. adv_driver_setup_dlg_proc);
  276. break;
  277. case IDM_EDIT_README: // edit readme.txt
  278. strcpy(gtmpstr, "notepad.exe ");
  279. strcat(gtmpstr, wi->ip.src_dir);
  280. strcat(gtmpstr,"\\readme.txt");
  281. WinExec(gtmpstr, SW_RESTORE);
  282. break;
  283. #endif
  284. return 0;
  285. case IDM_HELP:
  286. our_help(&wi->ip, WIN_NT);
  287. return 0;
  288. case IDM_HELPABOUT:
  289. strcpy(gtmpstr, szAppTitle);
  290. //strcpy(gtmpstr, aptitle);
  291. wsprintf(&gtmpstr[strlen(gtmpstr)],
  292. " Version %s\nCopyright (c) 1995-97 Comtrol Corp.",
  293. VERSION_STRING);
  294. MessageBox(hwnd, gtmpstr, "About",MB_OK);
  295. return 0;
  296. }
  297. break;
  298. case WM_SIZE:
  299. //frame_width = LOWORD(lParam);
  300. //frame_height = HIWORD(lParam);
  301. break; // have to let default have this too!
  302. case WM_PAINT:
  303. // PaintMainBMP(hwnd);
  304. hdc = BeginPaint(hwnd, &ps);
  305. EndPaint(hwnd, &ps);
  306. return 0;
  307. case WM_HELP: // question mark thing
  308. our_context_help(lParam);
  309. break;
  310. case WM_SYSCOMMAND:
  311. if ((wParam & 0xfff0) == SC_CLOSE)
  312. {
  313. if (allow_exit(1) == 0) // ok, quit
  314. {
  315. }
  316. else
  317. {
  318. return 0; // we handled this, don't exit app.
  319. }
  320. }
  321. break;
  322. case WM_QUIT:
  323. case WM_DESTROY: // message: window being destroyed
  324. PostQuitMessage(0);
  325. return 0 ;
  326. default:
  327. break;
  328. }
  329. return DefWindowProc(hwnd, message, wParam, lParam);
  330. }
  331. /*------------------------------------------------------------------------
  332. | auto_install - No prompt default installation, for automated installs.
  333. |------------------------------------------------------------------------*/
  334. static int auto_install(void)
  335. {
  336. //int stat;
  337. wi->ip.prompting_off = 1; // turn our_message() prompting off.
  338. get_nt_config(wi); // get configured io-addresses, irq, etc
  339. copy_setup_init(); // make a copy of config data for change detection
  340. // if 0 dev-nodes setup, add 1 for the user.
  341. if (wi->NumDevices == 0)
  342. {
  343. ++wi->NumDevices;
  344. validate_device(&wi->dev[0], 1);
  345. }
  346. do_install();
  347. return 0;
  348. }