cdverify.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : commando *
  23. * *
  24. * $Archive:: /Commando/Code/commando/cdverify.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/03/02 9:57a $*
  29. * *
  30. * $Revision:: 7 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "always.h"
  36. #include "cdverify.h"
  37. #include "wwstring.h"
  38. #include "popupdialog.h"
  39. #include "resource.h"
  40. //////////////////////////////////////////////////////////////////////
  41. // Local constants
  42. //////////////////////////////////////////////////////////////////////
  43. static const char *RENEGADE_MOVIES_VOLUME = "Renegade Data";
  44. ////////////////////////////////////////////////////////////////
  45. //
  46. // CDVerifyDialogClass
  47. //
  48. ////////////////////////////////////////////////////////////////
  49. class CDVerifyDialogClass : public PopupDialogClass
  50. {
  51. public:
  52. ////////////////////////////////////////////////////////////////
  53. // Public constructors/destructors
  54. ////////////////////////////////////////////////////////////////
  55. CDVerifyDialogClass (void) :
  56. Object (NULL),
  57. PopupDialogClass (IDD_CDVERIFY) {}
  58. void On_Command (int ctrl_id, int mesage_id, DWORD param);
  59. void Set_Object (CDVerifyClass *object) { Object = object; }
  60. private:
  61. ////////////////////////////////////////////////////////////////
  62. // Private member data
  63. ////////////////////////////////////////////////////////////////
  64. CDVerifyClass * Object;
  65. };
  66. //////////////////////////////////////////////////////////////////////
  67. //
  68. // Get_CD_Path
  69. //
  70. //////////////////////////////////////////////////////////////////////
  71. bool
  72. CDVerifyClass::Get_CD_Path (StringClass &drive_path)
  73. {
  74. bool retval = false;
  75. char buffer[1024] = { 0 };
  76. ::GetLogicalDriveStrings (sizeof (buffer), buffer);
  77. //
  78. // Loop over all the drives
  79. //
  80. const char *drive_root_name = buffer;
  81. while (drive_root_name[0] != 0) {
  82. //
  83. // Only check CD drives
  84. //
  85. if (::GetDriveType (drive_root_name) == DRIVE_CDROM) {
  86. //
  87. // Get the name of this volume
  88. //
  89. char volume_name[256] = { 0 };
  90. if (::GetVolumeInformation (drive_root_name, volume_name, sizeof (volume_name),
  91. NULL, NULL, NULL, NULL, NULL))
  92. {
  93. int cmp_len = ::lstrlen (volume_name);
  94. cmp_len = max (cmp_len, 11);
  95. //
  96. // Is this the movies CD?
  97. //
  98. if (::strnicmp (volume_name, RENEGADE_MOVIES_VOLUME, cmp_len) == 0) {
  99. retval = true;
  100. drive_path = drive_root_name;
  101. break;
  102. }
  103. }
  104. }
  105. //
  106. // Advance to the next drive
  107. //
  108. drive_root_name += ::lstrlen (drive_root_name) + 1;
  109. }
  110. return retval;
  111. }
  112. //////////////////////////////////////////////////////////////////////
  113. //
  114. // Get_CD_Path
  115. //
  116. //////////////////////////////////////////////////////////////////////
  117. void
  118. CDVerifyClass::Display_UI (Observer<CDVerifyEvent> *observer)
  119. {
  120. AddObserver (*observer);
  121. //
  122. // Display the dialog
  123. //
  124. CDVerifyDialogClass *dialog = new CDVerifyDialogClass;
  125. dialog->Set_Object (this);
  126. dialog->Start_Dialog ();
  127. REF_PTR_RELEASE (dialog);
  128. return ;
  129. }
  130. ////////////////////////////////////////////////////////////////
  131. //
  132. // On_Command
  133. //
  134. ////////////////////////////////////////////////////////////////
  135. void
  136. CDVerifyDialogClass::On_Command (int ctrl_id, int message_id, DWORD param)
  137. {
  138. //
  139. // Check to see if the CD is in the drive now...
  140. ///
  141. if (ctrl_id == IDOK) {
  142. StringClass path;
  143. if (Object->Get_CD_Path (path)) {
  144. //
  145. // Notify anybody who cares that the CD is in the drive
  146. //
  147. CDVerifyEvent event (CDVerifyEvent::VERIFIED, Object);
  148. Object->NotifyObservers (event);
  149. //
  150. // Close the dialog
  151. //
  152. End_Dialog ();
  153. }
  154. } else if (ctrl_id == IDCANCEL) {
  155. //
  156. // Notify anybody who cares that the user has cancelled the operation
  157. //
  158. CDVerifyEvent event (CDVerifyEvent::NOT_VERIFIED, Object);
  159. Object->NotifyObservers (event);
  160. //
  161. // Close the dialog
  162. //
  163. End_Dialog ();
  164. }
  165. PopupDialogClass::On_Command (ctrl_id, message_id, param);
  166. return ;
  167. }