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.

373 lines
8.9 KiB

  1. // Copyright (C) 1997 Microsoft Corporation
  2. //
  3. // paths page
  4. //
  5. // 12-22-97 sburns
  6. #include "headers.hxx"
  7. #include "page.hpp"
  8. #include "PathsPage.hpp"
  9. #include "resource.h"
  10. #include "state.hpp"
  11. #include "common.hpp"
  12. // NTRAID#NTBUG9-468577-2001/09/17-sburns
  13. // NTRAID#NTBUG9-475838-2001/10/02-sburns
  14. static const int DB_AND_LOG_MAX_PATH =
  15. MAX_PATH
  16. - 13 // for 8.3 named files under the path
  17. - 18; // for worst case UNC name of the path, 'cause NTBackup is broken.
  18. PathsPage::PathsPage()
  19. :
  20. DCPromoWizardPage(
  21. IDD_PATHS,
  22. IDS_PATHS_PAGE_TITLE,
  23. IDS_PATHS_PAGE_SUBTITLE),
  24. touchWizButtons(true)
  25. {
  26. LOG_CTOR(PathsPage);
  27. }
  28. PathsPage::~PathsPage()
  29. {
  30. LOG_DTOR(PathsPage);
  31. }
  32. void
  33. PathsPage::OnInit()
  34. {
  35. LOG_FUNCTION(PathsPage::OnInit);
  36. Win::Edit_LimitText(Win::GetDlgItem(hwnd, IDC_DB), DB_AND_LOG_MAX_PATH);
  37. Win::Edit_LimitText(Win::GetDlgItem(hwnd, IDC_LOG), DB_AND_LOG_MAX_PATH);
  38. State& state = State::GetInstance();
  39. if (state.UsingAnswerFile())
  40. {
  41. Win::SetDlgItemText(
  42. hwnd,
  43. IDC_DB,
  44. Win::ExpandEnvironmentStrings(
  45. state.GetAnswerFileOption(AnswerFile::OPTION_DATABASE_PATH)));
  46. Win::SetDlgItemText(
  47. hwnd,
  48. IDC_LOG,
  49. Win::ExpandEnvironmentStrings(
  50. state.GetAnswerFileOption(AnswerFile::OPTION_LOG_PATH)));
  51. }
  52. String root = Win::GetSystemWindowsDirectory();
  53. if (Win::GetTrimmedDlgItemText(hwnd, IDC_DB).empty())
  54. {
  55. Win::SetDlgItemText(
  56. hwnd,
  57. IDC_DB,
  58. root + String::load(IDS_DB_SUFFIX));
  59. }
  60. if (Win::GetTrimmedDlgItemText(hwnd, IDC_LOG).empty())
  61. {
  62. Win::SetDlgItemText(
  63. hwnd,
  64. IDC_LOG,
  65. root + String::load(IDS_LOG_SUFFIX));
  66. }
  67. }
  68. void
  69. PathsPage::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_DB).empty()
  79. && !Win::GetTrimmedDlgItemText(hwnd, IDC_LOG).empty() )
  80. ? PSWIZB_NEXT : 0;
  81. Win::PropSheet_SetWizButtons(Win::GetParent(hwnd), PSWIZB_BACK | next);
  82. }
  83. }
  84. bool
  85. PathsPage::OnCommand(
  86. HWND /* windowFrom */ ,
  87. unsigned controlIdFrom,
  88. unsigned code)
  89. {
  90. // LOG_FUNCTION(PathsPage::OnCommand);
  91. bool result = false;
  92. switch (controlIdFrom)
  93. {
  94. case IDC_BROWSE_DB:
  95. {
  96. if (code == BN_CLICKED)
  97. {
  98. String path = BrowseForFolder(hwnd, IDS_DB_BROWSE_TITLE);
  99. if (!path.empty())
  100. {
  101. Win::SetDlgItemText(hwnd, IDC_DB, path);
  102. }
  103. result = true;
  104. }
  105. break;
  106. }
  107. case IDC_BROWSE_LOG:
  108. {
  109. if (code == BN_CLICKED)
  110. {
  111. String path = BrowseForFolder(hwnd, IDS_LOG_BROWSE_TITLE);
  112. if (!path.empty())
  113. {
  114. Win::SetDlgItemText(hwnd, IDC_LOG, path);
  115. }
  116. result = true;
  117. }
  118. break;
  119. }
  120. case IDC_DB:
  121. case IDC_LOG:
  122. {
  123. switch (code)
  124. {
  125. case EN_CHANGE:
  126. {
  127. SetChanged(controlIdFrom);
  128. Enable();
  129. result = true;
  130. break;
  131. }
  132. case EN_KILLFOCUS:
  133. {
  134. // Since the normalization fully-expands relative paths, the
  135. // full pathname may not match what the user entered. So we
  136. // update the edit box contents to make sure they realize what
  137. // the relative path expands to.
  138. // NTRAID#NTBUG9-216148-2000/11/01-sburns
  139. String text = Win::GetTrimmedDlgItemText(hwnd, controlIdFrom);
  140. if (!text.empty())
  141. {
  142. // turn off setting of wizard buttons so that the call to
  143. // Enable made by the EN_CHANGE handler (which will be
  144. // called when we set the edit box text) will not call
  145. // PropSheet_SetWizButtons, which will mess up the tab
  146. // processing.
  147. touchWizButtons = false;
  148. Win::SetDlgItemText(
  149. hwnd,
  150. controlIdFrom,
  151. FS::NormalizePath(text));
  152. touchWizButtons = true;
  153. }
  154. result = true;
  155. break;
  156. }
  157. default:
  158. {
  159. // do nothing
  160. break;
  161. }
  162. }
  163. break;
  164. }
  165. default:
  166. {
  167. // do nothing
  168. break;
  169. }
  170. }
  171. return result;
  172. }
  173. bool
  174. PathsPage::OnSetActive()
  175. {
  176. LOG_FUNCTION(PathsPage::OnSetActive);
  177. Win::PropSheet_SetWizButtons(
  178. Win::GetParent(hwnd),
  179. PSWIZB_BACK);
  180. State& state = State::GetInstance();
  181. if (state.RunHiddenUnattended())
  182. {
  183. int nextPage = Validate();
  184. if (nextPage != -1)
  185. {
  186. GetWizard().SetNextPageID(hwnd, nextPage);
  187. }
  188. else
  189. {
  190. state.ClearHiddenWhileUnattended();
  191. }
  192. }
  193. Enable();
  194. return true;
  195. }
  196. int
  197. PathsPage::Validate()
  198. {
  199. LOG_FUNCTION(PathsPage::Validate);
  200. State& state = State::GetInstance();
  201. String dbPath = FS::NormalizePath(Win::GetTrimmedDlgItemText(hwnd, IDC_DB));
  202. String logPath = FS::NormalizePath(Win::GetTrimmedDlgItemText(hwnd, IDC_LOG));
  203. // If you change these, make sure you change the low disk space messages in
  204. // the resource file!
  205. static const unsigned DB_MIN_SPACE_MB = 200;
  206. static const unsigned LOG_MIN_SPACE_MB = 50;
  207. int nextPage = -1;
  208. bool valid = false;
  209. int editId = IDC_DB;
  210. String message;
  211. do
  212. {
  213. // // if replicating from media, destination folders may not be the
  214. // // source path.
  215. //
  216. // if (state.ReplicateFromMedia())
  217. // {
  218. // String p = state.GetReplicationSourcePath();
  219. // if (p.icompare(dbPath) == 0)
  220. // {
  221. // message = String::format(IDS_DB_CANT_MATCH_SOURCE_PATH, dbPath.c_str());
  222. // break;
  223. // }
  224. // }
  225. if (ValidateDcInstallPath(dbPath, hwnd, IDC_DB, false, true, true))
  226. {
  227. // grab the "X:\" part of the path
  228. String dbVolume = FS::GetRootFolder(dbPath);
  229. String logVolume = FS::GetRootFolder(logPath);
  230. bool sameVolume = (dbVolume.icompare(logVolume) == 0);
  231. if (
  232. !CheckDiskSpace(
  233. dbVolume,
  234. DB_MIN_SPACE_MB + (sameVolume ? LOG_MIN_SPACE_MB : 0)) )
  235. {
  236. message = String::load(IDS_LOW_SPACE_DB);
  237. break;
  238. }
  239. if (dbPath.icompare(logPath) != 0)
  240. {
  241. // the paths are different, so check the log path
  242. editId = IDC_LOG;
  243. if (
  244. ValidateDcInstallPath(
  245. logPath,
  246. hwnd,
  247. IDC_LOG,
  248. false,
  249. true,
  250. // require uncompressed folder for log, too.
  251. // NTRAID#NTBUG9-523532-2002/04/19-sburns
  252. true))
  253. {
  254. if (!CheckDiskSpace(logVolume, LOG_MIN_SPACE_MB))
  255. {
  256. message = String::load(IDS_LOW_SPACE_LOG);
  257. break;
  258. }
  259. // if (state.ReplicateFromMedia())
  260. // {
  261. // String p = state.GetReplicationSourcePath();
  262. // if (p.icompare(logPath) == 0)
  263. // {
  264. // message =
  265. // String::format(
  266. // IDS_LOG_CANT_MATCH_SOURCE_PATH,
  267. // logPath.c_str());
  268. // break;
  269. // }
  270. // }
  271. // paths differ, both are valid
  272. valid = true;
  273. }
  274. }
  275. else
  276. {
  277. // paths are the same, and we validated dbPath already
  278. valid = true;
  279. }
  280. }
  281. }
  282. while (0);
  283. if (!message.empty())
  284. {
  285. popup.Gripe(hwnd, editId, message);
  286. }
  287. if (valid)
  288. {
  289. state.SetDatabasePath(dbPath);
  290. state.SetLogPath(logPath);
  291. nextPage = IDD_PATHS2;
  292. }
  293. return nextPage;
  294. }