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.

361 lines
7.9 KiB

  1. // Copyright (C) 1997 Microsoft Corporation
  2. //
  3. // paths, part 2 page
  4. //
  5. // 1-8-97 sburns
  6. #include "headers.hxx"
  7. #include "page.hpp"
  8. #include "Paths2Page.hpp"
  9. #include "resource.h"
  10. #include "state.hpp"
  11. #include "common.hpp"
  12. // NTRAID#NTBUG9-468577-2001/09/17-sburns
  13. static const int SYSVOL_MAX_PATH = 90;
  14. Paths2Page::Paths2Page()
  15. :
  16. DCPromoWizardPage(
  17. IDD_PATHS2,
  18. IDS_PATHS2_PAGE_TITLE,
  19. IDS_PATHS2_PAGE_SUBTITLE),
  20. touchWizButtons(true)
  21. {
  22. LOG_CTOR(Paths2Page);
  23. }
  24. Paths2Page::~Paths2Page()
  25. {
  26. LOG_DTOR(Paths2Page);
  27. }
  28. String
  29. DetermineDefaultSysvolPath()
  30. {
  31. LOG_FUNCTION(DetermineDefaultSysvolPath);
  32. // prefer windir, but if that's not ntfs 5, find one that is.
  33. String result = Win::GetSystemWindowsDirectory();
  34. if (FS::GetFileSystemType(result) != FS::NTFS5)
  35. {
  36. result = GetFirstNtfs5HardDrive();
  37. }
  38. else
  39. {
  40. result += L"\\";
  41. }
  42. LOG(result);
  43. return result;
  44. }
  45. void
  46. Paths2Page::OnInit()
  47. {
  48. LOG_FUNCTION(Paths2Page::OnInit);
  49. Win::Edit_LimitText(Win::GetDlgItem(hwnd, IDC_SYSVOL), SYSVOL_MAX_PATH);
  50. State& state = State::GetInstance();
  51. if (state.UsingAnswerFile())
  52. {
  53. Win::SetDlgItemText(
  54. hwnd,
  55. IDC_SYSVOL,
  56. Win::ExpandEnvironmentStrings(
  57. state.GetAnswerFileOption(AnswerFile::OPTION_SYSVOL_PATH)));
  58. }
  59. String root = DetermineDefaultSysvolPath();
  60. if (Win::GetTrimmedDlgItemText(hwnd, IDC_SYSVOL).empty())
  61. {
  62. Win::SetDlgItemText(
  63. hwnd,
  64. IDC_SYSVOL,
  65. root + String::load(IDS_SYSVOL_SUFFIX));
  66. }
  67. }
  68. void
  69. Paths2Page::Enable()
  70. {
  71. // touchWizButtons is managed in the OnCommand handler for EN_KILLFOCUS.
  72. // Turns out that if you call PropSheet_SetWizButtons while handling a kill
  73. // focus event, you mess up the tab processing so that the focus jumps to
  74. // the default wizard button. That's really cool -- NOT!
  75. if (touchWizButtons)
  76. {
  77. int next =
  78. !Win::GetTrimmedDlgItemText(hwnd, IDC_SYSVOL).empty()
  79. ? PSWIZB_NEXT : 0;
  80. Win::PropSheet_SetWizButtons(Win::GetParent(hwnd), PSWIZB_BACK | next);
  81. }
  82. }
  83. bool
  84. Paths2Page::OnCommand(
  85. HWND /* windowFrom */ ,
  86. unsigned controlIdFrom,
  87. unsigned code)
  88. {
  89. // LOG_FUNCTION(Paths2Page::OnCommand);
  90. bool result = false;
  91. switch (controlIdFrom)
  92. {
  93. case IDC_BROWSE:
  94. {
  95. if (code == BN_CLICKED)
  96. {
  97. String path = BrowseForFolder(hwnd, IDS_SYSVOL_BROWSE_TITLE);
  98. if (!path.empty())
  99. {
  100. Win::SetDlgItemText(hwnd, IDC_SYSVOL, path);
  101. }
  102. result = true;
  103. }
  104. break;
  105. }
  106. case IDC_SYSVOL:
  107. {
  108. switch (code)
  109. {
  110. case EN_CHANGE:
  111. {
  112. SetChanged(controlIdFrom);
  113. Enable();
  114. result = true;
  115. break;
  116. }
  117. case EN_KILLFOCUS:
  118. {
  119. // Since the normalization fully-expands relative paths, the
  120. // full pathname may not match what the user entered. So we
  121. // update the edit box contents to make sure they realize what
  122. // the relative path expands to.
  123. // NTRAID#NTBUG9-216148-2000/11/01-sburns
  124. String text = Win::GetTrimmedDlgItemText(hwnd, controlIdFrom);
  125. if (!text.empty())
  126. {
  127. // turn off setting of wizard buttons so that the call to
  128. // Enable made by the EN_CHANGE handler (which will be
  129. // called when we set the edit box text) will not call
  130. // PropSheet_SetWizButtons, which will mess up the tab
  131. // processing.
  132. touchWizButtons = false;
  133. Win::SetDlgItemText(
  134. hwnd,
  135. controlIdFrom,
  136. FS::NormalizePath(text));
  137. touchWizButtons = true;
  138. }
  139. result = true;
  140. break;
  141. }
  142. default:
  143. {
  144. // do nothing
  145. break;
  146. }
  147. }
  148. break;
  149. }
  150. default:
  151. {
  152. // do nothing
  153. break;
  154. }
  155. }
  156. return false;
  157. }
  158. bool
  159. Paths2Page::OnSetActive()
  160. {
  161. LOG_FUNCTION(Paths2Page::OnSetActive);
  162. Win::PropSheet_SetWizButtons(
  163. Win::GetParent(hwnd),
  164. PSWIZB_BACK);
  165. State& state = State::GetInstance();
  166. if (state.RunHiddenUnattended())
  167. {
  168. int nextPage = Validate();
  169. if (nextPage != -1)
  170. {
  171. GetWizard().SetNextPageID(hwnd, nextPage);
  172. }
  173. else
  174. {
  175. state.ClearHiddenWhileUnattended();
  176. }
  177. }
  178. Enable();
  179. return true;
  180. }
  181. // returns true if the path is valid, false if not. Pesters the user on
  182. // validation failures.
  183. bool
  184. ValidateSYSVOLPath(const String& path, HWND parent, unsigned editResID)
  185. {
  186. LOG_FUNCTION(validateSysvolPath);
  187. ASSERT(Win::IsWindow(parent));
  188. ASSERT(!path.empty());
  189. // check that the path is not the same as the database or log paths
  190. // previously entered. 313059
  191. State& state = State::GetInstance();
  192. String db = state.GetDatabasePath();
  193. if (db.icompare(path) == 0)
  194. {
  195. popup.Gripe(
  196. parent,
  197. editResID,
  198. String::format(IDS_SYSVOL_CANT_MATCH_DB, db.c_str()));
  199. return false;
  200. }
  201. String log = state.GetLogPath();
  202. if (log.icompare(path) == 0)
  203. {
  204. popup.Gripe(
  205. parent,
  206. editResID,
  207. String::format(IDS_SYSVOL_CANT_MATCH_LOG, log.c_str()));
  208. return false;
  209. }
  210. // check that the path is not a parent folder of the database or log
  211. // paths previously entered. 320685
  212. if (FS::IsParentFolder(path, db))
  213. {
  214. popup.Gripe(
  215. parent,
  216. editResID,
  217. String::format(IDS_SYSVOL_CANT_BE_DB_PARENT, db.c_str()));
  218. return false;
  219. }
  220. if (FS::IsParentFolder(path, log))
  221. {
  222. popup.Gripe(
  223. parent,
  224. editResID,
  225. String::format(IDS_SYSVOL_CANT_BE_LOG_PARENT, log.c_str()));
  226. return false;
  227. }
  228. // // if replicating from media, destination sysvol folder may not be any
  229. // // of the source paths.
  230. //
  231. // if (state.ReplicateFromMedia())
  232. // {
  233. // String p = state.GetReplicationSourcePath();
  234. // if (p.icompare(path) == 0)
  235. // {
  236. // popup.Gripe(
  237. // parent,
  238. // editResID,
  239. // String::format(IDS_SYSVOL_CANT_MATCH_SOURCE_PATH, p.c_str()));
  240. // return false;
  241. // }
  242. // }
  243. // if you change this, change the error message resource too.
  244. static const unsigned SYSVOL_MIN_SPACE_MB = 100;
  245. if (!CheckDiskSpace(path, SYSVOL_MIN_SPACE_MB))
  246. {
  247. popup.Gripe(
  248. parent,
  249. editResID,
  250. String::format(IDS_SYSVOL_LOW_SPACE, log.c_str()));
  251. return false;
  252. }
  253. return true;
  254. }
  255. int
  256. Paths2Page::Validate()
  257. {
  258. LOG_FUNCTION(Paths2Page::Validate);
  259. int nextPage = -1;
  260. String path =
  261. FS::NormalizePath(Win::GetTrimmedDlgItemText(hwnd, IDC_SYSVOL));
  262. if (
  263. // require uncompressed folder
  264. // NTRAID#NTBUG9-523532-2002/04/19-sburns
  265. ValidateDcInstallPath(path, hwnd, IDC_SYSVOL, true, false, true)
  266. && ValidateSYSVOLPath(path, hwnd, IDC_SYSVOL) )
  267. {
  268. State& state = State::GetInstance();
  269. state.SetSYSVOLPath(path);
  270. if (state.GetOperation() == State::FOREST)
  271. {
  272. nextPage = IDD_NEW_SITE;
  273. }
  274. else
  275. {
  276. nextPage = IDD_PICK_SITE;
  277. }
  278. }
  279. return nextPage;
  280. }