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.

427 lines
9.9 KiB

  1. // Display.cpp : Defines the entry point for the console application.
  2. //
  3. #include "headers.hxx"
  4. #include <comdef.h>
  5. #include <crtdbg.h>
  6. #include "AdsiHelpers.hpp"
  7. #include "CSVDSReader.hpp"
  8. #include "AnalysisResults.hpp"
  9. #include "Analysis.hpp"
  10. #include "repair.hpp"
  11. #include "resource.h"
  12. #include "constants.hpp"
  13. #include "WelcomePage.hpp"
  14. #include "AnalysisPage.hpp"
  15. #include "constants.hpp"
  16. #include "UpdatesRequiredPage.hpp"
  17. #include "UpdatesPage.hpp"
  18. #include "FinishPage.hpp"
  19. HINSTANCE hResourceModuleHandle = 0;
  20. const wchar_t* HELPFILE_NAME = 0; // no context help available
  21. // don't change this: it is also the name of a mutex that the ui
  22. // uses to determine if it is already running.
  23. const wchar_t* RUNTIME_NAME = L"dspecup";
  24. DWORD DEFAULT_LOGGING_OPTIONS =
  25. Log::OUTPUT_TO_FILE
  26. | Log::OUTPUT_FUNCCALLS
  27. | Log::OUTPUT_LOGS
  28. | Log::OUTPUT_ERRORS
  29. | Log::OUTPUT_HEADER;
  30. Popup popup(IDS_APP_TITLE, false);
  31. // this is the mutex that indicates the program is running.
  32. HANDLE appRunningMutex = INVALID_HANDLE_VALUE;
  33. // these are the valid exit codes returned as the process exit code
  34. enum ExitCode
  35. {
  36. // the operation failed.
  37. EXIT_CODE_UNSUCCESSFUL = 0,
  38. // the operation succeeded
  39. EXIT_CODE_SUCCESSFUL = 1,
  40. };
  41. HRESULT
  42. Start()
  43. {
  44. LOG_FUNCTION(Start);
  45. HRESULT hr = S_OK;
  46. do
  47. {
  48. String targetDomainControllerName;
  49. String csvFileName,csv409Name;
  50. hr=GetInitialInformation(
  51. targetDomainControllerName,
  52. csvFileName,
  53. csv409Name
  54. );
  55. BREAK_ON_FAILED_HRESULT(hr);
  56. AnalysisResults results;
  57. CSVDSReader csvReaderIntl;
  58. hr=csvReaderIntl.read(csvFileName.c_str(),LOCALEIDS);
  59. BREAK_ON_FAILED_HRESULT(hr);
  60. CSVDSReader csvReader409;
  61. hr=csvReader409.read(csv409Name.c_str(),LOCALE409);
  62. BREAK_ON_FAILED_HRESULT(hr);
  63. String rootContainerDn,ldapPrefix,domainName;
  64. hr=InitializeADSI(
  65. targetDomainControllerName,
  66. ldapPrefix,
  67. rootContainerDn,
  68. domainName);
  69. BREAK_ON_FAILED_HRESULT(hr);
  70. String reportName;
  71. hr=GetFileName(L"RPT",reportName);
  72. BREAK_ON_FAILED_HRESULT(hr);
  73. Analysis analysis(
  74. csvReader409,
  75. csvReaderIntl,
  76. ldapPrefix,
  77. rootContainerDn,
  78. results,
  79. &reportName);
  80. hr=analysis.run();
  81. BREAK_ON_FAILED_HRESULT(hr);
  82. String ldiffName;
  83. hr=GetFileName(L"LDF",ldiffName);
  84. BREAK_ON_FAILED_HRESULT(hr);
  85. String csvName;
  86. hr=GetFileName(L"CSV",csvName);
  87. BREAK_ON_FAILED_HRESULT(hr);
  88. String saveName;
  89. hr=GetFileName(L"SAV",saveName);
  90. BREAK_ON_FAILED_HRESULT(hr);
  91. String logPath;
  92. hr=GetMyDocuments(logPath);
  93. if ( FAILED(hr) )
  94. {
  95. hr=Win::GetTempPath(logPath);
  96. BREAK_ON_FAILED_HRESULT_ERROR(hr,String::format(IDS_NO_WORK_PATH));
  97. }
  98. Repair repair(
  99. csvReader409,
  100. csvReaderIntl,
  101. domainName,
  102. rootContainerDn,
  103. results,
  104. ldiffName,
  105. csvName,
  106. saveName,
  107. logPath);
  108. hr=repair.run();
  109. BREAK_ON_FAILED_HRESULT(hr);
  110. hr=SetPreviousSuccessfullRun(
  111. ldapPrefix,
  112. rootContainerDn
  113. );
  114. BREAK_ON_FAILED_HRESULT(hr);
  115. }
  116. while (0);
  117. if (FAILED(hr))
  118. {
  119. ShowError(hr,error);
  120. }
  121. LOG_HRESULT(hr);
  122. return hr;
  123. }
  124. HRESULT
  125. StartUI()
  126. {
  127. LOG_FUNCTION(StartUI);
  128. HRESULT hr = S_OK;
  129. String rootContainerDn,ldapPrefix,domainName;
  130. do
  131. {
  132. String targetDomainControllerName;
  133. String csvFileName,csv409Name;
  134. hr=GetInitialInformation(
  135. targetDomainControllerName,
  136. csvFileName,
  137. csv409Name
  138. );
  139. BREAK_ON_FAILED_HRESULT(hr);
  140. AnalysisResults results;
  141. CSVDSReader csvReaderIntl;
  142. hr=csvReaderIntl.read(csvFileName.c_str(),LOCALEIDS);
  143. BREAK_ON_FAILED_HRESULT(hr);
  144. CSVDSReader csvReader409;
  145. hr=csvReader409.read(csv409Name.c_str(),LOCALE409);
  146. BREAK_ON_FAILED_HRESULT(hr);
  147. hr=InitializeADSI(
  148. targetDomainControllerName,
  149. ldapPrefix,
  150. rootContainerDn,
  151. domainName);
  152. BREAK_ON_FAILED_HRESULT(hr);
  153. Wizard wiz(
  154. IDS_WIZARD_TITLE,
  155. IDB_BANNER16,
  156. IDB_BANNER256,
  157. IDB_WATERMARK16,
  158. IDB_WATERMARK256
  159. );
  160. wiz.AddPage(new WelcomePage());
  161. String reportName;
  162. hr=GetFileName(L"RPT",reportName);
  163. BREAK_ON_FAILED_HRESULT(hr);
  164. wiz.AddPage(
  165. new AnalysisPage
  166. (
  167. csvReader409,
  168. csvReaderIntl,
  169. ldapPrefix,
  170. rootContainerDn,
  171. results,
  172. reportName
  173. )
  174. );
  175. wiz.AddPage(
  176. new UpdatesRequiredPage
  177. (
  178. reportName,
  179. results
  180. )
  181. );
  182. String ldiffName;
  183. hr=GetFileName(L"LDF",ldiffName);
  184. BREAK_ON_FAILED_HRESULT(hr);
  185. String csvName;
  186. hr=GetFileName(L"CSV",csvName);
  187. BREAK_ON_FAILED_HRESULT(hr);
  188. String saveName;
  189. hr=GetFileName(L"SAV",saveName);
  190. BREAK_ON_FAILED_HRESULT(hr);
  191. String logPath;
  192. hr=GetMyDocuments(logPath);
  193. if ( FAILED(hr) )
  194. {
  195. hr=Win::GetTempPath(logPath);
  196. BREAK_ON_FAILED_HRESULT_ERROR(hr,String::format(IDS_NO_WORK_PATH));
  197. }
  198. bool someRepairWasRun=false;
  199. wiz.AddPage(
  200. new UpdatesPage
  201. (
  202. csvReader409,
  203. csvReaderIntl,
  204. domainName,
  205. rootContainerDn,
  206. ldiffName,
  207. csvName,
  208. saveName,
  209. logPath,
  210. results,
  211. &someRepairWasRun
  212. )
  213. );
  214. wiz.AddPage(
  215. new FinishPage(
  216. someRepairWasRun,
  217. logPath
  218. )
  219. );
  220. hr=wiz.ModalExecute(Win::GetDesktopWindow());
  221. BREAK_ON_FAILED_HRESULT(hr);
  222. }
  223. while (0);
  224. if (FAILED(hr))
  225. {
  226. ShowError(hr,error);
  227. }
  228. else
  229. {
  230. if(FAILED(hrError))
  231. {
  232. // The error has already been shown to the
  233. // user, we have only to return it
  234. hr=hrError;
  235. }
  236. else
  237. {
  238. hr=SetPreviousSuccessfullRun(
  239. ldapPrefix,
  240. rootContainerDn
  241. );
  242. if (FAILED(hr))
  243. {
  244. ShowError(hr,error);
  245. }
  246. }
  247. }
  248. LOG_HRESULT(hr);
  249. return hr;
  250. }
  251. int WINAPI
  252. WinMain(
  253. HINSTANCE hInstance,
  254. HINSTANCE /* hPrevInstance */ ,
  255. LPSTR lpszCmdLine,
  256. int /* nCmdShow */)
  257. {
  258. LOG_FUNCTION(WinMain);
  259. hResourceModuleHandle = hInstance;
  260. ExitCode exitCode = EXIT_CODE_UNSUCCESSFUL;
  261. HRESULT hr;
  262. do
  263. {
  264. try
  265. {
  266. String cmdLine(lpszCmdLine);
  267. String noUI=String::format(IDS_NOUI);
  268. if (*lpszCmdLine!=0 && cmdLine.icompare(noUI)!=0)
  269. {
  270. error=String::format(IDS_USAGE);
  271. ShowError(E_FAIL,error);
  272. exitCode = EXIT_CODE_UNSUCCESSFUL;
  273. break;
  274. }
  275. hr = Win::CreateMutex(0, true, RUNTIME_NAME, appRunningMutex);
  276. if (hr == Win32ToHresult(ERROR_ALREADY_EXISTS))
  277. {
  278. // The application is already running
  279. error=String::format(IDS_ALREADY_RUNNING);
  280. ShowError(E_FAIL,error);
  281. exitCode = EXIT_CODE_UNSUCCESSFUL;
  282. break;
  283. }
  284. else
  285. {
  286. hr = ::CoInitialize(0);
  287. ASSERT(SUCCEEDED(hr));
  288. INITCOMMONCONTROLSEX sex;
  289. sex.dwSize = sizeof(sex);
  290. sex.dwICC = ICC_ANIMATE_CLASS | ICC_USEREX_CLASSES;
  291. BOOL init = ::InitCommonControlsEx(&sex);
  292. ASSERT(init);
  293. setReplaceW2KStrs();
  294. if (*lpszCmdLine==0)
  295. {
  296. hr = StartUI();
  297. }
  298. else
  299. {
  300. hr = Start();
  301. }
  302. //hr=makeStrings();
  303. if (SUCCEEDED(hr))
  304. {
  305. exitCode = EXIT_CODE_SUCCESSFUL;
  306. }
  307. else
  308. {
  309. exitCode = EXIT_CODE_UNSUCCESSFUL;
  310. }
  311. CoUninitialize();
  312. }
  313. }
  314. catch( std::bad_alloc )
  315. {
  316. // Since we are in an out of memory condition.
  317. // we will not show any messages.
  318. // The allocation functions have already
  319. // shown the user this condition
  320. exitCode = EXIT_CODE_UNSUCCESSFUL;
  321. }
  322. } while(0);
  323. return static_cast<int>(exitCode);
  324. }