FolderDialog.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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/FolderDialog.cpp $*
  25. * *
  26. * $Author:: Ian_l $*
  27. * *
  28. * $Modtime:: 12/13/01 5:46p $*
  29. * *
  30. * $Revision:: 9 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. // Includes.
  36. #include "FolderDialog.h"
  37. #include "ErrorHandler.h"
  38. #include "DialogText.h"
  39. #include "Installer.h"
  40. #include "ListCtrl.h"
  41. #include "RegistryManager.h"
  42. #include "Resource.h"
  43. #include "Translator.h"
  44. #include <io.h>
  45. /***********************************************************************************************
  46. * FolderDialogClass::On_Init_Dialog -- *
  47. * *
  48. * INPUT: *
  49. * *
  50. * OUTPUT: *
  51. * *
  52. * WARNINGS: *
  53. * *
  54. * HISTORY: *
  55. * 08/22/01 IML : Created. *
  56. *=============================================================================================*/
  57. void FolderDialogClass::On_Init_Dialog (void)
  58. {
  59. WideStringClass wildcardfolderpath;
  60. // Set-up the folder list control with available folders.
  61. if (_RegistryManager.Get_Folder_Path (wildcardfolderpath)) {
  62. const WCHAR *wildcardname = L"*.*";
  63. ListCtrlClass *listctrl;
  64. unsigned i;
  65. WIN32_FIND_DATA finddata;
  66. HANDLE handle;
  67. bool done = false;
  68. wildcardfolderpath += L"\\";
  69. wildcardfolderpath += wildcardname;
  70. StringClass multibytewildcardfolderpath (wildcardfolderpath);
  71. // Add a list item for each subdirectory.
  72. listctrl = Get_Dlg_Item (IDC_FOLDER_LIST)->As_ListCtrlClass();
  73. listctrl->Add_Column (L"", 1.0f, Vector3 (1.0f, 1.0f, 1.0f));
  74. i = 0;
  75. handle = FindFirstFile (multibytewildcardfolderpath, &finddata);
  76. if (handle != INVALID_HANDLE_VALUE) {
  77. while (!done) {
  78. WideStringClass filename (finddata.cFileName);
  79. if ((filename [0] != L'.') && (finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
  80. listctrl->Insert_Entry (i, filename);
  81. }
  82. if (done = FindNextFile (handle, &finddata) == 0) {
  83. if (GetLastError() != ERROR_NO_MORE_FILES) FATAL_SYSTEM_ERROR;
  84. }
  85. i++;
  86. }
  87. if (!FindClose (handle)) FATAL_SYSTEM_ERROR;
  88. listctrl->Sort_Alphabetically (0, ListCtrlClass::SORT_ASCENDING);
  89. }
  90. }
  91. InstallMenuDialogClass::On_Init_Dialog();
  92. }
  93. /***********************************************************************************************
  94. * FolderDialogClass::Get_Folder -- *
  95. * *
  96. * INPUT: *
  97. * *
  98. * OUTPUT: *
  99. * *
  100. * WARNINGS: *
  101. * *
  102. * HISTORY: *
  103. * 08/22/01 IML : Created. *
  104. *=============================================================================================*/
  105. const WCHAR *FolderDialogClass::Get_Folder (WideStringClass &folder)
  106. {
  107. folder = Get_Dlg_Item_Text (IDC_FOLDER_EDIT);
  108. return (folder);
  109. }
  110. /***********************************************************************************************
  111. * GameFolderDialogClass::On_Init_Dialog -- *
  112. * *
  113. * INPUT: *
  114. * *
  115. * OUTPUT: *
  116. * *
  117. * WARNINGS: *
  118. * *
  119. * HISTORY: *
  120. * 08/22/01 IML : Created. *
  121. *=============================================================================================*/
  122. void GameFolderDialogClass::On_Init_Dialog (void)
  123. {
  124. WideStringClass folder;
  125. // Initialize strings.
  126. Set_Dlg_Item_Text (IDC_FOLDER_STATIC1, TxWideStringClass (IDS_SELECT_GAME_FOLDER));
  127. // Extract game folder from registry (if it exists) - otherwise use a default.
  128. if (_RegistryManager.Get_Target_Game_Folder (folder)) {
  129. Set_Dlg_Item_Text (IDC_FOLDER_EDIT, folder);
  130. } else {
  131. Set_Dlg_Item_Text (IDC_FOLDER_EDIT, TxWideStringClass (IDS_DEFAULT_GAME_FOLDER, IDS_RESOURCE_DEFAULT_GAME_FOLDER));
  132. }
  133. FolderDialogClass::On_Init_Dialog();
  134. }
  135. /***********************************************************************************************
  136. * WOLFolderDialogClass::On_Init_Dialog -- *
  137. * *
  138. * INPUT: *
  139. * *
  140. * OUTPUT: *
  141. * *
  142. * WARNINGS: *
  143. * *
  144. * HISTORY: *
  145. * 08/22/01 IML : Created. *
  146. *=============================================================================================*/
  147. void WOLFolderDialogClass::On_Init_Dialog (void)
  148. {
  149. WideStringClass folder;
  150. // Initialize strings.
  151. Set_Dlg_Item_Text (IDC_FOLDER_STATIC1, TxWideStringClass (IDS_SELECT_WOL_FOLDER));
  152. // Extract game folder from registry (if it exists) - otherwise use a default.
  153. if (_RegistryManager.Get_Target_WOL_Folder (RegistryManagerClass::WOLAPI_COMPONENT, folder)) {
  154. Set_Dlg_Item_Text (IDC_FOLDER_EDIT, folder);
  155. } else {
  156. Set_Dlg_Item_Text (IDC_FOLDER_EDIT, TxWideStringClass (IDS_DEFAULT_WOL_FOLDER, IDS_RESOURCE_DEFAULT_WOL_FOLDER));
  157. }
  158. FolderDialogClass::On_Init_Dialog();
  159. }
  160. /***********************************************************************************************
  161. * FolderDialogClass::On_ListCtrl_Sel_Change -- *
  162. * *
  163. * INPUT: *
  164. * *
  165. * OUTPUT: *
  166. * *
  167. * WARNINGS: *
  168. * *
  169. * HISTORY: *
  170. * 08/22/01 IML : Created. *
  171. *=============================================================================================*/
  172. void FolderDialogClass::On_ListCtrl_Sel_Change (ListCtrlClass *list_ctrl, int ctrl_id, int old_index, int new_index)
  173. {
  174. Set_Dlg_Item_Text (IDC_FOLDER_EDIT, list_ctrl->Get_Entry_Text (new_index, 0));
  175. }
  176. /***********************************************************************************************
  177. * FolderDialogClass::On_Command -- *
  178. * *
  179. * INPUT: *
  180. * *
  181. * OUTPUT: *
  182. * *
  183. * WARNINGS: *
  184. * *
  185. * HISTORY: *
  186. * 08/22/01 IML : Created. *
  187. *=============================================================================================*/
  188. void FolderDialogClass::On_Command (int ctrl_id, int message_id, DWORD param)
  189. {
  190. switch (ctrl_id) {
  191. case IDOK:
  192. {
  193. WideStringClass foldername (Get_Dlg_Item_Text (IDC_FOLDER_EDIT));
  194. WideStringClass folderpathname;
  195. bool hasnonspacechar;
  196. int dummyid;
  197. // Check that the selected folder name has non-space characters.
  198. hasnonspacechar = false;
  199. for (int i = 0; i < foldername.Get_Length(); i++) {
  200. if (foldername [i] != L' ') hasnonspacechar = true;
  201. }
  202. if (!hasnonspacechar) {
  203. MessageBoxClass::Do_Dialog (TxWideStringClass (IDS_WARNING), TxWideStringClass (IDS_INVALID_FOLDER_NAME), MessageBoxClass::MESSAGE_BOX_TYPE_OK, this);
  204. return;
  205. }
  206. // Check that the selected folder path is valid.
  207. _RegistryManager.Get_Folder_Path (folderpathname);
  208. folderpathname += L"\\";
  209. folderpathname += Get_Dlg_Item_Text (IDC_FOLDER_EDIT);
  210. if (!Validate_Path (folderpathname, dummyid)) {
  211. MessageBoxClass::Do_Dialog (TxWideStringClass (IDS_WARNING), TxWideStringClass (IDS_INVALID_FOLDER_NAME), MessageBoxClass::MESSAGE_BOX_TYPE_OK, this);
  212. return;
  213. }
  214. }
  215. default:
  216. break;
  217. }
  218. InstallMenuDialogClass::On_Command (ctrl_id, message_id, param);
  219. }