DirectoryBrowser.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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/DirectoryBrowser.cpp $*
  25. * *
  26. * $Author:: Ian_l $*
  27. * *
  28. * $Modtime:: 11/25/01 11:12p $*
  29. * *
  30. * $Revision:: 6 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. // Includes.
  36. #include "DirectoryBrowser.h"
  37. #include "ErrorHandler.h"
  38. #include "TreeCtrl.h"
  39. #include <io.h>
  40. /***********************************************************************************************
  41. * DirectoryBrowserClass::Get_Selected_Path -- *
  42. * *
  43. * INPUT: *
  44. * *
  45. * OUTPUT: *
  46. * *
  47. * WARNINGS: *
  48. * *
  49. * HISTORY: *
  50. * 08/22/01 IML : Created. *
  51. *=============================================================================================*/
  52. void DirectoryBrowserClass::Get_Selected_Path (WideStringClass &selectedpath)
  53. {
  54. TreeCtrlClass *treectrl;
  55. treectrl = Get_Dlg_Item (IDC_BROWSER_TREE)->As_TreeCtrlClass();
  56. if (treectrl->Get_Selected_Item() != NULL) {
  57. Build_Pathname (treectrl->Get_Selected_Item(), selectedpath);
  58. } else {
  59. selectedpath = L"???";
  60. }
  61. }
  62. /***********************************************************************************************
  63. * BrowserDialogClass::On_Init_Dialog -- *
  64. * *
  65. * INPUT: *
  66. * *
  67. * OUTPUT: *
  68. * *
  69. * WARNINGS: *
  70. * *
  71. * HISTORY: *
  72. * 08/22/01 IML : Created. *
  73. *=============================================================================================*/
  74. void DirectoryBrowserClass::On_Init_Dialog (void)
  75. {
  76. TreeCtrlClass *treectrl;
  77. char drivename [] = "?:";
  78. treectrl = Get_Dlg_Item (IDC_BROWSER_TREE)->As_TreeCtrlClass();
  79. // Make an entry at the root of the tree control for every fixed drive.
  80. for (char r = 'A'; r <= 'Z'; r++) {
  81. drivename [0] = r;
  82. // If the drive is a fixed hard disc...
  83. if (GetDriveType (drivename) == DRIVE_FIXED) {
  84. TreeItemClass *treeitem;
  85. treeitem = treectrl->Insert_Item (WideStringClass (drivename), TreeCtrlClass::ICON_FOLDER, TreeCtrlClass::ICON_FOLDER_OPEN, NULL);
  86. treeitem->Set_Needs_Children (Has_Children (treectrl, treectrl->Get_ID(), treeitem));
  87. }
  88. }
  89. treectrl->Sort_Children_Alphabetically (NULL);
  90. // Must call base class.
  91. PopupDialogClass::On_Init_Dialog();
  92. }
  93. /***********************************************************************************************
  94. * DirectoryBrowserClass::On_TreeCtrl_Needs_Children -- *
  95. * *
  96. * INPUT: *
  97. * *
  98. * OUTPUT: *
  99. * *
  100. * WARNINGS: *
  101. * *
  102. * HISTORY: *
  103. * 08/22/01 IML : Created. *
  104. *=============================================================================================*/
  105. void DirectoryBrowserClass::On_TreeCtrl_Needs_Children (TreeCtrlClass *tree_ctrl, int ctrl_id, TreeItemClass *parent_item)
  106. {
  107. if (parent_item != NULL) {
  108. WideStringClass path;
  109. Build_Pathname (parent_item, path);
  110. Add_Folders (true, path, tree_ctrl, parent_item);
  111. tree_ctrl->Sort_Children_Alphabetically (parent_item);
  112. parent_item->Set_Needs_Children (false);
  113. }
  114. }
  115. /***********************************************************************************************
  116. * DirectoryBrowserClass::Has_Children -- *
  117. * *
  118. * INPUT: *
  119. * *
  120. * OUTPUT: *
  121. * *
  122. * WARNINGS: *
  123. * *
  124. * HISTORY: *
  125. * 08/22/01 IML : Created. *
  126. *=============================================================================================*/
  127. bool DirectoryBrowserClass::Has_Children (TreeCtrlClass *tree_ctrl, int ctrl_id, TreeItemClass *parent_item)
  128. {
  129. bool haschildren = true;
  130. if (parent_item != NULL) {
  131. WideStringClass path;
  132. Build_Pathname (parent_item, path);
  133. haschildren = Add_Folders (false, path, tree_ctrl, parent_item);
  134. }
  135. return (haschildren);
  136. }
  137. /***********************************************************************************************
  138. * DirectoryBrowserClass::Build_Pathname -- *
  139. * *
  140. * INPUT: *
  141. * *
  142. * OUTPUT: *
  143. * *
  144. * WARNINGS: *
  145. * *
  146. * HISTORY: *
  147. * 08/22/01 IML : Created. *
  148. *=============================================================================================*/
  149. void DirectoryBrowserClass::Build_Pathname (TreeItemClass *treenode, WideStringClass &path)
  150. {
  151. WideStringClass backslash ("\\");
  152. if (treenode->Get_Parent() != NULL) {
  153. Build_Pathname (treenode->Get_Parent(), path);
  154. }
  155. if (path.Get_Length() > 0) {
  156. path += backslash;
  157. }
  158. // Append the tree node's name whilst recursively unwinding.
  159. path += treenode->Get_Name();
  160. }
  161. /***********************************************************************************************
  162. * DirectoryBrowserClass::Add_Folders -- *
  163. * *
  164. * INPUT: *
  165. * *
  166. * OUTPUT: *
  167. * *
  168. * WARNINGS: *
  169. * *
  170. * HISTORY: *
  171. * 08/22/01 IML : Created. *
  172. *=============================================================================================*/
  173. bool DirectoryBrowserClass::Add_Folders (bool recurse, const WideStringClass &path, TreeCtrlClass *treectrl, TreeItemClass *treenode)
  174. {
  175. const WCHAR *wildcardname = L"*.*";
  176. WideStringClass pathname (path);
  177. StringClass multibytepathname;
  178. WIN32_FIND_DATA finddata;
  179. HANDLE handle;
  180. bool done = false;
  181. bool haschildren = false;
  182. // Add a child node for each subdirectory.
  183. pathname += L"\\";
  184. pathname += wildcardname;
  185. multibytepathname = pathname;
  186. handle = FindFirstFile (multibytepathname, &finddata);
  187. if (handle != INVALID_HANDLE_VALUE) {
  188. while (!done) {
  189. WideStringClass filename (finddata.cFileName);
  190. if ((filename [0] != L'.') && (finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
  191. TreeItemClass *treechild;
  192. haschildren = true;
  193. if (!recurse) break;
  194. treechild = treectrl->Insert_Item (filename, TreeCtrlClass::ICON_FOLDER, TreeCtrlClass::ICON_FOLDER_OPEN, treenode);
  195. treechild->Set_Needs_Children (Has_Children (treectrl, treectrl->Get_ID(), treechild));
  196. }
  197. if (done = FindNextFile (handle, &finddata) == 0) {
  198. if (GetLastError() != ERROR_NO_MORE_FILES) FATAL_SYSTEM_ERROR;
  199. }
  200. }
  201. if (!FindClose (handle)) FATAL_SYSTEM_ERROR;
  202. }
  203. // Does this node have any children?
  204. return (haschildren);
  205. }