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.

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