DirectoryDialog.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Installer *
  23. * *
  24. * $Archive:: /Commando/Code/Installer/DirectoryDialog.cpp $*
  25. * *
  26. * $Author:: Ian_l $*
  27. * *
  28. * $Modtime:: 12/13/01 5:46p $*
  29. * *
  30. * $Revision:: 8 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. // Includes.
  36. #include "DirectoryDialog.h"
  37. #include "DialogBase.h"
  38. #include "DialogText.h"
  39. #include "DirectoryBrowser.h"
  40. #include "ErrorHandler.h"
  41. #include "RegistryManager.h"
  42. #include "Resource.h"
  43. #include "Installer.h"
  44. #include "Translator.h"
  45. /***********************************************************************************************
  46. * DirectoryDialogClass::Update -- *
  47. * *
  48. * INPUT: *
  49. * *
  50. * OUTPUT: *
  51. * *
  52. * WARNINGS: *
  53. * *
  54. * HISTORY: *
  55. * 08/22/01 IML : Created. *
  56. *=============================================================================================*/
  57. void DirectoryDialogClass::Update (bool lazyupdate)
  58. {
  59. WideStringClass directorypath (Get_Dlg_Item_Text (IDC_DIRECTORY_EDIT));
  60. TxWideStringClass spaceneededstring (IDS_DISK_SPACE_NEEDED);
  61. WideStringClass sizestring;
  62. __int64 spaceavailable;
  63. if (!lazyupdate) {
  64. // Update static text control with disk space needed.
  65. spaceneededstring += Megabyte_Format (Get_Disk_Space_Needed(), sizestring);
  66. Set_Dlg_Item_Text (IDC_DIRECTORY_STATIC2, spaceneededstring);
  67. }
  68. // Lazily update disk space available.
  69. if (directorypath.Get_Length() >= 2) {
  70. if (directorypath [1] == L':') {
  71. if (!lazyupdate || (DriveLetter != directorypath [0])) {
  72. if (Get_Disk_Space_Available (directorypath, spaceavailable)) {
  73. TxWideStringClass spaceavailablestring (IDS_DISK_SPACE_AVAILABLE);
  74. spaceavailablestring += Megabyte_Format (spaceavailable, sizestring);
  75. Set_Dlg_Item_Text (IDC_DIRECTORY_STATIC3, spaceavailablestring);
  76. DriveLetter = directorypath [0];
  77. } else {
  78. Set_Dlg_Item_Text (IDC_DIRECTORY_STATIC3, L"");
  79. DriveLetter = '\0';
  80. }
  81. }
  82. } else {
  83. Set_Dlg_Item_Text (IDC_DIRECTORY_STATIC3, L"");
  84. DriveLetter = '\0';
  85. }
  86. } else {
  87. Set_Dlg_Item_Text (IDC_DIRECTORY_STATIC3, L"");
  88. DriveLetter = '\0';
  89. }
  90. }
  91. /***********************************************************************************************
  92. * DirectoryDialogClass::Megabyte_Format -- *
  93. * *
  94. * INPUT: *
  95. * *
  96. * OUTPUT: *
  97. * *
  98. * WARNINGS: *
  99. * *
  100. * HISTORY: *
  101. * 08/22/01 IML : Created. *
  102. *=============================================================================================*/
  103. WCHAR *DirectoryDialogClass::Megabyte_Format (__int64 bytecount, WideStringClass &outputstring)
  104. {
  105. char buffer [32];
  106. double size;
  107. // Output byte count in Megabytes.
  108. buffer [sizeof (buffer) - 1] = '\0';
  109. size = ((double) bytecount) / ((double)(1024 * 1024));
  110. _snprintf (buffer, sizeof (buffer) - 1, " %.2f ", size);
  111. outputstring = buffer;
  112. outputstring += TxWideStringClass (IDS_MEGABYTE_SYMBOL);
  113. return (outputstring.Peek_Buffer());
  114. }
  115. /***********************************************************************************************
  116. * DirectoryDialogClass::Callback -- *
  117. * *
  118. * INPUT: *
  119. * *
  120. * OUTPUT: *
  121. * *
  122. * WARNINGS: *
  123. * *
  124. * HISTORY: *
  125. * 08/22/01 IML : Created. *
  126. *=============================================================================================*/
  127. void DirectoryDialogClass::Callback (int id, PopupDialogClass *popup)
  128. {
  129. // Is this callback from the browser?
  130. if (popup == Browser) {
  131. switch (id) {
  132. case IDOK:
  133. {
  134. WideStringClass path;
  135. // Update edit control with selected path from browser.
  136. Browser->Get_Selected_Path (path);
  137. Set_Dlg_Item_Text (IDC_DIRECTORY_EDIT, path);
  138. Update();
  139. break;
  140. }
  141. case IDCANCEL:
  142. // Do nothing.
  143. break;
  144. default:
  145. break;
  146. }
  147. REF_PTR_RELEASE (Browser);
  148. } else {
  149. if (popup == OverwriteDialog) {
  150. switch (id) {
  151. case IDC_BUTTON_YES:
  152. On_Command (IDC_BUTTON_YES, 0, 0);
  153. REF_PTR_RELEASE (OverwriteDialog);
  154. break;
  155. default:
  156. REF_PTR_RELEASE (OverwriteDialog);
  157. break;
  158. }
  159. } else {
  160. // Callback is from some other source. Let the base class handle it.
  161. InstallMenuDialogClass::Callback (id, popup);
  162. }
  163. }
  164. }
  165. /***********************************************************************************************
  166. * DirectoryDialogClass::On_Activate -- *
  167. * *
  168. * INPUT: *
  169. * *
  170. * OUTPUT: *
  171. * *
  172. * WARNINGS: *
  173. * *
  174. * HISTORY: *
  175. * 08/22/01 IML : Created. *
  176. *=============================================================================================*/
  177. void DirectoryDialogClass::On_Activate (bool onoff)
  178. {
  179. // NOTE 0: Disk space needed/available may have changed since this dialog was last active.
  180. // NOTE 1: It is important to ensure that the dialog is running before Update() is called
  181. // (this indicates that the dialog has been initialized by the framework).
  182. if (onoff && Is_Running()) {
  183. Update();
  184. }
  185. InstallMenuDialogClass::On_Activate (onoff);
  186. }
  187. /***********************************************************************************************
  188. * DirectoryDialogClass::On_Frame_Update -- *
  189. * *
  190. * INPUT: *
  191. * *
  192. * OUTPUT: *
  193. * *
  194. * WARNINGS: *
  195. * *
  196. * HISTORY: *
  197. * 08/22/01 IML : Created. *
  198. *=============================================================================================*/
  199. void DirectoryDialogClass::On_Frame_Update (void)
  200. {
  201. Update (true);
  202. InstallMenuDialogClass::On_Frame_Update();
  203. }
  204. /***********************************************************************************************
  205. * DirectoryDialogClass::On_Command -- *
  206. * *
  207. * INPUT: *
  208. * *
  209. * OUTPUT: *
  210. * *
  211. * WARNINGS: *
  212. * *
  213. * HISTORY: *
  214. * 08/22/01 IML : Created. *
  215. *=============================================================================================*/
  216. void DirectoryDialogClass::On_Command (int ctrl_id, int message_id, DWORD param)
  217. {
  218. switch (ctrl_id)
  219. {
  220. case IDC_BUTTON_BROWSE:
  221. {
  222. Browser = NEW_REF (DirectoryBrowserClass, (this));
  223. Browser->Start_Dialog();
  224. break;
  225. }
  226. case IDOK:
  227. {
  228. WideStringClass path (Get_Dlg_Item_Text (IDC_DIRECTORY_EDIT));
  229. int errormessageid;
  230. __int64 spaceavailable;
  231. // Check that the selected path is valid.
  232. if (!Validate_Path (path, errormessageid)) {
  233. MessageBoxClass::Do_Dialog (TxWideStringClass (IDS_WARNING), TxWideStringClass (errormessageid), MessageBoxClass::MESSAGE_BOX_TYPE_OK, this);
  234. return;
  235. }
  236. // Check that the selected path is not a Windows system path.
  237. if (Is_System_Directory (path)) {
  238. MessageBoxClass::Do_Dialog (TxWideStringClass (IDS_WARNING), TxWideStringClass (IDS_SYSTEM_DIRECTORY), MessageBoxClass::MESSAGE_BOX_TYPE_OK, this);
  239. return;
  240. }
  241. // Check that there is enough disk space on the selected drive.
  242. if (!Get_Disk_Space_Available (path, spaceavailable)) {
  243. MessageBoxClass::Do_Dialog (TxWideStringClass (IDS_WARNING), TxWideStringClass (IDS_INVALID_PATH), MessageBoxClass::MESSAGE_BOX_TYPE_OK, this);
  244. return;
  245. }
  246. if (Get_Disk_Space_Needed() > spaceavailable) {
  247. MessageBoxClass::Do_Dialog (TxWideStringClass (IDS_WARNING), TxWideStringClass (IDS_NOT_ENOUGH_DISK_SPACE), MessageBoxClass::MESSAGE_BOX_TYPE_OK, this);
  248. return;
  249. }
  250. // If the path exists ask the user if he wishes to overwrite it?
  251. if (Directory_Exists (path)) {
  252. OverwriteDialog = MessageBoxClass::Create_Dialog (TxWideStringClass (IDS_WARNING), TxWideStringClass (IDS_DIRECTORY_EXISTS), MessageBoxClass::MESSAGE_BOX_TYPE_YES_NO, this);
  253. return;
  254. }
  255. break;
  256. }
  257. case IDC_BUTTON_YES:
  258. // NOTE: This command has come from the Overwrite dialog via the callback routine.
  259. InstallMenuDialogClass::On_Command (IDOK, message_id, param);
  260. return;
  261. default:
  262. break;
  263. }
  264. InstallMenuDialogClass::On_Command (ctrl_id, message_id, param);
  265. }
  266. /***********************************************************************************************
  267. * DirectoryDialogClass::Get_Path -- *
  268. * *
  269. * INPUT: *
  270. * *
  271. * OUTPUT: *
  272. * *
  273. * WARNINGS: *
  274. * *
  275. * HISTORY: *
  276. * 08/22/01 IML : Created. *
  277. *=============================================================================================*/
  278. const WCHAR *DirectoryDialogClass::Get_Path (WideStringClass &path)
  279. {
  280. path = Get_Dlg_Item_Text (IDC_DIRECTORY_EDIT);
  281. return (path);
  282. }
  283. /***********************************************************************************************
  284. * GameDirectoryDialogClass::On_Init_Dialog -- *
  285. * *
  286. * INPUT: *
  287. * *
  288. * OUTPUT: *
  289. * *
  290. * WARNINGS: *
  291. * *
  292. * HISTORY: *
  293. * 08/22/01 IML : Created. *
  294. *=============================================================================================*/
  295. void GameDirectoryDialogClass::On_Init_Dialog()
  296. {
  297. WideStringClass path;
  298. TxWideStringClass spaceneededstring (IDS_DISK_SPACE_NEEDED);
  299. Set_Dlg_Item_Text (IDC_DIRECTORY_STATIC1, TxWideStringClass (IDS_INSTALL_GAME_DIRECTORY));
  300. // Extract game path from registry (if it exists) - otherwise use a default.
  301. if (_RegistryManager.Get_Target_Game_Path (path)) {
  302. Set_Dlg_Item_Text (IDC_DIRECTORY_EDIT, path);
  303. } else {
  304. Set_Dlg_Item_Text (IDC_DIRECTORY_EDIT, TxWideStringClass (IDS_DEFAULT_GAME_PATH, IDS_RESOURCE_DEFAULT_GAME_PATH));
  305. }
  306. Update();
  307. InstallMenuDialogClass::On_Init_Dialog();
  308. }
  309. /***********************************************************************************************
  310. * WOLDirectoryDialogClass::On_Init_Dialog -- *
  311. * *
  312. * INPUT: *
  313. * *
  314. * OUTPUT: *
  315. * *
  316. * WARNINGS: *
  317. * *
  318. * HISTORY: *
  319. * 08/22/01 IML : Created. *
  320. *=============================================================================================*/
  321. void WOLDirectoryDialogClass::On_Init_Dialog()
  322. {
  323. WideStringClass path;
  324. TxWideStringClass spaceneededstring (IDS_DISK_SPACE_NEEDED);
  325. Set_Dlg_Item_Text (IDC_DIRECTORY_STATIC1, TxWideStringClass (IDS_INSTALL_WOL_DIRECTORY));
  326. // Extract WOL path from registry (if it exists) - otherwise use a default.
  327. if (_RegistryManager.Get_Target_WOL_Path (RegistryManagerClass::WOLAPI_COMPONENT, path)) {
  328. Set_Dlg_Item_Text (IDC_DIRECTORY_EDIT, path);
  329. } else {
  330. Set_Dlg_Item_Text (IDC_DIRECTORY_EDIT, TxWideStringClass (IDS_DEFAULT_WOL_PATH, IDS_RESOURCE_DEFAULT_WOL_PATH));
  331. }
  332. Update();
  333. InstallMenuDialogClass::On_Init_Dialog();
  334. }
  335. /***********************************************************************************************
  336. * WOLDirectoryDialogClass::On_Command -- *
  337. * *
  338. * INPUT: *
  339. * *
  340. * OUTPUT: *
  341. * *
  342. * WARNINGS: *
  343. * *
  344. * HISTORY: *
  345. * 08/22/01 IML : Created. *
  346. *=============================================================================================*/
  347. void WOLDirectoryDialogClass::On_Command (int ctrl_id, int message_id, DWORD param)
  348. {
  349. switch (ctrl_id)
  350. {
  351. case IDOK:
  352. {
  353. if (_Installer.Install_Game()) {
  354. WideStringClass gamepath;
  355. // Check that the selected WOL path is not the same as the target game path.
  356. if (Is_Same_Path (WideStringClass (Get_Dlg_Item_Text (IDC_DIRECTORY_EDIT)), _Installer.Get_Target_Game_Path (gamepath))) {
  357. MessageBoxClass::Do_Dialog (TxWideStringClass (IDS_WARNING), TxWideStringClass (IDS_SAME_PATHS), MessageBoxClass::MESSAGE_BOX_TYPE_OK, this);
  358. return;
  359. }
  360. }
  361. break;
  362. }
  363. default:
  364. break;
  365. }
  366. DirectoryDialogClass::On_Command (ctrl_id, message_id, param);
  367. }