CDManager.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. ** Command & Conquer Generals(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. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. //----------------------------------------------------------------------------
  24. //
  25. // Westwood Studios Pacific.
  26. //
  27. // Confidential Information
  28. // Copyright (C) 2001 - All Rights Reserved
  29. //
  30. //----------------------------------------------------------------------------
  31. //
  32. // Project: Generals
  33. //
  34. // Module: Game Engine Common
  35. //
  36. // File name: CDManager.cpp
  37. //
  38. // Created: 11/26/01 TR
  39. //
  40. //----------------------------------------------------------------------------
  41. //----------------------------------------------------------------------------
  42. // Includes
  43. //----------------------------------------------------------------------------
  44. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  45. #include "Common/CDManager.h"
  46. #include "GameLogic/GameLogic.h"
  47. //----------------------------------------------------------------------------
  48. // Externals
  49. //----------------------------------------------------------------------------
  50. //----------------------------------------------------------------------------
  51. // Defines
  52. //----------------------------------------------------------------------------
  53. //----------------------------------------------------------------------------
  54. // Private Types
  55. //----------------------------------------------------------------------------
  56. //----------------------------------------------------------------------------
  57. // Private Data
  58. //----------------------------------------------------------------------------
  59. //----------------------------------------------------------------------------
  60. // Public Data
  61. //----------------------------------------------------------------------------
  62. CDManagerInterface* TheCDManager = NULL;
  63. //----------------------------------------------------------------------------
  64. // Private Prototypes
  65. //----------------------------------------------------------------------------
  66. //----------------------------------------------------------------------------
  67. // Private Functions
  68. //----------------------------------------------------------------------------
  69. //----------------------------------------------------------------------------
  70. // Public Functions
  71. //----------------------------------------------------------------------------
  72. //============================================================================
  73. // CDDrive::CDDrive
  74. //============================================================================
  75. CDDrive::CDDrive()
  76. : m_disk(CD::UNKNOWN_DISK)
  77. {
  78. m_diskName.clear();
  79. m_drivePath.clear();
  80. }
  81. //============================================================================
  82. // CDDrive::~CDDrive
  83. //============================================================================
  84. CDDrive::~CDDrive()
  85. {
  86. }
  87. //============================================================================
  88. // CDDrive::getPath
  89. //============================================================================
  90. AsciiString CDDrive::getPath( void )
  91. {
  92. return m_drivePath;
  93. }
  94. //============================================================================
  95. // CDDrive::getDiskName
  96. //============================================================================
  97. AsciiString CDDrive::getDiskName( void )
  98. {
  99. return m_diskName;
  100. }
  101. void CDDrive::refreshInfo( void )
  102. {
  103. // map disk names to disk ID
  104. m_disk = CD::UNKNOWN_DISK;
  105. }
  106. //============================================================================
  107. // CDDrive::getDisk
  108. //============================================================================
  109. CD::Disk CDDrive::getDisk( void )
  110. {
  111. return m_disk;
  112. }
  113. //============================================================================
  114. // CDDrive::setPath
  115. //============================================================================
  116. void CDDrive::setPath( const Char *path )
  117. {
  118. m_drivePath = path;
  119. }
  120. //============================================================================
  121. // CDManager::CDManager
  122. //============================================================================
  123. CDManager::CDManager()
  124. {
  125. }
  126. //============================================================================
  127. // CDManager::~CDManager
  128. //============================================================================
  129. CDManager::~CDManager()
  130. {
  131. destroyAllDrives();
  132. }
  133. //============================================================================
  134. // CDManager::init
  135. //============================================================================
  136. void CDManager::init( void )
  137. {
  138. }
  139. //============================================================================
  140. // CDManager::update
  141. //============================================================================
  142. void CDManager::update( void )
  143. {
  144. // Every so often, check to make sure the CD is still in the drive
  145. if ((TheGameLogic->getFrame() % 300) == 299) {
  146. refreshDrives();
  147. }
  148. }
  149. //============================================================================
  150. // CDManager::reset
  151. //============================================================================
  152. void CDManager::reset( void )
  153. {
  154. }
  155. //============================================================================
  156. // CDManager::driveCount
  157. //============================================================================
  158. Int CDManager::driveCount( void )
  159. {
  160. return m_drives.nodeCount();
  161. }
  162. //============================================================================
  163. // CDManager::getDrive
  164. //============================================================================
  165. CDDriveInterface* CDManager::getDrive( Int index )
  166. {
  167. CDDriveInterface *cd = NULL;
  168. LListNode *node = m_drives.getNode( index );
  169. if ( node )
  170. {
  171. cd = (CDDriveInterface*) node->item();
  172. }
  173. return cd;
  174. }
  175. //============================================================================
  176. // CDManager::newDrive
  177. //============================================================================
  178. CDDriveInterface* CDManager::newDrive( const Char *path )
  179. {
  180. CDDrive *drive= (CDDrive*) createDrive();
  181. if ( drive )
  182. {
  183. drive->setPath( path );
  184. drive->m_node.setItem( drive );
  185. m_drives.add( &drive->m_node );
  186. }
  187. return drive;
  188. }
  189. //============================================================================
  190. // CDManager::refreshDrives
  191. //============================================================================
  192. void CDManager::refreshDrives( void )
  193. {
  194. LListNode *node = m_drives.firstNode();
  195. while ( node )
  196. {
  197. CDDriveInterface *drive = (CDDriveInterface *) node->item();
  198. if ( drive )
  199. {
  200. drive->refreshInfo();
  201. }
  202. node = node->next();
  203. }
  204. }
  205. //============================================================================
  206. // CDManager::destroyAllDrives
  207. //============================================================================
  208. void CDManager::destroyAllDrives( void )
  209. {
  210. LListNode *node;
  211. while ( (node = m_drives.firstNode() ) != NULL )
  212. {
  213. node->remove();
  214. CDDriveInterface *drive = (CDDriveInterface *) node->item();
  215. if ( drive )
  216. {
  217. delete drive;
  218. }
  219. }
  220. }