Source code of Windows XP (NT5)
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.

174 lines
2.4 KiB

  1. // Copyright (C) 1997-2000 Microsoft Corporation
  2. //
  3. // get syskey on diskette for replica from media page
  4. //
  5. // 25 Apr 2000 sburns
  6. #include "headers.hxx"
  7. #include "resource.h"
  8. #include "page.hpp"
  9. #include "SyskeyDiskDialog.hpp"
  10. #include "state.hpp"
  11. static const DWORD HELP_MAP[] =
  12. {
  13. 0, 0
  14. };
  15. SyskeyDiskDialog::SyskeyDiskDialog()
  16. :
  17. Dialog(IDD_SYSKEY_DISK, HELP_MAP)
  18. {
  19. LOG_CTOR(SyskeyDiskDialog);
  20. }
  21. SyskeyDiskDialog::~SyskeyDiskDialog()
  22. {
  23. LOG_DTOR(SyskeyDiskDialog);
  24. }
  25. void
  26. SyskeyDiskDialog::OnInit()
  27. {
  28. LOG_FUNCTION(SyskeyDiskDialog::OnInit);
  29. State& state = State::GetInstance();
  30. if (state.RunHiddenUnattended())
  31. {
  32. if (Validate())
  33. {
  34. Win::EndDialog(hwnd, IDOK);
  35. }
  36. else
  37. {
  38. state.ClearHiddenWhileUnattended();
  39. }
  40. }
  41. }
  42. bool
  43. SyskeyDiskDialog::OnCommand(
  44. HWND /* windowFrom */ ,
  45. unsigned controlIdFrom,
  46. unsigned code)
  47. {
  48. // LOG_FUNCTION(SyskeyDiskDialog::OnCommand);
  49. switch (controlIdFrom)
  50. {
  51. case IDOK:
  52. {
  53. if (code == BN_CLICKED)
  54. {
  55. if (Validate())
  56. {
  57. Win::EndDialog(hwnd, controlIdFrom);
  58. }
  59. }
  60. break;
  61. }
  62. case IDCANCEL:
  63. {
  64. if (code == BN_CLICKED)
  65. {
  66. Win::EndDialog(hwnd, controlIdFrom);
  67. }
  68. break;
  69. }
  70. default:
  71. {
  72. // do nothing
  73. break;
  74. }
  75. }
  76. return false;
  77. }
  78. HRESULT
  79. LocateSyskey(HWND hwnd)
  80. {
  81. LOG_FUNCTION(LocateSyskey);
  82. ASSERT(Win::IsWindow(hwnd));
  83. HRESULT hr = S_OK;
  84. do
  85. {
  86. if (FS::PathExists(L"A:\\StartKey.Key"))
  87. {
  88. LOG(L"syskey found on a:");
  89. break;
  90. }
  91. hr = E_FAIL;
  92. popup.Error(hwnd, IDS_SYSKEY_NOT_FOUND);
  93. }
  94. while (0);
  95. LOG_HRESULT(hr);
  96. return hr;
  97. }
  98. bool
  99. SyskeyDiskDialog::Validate()
  100. {
  101. LOG_FUNCTION(SyskeyDiskDialog::Validate);
  102. State& state = State::GetInstance();
  103. bool result = false;
  104. do
  105. {
  106. // look for the syskey
  107. HRESULT hr = LocateSyskey(hwnd);
  108. if (FAILED(hr))
  109. {
  110. // LocateSyskey will take care of emitting error messages, so
  111. // we just need to bail out here
  112. break;
  113. }
  114. // The only drive the syskey may be present on is A:.
  115. EncodedString es;
  116. es.Encode(L"A:");
  117. state.SetSyskey(es);
  118. result = true;
  119. }
  120. while (0);
  121. LOG(result ? L"true" : L"false");
  122. return result;
  123. }