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.

214 lines
5.0 KiB

  1. // Copyright (c) 2001 Microsoft Corporation
  2. //
  3. // File: NetDetectProgressDialog.cpp
  4. //
  5. // Synopsis: Defines the NetDetectProgressDialog which
  6. // gives a nice animation while detecting the
  7. // network settings
  8. //
  9. // History: 06/13/2001 JeffJon Created
  10. #include "pch.h"
  11. #include "resource.h"
  12. #include "InstallationUnitProvider.h"
  13. #include "NetDetectProgressDialog.h"
  14. #include "DisconnectedNICDialog.h"
  15. // Private window messages for sending the state of the finished thread
  16. const UINT NetDetectProgressDialog::CYS_THREAD_SUCCESS = WM_USER + 1001;
  17. const UINT NetDetectProgressDialog::CYS_THREAD_FAILED = WM_USER + 1002;
  18. const UINT NetDetectProgressDialog::CYS_THREAD_USER_CANCEL = WM_USER + 1003;
  19. void _cdecl
  20. netDetectThreadProc(void* p)
  21. {
  22. if (!p)
  23. {
  24. ASSERT(p);
  25. return;
  26. }
  27. NetDetectProgressDialog* dialog =
  28. reinterpret_cast<NetDetectProgressDialog*>(p);
  29. if (!dialog)
  30. {
  31. ASSERT(dialog);
  32. return;
  33. }
  34. // Initialize COM for this thread
  35. HRESULT hr = ::CoInitialize(0);
  36. if (FAILED(hr))
  37. {
  38. ASSERT(SUCCEEDED(hr));
  39. return;
  40. }
  41. Win::WaitCursor wait;
  42. unsigned int finishMessage = NetDetectProgressDialog::CYS_THREAD_SUCCESS;
  43. HWND hwnd = dialog->GetHWND();
  44. // Gather the machine network and role information
  45. State& state = State::GetInstance();
  46. if (!state.HasStateBeenRetrieved())
  47. {
  48. bool isDNSServer =
  49. InstallationUnitProvider::GetInstance().
  50. GetDNSInstallationUnit().IsServiceInstalled();
  51. bool isDHCPServer =
  52. InstallationUnitProvider::GetInstance().
  53. GetDHCPInstallationUnit().IsServiceInstalled();
  54. bool isRRASServer =
  55. InstallationUnitProvider::GetInstance().
  56. GetRRASInstallationUnit().IsServiceInstalled();
  57. bool doDHCPCheck = !isDNSServer && !isDHCPServer && !isRRASServer;
  58. if (!state.RetrieveMachineConfigurationInformation(
  59. Win::GetDlgItem(hwnd, IDC_STATUS_STATIC),
  60. doDHCPCheck,
  61. IDS_RETRIEVE_NIC_INFO,
  62. IDS_RETRIEVE_OS_INFO,
  63. IDS_LOCAL_AREA_CONNECTION,
  64. IDS_DETECTING_SETTINGS_FORMAT))
  65. {
  66. LOG(L"The machine configuration could not be retrieved.");
  67. ASSERT(false);
  68. finishMessage = NetDetectProgressDialog::CYS_THREAD_FAILED;
  69. }
  70. }
  71. if (finishMessage == NetDetectProgressDialog::CYS_THREAD_SUCCESS)
  72. {
  73. // check to make sure all interfaces are connected
  74. ASSERT(state.HasStateBeenRetrieved());
  75. for (unsigned int index = 0; index < state.GetNICCount(); ++index)
  76. {
  77. NetworkInterface* nic = state.GetNIC(index);
  78. if (!nic)
  79. {
  80. continue;
  81. }
  82. if (!nic->IsConnected())
  83. {
  84. // The NIC isn't connected so pop the warning
  85. // dialog and let the user determine whether to
  86. // continue or not
  87. DisconnectedNICDialog disconnectedNICDialog;
  88. if (IDCANCEL == disconnectedNICDialog.ModalExecute(hwnd))
  89. {
  90. // The user chose to cancel the wizard
  91. finishMessage = NetDetectProgressDialog::CYS_THREAD_USER_CANCEL;
  92. }
  93. break;
  94. }
  95. }
  96. }
  97. Win::SendMessage(
  98. hwnd,
  99. finishMessage,
  100. 0,
  101. 0);
  102. CoUninitialize();
  103. }
  104. static const DWORD HELP_MAP[] =
  105. {
  106. 0, 0
  107. };
  108. NetDetectProgressDialog::NetDetectProgressDialog()
  109. :
  110. shouldCancel(false),
  111. Dialog(
  112. IDD_NET_DETECT_PROGRESS_DIALOG,
  113. HELP_MAP)
  114. {
  115. LOG_CTOR(NetDetectProgressDialog);
  116. }
  117. NetDetectProgressDialog::~NetDetectProgressDialog()
  118. {
  119. LOG_DTOR(NetDetectProgressDialog);
  120. }
  121. void
  122. NetDetectProgressDialog::OnInit()
  123. {
  124. LOG_FUNCTION(NetDetectProgressDialog::OnInit);
  125. // Start up the animation
  126. Win::Animate_Open(
  127. Win::GetDlgItem(hwnd, IDC_ANIMATION),
  128. MAKEINTRESOURCE(IDR_SEARCH_AVI));
  129. // Start up another thread that will perform the operations
  130. // and post messages back to the page to update the UI
  131. _beginthread(netDetectThreadProc, 0, this);
  132. }
  133. bool
  134. NetDetectProgressDialog::OnMessage(
  135. UINT message,
  136. WPARAM /*wparam*/,
  137. LPARAM /*lparam*/)
  138. {
  139. // LOG_FUNCTION(NetDetectProgressDialog::OnMessage);
  140. bool result = false;
  141. switch (message)
  142. {
  143. case CYS_THREAD_USER_CANCEL:
  144. shouldCancel = true;
  145. // fall through...
  146. case CYS_THREAD_SUCCESS:
  147. case CYS_THREAD_FAILED:
  148. {
  149. Win::Animate_Stop(Win::GetDlgItem(hwnd, IDC_ANIMATION));
  150. HRESULT unused = Win::EndDialog(hwnd, message);
  151. ASSERT(SUCCEEDED(unused));
  152. result = true;
  153. break;
  154. }
  155. default:
  156. {
  157. // do nothing
  158. break;
  159. }
  160. }
  161. return result;
  162. }